Oracle 5.0 Reference Manual page 2244

Table of Contents

Advertisement

You can always check whether the statement should have produced a nonempty result by calling
mysql_field_count(). If
last query was a statement that does not return values (for example, an
mysql_field_count()
result. See the description of the
You can test for an error by calling
20.6.13.2. What Results You Can Get from a Query
In addition to the result set returned by a query, you can also get the following information:
mysql_affected_rows()
INSERT, UPDATE, or DELETE.
For a fast re-create, use
mysql_num_rows()
mysql_num_rows()
mysql_use_result(),
rows with mysql_fetch_row().
mysql_insert_id()
an
AUTO_INCREMENT
• Some queries
return additional information. The result is returned by mysql_info(). See the description for
mysql_info()
there is no additional information.
20.6.13.3. How to Get the Unique ID for the Last Inserted Row
If you insert a record into a table that contains an
stored into that column by calling the
You can check from your C applications whether a value was stored in an
by executing the following code (which assumes that you've checked that the statement succeeded). It
determines whether the query was an
if ((result = mysql_store_result(&mysql)) == 0 &&
mysql_field_count(&mysql) == 0 &&
mysql_insert_id(&mysql) != 0)
{
used_id = mysql_insert_id(&mysql);
}
When a new
SELECT LAST_INSERT_ID()
result set returned by the statement.
For
LAST_INSERT_ID()
connection basis. It is not changed by another client. It is not even changed if you update another
AUTO_INCREMENT
LAST_INSERT_ID()
perfectly valid. Each client will receive the last inserted ID for the last statement that client executed.
If you want to use the ID that was generated for one table and insert it into a second table, you can use
SQL statements like this:
INSERT INTO foo (auto,text)
VALUES(NULL,'text');
INSERT INTO foo2 (id,text)
Common Questions and Problems When Using the C API
mysql_field_count()
returns a nonzero value, the statement should have produced a nonempty
mysql_field_count()
mysql_error()
returns the number of rows affected by the last query when doing an
TRUNCATE
returns the number of rows in a result set. With mysql_store_result(),
may be called as soon as
mysql_num_rows()
returns the ID generated by the last query that inserted a row into a table with
index. See
(LOAD DATA INFILE
for the format of the string that it returns.
value has been generated, you can also obtain it by executing a
AUTO_INCREMENT
statement with
[961], the most recently generated ID is maintained in the server on a per-
column with a nonmagic value (that is, a value that is not
[961]
and
AUTO_INCREMENT
returns zero, the result is empty and the
or mysql_errno().
TABLE.
mysql_store_result()
may be called only after you have fetched all the
Section 20.6.6.37,
"mysql_insert_id()".
...,
INSERT INTO ... SELECT
AUTO_INCREMENT
mysql_insert_id()
with an
INSERT
AUTO_INCREMENT
mysql_query()
columns simultaneously from multiple clients is
# generate ID by inserting NULL
2224
or a DELETE). If
INSERT
function for an example.
returns. With
..., UPDATE)
returns a
mysql_info()
column, you can obtain the value
function.
AUTO_INCREMENT
index:
and retrieving the value from the
NULL
pointer if
NULL
column
and not 0). Using

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents