Menu

#114 [PHP]Return value is not zero when the previous query does not generate new rows of cubrid_insert_id method

open
nobody
None
5
2012-03-09
2012-03-09
Jira Trac
No

Test Build: CUBRID 2008 R4.1 (8.4.1.1018) (64bit release build for linux_gnu)
OS: Linux 64
Description:
first: inserting data into table, query generate new rows.
and then get the id generated for the AUTO_INCREMENT
second: inserting data into table, query doesn't generate new row.
and then get the isn't zero.

Description in [cubrid_insert_id|http://www.php.net/manual/en/function.cubrid-insert-id.php]
Return Values
A string representing the ID generated for an AUTO_INCREMENT column by the previous query, on success.
0, if the previous query does not generate new rows.
FALSE on failure.

Repro steps:
1. execute: php insert_id_test1.phpt
statement in insert_id_test1.phpt
{noformat}
$conn = cubrid_connect(localhost, 33113, demodb);
cubrid_execute($conn, DROP TABLE if exists insert_tb);
cubrid_execute($conn, CREATE TABLE insert_tb(a int auto_increment, b varchar(10)));

for($i=1;$i=10;$i++){
cubrid_execute($conn,insert into insert_tb(b) values($i));
}
$id1 = cubrid_insert_id();
var_dump($id1);
printf(\n\n);

cubrid_execute($conn,insert into insert_tb values(1,'1'));
$id2 = cubrid_insert_id($conn);
if(FALSE == $id2){
printf([002]Return value is false, [%d] [%s]\n,cubrid_errno($conn),cubrid_error($conn));
}elseif(0 == $id2){
printf([002]Return value is 0, [%d] [%s]\n,cubrid_errno($conn),cubrid_error($conn));
}else{
printf([002]id: %s\n,$id2);
}

cubrid_execute($conn,select * from insert_tb);
$id3 = cubrid_insert_id($conn);
if(FALSE == $id3){
printf([003]Return value is false, [%d] [%s]\n,cubrid_errno($conn),cubrid_error($conn));
}elseif(0 == $id3){
printf([003]Return value is 0, [%d] [%s]\n,cubrid_errno($conn),cubrid_error($conn));
}else{
printf([003]id: %s\n,$id3);
}
{noformat}

Actual result:
{noformat}
string(2) 10
[002]id: 10
[003]Return value is false, [0] []
Finished!
{noformat}

Expect result:
When the previous query does not generate new rows, would the ID generated for an AUTO_INCREMENT column be zero.

Discussion

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.