2
Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
4
The MySQL Connector/C is licensed under the terms of the GPLv2
5
<http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
6
MySQL Connectors. There are special exceptions to the terms and
7
conditions of the GPLv2 as it is applied to this software, see the
8
FLOSS License Exception
9
<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
11
This program is free software; you can redistribute it and/or modify
12
it under the terms of the GNU General Public License as published
13
by the Free Software Foundation; version 2 of the License.
15
This program is distributed in the hope that it will be useful, but
16
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20
You should have received a copy of the GNU General Public License along
21
with this program; if not, write to the Free Software Foundation, Inc.,
22
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26
#define MY_INT64_NUM_DECIMAL_DIGITS 21
27
#define MAX_INDEXES 64
29
/* A workaround for Sun Forte 5.6 on Solaris x86 */
31
static int cmp_double(double *a, double *b)
37
/* Test BUG#1115 (incorrect string parameter value allocation) */
39
static int test_bug1115(MYSQL *mysql)
43
MYSQL_BIND my_bind[1];
46
char query[MAX_TEST_QUERY_LENGTH];
48
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select");
49
check_mysql_rc(rc, mysql);
51
rc= mysql_query(mysql, "CREATE TABLE test_select(\
52
session_id char(9) NOT NULL, \
53
a int(8) unsigned NOT NULL, \
56
d datetime NOT NULL)");
57
check_mysql_rc(rc, mysql);
58
rc= mysql_query(mysql, "INSERT INTO test_select VALUES "
59
"(\"abc\", 1, 2, 3, 2003-08-30), "
60
"(\"abd\", 1, 2, 3, 2003-08-30), "
61
"(\"abf\", 1, 2, 3, 2003-08-30), "
62
"(\"abg\", 1, 2, 3, 2003-08-30), "
63
"(\"abh\", 1, 2, 3, 2003-08-30), "
64
"(\"abj\", 1, 2, 3, 2003-08-30), "
65
"(\"abk\", 1, 2, 3, 2003-08-30), "
66
"(\"abl\", 1, 2, 3, 2003-08-30), "
67
"(\"abq\", 1, 2, 3, 2003-08-30) ");
68
check_mysql_rc(rc, mysql);
69
rc= mysql_query(mysql, "INSERT INTO test_select VALUES "
70
"(\"abw\", 1, 2, 3, 2003-08-30), "
71
"(\"abe\", 1, 2, 3, 2003-08-30), "
72
"(\"abr\", 1, 2, 3, 2003-08-30), "
73
"(\"abt\", 1, 2, 3, 2003-08-30), "
74
"(\"aby\", 1, 2, 3, 2003-08-30), "
75
"(\"abu\", 1, 2, 3, 2003-08-30), "
76
"(\"abi\", 1, 2, 3, 2003-08-30), "
77
"(\"abo\", 1, 2, 3, 2003-08-30), "
78
"(\"abp\", 1, 2, 3, 2003-08-30), "
79
"(\"abz\", 1, 2, 3, 2003-08-30), "
80
"(\"abx\", 1, 2, 3, 2003-08-30)");
81
check_mysql_rc(rc, mysql);
83
strcpy(query, "SELECT * FROM test_select WHERE "
84
"CONVERT(session_id USING utf8)= ?");
85
stmt= mysql_stmt_init(mysql);
86
FAIL_IF(!stmt, mysql_error(mysql));
87
rc= mysql_stmt_prepare(stmt, query, strlen(query));
88
check_stmt_rc(rc, stmt);
90
FAIL_IF(mysql_stmt_param_count(stmt) != 1, "Paramcount != 1");
92
memset(my_bind, '\0', sizeof(MYSQL_BIND));
94
strcpy(szData, (char *)"abc");
95
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
96
my_bind[0].buffer= (void *)szData;
97
my_bind[0].buffer_length= 10;
98
my_bind[0].length= &length[0];
101
rc= mysql_stmt_bind_param(stmt, my_bind);
102
check_stmt_rc(rc, stmt);
104
rc= mysql_stmt_execute(stmt);
105
check_stmt_rc(rc, stmt);
108
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
110
FAIL_IF(rowcount != 1, "rowcount=%d != 1");
112
strcpy(szData, (char *)"venu");
113
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
114
my_bind[0].buffer= (void *)szData;
115
my_bind[0].buffer_length= 10;
116
my_bind[0].length= &length[0];
118
my_bind[0].is_null= 0;
120
rc= mysql_stmt_bind_param(stmt, my_bind);
121
check_stmt_rc(rc, stmt);
123
rc= mysql_stmt_execute(stmt);
124
check_stmt_rc(rc, stmt);
127
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
129
FAIL_IF(rowcount != 0, "rowcount != 0");
131
strcpy(szData, (char *)"abc");
132
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
133
my_bind[0].buffer= (void *)szData;
134
my_bind[0].buffer_length= 10;
135
my_bind[0].length= &length[0];
137
my_bind[0].is_null= 0;
139
rc= mysql_stmt_bind_param(stmt, my_bind);
140
check_stmt_rc(rc, stmt);
142
rc= mysql_stmt_execute(stmt);
143
check_stmt_rc(rc, stmt);
146
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
148
FAIL_IF(rowcount != 1, "rowcount != 1");
150
mysql_stmt_close(stmt);
154
/* Test BUG#1180 (optimized away part of WHERE clause) */
156
static int test_bug1180(MYSQL *mysql)
160
MYSQL_BIND my_bind[1];
163
char query[MAX_TEST_QUERY_LENGTH];
165
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_select");
166
check_mysql_rc(rc, mysql);
168
rc= mysql_query(mysql, "CREATE TABLE test_select(session_id char(9) NOT NULL)");
169
check_mysql_rc(rc, mysql);
170
rc= mysql_query(mysql, "INSERT INTO test_select VALUES (\"abc\")");
171
check_mysql_rc(rc, mysql);
173
strcpy(query, "SELECT * FROM test_select WHERE ?= \"1111\" and "
174
"session_id= \"abc\"");
175
stmt= mysql_stmt_init(mysql);
176
FAIL_IF(!stmt, mysql_error(mysql));
177
rc= mysql_stmt_prepare(stmt, query, strlen(query));
178
check_stmt_rc(rc, stmt);
180
FAIL_IF(mysql_stmt_param_count(stmt) != 1, "Paramcount != 1");
182
memset(my_bind, '\0', sizeof(MYSQL_BIND));
184
strcpy(szData, (char *)"abc");
185
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
186
my_bind[0].buffer= (void *)szData;
187
my_bind[0].buffer_length= 10;
188
my_bind[0].length= &length[0];
190
my_bind[0].is_null= 0;
192
rc= mysql_stmt_bind_param(stmt, my_bind);
193
check_stmt_rc(rc, stmt);
195
rc= mysql_stmt_execute(stmt);
196
check_stmt_rc(rc, stmt);
200
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
202
FAIL_IF(rowcount != 0, "rowcount != 0");
204
strcpy(szData, (char *)"1111");
205
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
206
my_bind[0].buffer= (void *)szData;
207
my_bind[0].buffer_length= 10;
208
my_bind[0].length= &length[0];
210
my_bind[0].is_null= 0;
212
rc= mysql_stmt_bind_param(stmt, my_bind);
213
check_stmt_rc(rc, stmt);
215
rc= mysql_stmt_execute(stmt);
216
check_stmt_rc(rc, stmt);
219
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
221
FAIL_IF(rowcount != 1, "rowcount != 1");
223
strcpy(szData, (char *)"abc");
224
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
225
my_bind[0].buffer= (void *)szData;
226
my_bind[0].buffer_length= 10;
227
my_bind[0].length= &length[0];
229
my_bind[0].is_null= 0;
231
rc= mysql_stmt_bind_param(stmt, my_bind);
232
check_stmt_rc(rc, stmt);
234
rc= mysql_stmt_execute(stmt);
235
check_stmt_rc(rc, stmt);
238
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
240
FAIL_IF(rowcount != 0, "rowcount != 0");
242
mysql_stmt_close(stmt);
249
Test BUG#1644 (Insertion of more than 3 NULL columns with parameter
253
static int test_bug1644(MYSQL *mysql)
258
MYSQL_BIND my_bind[4];
262
char query[MAX_TEST_QUERY_LENGTH];
264
rc= mysql_query(mysql, "DROP TABLE IF EXISTS foo_dfr");
265
check_mysql_rc(rc, mysql);
267
rc= mysql_query(mysql,
268
"CREATE TABLE foo_dfr(col1 int, col2 int, col3 int, col4 int);");
269
check_mysql_rc(rc, mysql);
271
strcpy(query, "INSERT INTO foo_dfr VALUES (?, ?, ?, ? )");
272
stmt= mysql_stmt_init(mysql);
273
FAIL_IF(!stmt, mysql_error(mysql));
274
rc= mysql_stmt_prepare(stmt, query, strlen(query));
275
check_stmt_rc(rc, stmt);
277
FAIL_IF(mysql_stmt_param_count(stmt) != 4, "Paramcount != 4");
279
memset(my_bind, '\0', sizeof(MYSQL_BIND) * 4);
283
for (i= 0 ; i < 4 ; i++)
285
my_bind[i].buffer_type= MYSQL_TYPE_LONG;
286
my_bind[i].buffer= (void *)#
287
my_bind[i].is_null= &isnull;
290
rc= mysql_stmt_bind_param(stmt, my_bind);
291
check_stmt_rc(rc, stmt);
293
rc= mysql_stmt_execute(stmt);
294
check_stmt_rc(rc, stmt);
297
for (i= 0 ; i < 4 ; i++)
298
my_bind[i].is_null= &isnull;
300
rc= mysql_stmt_bind_param(stmt, my_bind);
301
check_stmt_rc(rc, stmt);
303
rc= mysql_stmt_execute(stmt);
304
check_stmt_rc(rc, stmt);
308
for (i= 0 ; i < 4 ; i++)
309
my_bind[i].is_null= &isnull;
311
rc= mysql_stmt_bind_param(stmt, my_bind);
312
check_stmt_rc(rc, stmt);
314
rc= mysql_stmt_execute(stmt);
315
check_stmt_rc(rc, stmt);
317
mysql_stmt_close(stmt);
319
rc= mysql_query(mysql, "SELECT * FROM foo_dfr");
320
check_mysql_rc(rc, mysql);
322
result= mysql_store_result(mysql);
323
FAIL_IF(!result, "Invalid resultset");
325
FAIL_IF(mysql_num_rows(result) != 3, "rowcount != 3");
327
mysql_data_seek(result, 0);
329
row= mysql_fetch_row(result);
330
FAIL_IF(!row, "row = NULL");
331
for (i= 0 ; i < 4 ; i++)
333
FAIL_UNLESS(strcmp(row[i], "22") == 0, "Wrong value");
335
row= mysql_fetch_row(result);
336
FAIL_IF(!row, "Invalid row");
337
for (i= 0 ; i < 4 ; i++)
339
FAIL_UNLESS(row[i] == 0, "row[i] != 0");
341
row= mysql_fetch_row(result);
342
FAIL_IF(!row, "Invalid row");
343
for (i= 0 ; i < 4 ; i++)
345
FAIL_UNLESS(strcmp(row[i], "88") == 0, "row[i] != 88");
347
row= mysql_fetch_row(result);
348
FAIL_IF(row, "row != NULL");
350
mysql_free_result(result);
355
static int test_bug11037(MYSQL *mysql)
359
const char *stmt_text;
361
rc= mysql_query(mysql, "drop table if exists t1");
362
check_mysql_rc(rc, mysql);
364
rc= mysql_query(mysql, "create table t1 (id int not null)");
365
check_mysql_rc(rc, mysql);
367
rc= mysql_query(mysql, "insert into t1 values (1)");
368
check_mysql_rc(rc, mysql);
370
stmt_text= "select id FROM t1";
371
stmt= mysql_stmt_init(mysql);
372
FAIL_IF(!stmt, mysql_error(mysql));
373
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
374
check_stmt_rc(rc, stmt);
377
rc = mysql_stmt_fetch(stmt);
378
FAIL_UNLESS(rc==1, "Error expedted");
380
rc= mysql_stmt_execute(stmt);
381
check_stmt_rc(rc, stmt);
383
rc= mysql_stmt_fetch(stmt);
384
check_stmt_rc(rc, stmt);
386
rc= mysql_stmt_fetch(stmt);
387
FAIL_UNLESS(rc==MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
389
rc= mysql_stmt_fetch(stmt);
390
FAIL_UNLESS(rc==MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
392
mysql_stmt_close(stmt);
393
rc= mysql_query(mysql, "drop table t1");
394
check_mysql_rc(rc, mysql);
399
/* Bug#11183 "mysql_stmt_reset() doesn't reset information about error" */
401
static int test_bug11183(MYSQL *mysql)
405
char bug_statement[]= "insert into t1 values (1)";
407
rc= mysql_query(mysql, "drop table if exists t1");
408
check_mysql_rc(rc, mysql);
409
rc= mysql_query(mysql, "create table t1 (a int)");
410
check_mysql_rc(rc, mysql);
412
stmt= mysql_stmt_init(mysql);
413
FAIL_IF(!stmt, mysql_error(mysql));
415
rc= mysql_stmt_prepare(stmt, bug_statement, strlen(bug_statement));
416
check_stmt_rc(rc, stmt);
418
rc= mysql_query(mysql, "drop table t1");
419
check_mysql_rc(rc, mysql);
421
/* Trying to execute statement that should fail on execute stage */
422
rc= mysql_stmt_execute(stmt);
423
FAIL_IF(!rc, "Error expected");
425
mysql_stmt_reset(stmt);
426
FAIL_IF(!mysql_stmt_errno(stmt) == 0, "stmt->error != 0");
428
rc= mysql_query(mysql, "create table t1 (a int)");
429
check_mysql_rc(rc, mysql);
431
/* Trying to execute statement that should pass ok */
432
if (mysql_stmt_execute(stmt))
434
mysql_stmt_reset(stmt);
435
FAIL_IF(mysql_stmt_errno(stmt) == 0, "stmt->error != 0");
438
mysql_stmt_close(stmt);
440
rc= mysql_query(mysql, "drop table t1");
441
check_mysql_rc(rc, mysql);
446
static int test_bug12744(MYSQL *mysql)
448
MYSQL_STMT *stmt = NULL;
451
stmt = mysql_stmt_init(mysql);
452
FAIL_IF(!stmt, mysql_error(mysql));
453
rc= mysql_stmt_prepare(stmt, "SET @a:=1", 9);
454
check_stmt_rc(rc, stmt);
456
rc= mysql_stmt_execute(stmt);
457
check_stmt_rc(rc, stmt);
459
/* set reconnect, kill and ping to reconnect */
460
rc= mysql_options(mysql, MYSQL_OPT_RECONNECT, "1");
461
check_mysql_rc(rc, mysql);
462
rc= mysql_kill(mysql, mysql_thread_id(mysql));
463
check_mysql_rc(rc, mysql);
466
rc= mysql_ping(mysql);
467
check_mysql_rc(rc, mysql);
469
rc= mysql_stmt_close(stmt);
470
check_mysql_rc(rc, mysql);
475
static int test_bug1500(MYSQL *mysql)
478
MYSQL_BIND my_bind[3];
480
int32 int_data[3]= {2, 3, 4};
485
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bg1500");
486
check_mysql_rc(rc, mysql);
488
rc= mysql_query(mysql, "CREATE TABLE test_bg1500 (i INT)");
489
check_mysql_rc(rc, mysql);
491
rc= mysql_query(mysql, "INSERT INTO test_bg1500 VALUES (1), (2)");
492
check_mysql_rc(rc, mysql);
494
rc= mysql_commit(mysql);
495
check_mysql_rc(rc, mysql);
497
query= "SELECT i FROM test_bg1500 WHERE i IN (?, ?, ?)";
498
stmt= mysql_stmt_init(mysql);
499
FAIL_IF(!stmt, mysql_error(mysql));
500
rc= mysql_stmt_prepare(stmt, query, strlen(query));
501
check_stmt_rc(rc, stmt);
503
FAIL_IF(mysql_stmt_param_count(stmt) != 3, "paramcount != 3");
505
memset(my_bind, '\0', sizeof(my_bind));
507
my_bind[0].buffer= (void *)int_data;
508
my_bind[0].buffer_type= MYSQL_TYPE_LONG;
509
my_bind[2]= my_bind[1]= my_bind[0];
510
my_bind[1].buffer= (void *)(int_data + 1);
511
my_bind[2].buffer= (void *)(int_data + 2);
513
rc= mysql_stmt_bind_param(stmt, my_bind);
514
check_stmt_rc(rc, stmt);
516
rc= mysql_stmt_execute(stmt);
517
check_stmt_rc(rc, stmt);
520
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
522
FAIL_UNLESS(rc == 1, "rowcount != 1");
524
mysql_stmt_close(stmt);
526
rc= mysql_query(mysql, "DROP TABLE test_bg1500");
527
check_mysql_rc(rc, mysql);
529
rc= mysql_query(mysql, "CREATE TABLE test_bg1500 (s VARCHAR(25), FULLTEXT(s)) engine=MyISAM");
530
check_mysql_rc(rc, mysql);
532
rc= mysql_query(mysql,
533
"INSERT INTO test_bg1500 VALUES ('Gravedigger'), ('Greed'), ('Hollow Dogs')");
534
check_mysql_rc(rc, mysql);
536
rc= mysql_commit(mysql);
537
check_mysql_rc(rc, mysql);
539
query= "SELECT s FROM test_bg1500 WHERE MATCH (s) AGAINST (?)";
540
stmt= mysql_stmt_init(mysql);
541
FAIL_IF(!stmt, mysql_error(mysql));
542
rc= mysql_stmt_prepare(stmt, query, strlen(query));
543
check_stmt_rc(rc, stmt);
545
FAIL_IF(mysql_stmt_param_count(stmt) != 1, "paramcount != 1");
548
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
549
my_bind[0].buffer= (void *) data;
550
my_bind[0].buffer_length= strlen(data);
551
my_bind[0].is_null= 0;
552
my_bind[0].length= 0;
554
rc= mysql_stmt_bind_param(stmt, my_bind);
555
check_stmt_rc(rc, stmt);
557
rc= mysql_stmt_execute(stmt);
558
check_stmt_rc(rc, stmt);
561
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
563
FAIL_UNLESS(rc == 1, "rowcount != 1");
565
mysql_stmt_close(stmt);
567
/* This should work too */
568
query= "SELECT s FROM test_bg1500 WHERE MATCH (s) AGAINST (CONCAT(?, 'digger'))";
569
stmt= mysql_stmt_init(mysql);
570
FAIL_IF(!stmt, mysql_error(mysql));
571
rc= mysql_stmt_prepare(stmt, query, strlen(query));
572
check_stmt_rc(rc, stmt);
574
FAIL_IF(mysql_stmt_param_count(stmt) != 1, "paramcount != 1");
577
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
578
my_bind[0].buffer= (void *) data;
579
my_bind[0].buffer_length= strlen(data);
581
rc= mysql_stmt_bind_param(stmt, my_bind);
582
check_stmt_rc(rc, stmt);
584
rc= mysql_stmt_execute(stmt);
585
check_stmt_rc(rc, stmt);
588
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
590
FAIL_UNLESS(rc == 1, "rowcount != 1");
592
mysql_stmt_close(stmt);
597
static int test_bug15510(MYSQL *mysql)
601
const char *query= "select 1 from dual where 1/0";
604
rc= mysql_query(mysql, "set @@sql_mode='ERROR_FOR_DIVISION_BY_ZERO'");
605
check_mysql_rc(rc, mysql);
607
stmt= mysql_stmt_init(mysql);
609
rc= mysql_stmt_prepare(stmt, query, strlen(query));
610
check_stmt_rc(rc, stmt);
612
rc= mysql_stmt_execute(stmt);
613
check_stmt_rc(rc, stmt);
615
rc= mysql_stmt_fetch(stmt);
616
FAIL_UNLESS(mysql_warning_count(mysql), "Warning expected");
619
mysql_stmt_close(stmt);
620
rc= mysql_query(mysql, "set @@sql_mode=''");
621
check_mysql_rc(rc, mysql);
627
Bug #15518 - Reusing a stmt that has failed during prepare
631
static int test_bug15518(MYSQL *mysql)
636
stmt= mysql_stmt_init(mysql);
639
The prepare of foo should fail with errno 1064 since
640
it's not a valid query
642
rc= mysql_stmt_prepare(stmt, "foo", 3);
643
FAIL_UNLESS(rc && mysql_stmt_errno(stmt) && mysql_errno(mysql), "Error expected");
646
Use the same stmt and reprepare with another query that
649
rc= mysql_stmt_prepare(stmt, "SHOW STATUS", 12);
650
FAIL_UNLESS(!rc || mysql_stmt_errno(stmt) || mysql_errno(mysql), "Error expected");
652
rc= mysql_stmt_close(stmt);
653
check_mysql_rc(rc, mysql);
655
part2, when connection to server has been closed
658
stmt= mysql_stmt_init(mysql);
659
rc= mysql_stmt_prepare(stmt, "foo", 3);
660
FAIL_UNLESS(rc && mysql_stmt_errno(stmt) && mysql_errno(mysql), "Error expected");
662
/* Close connection to server */
666
Use the same stmt and reprepare with another query that
667
suceeds. The prepare should fail with error 2013 since
668
connection to server has been closed.
670
rc= mysql_stmt_prepare(stmt, "SHOW STATUS", 12);
671
FAIL_UNLESS(rc && mysql_stmt_errno(stmt), "Error expected");
673
mysql_stmt_close(stmt);
679
Bug #15613: "libmysqlclient API function mysql_stmt_prepare returns wrong
683
static int test_bug15613(MYSQL *mysql)
686
const char *stmt_text;
691
/* I. Prepare the table */
692
rc= mysql_query(mysql, "set names latin1");
693
check_mysql_rc(rc, mysql);
694
mysql_query(mysql, "drop table if exists t1");
695
rc= mysql_query(mysql,
696
"create table t1 (t text character set utf8, "
697
"tt tinytext character set utf8, "
698
"mt mediumtext character set utf8, "
699
"lt longtext character set utf8, "
700
"vl varchar(255) character set latin1,"
701
"vb varchar(255) character set binary,"
702
"vu varchar(255) character set utf8)");
703
check_mysql_rc(rc, mysql);
705
stmt= mysql_stmt_init(mysql);
707
/* II. Check SELECT metadata */
708
stmt_text= ("select t, tt, mt, lt, vl, vb, vu from t1");
709
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
710
metadata= mysql_stmt_result_metadata(stmt);
711
field= mysql_fetch_fields(metadata);
712
FAIL_UNLESS(field[0].length == 65535, "length != 65535");
713
FAIL_UNLESS(field[1].length == 255, "length != 244");
714
FAIL_UNLESS(field[2].length == 16777215, "length != 166777215");
715
FAIL_UNLESS(field[3].length == 4294967295UL, "length != 4294967295UL");
716
FAIL_UNLESS(field[4].length == 255, "length != 255");
717
FAIL_UNLESS(field[5].length == 255, "length != 255");
718
FAIL_UNLESS(field[6].length == 255, "length != 255");
719
mysql_free_result(metadata);
720
mysql_stmt_free_result(stmt);
723
rc= mysql_query(mysql, "drop table t1");
724
check_mysql_rc(rc, mysql);
725
rc= mysql_query(mysql, "set names default");
726
check_mysql_rc(rc, mysql);
727
mysql_stmt_close(stmt);
732
static int test_bug16144(MYSQL *mysql)
734
const my_bool flag_orig= (my_bool) 0xde;
735
my_bool flag= flag_orig;
738
/* Check that attr_get returns correct data on little and big endian CPUs */
739
stmt= mysql_stmt_init(mysql);
740
mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (const void*) &flag);
741
mysql_stmt_attr_get(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*) &flag);
742
FAIL_UNLESS(flag == flag_orig, "flag != flag_orig");
744
mysql_stmt_close(stmt);
750
This tests for various mysql_stmt_send_long_data bugs described in #1664
753
static int test_bug1664(MYSQL *mysql)
758
const char *str_data= "Simple string";
759
MYSQL_BIND my_bind[2];
760
const char *query= "INSERT INTO test_long_data(col2, col1) VALUES(?, ?)";
763
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_long_data");
764
check_mysql_rc(rc, mysql);
766
rc= mysql_query(mysql, "CREATE TABLE test_long_data(col1 int, col2 long varchar)");
767
check_mysql_rc(rc, mysql);
769
stmt= mysql_stmt_init(mysql);
770
rc= mysql_stmt_prepare(stmt, query, strlen(query));
771
check_stmt_rc(rc, stmt);
773
FAIL_IF(mysql_stmt_param_count(stmt) != 2, "Param count != 2");
775
memset(my_bind, '\0', sizeof(my_bind));
777
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
778
my_bind[0].buffer= (void *)str_data;
779
my_bind[0].buffer_length= strlen(str_data);
781
my_bind[1].buffer= (void *)&int_data;
782
my_bind[1].buffer_type= MYSQL_TYPE_LONG;
784
rc= mysql_stmt_bind_param(stmt, my_bind);
785
check_stmt_rc(rc, stmt);
790
Let us supply empty long_data. This should work and should
791
not break following execution.
794
rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data));
795
check_stmt_rc(rc, stmt);
797
rc= mysql_stmt_execute(stmt);
798
check_stmt_rc(rc, stmt);
799
if (verify_col_data(mysql, "test_long_data", "col1", "1"))
801
if (verify_col_data(mysql, "test_long_data", "col2", ""))
803
rc= mysql_query(mysql, "DELETE FROM test_long_data");
804
check_mysql_rc(rc, mysql);
806
/* This should pass OK */
807
data= (char *)"Data";
808
rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data));
809
check_stmt_rc(rc, stmt);
811
rc= mysql_stmt_execute(stmt);
812
check_stmt_rc(rc, stmt);
814
if (verify_col_data(mysql, "test_long_data", "col1", "1"))
816
if (verify_col_data(mysql, "test_long_data", "col2", "Data"))
820
rc= mysql_query(mysql, "DELETE FROM test_long_data");
821
check_mysql_rc(rc, mysql);
824
Now we are changing int parameter and don't do anything
825
with first parameter. Second mysql_stmt_execute() should run
826
OK treating this first parameter as string parameter.
831
rc= mysql_stmt_execute(stmt);
832
check_stmt_rc(rc, stmt);
834
if (verify_col_data(mysql, "test_long_data", "col1", "2"))
836
if (verify_col_data(mysql, "test_long_data", "col2", str_data))
840
rc= mysql_query(mysql, "DELETE FROM test_long_data");
841
check_mysql_rc(rc, mysql);
844
Now we are sending other long data. It should not be
845
concatened to previous.
848
data= (char *)"SomeOtherData";
849
rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data));
850
check_stmt_rc(rc, stmt);
852
rc= mysql_stmt_execute(stmt);
853
check_stmt_rc(rc, stmt);
855
if (verify_col_data(mysql, "test_long_data", "col1", "2"))
857
if (verify_col_data(mysql, "test_long_data", "col2", "SomeOtherData"))
860
mysql_stmt_close(stmt);
863
rc= mysql_query(mysql, "DELETE FROM test_long_data");
864
check_mysql_rc(rc, mysql);
866
/* Now let us test how mysql_stmt_reset works. */
867
stmt= mysql_stmt_init(mysql);
868
rc= mysql_stmt_prepare(stmt, query, strlen(query));
869
check_stmt_rc(rc, stmt);
870
rc= mysql_stmt_bind_param(stmt, my_bind);
871
check_stmt_rc(rc, stmt);
873
data= (char *)"SomeData";
874
rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data));
875
check_stmt_rc(rc, stmt);
877
rc= mysql_stmt_reset(stmt);
878
check_stmt_rc(rc, stmt);
880
rc= mysql_stmt_execute(stmt);
881
check_stmt_rc(rc, stmt);
883
if (verify_col_data(mysql, "test_long_data", "col1", "2"))
885
if (verify_col_data(mysql, "test_long_data", "col2", str_data))
888
mysql_stmt_close(stmt);
891
rc= mysql_query(mysql, "DROP TABLE test_long_data");
892
check_mysql_rc(rc, mysql);
897
mysql_stmt_close(stmt);
898
rc= mysql_query(mysql, "DROP TABLE test_long_data");
901
/* Test a misc bug */
903
static int test_ushort_bug(MYSQL *mysql)
906
MYSQL_BIND my_bind[4];
909
ulong s_length, l_length, ll_length, t_length;
910
ulonglong longlong_value;
913
const char *query= "SELECT * FROM test_ushort";
915
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_ushort");
916
check_mysql_rc(rc, mysql);
918
rc= mysql_query(mysql, "CREATE TABLE test_ushort(a smallint unsigned, \
919
b smallint unsigned, \
920
c smallint unsigned, \
921
d smallint unsigned)");
922
check_mysql_rc(rc, mysql);
924
rc= mysql_query(mysql,
925
"INSERT INTO test_ushort VALUES(35999, 35999, 35999, 200)");
926
check_mysql_rc(rc, mysql);
928
stmt= mysql_stmt_init(mysql);
929
FAIL_IF(!stmt, mysql_error(mysql));
930
rc= mysql_stmt_prepare(stmt, query, strlen(query));
931
check_stmt_rc(rc, stmt);
933
rc= mysql_stmt_execute(stmt);
934
check_stmt_rc(rc, stmt);
936
memset(my_bind, '\0', sizeof(my_bind));
937
my_bind[0].buffer_type= MYSQL_TYPE_SHORT;
938
my_bind[0].buffer= (void *)&short_value;
939
my_bind[0].is_unsigned= TRUE;
940
my_bind[0].length= &s_length;
942
my_bind[1].buffer_type= MYSQL_TYPE_LONG;
943
my_bind[1].buffer= (void *)&long_value;
944
my_bind[1].length= &l_length;
946
my_bind[2].buffer_type= MYSQL_TYPE_LONGLONG;
947
my_bind[2].buffer= (void *)&longlong_value;
948
my_bind[2].length= &ll_length;
950
my_bind[3].buffer_type= MYSQL_TYPE_TINY;
951
my_bind[3].buffer= (void *)&tiny_value;
952
my_bind[3].is_unsigned= TRUE;
953
my_bind[3].length= &t_length;
955
rc= mysql_stmt_bind_result(stmt, my_bind);
956
check_stmt_rc(rc, stmt);
958
rc= mysql_stmt_fetch(stmt);
959
check_stmt_rc(rc, stmt);
961
FAIL_UNLESS(short_value == 35999, "short_value != 35999");
962
FAIL_UNLESS(s_length == 2, "length != 2");
964
FAIL_UNLESS(long_value == 35999, "long_value != 35999");
965
FAIL_UNLESS(l_length == 4, "length != 4");
967
FAIL_UNLESS(longlong_value == 35999, "longlong_value != 35999");
968
FAIL_UNLESS(ll_length == 8, "length != 8");
970
FAIL_UNLESS(tiny_value == 200, "tiny_value != 200");
971
FAIL_UNLESS(t_length == 1, "length != 1");
973
rc= mysql_stmt_fetch(stmt);
974
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
976
mysql_stmt_close(stmt);
981
static int test_bug1946(MYSQL *mysql)
985
const char *query= "INSERT INTO prepare_command VALUES (?)";
988
rc= mysql_query(mysql, "DROP TABLE IF EXISTS prepare_command");
989
check_mysql_rc(rc, mysql)
991
rc= mysql_query(mysql, "CREATE TABLE prepare_command(ID INT)");
992
check_mysql_rc(rc, mysql)
994
stmt= mysql_stmt_init(mysql);
995
FAIL_IF(!stmt, mysql_error(mysql));
996
rc= mysql_stmt_prepare(stmt, query, strlen(query));
997
check_stmt_rc(rc, stmt);
999
rc= mysql_real_query(mysql, query, strlen(query));
1000
FAIL_IF(!rc, "Error expected");
1002
mysql_stmt_close(stmt);
1003
rc= mysql_query(mysql, "DROP TABLE prepare_command");
1004
check_mysql_rc(rc, mysql);
1008
static int test_bug20152(MYSQL *mysql)
1010
MYSQL_BIND my_bind[1];
1014
const char *query= "INSERT INTO t1 (f1) VALUES (?)";
1017
memset(my_bind, '\0', sizeof(my_bind));
1018
my_bind[0].buffer_type= MYSQL_TYPE_DATE;
1019
my_bind[0].buffer= (void*)&tm;
1028
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
1029
check_mysql_rc(rc, mysql)
1030
rc= mysql_query(mysql, "CREATE TABLE t1 (f1 DATE)");
1031
check_mysql_rc(rc, mysql)
1033
stmt= mysql_stmt_init(mysql);
1034
rc= mysql_stmt_prepare(stmt, query, strlen(query));
1035
check_stmt_rc(rc, stmt);
1036
rc= mysql_stmt_bind_param(stmt, my_bind);
1037
check_stmt_rc(rc, stmt);
1038
rc= mysql_stmt_execute(stmt);
1039
check_stmt_rc(rc, stmt);
1040
rc= mysql_stmt_close(stmt);
1041
check_stmt_rc(rc, stmt);
1042
rc= mysql_query(mysql, "DROP TABLE t1");
1043
check_mysql_rc(rc, mysql)
1044
FAIL_UNLESS(tm.hour == 14 && tm.minute == 9 && tm.second == 42, "time != 14:09:42");
1048
static int test_bug2247(MYSQL *mysql)
1054
const char *create= "CREATE TABLE bug2247(id INT UNIQUE AUTO_INCREMENT)";
1055
const char *insert= "INSERT INTO bug2247 VALUES (NULL)";
1056
const char *SELECT= "SELECT id FROM bug2247";
1057
const char *update= "UPDATE bug2247 SET id=id+10";
1058
const char *drop= "DROP TABLE IF EXISTS bug2247";
1059
ulonglong exp_count;
1060
enum { NUM_ROWS= 5 };
1063
/* create table and insert few rows */
1064
rc= mysql_query(mysql, drop);
1065
check_mysql_rc(rc, mysql)
1067
rc= mysql_query(mysql, create);
1068
check_mysql_rc(rc, mysql)
1070
stmt= mysql_stmt_init(mysql);
1071
FAIL_IF(!stmt, mysql_error(mysql));
1072
rc= mysql_stmt_prepare(stmt, insert, strlen(insert));
1073
check_stmt_rc(rc, stmt);
1074
for (i= 0; i < NUM_ROWS; ++i)
1076
rc= mysql_stmt_execute(stmt);
1077
check_stmt_rc(rc, stmt);
1079
exp_count= mysql_stmt_affected_rows(stmt);
1080
FAIL_UNLESS(exp_count == 1, "exp_count != 1");
1082
rc= mysql_query(mysql, SELECT);
1083
check_mysql_rc(rc, mysql)
1085
mysql_store_result overwrites mysql->affected_rows. Check that
1086
mysql_stmt_affected_rows() returns the same value, whereas
1087
mysql_affected_rows() value is correct.
1089
res= mysql_store_result(mysql);
1090
FAIL_IF(!res, "Invalid result set");
1092
FAIL_UNLESS(mysql_affected_rows(mysql) == NUM_ROWS, "affected_rows != NUM_ROWS");
1093
FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count");
1095
rc= mysql_query(mysql, update);
1096
check_mysql_rc(rc, mysql)
1097
FAIL_UNLESS(mysql_affected_rows(mysql) == NUM_ROWS, "affected_rows != NUM_ROWS");
1098
FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count");
1100
mysql_free_result(res);
1101
mysql_stmt_close(stmt);
1103
/* check that mysql_stmt_store_result modifies mysql_stmt_affected_rows */
1104
stmt= mysql_stmt_init(mysql);
1105
FAIL_IF(!stmt, mysql_error(mysql));
1106
rc= mysql_stmt_prepare(stmt, SELECT, strlen(SELECT));
1107
check_stmt_rc(rc, stmt);
1109
rc= mysql_stmt_execute(stmt);
1110
check_stmt_rc(rc, stmt); rc= mysql_stmt_store_result(stmt);
1111
check_stmt_rc(rc, stmt); exp_count= mysql_stmt_affected_rows(stmt);
1112
FAIL_UNLESS(exp_count == NUM_ROWS, "exp_count != NUM_ROWS");
1114
rc= mysql_query(mysql, insert);
1115
check_mysql_rc(rc, mysql)
1116
FAIL_UNLESS(mysql_affected_rows(mysql) == 1, "affected_rows != 1");
1117
FAIL_UNLESS(exp_count == mysql_stmt_affected_rows(stmt), "affected_rows != exp_count");
1119
mysql_stmt_close(stmt);
1124
Test for bug#2248 "mysql_fetch without prior mysql_stmt_execute hangs"
1127
static int test_bug2248(MYSQL *mysql)
1131
const char *query1= "SELECT DATABASE()";
1132
const char *query2= "INSERT INTO test_bug2248 VALUES (10)";
1135
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_bug2248");
1136
check_mysql_rc(rc, mysql)
1138
rc= mysql_query(mysql, "CREATE TABLE test_bug2248 (id int)");
1139
check_mysql_rc(rc, mysql)
1141
stmt= mysql_stmt_init(mysql);
1142
FAIL_IF(!stmt, mysql_error(mysql));
1143
rc= mysql_stmt_prepare(stmt, query1, strlen(query1));
1144
check_stmt_rc(rc, stmt);
1146
/* This should not hang */
1147
rc= mysql_stmt_fetch(stmt);
1148
FAIL_IF(!rc, "Error expected");
1151
rc= mysql_stmt_store_result(stmt);
1152
FAIL_IF(!rc, "Error expected");
1154
mysql_stmt_close(stmt);
1156
stmt= mysql_stmt_init(mysql);
1157
FAIL_IF(!stmt, mysql_error(mysql));
1158
rc= mysql_stmt_prepare(stmt, query2, strlen(query2));
1159
check_stmt_rc(rc, stmt);
1161
rc= mysql_stmt_execute(stmt);
1162
check_stmt_rc(rc, stmt);
1163
/* This too should not hang but should return proper error */
1164
rc= mysql_stmt_fetch(stmt);
1165
FAIL_UNLESS(rc == 1, "rc != 1");
1167
/* This too should not hang but should not bark */
1168
rc= mysql_stmt_store_result(stmt);
1169
check_stmt_rc(rc, stmt);
1170
/* This should return proper error */
1171
rc= mysql_stmt_fetch(stmt);
1172
FAIL_UNLESS(rc == 1, "rc != 1");
1174
mysql_stmt_close(stmt);
1176
rc= mysql_query(mysql, "DROP TABLE test_bug2248");
1177
check_mysql_rc(rc, mysql)
1182
BUG#23383: mysql_affected_rows() returns different values than
1183
mysql_stmt_affected_rows()
1185
Test that both mysql_affected_rows() and mysql_stmt_affected_rows()
1186
return -1 on error, 0 when no rows were affected, and (positive) row
1187
count when some rows were affected.
1189
static int test_bug23383(MYSQL *mysql)
1191
const char *insert_query= "INSERT INTO t1 VALUES (1), (2)";
1192
const char *update_query= "UPDATE t1 SET i= 4 WHERE i = 3";
1194
my_ulonglong row_count;
1197
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
1198
check_mysql_rc(rc, mysql);
1200
rc= mysql_query(mysql, "CREATE TABLE t1 (i INT UNIQUE)");
1201
check_mysql_rc(rc, mysql);
1203
rc= mysql_query(mysql, insert_query);
1204
check_mysql_rc(rc, mysql);
1205
row_count= mysql_affected_rows(mysql);
1206
FAIL_UNLESS(row_count == 2, "row_count != 2");
1208
rc= mysql_query(mysql, insert_query);
1209
FAIL_IF(!rc, "Error expected");
1210
row_count= mysql_affected_rows(mysql);
1211
FAIL_UNLESS(row_count == (my_ulonglong)-1, "rowcount != -1");
1213
rc= mysql_query(mysql, update_query);
1214
check_mysql_rc(rc, mysql);
1215
row_count= mysql_affected_rows(mysql);
1216
FAIL_UNLESS(row_count == 0, "");
1218
rc= mysql_query(mysql, "DELETE FROM t1");
1219
check_mysql_rc(rc, mysql);
1221
stmt= mysql_stmt_init(mysql);
1222
FAIL_IF(!stmt, mysql_error(mysql));
1224
rc= mysql_stmt_prepare(stmt, insert_query, strlen(insert_query));
1225
check_stmt_rc(rc, stmt);
1226
rc= mysql_stmt_execute(stmt);
1227
check_stmt_rc(rc, stmt);
1228
row_count= mysql_stmt_affected_rows(stmt);
1229
FAIL_UNLESS(row_count == 2, "row_count != 2");
1231
rc= mysql_stmt_execute(stmt);
1232
FAIL_UNLESS(rc != 0, "");
1233
row_count= mysql_stmt_affected_rows(stmt);
1234
FAIL_UNLESS(row_count == (my_ulonglong)-1, "rowcount != -1");
1236
rc= mysql_stmt_prepare(stmt, update_query, strlen(update_query));
1237
check_stmt_rc(rc, stmt);
1238
rc= mysql_stmt_execute(stmt);
1239
check_stmt_rc(rc, stmt);
1240
row_count= mysql_stmt_affected_rows(stmt);
1241
FAIL_UNLESS(row_count == 0, "rowcount != 0");
1243
rc= mysql_stmt_close(stmt);
1244
check_stmt_rc(rc, stmt);
1245
rc= mysql_query(mysql, "DROP TABLE t1");
1246
check_mysql_rc(rc, mysql);
1252
Bug#27592 (stack overrun when storing datetime value using prepared statements)
1255
static int test_bug27592(MYSQL *mysql)
1257
const int NUM_ITERATIONS= 40;
1260
MYSQL_STMT *stmt= NULL;
1262
MYSQL_TIME time_val;
1264
mysql_query(mysql, "DROP TABLE IF EXISTS t1");
1265
mysql_query(mysql, "CREATE TABLE t1(c2 DATETIME)");
1267
stmt= mysql_stmt_init(mysql);
1268
FAIL_IF(!stmt, mysql_error(mysql));
1269
rc= mysql_stmt_prepare(stmt, "INSERT INTO t1 VALUES (?)", strlen("INSERT INTO t1 VALUES (?)"));
1270
check_stmt_rc(rc, stmt);
1272
memset(bind, '\0', sizeof(bind));
1274
bind[0].buffer_type= MYSQL_TYPE_DATETIME;
1275
bind[0].buffer= (char *) &time_val;
1276
bind[0].length= NULL;
1278
for (i= 0; i < NUM_ITERATIONS; i++)
1280
time_val.year= 2007;
1284
time_val.minute= 41;
1287
time_val.second_part=0;
1290
rc= mysql_stmt_bind_param(stmt, bind);
1291
check_stmt_rc(rc, stmt);
1292
rc= mysql_stmt_execute(stmt);
1293
check_stmt_rc(rc, stmt);
1296
mysql_stmt_close(stmt);
1302
Bug#28934: server crash when receiving malformed com_execute packets
1305
static int test_bug28934(MYSQL *mysql)
1312
rc= mysql_query(mysql, "drop table if exists t1");
1313
check_mysql_rc(rc, mysql);
1314
rc= mysql_query(mysql, "create table t1(id int)");
1315
check_mysql_rc(rc, mysql);
1317
rc= mysql_query(mysql, "insert into t1 values(1),(2),(3),(4),(5)");
1318
check_mysql_rc(rc, mysql);
1320
stmt= mysql_stmt_init(mysql);
1321
FAIL_IF(!stmt, mysql_error(mysql));
1322
rc= mysql_stmt_prepare(stmt, "select * from t1 where id in(?,?,?,?,?)", strlen("select * from t1 where id in(?,?,?,?,?)"));
1323
check_stmt_rc(rc, stmt);
1325
memset (&bind, '\0', sizeof (bind));
1326
for (cnt= 0; cnt < 5; cnt++)
1328
bind[cnt].buffer_type= MYSQL_TYPE_LONG;
1329
bind[cnt].buffer= (char*)&cnt;
1330
bind[cnt].buffer_length= 0;
1332
rc= mysql_stmt_bind_param(stmt, bind);
1333
check_stmt_rc(rc, stmt);
1335
stmt->param_count=2;
1336
error= mysql_stmt_execute(stmt);
1337
FAIL_UNLESS(error != 0, "Error expected");
1338
mysql_stmt_close(stmt);
1340
rc= mysql_query(mysql, "drop table t1");
1341
check_mysql_rc(rc, mysql);
1345
static int test_bug3035(MYSQL *mysql)
1349
MYSQL_BIND bind_array[12], *my_bind= bind_array, *bind_end= my_bind + 12;
1357
ulonglong uint64_val;
1358
double double_val, udouble_val, double_tmp;
1359
char longlong_as_string[22], ulonglong_as_string[22];
1361
/* mins and maxes */
1362
const int8 int8_min= -128;
1363
const int8 int8_max= 127;
1364
const uint8 uint8_min= 0;
1365
const uint8 uint8_max= 255;
1367
const int16 int16_min= -32768;
1368
const int16 int16_max= 32767;
1369
const uint16 uint16_min= 0;
1370
const uint16 uint16_max= 65535;
1372
const int32 int32_max= 2147483647L;
1373
const int32 int32_min= -int32_max - 1;
1374
const uint32 uint32_min= 0;
1375
const uint32 uint32_max= 4294967295U;
1377
/* it might not work okay everyplace */
1378
const longlong int64_max= 9223372036854775807LL;
1379
const longlong int64_min= -int64_max - 1;
1381
const ulonglong uint64_min= 0U;
1382
const ulonglong uint64_max= 18446744073709551615ULL;
1384
const char *stmt_text;
1387
stmt_text= "DROP TABLE IF EXISTS t1";
1388
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
1389
check_mysql_rc(rc, mysql);
1391
stmt_text= "CREATE TABLE t1 (i8 TINYINT, ui8 TINYINT UNSIGNED, "
1392
"i16 SMALLINT, ui16 SMALLINT UNSIGNED, "
1393
"i32 INT, ui32 INT UNSIGNED, "
1394
"i64 BIGINT, ui64 BIGINT UNSIGNED, "
1395
"id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT)";
1396
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
1397
check_mysql_rc(rc, mysql);
1399
memset(bind_array, '\0', sizeof(bind_array));
1400
for (my_bind= bind_array; my_bind < bind_end; my_bind++)
1401
my_bind->error= &my_bind->error_value;
1403
bind_array[0].buffer_type= MYSQL_TYPE_TINY;
1404
bind_array[0].buffer= (void *) &int8_val;
1406
bind_array[1].buffer_type= MYSQL_TYPE_TINY;
1407
bind_array[1].buffer= (void *) &uint8_val;
1408
bind_array[1].is_unsigned= 1;
1410
bind_array[2].buffer_type= MYSQL_TYPE_SHORT;
1411
bind_array[2].buffer= (void *) &int16_val;
1413
bind_array[3].buffer_type= MYSQL_TYPE_SHORT;
1414
bind_array[3].buffer= (void *) &uint16_val;
1415
bind_array[3].is_unsigned= 1;
1417
bind_array[4].buffer_type= MYSQL_TYPE_LONG;
1418
bind_array[4].buffer= (void *) &int32_val;
1420
bind_array[5].buffer_type= MYSQL_TYPE_LONG;
1421
bind_array[5].buffer= (void *) &uint32_val;
1422
bind_array[5].is_unsigned= 1;
1424
bind_array[6].buffer_type= MYSQL_TYPE_LONGLONG;
1425
bind_array[6].buffer= (void *) &int64_val;
1427
bind_array[7].buffer_type= MYSQL_TYPE_LONGLONG;
1428
bind_array[7].buffer= (void *) &uint64_val;
1429
bind_array[7].is_unsigned= 1;
1431
stmt= mysql_stmt_init(mysql);
1432
check_stmt_rc(rc, stmt);
1434
stmt_text= "INSERT INTO t1 (i8, ui8, i16, ui16, i32, ui32, i64, ui64) "
1435
"VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
1436
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
1437
check_stmt_rc(rc, stmt);
1438
mysql_stmt_bind_param(stmt, bind_array);
1441
uint8_val= uint8_min;
1442
int16_val= int16_min;
1443
uint16_val= uint16_min;
1444
int32_val= int32_min;
1445
uint32_val= uint32_min;
1446
int64_val= int64_min;
1447
uint64_val= uint64_min;
1449
rc= mysql_stmt_execute(stmt);
1450
check_stmt_rc(rc, stmt);
1452
uint8_val= uint8_max;
1453
int16_val= int16_max;
1454
uint16_val= uint16_max;
1455
int32_val= int32_max;
1456
uint32_val= uint32_max;
1457
int64_val= int64_max;
1458
uint64_val= uint64_max;
1460
rc= mysql_stmt_execute(stmt);
1461
check_stmt_rc(rc, stmt);
1462
stmt_text= "SELECT i8, ui8, i16, ui16, i32, ui32, i64, ui64, ui64, "
1463
"cast(ui64 as signed), ui64, cast(ui64 as signed)"
1464
"FROM t1 ORDER BY id ASC";
1466
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
1467
check_stmt_rc(rc, stmt);
1468
rc= mysql_stmt_execute(stmt);
1469
check_stmt_rc(rc, stmt);
1470
bind_array[8].buffer_type= MYSQL_TYPE_DOUBLE;
1471
bind_array[8].buffer= (void *) &udouble_val;
1473
bind_array[9].buffer_type= MYSQL_TYPE_DOUBLE;
1474
bind_array[9].buffer= (void *) &double_val;
1476
bind_array[10].buffer_type= MYSQL_TYPE_STRING;
1477
bind_array[10].buffer= (void *) &ulonglong_as_string;
1478
bind_array[10].buffer_length= sizeof(ulonglong_as_string);
1480
bind_array[11].buffer_type= MYSQL_TYPE_STRING;
1481
bind_array[11].buffer= (void *) &longlong_as_string;
1482
bind_array[11].buffer_length= sizeof(longlong_as_string);
1484
mysql_stmt_bind_result(stmt, bind_array);
1486
rc= mysql_stmt_fetch(stmt);
1487
check_stmt_rc(rc, stmt);
1488
FAIL_UNLESS(int8_val == int8_min, "int8_val != int8_min");
1489
FAIL_UNLESS(uint8_val == uint8_min, "uint8_val != uint8_min");
1490
FAIL_UNLESS(int16_val == int16_min, "int16_val != int16_min");
1491
FAIL_UNLESS(uint16_val == uint16_min, "uint16_val != uint16_min");
1492
FAIL_UNLESS(int32_val == int32_min, "int32_val != int32_min");
1493
FAIL_UNLESS(uint32_val == uint32_min, "uint32_val != uint32_min");
1494
FAIL_UNLESS(int64_val == int64_min, "int64_val != int64_min");
1495
FAIL_UNLESS(uint64_val == uint64_min, "uint64_val != uint64_min");
1496
FAIL_UNLESS(double_val == (longlong) uint64_min, "double_val != uint64_min");
1497
double_tmp= ulonglong2double(uint64_val);
1498
FAIL_UNLESS(cmp_double(&udouble_val,&double_tmp), "udouble_val != double_tmp");
1499
FAIL_UNLESS(!strcmp(longlong_as_string, "0"), "longlong_as_string != '0'");
1500
FAIL_UNLESS(!strcmp(ulonglong_as_string, "0"), "ulonglong_as_string != '0'");
1502
rc= mysql_stmt_fetch(stmt);
1504
FAIL_UNLESS(rc == MYSQL_DATA_TRUNCATED || rc == 0, "rc != 0,MYSQL_DATA_TRUNCATED");
1506
FAIL_UNLESS(int8_val == int8_max, "int8_val != int8_max");
1507
FAIL_UNLESS(uint8_val == uint8_max, "uint8_val != uint8_max");
1508
FAIL_UNLESS(int16_val == int16_max, "int16_val != int16_max");
1509
FAIL_UNLESS(uint16_val == uint16_max, "uint16_val != uint16_max");
1510
FAIL_UNLESS(int32_val == int32_max, "int32_val != int32_max");
1511
FAIL_UNLESS(uint32_val == uint32_max, "uint32_val != uint32_max");
1512
FAIL_UNLESS(int64_val == int64_max, "int64_val != int64_max");
1513
FAIL_UNLESS(uint64_val == uint64_max, "uint64_val != uint64_max");
1514
FAIL_UNLESS(double_val == (longlong) uint64_val, "double_val != uint64_val");
1515
double_tmp= ulonglong2double(uint64_val);
1516
FAIL_UNLESS(cmp_double(&udouble_val,&double_tmp), "udouble_val != double_tmp");
1517
FAIL_UNLESS(!strcmp(longlong_as_string, "-1"), "longlong_as_string != '-1'");
1518
FAIL_UNLESS(!strcmp(ulonglong_as_string, "18446744073709551615"), "ulonglong_as_string != '18446744073709551615'");
1520
rc= mysql_stmt_fetch(stmt);
1521
FAIL_UNLESS(rc == MYSQL_NO_DATA, "");
1523
mysql_stmt_close(stmt);
1525
stmt_text= "DROP TABLE t1";
1526
mysql_real_query(mysql, stmt_text, strlen(stmt_text));
1531
Test for BUG#3420 ("select id1, value1 from t where id= ? or value= ?"
1532
returns all rows in the table)
1535
static int test_ps_conj_select(MYSQL *mysql)
1539
MYSQL_BIND my_bind[2];
1542
unsigned long str_length;
1543
char query[MAX_TEST_QUERY_LENGTH];
1545
rc= mysql_query(mysql, "drop table if exists t1");
1546
check_mysql_rc(rc, mysql);
1548
rc= mysql_query(mysql, "create table t1 (id1 int(11) NOT NULL default '0', "
1549
"value2 varchar(100), value1 varchar(100))");
1550
check_mysql_rc(rc, mysql);
1552
rc= mysql_query(mysql, "insert into t1 values (1, 'hh', 'hh'), "
1553
"(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')");
1554
check_mysql_rc(rc, mysql);
1556
strcpy(query, "select id1, value1 from t1 where id1= ? or "
1557
"CONVERT(value1 USING utf8)= ?");
1558
stmt= mysql_stmt_init(mysql);
1559
FAIL_IF(!stmt, mysql_error(mysql));
1560
rc= mysql_stmt_prepare(stmt, query, strlen(query));
1561
check_stmt_rc(rc, stmt);
1563
FAIL_IF(mysql_stmt_param_count(stmt) != 2, "param_count != 2");
1565
/* Always bzero all members of bind parameter */
1566
memset(my_bind, '\0', sizeof(my_bind));
1567
my_bind[0].buffer_type= MYSQL_TYPE_LONG;
1568
my_bind[0].buffer= (void *)&int_data;
1570
my_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
1571
my_bind[1].buffer= (void *)str_data;
1572
my_bind[1].buffer_length= array_elements(str_data);
1573
my_bind[1].length= &str_length;
1575
rc= mysql_stmt_bind_param(stmt, my_bind);
1576
check_stmt_rc(rc, stmt);
1578
strcpy(str_data, "hh");
1579
str_length= strlen(str_data);
1581
rc= mysql_stmt_execute(stmt);
1582
check_stmt_rc(rc, stmt);
1585
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
1587
FAIL_UNLESS(rc == 3, "rc != 3");
1589
mysql_stmt_close(stmt);
1593
/* Test for NULL as PS parameter (BUG#3367, BUG#3371) */
1595
static int test_ps_null_param(MYSQL *mysql)
1604
MYSQL_BIND out_bind;
1606
my_bool out_is_null;
1607
char out_str_data[20];
1609
const char *queries[]= {"select ?", "select ?+1",
1610
"select col1 from test_ps_nulls where col1 <=> ?",
1613
const char **cur_query= queries;
1616
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_ps_nulls");
1617
check_mysql_rc(rc, mysql);
1619
rc= mysql_query(mysql, "CREATE TABLE test_ps_nulls(col1 int)");
1620
check_mysql_rc(rc, mysql);
1622
rc= mysql_query(mysql, "INSERT INTO test_ps_nulls values (1), (null)");
1623
check_mysql_rc(rc, mysql);
1625
/* Always bzero all members of bind parameter */
1626
memset(&in_bind, '\0', sizeof(in_bind));
1627
memset(&out_bind, '\0', sizeof(out_bind));
1628
in_bind.buffer_type= MYSQL_TYPE_LONG;
1629
in_bind.is_null= &in_is_null;
1631
in_bind.buffer= (void *)&in_long;
1635
out_bind.buffer_type= MYSQL_TYPE_STRING;
1636
out_bind.is_null= &out_is_null;
1637
out_bind.length= &out_length;
1638
out_bind.buffer= out_str_data;
1639
out_bind.buffer_length= array_elements(out_str_data);
1641
/* Execute several queries, all returning NULL in result. */
1642
for(cur_query= queries; *cur_query; cur_query++)
1644
char query[MAX_TEST_QUERY_LENGTH];
1645
strcpy(query, *cur_query);
1646
stmt= mysql_stmt_init(mysql);
1647
FAIL_IF(!stmt, mysql_error(mysql));
1648
rc= mysql_stmt_prepare(stmt, query, strlen(query));
1649
check_stmt_rc(rc, stmt);
1650
FAIL_IF(mysql_stmt_param_count(stmt) != 1, "param_count != 1");
1652
rc= mysql_stmt_bind_param(stmt, &in_bind);
1653
check_stmt_rc(rc, stmt);
1654
rc= mysql_stmt_bind_result(stmt, &out_bind);
1655
check_stmt_rc(rc, stmt);
1656
rc= mysql_stmt_execute(stmt);
1657
check_stmt_rc(rc, stmt);
1658
rc= mysql_stmt_fetch(stmt);
1659
FAIL_UNLESS(rc != MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
1660
FAIL_UNLESS(out_is_null, "!out_is_null");
1661
rc= mysql_stmt_fetch(stmt);
1662
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
1663
mysql_stmt_close(stmt);
1669
utility for the next test; expects 3 rows in the result from a SELECT,
1670
compares each row/field with an expected value.
1672
#define test_ps_query_cache_result(i1,s1,l1,i2,s2,l2,i3,s3,l3) \
1673
r_metadata= mysql_stmt_result_metadata(stmt); \
1674
FAIL_UNLESS(r_metadata != NULL, ""); \
1675
rc= mysql_stmt_fetch(stmt); \
1676
check_stmt_rc(rc,stmt); \
1677
FAIL_UNLESS((r_int_data == i1) && (r_str_length == l1) && \
1678
(strcmp(r_str_data, s1) == 0), "test_ps_query_cache_result failure"); \
1679
rc= mysql_stmt_fetch(stmt); \
1680
check_stmt_rc(rc,stmt); \
1681
FAIL_UNLESS((r_int_data == i2) && (r_str_length == l2) && \
1682
(strcmp(r_str_data, s2) == 0), "test_ps_query_cache_result failure"); \
1683
rc= mysql_stmt_fetch(stmt); \
1684
check_stmt_rc(rc,stmt); \
1685
FAIL_UNLESS((r_int_data == i3) && (r_str_length == l3) && \
1686
(strcmp(r_str_data, s3) == 0), "test_ps_query_cache_result failure"); \
1687
rc= mysql_stmt_fetch(stmt); \
1688
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA"); \
1689
mysql_free_result(r_metadata);
1691
/* reads Qcache_hits from server and returns its value */
1692
static int query_cache_hits(MYSQL *mysql)
1699
rc= mysql_query(mysql, "show status like 'qcache_hits'");
1700
check_mysql_rc(rc, mysql);
1701
res= mysql_use_result(mysql);
1703
row= mysql_fetch_row(res);
1705
result= atoi(row[1]);
1706
mysql_free_result(res);
1712
Test that prepared statements make use of the query cache just as normal
1713
statements (BUG#735).
1715
static int test_ps_query_cache(MYSQL *mysql)
1717
MYSQL *lmysql= mysql;
1720
MYSQL_BIND p_bind[2],r_bind[2]; /* p: param bind; r: result bind */
1721
int32 p_int_data, r_int_data;
1722
char p_str_data[32], r_str_data[32];
1723
unsigned long p_str_length, r_str_length;
1724
MYSQL_RES *r_metadata;
1725
char query[MAX_TEST_QUERY_LENGTH];
1727
enum enum_test_ps_query_cache
1730
We iterate the same prepare/executes block, but have iterations where
1731
we vary the query cache conditions.
1733
/* the query cache is enabled for the duration of prep&execs: */
1736
same but using a new connection (to see if qcache serves results from
1737
the previous connection as it should):
1739
TEST_QCACHE_ON_WITH_OTHER_CONN,
1741
First border case: disables the query cache before prepare and
1742
re-enables it before execution (to test if we have no bug then):
1746
Second border case: enables the query cache before prepare and
1747
disables it before execution:
1751
enum enum_test_ps_query_cache iteration;
1754
/* prepare the table */
1756
rc= mysql_query(mysql, "drop table if exists t1");
1757
check_mysql_rc(rc, mysql);
1759
rc= mysql_query(mysql, "create table t1 (id1 int(11) NOT NULL default '0', "
1760
"value2 varchar(100), value1 varchar(100))");
1761
check_mysql_rc(rc, mysql);
1763
rc= mysql_query(mysql, "insert into t1 values (1, 'hh', 'hh'), "
1764
"(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')");
1765
check_mysql_rc(rc, mysql);
1767
for (iteration= TEST_QCACHE_ON; iteration <= TEST_QCACHE_ON_OFF; iteration++)
1769
switch (iteration) {
1770
case TEST_QCACHE_ON:
1771
case TEST_QCACHE_ON_OFF:
1772
rc= mysql_query(lmysql, "set global query_cache_size=1000000");
1773
check_mysql_rc(rc, mysql);
1775
case TEST_QCACHE_OFF_ON:
1776
rc= mysql_query(lmysql, "set global query_cache_size=0");
1777
check_mysql_rc(rc, mysql);
1779
case TEST_QCACHE_ON_WITH_OTHER_CONN:
1780
lmysql= test_connect(NULL);
1781
FAIL_IF(!lmysql, "Opening new connection failed");
1785
strcpy(query, "select id1, value1 from t1 where id1= ? or "
1786
"CONVERT(value1 USING utf8)= ?");
1787
stmt= mysql_stmt_init(lmysql);
1788
FAIL_IF(!stmt, mysql_error(lmysql));
1789
rc= mysql_stmt_prepare(stmt, query, strlen(query));
1790
check_stmt_rc(rc, stmt);
1792
FAIL_IF(mysql_stmt_param_count(stmt) != 2, "param_count != 2");
1794
switch (iteration) {
1795
case TEST_QCACHE_OFF_ON:
1796
rc= mysql_query(lmysql, "set global query_cache_size=1000000");
1797
check_mysql_rc(rc, mysql);
1799
case TEST_QCACHE_ON_OFF:
1800
rc= mysql_query(lmysql, "set global query_cache_size=0");
1801
check_mysql_rc(rc, mysql);
1806
memset(p_bind, '\0', sizeof(p_bind));
1807
p_bind[0].buffer_type= MYSQL_TYPE_LONG;
1808
p_bind[0].buffer= (void *)&p_int_data;
1809
p_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
1810
p_bind[1].buffer= (void *)p_str_data;
1811
p_bind[1].buffer_length= array_elements(p_str_data);
1812
p_bind[1].length= &p_str_length;
1814
rc= mysql_stmt_bind_param(stmt, p_bind);
1815
check_stmt_rc(rc, stmt);
1817
strcpy(p_str_data, "hh");
1818
p_str_length= strlen(p_str_data);
1820
memset(r_bind, '\0', sizeof(r_bind));
1821
r_bind[0].buffer_type= MYSQL_TYPE_LONG;
1822
r_bind[0].buffer= (void *)&r_int_data;
1823
r_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
1824
r_bind[1].buffer= (void *)r_str_data;
1825
r_bind[1].buffer_length= array_elements(r_str_data);
1826
r_bind[1].length= &r_str_length;
1828
rc= mysql_stmt_bind_result(stmt, r_bind);
1829
check_stmt_rc(rc, stmt);
1830
rc= mysql_stmt_execute(stmt);
1831
check_stmt_rc(rc, stmt);
1832
// test_ps_query_cache_result(1, "hh", 2, 2, "hh", 2, 1, "ii", 2);
1833
r_metadata= mysql_stmt_result_metadata(stmt);
1834
FAIL_UNLESS(r_metadata != NULL, "");
1835
rc= mysql_stmt_fetch(stmt);
1836
check_stmt_rc(rc,stmt);
1837
FAIL_UNLESS((r_int_data == 1) && (r_str_length == 2) &&
1838
(strcmp(r_str_data, "hh") == 0), "test_ps_query_cache_result failure"); \
1839
rc= mysql_stmt_fetch(stmt);
1840
check_stmt_rc(rc,stmt);
1841
FAIL_UNLESS((r_int_data == 2) && (r_str_length == 2) &&
1842
(strcmp(r_str_data, "hh") == 0), "test_ps_query_cache_result failure"); \
1843
rc= mysql_stmt_fetch(stmt);
1844
check_stmt_rc(rc,stmt);
1845
FAIL_UNLESS((r_int_data == 1) && (r_str_length == 2) &&
1846
(strcmp(r_str_data, "ii") == 0), "test_ps_query_cache_result failure"); \
1847
rc= mysql_stmt_fetch(stmt);
1848
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
1849
mysql_free_result(r_metadata);
1852
/* now retry with the same parameter values and see qcache hits */
1853
hits1= query_cache_hits(lmysql);
1854
rc= mysql_stmt_execute(stmt);
1855
check_stmt_rc(rc, stmt); test_ps_query_cache_result(1, "hh", 2, 2, "hh", 2, 1, "ii", 2);
1856
hits2= query_cache_hits(lmysql);
1858
case TEST_QCACHE_ON_WITH_OTHER_CONN:
1859
case TEST_QCACHE_ON: /* should have hit */
1860
FAIL_UNLESS(hits2-hits1 == 1, "hits2 != hits1 + 1");
1862
case TEST_QCACHE_OFF_ON:
1863
case TEST_QCACHE_ON_OFF: /* should not have hit */
1864
FAIL_UNLESS(hits2-hits1 == 0, "hits2 != hits1");
1868
/* now modify parameter values and see qcache hits */
1869
strcpy(p_str_data, "ii");
1870
p_str_length= strlen(p_str_data);
1871
rc= mysql_stmt_execute(stmt);
1872
check_stmt_rc(rc, stmt);
1873
test_ps_query_cache_result(1, "hh", 2, 1, "ii", 2, 2, "ii", 2);
1874
hits1= query_cache_hits(lmysql);
1877
case TEST_QCACHE_ON:
1878
case TEST_QCACHE_OFF_ON:
1879
case TEST_QCACHE_ON_OFF: /* should not have hit */
1880
FAIL_UNLESS(hits2-hits1 == 0, "hits2 != hits1");
1882
case TEST_QCACHE_ON_WITH_OTHER_CONN: /* should have hit */
1883
FAIL_UNLESS(hits1-hits2 == 1, "hits2 != hits1+1");
1887
rc= mysql_stmt_execute(stmt);
1888
check_stmt_rc(rc, stmt);
1889
test_ps_query_cache_result(1, "hh", 2, 1, "ii", 2, 2, "ii", 2);
1890
hits2= query_cache_hits(lmysql);
1892
mysql_stmt_close(stmt);
1895
case TEST_QCACHE_ON: /* should have hit */
1896
FAIL_UNLESS(hits2-hits1 == 1, "hits2 != hits1+1");
1898
case TEST_QCACHE_OFF_ON:
1899
case TEST_QCACHE_ON_OFF: /* should not have hit */
1900
FAIL_UNLESS(hits2-hits1 == 0, "hits2 != hits1");
1902
case TEST_QCACHE_ON_WITH_OTHER_CONN: /* should have hit */
1903
FAIL_UNLESS(hits2-hits1 == 1, "hits2 != hits1+1");
1907
} /* for(iteration=...) */
1909
if (lmysql != mysql)
1910
mysql_close(lmysql);
1912
rc= mysql_query(mysql, "set global query_cache_size=0");
1913
check_mysql_rc(rc, mysql);
1917
static int test_bug3117(MYSQL *mysql)
1926
rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
1927
check_mysql_rc(rc, mysql);
1929
rc= mysql_query(mysql, "CREATE TABLE t1 (id int auto_increment primary key)");
1930
check_mysql_rc(rc, mysql);
1932
stmt= mysql_stmt_init(mysql);
1933
FAIL_IF(!stmt, mysql_error(mysql));
1934
rc= mysql_stmt_prepare(stmt, "SELECT LAST_INSERT_ID()", strlen("SELECT LAST_INSERT_ID()"));
1935
check_stmt_rc(rc, stmt);
1937
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (NULL)");
1938
check_mysql_rc(rc, mysql);
1940
rc= mysql_stmt_execute(stmt);
1941
check_stmt_rc(rc, stmt);
1942
memset(&buffer, '\0', sizeof(buffer));
1943
buffer.buffer_type= MYSQL_TYPE_LONGLONG;
1944
buffer.buffer_length= sizeof(lii);
1945
buffer.buffer= (void *)&lii;
1946
buffer.length= &length;
1947
buffer.is_null= &is_null;
1949
rc= mysql_stmt_bind_result(stmt, &buffer);
1950
check_stmt_rc(rc, stmt);
1951
rc= mysql_stmt_store_result(stmt);
1952
check_stmt_rc(rc, stmt);
1953
rc= mysql_stmt_fetch(stmt);
1954
check_stmt_rc(rc, stmt);
1955
FAIL_UNLESS(is_null == 0 && lii == 1, "is_null != 0 || lii != 1");
1957
rc= mysql_query(mysql, "INSERT INTO t1 VALUES (NULL)");
1958
check_mysql_rc(rc, mysql);
1960
rc= mysql_stmt_execute(stmt);
1961
check_stmt_rc(rc, stmt);
1962
rc= mysql_stmt_fetch(stmt);
1963
check_stmt_rc(rc, stmt);
1964
FAIL_UNLESS(is_null == 0 && lii == 2, "is_null != 0 || lii != 2");
1966
mysql_stmt_close(stmt);
1968
rc= mysql_query(mysql, "DROP TABLE t1");
1969
check_mysql_rc(rc, mysql);
1974
Bug#36004 mysql_stmt_prepare resets the list of warnings
1977
static int test_bug36004(MYSQL *mysql)
1979
int rc, warning_count= 0;
1983
if (mysql_get_server_version(mysql) < 60000) {
1984
diag("Test requires MySQL Server version 6.0 or above");
1988
rc= mysql_query(mysql, "drop table if exists inexistant");
1989
check_mysql_rc(rc, mysql);
1991
FAIL_UNLESS(mysql_warning_count(mysql) == 1, "");
1992
query_int_variable(mysql, "@@warning_count", &warning_count);
1993
FAIL_UNLESS(warning_count, "Warning expected");
1995
stmt= mysql_stmt_init(mysql);
1996
FAIL_IF(!stmt, mysql_error(mysql));
1997
rc= mysql_stmt_prepare(stmt, "select 1", strlen("select 1"));
1998
check_stmt_rc(rc, stmt);
2000
FAIL_UNLESS(mysql_warning_count(mysql) == 0, "No warning expected");
2001
query_int_variable(mysql, "@@warning_count", &warning_count);
2002
FAIL_UNLESS(warning_count, "warning expected");
2004
rc= mysql_stmt_execute(stmt);
2005
check_stmt_rc(rc, stmt);
2006
FAIL_UNLESS(mysql_warning_count(mysql) == 0, "No warning expected");
2007
mysql_stmt_close(stmt);
2009
query_int_variable(mysql, "@@warning_count", &warning_count);
2010
FAIL_UNLESS(warning_count, "Warning expected");
2012
stmt= mysql_stmt_init(mysql);
2013
FAIL_IF(!stmt, mysql_error(mysql));
2014
rc= mysql_stmt_prepare(stmt, "drop table if exists inexistant", strlen("drop table if exists inexistant"));
2015
check_stmt_rc(rc, stmt);
2017
query_int_variable(mysql, "@@warning_count", &warning_count);
2018
FAIL_UNLESS(warning_count == 0, "No warning expected");
2019
mysql_stmt_close(stmt);
2024
static int test_bug3796(MYSQL *mysql)
2027
MYSQL_BIND my_bind[1];
2028
const char *concat_arg0= "concat_with_";
2029
enum { OUT_BUFF_SIZE= 30 };
2030
char out_buff[OUT_BUFF_SIZE];
2031
char canonical_buff[OUT_BUFF_SIZE];
2033
const char *stmt_text;
2037
/* Create and fill test table */
2038
stmt_text= "DROP TABLE IF EXISTS t1";
2039
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2040
check_mysql_rc(rc, mysql);
2042
stmt_text= "CREATE TABLE t1 (a INT, b VARCHAR(30))";
2043
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2044
check_mysql_rc(rc, mysql);
2046
stmt_text= "INSERT INTO t1 VALUES(1, 'ONE'), (2, 'TWO')";
2047
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2048
check_mysql_rc(rc, mysql);
2050
/* Create statement handle and prepare it with select */
2051
stmt= mysql_stmt_init(mysql);
2052
stmt_text= "SELECT concat(?, b) FROM t1";
2054
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2055
check_stmt_rc(rc, stmt);
2056
/* Bind input buffers */
2057
memset(my_bind, '\0', sizeof(my_bind));
2058
my_bind[0].buffer_type= MYSQL_TYPE_STRING;
2059
my_bind[0].buffer= (void *) concat_arg0;
2060
my_bind[0].buffer_length= strlen(concat_arg0);
2062
mysql_stmt_bind_param(stmt, my_bind);
2064
/* Execute the select statement */
2065
rc= mysql_stmt_execute(stmt);
2066
check_stmt_rc(rc, stmt);
2067
my_bind[0].buffer= (void *) out_buff;
2068
my_bind[0].buffer_length= OUT_BUFF_SIZE;
2069
my_bind[0].length= &out_length;
2071
mysql_stmt_bind_result(stmt, my_bind);
2073
rc= mysql_stmt_fetch(stmt);
2074
check_stmt_rc(rc, stmt);
2075
strcpy(canonical_buff, concat_arg0);
2076
strcat(canonical_buff, "ONE");
2077
FAIL_UNLESS(strlen(canonical_buff) == out_length &&
2078
strncmp(out_buff, canonical_buff, out_length) == 0, "");
2080
rc= mysql_stmt_fetch(stmt);
2081
check_stmt_rc(rc, stmt);
2082
strcpy(canonical_buff + strlen(concat_arg0), "TWO");
2083
FAIL_UNLESS(strlen(canonical_buff) == out_length &&
2084
strncmp(out_buff, canonical_buff, out_length) == 0, "");
2086
rc= mysql_stmt_fetch(stmt);
2087
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
2089
mysql_stmt_close(stmt);
2091
stmt_text= "DROP TABLE IF EXISTS t1";
2092
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2093
check_mysql_rc(rc, mysql);
2097
static int test_bug4026(MYSQL *mysql)
2100
MYSQL_BIND my_bind[2];
2101
MYSQL_TIME time_in, time_out;
2102
MYSQL_TIME datetime_in, datetime_out;
2103
const char *stmt_text;
2107
/* Check that microseconds are inserted and selected successfully */
2109
/* Create a statement handle and prepare it with select */
2110
stmt= mysql_stmt_init(mysql);
2111
stmt_text= "SELECT ?, ?";
2113
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2114
check_stmt_rc(rc, stmt);
2115
/* Bind input buffers */
2116
memset(my_bind, '\0', sizeof(my_bind));
2117
memset(&time_in, '\0', sizeof(time_in));
2118
memset(&time_out, '\0', sizeof(time_out));
2119
memset(&datetime_in, '\0', sizeof(datetime_in));
2120
memset(&datetime_out, '\0', sizeof(datetime_out));
2121
my_bind[0].buffer_type= MYSQL_TYPE_TIME;
2122
my_bind[0].buffer= (void *) &time_in;
2123
my_bind[1].buffer_type= MYSQL_TYPE_DATETIME;
2124
my_bind[1].buffer= (void *) &datetime_in;
2129
time_in.second_part= 123456;
2131
This is not necessary, just to make DIE_UNLESS below work: this field
2132
is filled in when time is received from server
2134
time_in.time_type= MYSQL_TIMESTAMP_TIME;
2136
datetime_in= time_in;
2137
datetime_in.year= 2003;
2138
datetime_in.month= 12;
2139
datetime_in.day= 31;
2140
datetime_in.time_type= MYSQL_TIMESTAMP_DATETIME;
2142
mysql_stmt_bind_param(stmt, my_bind);
2144
/* Execute the select statement */
2145
rc= mysql_stmt_execute(stmt);
2146
check_stmt_rc(rc, stmt);
2147
my_bind[0].buffer= (void *) &time_out;
2148
my_bind[1].buffer= (void *) &datetime_out;
2150
mysql_stmt_bind_result(stmt, my_bind);
2152
rc= mysql_stmt_fetch(stmt);
2153
FAIL_UNLESS(rc == 0, "rc != 0");
2154
FAIL_UNLESS(memcmp(&time_in, &time_out, sizeof(time_in)) == 0, "time_in != time_out");
2155
FAIL_UNLESS(memcmp(&datetime_in, &datetime_out, sizeof(datetime_in)) == 0, "datetime_in != datetime_out");
2156
mysql_stmt_close(stmt);
2161
static int test_bug4030(MYSQL *mysql)
2164
MYSQL_BIND my_bind[3];
2165
MYSQL_TIME time_canonical, time_out;
2166
MYSQL_TIME date_canonical, date_out;
2167
MYSQL_TIME datetime_canonical, datetime_out;
2168
const char *stmt_text;
2172
/* Check that microseconds are inserted and selected successfully */
2174
/* Execute a query with time values in prepared mode */
2175
stmt= mysql_stmt_init(mysql);
2176
stmt_text= "SELECT '23:59:59.123456', '2003-12-31', "
2177
"'2003-12-31 23:59:59.123456'";
2178
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2179
check_stmt_rc(rc, stmt);
2180
rc= mysql_stmt_execute(stmt);
2181
check_stmt_rc(rc, stmt);
2182
/* Bind output buffers */
2183
memset(my_bind, '\0', sizeof(my_bind));
2184
memset(&time_canonical, '\0', sizeof(time_canonical));
2185
memset(&time_out, '\0', sizeof(time_out));
2186
memset(&date_canonical, '\0', sizeof(date_canonical));
2187
memset(&date_out, '\0', sizeof(date_out));
2188
memset(&datetime_canonical, '\0', sizeof(datetime_canonical));
2189
memset(&datetime_out, '\0', sizeof(datetime_out));
2190
my_bind[0].buffer_type= MYSQL_TYPE_TIME;
2191
my_bind[0].buffer= (void *) &time_out;
2192
my_bind[1].buffer_type= MYSQL_TYPE_DATE;
2193
my_bind[1].buffer= (void *) &date_out;
2194
my_bind[2].buffer_type= MYSQL_TYPE_DATETIME;
2195
my_bind[2].buffer= (void *) &datetime_out;
2197
time_canonical.hour= 23;
2198
time_canonical.minute= 59;
2199
time_canonical.second= 59;
2200
time_canonical.second_part= 123456;
2201
time_canonical.time_type= MYSQL_TIMESTAMP_TIME;
2203
date_canonical.year= 2003;
2204
date_canonical.month= 12;
2205
date_canonical.day= 31;
2206
date_canonical.time_type= MYSQL_TIMESTAMP_DATE;
2208
datetime_canonical= time_canonical;
2209
datetime_canonical.year= 2003;
2210
datetime_canonical.month= 12;
2211
datetime_canonical.day= 31;
2212
datetime_canonical.time_type= MYSQL_TIMESTAMP_DATETIME;
2214
mysql_stmt_bind_result(stmt, my_bind);
2216
rc= mysql_stmt_fetch(stmt);
2217
FAIL_UNLESS(rc == 0, "rc != 0");
2218
FAIL_UNLESS(memcmp(&time_canonical, &time_out, sizeof(time_out)) == 0, "time_canonical != time_out");
2219
FAIL_UNLESS(memcmp(&date_canonical, &date_out, sizeof(date_out)) == 0, "date_canoncical != date_out");
2220
FAIL_UNLESS(memcmp(&datetime_canonical, &datetime_out, sizeof(datetime_out)) == 0, "datetime_canonical != datetime_out");
2221
mysql_stmt_close(stmt);
2225
static int test_bug4079(MYSQL *mysql)
2228
MYSQL_BIND my_bind[1];
2229
const char *stmt_text;
2233
/* Create and fill table */
2234
mysql_query(mysql, "DROP TABLE IF EXISTS t1");
2235
mysql_query(mysql, "CREATE TABLE t1 (a int)");
2236
mysql_query(mysql, "INSERT INTO t1 VALUES (1), (2)");
2238
/* Prepare erroneous statement */
2239
stmt= mysql_stmt_init(mysql);
2240
stmt_text= "SELECT 1 < (SELECT a FROM t1)";
2242
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2243
check_stmt_rc(rc, stmt);
2244
/* Execute the select statement */
2245
rc= mysql_stmt_execute(stmt);
2246
check_stmt_rc(rc, stmt);
2247
/* Bind input buffers */
2248
memset(my_bind, '\0', sizeof(my_bind));
2249
my_bind[0].buffer_type= MYSQL_TYPE_LONG;
2250
my_bind[0].buffer= (void *) &res;
2252
mysql_stmt_bind_result(stmt, my_bind);
2254
rc= mysql_stmt_fetch(stmt);
2255
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
2256
/* buggy version of libmysql hanged up here */
2257
mysql_stmt_close(stmt);
2261
static int test_bug4172(MYSQL *mysql)
2264
MYSQL_BIND my_bind[3];
2265
const char *stmt_text;
2269
char f[100], d[100], e[100];
2270
ulong f_len, d_len, e_len;
2273
mysql_query(mysql, "DROP TABLE IF EXISTS t1");
2274
mysql_query(mysql, "CREATE TABLE t1 (f float, d double, e decimal(10,4))");
2275
mysql_query(mysql, "INSERT INTO t1 VALUES (12345.1234, 123456.123456, "
2278
stmt= mysql_stmt_init(mysql);
2279
stmt_text= "SELECT f, d, e FROM t1";
2281
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2282
check_stmt_rc(rc, stmt); rc= mysql_stmt_execute(stmt);
2283
check_stmt_rc(rc, stmt);
2284
memset(my_bind, '\0', sizeof(my_bind)); my_bind[0].buffer_type= MYSQL_TYPE_STRING;
2285
my_bind[0].buffer= f;
2286
my_bind[0].buffer_length= sizeof(f);
2287
my_bind[0].length= &f_len;
2288
my_bind[1].buffer_type= MYSQL_TYPE_STRING;
2289
my_bind[1].buffer= d;
2290
my_bind[1].buffer_length= sizeof(d);
2291
my_bind[1].length= &d_len;
2292
my_bind[2].buffer_type= MYSQL_TYPE_STRING;
2293
my_bind[2].buffer= e;
2294
my_bind[2].buffer_length= sizeof(e);
2295
my_bind[2].length= &e_len;
2297
mysql_stmt_bind_result(stmt, my_bind);
2299
mysql_stmt_store_result(stmt);
2300
rc= mysql_stmt_fetch(stmt);
2301
check_stmt_rc(rc, stmt);
2302
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2303
check_mysql_rc(rc, mysql);
2304
res= mysql_store_result(mysql);
2305
row= mysql_fetch_row(res);
2307
diag("expected %s %s %s", row[0], row[1], row[2]);
2308
FAIL_UNLESS(!strcmp(f, row[0]) && !strcmp(d, row[1]) && !strcmp(e, row[2]), "");
2310
mysql_free_result(res);
2311
mysql_stmt_close(stmt);
2315
static int test_bug4231(MYSQL *mysql)
2318
MYSQL_BIND my_bind[2];
2320
const char *stmt_text;
2324
stmt_text= "DROP TABLE IF EXISTS t1";
2325
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2326
check_mysql_rc(rc, mysql);
2328
stmt_text= "CREATE TABLE t1 (a int)";
2329
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2330
check_mysql_rc(rc, mysql);
2332
stmt_text= "INSERT INTO t1 VALUES (1)";
2333
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2334
check_mysql_rc(rc, mysql);
2336
stmt= mysql_stmt_init(mysql);
2337
stmt_text= "SELECT a FROM t1 WHERE ? = ?";
2338
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2339
check_stmt_rc(rc, stmt);
2340
/* Bind input buffers */
2341
memset(my_bind, '\0', sizeof(my_bind)); memset(tm, '\0', sizeof(tm));
2342
my_bind[0].buffer_type= MYSQL_TYPE_DATE;
2343
my_bind[0].buffer= &tm[0];
2344
my_bind[1].buffer_type= MYSQL_TYPE_DATE;
2345
my_bind[1].buffer= &tm[1];
2347
mysql_stmt_bind_param(stmt, my_bind);
2348
check_stmt_rc(rc, stmt);
2350
First set server-side params to some non-zero non-equal values:
2351
then we will check that they are not used when client sends
2354
tm[0].time_type = MYSQL_TIMESTAMP_DATE;
2359
--tm[1].year; /* tm[0] != tm[1] */
2361
rc= mysql_stmt_execute(stmt);
2362
check_stmt_rc(rc, stmt);
2363
rc= mysql_stmt_fetch(stmt);
2365
/* binds are unequal, no rows should be returned */
2366
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
2368
/* Set one of the dates to zero */
2369
tm[0].year= tm[0].month= tm[0].day= 0;
2371
mysql_stmt_execute(stmt);
2372
rc= mysql_stmt_fetch(stmt);
2373
FAIL_UNLESS(rc == 0, "rc != 0");
2375
mysql_stmt_close(stmt);
2376
stmt_text= "DROP TABLE t1";
2377
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2378
check_mysql_rc(rc, mysql);
2382
static int test_bug4236(MYSQL *mysql)
2384
MYSQL_STMT *stmt, *stmt1;
2385
const char *stmt_text;
2391
stmt= mysql_stmt_init(mysql);
2393
/* mysql_stmt_execute() of statement with statement id= 0 crashed server */
2394
stmt_text= "SELECT 1";
2395
/* We need to prepare statement to pass by possible check in libmysql */
2396
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2397
check_stmt_rc(rc, stmt); /* Hack to check that server works OK if statement wasn't found */
2398
backup.stmt_id= stmt->stmt_id;
2400
rc= mysql_stmt_execute(stmt);
2401
FAIL_IF(!rc, "Error expected");
2403
/* lets try to hack with a new connection */
2404
mysql1= test_connect(NULL);
2405
stmt1= mysql_stmt_init(mysql1);
2406
stmt_text= "SELECT 2";
2407
rc= mysql_stmt_prepare(stmt1, stmt_text, strlen(stmt_text));
2408
check_stmt_rc(rc, stmt);
2410
stmt->stmt_id= stmt1->stmt_id;
2411
rc= mysql_stmt_execute(stmt);
2412
FAIL_IF(!rc, "Error expected");
2414
mysql_stmt_close(stmt1);
2415
mysql_close(mysql1);
2417
/* Restore original statement id to be able to reprepare it */
2418
stmt->stmt_id= backup.stmt_id;
2420
mysql_stmt_close(stmt);
2424
static int test_bug5126(MYSQL *mysql)
2427
MYSQL_BIND my_bind[2];
2429
const char *stmt_text;
2433
stmt_text= "DROP TABLE IF EXISTS t1";
2434
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2435
check_mysql_rc(rc, mysql);
2437
stmt_text= "CREATE TABLE t1 (a mediumint, b int)";
2438
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2439
check_mysql_rc(rc, mysql);
2441
stmt_text= "INSERT INTO t1 VALUES (8386608, 1)";
2442
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2443
check_mysql_rc(rc, mysql);
2445
stmt= mysql_stmt_init(mysql);
2446
stmt_text= "SELECT a, b FROM t1";
2447
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2448
check_stmt_rc(rc, stmt);
2449
rc= mysql_stmt_execute(stmt);
2450
check_stmt_rc(rc, stmt);
2451
/* Bind output buffers */
2452
memset(my_bind, '\0', sizeof(my_bind));
2453
my_bind[0].buffer_type= MYSQL_TYPE_LONG;
2454
my_bind[0].buffer= &c1;
2455
my_bind[1].buffer_type= MYSQL_TYPE_LONG;
2456
my_bind[1].buffer= &c2;
2458
mysql_stmt_bind_result(stmt, my_bind);
2460
rc= mysql_stmt_fetch(stmt);
2461
FAIL_UNLESS(rc == 0, "rc != 0");
2462
FAIL_UNLESS(c1 == 8386608 && c2 == 1, "c1 != 8386608 || c2 != 1");
2463
mysql_stmt_close(stmt);
2467
static int test_bug5194(MYSQL *mysql)
2470
MYSQL_BIND *my_bind;
2473
int param_str_length;
2474
const char *stmt_text;
2476
float float_array[250] =
2478
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2479
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2480
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2481
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2482
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2483
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2484
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2485
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2486
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2487
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2488
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2489
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2490
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
2491
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
2492
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
2493
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
2494
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
2495
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
2496
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
2497
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
2498
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
2499
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
2500
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
2501
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
2502
0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25
2504
float *fa_ptr= float_array;
2505
/* Number of columns per row */
2506
const int COLUMN_COUNT= sizeof(float_array)/sizeof(*float_array);
2507
/* Number of rows per bulk insert to start with */
2508
const int MIN_ROWS_PER_INSERT= 262;
2509
/* Max number of rows per bulk insert to end with */
2510
const int MAX_ROWS_PER_INSERT= 300;
2511
const int MAX_PARAM_COUNT= COLUMN_COUNT*MAX_ROWS_PER_INSERT;
2512
const char *query_template= "insert into t1 values %s";
2513
const int CHARS_PER_PARAM= 5; /* space needed to place ", ?" in the query */
2514
const int uint16_max= 65535;
2518
stmt_text= "drop table if exists t1";
2519
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2521
stmt_text= "create table if not exists t1"
2522
"(c1 float, c2 float, c3 float, c4 float, c5 float, c6 float, "
2523
"c7 float, c8 float, c9 float, c10 float, c11 float, c12 float, "
2524
"c13 float, c14 float, c15 float, c16 float, c17 float, c18 float, "
2525
"c19 float, c20 float, c21 float, c22 float, c23 float, c24 float, "
2526
"c25 float, c26 float, c27 float, c28 float, c29 float, c30 float, "
2527
"c31 float, c32 float, c33 float, c34 float, c35 float, c36 float, "
2528
"c37 float, c38 float, c39 float, c40 float, c41 float, c42 float, "
2529
"c43 float, c44 float, c45 float, c46 float, c47 float, c48 float, "
2530
"c49 float, c50 float, c51 float, c52 float, c53 float, c54 float, "
2531
"c55 float, c56 float, c57 float, c58 float, c59 float, c60 float, "
2532
"c61 float, c62 float, c63 float, c64 float, c65 float, c66 float, "
2533
"c67 float, c68 float, c69 float, c70 float, c71 float, c72 float, "
2534
"c73 float, c74 float, c75 float, c76 float, c77 float, c78 float, "
2535
"c79 float, c80 float, c81 float, c82 float, c83 float, c84 float, "
2536
"c85 float, c86 float, c87 float, c88 float, c89 float, c90 float, "
2537
"c91 float, c92 float, c93 float, c94 float, c95 float, c96 float, "
2538
"c97 float, c98 float, c99 float, c100 float, c101 float, c102 float, "
2539
"c103 float, c104 float, c105 float, c106 float, c107 float, c108 float, "
2540
"c109 float, c110 float, c111 float, c112 float, c113 float, c114 float, "
2541
"c115 float, c116 float, c117 float, c118 float, c119 float, c120 float, "
2542
"c121 float, c122 float, c123 float, c124 float, c125 float, c126 float, "
2543
"c127 float, c128 float, c129 float, c130 float, c131 float, c132 float, "
2544
"c133 float, c134 float, c135 float, c136 float, c137 float, c138 float, "
2545
"c139 float, c140 float, c141 float, c142 float, c143 float, c144 float, "
2546
"c145 float, c146 float, c147 float, c148 float, c149 float, c150 float, "
2547
"c151 float, c152 float, c153 float, c154 float, c155 float, c156 float, "
2548
"c157 float, c158 float, c159 float, c160 float, c161 float, c162 float, "
2549
"c163 float, c164 float, c165 float, c166 float, c167 float, c168 float, "
2550
"c169 float, c170 float, c171 float, c172 float, c173 float, c174 float, "
2551
"c175 float, c176 float, c177 float, c178 float, c179 float, c180 float, "
2552
"c181 float, c182 float, c183 float, c184 float, c185 float, c186 float, "
2553
"c187 float, c188 float, c189 float, c190 float, c191 float, c192 float, "
2554
"c193 float, c194 float, c195 float, c196 float, c197 float, c198 float, "
2555
"c199 float, c200 float, c201 float, c202 float, c203 float, c204 float, "
2556
"c205 float, c206 float, c207 float, c208 float, c209 float, c210 float, "
2557
"c211 float, c212 float, c213 float, c214 float, c215 float, c216 float, "
2558
"c217 float, c218 float, c219 float, c220 float, c221 float, c222 float, "
2559
"c223 float, c224 float, c225 float, c226 float, c227 float, c228 float, "
2560
"c229 float, c230 float, c231 float, c232 float, c233 float, c234 float, "
2561
"c235 float, c236 float, c237 float, c238 float, c239 float, c240 float, "
2562
"c241 float, c242 float, c243 float, c244 float, c245 float, c246 float, "
2563
"c247 float, c248 float, c249 float, c250 float)";
2564
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2565
check_mysql_rc(rc, mysql);
2567
my_bind= (MYSQL_BIND*) malloc(MAX_PARAM_COUNT * sizeof(MYSQL_BIND));
2568
query= (char*) malloc(strlen(query_template) +
2569
MAX_PARAM_COUNT * CHARS_PER_PARAM + 1);
2570
param_str= (char*) malloc(COLUMN_COUNT * CHARS_PER_PARAM);
2572
FAIL_IF(my_bind == 0 || query == 0 || param_str == 0, "Not enought memory")
2574
stmt= mysql_stmt_init(mysql);
2576
/* setup a template for one row of parameters */
2577
sprintf(param_str, "(");
2578
for (i= 1; i < COLUMN_COUNT; ++i)
2579
strcat(param_str, "?, ");
2580
strcat(param_str, "?)");
2581
param_str_length= strlen(param_str);
2583
/* setup bind array */
2584
memset(my_bind, '\0', MAX_PARAM_COUNT * sizeof(MYSQL_BIND));
2585
for (i= 0; i < MAX_PARAM_COUNT; ++i)
2587
my_bind[i].buffer_type= MYSQL_TYPE_FLOAT;
2588
my_bind[i].buffer= fa_ptr;
2589
if (++fa_ptr == float_array + COLUMN_COUNT)
2590
fa_ptr= float_array;
2594
Test each number of rows per bulk insert, so that we can see where
2597
for (nrows= MIN_ROWS_PER_INSERT; nrows <= MAX_ROWS_PER_INSERT; ++nrows)
2600
/* Create statement text for current number of rows */
2601
sprintf(query, query_template, param_str);
2602
query_ptr= query + strlen(query);
2603
for (i= 1; i < nrows; ++i)
2605
memcpy(query_ptr, ", ", 2);
2607
memcpy(query_ptr, param_str, param_str_length);
2608
query_ptr+= param_str_length;
2612
rc= mysql_stmt_prepare(stmt, query, query_ptr - query);
2614
if (rc && nrows * COLUMN_COUNT > uint16_max) /* expected error */
2617
check_stmt_rc(rc, stmt);
2619
/* bind the parameter array and execute the query */
2620
rc= mysql_stmt_bind_param(stmt, my_bind);
2621
check_stmt_rc(rc, stmt);
2622
rc= mysql_stmt_execute(stmt);
2623
check_stmt_rc(rc, stmt);
2624
rc= mysql_stmt_reset(stmt);
2629
rc= mysql_stmt_close(stmt);
2630
check_stmt_rc(rc, stmt);
2632
stmt_text= "drop table t1";
2633
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2634
check_mysql_rc(rc, mysql);
2638
static int test_bug5315(MYSQL *mysql)
2641
const char *stmt_text;
2645
stmt_text= "SELECT 1";
2646
stmt= mysql_stmt_init(mysql);
2647
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2648
check_stmt_rc(rc, stmt);
2649
rc= mysql_change_user(mysql, username, password, schema);
2650
check_mysql_rc(rc, mysql);
2652
rc= mysql_stmt_execute(stmt);
2653
FAIL_UNLESS(rc != 0, "Error expected");
2655
rc= mysql_stmt_close(stmt);
2656
check_stmt_rc(rc, stmt);
2658
stmt= mysql_stmt_init(mysql);
2659
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2660
check_stmt_rc(rc, stmt);
2661
rc= mysql_stmt_execute(stmt);
2662
check_stmt_rc(rc, stmt);
2663
mysql_stmt_close(stmt);
2667
static int test_bug5399(MYSQL *mysql)
2670
Ascii 97 is 'a', which gets mapped to Ascii 65 'A' unless internal
2671
statement id hash in the server uses binary collation.
2673
#define NUM_OF_USED_STMT 97
2674
MYSQL_STMT *stmt_list[NUM_OF_USED_STMT];
2676
MYSQL_BIND my_bind[1];
2682
memset(my_bind, '\0', sizeof(my_bind)); my_bind[0].buffer_type= MYSQL_TYPE_LONG;
2683
my_bind[0].buffer= &no;
2685
for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt)
2687
sprintf(buff, "select %d", (int) (stmt - stmt_list));
2688
*stmt= mysql_stmt_init(mysql);
2689
rc= mysql_stmt_prepare(*stmt, buff, strlen(buff));
2690
check_stmt_rc(rc, *stmt); mysql_stmt_bind_result(*stmt, my_bind);
2693
for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt)
2695
rc= mysql_stmt_execute(*stmt);
2696
check_stmt_rc(rc, *stmt);
2697
rc= mysql_stmt_store_result(*stmt);
2698
check_stmt_rc(rc, *stmt);
2699
rc= mysql_stmt_fetch(*stmt);
2700
FAIL_UNLESS((int32) (stmt - stmt_list) == no, "");
2703
for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt)
2704
mysql_stmt_close(*stmt);
2705
#undef NUM_OF_USED_STMT
2709
static int test_bug6046(MYSQL *mysql)
2712
const char *stmt_text;
2715
MYSQL_BIND my_bind[1];
2718
stmt_text= "DROP TABLE IF EXISTS t1";
2719
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2720
check_mysql_rc(rc, mysql);
2721
stmt_text= "CREATE TABLE t1 (a int, b int)";
2722
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2723
check_mysql_rc(rc, mysql);
2724
stmt_text= "INSERT INTO t1 VALUES (1,1),(2,2),(3,1),(4,2)";
2725
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2726
check_mysql_rc(rc, mysql);
2728
stmt= mysql_stmt_init(mysql);
2730
stmt_text= "SELECT t1.a FROM t1 NATURAL JOIN t1 as X1 "
2731
"WHERE t1.b > ? ORDER BY t1.a";
2733
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2734
check_stmt_rc(rc, stmt);
2736
memset(my_bind, '\0', sizeof(my_bind)); my_bind[0].buffer= &b;
2737
my_bind[0].buffer_type= MYSQL_TYPE_SHORT;
2739
mysql_stmt_bind_param(stmt, my_bind);
2741
rc= mysql_stmt_execute(stmt);
2742
check_stmt_rc(rc, stmt);
2743
mysql_stmt_store_result(stmt);
2745
rc= mysql_stmt_execute(stmt);
2746
check_stmt_rc(rc, stmt);
2747
mysql_stmt_close(stmt);
2751
static int test_bug6049(MYSQL *mysql)
2754
MYSQL_BIND my_bind[1];
2757
const char *stmt_text;
2763
stmt_text= "SELECT MAKETIME(-25, 12, 12)";
2765
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2766
check_mysql_rc(rc, mysql);
2767
res= mysql_store_result(mysql);
2768
row= mysql_fetch_row(res);
2770
stmt= mysql_stmt_init(mysql);
2771
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2772
check_stmt_rc(rc, stmt);
2773
rc= mysql_stmt_execute(stmt);
2774
check_stmt_rc(rc, stmt);
2775
memset(my_bind, '\0', sizeof(my_bind));
2776
my_bind[0].buffer_type = MYSQL_TYPE_STRING;
2777
my_bind[0].buffer = &buffer;
2778
my_bind[0].buffer_length = sizeof(buffer);
2779
my_bind[0].length = &length;
2781
mysql_stmt_bind_result(stmt, my_bind);
2782
rc= mysql_stmt_fetch(stmt);
2783
check_stmt_rc(rc, stmt);
2785
FAIL_UNLESS(strcmp(row[0], (char*) buffer) == 0, "row[0] != buffer");
2787
mysql_free_result(res);
2788
mysql_stmt_close(stmt);
2792
static int test_bug6058(MYSQL *mysql)
2795
MYSQL_BIND my_bind[1];
2798
const char *stmt_text;
2804
stmt_text= "SELECT CAST('0000-00-00' AS DATE)";
2806
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2807
check_mysql_rc(rc, mysql);
2808
res= mysql_store_result(mysql);
2809
row= mysql_fetch_row(res);
2811
stmt= mysql_stmt_init(mysql);
2812
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2813
check_stmt_rc(rc, stmt);
2814
rc= mysql_stmt_execute(stmt);
2815
check_stmt_rc(rc, stmt);
2816
memset(my_bind, '\0', sizeof(my_bind));
2817
my_bind[0].buffer_type = MYSQL_TYPE_STRING;
2818
my_bind[0].buffer = &buffer;
2819
my_bind[0].buffer_length = sizeof(buffer);
2820
my_bind[0].length = &length;
2822
mysql_stmt_bind_result(stmt, my_bind);
2823
rc= mysql_stmt_fetch(stmt);
2824
check_stmt_rc(rc, stmt);
2826
FAIL_UNLESS(strcmp(row[0], buffer) == 0, "row[0] != buffer");
2828
mysql_free_result(res);
2829
mysql_stmt_close(stmt);
2834
static int test_bug6059(MYSQL *mysql)
2837
const char *stmt_text;
2840
stmt_text= "SELECT 'foo' INTO OUTFILE 'x.3'";
2842
stmt= mysql_stmt_init(mysql);
2843
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2844
check_stmt_rc(rc, stmt);
2845
FAIL_UNLESS(mysql_stmt_field_count(stmt) == 0, "");
2846
mysql_stmt_close(stmt);
2850
static int test_bug6096(MYSQL *mysql)
2853
MYSQL_RES *query_result, *stmt_metadata;
2854
const char *stmt_text;
2855
MYSQL_BIND my_bind[12];
2856
MYSQL_FIELD *query_field_list, *stmt_field_list;
2857
ulong query_field_count, stmt_field_count;
2859
my_bool update_max_length= TRUE;
2863
stmt_text= "drop table if exists t1";
2864
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2865
check_mysql_rc(rc, mysql);
2867
mysql_query(mysql, "set sql_mode=''");
2868
stmt_text= "create table t1 (c_tinyint tinyint, c_smallint smallint, "
2869
" c_mediumint mediumint, c_int int, "
2870
" c_bigint bigint, c_float float, "
2871
" c_double double, c_varchar varchar(20), "
2872
" c_char char(20), c_time time, c_date date, "
2873
" c_datetime datetime)";
2874
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2875
check_mysql_rc(rc, mysql);
2876
stmt_text= "insert into t1 values (-100, -20000, 30000000, 4, 8, 1.0, "
2877
"2.0, 'abc', 'def', now(), now(), now())";
2878
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2879
check_mysql_rc(rc, mysql);
2881
stmt_text= "select * from t1";
2883
/* Run select in prepared and non-prepared mode and compare metadata */
2884
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2885
check_mysql_rc(rc, mysql);
2886
query_result= mysql_store_result(mysql);
2887
query_field_list= mysql_fetch_fields(query_result);
2888
query_field_count= mysql_num_fields(query_result);
2890
stmt= mysql_stmt_init(mysql);
2891
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
2892
check_stmt_rc(rc, stmt); rc= mysql_stmt_execute(stmt);
2893
check_stmt_rc(rc, stmt); mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH,
2894
(void*) &update_max_length);
2895
mysql_stmt_store_result(stmt);
2896
stmt_metadata= mysql_stmt_result_metadata(stmt);
2897
stmt_field_list= mysql_fetch_fields(stmt_metadata);
2898
stmt_field_count= mysql_num_fields(stmt_metadata);
2899
FAIL_UNLESS(stmt_field_count == query_field_count, "");
2902
/* Bind and fetch the data */
2904
memset(my_bind, '\0', sizeof(my_bind));
2905
for (i= 0; i < stmt_field_count; ++i)
2907
my_bind[i].buffer_type= MYSQL_TYPE_STRING;
2908
my_bind[i].buffer_length= stmt_field_list[i].max_length + 1;
2909
my_bind[i].buffer= malloc(my_bind[i].buffer_length);
2911
mysql_stmt_bind_result(stmt, my_bind);
2912
rc= mysql_stmt_fetch(stmt);
2913
check_stmt_rc(rc, stmt);
2914
rc= mysql_stmt_fetch(stmt);
2915
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
2919
for (i= 0; i < stmt_field_count; ++i)
2920
free(my_bind[i].buffer);
2921
mysql_stmt_close(stmt);
2922
mysql_free_result(query_result);
2923
mysql_free_result(stmt_metadata);
2924
stmt_text= "drop table t1";
2925
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2926
check_mysql_rc(rc, mysql);
2930
/* Bug#7990 - mysql_stmt_close doesn't reset mysql->net.last_error */
2932
static int test_bug7990(MYSQL *mysql)
2937
stmt= mysql_stmt_init(mysql);
2938
rc= mysql_stmt_prepare(stmt, "foo", 3);
2940
XXX: the fact that we store errno both in STMT and in
2941
MYSQL is not documented and is subject to change in 5.0
2943
FAIL_UNLESS(rc && mysql_stmt_errno(stmt) && mysql_errno(mysql), "Error expected");
2944
mysql_stmt_close(stmt);
2945
FAIL_UNLESS(!mysql_errno(mysql), "errno != 0");
2949
/* Bug#8330 - mysql_stmt_execute crashes (libmysql) */
2951
static int test_bug8330(MYSQL *mysql)
2953
const char *stmt_text;
2954
MYSQL_STMT *stmt[2];
2956
const char *query= "select a,b from t1 where a=?";
2957
MYSQL_BIND my_bind[2];
2960
stmt_text= "drop table if exists t1";
2961
/* in case some previos test failed */
2962
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2963
check_mysql_rc(rc, mysql);
2964
stmt_text= "create table t1 (a int, b int)";
2965
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2966
check_mysql_rc(rc, mysql);
2968
memset(my_bind, '\0', sizeof(my_bind));
2969
for (i=0; i < 2; i++)
2971
stmt[i]= mysql_stmt_init(mysql);
2972
rc= mysql_stmt_prepare(stmt[i], query, strlen(query));
2973
check_stmt_rc(rc, stmt[i]);
2974
my_bind[i].buffer_type= MYSQL_TYPE_LONG;
2975
my_bind[i].buffer= (void*) &lval[i];
2976
my_bind[i].is_null= 0;
2977
mysql_stmt_bind_param(stmt[i], &my_bind[i]);
2980
rc= mysql_stmt_execute(stmt[0]);
2981
check_stmt_rc(rc, stmt[0]);
2982
rc= mysql_stmt_execute(stmt[1]);
2983
FAIL_UNLESS(rc && mysql_stmt_errno(stmt[1]) == CR_COMMANDS_OUT_OF_SYNC, "Error expected");
2984
rc= mysql_stmt_execute(stmt[0]);
2985
check_stmt_rc(rc, stmt[0]);
2986
mysql_stmt_close(stmt[0]);
2987
mysql_stmt_close(stmt[1]);
2989
stmt_text= "drop table t1";
2990
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
2991
check_mysql_rc(rc, mysql);
2995
/* Test misc field information, bug: #74 */
2997
static int test_field_misc(MYSQL *mysql)
3004
rc= mysql_query(mysql, "SELECT @@autocommit");
3005
check_mysql_rc(rc, mysql);
3007
result= mysql_store_result(mysql);
3008
FAIL_IF(!result, "Invalid result set");
3011
while (mysql_fetch_row(result))
3013
FAIL_UNLESS(rc == 1, "rowcount != 1");
3015
verify_prepare_field(result, 0,
3016
"@@autocommit", "", /* field and its org name */
3017
MYSQL_TYPE_LONGLONG, /* field type */
3018
"", "", /* table and its org name */
3019
"", 1, 0); /* db name, length(its bool flag)*/
3021
mysql_free_result(result);
3023
stmt= mysql_stmt_init(mysql);
3024
FAIL_IF(!stmt, mysql_error(mysql));
3025
rc= mysql_stmt_prepare(stmt, "SELECT @@autocommit", strlen("SELECT @@autocommit"));
3026
check_stmt_rc(rc, stmt);
3028
rc= mysql_stmt_execute(stmt);
3029
check_stmt_rc(rc, stmt);
3031
result= mysql_stmt_result_metadata(stmt);
3032
FAIL_IF(!result, "Invalid result set");
3035
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
3037
FAIL_UNLESS(rc == 1, "rowcount != 1");
3039
verify_prepare_field(result, 0,
3040
"@@autocommit", "", /* field and its org name */
3041
MYSQL_TYPE_LONGLONG, /* field type */
3042
"", "", /* table and its org name */
3043
"", 1, 0); /* db name, length(its bool flag)*/
3045
mysql_free_result(result);
3046
mysql_stmt_close(stmt);
3048
stmt= mysql_stmt_init(mysql);
3049
FAIL_IF(!stmt, mysql_error(mysql));
3050
rc= mysql_stmt_prepare(stmt, "SELECT @@max_error_count", strlen("SELECT @@max_error_count"));
3051
check_stmt_rc(rc, stmt);
3053
result= mysql_stmt_result_metadata(stmt);
3054
FAIL_IF(!result, "Invalid result set");
3056
rc= mysql_stmt_execute(stmt);
3057
check_stmt_rc(rc, stmt);
3060
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
3062
FAIL_UNLESS(rc == 1, "rowcount != 1");
3064
if (verify_prepare_field(result, 0,
3065
"@@max_error_count", "", /* field and its org name */
3066
MYSQL_TYPE_LONGLONG, /* field type */
3067
"", "", /* table and its org name */
3068
/* db name, length */
3069
"", MY_INT64_NUM_DECIMAL_DIGITS , 0))
3072
mysql_free_result(result);
3073
mysql_stmt_close(stmt);
3075
stmt= mysql_stmt_init(mysql);
3076
FAIL_IF(!stmt, mysql_error(mysql));
3077
rc= mysql_stmt_prepare(stmt, "SELECT @@max_allowed_packet", strlen("SELECT @@max_allowed_packet"));
3078
check_stmt_rc(rc, stmt);
3080
result= mysql_stmt_result_metadata(stmt);
3081
FAIL_IF(!result, "Invalid result set");
3083
rc= mysql_stmt_execute(stmt);
3084
check_stmt_rc(rc, stmt);
3087
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
3089
FAIL_UNLESS(rc == 1, "rowcount != 1");
3091
if (verify_prepare_field(result, 0,
3092
"@@max_allowed_packet", "", /* field and its org name */
3093
MYSQL_TYPE_LONGLONG, /* field type */
3094
"", "", /* table and its org name */
3095
/* db name, length */
3096
"", MY_INT64_NUM_DECIMAL_DIGITS, 0))
3099
mysql_free_result(result);
3100
mysql_stmt_close(stmt);
3102
stmt= mysql_stmt_init(mysql);
3103
FAIL_IF(!stmt, mysql_error(mysql));
3104
rc= mysql_stmt_prepare(stmt, "SELECT @@sql_warnings", strlen("SELECT @@sql_warnings"));
3105
check_stmt_rc(rc, stmt);
3107
result= mysql_stmt_result_metadata(stmt);
3108
FAIL_IF(!result, "Invalid result set");
3110
rc= mysql_stmt_execute(stmt);
3111
check_stmt_rc(rc, stmt);
3114
while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
3116
FAIL_UNLESS(rc == 1, "rowcount != 1");
3118
if (verify_prepare_field(result, 0,
3119
"@@sql_warnings", "", /* field and its org name */
3120
MYSQL_TYPE_LONGLONG, /* field type */
3121
"", "", /* table and its org name */
3122
"", 1, 0)) /* db name, length */
3125
mysql_free_result(result);
3126
mysql_stmt_close(stmt);
3130
mysql_free_result(result);
3131
mysql_stmt_close(stmt);
3135
/* Test a memory ovverun bug */
3137
static int test_mem_overun(MYSQL *mysql)
3139
char buffer[10000], field[12];
3141
MYSQL_RES *field_res, *res;
3145
Test a memory ovverun bug when a table had 1000 fields with
3148
rc= mysql_query(mysql, "drop table if exists t_mem_overun");
3149
check_mysql_rc(rc, mysql);
3151
strcpy(buffer, "create table t_mem_overun(");
3152
for (i= 0; i < 1000; i++)
3154
sprintf(field, "c%d int, ", i);
3155
strcat(buffer, field);
3157
length= strlen(buffer);
3158
buffer[length-2]= ')';
3159
buffer[--length]= '\0';
3161
rc= mysql_real_query(mysql, buffer, length);
3162
check_mysql_rc(rc, mysql);
3164
strcpy(buffer, "insert into t_mem_overun values(");
3165
for (i= 0; i < 1000; i++)
3167
strcat(buffer, "1, ");
3169
length= strlen(buffer);
3170
buffer[length-2]= ')';
3171
buffer[--length]= '\0';
3173
rc= mysql_real_query(mysql, buffer, length);
3174
check_mysql_rc(rc, mysql);
3176
rc= mysql_query(mysql, "select * from t_mem_overun");
3177
check_mysql_rc(rc, mysql);
3179
res= mysql_store_result(mysql);
3181
while (mysql_fetch_row(res))
3183
FAIL_UNLESS(rc == 1, "rowcount != 1");
3184
mysql_free_result(res);
3186
stmt= mysql_stmt_init(mysql);
3187
FAIL_IF(!stmt, mysql_error(mysql));
3188
rc= mysql_stmt_prepare(stmt, "select * from t_mem_overun", strlen("select * from t_mem_overun"));
3189
check_stmt_rc(rc, stmt);
3191
rc= mysql_stmt_execute(stmt);
3192
check_stmt_rc(rc, stmt);
3194
field_res= mysql_stmt_result_metadata(stmt);
3195
FAIL_IF(!field_res, "Invalid result set");
3197
FAIL_UNLESS( 1000 == mysql_num_fields(field_res), "fields != 1000");
3199
rc= mysql_stmt_store_result(stmt);
3200
check_stmt_rc(rc, stmt);
3202
rc= mysql_stmt_fetch(stmt);
3203
check_stmt_rc(rc, stmt);
3205
rc= mysql_stmt_fetch(stmt);
3206
FAIL_UNLESS(rc == MYSQL_NO_DATA, "");
3208
mysql_free_result(field_res);
3210
mysql_stmt_close(stmt);
3214
static int test_bug8722(MYSQL *mysql)
3218
const char *stmt_text;
3220
/* Prepare test data */
3221
stmt_text= "drop table if exists t1";
3222
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
3223
check_mysql_rc(rc, mysql);
3224
stmt_text= "drop view if exists v1";
3225
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
3226
check_mysql_rc(rc, mysql);
3227
stmt_text= "CREATE TABLE t1 (c1 varchar(10), c2 varchar(10), c3 varchar(10),"
3228
" c4 varchar(10), c5 varchar(10), c6 varchar(10),"
3229
" c7 varchar(10), c8 varchar(10), c9 varchar(10),"
3231
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
3232
check_mysql_rc(rc, mysql);
3233
stmt_text= "INSERT INTO t1 VALUES (1,2,3,4,5,6,7,8,9,10)";
3234
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
3235
check_mysql_rc(rc, mysql);
3236
stmt_text= "CREATE VIEW v1 AS SELECT * FROM t1";
3237
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
3238
check_mysql_rc(rc, mysql);
3240
stmt= mysql_stmt_init(mysql);
3241
stmt_text= "select * from v1";
3242
rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
3243
check_stmt_rc(rc, stmt);
3244
mysql_stmt_close(stmt);
3245
stmt_text= "drop table if exists t1, v1";
3246
rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
3247
check_mysql_rc(rc, mysql);
3251
/* Test DECIMAL conversion */
3253
static int test_decimal_bug(MYSQL *mysql)
3256
MYSQL_BIND my_bind[1];
3261
mysql_autocommit(mysql, TRUE);
3263
rc= mysql_query(mysql, "drop table if exists test_decimal_bug");
3264
check_mysql_rc(rc, mysql);
3266
rc= mysql_query(mysql, "create table test_decimal_bug(c1 decimal(10, 2))");
3267
check_mysql_rc(rc, mysql);
3269
rc= mysql_query(mysql, "insert into test_decimal_bug value(8), (10.22), (5.61)");
3270
check_mysql_rc(rc, mysql);
3272
stmt= mysql_stmt_init(mysql);
3273
FAIL_IF(!stmt, mysql_error(mysql));
3274
rc= mysql_stmt_prepare(stmt, "select c1 from test_decimal_bug where c1=?",
3275
strlen("select c1 from test_decimal_bug where c1=?"));
3276
check_stmt_rc(rc, stmt);
3279
We need to bzero bind structure because mysql_stmt_bind_param checks all
3282
memset(my_bind, '\0', sizeof(my_bind));
3284
my_bind[0].buffer_type= MYSQL_TYPE_NEWDECIMAL;
3285
my_bind[0].buffer= (void *)data;
3286
my_bind[0].buffer_length= 25;
3287
my_bind[0].is_null= &is_null;
3290
rc= mysql_stmt_bind_param(stmt, my_bind);
3291
check_stmt_rc(rc, stmt);
3293
strcpy(data, "8.0");
3294
rc= mysql_stmt_execute(stmt);
3295
check_stmt_rc(rc, stmt);
3298
rc= mysql_stmt_bind_result(stmt, my_bind);
3299
check_stmt_rc(rc, stmt);
3301
rc= mysql_stmt_fetch(stmt);
3302
check_stmt_rc(rc, stmt);
3304
FAIL_UNLESS(strcmp(data, "8.00") == 0, "data != '8.00'");
3306
rc= mysql_stmt_fetch(stmt);
3307
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
3309
strcpy(data, "5.61");
3310
rc= mysql_stmt_execute(stmt);
3311
check_stmt_rc(rc, stmt);
3314
rc= mysql_stmt_bind_result(stmt, my_bind);
3315
check_stmt_rc(rc, stmt);
3317
rc= mysql_stmt_fetch(stmt);
3318
check_stmt_rc(rc, stmt);
3320
FAIL_UNLESS(strcmp(data, "5.61") == 0, "data != '5.61'");
3322
rc= mysql_stmt_fetch(stmt);
3323
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
3326
rc= mysql_stmt_execute(stmt);
3327
check_stmt_rc(rc, stmt);
3329
rc= mysql_stmt_fetch(stmt);
3330
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
3332
strcpy(data, "10.22"); is_null= 0;
3333
rc= mysql_stmt_execute(stmt);
3334
check_stmt_rc(rc, stmt);
3337
rc= mysql_stmt_bind_result(stmt, my_bind);
3338
check_stmt_rc(rc, stmt);
3340
rc= mysql_stmt_fetch(stmt);
3341
check_stmt_rc(rc, stmt);
3343
FAIL_UNLESS(strcmp(data, "10.22") == 0, "data != '10.22'");
3345
rc= mysql_stmt_fetch(stmt);
3346
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
3348
mysql_stmt_close(stmt);
3352
/* Test EXPLAIN bug (#115, reported by mark@mysql.com & georg@php.net). */
3354
static int test_explain_bug(MYSQL *mysql)
3361
mysql_autocommit(mysql, TRUE);
3363
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_explain");
3364
check_mysql_rc(rc, mysql);
3366
rc= mysql_query(mysql, "CREATE TABLE test_explain(id int, name char(2))");
3367
check_mysql_rc(rc, mysql);
3369
stmt= mysql_stmt_init(mysql);
3370
FAIL_IF(!stmt, mysql_error(mysql));
3371
rc= mysql_stmt_prepare(stmt, "explain test_explain", strlen("explain test_explain"));
3372
check_stmt_rc(rc, stmt);
3374
rc= mysql_stmt_execute(stmt);
3375
check_stmt_rc(rc, stmt);
3378
while (!mysql_stmt_fetch(stmt))
3380
FAIL_UNLESS(rc == 2, "rowcount != 2");
3382
result= mysql_stmt_result_metadata(stmt);
3383
FAIL_IF(!result, "Invalid result set");
3385
FAIL_UNLESS(6 == mysql_num_fields(result), "fields != 6");
3387
if (verify_prepare_field(result, 0, "Field", "COLUMN_NAME",
3388
mysql_get_server_version(mysql) <= 50000 ?
3389
MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
3391
mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema",
3395
if (verify_prepare_field(result, 1, "Type", "COLUMN_TYPE", MYSQL_TYPE_BLOB,
3397
mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema",
3401
if (verify_prepare_field(result, 2, "Null", "IS_NULLABLE",
3402
mysql_get_server_version(mysql) <= 50000 ?
3403
MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
3405
mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema",
3409
if (verify_prepare_field(result, 3, "Key", "COLUMN_KEY",
3410
mysql_get_server_version(mysql) <= 50000 ?
3411
MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
3413
mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema",
3417
if ( mysql_get_server_version(mysql) >= 50027 )
3419
/* The patch for bug#23037 changes column type of DEAULT to blob */
3420
if (verify_prepare_field(result, 4, "Default", "COLUMN_DEFAULT",
3421
MYSQL_TYPE_BLOB, 0, 0,
3422
mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema",
3428
if (verify_prepare_field(result, 4, "Default", "COLUMN_DEFAULT",
3429
mysql_get_server_version(mysql) >= 50027 ?
3431
mysql_get_server_version(mysql) <= 50000 ?
3432
MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
3434
mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema",
3435
mysql_get_server_version(mysql) >= 50027 ? 0 :64, 0))
3439
if (verify_prepare_field(result, 5, "Extra", "EXTRA",
3440
mysql_get_server_version(mysql) <= 50000 ?
3441
MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
3443
mysql_get_server_version(mysql) <= 50400 ? "" : "information_schema",
3447
mysql_free_result(result);
3448
mysql_stmt_close(stmt);
3450
stmt= mysql_stmt_init(mysql);
3451
FAIL_IF(!stmt, mysql_error(mysql));
3452
rc= mysql_stmt_prepare(stmt, "explain select id, name FROM test_explain", strlen("explain select id, name FROM test_explain"));
3453
check_stmt_rc(rc, stmt);
3455
rc= mysql_stmt_execute(stmt);
3456
check_stmt_rc(rc, stmt);
3459
while (!mysql_stmt_fetch(stmt))
3461
FAIL_UNLESS(rc == 1, "rowcount != 1");
3463
result= mysql_stmt_result_metadata(stmt);
3464
FAIL_IF(!result, "Invalid result set");
3466
FAIL_UNLESS(10 == mysql_num_fields(result), "fields != 10");
3468
if (verify_prepare_field(result, 0, "id", "", MYSQL_TYPE_LONGLONG, "", "", "", 3, 0))
3471
if (verify_prepare_field(result, 1, "select_type", "", MYSQL_TYPE_VAR_STRING, "", "", "", 19, 0))
3474
if (verify_prepare_field(result, 2, "table", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_CHAR_LEN, 0))
3477
if (verify_prepare_field(result, 3, "type", "", MYSQL_TYPE_VAR_STRING, "", "", "", 10, 0))
3480
if (verify_prepare_field(result, 4, "possible_keys", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_CHAR_LEN*MAX_KEY, 0))
3483
if ( verify_prepare_field(result, 5, "key", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_CHAR_LEN, 0))
3486
if (mysql_get_server_version(mysql) <= 50000)
3488
if (verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_LONGLONG, "", "", "", 3, 0))
3491
else if (mysql_get_server_version(mysql) <= 60000)
3493
if (verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_VAR_STRING, "", "", "", NAME_CHAR_LEN*MAX_KEY, 0))
3498
if (verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_VAR_STRING, "", "", "", (MAX_KEY_LENGTH_DECIMAL_WIDTH + 1) * MAX_KEY, 0))
3502
if (verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_VAR_STRING, "", "", "",
3503
NAME_CHAR_LEN*16, 0))
3506
if (verify_prepare_field(result, 8, "rows", "", MYSQL_TYPE_LONGLONG, "", "", "", 10, 0))
3509
if (verify_prepare_field(result, 9, "Extra", "", MYSQL_TYPE_VAR_STRING, "", "", "", 255, 0))
3512
mysql_free_result(result);
3513
mysql_stmt_close(stmt);
3516
mysql_free_result(result);
3517
mysql_stmt_close(stmt);
3521
static int test_sshort_bug(MYSQL *mysql)
3524
MYSQL_BIND my_bind[4];
3527
ulong s_length, l_length, ll_length, t_length;
3528
ulonglong longlong_value;
3532
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_sshort");
3533
check_mysql_rc(rc, mysql);
3535
rc= mysql_query(mysql, "CREATE TABLE test_sshort(a smallint signed, \
3536
b smallint signed, \
3537
c smallint unsigned, \
3538
d smallint unsigned)");
3539
check_mysql_rc(rc, mysql);
3541
rc= mysql_query(mysql, "INSERT INTO test_sshort VALUES(-5999, -5999, 35999, 200)");
3542
check_mysql_rc(rc, mysql);
3545
stmt= mysql_stmt_init(mysql);
3546
FAIL_IF(!stmt, mysql_error(mysql));
3547
rc= mysql_stmt_prepare(stmt, "SELECT * FROM test_sshort", strlen("SELECT * FROM test_sshort"));
3548
check_stmt_rc(rc, stmt);
3550
rc= mysql_stmt_execute(stmt);
3551
check_stmt_rc(rc, stmt);
3553
memset(my_bind, '\0', sizeof(my_bind));
3554
my_bind[0].buffer_type= MYSQL_TYPE_SHORT;
3555
my_bind[0].buffer= (void *)&short_value;
3556
my_bind[0].length= &s_length;
3558
my_bind[1].buffer_type= MYSQL_TYPE_LONG;
3559
my_bind[1].buffer= (void *)&long_value;
3560
my_bind[1].length= &l_length;
3562
my_bind[2].buffer_type= MYSQL_TYPE_LONGLONG;
3563
my_bind[2].buffer= (void *)&longlong_value;
3564
my_bind[2].length= &ll_length;
3566
my_bind[3].buffer_type= MYSQL_TYPE_TINY;
3567
my_bind[3].buffer= (void *)&tiny_value;
3568
my_bind[3].is_unsigned= TRUE;
3569
my_bind[3].length= &t_length;
3571
rc= mysql_stmt_bind_result(stmt, my_bind);
3572
check_stmt_rc(rc, stmt);
3574
rc= mysql_stmt_fetch(stmt);
3575
check_stmt_rc(rc, stmt);
3577
FAIL_UNLESS(short_value == -5999, "sv != -5999");
3578
FAIL_UNLESS(s_length == 2, "s_length != 2");
3580
FAIL_UNLESS(long_value == -5999, "l_v != -5999");
3581
FAIL_UNLESS(l_length == 4, "l_length != 4");
3583
FAIL_UNLESS(longlong_value == 35999, "llv != 35999");
3584
FAIL_UNLESS(ll_length == 8, "ll_length != 8");
3586
FAIL_UNLESS(tiny_value == 200, "t_v != 200");
3587
FAIL_UNLESS(t_length == 1, "t_length != 1");
3589
rc= mysql_stmt_fetch(stmt);
3590
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
3592
mysql_stmt_close(stmt);
3597
/* Test a misc tinyint-signed conversion bug */
3599
static int test_stiny_bug(MYSQL *mysql)
3602
MYSQL_BIND my_bind[4];
3605
ulong s_length, l_length, ll_length, t_length;
3606
ulonglong longlong_value;
3610
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_stiny");
3611
check_mysql_rc(rc, mysql);
3613
rc= mysql_query(mysql, "CREATE TABLE test_stiny(a tinyint signed, \
3615
c tinyint unsigned, \
3616
d tinyint unsigned)");
3617
check_mysql_rc(rc, mysql);
3619
rc= mysql_query(mysql, "INSERT INTO test_stiny VALUES(-128, -127, 255, 0)");
3620
check_mysql_rc(rc, mysql);
3623
stmt= mysql_stmt_init(mysql);
3624
FAIL_IF(!stmt, mysql_error(mysql));
3625
rc= mysql_stmt_prepare(stmt, "SELECT * FROM test_stiny", strlen("SELECT * FROM test_stiny"));
3626
check_stmt_rc(rc, stmt);
3628
rc= mysql_stmt_execute(stmt);
3629
check_stmt_rc(rc, stmt);
3631
memset(my_bind, '\0', sizeof(my_bind));
3632
my_bind[0].buffer_type= MYSQL_TYPE_SHORT;
3633
my_bind[0].buffer= (void *)&short_value;
3634
my_bind[0].length= &s_length;
3636
my_bind[1].buffer_type= MYSQL_TYPE_LONG;
3637
my_bind[1].buffer= (void *)&long_value;
3638
my_bind[1].length= &l_length;
3640
my_bind[2].buffer_type= MYSQL_TYPE_LONGLONG;
3641
my_bind[2].buffer= (void *)&longlong_value;
3642
my_bind[2].length= &ll_length;
3644
my_bind[3].buffer_type= MYSQL_TYPE_TINY;
3645
my_bind[3].buffer= (void *)&tiny_value;
3646
my_bind[3].length= &t_length;
3648
rc= mysql_stmt_bind_result(stmt, my_bind);
3649
check_stmt_rc(rc, stmt);
3651
rc= mysql_stmt_fetch(stmt);
3652
check_stmt_rc(rc, stmt);
3654
FAIL_UNLESS(short_value == -128, "s_v != -128");
3655
FAIL_UNLESS(s_length == 2, "s_length != 2");
3657
FAIL_UNLESS(long_value == -127, "l_v != -127");
3658
FAIL_UNLESS(l_length == 4, "l_length != 4");
3660
FAIL_UNLESS(longlong_value == 255, "llv != 255");
3661
FAIL_UNLESS(ll_length == 8, "ll_length != 8");
3663
FAIL_UNLESS(tiny_value == 0, "t_v != 0");
3664
FAIL_UNLESS(t_length == 1, "t_length != 1");
3666
rc= mysql_stmt_fetch(stmt);
3667
FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
3669
mysql_stmt_close(stmt);
3673
static int test_bug53311(MYSQL *mysql)
3678
char *query= "INSERT INTO bug53311 VALUES (1)";
3680
rc= mysql_options(mysql, MYSQL_OPT_RECONNECT, "1");
3681
check_mysql_rc(rc, mysql);
3683
rc= mysql_query(mysql, "DROP TABLE IF EXISTS bug53311");
3684
check_mysql_rc(rc, mysql);
3686
rc= mysql_query(mysql, "CREATE TABLE bug53311 (a int)");
3687
check_mysql_rc(rc, mysql);
3689
stmt= mysql_stmt_init(mysql);
3690
rc= mysql_stmt_prepare(stmt, query, strlen(query));
3691
check_stmt_rc(rc, stmt);
3693
for (i=0; i < 2; i++)
3695
rc= mysql_stmt_execute(stmt);
3696
check_stmt_rc(rc, stmt);
3699
/* kill connection */
3700
rc= mysql_kill(mysql, mysql_thread_id(mysql));
3701
check_mysql_rc(rc, mysql);
3704
rc= mysql_stmt_execute(stmt);
3705
FAIL_IF(rc == 0, "Error expected");
3706
FAIL_IF(mysql_stmt_errno(stmt) == 0, "Errno != 0 expected");
3707
rc= mysql_stmt_close(stmt);
3708
check_mysql_rc(rc, mysql);
3713
struct my_tests_st my_tests[] = {
3714
{"test_bug1115", test_bug1115, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3715
{"test_bug1180", test_bug1180, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3716
{"test_bug1644", test_bug1644, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3717
{"test_bug11037", test_bug11037, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3718
{"test_bug11183", test_bug11183, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3719
{"test_bug12744", test_bug12744, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3720
{"test_bug1500", test_bug1500, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3721
{"test_bug15510", test_bug15510, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3722
{"test_bug15518", test_bug15518, TEST_CONNECTION_NEW | TEST_CONNECTION_DONT_CLOSE, CLIENT_MULTI_STATEMENTS, NULL , NULL},
3723
{"test_bug15613", test_bug15613, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3724
{"test_bug16144", test_bug16144, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3725
{"test_bug1664", test_bug1664, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3726
{"test_bug1946", test_bug1946, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3727
{"test_bug2247", test_bug2247, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3728
{"test_bug2248", test_bug2248, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3729
{"test_bug20152", test_bug20152, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3730
{"test_bug23383", test_bug23383, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3731
{"test_bug27592", test_bug27592, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3732
{"test_bug28934", test_bug28934, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3733
{"test_bug36004", test_bug36004, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3734
{"test_bug3035", test_bug3035, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3735
{"test_bug3117", test_bug3117, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3736
{"test_bug3796", test_bug3796, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3737
{"test_bug4026", test_bug4026, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3738
{"test_bug4030", test_bug4030, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3739
{"test_bug4079", test_bug4079, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3740
{"test_bug4172", test_bug4172, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3741
{"test_bug4231", test_bug4231, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3742
{"test_bug4236", test_bug4236, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3743
{"test_bug5126", test_bug5126, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3744
{"test_bug5194", test_bug5194, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3745
{"test_bug5315", test_bug5315, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3746
{"test_bug5399", test_bug5399, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3747
{"test_bug6046", test_bug6046, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3748
{"test_bug6049", test_bug6049, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3749
{"test_bug6058", test_bug6058, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3750
{"test_bug6059", test_bug6059, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3751
{"test_bug6096", test_bug6096, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3752
{"test_bug7990", test_bug7990, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3753
{"test_bug8330", test_bug8330, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3754
{"test_bug8722", test_bug8722, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3755
{"test_ps_conj_select", test_ps_conj_select, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3756
{"test_ps_null_param", test_ps_null_param, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3757
{"test_ps_query_cache", test_ps_query_cache, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3758
{"test_ushort_bug", test_ushort_bug, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3759
{"test_field_misc", test_field_misc, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3760
{"test_mem_overun", test_mem_overun, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3761
{"test_decimal_bug", test_decimal_bug, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3762
{"test_explain_bug", test_explain_bug, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3763
{"test_sshort_bug", test_sshort_bug, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3764
{"test_stiny_bug", test_stiny_bug, TEST_CONNECTION_DEFAULT, 0, NULL , NULL},
3765
{"test_bug53311", test_bug53311, TEST_CONNECTION_NEW, 0, NULL , NULL},
3766
{NULL, NULL, 0, 0, NULL, NULL}
3769
int main(int argc, char **argv)
3772
// get_options(&argc, &argv);
3776
run_tests(my_tests);
3778
return(exit_status());