开发者

mysql: getting affected rows of an insert to a temporary table

after I pe开发者_如何学JAVArform an insert to a temporary table i would like to get the number of affected rows (how many rows i insert to the table).

what's the equivalent command of mysql_affected_rows() in SQL?

ROW_COUNT() returns -1;

using Mysql Server 5.1

thanks


ROW COUNT might be what you are looking for. Read the docs, there are details.

EDIT:
As I said, there are details - ROW_COUNT() works only from the same session and only immediately following an update query, otherwise it resets to -1.
There are other details, read the docs.


CREATE TEMPORARY TABLE mytest select login_token.id from login_token;

when I use the following command, MySQL returns the following status:

Query OK, 301 rows affected (0.02 sec)
Records: 301  Duplicates: 0  Warnings: 0

but when I query for ROW_COUNT():

mysql> select ROW_COUNT();
+-------------+
| ROW_COUNT() |
+-------------+
|          -1 |
+-------------+
1 row in set (0.00 sec)

I searched the net a lot and i found that the only proper solution is to run a count query.

select count(1) from  mytest;


did you mean from sql query ?

SELECT ROW_COUNT();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜