1/*
2Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
3
4The 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
6MySQL Connectors. There are special exceptions to the terms and
7conditions of the GPLv2 as it is applied to this software, see the
8FLOSS License Exception
9<http://www.mysql.com/about/legal/licensing/foss-exception.html>.
10
11This program is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published
13by the Free Software Foundation; version 2 of the License.
14
15This program is distributed in the hope that it will be useful, but
16WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18for more details.
19
20You should have received a copy of the GNU General Public License along
21with this program; if not, write to the Free Software Foundation, Inc.,
2251 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23*/
24#include "my_test.h"
25#include "ma_common.h"
26
27#include <mysql/client_plugin.h>
28
29
30/*
31 Bug#28075 "COM_DEBUG crashes mysqld"
32*/
33#ifdef _WIN32
34#define R_OK 4
35#endif
36
37static int test_bug28075(MYSQL *mysql)
38{
39 int rc;
40
41 rc= mysql_dump_debug_info(mysql);
42 check_mysql_rc(rc, mysql);
43
44 rc= mysql_ping(mysql);
45 check_mysql_rc(rc, mysql);
46
47 return OK;
48}
49
50/*
51 Bug#28505: mysql_affected_rows() returns wrong value if CLIENT_FOUND_ROWS
52 flag is set.
53*/
54
55static int test_bug28505(MYSQL *mysql)
56{
57 unsigned long long res;
58 int rc;
59
60 rc= mysql_query(mysql, "drop table if exists t1");
61 check_mysql_rc(rc, mysql);
62 rc= mysql_query(mysql, "create table t1(f1 int primary key)");
63 check_mysql_rc(rc, mysql);
64 rc= mysql_query(mysql, "insert into t1 values(1)");
65 check_mysql_rc(rc, mysql);
66 rc= mysql_query(mysql, "insert into t1 values(1) on duplicate key update f1=1");
67 check_mysql_rc(rc, mysql);
68 res= mysql_affected_rows(mysql);
69 FAIL_UNLESS(!res, "res != 0");
70 rc= mysql_query(mysql, "drop table t1");
71 check_mysql_rc(rc, mysql);
72 return OK;
73}
74
75/*
76 Bug #29692 Single row inserts can incorrectly report a huge number of
77 row insertions
78*/
79
80static int test_bug29692(MYSQL *mysql)
81{
82 int rc;
83 rc= mysql_query(mysql, "drop table if exists t1");
84 check_mysql_rc(rc, mysql);
85 rc= mysql_query(mysql, "create table t1(f1 int)");
86 check_mysql_rc(rc, mysql);
87 rc= mysql_query(mysql, "insert into t1 values(1)");
88 check_mysql_rc(rc, mysql);
89 FAIL_UNLESS(1 == mysql_affected_rows(mysql), "affected_rows != 1");
90 rc= mysql_query(mysql, "drop table t1");
91 check_mysql_rc(rc, mysql);
92 return OK;
93}
94
95static int bug31418_impl()
96{
97 my_bool is_null;
98 MYSQL *mysql;
99 int rc;
100
101
102 /* Create a new connection. */
103
104 mysql= test_connect(NULL);
105 if (!mysql)
106 return FAIL;
107
108 /***********************************************************************
109 Check that lock is free:
110 - IS_FREE_LOCK() should return 1;
111 - IS_USED_LOCK() should return NULL;
112 ***********************************************************************/
113
114 is_null= query_int_variable(mysql,
115 "IS_FREE_LOCK('bug31418')",
116 &rc);
117 FAIL_UNLESS(!is_null && rc, "rc = 0");
118
119 is_null= query_int_variable(mysql,
120 "IS_USED_LOCK('bug31418')",
121 &rc);
122 FAIL_UNLESS(is_null, "rc = 0");
123
124 /***********************************************************************
125 Acquire lock and check the lock status (the lock must be in use):
126 - IS_FREE_LOCK() should return 0;
127 - IS_USED_LOCK() should return non-zero thread id;
128 ***********************************************************************/
129
130 query_int_variable(mysql, "GET_LOCK('bug31418', 1)", &rc);
131 FAIL_UNLESS(rc, "rc = 0");
132
133 is_null= query_int_variable(mysql,
134 "IS_FREE_LOCK('bug31418')",
135 &rc);
136 FAIL_UNLESS(!is_null && !rc, "rc = 0");
137
138 is_null= query_int_variable(mysql,
139 "IS_USED_LOCK('bug31418')",
140 &rc);
141 FAIL_UNLESS(!is_null && rc, "rc = 0");
142
143 /***********************************************************************
144 Issue COM_CHANGE_USER command and check the lock status
145 (the lock must be free):
146 - IS_FREE_LOCK() should return 1;
147 - IS_USED_LOCK() should return NULL;
148 **********************************************************************/
149
150 rc= mysql_change_user(mysql, username, password, schema ? schema : "test");
151 check_mysql_rc(rc, mysql);
152
153 is_null= query_int_variable(mysql,
154 "IS_FREE_LOCK('bug31418')",
155 &rc);
156 FAIL_UNLESS(!is_null && rc, "rc = 0");
157
158 is_null= query_int_variable(mysql,
159 "IS_USED_LOCK('bug31418')",
160 &rc);
161 FAIL_UNLESS(is_null, "rc = 0");
162
163 /***********************************************************************
164 That's it. Cleanup.
165 ***********************************************************************/
166
167 mysql_close(mysql);
168 return OK;
169}
170
171static int test_bug31418(MYSQL *unused __attribute__((unused)))
172{
173 int i;
174
175 if (!is_mariadb)
176 return SKIP;
177 /* Run test case for BUG#31418 for three different connections. */
178
179 for (i=0; i < 3; i++)
180 if (bug31418_impl())
181 return FAIL;
182
183 return OK;
184}
185
186/* Query processing */
187
188static int test_debug_example(MYSQL *mysql)
189{
190 int rc;
191 MYSQL_RES *result;
192
193
194 rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_debug_example");
195 check_mysql_rc(rc, mysql);
196
197 rc= mysql_query(mysql, "CREATE TABLE test_debug_example("
198 "id INT PRIMARY KEY AUTO_INCREMENT, "
199 "name VARCHAR(20), xxx INT)");
200 check_mysql_rc(rc, mysql);
201
202 rc= mysql_query(mysql, "INSERT INTO test_debug_example (name) "
203 "VALUES ('mysql')");
204 check_mysql_rc(rc, mysql);
205
206 rc= mysql_query(mysql, "UPDATE test_debug_example SET name='updated' "
207 "WHERE name='deleted'");
208 check_mysql_rc(rc, mysql);
209
210 rc= mysql_query(mysql, "SELECT * FROM test_debug_example where name='mysql'");
211 check_mysql_rc(rc, mysql);
212
213 result= mysql_use_result(mysql);
214 FAIL_IF(!result, "Invalid result set");
215
216 while (mysql_fetch_row(result));
217 mysql_free_result(result);
218
219 rc= mysql_query(mysql, "DROP TABLE test_debug_example");
220 check_mysql_rc(rc, mysql);
221 return OK;
222}
223
224/*
225 Test a crash when invalid/corrupted .frm is used in the
226 SHOW TABLE STATUS
227 bug #93 (reported by serg@mysql.com).
228*/
229
230static int test_frm_bug(MYSQL *mysql)
231{
232 MYSQL_STMT *stmt;
233 MYSQL_BIND my_bind[2];
234 MYSQL_RES *result;
235 MYSQL_ROW row;
236 FILE *test_file;
237 char data_dir[FN_REFLEN];
238 char test_frm[FN_REFLEN];
239 int rc;
240
241 mysql_autocommit(mysql, TRUE);
242
243 rc= mysql_query(mysql, "drop table if exists test_frm_bug");
244 check_mysql_rc(rc, mysql);
245
246 rc= mysql_query(mysql, "flush tables");
247 check_mysql_rc(rc, mysql);
248
249 stmt= mysql_stmt_init(mysql);
250 FAIL_IF(!stmt, mysql_error(mysql));
251 rc= mysql_stmt_prepare(stmt, SL("show variables like 'datadir'"));
252 check_stmt_rc(rc, stmt);
253
254 rc= mysql_stmt_execute(stmt);
255 check_stmt_rc(rc, stmt);
256
257 memset(my_bind, '\0', sizeof(my_bind));
258 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
259 my_bind[0].buffer= data_dir;
260 my_bind[0].buffer_length= FN_REFLEN;
261 my_bind[1]= my_bind[0];
262
263 rc= mysql_stmt_bind_result(stmt, my_bind);
264 check_stmt_rc(rc, stmt);
265
266 rc= mysql_stmt_fetch(stmt);
267 check_stmt_rc(rc, stmt);
268
269 rc= mysql_stmt_fetch(stmt);
270 FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
271
272 sprintf(test_frm, "%s/%s/test_frm_bug.frm", data_dir, schema);
273
274
275 if (!(test_file= fopen(test_frm, "w")))
276 {
277 mysql_stmt_close(stmt);
278 diag("Can't write to file %s -> SKIP", test_frm);
279 return SKIP;
280 }
281
282 rc= mysql_query(mysql, "SHOW TABLE STATUS like 'test_frm_bug'");
283 check_mysql_rc(rc, mysql);
284
285 result= mysql_store_result(mysql);
286 FAIL_IF(!result, "Invalid result set");/* It can't be NULL */
287
288 rc= 0;
289 while (mysql_fetch_row(result))
290 rc++;
291 FAIL_UNLESS(rc == 1, "rowcount != 0");
292
293 mysql_data_seek(result, 0);
294
295 row= mysql_fetch_row(result);
296 FAIL_IF(!row, "couldn't fetch row");
297
298 FAIL_UNLESS(row[17] != 0, "row[17] != 0");
299
300 mysql_free_result(result);
301 mysql_stmt_close(stmt);
302
303 fclose(test_file);
304 mysql_query(mysql, "drop table if exists test_frm_bug");
305 unlink(test_frm);
306 return OK;
307}
308
309static int test_wl4166_1(MYSQL *mysql)
310{
311 MYSQL_STMT *stmt;
312 int int_data;
313 char str_data[50];
314 char tiny_data;
315 short small_data;
316 longlong big_data;
317 float real_data;
318 double double_data;
319 ulong length[7];
320 my_bool is_null[7];
321 MYSQL_BIND my_bind[7];
322 const char *query;
323 int rc;
324 int i;
325
326 if (mysql_get_server_version(mysql) < 50100) {
327 diag("Test requires MySQL Server version 5.1 or above");
328 return SKIP;
329 }
330 rc= mysql_query(mysql, "DROP TABLE IF EXISTS table_4166");
331 check_mysql_rc(rc, mysql);
332
333 rc= mysql_query(mysql, "CREATE TABLE table_4166(col1 tinyint NOT NULL, "
334 "col2 varchar(15), col3 int, "
335 "col4 smallint, col5 bigint, "
336 "col6 float, col7 double, "
337 "colX varchar(10) default NULL)");
338 check_mysql_rc(rc, mysql);
339
340 stmt= mysql_stmt_init(mysql);
341 FAIL_IF(!stmt, mysql_error(mysql));
342 query= "INSERT INTO table_4166(col1, col2, col3, col4, col5, col6, col7) "
343 "VALUES(?, ?, ?, ?, ?, ?, ?)";
344 rc= mysql_stmt_prepare(stmt, SL(query));
345 check_stmt_rc(rc, stmt);
346
347 FAIL_IF(mysql_stmt_param_count(stmt) != 7, "param_count != 7");
348
349 memset(my_bind, '\0', sizeof(my_bind));
350 /* tinyint */
351 my_bind[0].buffer_type= MYSQL_TYPE_TINY;
352 my_bind[0].buffer= (void *)&tiny_data;
353 /* string */
354 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
355 my_bind[1].buffer= (void *)str_data;
356 my_bind[1].buffer_length= 1000; /* Max string length */
357 /* integer */
358 my_bind[2].buffer_type= MYSQL_TYPE_LONG;
359 my_bind[2].buffer= (void *)&int_data;
360 /* short */
361 my_bind[3].buffer_type= MYSQL_TYPE_SHORT;
362 my_bind[3].buffer= (void *)&small_data;
363 /* bigint */
364 my_bind[4].buffer_type= MYSQL_TYPE_LONGLONG;
365 my_bind[4].buffer= (void *)&big_data;
366 /* float */
367 my_bind[5].buffer_type= MYSQL_TYPE_FLOAT;
368 my_bind[5].buffer= (void *)&real_data;
369 /* double */
370 my_bind[6].buffer_type= MYSQL_TYPE_DOUBLE;
371 my_bind[6].buffer= (void *)&double_data;
372
373 for (i= 0; i < (int) array_elements(my_bind); i++)
374 {
375 my_bind[i].length= &length[i];
376 my_bind[i].is_null= &is_null[i];
377 is_null[i]= 0;
378 }
379
380 rc= mysql_stmt_bind_param(stmt, my_bind);
381 check_stmt_rc(rc, stmt);
382
383 int_data= 320;
384 small_data= 1867;
385 big_data= 1000;
386 real_data= 2;
387 double_data= 6578.001;
388
389 /* now, execute the prepared statement to insert 10 records.. */
390 for (tiny_data= 0; tiny_data < 10; tiny_data++)
391 {
392 length[1]= sprintf(str_data, "MySQL%d", int_data);
393 rc= mysql_stmt_execute(stmt);
394 check_stmt_rc(rc, stmt);
395 int_data += 25;
396 small_data += 10;
397 big_data += 100;
398 real_data += 1;
399 double_data += 10.09;
400 }
401
402 /* force a re-prepare with some DDL */
403
404 rc= mysql_query(mysql,
405 "ALTER TABLE table_4166 change colX colX varchar(20) default NULL");
406 check_mysql_rc(rc, mysql);
407
408 /*
409 execute the prepared statement again,
410 without changing the types of parameters already bound.
411 */
412
413 for (tiny_data= 50; tiny_data < 60; tiny_data++)
414 {
415 length[1]= sprintf(str_data, "MySQL%d", int_data);
416 rc= mysql_stmt_execute(stmt);
417 check_stmt_rc(rc, stmt);
418 int_data += 25;
419 small_data += 10;
420 big_data += 100;
421 real_data += 1;
422 double_data += 10.09;
423 }
424
425 mysql_stmt_close(stmt);
426
427 rc= mysql_query(mysql, "DROP TABLE table_4166");
428 check_mysql_rc(rc, mysql);
429 return OK;
430}
431
432
433static int test_wl4166_2(MYSQL *mysql)
434{
435 MYSQL_STMT *stmt;
436 int c_int;
437 MYSQL_TIME d_date;
438 MYSQL_BIND bind_out[2];
439 int rc;
440
441 if (mysql_get_server_version(mysql) < 50100) {
442 diag("Test requires MySQL Server version 5.1 or above");
443 return SKIP;
444 }
445
446 rc= mysql_query(mysql, "drop table if exists t1");
447 check_mysql_rc(rc, mysql);
448 rc= mysql_query(mysql, "create table t1 (c_int int, d_date date)");
449 check_mysql_rc(rc, mysql);
450 rc= mysql_query(mysql,
451 "insert into t1 (c_int, d_date) values (42, '1948-05-15')");
452 check_mysql_rc(rc, mysql);
453
454 stmt= mysql_stmt_init(mysql);
455 FAIL_IF(!stmt, mysql_error(mysql));
456 rc= mysql_stmt_prepare(stmt, SL("select * from t1"));
457 check_stmt_rc(rc, stmt);
458
459 memset(bind_out, '\0', sizeof(bind_out));
460 bind_out[0].buffer_type= MYSQL_TYPE_LONG;
461 bind_out[0].buffer= (void*) &c_int;
462
463 bind_out[1].buffer_type= MYSQL_TYPE_DATE;
464 bind_out[1].buffer= (void*) &d_date;
465
466 rc= mysql_stmt_bind_result(stmt, bind_out);
467 check_stmt_rc(rc, stmt);
468
469 /* int -> varchar transition */
470
471 rc= mysql_query(mysql,
472 "alter table t1 change column c_int c_int varchar(11)");
473 check_mysql_rc(rc, mysql);
474
475 rc= mysql_stmt_execute(stmt);
476 check_stmt_rc(rc, stmt);
477
478 rc= mysql_stmt_fetch(stmt);
479 check_stmt_rc(rc, stmt);
480
481 FAIL_UNLESS(c_int == 42, "c_int != 42");
482 FAIL_UNLESS(d_date.year == 1948, "y!=1948");
483 FAIL_UNLESS(d_date.month == 5, "m != 5");
484 FAIL_UNLESS(d_date.day == 15, "d != 15");
485
486 rc= mysql_stmt_fetch(stmt);
487 FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
488
489 /* varchar to int retrieval with truncation */
490
491 rc= mysql_query(mysql, "update t1 set c_int='abcde'");
492 check_mysql_rc(rc, mysql);
493
494 rc= mysql_stmt_execute(stmt);
495 check_stmt_rc(rc, stmt);
496
497 rc= mysql_stmt_fetch(stmt);
498 FAIL_IF(!rc, "Error expected");
499
500 FAIL_UNLESS(c_int == 0, "c != 0");
501
502 rc= mysql_stmt_fetch(stmt);
503 FAIL_UNLESS(rc == MYSQL_NO_DATA, "rc != MYSQL_NO_DATA");
504
505 /* alter table and increase the number of columns */
506 rc= mysql_query(mysql, "alter table t1 add column d_int int");
507 check_mysql_rc(rc, mysql);
508
509 rc= mysql_stmt_execute(stmt);
510 FAIL_IF(!rc, "Error expected");
511
512 rc= mysql_stmt_reset(stmt);
513 check_stmt_rc(rc, stmt);
514
515 /* decrease the number of columns */
516 rc= mysql_query(mysql, "alter table t1 drop d_date, drop d_int");
517 check_mysql_rc(rc, mysql);
518 rc= mysql_stmt_execute(stmt);
519 diag("rc=%d error: %d\n", rc, mysql_stmt_errno(stmt));
520 FAIL_IF(!rc, "Error expected");
521
522 mysql_stmt_close(stmt);
523 rc= mysql_query(mysql, "drop table t1");
524 check_mysql_rc(rc, mysql);
525
526 return OK;
527}
528
529
530/**
531 Test how warnings generated during assignment of parameters
532 are (currently not) preserve in case of reprepare.
533*/
534
535static int test_wl4166_3(MYSQL *mysql)
536{
537 int rc;
538 MYSQL_STMT *stmt;
539 MYSQL_BIND my_bind[1];
540 MYSQL_TIME tm[1];
541
542 if (mysql_get_server_version(mysql) < 50100) {
543 diag("Test requires MySQL Server version 5.1 or above");
544 return SKIP;
545 }
546
547 rc= mysql_query(mysql, "drop table if exists t1");
548 check_mysql_rc(rc, mysql);
549
550 rc= mysql_query(mysql, "create table t1 (year datetime)");
551 check_mysql_rc(rc, mysql);
552
553 stmt= mysql_stmt_init(mysql);
554 FAIL_IF(!stmt, mysql_error(mysql));
555 rc= mysql_stmt_prepare(stmt, SL("insert into t1 (year) values (?)"));
556 check_stmt_rc(rc, stmt);
557
558 FAIL_IF(mysql_stmt_param_count(stmt) != 1, "param_count != 1");
559
560 memset(my_bind, '\0', sizeof(my_bind));
561 my_bind[0].buffer_type= MYSQL_TYPE_DATETIME;
562 my_bind[0].buffer= &tm[0];
563
564 rc= mysql_stmt_bind_param(stmt, my_bind);
565 check_stmt_rc(rc, stmt);
566
567 tm[0].year= 2014;
568 tm[0].month= 1; tm[0].day= 1;
569 tm[0].hour= 1; tm[0].minute= 1; tm[0].second= 1;
570 tm[0].second_part= 0; tm[0].neg= 0;
571
572 /* Cause a statement reprepare */
573 rc= mysql_query(mysql, "alter table t1 add column c int");
574 check_mysql_rc(rc, mysql);
575
576 rc= mysql_stmt_execute(stmt);
577 diag("rc=%d %s", rc, mysql_stmt_error(stmt));
578 check_stmt_rc(rc, stmt);
579
580 if (verify_col_data(mysql, "t1", "year", "2014-01-01 01:01:01")) {
581 mysql_stmt_close(stmt);
582 rc= mysql_query(mysql, "drop table t1");
583 return FAIL;
584 }
585
586 mysql_stmt_close(stmt);
587
588 rc= mysql_query(mysql, "drop table t1");
589 check_mysql_rc(rc, mysql);
590 return OK;
591}
592
593
594/**
595 Test that long data parameters, as well as parameters
596 that were originally in a different character set, are
597 preserved in case of reprepare.
598*/
599
600static int test_wl4166_4(MYSQL *mysql)
601{
602 MYSQL_STMT *stmt;
603 int rc;
604 const char *stmt_text;
605 MYSQL_BIND bind_array[2];
606
607 /* Represented as numbers to keep UTF8 tools from clobbering them. */
608 const char *koi8= "\xee\xd5\x2c\x20\xda\xc1\x20\xd2\xd9\xc2\xc1\xcc\xcb\xd5";
609 const char *cp1251= "\xcd\xf3\x2c\x20\xe7\xe0\x20\xf0\xfb\xe1\xe0\xeb\xea\xf3";
610 char buf1[16], buf2[16];
611 ulong buf1_len, buf2_len;
612
613 if (mysql_get_server_version(mysql) < 50100) {
614 diag("Test requires MySQL Server version 5.1 or above");
615 return SKIP;
616 }
617
618 rc= mysql_query(mysql, "drop table if exists t1");
619 check_mysql_rc(rc, mysql);
620
621 /*
622 Create table with binary columns, set session character set to cp1251,
623 client character set to koi8, and make sure that there is conversion
624 on insert and no conversion on select
625 */
626 rc= mysql_query(mysql,
627 "create table t1 (c1 varbinary(255), c2 varbinary(255))");
628 check_mysql_rc(rc, mysql);
629 rc= mysql_query(mysql, "set character_set_client=koi8r, "
630 "character_set_connection=cp1251, "
631 "character_set_results=koi8r");
632 check_mysql_rc(rc, mysql);
633
634 memset(bind_array, '\0', sizeof(bind_array));
635
636 bind_array[0].buffer_type= MYSQL_TYPE_STRING;
637
638 bind_array[1].buffer_type= MYSQL_TYPE_STRING;
639 bind_array[1].buffer= (void *) koi8;
640 bind_array[1].buffer_length= (unsigned long)strlen(koi8);
641
642 stmt= mysql_stmt_init(mysql);
643 check_stmt_rc(rc, stmt);
644
645 stmt_text= "insert into t1 (c1, c2) values (?, ?)";
646
647 rc= mysql_stmt_prepare(stmt, SL(stmt_text));
648 check_stmt_rc(rc, stmt);
649
650 mysql_stmt_bind_param(stmt, bind_array);
651
652 mysql_stmt_send_long_data(stmt, 0, koi8, (unsigned long)strlen(koi8));
653
654 /* Cause a reprepare at statement execute */
655 rc= mysql_query(mysql, "alter table t1 add column d int");
656 check_mysql_rc(rc, mysql);
657
658 rc= mysql_stmt_execute(stmt);
659 check_stmt_rc(rc, stmt);
660
661 stmt_text= "select c1, c2 from t1";
662
663 /* c1 and c2 are binary so no conversion will be done on select */
664 rc= mysql_stmt_prepare(stmt, SL(stmt_text));
665 check_stmt_rc(rc, stmt);
666
667 rc= mysql_stmt_execute(stmt);
668 check_stmt_rc(rc, stmt);
669
670 bind_array[0].buffer= buf1;
671 bind_array[0].buffer_length= sizeof(buf1);
672 bind_array[0].length= &buf1_len;
673
674 bind_array[1].buffer= buf2;
675 bind_array[1].buffer_length= sizeof(buf2);
676 bind_array[1].length= &buf2_len;
677
678 mysql_stmt_bind_result(stmt, bind_array);
679
680 rc= mysql_stmt_fetch(stmt);
681 check_stmt_rc(rc, stmt);
682
683 FAIL_UNLESS(buf1_len == strlen(cp1251), "");
684 FAIL_UNLESS(buf2_len == strlen(cp1251), "");
685 FAIL_UNLESS(!memcmp(buf1, cp1251, buf1_len), "");
686 FAIL_UNLESS(!memcmp(buf2, cp1251, buf1_len), "");
687
688 rc= mysql_stmt_fetch(stmt);
689 FAIL_UNLESS(rc == MYSQL_NO_DATA, "");
690
691 mysql_stmt_close(stmt);
692
693 rc= mysql_query(mysql, "drop table t1");
694 check_mysql_rc(rc, mysql);
695 rc= mysql_query(mysql, "set names default");
696 check_mysql_rc(rc, mysql);
697 return OK;
698}
699
700/**
701 Test that COM_REFRESH issues a implicit commit.
702*/
703
704static int test_wl4284_1(MYSQL *mysql)
705{
706 int rc;
707 MYSQL_ROW row;
708 MYSQL_RES *result;
709
710 diag("Test temporarily disabled");
711 return SKIP;
712
713 if (mysql_get_server_version(mysql) < 60000) {
714 diag("Test requires MySQL Server version 6.0 or above");
715 return SKIP;
716 }
717
718 /* set AUTOCOMMIT to OFF */
719 rc= mysql_autocommit(mysql, FALSE);
720 check_mysql_rc(rc, mysql);
721
722 rc= mysql_query(mysql, "DROP TABLE IF EXISTS trans");
723 check_mysql_rc(rc, mysql);
724
725 rc= mysql_query(mysql, "CREATE TABLE trans (a INT) ENGINE=InnoDB");
726
727 if (mysql_errno(mysql) == ER_UNKNOWN_STORAGE_ENGINE)
728 {
729 diag("InnoDB not configured or available");
730 return SKIP;
731 }
732
733 check_mysql_rc(rc, mysql);
734
735
736 rc= mysql_query(mysql, "INSERT INTO trans VALUES(1)");
737 check_mysql_rc(rc, mysql);
738
739 rc= mysql_refresh(mysql, REFRESH_GRANT | REFRESH_TABLES);
740 check_mysql_rc(rc, mysql);
741
742 rc= mysql_rollback(mysql);
743 check_mysql_rc(rc, mysql);
744
745 rc= mysql_query(mysql, "SELECT * FROM trans");
746 check_mysql_rc(rc, mysql);
747
748 result= mysql_use_result(mysql);
749 FAIL_IF(!result, "Invalid result set");
750
751 row= mysql_fetch_row(result);
752 FAIL_IF(!row, "Can't fetch row");
753
754 mysql_free_result(result);
755
756 /* set AUTOCOMMIT to OFF */
757 rc= mysql_autocommit(mysql, FALSE);
758 check_mysql_rc(rc, mysql);
759
760 rc= mysql_query(mysql, "DROP TABLE trans");
761 check_mysql_rc(rc, mysql);
762
763 return OK;
764}
765
766static int test_bug49694(MYSQL *mysql)
767{
768 int rc;
769 int i;
770 FILE *fp;
771
772 rc= mysql_query(mysql, "DROP TABLE IF EXISTS enclist");
773 check_mysql_rc(rc, mysql);
774
775 rc= mysql_query(mysql, "CREATE TABLE `enclist` ("
776 " `pat_id` int(11) NOT NULL,"
777 " `episode_id` int(11) NOT NULL,"
778 " `enc_id` double NOT NULL,"
779 " PRIMARY KEY (`pat_id`,`episode_id`,`enc_id`)"
780 ") ENGINE=MyISAM DEFAULT CHARSET=latin1");
781 check_mysql_rc(rc, mysql);
782
783 fp= fopen("data.csv", "w");
784 FAIL_IF(!fp, "Can't open data.csv");
785
786 for (i=0; i < 100; i++)
787 fprintf (fp, "%.08d,%d,%f\r\n", 100 + i, i % 3 + 1, 60000.0 + i/100);
788 fclose(fp);
789
790 rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE enclist "
791 "FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'");
792 check_mysql_rc(rc, mysql);
793
794 rc= mysql_query(mysql, "DELETE FROM enclist");
795 check_mysql_rc(rc, mysql);
796
797 FAIL_IF(mysql_affected_rows(mysql) != 100, "Import failure. Expected 2 imported rows");
798
799 rc= mysql_query(mysql, "DROP TABLE enclist");
800 check_mysql_rc(rc, mysql);
801 return OK;
802}
803
804static int test_conc49(MYSQL *mysql)
805{
806 int rc;
807 MYSQL_RES *res;
808 int i;
809 FILE *fp= fopen("./sample.csv", "w");
810 for (i=1; i < 4; i++)
811 fprintf(fp, "\"%d\", \"%d\", \"%d\"\r\n", i, i, i);
812 fclose(fp);
813 rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc49");
814 check_mysql_rc(rc, mysql);
815 rc= mysql_query(mysql, "CREATE TABLE conc49 (a int, b int, c int) Engine=InnoDB DEFAULT CHARSET=latin1");
816 check_mysql_rc(rc, mysql);
817 rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE './sample.csv' INTO TABLE conc49 FIELDS ESCAPED BY ' ' TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\r\n'");
818 check_mysql_rc(rc, mysql);
819
820 rc= mysql_query(mysql, "SELECT a FROM conc49");
821 check_mysql_rc(rc, mysql);
822 res= mysql_store_result(mysql);
823 rc= (int)mysql_num_rows(res);
824 mysql_free_result(res);
825 FAIL_IF(rc != 3, "3 rows expected");
826 rc= mysql_query(mysql, "DROP TABLE IF EXISTS conc49");
827 check_mysql_rc(rc, mysql);
828 return OK;
829}
830
831static int test_ldi_path(MYSQL *mysql)
832{
833 int rc;
834
835 rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
836 check_mysql_rc(rc, mysql);
837
838 rc= mysql_query(mysql, "CREATE TABLE t1 (a int)");
839 check_mysql_rc(rc, mysql);
840
841#ifdef _WIN32
842 rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE 'X:/non_existing_path/data.csv' INTO TABLE t1 "
843 "FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'");
844#else
845 rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE '/non_existing_path/data.csv' INTO TABLE t1 "
846 "FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'");
847#endif
848 FAIL_IF(rc== 0, "Error expected");
849 diag("Error: %d", mysql_errno(mysql));
850 FAIL_IF(mysql_errno(mysql) == 0, "Error expected");
851
852 rc= mysql_query(mysql, "DROP TABLE t1");
853 check_mysql_rc(rc, mysql);
854 return OK;
855}
856
857#if _WIN32
858static int test_conc44(MYSQL *mysql)
859{
860 char query[1024];
861 char *a_filename= "æøå.csv";
862 int rc;
863 int i;
864 FILE *fp;
865
866 rc= mysql_set_character_set(mysql, "latin1");
867 check_mysql_rc(rc, mysql);
868
869 rc= mysql_query(mysql, "DROP TABLE IF EXISTS enclist");
870 check_mysql_rc(rc, mysql);
871
872 rc= mysql_query(mysql, "CREATE TABLE `enclist` ("
873 " `pat_id` int(11) NOT NULL,"
874 " `episode_id` int(11) NOT NULL,"
875 " `enc_id` double NOT NULL,"
876 " PRIMARY KEY (`pat_id`,`episode_id`,`enc_id`)"
877 ") ENGINE=MyISAM DEFAULT CHARSET=latin1");
878 check_mysql_rc(rc, mysql);
879
880 fp= fopen(a_filename, "w");
881 FAIL_IF(!fp, "Can't open file");
882
883 for (i=0; i < 100; i++)
884 fprintf (fp, "%.08d,%d,%f\r\n", 100 + i, i % 3 + 1, 60000.0 + i/100);
885 fclose(fp);
886
887 sprintf(query, "LOAD DATA LOCAL INFILE '%s' INTO TABLE enclist "
888 "FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'", a_filename);
889 rc= mysql_query(mysql, query);
890 check_mysql_rc(rc, mysql);
891
892 rc= mysql_query(mysql, "DELETE FROM enclist");
893 check_mysql_rc(rc, mysql);
894
895 FAIL_IF(mysql_affected_rows(mysql) != 100, "Import failure. Expected 2 imported rows");
896
897 rc= mysql_query(mysql, "DROP TABLE enclist");
898 check_mysql_rc(rc, mysql);
899 return OK;
900}
901#endif
902
903static int test_connect_attrs(MYSQL *my)
904{
905 MYSQL *mysql;
906 MYSQL_RES *result;
907 int rc, len;
908
909 rc= mysql_query(my, "SELECT * FROM performance_schema.session_connect_attrs LIMIT 1");
910 if (rc != 0)
911 {
912 diag("Server doesn't support connection attributes");
913 return SKIP;
914 }
915
916 result= mysql_store_result(my);
917 /* MariaDB Connector/C already sent connection attrs after handshake. So if the table is
918 empty, it indicates that the performance schema is disabled */
919 if (!mysql_num_rows(result))
920 {
921 diag("skip: performance_schema not enabled");
922 mysql_free_result(result);
923 return SKIP;
924 }
925 mysql_free_result(result);
926
927 mysql= mysql_init(NULL);
928
929 mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo0", "bar0");
930 mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo1", "bar1");
931 mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo2", "bar2");
932
933 FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema,
934 port, socketname, 0), mysql_error(my));
935
936 if (!(mysql->server_capabilities & CLIENT_CONNECT_ATTRS))
937 {
938 diag("Server doesn't support connection attributes");
939 return SKIP;
940 }
941
942 rc= mysql_query(mysql, "SELECT * FROM performance_schema.session_connect_attrs where attr_name like 'foo%'");
943 check_mysql_rc(rc, mysql);
944 result= mysql_store_result(mysql);
945 rc= (int)mysql_num_rows(result);
946 mysql_free_result(result);
947
948 mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_RESET, NULL);
949 mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo0", "bar0");
950 mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo1", "bar1");
951 mysql_options4(mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "foo2", "bar2");
952 mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "foo0");
953 mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "foo1");
954 mysql_options(mysql, MYSQL_OPT_CONNECT_ATTR_DELETE, "foo2");
955
956 len= (int)mysql->options.extension->connect_attrs_len;
957
958 mysql_close(mysql);
959
960 FAIL_IF(rc < 3, "Expected 3 or more rows");
961 FAIL_IF(len != 0, "Expected connection_attr_len=0");
962
963 return OK;
964}
965
966static int test_conc_114(MYSQL *mysql)
967{
968 if (mysql_client_find_plugin(mysql, "foo", 0))
969 {
970 diag("Null pointer expected");
971 return FAIL;
972 }
973 diag("Error: %s", mysql_error(mysql));
974 return OK;
975}
976
977/* run with valgrind */
978static int test_conc117(MYSQL *unused __attribute__((unused)))
979{
980 my_bool reconnect= 1;
981 MYSQL *my= mysql_init(NULL);
982 FAIL_IF(!my_test_connect(my, hostname, username, password, schema,
983 port, socketname, 0), mysql_error(my));
984
985 mysql_kill(my, mysql_thread_id(my));
986
987 mysql_options(my, MYSQL_OPT_RECONNECT, &reconnect);
988
989 mysql_query(my, "SET @a:=1");
990 mysql_close(my);
991
992 return OK;
993}
994
995static int test_read_timeout(MYSQL *unused __attribute__((unused)))
996{
997 int timeout= 5, rc;
998 MYSQL *my= mysql_init(NULL);
999 mysql_options(my, MYSQL_OPT_READ_TIMEOUT, &timeout);
1000 FAIL_IF(!my_test_connect(my, hostname, username, password, schema,
1001 port, socketname, 0), mysql_error(my));
1002
1003 rc= mysql_query(my, "SELECT SLEEP(50)");
1004
1005 FAIL_IF(rc == 0, "error expected");
1006 diag("error: %s", mysql_error(my));
1007
1008 mysql_close(my);
1009
1010 return OK;
1011}
1012
1013#ifdef HAVE_REMOTEIO
1014void *remote_plugin;
1015static int test_remote1(MYSQL *mysql)
1016{
1017 int rc;
1018
1019 remote_plugin= (void *)mysql_client_find_plugin(mysql, "remote_io", MARIADB_CLIENT_REMOTEIO_PLUGIN);
1020 if (!remote_plugin)
1021 {
1022 diag("skip - no remote io plugin available");
1023 diag("error: %s", mysql_error(mysql));
1024 return SKIP;
1025 }
1026
1027 rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
1028 check_mysql_rc(rc, mysql);
1029
1030 rc= mysql_query(mysql, "CREATE TABLE t1 (a text)");
1031 check_mysql_rc(rc, mysql);
1032
1033 rc= mysql_query(mysql, "LOAD DATA LOCAL INFILE 'http://www.example.com' INTO TABLE t1");
1034 if (rc && mysql_errno(mysql) == 2058)
1035 {
1036 diag("remote_io plugin not available");
1037 return SKIP;
1038 }
1039 check_mysql_rc(rc, mysql);
1040 return OK;
1041}
1042
1043static int test_remote2(MYSQL *my)
1044{
1045 MYSQL *mysql;
1046
1047 if (!remote_plugin)
1048 {
1049 diag("skip - no remote io plugin available");
1050 return SKIP;
1051 }
1052 mysql= mysql_init(NULL);
1053
1054 mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "http://localhost/test.cnf");
1055 mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "test");
1056 my_test_connect(mysql, hostname, username, password, schema,
1057 0, socketname, 0), mysql_error(my);
1058 diag("port: %d", mysql->port);
1059 mysql_close(mysql);
1060 return OK;
1061}
1062#endif
1063
1064#ifndef _WIN32
1065static int test_mdev12965(MYSQL *unused __attribute__((unused)))
1066{
1067 MYSQL *mysql;
1068 my_bool reconnect = 0;
1069 FILE *fp= NULL;
1070 const char *env= getenv("MYSQL_TMP_DIR");
1071 char cnf_file1[FN_REFLEN + 1];
1072
1073 if (travis_test)
1074 return SKIP;
1075
1076 if (!env)
1077 env= "/tmp";
1078
1079 setenv("HOME", env, 1);
1080
1081 snprintf(cnf_file1, FN_REFLEN, "%s%c.my.cnf", env, FN_LIBCHAR);
1082
1083 diag("Config file: %s", cnf_file1);
1084
1085 FAIL_IF(!access(cnf_file1, R_OK), "access");
1086
1087 mysql= mysql_init(NULL);
1088 fp= fopen(cnf_file1, "w");
1089 FAIL_IF(!fp, "fopen");
1090
1091 fprintf(fp, "[client]\ndefault-character-set=latin2\nreconnect=1\n");
1092 fclose(fp);
1093
1094 mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "");
1095 my_test_connect(mysql, hostname, username, password,
1096 schema, 0, socketname, 0);
1097
1098 remove(cnf_file1);
1099
1100 FAIL_IF(strcmp(mysql_character_set_name(mysql), "latin2"), "expected charset latin2");
1101 mysql_get_optionv(mysql, MYSQL_OPT_RECONNECT, &reconnect);
1102 FAIL_IF(reconnect != 1, "expected reconnect=1");
1103 mysql_close(mysql);
1104 return OK;
1105}
1106#endif
1107
1108static int test_get_info(MYSQL *mysql)
1109{
1110 size_t sval;
1111 unsigned int ival;
1112 char *cval;
1113 int rc;
1114 MY_CHARSET_INFO cs;
1115 MARIADB_CHARSET_INFO *ci;
1116 char **errors;
1117
1118 rc= mariadb_get_infov(mysql, MARIADB_MAX_ALLOWED_PACKET, &sval);
1119 FAIL_IF(rc, "mysql_get_info failed");
1120 diag("max_allowed_packet: %lu", (unsigned long)sval);
1121 rc= mariadb_get_infov(mysql, MARIADB_NET_BUFFER_LENGTH, &sval);
1122 FAIL_IF(rc, "mysql_get_info failed");
1123 diag("net_buffer_length: %lu", (unsigned long)sval);
1124 rc= mariadb_get_infov(mysql, MARIADB_CLIENT_VERSION_ID, &sval);
1125 FAIL_IF(rc, "mysql_get_info failed");
1126 diag("client_version_id: %lu", (unsigned long)sval);
1127 rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_VERSION_ID, &sval);
1128 FAIL_IF(rc, "mysql_get_info failed");
1129 diag("server_version_id: %lu", (unsigned long)sval);
1130 rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_MARIADB_CHARSET_INFO, &cs);
1131 FAIL_IF(rc, "mysql_get_info failed");
1132 diag("charset name: %s", cs.csname);
1133 rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_PVIO_TYPE, &ival);
1134 FAIL_IF(rc, "mysql_get_info failed");
1135 diag("connection type: %d", ival);
1136 rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_PROTOCOL_VERSION_ID, &ival);
1137 FAIL_IF(rc, "mysql_get_info failed");
1138 diag("protocol_version: %d", ival);
1139 rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_TYPE, &cval);
1140 FAIL_IF(rc, "mysql_get_info failed");
1141 diag("server_type: %s", cval);
1142 rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_VERSION, &cval);
1143 FAIL_IF(rc, "mysql_get_info failed");
1144 diag("server_version: %s", cval);
1145 rc= mariadb_get_infov(mysql, MARIADB_CLIENT_VERSION, &cval);
1146 FAIL_IF(rc, "mysql_get_info failed");
1147 diag("client_version: %s", cval);
1148 rc= mariadb_get_infov(mysql, MARIADB_CHARSET_NAME, &ci, "utf8");
1149 FAIL_IF(rc, "mysql_get_info failed");
1150 diag("charset_name: %s", ci->csname);
1151 diag("charset_nr: %d", ci->nr);
1152 rc= mariadb_get_infov(mysql, MARIADB_CHARSET_ID, &ci, 63);
1153 FAIL_IF(rc, "mysql_get_info failed");
1154 diag("charset_name: %s", ci->csname);
1155 rc= mariadb_get_infov(mysql, MARIADB_CLIENT_ERRORS, &errors);
1156 FAIL_IF(rc, "mysql_get_info failed");
1157 diag("error[0]: %s", errors[0]);
1158 rc= mysql_query(mysql, "DROP TABLE IF exists t1");
1159 check_mysql_rc(rc, mysql);
1160 rc= mysql_query(mysql, "CREATE TABLE t1 (a int)");
1161 check_mysql_rc(rc, mysql);
1162 rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1),(2)");
1163 check_mysql_rc(rc, mysql);
1164 rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_INFO, &cval);
1165 FAIL_IF(rc, "mysql_get_info failed");
1166 diag("mariadb_info: %s", cval);
1167 return OK;
1168}
1169
1170static int test_zerofill(MYSQL *mysql)
1171{
1172 int rc;
1173 MYSQL_ROW row;
1174 MYSQL_RES *res;
1175
1176 rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
1177 check_mysql_rc(rc, mysql);
1178
1179 rc= mysql_query(mysql, "CREATE TABLE t1 (a int(10) zerofill)");
1180 check_mysql_rc(rc, mysql);
1181
1182 rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)");
1183 check_mysql_rc(rc, mysql);
1184
1185 rc= mysql_query(mysql, "SELECT a FROM t1");
1186 check_mysql_rc(rc, mysql);
1187
1188 if ((res= mysql_store_result(mysql)))
1189 {
1190 row= mysql_fetch_row(res);
1191 diag("zerofill: %s", row[0]);
1192 mysql_free_result(res);
1193 }
1194 return OK;
1195}
1196
1197static int test_server_status(MYSQL *mysql)
1198{
1199 int rc;
1200 unsigned int server_status;
1201 MYSQL_STMT *stmt;
1202
1203 if (mysql_get_server_version(mysql) < 100200)
1204 return SKIP;
1205
1206 stmt= mysql_stmt_init(mysql);
1207
1208 rc= mysql_autocommit(mysql, 1);
1209 mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status);
1210 FAIL_IF(!(server_status & SERVER_STATUS_AUTOCOMMIT),
1211 "autocommit flag not set");
1212
1213 rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
1214 check_mysql_rc(rc, mysql);
1215
1216 rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b int)");
1217 check_mysql_rc(rc, mysql);
1218
1219 rc= mysql_query(mysql, "INSERT INTO t1 (a) VALUES (1),(2),(3),(4),(5)");
1220 check_mysql_rc(rc, mysql);
1221
1222 rc= mysql_query(mysql, "UPDATE t1 SET a=9 WHERE a=8");
1223 check_mysql_rc(rc, mysql);
1224
1225 mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status);
1226 FAIL_IF(!(server_status & SERVER_QUERY_NO_INDEX_USED), "autocommit flag not set");
1227
1228 rc= mysql_query(mysql, "CREATE SCHEMA test_tmp");
1229 check_mysql_rc(rc, mysql);
1230
1231 rc= mysql_select_db(mysql, "test_tmp");
1232 check_mysql_rc(rc, mysql);
1233
1234 rc= mysql_query(mysql, "DROP SCHEMA test_tmp");
1235 check_mysql_rc(rc, mysql);
1236
1237 mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_STATUS, &server_status);
1238 FAIL_IF(!(server_status & SERVER_STATUS_DB_DROPPED),
1239 "DB_DROP flag not set");
1240
1241 FAIL_IF(!(server_status & SERVER_SESSION_STATE_CHANGED),
1242 "SESSION_STATE_CHANGED flag not set");
1243
1244 rc= mysql_select_db(mysql, schema);
1245 check_mysql_rc(rc, mysql);
1246
1247 mysql_stmt_close(stmt);
1248
1249 return OK;
1250}
1251
1252static int test_wl6797(MYSQL *mysql)
1253{
1254 MYSQL_STMT *stmt;
1255 int rc;
1256 const char *stmt_text;
1257 my_ulonglong res;
1258
1259 if (mysql_get_server_version(mysql) < 50703 ||
1260 (mariadb_connection(mysql) && mysql_get_server_version(mysql) < 100203))
1261 {
1262 diag("Skipping test_wl6797: "
1263 "tested feature does not exist in versions before MySQL 5.7.3 and MariaDB 10.2\n");
1264 return OK;
1265 }
1266 /* clean up the session */
1267 rc= mysql_reset_connection(mysql);
1268 FAIL_UNLESS(rc == 0, "");
1269
1270 /* do prepare of a query */
1271 mysql_query(mysql, "use test");
1272 mysql_query(mysql, "DROP TABLE IF EXISTS t1");
1273 mysql_query(mysql, "CREATE TABLE t1 (a int)");
1274
1275 stmt= mysql_stmt_init(mysql);
1276 stmt_text= "INSERT INTO t1 VALUES (1), (2)";
1277
1278 rc= mysql_stmt_prepare(stmt, SL(stmt_text));
1279 check_mysql_rc(rc, mysql);
1280
1281 /* Execute the insert statement */
1282 rc= mysql_stmt_execute(stmt);
1283 check_mysql_rc(rc, mysql);
1284
1285 /*
1286 clean the session this should remove the prepare statement
1287 from the cache.
1288 */
1289 rc= mysql_reset_connection(mysql);
1290 FAIL_UNLESS(rc == 0, "");
1291
1292 /* this below stmt should report error */
1293 rc= mysql_stmt_execute(stmt);
1294 FAIL_IF(rc == 0, "");
1295
1296 /*
1297 bug#17653288: MYSQL_RESET_CONNECTION DOES NOT RESET LAST_INSERT_ID
1298 */
1299
1300 mysql_query(mysql, "DROP TABLE IF EXISTS t2");
1301 rc= mysql_query(mysql, "CREATE TABLE t2 (a int NOT NULL PRIMARY KEY"\
1302 " auto_increment)");
1303 check_mysql_rc(rc, mysql);
1304 rc= mysql_query(mysql, "INSERT INTO t2 VALUES (null)");
1305 check_mysql_rc(rc, mysql);
1306 res= mysql_insert_id(mysql);
1307 FAIL_UNLESS(res == 1, "");
1308 rc= mysql_reset_connection(mysql);
1309 FAIL_UNLESS(rc == 0, "");
1310 res= mysql_insert_id(mysql);
1311 FAIL_UNLESS(res == 0, "");
1312
1313 rc= mysql_query(mysql, "INSERT INTO t2 VALUES (last_insert_id(100))");
1314 check_mysql_rc(rc, mysql);
1315 res= mysql_insert_id(mysql);
1316 FAIL_UNLESS(res == 100, "");
1317 rc= mysql_reset_connection(mysql);
1318 FAIL_UNLESS(rc == 0, "");
1319 res= mysql_insert_id(mysql);
1320 FAIL_UNLESS(res == 0, "");
1321
1322 mysql_query(mysql, "DROP TABLE IF EXISTS t1");
1323 mysql_query(mysql, "DROP TABLE IF EXISTS t2");
1324 mysql_stmt_close(stmt);
1325 return OK;
1326}
1327
1328struct my_tests_st my_tests[] = {
1329#ifndef _WIN32
1330 {"test_mdev12965", test_mdev12965, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1331#endif
1332 {"test_wl6797", test_wl6797, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1333 {"test_server_status", test_server_status, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1334 {"test_read_timeout", test_read_timeout, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1335 {"test_zerofill", test_zerofill, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1336#ifdef HAVE_REMOTEIO
1337 {"test_remote1", test_remote1, TEST_CONNECTION_NEW, 0, NULL, NULL},
1338 {"test_remote2", test_remote2, TEST_CONNECTION_NEW, 0, NULL, NULL},
1339#endif
1340 {"test_get_info", test_get_info, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1341 {"test_conc117", test_conc117, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1342 {"test_conc_114", test_conc_114, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1343 {"test_connect_attrs", test_connect_attrs, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1344 {"test_conc49", test_conc49, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1345 {"test_bug28075", test_bug28075, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1346 {"test_bug28505", test_bug28505, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1347 {"test_debug_example", test_debug_example, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1348 {"test_bug29692", test_bug29692, TEST_CONNECTION_NEW, CLIENT_FOUND_ROWS, NULL, NULL},
1349 {"test_bug31418", test_bug31418, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
1350 {"test_frm_bug", test_frm_bug, TEST_CONNECTION_NEW, 0, NULL, NULL},
1351 {"test_wl4166_1", test_wl4166_1, TEST_CONNECTION_NEW, 0, NULL, NULL},
1352 {"test_wl4166_2", test_wl4166_2, TEST_CONNECTION_NEW, 0, NULL, NULL},
1353 {"test_wl4166_3", test_wl4166_3, TEST_CONNECTION_NEW, 0, NULL, NULL},
1354 {"test_wl4166_4", test_wl4166_4, TEST_CONNECTION_NEW, 0, NULL, NULL},
1355 {"test_wl4284_1", test_wl4284_1, TEST_CONNECTION_NEW, 0, NULL, NULL},
1356 {"test_bug49694", test_bug49694, TEST_CONNECTION_NEW, 0, NULL, NULL},
1357 {"test_ldi_path", test_ldi_path, TEST_CONNECTION_NEW, 0, NULL, NULL},
1358#ifdef _WIN32
1359 {"test_conc44", test_conc44, TEST_CONNECTION_NEW, 0, NULL, NULL},
1360#endif
1361 {NULL, NULL, 0, 0, NULL, 0}
1362};
1363
1364
1365int main(int argc, char **argv)
1366{
1367 if (argc > 1)
1368 get_options(argc, argv);
1369
1370 get_envvars();
1371
1372 run_tests(my_tests);
1373
1374 return(exit_status());
1375}
1376