#include "my_global.h" #include "mysql.h" /* create table bug12243(a int) engine=innodb; insert into bug12243 values (1), (2); */ #define SELECT123 "SELECT a FROM bug12243" int main(int argc, char **argv) { MYSQL *conn; MYSQL_STMT *prep_stmt = NULL, *prep_stmt2; int res; const ulong type= (ulong)CURSOR_TYPE_READ_ONLY; mysql_library_init(argc, argv, NULL); if (!(conn = mysql_real_connect(mysql_init(NULL), "10.17.69.84", "root", "mysql50", "test", 0, NULL, 0))) { fprintf(stderr, "Could not connect\n"); exit(1); } mysql_query(conn, "set autocommit=0"); prep_stmt= mysql_stmt_init(conn); prep_stmt2= mysql_stmt_init(conn); mysql_stmt_attr_set(prep_stmt, STMT_ATTR_CURSOR_TYPE, (const void *)&type); mysql_stmt_attr_set(prep_stmt2, STMT_ATTR_CURSOR_TYPE, (const void *)&type); res= mysql_stmt_prepare(prep_stmt, SELECT123 , strlen(SELECT123)); res= mysql_stmt_execute(prep_stmt); res= mysql_stmt_fetch(prep_stmt); res= mysql_stmt_prepare(prep_stmt2, SELECT123 , strlen(SELECT123)); res= mysql_stmt_execute(prep_stmt2); res= mysql_stmt_fetch(prep_stmt2); res= mysql_stmt_close(prep_stmt); res= mysql_query(conn, "commit"); res= mysql_stmt_fetch(prep_stmt2); }