/* gcc bug27592.c -g -o bug27592 -L/home/sbester/server/5.0/mysql-5.0.36-linux-i686/lib -I/home/sbester/server/5.0/mysql-5.0.36-linux-i686/include -lmysqlclient_r -lz -lpthread */ #include #include #include #include int main() { MYSQL *dbc=NULL; MYSQL_STMT *stmt=NULL; MYSQL_BIND bind[1]; MYSQL_TIME time_val; int param_count=0; int i=0; struct timeval tv; srand48(1); char *query="insert into t1 values (?)"; if (0 == (dbc = mysql_init(dbc))) { printf("mysql_init failed\n"); exit(1); } if (!mysql_real_connect(dbc,"192.168.250.4","root","","test",3306, NULL,CLIENT_FOUND_ROWS|CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS)) { printf("mysql_real_connect failed: %s (%d)\n", mysql_error(dbc),mysql_errno(dbc)); exit(1); } mysql_query(dbc,"drop table if exists t1"); mysql_query(dbc,"create table t1(c2 datetime)engine=innodb"); //printf("about to call mysql_stmt_init\n"); stmt = mysql_stmt_init(dbc); if (!stmt) { printf("mysql_stmt_init failed: %s (%d)\n", mysql_error(dbc),mysql_errno(dbc)); exit(1); } //printf("about to call mysql_stmt_prepare\n"); if(mysql_stmt_prepare(stmt, query, strlen(query))) { printf("mysql_stmt_prepare failed: %s (%d)\n",mysql_stmt_error(stmt),mysql_stmt_errno(stmt)); exit(1); } //printf("about to call mysql_stmt_param_count\n"); param_count = mysql_stmt_param_count(stmt); //printf("query '%s' has %d parameters\n",query,param_count); memset(bind, 0, sizeof(bind)); bind[0].buffer_type=MYSQL_TYPE_DATETIME; bind[0].buffer=(char*)&time_val; bind[0].length=NULL; for(i=0;i<100000;i++) { printf("iteration %d\n",i); time_val.year =1000+lrand48()%1000; time_val.month =1+lrand48()%12; time_val.day =1+lrand48()%31; time_val.hour =lrand48()%23; time_val.minute =lrand48()%59; time_val.second =lrand48()%59; time_val.second_part=0; time_val.neg=0; //printf("about to call mysql_stmt_bind_param\n"); if (mysql_stmt_bind_param(stmt, bind)) { printf("mysql_stmt_bind_param failed %s (%d)\n",mysql_stmt_error(stmt),mysql_stmt_errno(stmt)); exit(1); } //printf("mysql_stmt_execute\n"); if (mysql_stmt_execute(stmt)) { printf("mysql_stmt_execute failed: %s (%d)\n", mysql_stmt_error(stmt),mysql_stmt_errno(stmt)); exit(1); } } //printf("about to call mysql_stmt_close\n"); mysql_stmt_close(stmt); //printf("about to call mysql_close\n"); mysql_close(dbc); }