I have 2 statements that I'd like to string together in a query, but
according to everything I'm seeing, it's not possible.
What I'm doing is an insert of a row, where the primary key is an auto
increment. I want to retrieve that by using LAST_INSERT_ID( ). I
tried sending another query after the first (once I knew that it the
data was what I need) but it didn't return anything. It seems that
that function can't be used in separate calls or something. Either
that or there's a setting that I need to check. Any ideas? 7 1479
On Fri, 02 Mar 2007 11:28:02 -0800, pa***********@g mail.com wrote:
I have 2 statements that I'd like to string together in a query, but
according to everything I'm seeing, it's not possible.
What I'm doing is an insert of a row, where the primary key is an auto
increment. I want to retrieve that by using LAST_INSERT_ID( ). I
tried sending another query after the first (once I knew that it the
data was what I need) but it didn't return anything. It seems that
that function can't be used in separate calls or something. Either
that or there's a setting that I need to check. Any ideas?
If you're trying to return the last inserted row on a table with an auto
increment field all you have to do is query the maximum value in that
field.
..oO(Ivan Marsh)
>On Fri, 02 Mar 2007 11:28:02 -0800, pa***********@g mail.com wrote:
>I have 2 statements that I'd like to string together in a query, but according to everything I'm seeing, it's not possible. What I'm doing is an insert of a row, where the primary key is an auto increment. I want to retrieve that by using LAST_INSERT_ID( ). I tried sending another query after the first (once I knew that it the data was what I need) but it didn't return anything. It seems that that function can't be used in separate calls or something. Either that or there's a setting that I need to check. Any ideas?
Neither nor, there's an error in your second query. Please post some
code and the used query.
>If you're trying to return the last inserted row on a table with an auto increment field all you have to do is query the maximum value in that field.
Wrong! Never do it that way, never! Google for "race condition" and you
will know why. The correct way to do it is to call LAST_INSERT_ID( ),
either natively in a query or through a higher API function like
mysql_insert_id ().
Micha
Ivan Marsh wrote:
On Fri, 02 Mar 2007 11:28:02 -0800, pa***********@g mail.com wrote:
>I have 2 statements that I'd like to string together in a query, but according to everything I'm seeing, it's not possible. What I'm doing is an insert of a row, where the primary key is an auto increment. I want to retrieve that by using LAST_INSERT_ID( ). I tried sending another query after the first (once I knew that it the data was what I need) but it didn't return anything. It seems that that function can't be used in separate calls or something. Either that or there's a setting that I need to check. Any ideas?
If you're trying to return the last inserted row on a table with an auto
increment field all you have to do is query the maximum value in that
field.
And if you have two people insert at the same time one is going to get
the wrong value.
A terrible way to do it!
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== ===
I have 2 statements that I'd like to string together in a query, but
according to everything I'm seeing, it's not possible.
What I'm doing is an insert of a row, where the primary key is an auto
increment. I want to retrieve that by using LAST_INSERT_ID( ). I
tried sending another query after the first (once I knew that it the
data was what I need) but it didn't return anything. It seems that
that function can't be used in separate calls or something. Either
that or there's a setting that I need to check. Any ideas?
It is already suggested that you post the queries themselves. But it
could be something else: If you issue the queries in separate
connections, they will not work together. A connection in MySQL (I
assume you are using MySQL) is like a session: variables only exist
within that session and the result of LAST_INSERT_ID is also not visible
to other connections.
So you do issue the queries in one connection, I hope?
Best regards
Jerry Stuckle wrote:
And if you have two people insert at the same time one is going to get
the wrong value.
A terrible way to do it!
That has changed now, hasn't it?
My understanding now is that it will return the last value
created *on that particular connection*.
p.s. I'm still working on that join tutorial you gave me. Thx.
Sanders Kaufman wrote:
Jerry Stuckle wrote:
>And if you have two people insert at the same time one is going to get the wrong value.
A terrible way to do it!
That has changed now, hasn't it?
My understanding now is that it will return the last value created *on
that particular connection*.
p.s. I'm still working on that join tutorial you gave me. Thx.
No,
SELECT MAX(id) FROM mytable;
always returns the maximum value, no matter who inserted it.
You're thinking about mysql_last_inse rt_id(), which is connection specific.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attgl obal.net
=============== ===
On Mar 3, 1:07 pm, Dikkie Dik <nos...@nospam. orgwrote:
I have 2 statements that I'd like to string together in a query, but
according to everything I'm seeing, it's not possible.
What I'm doing is an insert of a row, where the primary key is an auto
increment. I want to retrieve that by using LAST_INSERT_ID( ). I
tried sending another query after the first (once I knew that it the
data was what I need) but it didn't return anything. It seems that
that function can't be used in separate calls or something. Either
that or there's a setting that I need to check. Any ideas?
It is already suggested that you post the queries themselves. But it
could be something else: If you issue the queries in separate
connections, they will not work together. A connection in MySQL (I
assume you are using MySQL) is like a session: variables only exist
within that session and the result of LAST_INSERT_ID is also not visible
to other connections.
So you do issue the queries in one connection, I hope?
Best regards
I actually solved it a different way. I was using a unique value to
create the table as it was, so I just used that instead.
I was using "SELECT LAST_INSERT_ID( );" as my second query. The first
just being a general insert. I'm positive there was nothing wrong
with my queries because I put them in the console, and it worked
fine. I think there might be some issues with my db wrapper, but
that's a separate issue I think. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Shmuel |
last post by:
Is it possible to query multiple statements at once?
Like:
$query = "set @p := 1; select @p + 1";
$results = mysql_query($query);
I'm thinking of PHP4. There is in mysqli the prepare statement,
but I can't use that.
Shmuel.
|
by: Steve |
last post by:
I have a SQL query I'm invoking via VB6 & ADO 2.8, that requires three
"Left Outer Joins" in order to return every transaction for a specific
set of criteria.
Using three "Left Outer Joins" slows the system down considerably.
I've tried creating a temp db, but I can't figure out how to execute
two select commands. (It throws the exception...
|
by: Zero.NULL |
last post by:
My multiple level nested corelated query is not fetching correct
result. It work fine on small set of data, but fails on larger set of
data. Any clue?
Explaining data storing and discussing design would be tough for me
here, still to show you how complex I have created my life, here is the
query:
select
(
|
by: DG |
last post by:
Hi,
Can anyone advise how to execute multiple statements in a single query
batch. For example-
update customers set customer_name = 'Smith' where customer_name =
'Smyth';
select * from customers;
I can execute each statement individually but get the 'you have an error in
|
by: Glenn Davy |
last post by:
Hidely hodley everyone
I'd like to run a series of of sql ddl statements against an msde2000
server. Normally I just deploy cmd file that impliments as osql statement,
but I'd like to store the 'patch' in an mdb file and use say ado or even
a passthrough statement to execute it.
The problem I've got Is I access (?) seems to require me to...
| |
by: Annie D via AccessMonster.com |
last post by:
Hi,
Is it possible to use multiple statements in SQL?? (I’ve never used it before)
:
I have one query that i'm working with, The statements I want to use are as
below, they all work individually, but not together, Access help is as much
use as a chocolate fireguard in this case! any suggestions or explainations
would be gratefully...
|
by: mimo |
last post by:
Hello,
I have seen samples on how to pull data from one table and save back to it
using the Form View control.
How do I pull from multiple tables and save back to multiple tables on one
screen? Is there a sample of this somewhere?
For example I want to create a Name and an Address from one screen. It has
to create a Name Record, a...
|
by: alingsjtu |
last post by:
Hello, every body.
When execute dynamic generated multiple OPENQUERY statements (which
linkes to DB2) in SQLServer, I always got SQL1040N The maximum number
of applications is already connected to the database. SQLSTATE=57030.
Background:
I created a linked server to DB2 8.1 database which called
GRR_DB2Server. In my stored procedure...
|
by: =?Utf-8?B?QVRT?= |
last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g.
Please help,
I'm trying to write an ASP page to use ADO to run a long query against an
Oracle 10g database, to create tables, if they do not already exist. In terms
of ASP/ADO, that would be fine in a SQL Server Sense by a simply
ASP/Server-Side JavaScript as such:
var...
|
by: harsha318 |
last post by:
Hi
I need to have a single query and which can have multiple statements
For eg:
string str = string.Empty;
str = "select * from Customers;Select * from Orders";
iDB2Connection iDB2con = new iDB2Connection(connStr);
iDB2Command iDBCmd = iDB2con.CreateCommand();
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |