27 #include "mysql_client_fw.c"
31 static void client_query()
35 myheader(
"client_query");
37 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
40 rc= mysql_query(mysql,
"CREATE TABLE t1("
41 "id int primary key auto_increment, "
45 rc= mysql_query(mysql,
"CREATE TABLE t1(id int, name varchar(20))");
48 rc= mysql_query(mysql,
"INSERT INTO t1(name) VALUES('mysql')");
51 rc= mysql_query(mysql,
"INSERT INTO t1(name) VALUES('monty')");
54 rc= mysql_query(mysql,
"INSERT INTO t1(name) VALUES('venu')");
57 rc= mysql_query(mysql,
"INSERT INTO t1(name) VALUES('deleted')");
60 rc= mysql_query(mysql,
"INSERT INTO t1(name) VALUES('deleted')");
63 rc= mysql_query(mysql,
"UPDATE t1 SET name= 'updated' "
64 "WHERE name= 'deleted'");
67 rc= mysql_query(mysql,
"UPDATE t1 SET id= 3 WHERE name= 'updated'");
70 myquery(mysql_query(mysql,
"drop table t1"));
76 static void client_store_result()
81 myheader(
"client_store_result");
83 rc= mysql_query(mysql,
"SELECT * FROM t1");
87 result= mysql_store_result(mysql);
90 (void) my_process_result_set(result);
91 mysql_free_result(result);
97 static void client_use_result()
101 myheader(
"client_use_result");
103 rc= mysql_query(mysql,
"SELECT * FROM t1");
107 result= mysql_use_result(mysql);
110 (void) my_process_result_set(result);
111 mysql_free_result(result);
117 static void test_debug_example()
122 myheader(
"test_debug_example");
124 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_debug_example");
127 rc= mysql_query(mysql,
"CREATE TABLE test_debug_example("
128 "id INT PRIMARY KEY AUTO_INCREMENT, "
129 "name VARCHAR(20), xxx INT)");
132 rc= mysql_query(mysql,
"INSERT INTO test_debug_example (name) "
136 rc= mysql_query(mysql,
"UPDATE test_debug_example SET name='updated' "
137 "WHERE name='deleted'");
140 rc= mysql_query(mysql,
"SELECT * FROM test_debug_example where name='mysql'");
143 result= mysql_use_result(mysql);
146 (void) my_process_result_set(result);
147 mysql_free_result(result);
149 rc= mysql_query(mysql,
"DROP TABLE test_debug_example");
156 static void test_tran_bdb()
162 myheader(
"test_tran_bdb");
165 rc= mysql_autocommit(mysql, FALSE);
168 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS my_demo_transaction");
173 rc= mysql_query(mysql,
"CREATE TABLE my_demo_transaction( "
174 "col1 int , col2 varchar(30)) ENGINE= BDB");
178 rc= mysql_query(mysql,
"INSERT INTO my_demo_transaction VALUES(10, 'venu')");
181 rc= mysql_commit(mysql);
185 rc= mysql_query(mysql,
"INSERT INTO my_demo_transaction VALUES(20, 'mysql')");
188 rc= mysql_rollback(mysql);
192 rc= mysql_query(mysql,
"DELETE FROM my_demo_transaction WHERE col1= 10");
195 rc= mysql_rollback(mysql);
199 rc= mysql_query(mysql,
"SELECT * FROM my_demo_transaction");
203 result= mysql_store_result(mysql);
206 (void) my_process_result_set(result);
207 mysql_free_result(result);
210 rc= mysql_query(mysql,
"SELECT * FROM my_demo_transaction");
214 result= mysql_use_result(mysql);
217 row= mysql_fetch_row(result);
220 row= mysql_fetch_row(result);
223 mysql_free_result(result);
224 mysql_autocommit(mysql, TRUE);
230 static void test_tran_innodb()
236 myheader(
"test_tran_innodb");
239 rc= mysql_autocommit(mysql, FALSE);
242 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS my_demo_transaction");
246 rc= mysql_query(mysql,
"CREATE TABLE my_demo_transaction(col1 int, "
247 "col2 varchar(30)) ENGINE= InnoDB");
251 rc= mysql_query(mysql,
"INSERT INTO my_demo_transaction VALUES(10, 'venu')");
254 rc= mysql_commit(mysql);
258 rc= mysql_query(mysql,
"INSERT INTO my_demo_transaction VALUES(20, 'mysql')");
261 rc= mysql_rollback(mysql);
265 rc= mysql_query(mysql,
"DELETE FROM my_demo_transaction WHERE col1= 10");
268 rc= mysql_rollback(mysql);
272 rc= mysql_query(mysql,
"SELECT * FROM my_demo_transaction");
276 result= mysql_store_result(mysql);
279 (void) my_process_result_set(result);
280 mysql_free_result(result);
283 rc= mysql_query(mysql,
"SELECT * FROM my_demo_transaction");
287 result= mysql_use_result(mysql);
290 row= mysql_fetch_row(result);
293 row= mysql_fetch_row(result);
296 mysql_free_result(result);
297 mysql_autocommit(mysql, TRUE);
303 static void test_prepare_insert_update()
309 "CREATE TABLE t1 (a INT, b INT, c INT, UNIQUE (A), UNIQUE(B))",
310 "INSERT t1 VALUES (1,2,10), (3,4,20)",
311 "INSERT t1 VALUES (5,6,30), (7,4,40), (8,9,60) ON DUPLICATE KEY UPDATE c=c+100",
313 "INSERT t1 SET a=5 ON DUPLICATE KEY UPDATE b=0",
315 "INSERT t1 VALUES (2,1,11), (7,4,40) ON DUPLICATE KEY UPDATE c=c+VALUES(a)",
317 const char **cur_query;
319 myheader(
"test_prepare_insert_update");
321 for (cur_query= testcase; *cur_query; cur_query++)
323 char query[MAX_TEST_QUERY_LENGTH];
324 printf(
"\nRunning query: %s", *cur_query);
325 strmov(query, *cur_query);
326 stmt= mysql_simple_prepare(mysql, query);
329 verify_param_count(stmt, 0);
330 rc= mysql_stmt_execute(stmt);
332 check_execute(stmt, rc);
338 printf(
"\nExecuting last statement again");
339 rc= mysql_stmt_execute(stmt);
340 check_execute(stmt, rc);
341 rc= mysql_stmt_execute(stmt);
342 check_execute(stmt, rc);
345 mysql_stmt_close(stmt);
348 rc= mysql_commit(mysql);
354 static void test_prepare_simple()
358 char query[MAX_TEST_QUERY_LENGTH];
360 myheader(
"test_prepare_simple");
362 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_prepare_simple");
365 rc= mysql_query(mysql,
"CREATE TABLE test_prepare_simple("
366 "id int, name varchar(50))");
370 strmov(query,
"INSERT INTO test_prepare_simple VALUES(?, ?)");
371 stmt= mysql_simple_prepare(mysql, query);
374 verify_param_count(stmt, 2);
375 mysql_stmt_close(stmt);
378 strmov(query,
"UPDATE test_prepare_simple SET id=? "
379 "WHERE id=? AND CONVERT(name USING utf8)= ?");
380 stmt= mysql_simple_prepare(mysql, query);
383 verify_param_count(stmt, 3);
384 mysql_stmt_close(stmt);
387 strmov(query,
"DELETE FROM test_prepare_simple WHERE id=10");
388 stmt= mysql_simple_prepare(mysql, query);
391 verify_param_count(stmt, 0);
393 rc= mysql_stmt_execute(stmt);
394 check_execute(stmt, rc);
395 mysql_stmt_close(stmt);
398 strmov(query,
"DELETE FROM test_prepare_simple WHERE id=?");
399 stmt= mysql_simple_prepare(mysql, query);
402 verify_param_count(stmt, 1);
404 mysql_stmt_close(stmt);
407 strmov(query,
"SELECT * FROM test_prepare_simple WHERE id=? "
408 "AND CONVERT(name USING utf8)= ?");
409 stmt= mysql_simple_prepare(mysql, query);
412 verify_param_count(stmt, 2);
414 mysql_stmt_close(stmt);
417 rc= mysql_commit(mysql);
423 #define FILE_PATH_SIZE 4096
425 char mct_log_file_path[FILE_PATH_SIZE];
426 FILE *mct_log_file= NULL;
428 void mct_start_logging(
const char *test_case_name)
430 const char *tmp_dir= getenv(
"MYSQL_TMP_DIR");
434 printf(
"Warning: MYSQL_TMP_DIR is not set. Logging is disabled.\n");
440 printf(
"Warning: can not start logging for test case '%s' "
441 "because log is already open\n",
442 (
const char *) test_case_name);
451 if (strlen(tmp_dir) + strlen(test_case_name) + 10 > FILE_PATH_SIZE)
453 printf(
"Warning: MYSQL_TMP_DIR is too long. Logging is disabled.\n");
457 my_snprintf(mct_log_file_path, FILE_PATH_SIZE,
459 (
const char *) tmp_dir,
460 (
const char *) test_case_name);
462 mct_log_file= my_fopen(mct_log_file_path, O_WRONLY | O_BINARY, MYF(MY_WME));
466 printf(
"Warning: can not open log file (%s): %s. Logging is disabled.\n",
467 (
const char *) mct_log_file_path,
468 (
const char *) strerror(errno));
473 void mct_log(
const char *format, ...)
476 va_start(args, format);
477 vprintf(format, args);
483 va_start(args, format);
484 vfprintf(mct_log_file, format, args);
494 my_fclose(mct_log_file, MYF(0));
498 #define WL4435_NUM_PARAMS 10
499 #define WL4435_STRING_SIZE 30
501 static void test_wl4435()
505 char query[MAX_TEST_QUERY_LENGTH];
507 char str_data[20][WL4435_STRING_SIZE];
509 char dec_data[20][WL4435_STRING_SIZE];
511 ulong str_length= WL4435_STRING_SIZE;
517 myheader(
"test_wl4435");
518 mct_start_logging(
"test_wl4435");
520 rc= mysql_query(mysql,
"DROP PROCEDURE IF EXISTS p1");
523 rc= mysql_query(mysql,
"DROP PROCEDURE IF EXISTS p2");
526 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
529 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t2");
532 rc= mysql_query(mysql,
"CREATE TABLE t1(a1 INT, a2 CHAR(32), "
533 " a3 DOUBLE(4, 2), a4 DECIMAL(3, 1))");
536 rc= mysql_query(mysql,
"CREATE TABLE t2(b0 INT, b1 INT, b2 CHAR(32), "
537 " b3 DOUBLE(4, 2), b4 DECIMAL(3, 1))");
540 rc= mysql_query(mysql,
"INSERT INTO t1 VALUES"
541 "(1, '11', 12.34, 56.7), "
542 "(2, '12', 56.78, 90.1), "
543 "(3, '13', 23.45, 67.8)");
546 rc= mysql_query(mysql,
"INSERT INTO t2 VALUES"
547 "(100, 10, '110', 70.70, 10.1), "
548 "(200, 20, '120', 80.80, 20.2), "
549 "(300, 30, '130', 90.90, 30.3)");
552 rc= mysql_query(mysql,
553 "CREATE PROCEDURE p1("
555 " OUT v_str_1 CHAR(32), "
556 " OUT v_dbl_1 DOUBLE(4, 2), "
557 " OUT v_dec_1 DECIMAL(6, 3), "
560 " INOUT v_str_2 CHAR(64), "
561 " INOUT v_dbl_2 DOUBLE(5, 3), "
562 " INOUT v_dec_2 DECIMAL(7, 4), "
563 " INOUT v_int_2 INT)"
567 " SET v_str_1 = 'test_1'; "
568 " SET v_dbl_1 = 12.34; "
569 " SET v_dec_1 = 567.891; "
570 " SET v_int_1 = 2345; "
571 " SET v_str_2 = 'test_2'; "
572 " SET v_dbl_2 = 67.891; "
573 " SET v_dec_2 = 234.6789; "
574 " SET v_int_2 = 6789; "
575 " SELECT * FROM t1; "
576 " SELECT * FROM t2; "
580 rc= mysql_query(mysql,
581 "CREATE PROCEDURE p2("
582 " IN i1 VARCHAR(255) CHARACTER SET koi8r, "
583 " OUT o1 VARCHAR(255) CHARACTER SET cp1251, "
584 " OUT o2 VARBINARY(255)) "
591 strmov(query,
"CALL p1(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
592 stmt= mysql_simple_prepare(mysql, query);
597 memset(ps_params, 0,
sizeof (ps_params));
601 ps_params[0].buffer_type= MYSQL_TYPE_LONG;
602 ps_params[0].buffer= (
char *) &int_data[0];
603 ps_params[0].length= 0;
604 ps_params[0].is_null= 0;
608 ps_params[1].buffer_type= MYSQL_TYPE_STRING;
609 ps_params[1].buffer= (
char *) str_data[0];
610 ps_params[1].buffer_length= WL4435_STRING_SIZE;
611 ps_params[1].length= &str_length;
612 ps_params[1].is_null= 0;
616 ps_params[2].buffer_type= MYSQL_TYPE_DOUBLE;
617 ps_params[2].buffer= (
char *) &dbl_data[0];
618 ps_params[2].length= 0;
619 ps_params[2].is_null= 0;
623 ps_params[3].buffer_type= MYSQL_TYPE_NEWDECIMAL;
624 ps_params[3].buffer= (
char *) dec_data[0];
625 ps_params[3].buffer_length= WL4435_STRING_SIZE;
626 ps_params[3].length= 0;
627 ps_params[3].is_null= 0;
631 ps_params[4].buffer_type= MYSQL_TYPE_LONG;
632 ps_params[4].buffer= (
char *) &int_data[0];
633 ps_params[4].length= 0;
634 ps_params[4].is_null= 0;
638 ps_params[5].buffer_type= MYSQL_TYPE_LONG;
639 ps_params[5].buffer= (
char *) &int_data[0];
640 ps_params[5].length= 0;
641 ps_params[5].is_null= 0;
645 ps_params[6].buffer_type= MYSQL_TYPE_STRING;
646 ps_params[6].buffer= (
char *) str_data[0];
647 ps_params[6].buffer_length= WL4435_STRING_SIZE;
648 ps_params[6].length= &str_length;
649 ps_params[6].is_null= 0;
653 ps_params[7].buffer_type= MYSQL_TYPE_DOUBLE;
654 ps_params[7].buffer= (
char *) &dbl_data[0];
655 ps_params[7].length= 0;
656 ps_params[7].is_null= 0;
660 ps_params[8].buffer_type= MYSQL_TYPE_DECIMAL;
661 ps_params[8].buffer= (
char *) dec_data[0];
662 ps_params[8].buffer_length= WL4435_STRING_SIZE;
663 ps_params[8].length= 0;
664 ps_params[8].is_null= 0;
668 ps_params[9].buffer_type= MYSQL_TYPE_LONG;
669 ps_params[9].buffer= (
char *) &int_data[0];
670 ps_params[9].length= 0;
671 ps_params[9].is_null= 0;
675 rc= mysql_stmt_bind_param(stmt, ps_params);
679 for (exec_counter= 0; exec_counter < 3; ++exec_counter)
685 mct_log(
"\nexec_counter: %d\n", (
int) exec_counter);
687 rc= mysql_stmt_execute(stmt);
688 check_execute(stmt, rc);
694 MYSQL_RES *rs_metadata= mysql_stmt_result_metadata(stmt);
696 num_fields= mysql_stmt_field_count(stmt);
697 fields= mysql_fetch_fields(rs_metadata);
700 memset(rs_bind, 0,
sizeof (
MYSQL_BIND) * num_fields);
702 mct_log(
"num_fields: %d\n", (
int) num_fields);
704 for (i = 0; i < num_fields; ++
i)
706 mct_log(
" - %d: name: '%s'/'%s'; table: '%s'/'%s'; "
707 "db: '%s'; catalog: '%s'; length: %d; max_length: %d; "
708 "type: %d; decimals: %d\n",
710 (
const char *) fields[i].
name,
711 (
const char *) fields[i].org_name,
712 (
const char *) fields[i].
table,
713 (
const char *) fields[i].org_table,
714 (
const char *) fields[i].db,
715 (
const char *) fields[i].catalog,
716 (
int) fields[i].length,
717 (
int) fields[i].max_length,
718 (
int) fields[i].
type,
719 (
int) fields[i].decimals);
721 rs_bind[
i].buffer_type= fields[
i].type;
722 rs_bind[
i].is_null= &is_null;
724 switch (fields[i].type)
726 case MYSQL_TYPE_LONG:
727 rs_bind[
i].buffer= (
char *) &(int_data[i]);
728 rs_bind[
i].buffer_length=
sizeof (int_data);
731 case MYSQL_TYPE_STRING:
732 rs_bind[
i].buffer= (
char *) str_data[i];
733 rs_bind[
i].buffer_length= WL4435_STRING_SIZE;
734 rs_bind[
i].length= &str_length;
737 case MYSQL_TYPE_DOUBLE:
738 rs_bind[
i].buffer= (
char *) &dbl_data[i];
739 rs_bind[
i].buffer_length=
sizeof (dbl_data);
742 case MYSQL_TYPE_NEWDECIMAL:
743 rs_bind[
i].buffer= (
char *) dec_data[i];
744 rs_bind[
i].buffer_length= WL4435_STRING_SIZE;
745 rs_bind[
i].length= &str_length;
749 fprintf(stderr,
"ERROR: unexpected type: %d.\n", fields[i].type);
754 rc= mysql_stmt_bind_result(stmt, rs_bind);
755 check_execute(stmt, rc);
761 int rc= mysql_stmt_fetch(stmt);
763 if (rc == 1 || rc == MYSQL_NO_DATA)
768 for (i = 0; i < num_fields; ++
i)
770 switch (rs_bind[i].buffer_type)
772 case MYSQL_TYPE_LONG:
773 mct_log(
" int: %ld;",
774 (
long) *((
int *) rs_bind[i].buffer));
777 case MYSQL_TYPE_STRING:
778 mct_log(
" str: '%s';",
779 (
char *) rs_bind[i].buffer);
782 case MYSQL_TYPE_DOUBLE:
783 mct_log(
" dbl: %lf;",
784 (
double) *((
double *) rs_bind[i].buffer));
787 case MYSQL_TYPE_NEWDECIMAL:
788 mct_log(
" dec: '%s';",
789 (
char *) rs_bind[i].buffer);
793 printf(
" unexpected type (%d)\n",
794 rs_bind[i].buffer_type);
802 rc= mysql_stmt_next_result(stmt);
803 mct_log(
"mysql_stmt_next_result(): %d; field_count: %d\n",
804 (
int) rc, (
int) mysql->field_count);
807 mysql_free_result(rs_metadata);
811 printf(
"Error: %s (errno: %d)\n",
812 mysql_stmt_error(stmt), mysql_stmt_errno(stmt));
819 if (!mysql->field_count)
828 mysql_stmt_close(stmt);
832 rc= mysql_commit(mysql);
838 const char *str_koi8r=
"\xee\xd5\x2c\x20\xda\xc1\x20\xd2\xd9\xc2\xc1\xcc\xcb\xd5";
839 const char *str_cp1251=
"\xcd\xf3\x2c\x20\xe7\xe0\x20\xf0\xfb\xe1\xe0\xeb\xea\xf3";
847 strmov(query,
"CALL p2(?, ?, ?)");
848 stmt= mysql_simple_prepare(mysql, query);
853 memset(ps_params, 0,
sizeof (ps_params));
855 ps_params[0].buffer_type= MYSQL_TYPE_STRING;
856 ps_params[0].buffer= (
char *) str_koi8r;
857 ps_params[0].buffer_length= strlen(str_koi8r);
859 ps_params[1].buffer_type= MYSQL_TYPE_STRING;
860 ps_params[1].buffer= o1_buffer;
861 ps_params[1].buffer_length= 0;
863 ps_params[2].buffer_type= MYSQL_TYPE_STRING;
864 ps_params[2].buffer= o2_buffer;
865 ps_params[2].buffer_length= 0;
869 rc= mysql_stmt_bind_param(stmt, ps_params);
870 check_execute(stmt, rc);
874 rc= mysql_query(mysql,
"SET NAMES binary");
879 rc= mysql_stmt_execute(stmt);
880 check_execute(stmt, rc);
884 memset(rs_bind, 0,
sizeof (rs_bind));
886 rs_bind[0].buffer_type= MYSQL_TYPE_STRING;
887 rs_bind[0].buffer= o1_buffer;
888 rs_bind[0].buffer_length=
sizeof (o1_buffer);
889 rs_bind[0].length= &o1_length;
891 rs_bind[1].buffer_type= MYSQL_TYPE_BLOB;
892 rs_bind[1].buffer= o2_buffer;
893 rs_bind[1].buffer_length=
sizeof (o2_buffer);
894 rs_bind[1].length= &o2_length;
896 rc= mysql_stmt_bind_result(stmt, rs_bind);
897 check_execute(stmt, rc);
901 rc= mysql_stmt_fetch(stmt);
902 check_execute(stmt, rc);
906 DIE_UNLESS(o1_length == strlen(str_cp1251));
907 DIE_UNLESS(o2_length == strlen(str_koi8r));
908 DIE_UNLESS(!memcmp(o1_buffer, str_cp1251, o1_length));
909 DIE_UNLESS(!memcmp(o2_buffer, str_koi8r, o2_length));
911 rc= mysql_stmt_fetch(stmt);
912 DIE_UNLESS(rc == MYSQL_NO_DATA);
914 rc= mysql_stmt_next_result(stmt);
915 DIE_UNLESS(rc == 0 && mysql->field_count == 0);
917 mysql_stmt_close(stmt);
919 rc= mysql_commit(mysql);
924 static void test_wl4435_2()
929 char query[MAX_TEST_QUERY_LENGTH];
931 myheader(
"test_wl4435_2");
932 mct_start_logging(
"test_wl4435_2");
939 for (i= 0; i < 10; ++
i)
947 rc= mysql_query(mysql,
"DROP PROCEDURE IF EXISTS p1");
950 rc= mysql_query(mysql,
951 "CREATE PROCEDURE p1()"
954 " SELECT 2, 3 UNION SELECT 4, 5; "
961 strmov(query,
"CALL p1()");
962 stmt= mysql_simple_prepare(mysql, query);
967 rc= mysql_stmt_execute(stmt);
968 check_execute(stmt, rc);
972 mysql_stmt_close(stmt);
975 rc= mysql_commit(mysql);
978 rc= mysql_query(mysql,
"DROP PROCEDURE p1");
985 #define WL4435_TEST(sql_type, sql_value, \
986 c_api_in_type, c_api_out_type, \
987 c_type, c_type_ext, \
988 printf_args, assert_condition) \
994 MYSQL_RES *rs_metadata; \
995 MYSQL_FIELD *fields; \
996 c_type pspv c_type_ext; \
999 memset(&pspv, 0, sizeof (pspv)); \
1001 rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); \
1004 rc= mysql_query(mysql, \
1005 "CREATE PROCEDURE p1(OUT v " sql_type ") SET v = " sql_value ";"); \
1008 ps = mysql_simple_prepare(mysql, "CALL p1(?)"); \
1010 memset(&psp, 0, sizeof (psp)); \
1011 psp.buffer_type= c_api_in_type; \
1012 psp.is_null= &psp_null; \
1013 psp.buffer= (char *) &pspv; \
1014 psp.buffer_length= sizeof (psp); \
1016 rc= mysql_stmt_bind_param(ps, &psp); \
1017 check_execute(ps, rc); \
1019 rc= mysql_stmt_execute(ps); \
1020 check_execute(ps, rc); \
1022 DIE_UNLESS(mysql->server_status & SERVER_PS_OUT_PARAMS); \
1023 DIE_UNLESS(mysql_stmt_field_count(ps) == 1); \
1025 rs_metadata= mysql_stmt_result_metadata(ps); \
1026 fields= mysql_fetch_fields(rs_metadata); \
1028 rc= mysql_stmt_bind_result(ps, &psp); \
1029 check_execute(ps, rc); \
1031 rc= mysql_stmt_fetch(ps); \
1032 DIE_UNLESS(rc == 0); \
1034 DIE_UNLESS(fields[0].type == c_api_out_type); \
1035 printf printf_args; \
1036 printf("; in type: %d; out type: %d\n", \
1037 (int) c_api_in_type, (int) c_api_out_type); \
1039 rc= mysql_stmt_fetch(ps); \
1040 DIE_UNLESS(rc == MYSQL_NO_DATA); \
1042 rc= mysql_stmt_next_result(ps); \
1043 DIE_UNLESS(rc == 0); \
1045 mysql_free_result(rs_metadata); \
1046 mysql_stmt_free_result(ps); \
1047 mysql_stmt_close(ps); \
1049 DIE_UNLESS(assert_condition); \
1053 static void test_wl4435_3()
1078 WL4435_TEST(
"TINYINT",
"127",
1079 MYSQL_TYPE_TINY, MYSQL_TYPE_TINY,
1081 (
" - TINYINT / char / MYSQL_TYPE_TINY:\t\t\t %d", (
int) pspv),
1084 WL4435_TEST(
"SMALLINT",
"32767",
1085 MYSQL_TYPE_SHORT, MYSQL_TYPE_SHORT,
1087 (
" - SMALLINT / short / MYSQL_TYPE_SHORT:\t\t %d", (
int) pspv),
1090 WL4435_TEST(
"INT",
"2147483647",
1091 MYSQL_TYPE_LONG, MYSQL_TYPE_LONG,
1093 (
" - INT / int / MYSQL_TYPE_LONG:\t\t\t %d", pspv),
1094 pspv == 2147483647l);
1096 WL4435_TEST(
"BIGINT",
"9223372036854775807",
1097 MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG,
1099 (
" - BIGINT / long long / MYSQL_TYPE_LONGLONG:\t\t %lld", pspv),
1100 pspv == 9223372036854775807ll);
1102 WL4435_TEST(
"TIMESTAMP",
"'2007-11-18 15:01:02'",
1103 MYSQL_TYPE_TIMESTAMP, MYSQL_TYPE_TIMESTAMP,
1105 (
" - TIMESTAMP / MYSQL_TIME / MYSQL_TYPE_TIMESTAMP:\t "
1106 "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
1107 (
int) pspv.year, (
int) pspv.month, (
int) pspv.day,
1108 (
int) pspv.hour, (
int) pspv.minute, (
int) pspv.second),
1109 pspv.year == 2007 && pspv.month == 11 && pspv.day == 18 &&
1110 pspv.hour == 15 && pspv.minute == 1 && pspv.second == 2);
1112 WL4435_TEST(
"DATETIME",
"'1234-11-12 12:34:59'",
1113 MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
1115 (
" - DATETIME / MYSQL_TIME / MYSQL_TYPE_DATETIME:\t "
1116 "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
1117 (
int) pspv.year, (
int) pspv.month, (
int) pspv.day,
1118 (
int) pspv.hour, (
int) pspv.minute, (
int) pspv.second),
1119 pspv.year == 1234 && pspv.month == 11 && pspv.day == 12 &&
1120 pspv.hour == 12 && pspv.minute == 34 && pspv.second == 59);
1122 WL4435_TEST(
"TIME",
"'123:45:01'",
1123 MYSQL_TYPE_TIME, MYSQL_TYPE_TIME,
1125 (
" - TIME / MYSQL_TIME / MYSQL_TYPE_TIME:\t\t "
1127 (
int) pspv.hour, (
int) pspv.minute, (
int) pspv.second),
1128 pspv.hour == 123 && pspv.minute == 45 && pspv.second == 1);
1130 WL4435_TEST(
"DATE",
"'1234-11-12'",
1131 MYSQL_TYPE_DATE, MYSQL_TYPE_DATE,
1133 (
" - DATE / MYSQL_TIME / MYSQL_TYPE_DATE:\t\t "
1135 (
int) pspv.year, (
int) pspv.month, (
int) pspv.day),
1136 pspv.year == 1234 && pspv.month == 11 && pspv.day == 12);
1138 WL4435_TEST(
"YEAR",
"'2010'",
1139 MYSQL_TYPE_SHORT, MYSQL_TYPE_YEAR,
1141 (
" - YEAR / short / MYSQL_TYPE_SHORT:\t\t\t %.4d", (
int) pspv),
1144 WL4435_TEST(
"FLOAT(7, 4)",
"123.4567",
1145 MYSQL_TYPE_FLOAT, MYSQL_TYPE_FLOAT,
1147 (
" - FLOAT / float / MYSQL_TYPE_FLOAT:\t\t\t %g", (
double) pspv),
1148 pspv - 123.4567 < 0.0001);
1150 WL4435_TEST(
"DOUBLE(8, 5)",
"123.45678",
1151 MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
1153 (
" - DOUBLE / double / MYSQL_TYPE_DOUBLE:\t\t %g", (
double) pspv),
1154 pspv - 123.45678 < 0.00001);
1156 WL4435_TEST(
"DECIMAL(9, 6)",
"123.456789",
1157 MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
1159 (
" - DECIMAL / char[] / MYSQL_TYPE_NEWDECIMAL:\t\t '%s'", (
char *) pspv),
1160 !strcmp(pspv,
"123.456789"));
1162 WL4435_TEST(
"CHAR(32)",
"REPEAT('C', 16)",
1163 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
1165 (
" - CHAR(32) / char[] / MYSQL_TYPE_STRING:\t\t '%s'", (
char *) pspv),
1166 !strcmp(pspv,
"CCCCCCCCCCCCCCCC"));
1168 WL4435_TEST(
"VARCHAR(32)",
"REPEAT('V', 16)",
1169 MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_VAR_STRING,
1171 (
" - VARCHAR(32) / char[] / MYSQL_TYPE_VAR_STRING:\t '%s'", (
char *) pspv),
1172 !strcmp(pspv,
"VVVVVVVVVVVVVVVV"));
1174 WL4435_TEST(
"TINYTEXT",
"REPEAT('t', 16)",
1175 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_BLOB,
1177 (
" - TINYTEXT / char[] / MYSQL_TYPE_TINY_BLOB:\t\t '%s'", (
char *) pspv),
1178 !strcmp(pspv,
"tttttttttttttttt"));
1180 WL4435_TEST(
"TEXT",
"REPEAT('t', 16)",
1181 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1183 (
" - TEXT / char[] / MYSQL_TYPE_BLOB:\t\t\t '%s'", (
char *) pspv),
1184 !strcmp(pspv,
"tttttttttttttttt"));
1186 WL4435_TEST(
"MEDIUMTEXT",
"REPEAT('t', 16)",
1187 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_BLOB,
1189 (
" - MEDIUMTEXT / char[] / MYSQL_TYPE_MEDIUM_BLOB:\t '%s'", (
char *) pspv),
1190 !strcmp(pspv,
"tttttttttttttttt"));
1192 WL4435_TEST(
"LONGTEXT",
"REPEAT('t', 16)",
1193 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_BLOB,
1195 (
" - LONGTEXT / char[] / MYSQL_TYPE_LONG_BLOB:\t\t '%s'", (
char *) pspv),
1196 !strcmp(pspv,
"tttttttttttttttt"));
1198 WL4435_TEST(
"BINARY(32)",
"REPEAT('\1', 16)",
1199 MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
1201 (
" - BINARY(32) / char[] / MYSQL_TYPE_STRING:\t\t '%s'", (
char *) pspv),
1202 memset(tmp, 1, 16) && !memcmp(tmp, pspv, 16));
1204 WL4435_TEST(
"VARBINARY(32)",
"REPEAT('\1', 16)",
1205 MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_VAR_STRING,
1207 (
" - VARBINARY(32) / char[] / MYSQL_TYPE_VAR_STRING:\t '%s'", (
char *) pspv),
1208 memset(tmp, 1, 16) && !memcmp(tmp, pspv, 16));
1210 WL4435_TEST(
"TINYBLOB",
"REPEAT('\2', 16)",
1211 MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_BLOB,
1213 (
" - TINYBLOB / char[] / MYSQL_TYPE_TINY_BLOB:\t\t '%s'", (
char *) pspv),
1214 memset(tmp, 2, 16) && !memcmp(tmp, pspv, 16));
1216 WL4435_TEST(
"BLOB",
"REPEAT('\2', 16)",
1217 MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
1219 (
" - BLOB / char[] / MYSQL_TYPE_BLOB:\t\t\t '%s'", (
char *) pspv),
1220 memset(tmp, 2, 16) && !memcmp(tmp, pspv, 16));
1222 WL4435_TEST(
"MEDIUMBLOB",
"REPEAT('\2', 16)",
1223 MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_BLOB,
1225 (
" - MEDIUMBLOB / char[] / MYSQL_TYPE_MEDIUM_BLOB:\t '%s'", (
char *) pspv),
1226 memset(tmp, 2, 16) && !memcmp(tmp, pspv, 16));
1228 WL4435_TEST(
"LONGBLOB",
"REPEAT('\2', 16)",
1229 MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_BLOB,
1231 (
" - LONGBLOB / char[] / MYSQL_TYPE_LONG_BLOB:\t\t '%s'", (
char *) pspv),
1232 memset(tmp, 2, 16) && !memcmp(tmp, pspv, 16));
1238 static void test_prepare_field_result()
1243 char query[MAX_TEST_QUERY_LENGTH];
1245 myheader(
"test_prepare_field_result");
1247 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_prepare_field_result");
1250 rc= mysql_query(mysql,
"CREATE TABLE test_prepare_field_result(int_c int, "
1251 "var_c varchar(50), ts_c timestamp, "
1252 "char_c char(4), date_c date, extra tinyint)");
1256 strmov(query,
"SELECT int_c, var_c, date_c as date, ts_c, char_c FROM "
1257 " test_prepare_field_result as t1 WHERE int_c=?");
1258 stmt= mysql_simple_prepare(mysql, query);
1261 verify_param_count(stmt, 1);
1263 result= mysql_stmt_result_metadata(stmt);
1266 my_print_result_metadata(result);
1269 fprintf(stdout,
"\n\n field attributes:\n");
1270 verify_prepare_field(result, 0,
"int_c",
"int_c", MYSQL_TYPE_LONG,
1271 "t1",
"test_prepare_field_result", current_db, 11, 0);
1272 verify_prepare_field(result, 1,
"var_c",
"var_c", MYSQL_TYPE_VAR_STRING,
1273 "t1",
"test_prepare_field_result", current_db, 50, 0);
1274 verify_prepare_field(result, 2,
"date",
"date_c", MYSQL_TYPE_DATE,
1275 "t1",
"test_prepare_field_result", current_db, 10, 0);
1276 verify_prepare_field(result, 3,
"ts_c",
"ts_c", MYSQL_TYPE_TIMESTAMP,
1277 "t1",
"test_prepare_field_result", current_db, 19, 0);
1278 verify_prepare_field(result, 4,
"char_c",
"char_c",
1279 (mysql_get_server_version(mysql) <= 50000 ?
1280 MYSQL_TYPE_VAR_STRING : MYSQL_TYPE_STRING),
1281 "t1",
"test_prepare_field_result", current_db, 4, 0);
1283 verify_field_count(result, 5);
1284 mysql_free_result(result);
1285 mysql_stmt_close(stmt);
1291 static void test_prepare_syntax()
1295 char query[MAX_TEST_QUERY_LENGTH];
1297 myheader(
"test_prepare_syntax");
1299 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_prepare_syntax");
1302 rc= mysql_query(mysql,
"CREATE TABLE test_prepare_syntax("
1303 "id int, name varchar(50), extra int)");
1306 strmov(query,
"INSERT INTO test_prepare_syntax VALUES(?");
1307 stmt= mysql_simple_prepare(mysql, query);
1310 strmov(query,
"SELECT id, name FROM test_prepare_syntax WHERE id=? AND WHERE");
1311 stmt= mysql_simple_prepare(mysql, query);
1315 rc= mysql_commit(mysql);
1322 static void test_prepare()
1326 int int_data, o_int_data;
1327 char str_data[50], data[50];
1328 char tiny_data, o_tiny_data;
1329 short small_data, o_small_data;
1330 longlong big_data, o_big_data;
1331 float real_data, o_real_data;
1332 double double_data, o_double_data;
1333 ulong length[7], len;
1337 char query[MAX_TEST_QUERY_LENGTH];
1339 myheader(
"test_prepare");
1341 rc= mysql_autocommit(mysql, TRUE);
1344 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS my_prepare");
1347 rc= mysql_query(mysql,
"CREATE TABLE my_prepare(col1 tinyint, "
1348 "col2 varchar(15), col3 int, "
1349 "col4 smallint, col5 bigint, "
1350 "col6 float, col7 double )");
1354 strxmov(query,
"INSERT INTO my_prepare VALUES(?, ?, ?, ?, ?, ?, ?)", NullS);
1355 stmt= mysql_simple_prepare(mysql, query);
1358 verify_param_count(stmt, 7);
1360 memset(my_bind, 0,
sizeof(my_bind));
1363 my_bind[0].buffer_type= MYSQL_TYPE_TINY;
1364 my_bind[0].buffer= (
void *)&tiny_data;
1366 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
1367 my_bind[1].buffer= (
void *)str_data;
1368 my_bind[1].buffer_length= 1000;
1370 my_bind[2].buffer_type= MYSQL_TYPE_LONG;
1371 my_bind[2].buffer= (
void *)&int_data;
1373 my_bind[3].buffer_type= MYSQL_TYPE_SHORT;
1374 my_bind[3].buffer= (
void *)&small_data;
1376 my_bind[4].buffer_type= MYSQL_TYPE_LONGLONG;
1377 my_bind[4].buffer= (
void *)&big_data;
1379 my_bind[5].buffer_type= MYSQL_TYPE_FLOAT;
1380 my_bind[5].buffer= (
void *)&real_data;
1382 my_bind[6].buffer_type= MYSQL_TYPE_DOUBLE;
1383 my_bind[6].buffer= (
void *)&double_data;
1385 for (i= 0; i < (int) array_elements(my_bind); i++)
1387 my_bind[
i].length= &length[
i];
1388 my_bind[
i].is_null= &is_null[
i];
1392 rc= mysql_stmt_bind_param(stmt, my_bind);
1393 check_execute(stmt, rc);
1399 double_data= 6578.001;
1402 for (tiny_data= 0; tiny_data < 100; tiny_data++)
1404 length[1]= sprintf(str_data,
"MySQL%d", int_data);
1405 rc= mysql_stmt_execute(stmt);
1406 check_execute(stmt, rc);
1411 double_data += 10.09;
1414 mysql_stmt_close(stmt);
1417 rc= mysql_commit(mysql);
1421 rc= my_stmt_result(
"SELECT * FROM my_prepare");
1422 DIE_UNLESS(tiny_data == (
char) rc);
1424 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM my_prepare");
1427 rc= mysql_stmt_bind_result(stmt, my_bind);
1428 check_execute(stmt, rc);
1431 rc= mysql_stmt_execute(stmt);
1432 check_execute(stmt, rc);
1438 o_double_data= 6578.001;
1441 for (o_tiny_data= 0; o_tiny_data < 100; o_tiny_data++)
1443 len= sprintf(data,
"MySQL%d", o_int_data);
1445 rc= mysql_stmt_fetch(stmt);
1446 check_execute(stmt, rc);
1450 fprintf(stdout,
"\n");
1451 fprintf(stdout,
"\n\t tiny : %d (%lu)", tiny_data, length[0]);
1452 fprintf(stdout,
"\n\t short : %d (%lu)", small_data, length[3]);
1453 fprintf(stdout,
"\n\t int : %d (%lu)", int_data, length[2]);
1454 fprintf(stdout,
"\n\t big : %s (%lu)", llstr(big_data, llbuf),
1457 fprintf(stdout,
"\n\t float : %f (%lu)", real_data, length[5]);
1458 fprintf(stdout,
"\n\t double : %f (%lu)", double_data, length[6]);
1460 fprintf(stdout,
"\n\t str : %s (%lu)", str_data, length[1]);
1463 DIE_UNLESS(tiny_data == o_tiny_data);
1464 DIE_UNLESS(is_null[0] == 0);
1465 DIE_UNLESS(length[0] == 1);
1467 DIE_UNLESS(int_data == o_int_data);
1468 DIE_UNLESS(length[2] == 4);
1470 DIE_UNLESS(small_data == o_small_data);
1471 DIE_UNLESS(length[3] == 2);
1473 DIE_UNLESS(big_data == o_big_data);
1474 DIE_UNLESS(length[4] == 8);
1476 DIE_UNLESS(real_data == o_real_data);
1477 DIE_UNLESS(length[5] == 4);
1479 DIE_UNLESS(cmp_double(&double_data, &o_double_data));
1480 DIE_UNLESS(length[6] == 8);
1482 DIE_UNLESS(strcmp(data, str_data) == 0);
1483 DIE_UNLESS(length[1] == len);
1489 o_double_data += 10.09;
1492 rc= mysql_stmt_fetch(stmt);
1493 DIE_UNLESS(rc == MYSQL_NO_DATA);
1495 mysql_stmt_close(stmt);
1502 static void test_double_compare()
1506 char real_data[10], tiny_data;
1511 char query[MAX_TEST_QUERY_LENGTH];
1513 myheader(
"test_double_compare");
1515 rc= mysql_autocommit(mysql, TRUE);
1518 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_double_compare");
1521 rc= mysql_query(mysql,
"CREATE TABLE test_double_compare(col1 tinyint, "
1522 " col2 float, col3 double )");
1525 rc= mysql_query(mysql,
"INSERT INTO test_double_compare "
1526 "VALUES (1, 10.2, 34.5)");
1529 strmov(query,
"UPDATE test_double_compare SET col1=100 "
1530 "WHERE col1 = ? AND col2 = ? AND COL3 = ?");
1531 stmt= mysql_simple_prepare(mysql, query);
1534 verify_param_count(stmt, 3);
1537 memset(my_bind, 0,
sizeof(my_bind));
1540 my_bind[0].buffer_type= MYSQL_TYPE_TINY;
1541 my_bind[0].buffer= (
void *)&tiny_data;
1544 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
1545 my_bind[1].buffer= (
void *)&real_data;
1546 my_bind[1].buffer_length=
sizeof(real_data);
1547 my_bind[1].length= &length[1];
1551 my_bind[2].buffer_type= MYSQL_TYPE_DOUBLE;
1552 my_bind[2].buffer= (
void *)&double_data;
1555 strmov(real_data,
"10.2");
1557 rc= mysql_stmt_bind_param(stmt, my_bind);
1558 check_execute(stmt, rc);
1560 rc= mysql_stmt_execute(stmt);
1561 check_execute(stmt, rc);
1563 verify_affected_rows(0);
1565 mysql_stmt_close(stmt);
1568 rc= mysql_commit(mysql);
1572 rc= mysql_query(mysql,
"SELECT * FROM test_double_compare");
1576 result= mysql_store_result(mysql);
1579 rc= my_process_result_set(result);
1580 DIE_UNLESS((
int)tiny_data == rc);
1581 mysql_free_result(result);
1587 static void test_null()
1594 char query[MAX_TEST_QUERY_LENGTH];
1596 myheader(
"test_null");
1598 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_null");
1601 rc= mysql_query(mysql,
"CREATE TABLE test_null(col1 int, col2 varchar(50))");
1605 strmov(query,
"INSERT INTO test_null(col3, col2) VALUES(?, ?)");
1606 stmt= mysql_simple_prepare(mysql, query);
1609 strmov(query,
"INSERT INTO test_null(col1, col2) VALUES(?, ?)");
1610 stmt= mysql_simple_prepare(mysql, query);
1613 verify_param_count(stmt, 2);
1616 memset(my_bind, 0,
sizeof(my_bind));
1618 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
1619 my_bind[0].is_null= &is_null[0];
1621 my_bind[1]= my_bind[0];
1623 rc= mysql_stmt_bind_param(stmt, my_bind);
1624 check_execute(stmt, rc);
1627 for (nData= 0; nData<10; nData++)
1629 rc= mysql_stmt_execute(stmt);
1630 check_execute(stmt, rc);
1634 my_bind[0].buffer_type= MYSQL_TYPE_NULL;
1636 my_bind[1]= my_bind[0];
1638 rc= mysql_stmt_bind_param(stmt, my_bind);
1639 check_execute(stmt, rc);
1641 for (nData= 0; nData<10; nData++)
1643 rc= mysql_stmt_execute(stmt);
1644 check_execute(stmt, rc);
1647 mysql_stmt_close(stmt);
1650 rc= mysql_commit(mysql);
1654 rc= my_stmt_result(
"SELECT * FROM test_null");;
1655 DIE_UNLESS((
int) nData == rc);
1658 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
1659 my_bind[0].buffer= (
void *)&nData;
1660 my_bind[0].length= 0;
1661 my_bind[1]= my_bind[0];
1662 my_bind[0].is_null= &is_null[0];
1663 my_bind[1].is_null= &is_null[1];
1665 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_null");
1668 rc= mysql_stmt_execute(stmt);
1669 check_execute(stmt, rc);
1671 rc= mysql_stmt_bind_result(stmt, my_bind);
1672 check_execute(stmt, rc);
1675 is_null[0]= is_null[1]= 0;
1676 while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
1678 DIE_UNLESS(is_null[0]);
1679 DIE_UNLESS(is_null[1]);
1681 is_null[0]= is_null[1]= 0;
1683 DIE_UNLESS(rc == (
int) nData);
1684 mysql_stmt_close(stmt);
1690 static void test_ps_null_param()
1701 my_bool out_is_null;
1702 char out_str_data[20];
1704 const char *queries[]= {
"select ?",
"select ?+1",
1705 "select col1 from test_ps_nulls where col1 <=> ?",
1708 const char **cur_query= queries;
1710 myheader(
"test_null_ps_param_in_result");
1712 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_ps_nulls");
1715 rc= mysql_query(mysql,
"CREATE TABLE test_ps_nulls(col1 int)");
1718 rc= mysql_query(mysql,
"INSERT INTO test_ps_nulls values (1), (null)");
1722 memset(&in_bind, 0,
sizeof(in_bind));
1723 memset(&out_bind, 0,
sizeof(out_bind));
1725 in_bind.buffer_type= MYSQL_TYPE_LONG;
1726 in_bind.is_null= &in_is_null;
1728 in_bind.buffer= (
void *)&in_long;
1732 out_bind.buffer_type= MYSQL_TYPE_STRING;
1733 out_bind.is_null= &out_is_null;
1734 out_bind.length= &out_length;
1735 out_bind.buffer= out_str_data;
1736 out_bind.buffer_length= array_elements(out_str_data);
1739 for(cur_query= queries; *cur_query; cur_query++)
1741 char query[MAX_TEST_QUERY_LENGTH];
1742 strmov(query, *cur_query);
1743 stmt= mysql_simple_prepare(mysql, query);
1745 verify_param_count(stmt, 1);
1747 rc= mysql_stmt_bind_param(stmt, &in_bind);
1748 check_execute(stmt, rc);
1749 rc= mysql_stmt_bind_result(stmt, &out_bind);
1750 check_execute(stmt, rc);
1751 rc= mysql_stmt_execute(stmt);
1752 check_execute(stmt, rc);
1753 rc= mysql_stmt_fetch(stmt);
1754 DIE_UNLESS(rc != MYSQL_NO_DATA);
1755 DIE_UNLESS(out_is_null);
1756 rc= mysql_stmt_fetch(stmt);
1757 DIE_UNLESS(rc == MYSQL_NO_DATA);
1758 mysql_stmt_close(stmt);
1765 static void test_fetch_null()
1772 my_bool is_null[11];
1773 char query[MAX_TEST_QUERY_LENGTH];
1775 myheader(
"test_fetch_null");
1777 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_fetch_null");
1780 rc= mysql_query(mysql,
"CREATE TABLE test_fetch_null("
1781 " col1 tinyint, col2 smallint, "
1782 " col3 int, col4 bigint, "
1783 " col5 float, col6 double, "
1784 " col7 date, col8 time, "
1785 " col9 varbinary(10), "
1786 " col10 varchar(50), "
1787 " col11 char(20))");
1790 rc= mysql_query(mysql,
"INSERT INTO test_fetch_null (col11) "
1791 "VALUES (1000), (88), (389789)");
1794 rc= mysql_commit(mysql);
1798 memset(my_bind, 0,
sizeof(my_bind));
1799 for (i= 0; i < (int) array_elements(my_bind); i++)
1801 my_bind[
i].buffer_type= MYSQL_TYPE_LONG;
1802 my_bind[
i].is_null= &is_null[
i];
1803 my_bind[
i].length= &length[
i];
1805 my_bind[i-1].buffer= (
void *)&nData;
1807 strmov((
char *)query ,
"SELECT * FROM test_fetch_null");
1809 rc= my_stmt_result(query);
1810 DIE_UNLESS(rc == 3);
1812 stmt= mysql_simple_prepare(mysql, query);
1815 rc= mysql_stmt_bind_result(stmt, my_bind);
1816 check_execute(stmt, rc);
1818 rc= mysql_stmt_execute(stmt);
1819 check_execute(stmt, rc);
1822 while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
1825 for (i= 0; i < 10; i++)
1828 fprintf(stdout,
"\n data[%d] : %s", i,
1829 is_null[i] ?
"NULL" :
"NOT NULL");
1830 DIE_UNLESS(is_null[i]);
1833 fprintf(stdout,
"\n data[%d]: %d", i, nData);
1834 DIE_UNLESS(nData == 1000 || nData == 88 || nData == 389789);
1835 DIE_UNLESS(is_null[i] == 0);
1836 DIE_UNLESS(length[i] == 4);
1838 DIE_UNLESS(rc == 3);
1839 mysql_stmt_close(stmt);
1845 static void test_select_version()
1850 myheader(
"test_select_version");
1852 stmt= mysql_simple_prepare(mysql,
"SELECT @@version");
1855 verify_param_count(stmt, 0);
1857 rc= mysql_stmt_execute(stmt);
1858 check_execute(stmt, rc);
1860 my_process_stmt_result(stmt);
1861 mysql_stmt_close(stmt);
1867 static void test_select_show_table()
1872 myheader(
"test_select_show_table");
1874 stmt= mysql_simple_prepare(mysql,
"SHOW TABLES FROM mysql");
1877 verify_param_count(stmt, 0);
1879 for (i= 1; i < 3; i++)
1881 rc= mysql_stmt_execute(stmt);
1882 check_execute(stmt, rc);
1885 my_process_stmt_result(stmt);
1886 mysql_stmt_close(stmt);
1892 static void test_select_direct()
1897 myheader(
"test_select_direct");
1899 rc= mysql_autocommit(mysql, TRUE);
1902 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_select");
1905 rc= mysql_query(mysql,
"CREATE TABLE test_select(id int, id1 tinyint, "
1908 " name varchar(50))");
1912 rc= mysql_query(mysql,
"INSERT INTO test_select VALUES(10, 5, 2.3, 4.5, 'venu')");
1915 rc= mysql_commit(mysql);
1918 rc= mysql_query(mysql,
"SELECT * FROM test_select");
1922 result= mysql_store_result(mysql);
1925 (void) my_process_result_set(result);
1926 mysql_free_result(result);
1932 static void test_select_prepare()
1937 myheader(
"test_select_prepare");
1939 rc= mysql_autocommit(mysql, TRUE);
1942 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_select");
1945 rc= mysql_query(mysql,
"CREATE TABLE test_select(id int, name varchar(50))");
1949 rc= mysql_query(mysql,
"INSERT INTO test_select VALUES(10, 'venu')");
1952 rc= mysql_commit(mysql);
1955 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_select");
1958 rc= mysql_stmt_execute(stmt);
1959 check_execute(stmt, rc);
1961 rc= my_process_stmt_result(stmt);
1962 DIE_UNLESS(rc == 1);
1963 mysql_stmt_close(stmt);
1965 rc= mysql_query(mysql,
"DROP TABLE test_select");
1968 rc= mysql_query(mysql,
"CREATE TABLE test_select(id tinyint, id1 int, "
1969 " id2 float, id3 float, "
1970 " name varchar(50))");
1974 rc= mysql_query(mysql,
"INSERT INTO test_select(id, id1, id2, name) VALUES(10, 5, 2.3, 'venu')");
1977 rc= mysql_commit(mysql);
1980 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_select");
1983 rc= mysql_stmt_execute(stmt);
1984 check_execute(stmt, rc);
1986 rc= my_process_stmt_result(stmt);
1987 DIE_UNLESS(rc == 1);
1988 mysql_stmt_close(stmt);
1994 static void test_select()
2002 char query[MAX_TEST_QUERY_LENGTH];
2004 myheader(
"test_select");
2006 rc= mysql_autocommit(mysql, TRUE);
2009 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_select");
2012 rc= mysql_query(mysql,
"CREATE TABLE test_select(id int, name varchar(50))");
2016 rc= mysql_query(mysql,
"INSERT INTO test_select VALUES(10, 'venu')");
2020 rc= mysql_query(mysql,
"INSERT INTO test_select VALUES(20, 'mysql')");
2023 rc= mysql_commit(mysql);
2026 strmov(query,
"SELECT * FROM test_select WHERE id= ? "
2027 "AND CONVERT(name USING utf8) =?");
2028 stmt= mysql_simple_prepare(mysql, query);
2031 verify_param_count(stmt, 2);
2034 memset(my_bind, 0,
sizeof(my_bind));
2038 strmov(szData, (
char *)
"venu");
2039 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
2040 my_bind[1].buffer= (
void *)szData;
2041 my_bind[1].buffer_length= 4;
2042 my_bind[1].length= &length[1];
2045 my_bind[0].buffer= (
void *)&nData;
2046 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
2048 rc= mysql_stmt_bind_param(stmt, my_bind);
2049 check_execute(stmt, rc);
2051 rc= mysql_stmt_execute(stmt);
2052 check_execute(stmt, rc);
2054 rc= my_process_stmt_result(stmt);
2055 DIE_UNLESS(rc == 1);
2057 mysql_stmt_close(stmt);
2066 static void test_ps_conj_select()
2073 unsigned long str_length;
2074 char query[MAX_TEST_QUERY_LENGTH];
2075 myheader(
"test_ps_conj_select");
2077 rc= mysql_query(mysql,
"drop table if exists t1");
2080 rc= mysql_query(mysql,
"create table t1 (id1 int(11) NOT NULL default '0', "
2081 "value2 varchar(100), value1 varchar(100))");
2084 rc= mysql_query(mysql,
"insert into t1 values (1, 'hh', 'hh'), "
2085 "(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')");
2088 strmov(query,
"select id1, value1 from t1 where id1= ? or "
2089 "CONVERT(value1 USING utf8)= ?");
2090 stmt= mysql_simple_prepare(mysql, query);
2093 verify_param_count(stmt, 2);
2096 memset(my_bind, 0,
sizeof(my_bind));
2098 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
2099 my_bind[0].buffer= (
void *)&int_data;
2101 my_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
2102 my_bind[1].buffer= (
void *)str_data;
2103 my_bind[1].buffer_length= array_elements(str_data);
2104 my_bind[1].length= &str_length;
2106 rc= mysql_stmt_bind_param(stmt, my_bind);
2107 check_execute(stmt, rc);
2110 strmov(str_data,
"hh");
2111 str_length= strlen(str_data);
2113 rc= mysql_stmt_execute(stmt);
2114 check_execute(stmt, rc);
2116 rc= my_process_stmt_result(stmt);
2117 DIE_UNLESS(rc == 3);
2119 mysql_stmt_close(stmt);
2124 static uint query_cache_hits(
MYSQL *
conn)
2131 rc= mysql_query(conn,
"show status like 'qcache_hits'");
2133 res= mysql_use_result(conn);
2136 row= mysql_fetch_row(res);
2139 result= atoi(row[1]);
2140 mysql_free_result(res);
2149 #define test_ps_query_cache_result(i1,s1,l1,i2,s2,l2,i3,s3,l3) \
2150 r_metadata= mysql_stmt_result_metadata(stmt); \
2151 DIE_UNLESS(r_metadata != NULL); \
2152 rc= mysql_stmt_fetch(stmt); \
2153 check_execute(stmt, rc); \
2155 fprintf(stdout, "\n row 1: %d, %s(%lu)", r_int_data, \
2156 r_str_data, r_str_length); \
2157 DIE_UNLESS((r_int_data == i1) && (r_str_length == l1) && \
2158 (strcmp(r_str_data, s1) == 0)); \
2159 rc= mysql_stmt_fetch(stmt); \
2160 check_execute(stmt, rc); \
2162 fprintf(stdout, "\n row 2: %d, %s(%lu)", r_int_data, \
2163 r_str_data, r_str_length); \
2164 DIE_UNLESS((r_int_data == i2) && (r_str_length == l2) && \
2165 (strcmp(r_str_data, s2) == 0)); \
2166 rc= mysql_stmt_fetch(stmt); \
2167 check_execute(stmt, rc); \
2169 fprintf(stdout, "\n row 3: %d, %s(%lu)", r_int_data, \
2170 r_str_data, r_str_length); \
2171 DIE_UNLESS((r_int_data == i3) && (r_str_length == l3) && \
2172 (strcmp(r_str_data, s3) == 0)); \
2173 rc= mysql_stmt_fetch(stmt); \
2174 DIE_UNLESS(rc == MYSQL_NO_DATA); \
2175 mysql_free_result(r_metadata);
2182 static void test_ps_query_cache()
2184 MYSQL *lmysql= mysql;
2188 int32 p_int_data, r_int_data;
2189 char p_str_data[32], r_str_data[32];
2190 unsigned long p_str_length, r_str_length;
2192 char query[MAX_TEST_QUERY_LENGTH];
2194 enum enum_test_ps_query_cache
2206 TEST_QCACHE_ON_WITH_OTHER_CONN,
2218 enum enum_test_ps_query_cache iteration;
2220 myheader(
"test_ps_query_cache");
2222 rc= mysql_query(mysql,
"SET SQL_MODE=''");
2227 rc= mysql_query(mysql,
"drop table if exists t1");
2230 rc= mysql_query(mysql,
"create table t1 (id1 int(11) NOT NULL default '0', "
2231 "value2 varchar(100), value1 varchar(100))");
2234 rc= mysql_query(mysql,
"insert into t1 values (1, 'hh', 'hh'), "
2235 "(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')");
2238 for (iteration= TEST_QCACHE_ON; iteration <= TEST_QCACHE_ON_OFF; iteration++)
2241 switch (iteration) {
2242 case TEST_QCACHE_ON:
2243 case TEST_QCACHE_ON_OFF:
2244 rc= mysql_query(lmysql,
"set global query_cache_size=1000000");
2247 case TEST_QCACHE_OFF_ON:
2248 rc= mysql_query(lmysql,
"set global query_cache_size=0");
2251 case TEST_QCACHE_ON_WITH_OTHER_CONN:
2253 fprintf(stdout,
"\n Establishing a test connection ...");
2254 if (!(lmysql= mysql_client_init(NULL)))
2256 printf(
"mysql_client_init() failed");
2259 if (!(mysql_real_connect(lmysql, opt_host, opt_user,
2260 opt_password, current_db, opt_port,
2261 opt_unix_socket, 0)))
2263 printf(
"connection failed");
2264 mysql_close(lmysql);
2267 rc= mysql_query(lmysql,
"SET SQL_MODE=''");
2271 fprintf(stdout,
"OK");
2274 strmov(query,
"select id1, value1 from t1 where id1= ? or "
2275 "CONVERT(value1 USING utf8)= ?");
2276 stmt= mysql_simple_prepare(lmysql, query);
2279 verify_param_count(stmt, 2);
2281 switch (iteration) {
2282 case TEST_QCACHE_OFF_ON:
2283 rc= mysql_query(lmysql,
"set global query_cache_size=1000000");
2286 case TEST_QCACHE_ON_OFF:
2287 rc= mysql_query(lmysql,
"set global query_cache_size=0");
2293 memset(p_bind, 0,
sizeof(p_bind));
2294 p_bind[0].buffer_type= MYSQL_TYPE_LONG;
2295 p_bind[0].buffer= (
void *)&p_int_data;
2296 p_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
2297 p_bind[1].buffer= (
void *)p_str_data;
2298 p_bind[1].buffer_length= array_elements(p_str_data);
2299 p_bind[1].length= &p_str_length;
2301 rc= mysql_stmt_bind_param(stmt, p_bind);
2302 check_execute(stmt, rc);
2305 strmov(p_str_data,
"hh");
2306 p_str_length= strlen(p_str_data);
2308 memset(r_bind, 0,
sizeof(r_bind));
2309 r_bind[0].buffer_type= MYSQL_TYPE_LONG;
2310 r_bind[0].buffer= (
void *)&r_int_data;
2311 r_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
2312 r_bind[1].buffer= (
void *)r_str_data;
2313 r_bind[1].buffer_length= array_elements(r_str_data);
2314 r_bind[1].length= &r_str_length;
2316 rc= mysql_stmt_bind_result(stmt, r_bind);
2317 check_execute(stmt, rc);
2319 rc= mysql_stmt_execute(stmt);
2320 check_execute(stmt, rc);
2322 test_ps_query_cache_result(1,
"hh", 2, 2,
"hh", 2, 1,
"ii", 2);
2325 hits1= query_cache_hits(lmysql);
2326 rc= mysql_stmt_execute(stmt);
2327 check_execute(stmt, rc);
2328 test_ps_query_cache_result(1,
"hh", 2, 2,
"hh", 2, 1,
"ii", 2);
2329 hits2= query_cache_hits(lmysql);
2331 case TEST_QCACHE_ON_WITH_OTHER_CONN:
2332 case TEST_QCACHE_ON:
2333 DIE_UNLESS(hits2-hits1 == 1);
2335 case TEST_QCACHE_OFF_ON:
2336 case TEST_QCACHE_ON_OFF:
2337 DIE_UNLESS(hits2-hits1 == 0);
2342 strmov(p_str_data,
"ii");
2343 p_str_length= strlen(p_str_data);
2344 rc= mysql_stmt_execute(stmt);
2345 check_execute(stmt, rc);
2346 test_ps_query_cache_result(1,
"hh", 2, 1,
"ii", 2, 2,
"ii", 2);
2347 hits1= query_cache_hits(lmysql);
2350 case TEST_QCACHE_ON:
2351 case TEST_QCACHE_OFF_ON:
2352 case TEST_QCACHE_ON_OFF:
2353 DIE_UNLESS(hits2-hits1 == 0);
2355 case TEST_QCACHE_ON_WITH_OTHER_CONN:
2356 DIE_UNLESS(hits1-hits2 == 1);
2360 rc= mysql_stmt_execute(stmt);
2361 check_execute(stmt, rc);
2363 test_ps_query_cache_result(1,
"hh", 2, 1,
"ii", 2, 2,
"ii", 2);
2364 hits2= query_cache_hits(lmysql);
2366 mysql_stmt_close(stmt);
2369 case TEST_QCACHE_ON:
2370 DIE_UNLESS(hits2-hits1 == 1);
2372 case TEST_QCACHE_OFF_ON:
2373 case TEST_QCACHE_ON_OFF:
2374 DIE_UNLESS(hits2-hits1 == 0);
2376 case TEST_QCACHE_ON_WITH_OTHER_CONN:
2377 DIE_UNLESS(hits2-hits1 == 1);
2383 if (lmysql != mysql)
2384 mysql_close(lmysql);
2386 rc= mysql_query(mysql,
"set global query_cache_size=DEFAULT");
2393 static void test_bug1115()
2400 char query[MAX_TEST_QUERY_LENGTH];
2402 myheader(
"test_bug1115");
2404 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_select");
2407 rc= mysql_query(mysql,
"CREATE TABLE test_select(\
2408 session_id char(9) NOT NULL, \
2409 a int(8) unsigned NOT NULL, \
2410 b int(5) NOT NULL, \
2411 c int(5) NOT NULL, \
2412 d datetime NOT NULL)");
2414 rc= mysql_query(mysql,
"INSERT INTO test_select VALUES "
2415 "(\"abc\", 1, 2, 3, 2003-08-30), "
2416 "(\"abd\", 1, 2, 3, 2003-08-30), "
2417 "(\"abf\", 1, 2, 3, 2003-08-30), "
2418 "(\"abg\", 1, 2, 3, 2003-08-30), "
2419 "(\"abh\", 1, 2, 3, 2003-08-30), "
2420 "(\"abj\", 1, 2, 3, 2003-08-30), "
2421 "(\"abk\", 1, 2, 3, 2003-08-30), "
2422 "(\"abl\", 1, 2, 3, 2003-08-30), "
2423 "(\"abq\", 1, 2, 3, 2003-08-30) ");
2425 rc= mysql_query(mysql,
"INSERT INTO test_select VALUES "
2426 "(\"abw\", 1, 2, 3, 2003-08-30), "
2427 "(\"abe\", 1, 2, 3, 2003-08-30), "
2428 "(\"abr\", 1, 2, 3, 2003-08-30), "
2429 "(\"abt\", 1, 2, 3, 2003-08-30), "
2430 "(\"aby\", 1, 2, 3, 2003-08-30), "
2431 "(\"abu\", 1, 2, 3, 2003-08-30), "
2432 "(\"abi\", 1, 2, 3, 2003-08-30), "
2433 "(\"abo\", 1, 2, 3, 2003-08-30), "
2434 "(\"abp\", 1, 2, 3, 2003-08-30), "
2435 "(\"abz\", 1, 2, 3, 2003-08-30), "
2436 "(\"abx\", 1, 2, 3, 2003-08-30)");
2439 strmov(query,
"SELECT * FROM test_select WHERE "
2440 "CONVERT(session_id USING utf8)= ?");
2441 stmt= mysql_simple_prepare(mysql, query);
2444 verify_param_count(stmt, 1);
2447 memset(my_bind, 0,
sizeof(my_bind));
2449 strmov(szData, (
char *)
"abc");
2450 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
2451 my_bind[0].buffer= (
void *)szData;
2452 my_bind[0].buffer_length= 10;
2453 my_bind[0].length= &length[0];
2456 rc= mysql_stmt_bind_param(stmt, my_bind);
2457 check_execute(stmt, rc);
2459 rc= mysql_stmt_execute(stmt);
2460 check_execute(stmt, rc);
2462 rc= my_process_stmt_result(stmt);
2463 DIE_UNLESS(rc == 1);
2465 strmov(szData, (
char *)
"venu");
2466 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
2467 my_bind[0].buffer= (
void *)szData;
2468 my_bind[0].buffer_length= 10;
2469 my_bind[0].length= &length[0];
2471 my_bind[0].is_null= 0;
2473 rc= mysql_stmt_bind_param(stmt, my_bind);
2474 check_execute(stmt, rc);
2476 rc= mysql_stmt_execute(stmt);
2477 check_execute(stmt, rc);
2479 rc= my_process_stmt_result(stmt);
2480 DIE_UNLESS(rc == 0);
2482 strmov(szData, (
char *)
"abc");
2483 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
2484 my_bind[0].buffer= (
void *)szData;
2485 my_bind[0].buffer_length= 10;
2486 my_bind[0].length= &length[0];
2488 my_bind[0].is_null= 0;
2490 rc= mysql_stmt_bind_param(stmt, my_bind);
2491 check_execute(stmt, rc);
2493 rc= mysql_stmt_execute(stmt);
2494 check_execute(stmt, rc);
2496 rc= my_process_stmt_result(stmt);
2497 DIE_UNLESS(rc == 1);
2499 mysql_stmt_close(stmt);
2505 static void test_bug1180()
2512 char query[MAX_TEST_QUERY_LENGTH];
2514 myheader(
"test_select_bug");
2516 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_select");
2519 rc= mysql_query(mysql,
"CREATE TABLE test_select(session_id char(9) NOT NULL)");
2521 rc= mysql_query(mysql,
"INSERT INTO test_select VALUES (\"abc\")");
2524 strmov(query,
"SELECT * FROM test_select WHERE ?= \"1111\" and "
2525 "session_id= \"abc\"");
2526 stmt= mysql_simple_prepare(mysql, query);
2529 verify_param_count(stmt, 1);
2532 memset(my_bind, 0,
sizeof(my_bind));
2534 strmov(szData, (
char *)
"abc");
2535 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
2536 my_bind[0].buffer= (
void *)szData;
2537 my_bind[0].buffer_length= 10;
2538 my_bind[0].length= &length[0];
2540 my_bind[0].is_null= 0;
2542 rc= mysql_stmt_bind_param(stmt, my_bind);
2543 check_execute(stmt, rc);
2545 rc= mysql_stmt_execute(stmt);
2546 check_execute(stmt, rc);
2548 rc= my_process_stmt_result(stmt);
2549 DIE_UNLESS(rc == 0);
2551 strmov(szData, (
char *)
"1111");
2552 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
2553 my_bind[0].buffer= (
void *)szData;
2554 my_bind[0].buffer_length= 10;
2555 my_bind[0].length= &length[0];
2557 my_bind[0].is_null= 0;
2559 rc= mysql_stmt_bind_param(stmt, my_bind);
2560 check_execute(stmt, rc);
2562 rc= mysql_stmt_execute(stmt);
2563 check_execute(stmt, rc);
2565 rc= my_process_stmt_result(stmt);
2566 DIE_UNLESS(rc == 1);
2568 strmov(szData, (
char *)
"abc");
2569 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
2570 my_bind[0].buffer= (
void *)szData;
2571 my_bind[0].buffer_length= 10;
2572 my_bind[0].length= &length[0];
2574 my_bind[0].is_null= 0;
2576 rc= mysql_stmt_bind_param(stmt, my_bind);
2577 check_execute(stmt, rc);
2579 rc= mysql_stmt_execute(stmt);
2580 check_execute(stmt, rc);
2582 rc= my_process_stmt_result(stmt);
2583 DIE_UNLESS(rc == 0);
2585 mysql_stmt_close(stmt);
2594 static void test_bug1644()
2603 char query[MAX_TEST_QUERY_LENGTH];
2605 myheader(
"test_bug1644");
2607 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS foo_dfr");
2610 rc= mysql_query(mysql,
2611 "CREATE TABLE foo_dfr(col1 int, col2 int, col3 int, col4 int);");
2614 strmov(query,
"INSERT INTO foo_dfr VALUES (?, ?, ?, ? )");
2615 stmt= mysql_simple_prepare(mysql, query);
2618 verify_param_count(stmt, 4);
2621 memset(my_bind, 0,
sizeof(my_bind));
2625 for (i= 0 ; i < 4 ; i++)
2627 my_bind[
i].buffer_type= MYSQL_TYPE_LONG;
2628 my_bind[
i].buffer= (
void *)#
2629 my_bind[
i].is_null= &isnull;
2632 rc= mysql_stmt_bind_param(stmt, my_bind);
2633 check_execute(stmt, rc);
2635 rc= mysql_stmt_execute(stmt);
2636 check_execute(stmt, rc);
2639 for (i= 0 ; i < 4 ; i++)
2640 my_bind[i].is_null= &isnull;
2642 rc= mysql_stmt_bind_param(stmt, my_bind);
2643 check_execute(stmt, rc);
2645 rc= mysql_stmt_execute(stmt);
2646 check_execute(stmt, rc);
2650 for (i= 0 ; i < 4 ; i++)
2651 my_bind[i].is_null= &isnull;
2653 rc= mysql_stmt_bind_param(stmt, my_bind);
2654 check_execute(stmt, rc);
2656 rc= mysql_stmt_execute(stmt);
2657 check_execute(stmt, rc);
2659 mysql_stmt_close(stmt);
2661 rc= mysql_query(mysql,
"SELECT * FROM foo_dfr");
2664 result= mysql_store_result(mysql);
2667 rc= my_process_result_set(result);
2668 DIE_UNLESS(rc == 3);
2670 mysql_data_seek(result, 0);
2672 row= mysql_fetch_row(result);
2674 for (i= 0 ; i < 4 ; i++)
2676 DIE_UNLESS(strcmp(row[i],
"22") == 0);
2678 row= mysql_fetch_row(result);
2680 for (i= 0 ; i < 4 ; i++)
2682 DIE_UNLESS(row[i] == 0);
2684 row= mysql_fetch_row(result);
2686 for (i= 0 ; i < 4 ; i++)
2688 DIE_UNLESS(strcmp(row[i],
"88") == 0);
2690 row= mysql_fetch_row(result);
2693 mysql_free_result(result);
2699 static void test_select_show()
2703 char query[MAX_TEST_QUERY_LENGTH];
2705 myheader(
"test_select_show");
2707 mysql_autocommit(mysql, TRUE);
2709 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_show");
2712 rc= mysql_query(mysql,
"CREATE TABLE test_show(id int(4) NOT NULL primary "
2713 " key, name char(2))");
2716 stmt= mysql_simple_prepare(mysql,
"show columns from test_show");
2719 verify_param_count(stmt, 0);
2721 rc= mysql_stmt_execute(stmt);
2722 check_execute(stmt, rc);
2724 my_process_stmt_result(stmt);
2725 mysql_stmt_close(stmt);
2727 stmt= mysql_simple_prepare(mysql,
"show tables from mysql like ?");
2730 strxmov(query,
"show tables from ", current_db,
" like \'test_show\'", NullS);
2731 stmt= mysql_simple_prepare(mysql, query);
2734 rc= mysql_stmt_execute(stmt);
2735 check_execute(stmt, rc);
2737 my_process_stmt_result(stmt);
2738 mysql_stmt_close(stmt);
2740 stmt= mysql_simple_prepare(mysql,
"describe test_show");
2743 rc= mysql_stmt_execute(stmt);
2744 check_execute(stmt, rc);
2746 my_process_stmt_result(stmt);
2747 mysql_stmt_close(stmt);
2749 stmt= mysql_simple_prepare(mysql,
"show keys from test_show");
2752 rc= mysql_stmt_execute(stmt);
2753 check_execute(stmt, rc);
2755 rc= my_process_stmt_result(stmt);
2756 DIE_UNLESS(rc == 1);
2757 mysql_stmt_close(stmt);
2763 static void test_simple_update()
2772 char query[MAX_TEST_QUERY_LENGTH];
2774 myheader(
"test_simple_update");
2776 rc= mysql_autocommit(mysql, TRUE);
2779 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_update");
2782 rc= mysql_query(mysql,
"CREATE TABLE test_update(col1 int, "
2783 " col2 varchar(50), col3 int )");
2786 rc= mysql_query(mysql,
"INSERT INTO test_update VALUES(1, 'MySQL', 100)");
2789 verify_affected_rows(1);
2791 rc= mysql_commit(mysql);
2795 strmov(query,
"UPDATE test_update SET col2= ? WHERE col1= ?");
2796 stmt= mysql_simple_prepare(mysql, query);
2799 verify_param_count(stmt, 2);
2802 memset(my_bind, 0,
sizeof(my_bind));
2805 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
2806 my_bind[0].buffer= szData;
2807 my_bind[0].buffer_length=
sizeof(szData);
2808 my_bind[0].length= &length[0];
2809 length[0]= sprintf(szData,
"updated-data");
2811 my_bind[1].buffer= (
void *) &nData;
2812 my_bind[1].buffer_type= MYSQL_TYPE_LONG;
2814 rc= mysql_stmt_bind_param(stmt, my_bind);
2815 check_execute(stmt, rc);
2817 rc= mysql_stmt_execute(stmt);
2818 check_execute(stmt, rc);
2819 verify_affected_rows(1);
2821 mysql_stmt_close(stmt);
2824 rc= mysql_commit(mysql);
2828 rc= mysql_query(mysql,
"SELECT * FROM test_update");
2832 result= mysql_store_result(mysql);
2835 rc= my_process_result_set(result);
2836 DIE_UNLESS(rc == 1);
2837 mysql_free_result(result);
2843 static void test_long_data()
2850 char query[MAX_TEST_QUERY_LENGTH];
2852 myheader(
"test_long_data");
2854 rc= mysql_autocommit(mysql, TRUE);
2857 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_long_data");
2860 rc= mysql_query(mysql,
"CREATE TABLE test_long_data(col1 int, "
2861 " col2 long varchar, col3 long varbinary)");
2864 strmov(query,
"INSERT INTO test_long_data(col1, col2) VALUES(?)");
2865 stmt= mysql_simple_prepare(mysql, query);
2868 strmov(query,
"INSERT INTO test_long_data(col1, col2, col3) VALUES(?, ?, ?)");
2869 stmt= mysql_simple_prepare(mysql, query);
2872 verify_param_count(stmt, 3);
2875 memset(my_bind, 0,
sizeof(my_bind));
2877 my_bind[0].buffer= (
void *)&int_data;
2878 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
2880 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
2882 my_bind[2]= my_bind[1];
2883 rc= mysql_stmt_bind_param(stmt, my_bind);
2884 check_execute(stmt, rc);
2887 data= (
char *)
"Michael";
2890 rc= mysql_stmt_send_long_data(stmt, 1, data, strlen(data));
2891 data= (
char *)
" 'Monty' Widenius";
2892 rc= mysql_stmt_send_long_data(stmt, 1, data, strlen(data));
2893 check_execute(stmt, rc);
2894 rc= mysql_stmt_send_long_data(stmt, 2,
"Venu (venu@mysql.com)", 4);
2895 check_execute(stmt, rc);
2898 rc= mysql_stmt_execute(stmt);
2900 fprintf(stdout,
" mysql_stmt_execute() returned %d\n", rc);
2901 check_execute(stmt, rc);
2903 rc= mysql_commit(mysql);
2907 rc= mysql_query(mysql,
"SELECT * FROM test_long_data");
2911 result= mysql_store_result(mysql);
2914 rc= my_process_result_set(result);
2915 DIE_UNLESS(rc == 1);
2916 mysql_free_result(result);
2918 verify_col_data(
"test_long_data",
"col1",
"999");
2919 verify_col_data(
"test_long_data",
"col2",
"Michael 'Monty' Widenius");
2920 verify_col_data(
"test_long_data",
"col3",
"Venu");
2921 mysql_stmt_close(stmt);
2927 static void test_long_data_str()
2937 char query[MAX_TEST_QUERY_LENGTH];
2939 myheader(
"test_long_data_str");
2941 rc= mysql_autocommit(mysql, TRUE);
2944 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_long_data_str");
2947 rc= mysql_query(mysql,
"CREATE TABLE test_long_data_str(id int, longstr long varchar)");
2950 strmov(query,
"INSERT INTO test_long_data_str VALUES(?, ?)");
2951 stmt= mysql_simple_prepare(mysql, query);
2954 verify_param_count(stmt, 2);
2957 memset(my_bind, 0,
sizeof(my_bind));
2959 my_bind[0].buffer= (
void *)&length;
2960 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
2961 my_bind[0].is_null= &is_null[0];
2965 my_bind[1].buffer= data;
2966 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
2967 my_bind[1].length= &length1;
2968 my_bind[1].is_null= &is_null[1];
2970 rc= mysql_stmt_bind_param(stmt, my_bind);
2971 check_execute(stmt, rc);
2974 strmov(data,
"MySQL AB");
2977 for(i= 0; i < 4; i++)
2979 rc= mysql_stmt_send_long_data(stmt, 1, (
char *)data, 5);
2980 check_execute(stmt, rc);
2983 rc= mysql_stmt_execute(stmt);
2985 fprintf(stdout,
" mysql_stmt_execute() returned %d\n", rc);
2986 check_execute(stmt, rc);
2988 mysql_stmt_close(stmt);
2990 rc= mysql_commit(mysql);
2994 rc= mysql_query(mysql,
"SELECT LENGTH(longstr), longstr FROM test_long_data_str");
2998 result= mysql_store_result(mysql);
3001 rc= my_process_result_set(result);
3002 DIE_UNLESS(rc == 1);
3003 mysql_free_result(result);
3005 sprintf(data,
"%d", i*5);
3006 verify_col_data(
"test_long_data_str",
"LENGTH(longstr)", data);
3009 strxmov(data, data,
"MySQL", NullS);
3010 verify_col_data(
"test_long_data_str",
"longstr", data);
3012 rc= mysql_query(mysql,
"DROP TABLE test_long_data_str");
3019 static void test_long_data_str1()
3025 ulong max_blob_length, blob_length, length1;
3030 char query[MAX_TEST_QUERY_LENGTH];
3032 myheader(
"test_long_data_str1");
3034 rc= mysql_autocommit(mysql, TRUE);
3037 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_long_data_str");
3040 rc= mysql_query(mysql,
"CREATE TABLE test_long_data_str(longstr long varchar, blb long varbinary)");
3043 strmov(query,
"INSERT INTO test_long_data_str VALUES(?, ?)");
3044 stmt= mysql_simple_prepare(mysql, query);
3047 verify_param_count(stmt, 2);
3050 memset(my_bind, 0,
sizeof(my_bind));
3052 my_bind[0].buffer= data;
3053 my_bind[0].buffer_length=
sizeof(data);
3054 my_bind[0].length= &length1;
3055 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
3058 my_bind[1]= my_bind[0];
3059 my_bind[1].buffer_type= MYSQL_TYPE_BLOB;
3061 rc= mysql_stmt_bind_param(stmt, my_bind);
3062 check_execute(stmt, rc);
3063 length= sprintf(data,
"MySQL AB");
3066 for (i= 0; i < 3; i++)
3068 rc= mysql_stmt_send_long_data(stmt, 0, data, length);
3069 check_execute(stmt, rc);
3071 rc= mysql_stmt_send_long_data(stmt, 1, data, 2);
3072 check_execute(stmt, rc);
3076 rc= mysql_stmt_execute(stmt);
3078 fprintf(stdout,
" mysql_stmt_execute() returned %d\n", rc);
3079 check_execute(stmt, rc);
3081 mysql_stmt_close(stmt);
3083 rc= mysql_commit(mysql);
3087 rc= mysql_query(mysql,
"SELECT LENGTH(longstr), longstr, LENGTH(blb), blb FROM test_long_data_str");
3091 result= mysql_store_result(mysql);
3093 mysql_field_seek(result, 1);
3094 field= mysql_fetch_field(result);
3095 max_blob_length= field->max_length;
3099 rc= my_process_result_set(result);
3100 DIE_UNLESS(rc == 1);
3101 mysql_free_result(result);
3103 sprintf(data,
"%ld", (
long)i*length);
3104 verify_col_data(
"test_long_data_str",
"length(longstr)", data);
3106 sprintf(data,
"%d", i*2);
3107 verify_col_data(
"test_long_data_str",
"length(blb)", data);
3110 stmt= mysql_simple_prepare(mysql,
"SELECT * from test_long_data_str");
3112 verify_param_count(stmt, 0);
3114 rc= mysql_stmt_execute(stmt);
3115 check_execute(stmt, rc);
3117 rc= mysql_stmt_store_result(stmt);
3118 check_execute(stmt, rc);
3120 result= mysql_stmt_result_metadata(stmt);
3121 field= mysql_fetch_fields(result);
3124 DIE_UNLESS(field->max_length == 0);
3125 mysql_free_result(result);
3129 mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (
void*) &true_value);
3130 rc= mysql_stmt_execute(stmt);
3131 check_execute(stmt, rc);
3133 rc= mysql_stmt_store_result(stmt);
3134 check_execute(stmt, rc);
3136 result= mysql_stmt_result_metadata(stmt);
3137 field= mysql_fetch_fields(result);
3139 DIE_UNLESS(field->max_length == max_blob_length);
3142 memset(my_bind, 0,
sizeof(*my_bind));
3143 my_bind[0].buffer_type= MYSQL_TYPE_BLOB;
3144 my_bind[0].buffer= (
void *) &data;
3145 my_bind[0].buffer_length= 16;
3146 my_bind[0].length= &blob_length;
3147 my_bind[0].error= &my_bind[0].error_value;
3148 rc= mysql_stmt_bind_result(stmt, my_bind);
3151 rc= mysql_stmt_fetch(stmt);
3152 DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED);
3153 DIE_UNLESS(my_bind[0].error_value);
3154 DIE_UNLESS(strlen(data) == 16);
3155 DIE_UNLESS(blob_length == max_blob_length);
3158 memset((my_bind+1), 0,
sizeof(*my_bind));
3159 my_bind[1].buffer_type= MYSQL_TYPE_BLOB;
3160 my_bind[1].buffer= (
void *) &data;
3161 my_bind[1].buffer_length=
sizeof(data);
3162 my_bind[1].length= &blob_length;
3163 memset(data, 0,
sizeof(data));
3164 mysql_stmt_fetch_column(stmt, my_bind+1, 0, 0);
3165 DIE_UNLESS(strlen(data) == max_blob_length);
3167 mysql_free_result(result);
3168 mysql_stmt_close(stmt);
3171 rc= mysql_query(mysql,
"DROP TABLE test_long_data_str");
3178 static void test_long_data_bin()
3186 char query[MAX_TEST_QUERY_LENGTH];
3189 myheader(
"test_long_data_bin");
3191 rc= mysql_autocommit(mysql, TRUE);
3194 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_long_data_bin");
3197 rc= mysql_query(mysql,
"CREATE TABLE test_long_data_bin(id int, longbin long varbinary)");
3200 strmov(query,
"INSERT INTO test_long_data_bin VALUES(?, ?)");
3201 stmt= mysql_simple_prepare(mysql, query);
3204 verify_param_count(stmt, 2);
3207 memset(my_bind, 0,
sizeof(my_bind));
3209 my_bind[0].buffer= (
void *)&length;
3210 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
3213 my_bind[1].buffer= data;
3214 my_bind[1].buffer_type= MYSQL_TYPE_LONG_BLOB;
3215 rc= mysql_stmt_bind_param(stmt, my_bind);
3216 check_execute(stmt, rc);
3219 strmov(data,
"MySQL AB");
3224 for (i= 0; i < 100; i++)
3226 rc= mysql_stmt_send_long_data(stmt, 1, (
char *)data, 4);
3227 check_execute(stmt, rc);
3231 rc= mysql_stmt_execute(stmt);
3233 fprintf(stdout,
" mysql_stmt_execute() returned %d\n", rc);
3234 check_execute(stmt, rc);
3236 mysql_stmt_close(stmt);
3238 rc= mysql_commit(mysql);
3242 rc= mysql_query(mysql,
"SELECT LENGTH(longbin), longbin FROM test_long_data_bin");
3246 result= mysql_store_result(mysql);
3249 rc= my_process_result_set(result);
3250 DIE_UNLESS(rc == 1);
3251 mysql_free_result(result);
3257 static void test_simple_delete()
3261 char szData[30]= {0};
3266 char query[MAX_TEST_QUERY_LENGTH];
3268 myheader(
"test_simple_delete");
3270 rc= mysql_autocommit(mysql, TRUE);
3273 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_simple_delete");
3276 rc= mysql_query(mysql,
"CREATE TABLE test_simple_delete(col1 int, \
3277 col2 varchar(50), col3 int )");
3280 rc= mysql_query(mysql,
"INSERT INTO test_simple_delete VALUES(1, 'MySQL', 100)");
3283 verify_affected_rows(1);
3285 rc= mysql_commit(mysql);
3289 strmov(query,
"DELETE FROM test_simple_delete WHERE col1= ? AND "
3290 "CONVERT(col2 USING utf8)= ? AND col3= 100");
3291 stmt= mysql_simple_prepare(mysql, query);
3294 verify_param_count(stmt, 2);
3297 memset(my_bind, 0,
sizeof(my_bind));
3300 strmov(szData,
"MySQL");
3301 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
3302 my_bind[1].buffer= szData;
3303 my_bind[1].buffer_length=
sizeof(szData);
3304 my_bind[1].length= &length[1];
3307 my_bind[0].buffer= (
void *)&nData;
3308 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
3310 rc= mysql_stmt_bind_param(stmt, my_bind);
3311 check_execute(stmt, rc);
3313 rc= mysql_stmt_execute(stmt);
3314 check_execute(stmt, rc);
3316 verify_affected_rows(1);
3318 mysql_stmt_close(stmt);
3321 rc= mysql_commit(mysql);
3325 rc= mysql_query(mysql,
"SELECT * FROM test_simple_delete");
3329 result= mysql_store_result(mysql);
3332 rc= my_process_result_set(result);
3333 DIE_UNLESS(rc == 0);
3334 mysql_free_result(result);
3340 static void test_update()
3349 char query[MAX_TEST_QUERY_LENGTH];
3351 myheader(
"test_update");
3353 rc= mysql_autocommit(mysql, TRUE);
3356 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_update");
3359 rc= mysql_query(mysql,
"CREATE TABLE test_update("
3360 "col1 int primary key auto_increment, "
3361 "col2 varchar(50), col3 int )");
3364 strmov(query,
"INSERT INTO test_update(col2, col3) VALUES(?, ?)");
3365 stmt= mysql_simple_prepare(mysql, query);
3368 verify_param_count(stmt, 2);
3371 memset(my_bind, 0,
sizeof(my_bind));
3374 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
3375 my_bind[0].buffer= szData;
3376 my_bind[0].buffer_length=
sizeof(szData);
3377 my_bind[0].length= &length[0];
3378 length[0]= sprintf(szData,
"inserted-data");
3380 my_bind[1].buffer= (
void *)&nData;
3381 my_bind[1].buffer_type= MYSQL_TYPE_LONG;
3383 rc= mysql_stmt_bind_param(stmt, my_bind);
3384 check_execute(stmt, rc);
3387 rc= mysql_stmt_execute(stmt);
3388 check_execute(stmt, rc);
3390 verify_affected_rows(1);
3391 mysql_stmt_close(stmt);
3393 strmov(query,
"UPDATE test_update SET col2= ? WHERE col3= ?");
3394 stmt= mysql_simple_prepare(mysql, query);
3397 verify_param_count(stmt, 2);
3401 memset(my_bind, 0,
sizeof(my_bind));
3403 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
3404 my_bind[0].buffer= szData;
3405 my_bind[0].buffer_length=
sizeof(szData);
3406 my_bind[0].length= &length[0];
3407 length[0]= sprintf(szData,
"updated-data");
3409 my_bind[1].buffer= (
void *)&nData;
3410 my_bind[1].buffer_type= MYSQL_TYPE_LONG;
3412 rc= mysql_stmt_bind_param(stmt, my_bind);
3413 check_execute(stmt, rc);
3415 rc= mysql_stmt_execute(stmt);
3416 check_execute(stmt, rc);
3417 verify_affected_rows(1);
3419 mysql_stmt_close(stmt);
3422 rc= mysql_commit(mysql);
3426 rc= mysql_query(mysql,
"SELECT * FROM test_update");
3430 result= mysql_store_result(mysql);
3433 rc= my_process_result_set(result);
3434 DIE_UNLESS(rc == 1);
3435 mysql_free_result(result);
3441 static void test_prepare_noparam()
3446 char query[MAX_TEST_QUERY_LENGTH];
3448 myheader(
"test_prepare_noparam");
3450 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS my_prepare");
3454 rc= mysql_query(mysql,
"CREATE TABLE my_prepare(col1 int, col2 varchar(50))");
3458 strmov(query,
"INSERT INTO my_prepare VALUES(10, 'venu')");
3459 stmt= mysql_simple_prepare(mysql, query);
3462 verify_param_count(stmt, 0);
3464 rc= mysql_stmt_execute(stmt);
3465 check_execute(stmt, rc);
3467 mysql_stmt_close(stmt);
3470 rc= mysql_commit(mysql);
3474 rc= mysql_query(mysql,
"SELECT * FROM my_prepare");
3478 result= mysql_store_result(mysql);
3481 rc= my_process_result_set(result);
3482 DIE_UNLESS(rc == 1);
3483 mysql_free_result(result);
3489 static void test_bind_result()
3499 myheader(
"test_bind_result");
3501 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bind_result");
3504 rc= mysql_query(mysql,
"CREATE TABLE test_bind_result(col1 int , col2 varchar(50))");
3507 rc= mysql_query(mysql,
"INSERT INTO test_bind_result VALUES(10, 'venu')");
3510 rc= mysql_query(mysql,
"INSERT INTO test_bind_result VALUES(20, 'MySQL')");
3513 rc= mysql_query(mysql,
"INSERT INTO test_bind_result(col2) VALUES('monty')");
3516 rc= mysql_commit(mysql);
3521 memset(my_bind, 0,
sizeof(my_bind));
3522 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
3523 my_bind[0].buffer= (
void *) &nData;
3524 my_bind[0].is_null= &is_null[0];
3526 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
3527 my_bind[1].buffer= szData;
3528 my_bind[1].buffer_length=
sizeof(szData);
3529 my_bind[1].length= &length1;
3530 my_bind[1].is_null= &is_null[1];
3532 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_bind_result");
3535 rc= mysql_stmt_bind_result(stmt, my_bind);
3536 check_execute(stmt, rc);
3538 rc= mysql_stmt_execute(stmt);
3539 check_execute(stmt, rc);
3541 rc= mysql_stmt_fetch(stmt);
3542 check_execute(stmt, rc);
3545 fprintf(stdout,
"\n row 1: %d, %s(%lu)", nData, szData, length1);
3546 DIE_UNLESS(nData == 10);
3547 DIE_UNLESS(strcmp(szData,
"venu") == 0);
3548 DIE_UNLESS(length1 == 4);
3550 rc= mysql_stmt_fetch(stmt);
3551 check_execute(stmt, rc);
3554 fprintf(stdout,
"\n row 2: %d, %s(%lu)", nData, szData, length1);
3555 DIE_UNLESS(nData == 20);
3556 DIE_UNLESS(strcmp(szData,
"MySQL") == 0);
3557 DIE_UNLESS(length1 == 5);
3559 rc= mysql_stmt_fetch(stmt);
3560 check_execute(stmt, rc);
3562 if (!opt_silent && is_null[0])
3563 fprintf(stdout,
"\n row 3: NULL, %s(%lu)", szData, length1);
3564 DIE_UNLESS(is_null[0]);
3565 DIE_UNLESS(strcmp(szData,
"monty") == 0);
3566 DIE_UNLESS(length1 == 5);
3568 rc= mysql_stmt_fetch(stmt);
3569 DIE_UNLESS(rc == MYSQL_NO_DATA);
3571 mysql_stmt_close(stmt);
3577 static void test_bind_result_ext()
3587 char szData[20], bData[20];
3588 ulong szLength, bLength;
3593 myheader(
"test_bind_result_ext");
3595 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bind_result");
3598 rc= mysql_query(mysql,
"CREATE TABLE test_bind_result(c1 tinyint, "
3600 " c3 int, c4 bigint, "
3601 " c5 float, c6 double, "
3602 " c7 varbinary(10), "
3603 " c8 varchar(50))");
3606 rc= mysql_query(mysql,
"INSERT INTO test_bind_result "
3607 "VALUES (19, 2999, 3999, 4999999, "
3608 " 2345.6, 5678.89563, 'venu', 'mysql')");
3611 rc= mysql_commit(mysql);
3614 memset(my_bind, 0,
sizeof(my_bind));
3615 for (i= 0; i < (int) array_elements(my_bind); i++)
3617 my_bind[
i].length= &length[
i];
3618 my_bind[
i].is_null= &is_null[
i];
3621 my_bind[0].buffer_type= MYSQL_TYPE_TINY;
3622 my_bind[0].buffer= (
void *)&t_data;
3624 my_bind[1].buffer_type= MYSQL_TYPE_SHORT;
3625 my_bind[2].buffer_type= MYSQL_TYPE_LONG;
3627 my_bind[3].buffer_type= MYSQL_TYPE_LONGLONG;
3628 my_bind[1].buffer= (
void *)&s_data;
3630 my_bind[2].buffer= (
void *)&i_data;
3631 my_bind[3].buffer= (
void *)&b_data;
3633 my_bind[4].buffer_type= MYSQL_TYPE_FLOAT;
3634 my_bind[4].buffer= (
void *)&f_data;
3636 my_bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
3637 my_bind[5].buffer= (
void *)&d_data;
3639 my_bind[6].buffer_type= MYSQL_TYPE_STRING;
3640 my_bind[6].buffer= (
void *)szData;
3641 my_bind[6].buffer_length=
sizeof(szData);
3642 my_bind[6].length= &szLength;
3644 my_bind[7].buffer_type= MYSQL_TYPE_TINY_BLOB;
3645 my_bind[7].buffer= (
void *)&bData;
3646 my_bind[7].length= &bLength;
3647 my_bind[7].buffer_length=
sizeof(bData);
3649 stmt= mysql_simple_prepare(mysql,
"select * from test_bind_result");
3652 rc= mysql_stmt_bind_result(stmt, my_bind);
3653 check_execute(stmt, rc);
3655 rc= mysql_stmt_execute(stmt);
3656 check_execute(stmt, rc);
3658 rc= mysql_stmt_fetch(stmt);
3659 check_execute(stmt, rc);
3663 fprintf(stdout,
"\n data (tiny) : %d", t_data);
3664 fprintf(stdout,
"\n data (short) : %d", s_data);
3665 fprintf(stdout,
"\n data (int) : %d", i_data);
3666 fprintf(stdout,
"\n data (big) : %s", llstr(b_data, llbuf));
3668 fprintf(stdout,
"\n data (float) : %f", f_data);
3669 fprintf(stdout,
"\n data (double) : %f", d_data);
3671 fprintf(stdout,
"\n data (str) : %s(%lu)", szData, szLength);
3673 bData[bLength]=
'\0';
3674 fprintf(stdout,
"\n data (bin) : %s(%lu)", bData, bLength);
3677 DIE_UNLESS(t_data == 19);
3678 DIE_UNLESS(s_data == 2999);
3679 DIE_UNLESS(i_data == 3999);
3680 DIE_UNLESS(b_data == 4999999);
3683 DIE_UNLESS(strcmp(szData,
"venu") == 0);
3684 DIE_UNLESS(strncmp(bData,
"mysql", 5) == 0);
3685 DIE_UNLESS(szLength == 4);
3686 DIE_UNLESS(bLength == 5);
3688 rc= mysql_stmt_fetch(stmt);
3689 DIE_UNLESS(rc == MYSQL_NO_DATA);
3691 mysql_stmt_close(stmt);
3697 static void test_bind_result_ext1()
3713 myheader(
"test_bind_result_ext1");
3715 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bind_result");
3718 rc= mysql_query(mysql,
"CREATE TABLE test_bind_result(c1 tinyint, c2 smallint, \
3719 c3 int, c4 bigint, \
3720 c5 float, c6 double, \
3725 rc= mysql_query(mysql,
"INSERT INTO test_bind_result VALUES(120, 2999, 3999, 54, \
3730 rc= mysql_commit(mysql);
3733 memset(my_bind, 0,
sizeof(my_bind));
3734 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
3735 my_bind[0].buffer= (
void *) t_data;
3736 my_bind[0].buffer_length=
sizeof(t_data);
3737 my_bind[0].error= &my_bind[0].error_value;
3739 my_bind[1].buffer_type= MYSQL_TYPE_FLOAT;
3740 my_bind[1].buffer= (
void *)&s_data;
3741 my_bind[1].buffer_length= 0;
3742 my_bind[1].error= &my_bind[1].error_value;
3744 my_bind[2].buffer_type= MYSQL_TYPE_SHORT;
3745 my_bind[2].buffer= (
void *)&i_data;
3746 my_bind[2].buffer_length= 0;
3747 my_bind[2].error= &my_bind[2].error_value;
3749 my_bind[3].buffer_type= MYSQL_TYPE_TINY;
3750 my_bind[3].buffer= (
void *)&b_data;
3751 my_bind[3].buffer_length= 0;
3752 my_bind[3].error= &my_bind[3].error_value;
3754 my_bind[4].buffer_type= MYSQL_TYPE_LONG;
3755 my_bind[4].buffer= (
void *)&f_data;
3756 my_bind[4].buffer_length= 0;
3757 my_bind[4].error= &my_bind[4].error_value;
3759 my_bind[5].buffer_type= MYSQL_TYPE_STRING;
3760 my_bind[5].buffer= (
void *)d_data;
3761 my_bind[5].buffer_length=
sizeof(d_data);
3762 my_bind[5].error= &my_bind[5].error_value;
3764 my_bind[6].buffer_type= MYSQL_TYPE_LONG;
3765 my_bind[6].buffer= (
void *)&bData;
3766 my_bind[6].buffer_length= 0;
3767 my_bind[6].error= &my_bind[6].error_value;
3769 my_bind[7].buffer_type= MYSQL_TYPE_DOUBLE;
3770 my_bind[7].buffer= (
void *)&szData;
3771 my_bind[7].buffer_length= 0;
3772 my_bind[7].error= &my_bind[7].error_value;
3774 for (i= 0; i < array_elements(my_bind); i++)
3776 my_bind[
i].is_null= &is_null[
i];
3777 my_bind[
i].length= &length[
i];
3780 stmt= mysql_simple_prepare(mysql,
"select * from test_bind_result");
3783 rc= mysql_stmt_bind_result(stmt, my_bind);
3784 check_execute(stmt, rc);
3786 rc= mysql_stmt_execute(stmt);
3787 check_execute(stmt, rc);
3789 rc= mysql_stmt_fetch(stmt);
3790 printf(
"rc=%d\n", rc);
3791 DIE_UNLESS(rc == 0);
3795 fprintf(stdout,
"\n data (tiny) : %s(%lu)", t_data, length[0]);
3796 fprintf(stdout,
"\n data (short) : %f(%lu)", s_data, length[1]);
3797 fprintf(stdout,
"\n data (int) : %d(%lu)", i_data, length[2]);
3798 fprintf(stdout,
"\n data (big) : %d(%lu)", b_data, length[3]);
3800 fprintf(stdout,
"\n data (float) : %d(%lu)", f_data, length[4]);
3801 fprintf(stdout,
"\n data (double) : %s(%lu)", d_data, length[5]);
3803 fprintf(stdout,
"\n data (bin) : %ld(%lu)", bData, length[6]);
3804 fprintf(stdout,
"\n data (str) : %g(%lu)", szData, length[7]);
3807 DIE_UNLESS(strcmp(t_data,
"120") == 0);
3808 DIE_UNLESS(i_data == 3999);
3809 DIE_UNLESS(f_data == 2);
3810 DIE_UNLESS(strcmp(d_data,
"58.89") == 0);
3811 DIE_UNLESS(b_data == 54);
3813 DIE_UNLESS(length[0] == 3);
3814 DIE_UNLESS(length[1] == 4);
3815 DIE_UNLESS(length[2] == 2);
3816 DIE_UNLESS(length[3] == 1);
3817 DIE_UNLESS(length[4] == 4);
3818 DIE_UNLESS(length[5] == 5);
3819 DIE_UNLESS(length[6] == 4);
3820 DIE_UNLESS(length[7] == 8);
3822 rc= mysql_stmt_fetch(stmt);
3823 DIE_UNLESS(rc == MYSQL_NO_DATA);
3825 mysql_stmt_close(stmt);
3831 static void bind_fetch(
int row_count)
3834 int rc,
i, count= row_count;
3847 stmt= mysql_simple_prepare(mysql,
"INSERT INTO test_bind_fetch VALUES "
3848 "(?, ?, ?, ?, ?, ?, ?)");
3851 verify_param_count(stmt, 7);
3854 memset(my_bind, 0,
sizeof(my_bind));
3856 for (i= 0; i < (int) array_elements(my_bind); i++)
3858 my_bind[
i].buffer_type= MYSQL_TYPE_LONG;
3859 my_bind[
i].buffer= (
void *) &data[i];
3861 rc= mysql_stmt_bind_param(stmt, my_bind);
3862 check_execute(stmt, rc);
3867 for (i= 0; i < (int) array_elements(my_bind); i++)
3872 rc= mysql_stmt_execute(stmt);
3873 check_execute(stmt, rc);
3876 rc= mysql_commit(mysql);
3879 mysql_stmt_close(stmt);
3881 rc= my_stmt_result(
"SELECT * FROM test_bind_fetch");
3882 DIE_UNLESS(row_count == rc);
3884 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_bind_fetch");
3887 for (i= 0; i < (int) array_elements(my_bind); i++)
3889 my_bind[
i].buffer= (
void *) &data[i];
3890 my_bind[
i].length= &length[
i];
3891 my_bind[
i].is_null= &is_null[
i];
3894 my_bind[0].buffer_type= MYSQL_TYPE_TINY;
3895 my_bind[0].buffer= (
void *)&i8_data;
3897 my_bind[1].buffer_type= MYSQL_TYPE_SHORT;
3898 my_bind[1].buffer= (
void *)&i16_data;
3900 my_bind[2].buffer_type= MYSQL_TYPE_LONG;
3901 my_bind[2].buffer= (
void *)&i32_data;
3903 my_bind[3].buffer_type= MYSQL_TYPE_LONGLONG;
3904 my_bind[3].buffer= (
void *)&i64_data;
3906 my_bind[4].buffer_type= MYSQL_TYPE_FLOAT;
3907 my_bind[4].buffer= (
void *)&f_data;
3909 my_bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
3910 my_bind[5].buffer= (
void *)&d_data;
3912 my_bind[6].buffer_type= MYSQL_TYPE_STRING;
3913 my_bind[6].buffer= (
void *)&s_data;
3914 my_bind[6].buffer_length=
sizeof(s_data);
3916 rc= mysql_stmt_bind_result(stmt, my_bind);
3917 check_execute(stmt, rc);
3919 rc= mysql_stmt_execute(stmt);
3920 check_execute(stmt, rc);
3922 rc= mysql_stmt_store_result(stmt);
3923 check_execute(stmt, rc);
3927 rc= mysql_stmt_fetch(stmt);
3928 check_execute(stmt, rc);
3932 fprintf(stdout,
"\n");
3933 fprintf(stdout,
"\n tiny : %ld(%lu)", (ulong) i8_data, length[0]);
3934 fprintf(stdout,
"\n short : %ld(%lu)", (ulong) i16_data, length[1]);
3935 fprintf(stdout,
"\n int : %ld(%lu)", (ulong) i32_data, length[2]);
3936 fprintf(stdout,
"\n longlong : %ld(%lu)", (ulong) i64_data, length[3]);
3937 fprintf(stdout,
"\n float : %f(%lu)", f_data, length[4]);
3938 fprintf(stdout,
"\n double : %g(%lu)", d_data, length[5]);
3939 fprintf(stdout,
"\n char : %s(%lu)", s_data, length[6]);
3944 DIE_UNLESS((
int) i8_data == rc);
3945 DIE_UNLESS(length[0] == 1);
3949 DIE_UNLESS((
int) i16_data == rc);
3950 DIE_UNLESS(length[1] == 2);
3954 DIE_UNLESS((
int) i32_data == rc);
3955 DIE_UNLESS(length[2] == 4);
3959 DIE_UNLESS((
int) i64_data == rc);
3960 DIE_UNLESS(length[3] == 8);
3964 DIE_UNLESS((
int)f_data == rc);
3965 DIE_UNLESS(length[4] == 4);
3969 DIE_UNLESS((
int)d_data == rc);
3970 DIE_UNLESS(length[5] == 8);
3976 long len= sprintf(buff,
"%d", rc);
3977 DIE_UNLESS(strcmp(s_data, buff) == 0);
3978 DIE_UNLESS(length[6] == (ulong) len);
3981 rc= mysql_stmt_fetch(stmt);
3982 DIE_UNLESS(rc == MYSQL_NO_DATA);
3984 mysql_stmt_close(stmt);
3990 static void test_fetch_date()
3995 char date[25], my_time[25], ts[25], ts_4[25], ts_6[20], dt[20];
3996 ulong d_length, t_length, ts_length, ts4_length, ts6_length,
3997 dt_length, y_length;
4002 myheader(
"test_fetch_date");
4005 rc= mysql_query(mysql,
"SET SQL_MODE=''");
4008 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bind_result");
4011 rc= mysql_query(mysql,
"CREATE TABLE test_bind_result(c1 date, c2 time, \
4019 rc= mysql_query(mysql,
"SET SQL_MODE=''");
4020 rc= mysql_query(mysql,
"INSERT INTO test_bind_result VALUES('2002-01-02', \
4022 '2002-01-02 17:46:59', \
4025 '2020', '1999-12-29')");
4028 rc= mysql_commit(mysql);
4031 memset(my_bind, 0,
sizeof(my_bind));
4032 for (i= 0; i < array_elements(my_bind); i++)
4034 my_bind[
i].is_null= &is_null[
i];
4035 my_bind[
i].length= &length[
i];
4038 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
4039 my_bind[1]= my_bind[2]= my_bind[0];
4041 my_bind[0].buffer= (
void *)&date;
4042 my_bind[0].buffer_length=
sizeof(date);
4043 my_bind[0].length= &d_length;
4045 my_bind[1].buffer= (
void *)&my_time;
4046 my_bind[1].buffer_length=
sizeof(my_time);
4047 my_bind[1].length= &t_length;
4049 my_bind[2].buffer= (
void *)&ts;
4050 my_bind[2].buffer_length=
sizeof(ts);
4051 my_bind[2].length= &ts_length;
4053 my_bind[3].buffer_type= MYSQL_TYPE_LONG;
4054 my_bind[3].buffer= (
void *)&year;
4055 my_bind[3].length= &y_length;
4057 my_bind[4].buffer_type= MYSQL_TYPE_STRING;
4058 my_bind[4].buffer= (
void *)&dt;
4059 my_bind[4].buffer_length=
sizeof(dt);
4060 my_bind[4].length= &dt_length;
4062 my_bind[5].buffer_type= MYSQL_TYPE_STRING;
4063 my_bind[5].buffer= (
void *)&ts_4;
4064 my_bind[5].buffer_length=
sizeof(ts_4);
4065 my_bind[5].length= &ts4_length;
4067 my_bind[6].buffer_type= MYSQL_TYPE_STRING;
4068 my_bind[6].buffer= (
void *)&ts_6;
4069 my_bind[6].buffer_length=
sizeof(ts_6);
4070 my_bind[6].length= &ts6_length;
4072 rc= my_stmt_result(
"SELECT * FROM test_bind_result");
4073 DIE_UNLESS(rc == 1);
4075 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_bind_result");
4078 rc= mysql_stmt_bind_result(stmt, my_bind);
4079 check_execute(stmt, rc);
4081 rc= mysql_stmt_execute(stmt);
4082 check_execute(stmt, rc);
4085 rc= mysql_stmt_fetch(stmt);
4086 check_execute(stmt, rc);
4090 fprintf(stdout,
"\n date : %s(%lu)", date, d_length);
4091 fprintf(stdout,
"\n time : %s(%lu)", my_time, t_length);
4092 fprintf(stdout,
"\n ts : %s(%lu)", ts, ts_length);
4093 fprintf(stdout,
"\n year : %d(%lu)", year, y_length);
4094 fprintf(stdout,
"\n dt : %s(%lu)", dt, dt_length);
4095 fprintf(stdout,
"\n ts(4) : %s(%lu)", ts_4, ts4_length);
4096 fprintf(stdout,
"\n ts(6) : %s(%lu)", ts_6, ts6_length);
4099 DIE_UNLESS(strcmp(date,
"2002-01-02") == 0);
4100 DIE_UNLESS(d_length == 10);
4102 DIE_UNLESS(strcmp(my_time,
"12:49:00") == 0);
4103 DIE_UNLESS(t_length == 8);
4105 DIE_UNLESS(strcmp(ts,
"2002-01-02 17:46:59") == 0);
4106 DIE_UNLESS(ts_length == 19);
4108 DIE_UNLESS(year == 2010);
4109 DIE_UNLESS(y_length == 4);
4111 DIE_UNLESS(strcmp(dt,
"2010-07-10 00:00:00") == 0);
4112 DIE_UNLESS(dt_length == 19);
4114 DIE_UNLESS(strcmp(ts_4,
"0000-00-00 00:00:00") == 0);
4115 DIE_UNLESS(ts4_length == strlen(
"0000-00-00 00:00:00"));
4117 DIE_UNLESS(strcmp(ts_6,
"1999-12-29 00:00:00") == 0);
4118 DIE_UNLESS(ts6_length == 19);
4120 rc= mysql_stmt_fetch(stmt);
4121 DIE_UNLESS(rc == MYSQL_NO_DATA);
4123 mysql_stmt_close(stmt);
4129 static void test_fetch_str()
4133 myheader(
"test_fetch_str");
4135 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bind_fetch");
4138 rc= mysql_query(mysql,
"CREATE TABLE test_bind_fetch(c1 char(10), \
4153 static void test_fetch_long()
4157 myheader(
"test_fetch_long");
4159 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bind_fetch");
4162 rc= mysql_query(mysql,
"CREATE TABLE test_bind_fetch(c1 int unsigned, \
4177 static void test_fetch_short()
4181 myheader(
"test_fetch_short");
4183 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bind_fetch");
4186 rc= mysql_query(mysql,
"CREATE TABLE test_bind_fetch(c1 smallint unsigned, \
4188 c3 smallint unsigned, \
4192 c7 smallint unsigned)");
4201 static void test_fetch_tiny()
4205 myheader(
"test_fetch_tiny");
4207 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bind_fetch");
4210 rc= mysql_query(mysql,
"CREATE TABLE test_bind_fetch(c1 tinyint unsigned, \
4212 c3 tinyint unsigned, \
4216 c7 tinyint unsigned)");
4226 static void test_fetch_bigint()
4230 myheader(
"test_fetch_bigint");
4232 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bind_fetch");
4235 rc= mysql_query(mysql,
"CREATE TABLE test_bind_fetch(c1 bigint, \
4237 c3 bigint unsigned, \
4238 c4 bigint unsigned, \
4239 c5 bigint unsigned, \
4240 c6 bigint unsigned, \
4241 c7 bigint unsigned)");
4251 static void test_fetch_float()
4255 myheader(
"test_fetch_float");
4257 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bind_fetch");
4260 rc= mysql_query(mysql,
"CREATE TABLE test_bind_fetch(c1 float(3), \
4262 c3 float unsigned, \
4266 c7 float(10) unsigned)");
4276 static void test_fetch_double()
4280 myheader(
"test_fetch_double");
4282 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bind_fetch");
4285 rc= mysql_query(mysql,
"CREATE TABLE test_bind_fetch(c1 double(5, 2), "
4286 "c2 double unsigned, c3 double unsigned, "
4287 "c4 double unsigned, c5 double unsigned, "
4288 "c6 double unsigned, c7 double unsigned)");
4298 static void test_prepare_ext()
4308 char query[MAX_TEST_QUERY_LENGTH];
4309 myheader(
"test_prepare_ext");
4311 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_prepare_ext");
4314 sql= (
char *)
"CREATE TABLE test_prepare_ext"
4324 " c9 double precision,"
4326 " c11 decimal(7, 4),"
4327 " c12 numeric(8, 4),"
4346 " c31 enum('one', 'two', 'three'),"
4347 " c32 set('monday', 'tuesday', 'wednesday'))";
4349 rc= mysql_query(mysql, sql);
4353 strmov(query, (
char *)
"INSERT INTO test_prepare_ext(c1, c2, c3, c4, c5, c6) VALUES(?, ?, ?, ?, ?, ?)");
4354 stmt= mysql_simple_prepare(mysql, query);
4357 verify_param_count(stmt, 6);
4360 memset(my_bind, 0,
sizeof(my_bind));
4363 my_bind[0].buffer_type= MYSQL_TYPE_TINY;
4364 my_bind[0].buffer= (
void *)&tData;
4367 my_bind[1].buffer_type= MYSQL_TYPE_SHORT;
4368 my_bind[1].buffer= (
void *)&sData;
4371 my_bind[2].buffer_type= MYSQL_TYPE_LONG;
4372 my_bind[2].buffer= (
void *)&nData;
4375 my_bind[3].buffer_type= MYSQL_TYPE_LONG;
4376 my_bind[3].buffer= (
void *)&nData;
4379 my_bind[4].buffer_type= MYSQL_TYPE_LONG;
4380 my_bind[4].buffer= (
void *)&nData;
4383 my_bind[5].buffer_type= MYSQL_TYPE_LONGLONG;
4384 my_bind[5].buffer= (
void *)&bData;
4386 rc= mysql_stmt_bind_param(stmt, my_bind);
4387 check_execute(stmt, rc);
4392 for (nData= 0; nData<10; nData++, tData++, sData++, bData++)
4394 rc= mysql_stmt_execute(stmt);
4395 check_execute(stmt, rc);
4397 mysql_stmt_close(stmt);
4401 stmt= mysql_simple_prepare(mysql,
"SELECT c1, c2, c3, c4, c5, c6 "
4402 "FROM test_prepare_ext");
4406 rc= mysql_stmt_execute(stmt);
4407 check_execute(stmt, rc);
4409 rc= my_process_stmt_result(stmt);
4410 DIE_UNLESS(nData == rc);
4412 mysql_stmt_close(stmt);
4418 static void test_field_names()
4423 myheader(
"test_field_names");
4426 fprintf(stdout,
"\n %d, %d, %d", MYSQL_TYPE_DECIMAL, MYSQL_TYPE_NEWDATE, MYSQL_TYPE_ENUM);
4427 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_field_names1");
4430 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_field_names2");
4433 rc= mysql_query(mysql,
"CREATE TABLE test_field_names1(id int, name varchar(50))");
4436 rc= mysql_query(mysql,
"CREATE TABLE test_field_names2(id int, name varchar(50))");
4440 rc= mysql_query(mysql,
"SELECT id as 'id-alias' FROM test_field_names1");
4443 result= mysql_use_result(mysql);
4446 rc= my_process_result_set(result);
4447 DIE_UNLESS(rc == 0);
4448 mysql_free_result(result);
4451 rc= mysql_query(mysql,
"SELECT t1.id as 'id-alias', test_field_names2.name FROM test_field_names1 t1, test_field_names2");
4454 result= mysql_use_result(mysql);
4457 rc= my_process_result_set(result);
4458 DIE_UNLESS(rc == 0);
4459 mysql_free_result(result);
4465 static void test_warnings()
4470 myheader(
"test_warnings");
4472 mysql_query(mysql,
"DROP TABLE if exists test_non_exists");
4474 rc= mysql_query(mysql,
"DROP TABLE if exists test_non_exists");
4478 fprintf(stdout,
"\n total warnings: %d", mysql_warning_count(mysql));
4479 rc= mysql_query(mysql,
"SHOW WARNINGS");
4482 result= mysql_store_result(mysql);
4485 rc= my_process_result_set(result);
4486 DIE_UNLESS(rc == 1);
4487 mysql_free_result(result);
4493 static void test_errors()
4498 myheader(
"test_errors");
4500 mysql_query(mysql,
"DROP TABLE if exists test_non_exists");
4502 rc= mysql_query(mysql,
"DROP TABLE test_non_exists");
4505 rc= mysql_query(mysql,
"SHOW ERRORS");
4508 result= mysql_store_result(mysql);
4511 (void) my_process_result_set(result);
4512 mysql_free_result(result);
4518 static void test_insert()
4528 myheader(
"test_insert");
4530 rc= mysql_autocommit(mysql, TRUE);
4533 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_prep_insert");
4536 rc= mysql_query(mysql,
"CREATE TABLE test_prep_insert(col1 tinyint, \
4537 col2 varchar(50))");
4541 stmt= mysql_simple_prepare(mysql,
4542 "INSERT INTO test_prep_insert VALUES(?, ?)");
4545 verify_param_count(stmt, 2);
4551 memset(my_bind, 0,
sizeof(my_bind));
4554 my_bind[0].buffer_type= MYSQL_TYPE_TINY;
4555 my_bind[0].buffer= (
void *)&tiny_data;
4558 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
4559 my_bind[1].buffer= str_data;
4560 my_bind[1].buffer_length=
sizeof(str_data);;
4561 my_bind[1].length= &length;
4563 rc= mysql_stmt_bind_param(stmt, my_bind);
4564 check_execute(stmt, rc);
4567 for (tiny_data= 0; tiny_data < 3; tiny_data++)
4569 length= sprintf(str_data,
"MySQL%d", tiny_data);
4570 rc= mysql_stmt_execute(stmt);
4571 check_execute(stmt, rc);
4574 mysql_stmt_close(stmt);
4577 rc= mysql_commit(mysql);
4581 rc= mysql_query(mysql,
"SELECT * FROM test_prep_insert");
4585 result= mysql_store_result(mysql);
4588 rc= my_process_result_set(result);
4589 DIE_UNLESS((
int) tiny_data == rc);
4590 mysql_free_result(result);
4597 static void test_prepare_resultset()
4603 myheader(
"test_prepare_resultset");
4605 rc= mysql_autocommit(mysql, TRUE);
4608 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_prepare_resultset");
4611 rc= mysql_query(mysql,
"CREATE TABLE test_prepare_resultset(id int, \
4612 name varchar(50), extra double)");
4615 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_prepare_resultset");
4618 verify_param_count(stmt, 0);
4620 result= mysql_stmt_result_metadata(stmt);
4622 my_print_result_metadata(result);
4623 mysql_free_result(result);
4624 mysql_stmt_close(stmt);
4630 static void test_field_flags()
4638 myheader(
"test_field_flags");
4640 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_field_flags");
4643 rc= mysql_query(mysql,
"CREATE TABLE test_field_flags(id int NOT NULL AUTO_INCREMENT PRIMARY KEY, \
4653 rc= mysql_query(mysql,
"SELECT * FROM test_field_flags");
4656 result= mysql_use_result(mysql);
4659 mysql_field_seek(result, 0);
4661 fputc(
'\n', stdout);
4663 for(i= 0; i< mysql_num_fields(result); i++)
4665 field= mysql_fetch_field(result);
4668 fprintf(stdout,
"\n field:%d", i);
4669 if (field->flags & NOT_NULL_FLAG)
4670 fprintf(stdout,
"\n NOT_NULL_FLAG");
4671 if (field->flags & PRI_KEY_FLAG)
4672 fprintf(stdout,
"\n PRI_KEY_FLAG");
4673 if (field->flags & UNIQUE_KEY_FLAG)
4674 fprintf(stdout,
"\n UNIQUE_KEY_FLAG");
4675 if (field->flags & MULTIPLE_KEY_FLAG)
4676 fprintf(stdout,
"\n MULTIPLE_KEY_FLAG");
4677 if (field->flags & AUTO_INCREMENT_FLAG)
4678 fprintf(stdout,
"\n AUTO_INCREMENT_FLAG");
4682 mysql_free_result(result);
4688 static void test_stmt_close()
4696 char query[MAX_TEST_QUERY_LENGTH];
4698 myheader(
"test_stmt_close");
4701 fprintf(stdout,
"\n Establishing a test connection ...");
4702 if (!(lmysql= mysql_client_init(NULL)))
4704 myerror(
"mysql_client_init() failed");
4707 if (!(mysql_real_connect(lmysql, opt_host, opt_user,
4708 opt_password, current_db, opt_port,
4709 opt_unix_socket, 0)))
4711 myerror(
"connection failed");
4714 lmysql->reconnect= 1;
4716 fprintf(stdout,
"OK");
4720 mysql_autocommit(lmysql, TRUE);
4722 rc= mysql_query(lmysql,
"SET SQL_MODE = ''");
4725 rc= mysql_query(lmysql,
"DROP TABLE IF EXISTS test_stmt_close");
4728 rc= mysql_query(lmysql,
"CREATE TABLE test_stmt_close(id int)");
4731 strmov(query,
"DO \"nothing\"");
4732 stmt1= mysql_simple_prepare(lmysql, query);
4735 verify_param_count(stmt1, 0);
4737 strmov(query,
"INSERT INTO test_stmt_close(id) VALUES(?)");
4738 stmt_x= mysql_simple_prepare(mysql, query);
4741 verify_param_count(stmt_x, 1);
4743 strmov(query,
"UPDATE test_stmt_close SET id= ? WHERE id= ?");
4744 stmt3= mysql_simple_prepare(lmysql, query);
4747 verify_param_count(stmt3, 2);
4749 strmov(query,
"SELECT * FROM test_stmt_close WHERE id= ?");
4750 stmt2= mysql_simple_prepare(lmysql, query);
4753 verify_param_count(stmt2, 1);
4755 rc= mysql_stmt_close(stmt1);
4757 fprintf(stdout,
"\n mysql_close_stmt(1) returned: %d", rc);
4758 DIE_UNLESS(rc == 0);
4768 mysql_stmt_close(stmt2);
4769 mysql_stmt_close(stmt3);
4770 mysql_close(lmysql);
4776 memset(my_bind, 0,
sizeof(my_bind));
4778 my_bind[0].buffer= (
void *)&count;
4779 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
4782 rc= mysql_stmt_bind_param(stmt_x, my_bind);
4783 check_execute(stmt_x, rc);
4785 rc= mysql_stmt_execute(stmt_x);
4786 check_execute(stmt_x, rc);
4788 verify_st_affected_rows(stmt_x, 1);
4790 rc= mysql_stmt_close(stmt_x);
4792 fprintf(stdout,
"\n mysql_close_stmt(x) returned: %d", rc);
4793 DIE_UNLESS( rc == 0);
4795 rc= mysql_query(mysql,
"SELECT id FROM test_stmt_close");
4798 result= mysql_store_result(mysql);
4801 rc= my_process_result_set(result);
4802 DIE_UNLESS(rc == 1);
4803 mysql_free_result(result);
4809 static void test_set_variable()
4813 int set_count, def_count, get_count;
4815 char var[NAME_LEN+1];
4818 myheader(
"test_set_variable");
4820 mysql_autocommit(mysql, TRUE);
4822 stmt1= mysql_simple_prepare(mysql,
"show variables like 'max_error_count'");
4829 memset(get_bind, 0,
sizeof(get_bind));
4831 get_bind[0].buffer_type= MYSQL_TYPE_STRING;
4832 get_bind[0].buffer= (
void *)var;
4833 get_bind[0].length= &length;
4834 get_bind[0].buffer_length= (int)NAME_LEN;
4837 get_bind[1].buffer_type= MYSQL_TYPE_LONG;
4838 get_bind[1].buffer= (
void *)&get_count;
4840 rc= mysql_stmt_execute(stmt1);
4841 check_execute(stmt1, rc);
4843 rc= mysql_stmt_bind_result(stmt1, get_bind);
4844 check_execute(stmt1, rc);
4846 rc= mysql_stmt_fetch(stmt1);
4847 check_execute(stmt1, rc);
4850 fprintf(stdout,
"\n max_error_count(default): %d", get_count);
4851 def_count= get_count;
4853 DIE_UNLESS(strcmp(var,
"max_error_count") == 0);
4854 rc= mysql_stmt_fetch(stmt1);
4855 DIE_UNLESS(rc == MYSQL_NO_DATA);
4857 stmt= mysql_simple_prepare(mysql,
"set max_error_count= ?");
4860 memset(set_bind, 0,
sizeof(set_bind));
4862 set_bind[0].buffer_type= MYSQL_TYPE_LONG;
4863 set_bind[0].buffer= (
void *)&set_count;
4865 rc= mysql_stmt_bind_param(stmt, set_bind);
4866 check_execute(stmt, rc);
4869 rc= mysql_stmt_execute(stmt);
4870 check_execute(stmt, rc);
4872 mysql_commit(mysql);
4874 rc= mysql_stmt_execute(stmt1);
4875 check_execute(stmt1, rc);
4877 rc= mysql_stmt_fetch(stmt1);
4878 check_execute(stmt1, rc);
4881 fprintf(stdout,
"\n max_error_count : %d", get_count);
4882 DIE_UNLESS(get_count == set_count);
4884 rc= mysql_stmt_fetch(stmt1);
4885 DIE_UNLESS(rc == MYSQL_NO_DATA);
4888 set_count= def_count;
4889 rc= mysql_stmt_execute(stmt);
4890 check_execute(stmt, rc);
4892 rc= mysql_stmt_execute(stmt1);
4893 check_execute(stmt1, rc);
4895 rc= mysql_stmt_fetch(stmt1);
4896 check_execute(stmt1, rc);
4899 fprintf(stdout,
"\n max_error_count(default): %d", get_count);
4900 DIE_UNLESS(get_count == set_count);
4902 rc= mysql_stmt_fetch(stmt1);
4903 DIE_UNLESS(rc == MYSQL_NO_DATA);
4905 mysql_stmt_close(stmt);
4906 mysql_stmt_close(stmt1);
4911 static void test_func_fields()
4917 myheader(
"test_func_fields");
4919 rc= mysql_autocommit(mysql, TRUE);
4922 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_dateformat");
4925 rc= mysql_query(mysql,
"CREATE TABLE test_dateformat(id int, \
4929 rc= mysql_query(mysql,
"INSERT INTO test_dateformat(id) values(10)");
4932 rc= mysql_query(mysql,
"SELECT ts FROM test_dateformat");
4935 result= mysql_store_result(mysql);
4938 field= mysql_fetch_field(result);
4941 fprintf(stdout,
"\n table name: `%s` (expected: `%s`)", field->table,
4943 DIE_UNLESS(strcmp(field->table,
"test_dateformat") == 0);
4945 field= mysql_fetch_field(result);
4948 mysql_free_result(result);
4951 rc= mysql_query(mysql,
"SELECT DATE_FORMAT(ts, '%Y') AS 'venu' FROM test_dateformat");
4954 result= mysql_store_result(mysql);
4957 field= mysql_fetch_field(result);
4960 fprintf(stdout,
"\n table name: `%s` (expected: `%s`)", field->table,
"");
4961 DIE_UNLESS(field->table[0] ==
'\0');
4963 field= mysql_fetch_field(result);
4966 mysql_free_result(result);
4969 rc= mysql_query(mysql,
"SELECT DATE_FORMAT(ts, '%Y') AS 'YEAR' FROM test_dateformat");
4972 result= mysql_store_result(mysql);
4975 field= mysql_fetch_field(result);
4979 printf(
"\n field name: `%s` (expected: `%s`)", field->name,
"YEAR");
4980 printf(
"\n field org name: `%s` (expected: `%s`)", field->org_name,
"");
4982 DIE_UNLESS(strcmp(field->name,
"YEAR") == 0);
4983 DIE_UNLESS(field->org_name[0] ==
'\0');
4985 field= mysql_fetch_field(result);
4988 mysql_free_result(result);
4994 static void test_multi_stmt()
5004 myheader(
"test_multi_stmt");
5006 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_multi_table");
5009 rc= mysql_query(mysql,
"CREATE TABLE test_multi_table(id int, name char(20))");
5012 rc= mysql_query(mysql,
"INSERT INTO test_multi_table values(10, 'mysql')");
5015 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_multi_table "
5019 stmt2= mysql_simple_prepare(mysql,
"UPDATE test_multi_table "
5020 "SET name='updated' WHERE id=10");
5023 verify_param_count(stmt, 1);
5029 memset(my_bind, 0,
sizeof(my_bind));
5031 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
5032 my_bind[0].buffer= (
void *)&
id;
5033 my_bind[0].is_null= &is_null[0];
5034 my_bind[0].length= &length[0];
5038 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
5039 my_bind[1].buffer= (
void *)name;
5040 my_bind[1].buffer_length=
sizeof(
name);
5041 my_bind[1].length= &length[1];
5042 my_bind[1].is_null= &is_null[1];
5044 rc= mysql_stmt_bind_param(stmt, my_bind);
5045 check_execute(stmt, rc);
5047 rc= mysql_stmt_bind_result(stmt, my_bind);
5048 check_execute(stmt, rc);
5051 rc= mysql_stmt_execute(stmt);
5052 check_execute(stmt, rc);
5055 rc= mysql_stmt_fetch(stmt);
5056 check_execute(stmt, rc);
5060 fprintf(stdout,
"\n int_data: %lu(%lu)", (ulong)
id, length[0]);
5061 fprintf(stdout,
"\n str_data: %s(%lu)", name, length[1]);
5063 DIE_UNLESS(
id == 10);
5064 DIE_UNLESS(strcmp(name,
"mysql") == 0);
5066 rc= mysql_stmt_fetch(stmt);
5067 DIE_UNLESS(rc == MYSQL_NO_DATA);
5070 stmt1= mysql_simple_prepare(mysql,
"DELETE FROM test_multi_table "
5072 "CONVERT(name USING utf8)=?");
5075 verify_param_count(stmt1, 2);
5077 rc= mysql_stmt_bind_param(stmt1, my_bind);
5078 check_execute(stmt1, rc);
5080 rc= mysql_stmt_execute(stmt2);
5081 check_execute(stmt2, rc);
5083 verify_st_affected_rows(stmt2, 1);
5085 rc= mysql_stmt_execute(stmt);
5086 check_execute(stmt, rc);
5088 rc= mysql_stmt_fetch(stmt);
5089 check_execute(stmt, rc);
5093 fprintf(stdout,
"\n int_data: %lu(%lu)", (ulong)
id, length[0]);
5094 fprintf(stdout,
"\n str_data: %s(%lu)", name, length[1]);
5096 DIE_UNLESS(
id == 10);
5097 DIE_UNLESS(strcmp(name,
"updated") == 0);
5099 rc= mysql_stmt_fetch(stmt);
5100 DIE_UNLESS(rc == MYSQL_NO_DATA);
5102 rc= mysql_stmt_execute(stmt1);
5103 check_execute(stmt1, rc);
5105 verify_st_affected_rows(stmt1, 1);
5107 mysql_stmt_close(stmt1);
5109 rc= mysql_stmt_execute(stmt);
5110 check_execute(stmt, rc);
5112 rc= mysql_stmt_fetch(stmt);
5113 DIE_UNLESS(rc == MYSQL_NO_DATA);
5115 rc= my_stmt_result(
"SELECT * FROM test_multi_table");
5116 DIE_UNLESS(rc == 0);
5118 mysql_stmt_close(stmt);
5119 mysql_stmt_close(stmt2);
5126 static void test_manual_sample()
5128 unsigned int param_count;
5134 ulonglong affected_rows;
5137 char query[MAX_TEST_QUERY_LENGTH];
5139 myheader(
"test_manual_sample");
5146 mysql_autocommit(mysql, 1);
5147 if (mysql_query(mysql,
"DROP TABLE IF EXISTS test_table"))
5149 fprintf(stderr,
"\n drop table failed");
5150 fprintf(stderr,
"\n %s", mysql_error(mysql));
5153 if (mysql_query(mysql,
"CREATE TABLE test_table(col1 int, col2 varchar(50), \
5157 fprintf(stderr,
"\n create table failed");
5158 fprintf(stderr,
"\n %s", mysql_error(mysql));
5163 strmov(query,
"INSERT INTO test_table(col1, col2, col3) values(?, ?, ?)");
5164 if (!(stmt= mysql_simple_prepare(mysql, query)))
5166 fprintf(stderr,
"\n prepare, insert failed");
5167 fprintf(stderr,
"\n %s", mysql_error(mysql));
5171 fprintf(stdout,
"\n prepare, insert successful");
5174 param_count= mysql_stmt_param_count(stmt);
5177 fprintf(stdout,
"\n total parameters in insert: %d", param_count);
5178 if (param_count != 3)
5180 fprintf(stderr,
"\n invalid parameter count returned by MySQL");
5190 memset(my_bind, 0,
sizeof(my_bind));
5193 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
5194 my_bind[0].buffer= (
void *)&int_data;
5197 my_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
5198 my_bind[1].buffer= (
void *)str_data;
5199 my_bind[1].buffer_length=
sizeof(str_data);
5202 my_bind[2].buffer_type= MYSQL_TYPE_SHORT;
5203 my_bind[2].buffer= (
void *)&small_data;
5204 my_bind[2].is_null= &is_null;
5208 if (mysql_stmt_bind_param(stmt, my_bind))
5210 fprintf(stderr,
"\n param bind failed");
5211 fprintf(stderr,
"\n %s", mysql_stmt_error(stmt));
5217 strmov(str_data,
"MySQL");
5223 if (mysql_stmt_execute(stmt))
5225 fprintf(stderr,
"\n execute 1 failed");
5226 fprintf(stderr,
"\n %s", mysql_stmt_error(stmt));
5231 affected_rows= mysql_stmt_affected_rows(stmt);
5234 fprintf(stdout,
"\n total affected rows: %ld", (ulong) affected_rows);
5235 if (affected_rows != 1)
5237 fprintf(stderr,
"\n invalid affected rows by MySQL");
5243 strmov(str_data,
"The most popular open source database");
5248 if (mysql_stmt_execute(stmt))
5250 fprintf(stderr,
"\n execute 2 failed");
5251 fprintf(stderr,
"\n %s", mysql_stmt_error(stmt));
5256 affected_rows= mysql_stmt_affected_rows(stmt);
5259 fprintf(stdout,
"\n total affected rows: %ld", (ulong) affected_rows);
5260 if (affected_rows != 1)
5262 fprintf(stderr,
"\n invalid affected rows by MySQL");
5267 if (mysql_stmt_close(stmt))
5269 fprintf(stderr,
"\n failed while closing the statement");
5270 fprintf(stderr,
"\n %s", mysql_stmt_error(stmt));
5273 rc= my_stmt_result(
"SELECT * FROM test_table");
5274 DIE_UNLESS(rc == 2);
5277 if (mysql_query(mysql,
"DROP TABLE test_table"))
5279 fprintf(stderr,
"\n drop table failed");
5280 fprintf(stderr,
"\n %s", mysql_error(mysql));
5284 fprintf(stdout,
"Success !!!");
5290 static void test_prepare_alter()
5297 myheader(
"test_prepare_alter");
5299 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_prep_alter");
5302 rc= mysql_query(mysql,
"CREATE TABLE test_prep_alter(id int, name char(20))");
5305 rc= mysql_query(mysql,
"INSERT INTO test_prep_alter values(10, 'venu'), (20, 'mysql')");
5308 stmt= mysql_simple_prepare(mysql,
"INSERT INTO test_prep_alter VALUES(?, 'monty')");
5311 verify_param_count(stmt, 1);
5317 memset(my_bind, 0,
sizeof(my_bind));
5320 my_bind[0].buffer_type= MYSQL_TYPE_SHORT;
5321 my_bind[0].buffer= (
void *)&
id;
5322 my_bind[0].is_null= &is_null;
5324 rc= mysql_stmt_bind_param(stmt, my_bind);
5325 check_execute(stmt, rc);
5328 rc= mysql_stmt_execute(stmt);
5329 check_execute(stmt, rc);
5331 if (thread_query(
"ALTER TABLE test_prep_alter change id id_new varchar(20)"))
5335 rc= mysql_stmt_execute(stmt);
5336 check_execute(stmt, rc);
5338 rc= my_stmt_result(
"SELECT * FROM test_prep_alter");
5339 DIE_UNLESS(rc == 4);
5341 mysql_stmt_close(stmt);
5347 static void test_multi_statements()
5353 const char *query=
"\
5354 DROP TABLE IF EXISTS test_multi_tab;\
5355 CREATE TABLE test_multi_tab(id int, name char(20));\
5356 INSERT INTO test_multi_tab(id) VALUES(10), (20);\
5357 INSERT INTO test_multi_tab VALUES(20, 'insert;comma');\
5358 SELECT * FROM test_multi_tab;\
5359 UPDATE test_multi_tab SET name='new;name' WHERE id=20;\
5360 DELETE FROM test_multi_tab WHERE name='new;name';\
5361 SELECT * FROM test_multi_tab;\
5362 DELETE FROM test_multi_tab WHERE id=10;\
5363 SELECT * FROM test_multi_tab;\
5364 DROP TABLE test_multi_tab;\
5366 DROP TABLE IF EXISTS test_multi_tab";
5367 uint count, exp_value;
5368 uint rows[]= {0, 0, 2, 1, 3, 2, 2, 1, 1, 0, 0, 1, 0};
5370 myheader(
"test_multi_statements");
5376 rc= mysql_query(mysql, query);
5379 rc= mysql_next_result(mysql);
5380 DIE_UNLESS(rc == -1);
5381 rc= mysql_more_results(mysql);
5382 DIE_UNLESS(rc == 0);
5384 if (!(mysql_local= mysql_client_init(NULL)))
5386 fprintf(stdout,
"\n mysql_client_init() failed");
5391 if (!(mysql_real_connect(mysql_local, opt_host, opt_user,
5392 opt_password, current_db, opt_port,
5393 opt_unix_socket, CLIENT_MULTI_STATEMENTS)))
5395 fprintf(stdout,
"\n connection failed(%s)", mysql_error(mysql_local));
5398 mysql_local->reconnect= 1;
5400 rc= mysql_query(mysql_local, query);
5403 for (count= 0 ; count < array_elements(rows) ; count++)
5406 fprintf(stdout,
"\n Query %d: ", count);
5407 if ((result= mysql_store_result(mysql_local)))
5409 (void) my_process_result_set(result);
5410 mysql_free_result(result);
5412 else if (!opt_silent)
5413 fprintf(stdout,
"OK, %ld row(s) affected, %ld warning(s)\n",
5414 (ulong) mysql_affected_rows(mysql_local),
5415 (ulong) mysql_warning_count(mysql_local));
5417 exp_value= (uint) mysql_affected_rows(mysql_local);
5418 if (rows[count] != exp_value)
5420 fprintf(stderr,
"row %d had affected rows: %d, should be %d\n",
5421 count, exp_value, rows[count]);
5424 if (count != array_elements(rows) -1)
5426 if (!(rc= mysql_more_results(mysql_local)))
5429 "mysql_more_result returned wrong value: %d for row %d\n",
5433 if ((rc= mysql_next_result(mysql_local)))
5435 exp_value= mysql_errno(mysql_local);
5442 rc= mysql_more_results(mysql_local);
5443 DIE_UNLESS(rc == 0);
5444 rc= mysql_next_result(mysql_local);
5445 DIE_UNLESS(rc == -1);
5451 rc= mysql_query(mysql_local,
"select 1+1+a;select 1+1");
5453 rc= mysql_more_results(mysql_local);
5454 DIE_UNLESS(rc == 0);
5455 rc= mysql_next_result(mysql_local);
5456 DIE_UNLESS(rc == -1);
5458 rc= mysql_query(mysql_local,
"select 1+1;select 1+1+a;select 1");
5460 result= mysql_store_result(mysql_local);
5462 mysql_free_result(result);
5463 rc= mysql_more_results(mysql_local);
5464 DIE_UNLESS(rc == 1);
5465 rc= mysql_next_result(mysql_local);
5472 rc= mysql_query(mysql_local,
"select 1+1+1");
5474 result= mysql_store_result(mysql_local);
5476 (void) my_process_result_set(result);
5477 mysql_free_result(result);
5482 rc= mysql_query(mysql_local,
"select 1; select * from not_existing_table");
5484 result= mysql_store_result(mysql_local);
5485 mysql_free_result(result);
5487 rc= mysql_next_result(mysql_local);
5490 rc= mysql_next_result(mysql_local);
5493 mysql_close(mysql_local);
5502 static void test_prepare_multi_statements()
5506 char query[MAX_TEST_QUERY_LENGTH];
5507 myheader(
"test_prepare_multi_statements");
5509 if (!(mysql_local= mysql_client_init(NULL)))
5511 fprintf(stderr,
"\n mysql_client_init() failed");
5515 if (!(mysql_real_connect(mysql_local, opt_host, opt_user,
5516 opt_password, current_db, opt_port,
5517 opt_unix_socket, CLIENT_MULTI_STATEMENTS)))
5519 fprintf(stderr,
"\n connection failed(%s)", mysql_error(mysql_local));
5522 mysql_local->reconnect= 1;
5523 strmov(query,
"select 1; select 'another value'");
5524 stmt= mysql_simple_prepare(mysql_local, query);
5526 mysql_close(mysql_local);
5532 static void test_store_result()
5539 ulong length, length1;
5542 myheader(
"test_store_result");
5544 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_store_result");
5547 rc= mysql_query(mysql,
"CREATE TABLE test_store_result(col1 int , col2 varchar(50))");
5550 rc= mysql_query(mysql,
"INSERT INTO test_store_result VALUES(10, 'venu'), (20, 'mysql')");
5553 rc= mysql_query(mysql,
"INSERT INTO test_store_result(col2) VALUES('monty')");
5556 rc= mysql_commit(mysql);
5560 memset(my_bind, 0,
sizeof(my_bind));
5561 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
5562 my_bind[0].buffer= (
void *) &nData;
5563 my_bind[0].length= &length;
5564 my_bind[0].is_null= &is_null[0];
5567 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
5568 my_bind[1].buffer= szData;
5569 my_bind[1].buffer_length=
sizeof(szData);
5570 my_bind[1].length= &length1;
5571 my_bind[1].is_null= &is_null[1];
5574 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_store_result");
5577 rc= mysql_stmt_bind_result(stmt, my_bind);
5578 check_execute(stmt, rc);
5580 rc= mysql_stmt_execute(stmt);
5581 check_execute(stmt, rc);
5583 rc= mysql_stmt_store_result(stmt);
5584 check_execute(stmt, rc);
5586 rc= mysql_stmt_fetch(stmt);
5587 check_execute(stmt, rc);
5590 fprintf(stdout,
"\n row 1: %ld, %s(%lu)", (
long) nData, szData, length1);
5591 DIE_UNLESS(nData == 10);
5592 DIE_UNLESS(strcmp(szData,
"venu") == 0);
5593 DIE_UNLESS(length1 == 4);
5595 rc= mysql_stmt_fetch(stmt);
5596 check_execute(stmt, rc);
5599 fprintf(stdout,
"\n row 2: %ld, %s(%lu)", (
long) nData, szData, length1);
5600 DIE_UNLESS(nData == 20);
5601 DIE_UNLESS(strcmp(szData,
"mysql") == 0);
5602 DIE_UNLESS(length1 == 5);
5605 rc= mysql_stmt_fetch(stmt);
5606 check_execute(stmt, rc);
5608 if (!opt_silent && is_null[0])
5609 fprintf(stdout,
"\n row 3: NULL, %s(%lu)", szData, length1);
5610 DIE_UNLESS(is_null[0]);
5611 DIE_UNLESS(strcmp(szData,
"monty") == 0);
5612 DIE_UNLESS(length1 == 5);
5614 rc= mysql_stmt_fetch(stmt);
5615 DIE_UNLESS(rc == MYSQL_NO_DATA);
5617 rc= mysql_stmt_execute(stmt);
5618 check_execute(stmt, rc);
5620 rc= mysql_stmt_store_result(stmt);
5621 check_execute(stmt, rc);
5623 rc= mysql_stmt_fetch(stmt);
5624 check_execute(stmt, rc);
5627 fprintf(stdout,
"\n row 1: %ld, %s(%lu)", (
long) nData, szData, length1);
5628 DIE_UNLESS(nData == 10);
5629 DIE_UNLESS(strcmp(szData,
"venu") == 0);
5630 DIE_UNLESS(length1 == 4);
5632 rc= mysql_stmt_fetch(stmt);
5633 check_execute(stmt, rc);
5636 fprintf(stdout,
"\n row 2: %ld, %s(%lu)", (
long) nData, szData, length1);
5637 DIE_UNLESS(nData == 20);
5638 DIE_UNLESS(strcmp(szData,
"mysql") == 0);
5639 DIE_UNLESS(length1 == 5);
5642 rc= mysql_stmt_fetch(stmt);
5643 check_execute(stmt, rc);
5645 if (!opt_silent && is_null[0])
5646 fprintf(stdout,
"\n row 3: NULL, %s(%lu)", szData, length1);
5647 DIE_UNLESS(is_null[0]);
5648 DIE_UNLESS(strcmp(szData,
"monty") == 0);
5649 DIE_UNLESS(length1 == 5);
5651 rc= mysql_stmt_fetch(stmt);
5652 DIE_UNLESS(rc == MYSQL_NO_DATA);
5654 mysql_stmt_close(stmt);
5660 static void test_store_result1()
5665 myheader(
"test_store_result1");
5667 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_store_result");
5670 rc= mysql_query(mysql,
"CREATE TABLE test_store_result(col1 int , col2 varchar(50))");
5673 rc= mysql_query(mysql,
"INSERT INTO test_store_result VALUES(10, 'venu'), (20, 'mysql')");
5676 rc= mysql_query(mysql,
"INSERT INTO test_store_result(col2) VALUES('monty')");
5679 rc= mysql_commit(mysql);
5682 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_store_result");
5685 rc= mysql_stmt_execute(stmt);
5686 check_execute(stmt, rc);
5688 rc= mysql_stmt_store_result(stmt);
5689 check_execute(stmt, rc);
5692 while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
5695 fprintf(stdout,
"\n total rows: %d", rc);
5696 DIE_UNLESS(rc == 3);
5698 rc= mysql_stmt_execute(stmt);
5699 check_execute(stmt, rc);
5701 rc= mysql_stmt_store_result(stmt);
5702 check_execute(stmt, rc);
5705 while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
5708 fprintf(stdout,
"\n total rows: %d", rc);
5709 DIE_UNLESS(rc == 3);
5711 mysql_stmt_close(stmt);
5717 static void test_store_result2()
5724 char query[MAX_TEST_QUERY_LENGTH];
5726 myheader(
"test_store_result2");
5728 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_store_result");
5731 rc= mysql_query(mysql,
"CREATE TABLE test_store_result(col1 int , col2 varchar(50))");
5734 rc= mysql_query(mysql,
"INSERT INTO test_store_result VALUES(10, 'venu'), (20, 'mysql')");
5737 rc= mysql_query(mysql,
"INSERT INTO test_store_result(col2) VALUES('monty')");
5740 rc= mysql_commit(mysql);
5747 memset(my_bind, 0,
sizeof(my_bind));
5749 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
5750 my_bind[0].buffer= (
void *) &nData;
5751 my_bind[0].length= &length;
5752 my_bind[0].is_null= 0;
5754 strmov((
char *)query ,
"SELECT col1 FROM test_store_result where col1= ?");
5755 stmt= mysql_simple_prepare(mysql, query);
5758 rc= mysql_stmt_bind_param(stmt, my_bind);
5759 check_execute(stmt, rc);
5761 rc= mysql_stmt_bind_result(stmt, my_bind);
5762 check_execute(stmt, rc);
5764 nData= 10; length= 0;
5765 rc= mysql_stmt_execute(stmt);
5766 check_execute(stmt, rc);
5769 rc= mysql_stmt_store_result(stmt);
5770 check_execute(stmt, rc);
5772 rc= mysql_stmt_fetch(stmt);
5773 check_execute(stmt, rc);
5776 fprintf(stdout,
"\n row 1: %d", nData);
5777 DIE_UNLESS(nData == 10);
5779 rc= mysql_stmt_fetch(stmt);
5780 DIE_UNLESS(rc == MYSQL_NO_DATA);
5783 rc= mysql_stmt_execute(stmt);
5784 check_execute(stmt, rc);
5787 rc= mysql_stmt_store_result(stmt);
5788 check_execute(stmt, rc);
5790 rc= mysql_stmt_fetch(stmt);
5791 check_execute(stmt, rc);
5794 fprintf(stdout,
"\n row 1: %d", nData);
5795 DIE_UNLESS(nData == 20);
5797 rc= mysql_stmt_fetch(stmt);
5798 DIE_UNLESS(rc == MYSQL_NO_DATA);
5799 mysql_stmt_close(stmt);
5805 static void test_subselect()
5811 DBUG_ENTER(
"test_subselect");
5813 myheader(
"test_subselect");
5815 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_sub1");
5818 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_sub2");
5821 rc= mysql_query(mysql,
"CREATE TABLE test_sub1(id int)");
5824 rc= mysql_query(mysql,
"CREATE TABLE test_sub2(id int, id1 int)");
5827 rc= mysql_query(mysql,
"INSERT INTO test_sub1 values(2)");
5830 rc= mysql_query(mysql,
"INSERT INTO test_sub2 VALUES(1, 7), (2, 7)");
5833 rc= mysql_commit(mysql);
5841 memset(my_bind, 0,
sizeof(my_bind));
5843 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
5844 my_bind[0].buffer= (
void *) &
id;
5845 my_bind[0].length= 0;
5846 my_bind[0].is_null= 0;
5848 stmt= mysql_simple_prepare(mysql,
"INSERT INTO test_sub2(id) SELECT * FROM test_sub1 WHERE id= ?");
5851 rc= mysql_stmt_bind_param(stmt, my_bind);
5852 check_execute(stmt, rc);
5855 rc= mysql_stmt_execute(stmt);
5856 check_execute(stmt, rc);
5858 verify_st_affected_rows(stmt, 1);
5861 rc= mysql_stmt_execute(stmt);
5862 check_execute(stmt, rc);
5864 verify_st_affected_rows(stmt, 0);
5866 mysql_stmt_close(stmt);
5868 rc= my_stmt_result(
"SELECT * FROM test_sub2");
5869 DIE_UNLESS(rc == 3);
5871 rc= my_stmt_result(
"SELECT ROW(1, 7) IN (select id, id1 "
5872 "from test_sub2 WHERE id1= 8)");
5873 DIE_UNLESS(rc == 1);
5874 rc= my_stmt_result(
"SELECT ROW(1, 7) IN (select id, id1 "
5875 "from test_sub2 WHERE id1= 7)");
5876 DIE_UNLESS(rc == 1);
5878 stmt= mysql_simple_prepare(mysql, (
"SELECT ROW(1, 7) IN (select id, id1 "
5879 "from test_sub2 WHERE id1= ?)"));
5882 rc= mysql_stmt_bind_param(stmt, my_bind);
5883 check_execute(stmt, rc);
5885 rc= mysql_stmt_bind_result(stmt, my_bind);
5886 check_execute(stmt, rc);
5889 rc= mysql_stmt_execute(stmt);
5890 check_execute(stmt, rc);
5892 rc= mysql_stmt_fetch(stmt);
5893 check_execute(stmt, rc);
5896 fprintf(stdout,
"\n row 1: %d",
id);
5897 DIE_UNLESS(
id == 1);
5899 rc= mysql_stmt_fetch(stmt);
5900 DIE_UNLESS(rc == MYSQL_NO_DATA);
5903 rc= mysql_stmt_execute(stmt);
5904 check_execute(stmt, rc);
5906 rc= mysql_stmt_fetch(stmt);
5907 check_execute(stmt, rc);
5910 fprintf(stdout,
"\n row 1: %d",
id);
5911 DIE_UNLESS(
id == 0);
5913 rc= mysql_stmt_fetch(stmt);
5914 DIE_UNLESS(rc == MYSQL_NO_DATA);
5916 mysql_stmt_close(stmt);
5926 static void bind_date_conv(uint row_count, my_bool preserveFractions)
5929 uint rc,
i, count= row_count;
5932 my_bool is_null[4]= {0};
5935 uint year, month, day, hour, minute, sec;
5936 uint now_year= 1990, now_month= 3, now_day= 13;
5938 rc= mysql_query(mysql,
"SET timestamp=UNIX_TIMESTAMP('1990-03-13')");
5941 stmt= mysql_simple_prepare(mysql,
"INSERT INTO test_date VALUES(?, ?, ?, ?)");
5944 verify_param_count(stmt, 4);
5950 memset(my_bind, 0,
sizeof(my_bind));
5952 my_bind[0].buffer_type= MYSQL_TYPE_TIMESTAMP;
5953 my_bind[1].buffer_type= MYSQL_TYPE_TIME;
5954 my_bind[2].buffer_type= MYSQL_TYPE_DATETIME;
5955 my_bind[3].buffer_type= MYSQL_TYPE_DATE;
5957 for (i= 0; i < (int) array_elements(my_bind); i++)
5959 my_bind[
i].buffer= (
void *) &tm[i];
5960 my_bind[
i].is_null= &is_null[
i];
5961 my_bind[
i].length= &length[
i];
5962 my_bind[
i].buffer_length= 30;
5976 rc= mysql_stmt_bind_param(stmt, my_bind);
5977 check_execute(stmt, rc);
5979 for (count= 0; count < row_count; count++)
5981 for (i= 0; i < (int) array_elements(my_bind); i++)
5985 if (my_bind[i].buffer_type != MYSQL_TYPE_TIME)
5987 tm[
i].year= year+count;
5988 tm[
i].month= month+count;
5989 tm[
i].day= day+count;
5992 tm[
i].year= tm[
i].month= tm[
i].day= 0;
5993 if (my_bind[i].buffer_type != MYSQL_TYPE_DATE)
5995 tm[
i].hour= hour+count;
5996 tm[
i].minute= minute+count;
5997 tm[
i].second= sec+count;
6000 tm[
i].hour= tm[
i].minute= tm[
i].second= 0;
6002 rc= mysql_stmt_execute(stmt);
6003 check_execute(stmt, rc);
6006 rc= mysql_commit(mysql);
6009 mysql_stmt_close(stmt);
6011 rc= my_stmt_result(
"SELECT * FROM test_date");
6012 DIE_UNLESS(row_count == rc);
6014 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_date");
6017 rc= mysql_stmt_bind_result(stmt, my_bind);
6018 check_execute(stmt, rc);
6020 rc= mysql_stmt_execute(stmt);
6021 check_execute(stmt, rc);
6023 rc= mysql_stmt_store_result(stmt);
6024 check_execute(stmt, rc);
6026 for (count= 0; count < row_count; count++)
6028 rc= mysql_stmt_fetch(stmt);
6029 DIE_UNLESS(rc == 0 || rc == MYSQL_DATA_TRUNCATED);
6032 fprintf(stdout,
"\n");
6033 for (i= 0; i < array_elements(my_bind); i++)
6036 fprintf(stdout,
"\ntime[%d]: %02d-%02d-%02d %02d:%02d:%02d.%06lu",
6037 i, tm[i].year, tm[i].month, tm[i].day,
6038 tm[i].hour, tm[i].minute, tm[i].second,
6040 DIE_UNLESS(tm[i].year == 0 || tm[i].year == year + count ||
6041 (tm[i].year == now_year &&
6042 my_bind[i].buffer_type == MYSQL_TYPE_TIME));
6043 DIE_UNLESS(tm[i].month == 0 || tm[i].month == month + count ||
6044 (tm[i].month == now_month &&
6045 my_bind[i].buffer_type == MYSQL_TYPE_TIME));
6046 DIE_UNLESS(tm[i].day == 0 || tm[i].day == day + count ||
6047 (tm[i].day == now_day &&
6048 my_bind[i].buffer_type == MYSQL_TYPE_TIME));
6050 DIE_UNLESS(tm[i].hour == 0 || tm[i].hour == hour+count);
6051 DIE_UNLESS(tm[i].minute == 0 || tm[i].minute == minute+count);
6052 DIE_UNLESS(tm[i].second == 0 || tm[i].second == sec+count);
6053 if (preserveFractions) {
6055 DIE_UNLESS(tm[i].second_part == 0);
6057 DIE_UNLESS(tm[i].second_part == second_part+count);
6060 DIE_UNLESS((tm[i].second_part == 0)||
6061 tm[i].second_part == second_part+count);
6065 rc= mysql_stmt_fetch(stmt);
6066 DIE_UNLESS(rc == MYSQL_NO_DATA);
6068 mysql_stmt_close(stmt);
6074 static void test_date()
6078 myheader(
"test_date");
6080 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_date");
6083 rc= mysql_query(mysql,
"CREATE TABLE test_date(c1 TIMESTAMP, \
6090 bind_date_conv(5,FALSE);
6096 static void test_date_frac()
6100 myheader(
"test_date");
6102 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_date");
6105 rc= mysql_query(mysql,
"CREATE TABLE test_date(c1 TIMESTAMP(6), \
6112 bind_date_conv(5,TRUE);
6118 static void test_date_date()
6122 myheader(
"test_date_date");
6124 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_date");
6127 rc= mysql_query(mysql,
"CREATE TABLE test_date(c1 DATE, \
6134 bind_date_conv(3,FALSE);
6140 static void test_date_time()
6144 myheader(
"test_date_time");
6146 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_date");
6149 rc= mysql_query(mysql,
"CREATE TABLE test_date(c1 TIME, \
6156 bind_date_conv(3, FALSE);
6162 static void test_date_ts()
6166 myheader(
"test_date_ts");
6168 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_date");
6171 rc= mysql_query(mysql,
"CREATE TABLE test_date(c1 TIMESTAMP, \
6178 bind_date_conv(2, FALSE);
6184 static void test_date_dt()
6188 myheader(
"test_date_dt");
6190 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_date");
6193 rc= mysql_query(mysql,
"CREATE TABLE test_date(c1 datetime, "
6194 " c2 datetime, c3 datetime, c4 date)");
6197 bind_date_conv(2, FALSE);
6207 static void test_temporal_param()
6212 ulong length[N_PARAMS], length2[N_PARAMS];
6213 MYSQL_BIND my_bind[N_PARAMS], my_bind2[N_PARAMS];
6214 my_bool is_null[N_PARAMS], is_null2[N_PARAMS];
6216 longlong bigint= 123;
6221 memset(&my_bind, 0,
sizeof(my_bind));
6222 memset(&my_bind2, 0,
sizeof(my_bind2));
6223 memset(&length, 0,
sizeof(length));
6224 memset(&length2, 0,
sizeof(length2));
6225 memset(&is_null, 0,
sizeof(is_null));
6226 memset(&is_null2, 0,
sizeof(is_null2));
6229 my_bind[0].buffer_type= MYSQL_TYPE_TIMESTAMP;
6230 my_bind[0].buffer= (
void *) &tm;
6231 my_bind[0].is_null= &is_null[0];
6232 my_bind[0].length= &length[0];
6233 my_bind[0].buffer_length=
sizeof(tm);
6236 my_bind[2]= my_bind[1]= my_bind[0];
6239 my_bind2[0].buffer_type= MYSQL_TYPE_LONGLONG;
6240 my_bind2[0].length= &length2[0];
6241 my_bind2[0].is_null= &is_null2[0];
6242 my_bind2[0].buffer_length=
sizeof(bigint);
6243 my_bind2[0].buffer= (
void *) &bigint;
6245 my_bind2[1].buffer_type= MYSQL_TYPE_DOUBLE;
6246 my_bind2[1].length= &length2[1];
6247 my_bind2[1].is_null= &is_null2[1];
6248 my_bind2[1].buffer_length=
sizeof(real);
6249 my_bind2[1].buffer= (
void *) ℜ
6251 my_bind2[2].buffer_type= MYSQL_TYPE_STRING;
6252 my_bind2[2].length= &length2[2];
6253 my_bind2[2].is_null= &is_null2[2];
6254 my_bind2[2].buffer_length=
sizeof(dec);
6255 my_bind2[2].buffer= (
void *) &dec;
6259 stmt= mysql_simple_prepare(mysql,
"SELECT CAST(? AS SIGNED), ?+0e0, ?+0.0");
6261 verify_param_count(stmt, N_PARAMS);
6263 rc= mysql_stmt_bind_param(stmt, my_bind);
6264 check_execute(stmt, rc);
6266 rc= mysql_stmt_bind_result(stmt, my_bind2);
6267 check_execute(stmt, rc);
6271 tm.time_type= MYSQL_TIMESTAMP_DATETIME;
6281 rc= mysql_stmt_execute(stmt);
6282 check_execute(stmt, rc);
6284 rc= mysql_stmt_store_result(stmt);
6285 check_execute(stmt, rc);
6287 rc= mysql_stmt_fetch(stmt);
6288 check_execute(stmt, rc);
6291 printf(
"\n%lld %f '%s'\n", bigint, real, dec);
6294 DIE_UNLESS(bigint == 20011020101100LL);
6295 DIE_UNLESS(real == 20011020101059.5);
6296 DIE_UNLESS(!strcmp(dec,
"20011020101059.5"));
6298 mysql_stmt_close(stmt);
6301 my_bind[0].buffer_type= my_bind[1].buffer_type=
6302 my_bind[2].buffer_type= MYSQL_TYPE_TIME;
6305 stmt= mysql_simple_prepare(mysql,
"SELECT CAST(? AS SIGNED), ?+0e0, ?+0.0");
6307 verify_param_count(stmt, N_PARAMS);
6309 rc= mysql_stmt_bind_param(stmt, my_bind);
6310 check_execute(stmt, rc);
6312 rc= mysql_stmt_bind_result(stmt, my_bind2);
6313 check_execute(stmt, rc);
6317 tm.time_type= MYSQL_TIMESTAMP_TIME;
6318 tm.year= tm.month= tm.day= 0;
6325 rc= mysql_stmt_execute(stmt);
6326 check_execute(stmt, rc);
6328 rc= mysql_stmt_store_result(stmt);
6329 check_execute(stmt, rc);
6331 rc= mysql_stmt_fetch(stmt);
6332 check_execute(stmt, rc);
6335 printf(
"\n%lld %f '%s'\n", bigint, real, dec);
6338 DIE_UNLESS(bigint == 101100);
6339 DIE_UNLESS(real == 101059.5);
6340 DIE_UNLESS(!strcmp(dec,
"101059.5"));
6342 mysql_stmt_close(stmt);
6350 static void test_pure_coverage()
6357 myheader(
"test_pure_coverage");
6359 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_pure");
6362 rc= mysql_query(mysql,
"CREATE TABLE test_pure(c1 int, c2 varchar(20))");
6365 stmt= mysql_simple_prepare(mysql,
"insert into test_pure(c67788) values(10)");
6369 stmt= mysql_simple_prepare(mysql,
"insert into test_pure(c2) values(10)");
6372 rc= mysql_stmt_bind_param(stmt, (
MYSQL_BIND*)0);
6373 check_execute(stmt, rc);
6375 rc= mysql_stmt_execute(stmt);
6376 check_execute(stmt, rc);
6378 rc= mysql_stmt_bind_result(stmt, (
MYSQL_BIND*)0);
6379 DIE_UNLESS(rc == 1);
6381 mysql_stmt_close(stmt);
6383 stmt= mysql_simple_prepare(mysql,
"insert into test_pure(c2) values(?)");
6390 memset(my_bind, 0,
sizeof(my_bind));
6392 my_bind[0].length= &length;
6393 my_bind[0].is_null= 0;
6394 my_bind[0].buffer_length= 0;
6396 my_bind[0].buffer_type= MYSQL_TYPE_GEOMETRY;
6397 rc= mysql_stmt_bind_param(stmt, my_bind);
6398 check_execute_r(stmt, rc);
6400 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
6401 rc= mysql_stmt_bind_param(stmt, my_bind);
6402 check_execute(stmt, rc);
6404 rc= mysql_stmt_store_result(stmt);
6405 check_execute(stmt, rc);
6407 mysql_stmt_close(stmt);
6409 stmt= mysql_simple_prepare(mysql,
"select * from test_pure");
6410 check_execute(stmt, rc);
6412 rc= mysql_stmt_execute(stmt);
6413 check_execute(stmt, rc);
6416 my_bind[0].buffer_type= MYSQL_TYPE_GEOMETRY;
6417 rc= mysql_stmt_bind_result(stmt, my_bind);
6418 check_execute_r(stmt, rc);
6420 rc= mysql_stmt_store_result(stmt);
6423 rc= mysql_stmt_store_result(stmt);
6426 mysql_stmt_close(stmt);
6428 mysql_query(mysql,
"DROP TABLE test_pure");
6434 static void test_buffers()
6444 myheader(
"test_buffers");
6446 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_buffer");
6449 rc= mysql_query(mysql,
"CREATE TABLE test_buffer(str varchar(20))");
6452 rc= mysql_query(mysql,
"insert into test_buffer values('MySQL')\
6453 , ('Database'), ('Open-Source'), ('Popular')");
6456 stmt= mysql_simple_prepare(mysql,
"select str from test_buffer");
6459 rc= mysql_stmt_execute(stmt);
6460 check_execute(stmt, rc);
6462 memset(buffer, 0,
sizeof(buffer));
6464 memset(my_bind, 0,
sizeof(my_bind));
6465 my_bind[0].length= &length;
6466 my_bind[0].is_null= &is_null;
6467 my_bind[0].buffer_length= 1;
6468 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
6469 my_bind[0].buffer= (
void *)buffer;
6470 my_bind[0].error= &my_bind[0].error_value;
6472 rc= mysql_stmt_bind_result(stmt, my_bind);
6473 check_execute(stmt, rc);
6475 rc= mysql_stmt_store_result(stmt);
6476 check_execute(stmt, rc);
6479 rc= mysql_stmt_fetch(stmt);
6480 DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED);
6481 DIE_UNLESS(my_bind[0].error_value);
6483 fprintf(stdout,
"\n data: %s (%lu)", buffer, length);
6484 DIE_UNLESS(buffer[0] ==
'M');
6485 DIE_UNLESS(buffer[1] ==
'X');
6486 DIE_UNLESS(length == 5);
6488 my_bind[0].buffer_length= 8;
6489 rc= mysql_stmt_bind_result(stmt, my_bind);
6490 check_execute(stmt, rc);
6492 rc= mysql_stmt_fetch(stmt);
6493 check_execute(stmt, rc);
6495 fprintf(stdout,
"\n data: %s (%lu)", buffer, length);
6496 DIE_UNLESS(strncmp(buffer,
"Database", 8) == 0);
6497 DIE_UNLESS(length == 8);
6499 my_bind[0].buffer_length= 12;
6500 rc= mysql_stmt_bind_result(stmt, my_bind);
6501 check_execute(stmt, rc);
6503 rc= mysql_stmt_fetch(stmt);
6504 check_execute(stmt, rc);
6506 fprintf(stdout,
"\n data: %s (%lu)", buffer, length);
6507 DIE_UNLESS(strcmp(buffer,
"Open-Source") == 0);
6508 DIE_UNLESS(length == 11);
6510 my_bind[0].buffer_length= 6;
6511 rc= mysql_stmt_bind_result(stmt, my_bind);
6512 check_execute(stmt, rc);
6514 rc= mysql_stmt_fetch(stmt);
6515 DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED);
6516 DIE_UNLESS(my_bind[0].error_value);
6518 fprintf(stdout,
"\n data: %s (%lu)", buffer, length);
6519 DIE_UNLESS(strncmp(buffer,
"Popula", 6) == 0);
6520 DIE_UNLESS(length == 7);
6522 mysql_stmt_close(stmt);
6528 static void test_open_direct()
6534 myheader(
"test_open_direct");
6536 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_open_direct");
6539 rc= mysql_query(mysql,
"CREATE TABLE test_open_direct(id int, name char(6))");
6542 stmt= mysql_simple_prepare(mysql,
"INSERT INTO test_open_direct values(10, 'mysql')");
6545 rc= mysql_query(mysql,
"SELECT * FROM test_open_direct");
6548 result= mysql_store_result(mysql);
6551 rc= my_process_result_set(result);
6552 DIE_UNLESS(rc == 0);
6553 mysql_free_result(result);
6555 rc= mysql_stmt_execute(stmt);
6556 check_execute(stmt, rc);
6558 verify_st_affected_rows(stmt, 1);
6560 rc= mysql_query(mysql,
"SELECT * FROM test_open_direct");
6563 result= mysql_store_result(mysql);
6566 rc= my_process_result_set(result);
6567 DIE_UNLESS(rc == 1);
6568 mysql_free_result(result);
6570 rc= mysql_stmt_execute(stmt);
6571 check_execute(stmt, rc);
6573 verify_st_affected_rows(stmt, 1);
6575 rc= mysql_query(mysql,
"SELECT * FROM test_open_direct");
6578 result= mysql_store_result(mysql);
6581 rc= my_process_result_set(result);
6582 DIE_UNLESS(rc == 2);
6583 mysql_free_result(result);
6585 mysql_stmt_close(stmt);
6588 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_open_direct");
6591 rc= mysql_stmt_execute(stmt);
6592 check_execute(stmt, rc);
6594 rc= mysql_stmt_fetch(stmt);
6595 check_execute(stmt, rc);
6597 rc= mysql_query(mysql,
"INSERT INTO test_open_direct(id) VALUES(20)");
6600 rc= mysql_stmt_close(stmt);
6601 check_execute(stmt, rc);
6603 rc= mysql_query(mysql,
"INSERT INTO test_open_direct(id) VALUES(20)");
6607 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_open_direct");
6610 rc= mysql_stmt_execute(stmt);
6611 check_execute(stmt, rc);
6613 rc= mysql_stmt_store_result(stmt);
6614 check_execute(stmt, rc);
6616 rc= mysql_stmt_fetch(stmt);
6617 check_execute(stmt, rc);
6619 rc= mysql_query(mysql,
"drop table test_open_direct");
6622 rc= mysql_stmt_close(stmt);
6623 check_execute(stmt, rc);
6629 static void test_fetch_nobuffs()
6636 myheader(
"test_fetch_nobuffs");
6638 stmt= mysql_simple_prepare(mysql,
"SELECT DATABASE(), CURRENT_USER(), \
6639 CURRENT_DATE(), CURRENT_TIME()");
6642 rc= mysql_stmt_execute(stmt);
6643 check_execute(stmt, rc);
6646 while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
6650 fprintf(stdout,
"\n total rows : %d", rc);
6651 DIE_UNLESS(rc == 1);
6654 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
6655 my_bind[0].buffer= (
void *)str[0];
6656 my_bind[0].buffer_length=
sizeof(str[0]);
6657 my_bind[1]= my_bind[2]= my_bind[3]= my_bind[0];
6658 my_bind[1].buffer= (
void *)str[1];
6659 my_bind[2].buffer= (
void *)str[2];
6660 my_bind[3].buffer= (
void *)str[3];
6662 rc= mysql_stmt_bind_result(stmt, my_bind);
6663 check_execute(stmt, rc);
6665 rc= mysql_stmt_execute(stmt);
6666 check_execute(stmt, rc);
6669 while (mysql_stmt_fetch(stmt) != MYSQL_NO_DATA)
6674 fprintf(stdout,
"\n CURRENT_DATABASE(): %s", str[0]);
6675 fprintf(stdout,
"\n CURRENT_USER() : %s", str[1]);
6676 fprintf(stdout,
"\n CURRENT_DATE() : %s", str[2]);
6677 fprintf(stdout,
"\n CURRENT_TIME() : %s", str[3]);
6681 fprintf(stdout,
"\n total rows : %d", rc);
6682 DIE_UNLESS(rc == 1);
6684 mysql_stmt_close(stmt);
6690 static void test_ushort_bug()
6696 ulong s_length, l_length, ll_length, t_length;
6697 ulonglong longlong_value;
6701 myheader(
"test_ushort_bug");
6703 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_ushort");
6706 rc= mysql_query(mysql,
"CREATE TABLE test_ushort(a smallint unsigned, \
6707 b smallint unsigned, \
6708 c smallint unsigned, \
6709 d smallint unsigned)");
6712 rc= mysql_query(mysql,
6713 "INSERT INTO test_ushort VALUES(35999, 35999, 35999, 200)");
6717 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_ushort");
6720 rc= mysql_stmt_execute(stmt);
6721 check_execute(stmt, rc);
6723 memset(my_bind, 0,
sizeof(my_bind));
6724 my_bind[0].buffer_type= MYSQL_TYPE_SHORT;
6725 my_bind[0].buffer= (
void *)&short_value;
6726 my_bind[0].is_unsigned= TRUE;
6727 my_bind[0].length= &s_length;
6729 my_bind[1].buffer_type= MYSQL_TYPE_LONG;
6730 my_bind[1].buffer= (
void *)&long_value;
6731 my_bind[1].length= &l_length;
6733 my_bind[2].buffer_type= MYSQL_TYPE_LONGLONG;
6734 my_bind[2].buffer= (
void *)&longlong_value;
6735 my_bind[2].length= &ll_length;
6737 my_bind[3].buffer_type= MYSQL_TYPE_TINY;
6738 my_bind[3].buffer= (
void *)&tiny_value;
6739 my_bind[3].is_unsigned= TRUE;
6740 my_bind[3].length= &t_length;
6742 rc= mysql_stmt_bind_result(stmt, my_bind);
6743 check_execute(stmt, rc);
6745 rc= mysql_stmt_fetch(stmt);
6746 check_execute(stmt, rc);
6750 fprintf(stdout,
"\n ushort : %d (%ld)", short_value, s_length);
6751 fprintf(stdout,
"\n ulong : %lu (%ld)", (ulong) long_value, l_length);
6752 fprintf(stdout,
"\n longlong : %s (%ld)", llstr(longlong_value, llbuf),
6754 fprintf(stdout,
"\n tinyint : %d (%ld)", tiny_value, t_length);
6757 DIE_UNLESS(short_value == 35999);
6758 DIE_UNLESS(s_length == 2);
6760 DIE_UNLESS(long_value == 35999);
6761 DIE_UNLESS(l_length == 4);
6763 DIE_UNLESS(longlong_value == 35999);
6764 DIE_UNLESS(ll_length == 8);
6766 DIE_UNLESS(tiny_value == 200);
6767 DIE_UNLESS(t_length == 1);
6769 rc= mysql_stmt_fetch(stmt);
6770 DIE_UNLESS(rc == MYSQL_NO_DATA);
6772 mysql_stmt_close(stmt);
6778 static void test_sshort_bug()
6784 ulong s_length, l_length, ll_length, t_length;
6785 ulonglong longlong_value;
6790 myheader(
"test_sshort_bug");
6792 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_sshort");
6795 rc= mysql_query(mysql,
"CREATE TABLE test_sshort(a smallint signed, \
6796 b smallint signed, \
6797 c smallint unsigned, \
6798 d smallint unsigned)");
6801 rc= mysql_query(mysql,
"INSERT INTO test_sshort VALUES(-5999, -5999, 35999, 200)");
6805 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_sshort");
6808 rc= mysql_stmt_execute(stmt);
6809 check_execute(stmt, rc);
6811 memset(my_bind, 0,
sizeof(my_bind));
6812 my_bind[0].buffer_type= MYSQL_TYPE_SHORT;
6813 my_bind[0].buffer= (
void *)&short_value;
6814 my_bind[0].length= &s_length;
6816 my_bind[1].buffer_type= MYSQL_TYPE_LONG;
6817 my_bind[1].buffer= (
void *)&long_value;
6818 my_bind[1].length= &l_length;
6820 my_bind[2].buffer_type= MYSQL_TYPE_LONGLONG;
6821 my_bind[2].buffer= (
void *)&longlong_value;
6822 my_bind[2].length= &ll_length;
6824 my_bind[3].buffer_type= MYSQL_TYPE_TINY;
6825 my_bind[3].buffer= (
void *)&tiny_value;
6826 my_bind[3].is_unsigned= TRUE;
6827 my_bind[3].length= &t_length;
6829 rc= mysql_stmt_bind_result(stmt, my_bind);
6830 check_execute(stmt, rc);
6832 rc= mysql_stmt_fetch(stmt);
6833 check_execute(stmt, rc);
6837 fprintf(stdout,
"\n sshort : %d (%ld)", short_value, s_length);
6838 fprintf(stdout,
"\n slong : %ld (%ld)", (
long) long_value, l_length);
6839 fprintf(stdout,
"\n longlong : %s (%ld)", llstr(longlong_value, llbuf),
6841 fprintf(stdout,
"\n tinyint : %d (%ld)", tiny_value, t_length);
6844 DIE_UNLESS(short_value == -5999);
6845 DIE_UNLESS(s_length == 2);
6847 DIE_UNLESS(long_value == -5999);
6848 DIE_UNLESS(l_length == 4);
6850 DIE_UNLESS(longlong_value == 35999);
6851 DIE_UNLESS(ll_length == 8);
6853 DIE_UNLESS(tiny_value == 200);
6854 DIE_UNLESS(t_length == 1);
6856 rc= mysql_stmt_fetch(stmt);
6857 DIE_UNLESS(rc == MYSQL_NO_DATA);
6859 mysql_stmt_close(stmt);
6865 static void test_stiny_bug()
6871 ulong s_length, l_length, ll_length, t_length;
6872 ulonglong longlong_value;
6877 myheader(
"test_stiny_bug");
6879 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_stiny");
6882 rc= mysql_query(mysql,
"CREATE TABLE test_stiny(a tinyint signed, \
6884 c tinyint unsigned, \
6885 d tinyint unsigned)");
6888 rc= mysql_query(mysql,
"INSERT INTO test_stiny VALUES(-128, -127, 255, 0)");
6892 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_stiny");
6895 rc= mysql_stmt_execute(stmt);
6896 check_execute(stmt, rc);
6898 memset(my_bind, 0,
sizeof(my_bind));
6899 my_bind[0].buffer_type= MYSQL_TYPE_SHORT;
6900 my_bind[0].buffer= (
void *)&short_value;
6901 my_bind[0].length= &s_length;
6903 my_bind[1].buffer_type= MYSQL_TYPE_LONG;
6904 my_bind[1].buffer= (
void *)&long_value;
6905 my_bind[1].length= &l_length;
6907 my_bind[2].buffer_type= MYSQL_TYPE_LONGLONG;
6908 my_bind[2].buffer= (
void *)&longlong_value;
6909 my_bind[2].length= &ll_length;
6911 my_bind[3].buffer_type= MYSQL_TYPE_TINY;
6912 my_bind[3].buffer= (
void *)&tiny_value;
6913 my_bind[3].length= &t_length;
6915 rc= mysql_stmt_bind_result(stmt, my_bind);
6916 check_execute(stmt, rc);
6918 rc= mysql_stmt_fetch(stmt);
6919 check_execute(stmt, rc);
6923 fprintf(stdout,
"\n sshort : %d (%ld)", short_value, s_length);
6924 fprintf(stdout,
"\n slong : %ld (%ld)", (
long) long_value, l_length);
6925 fprintf(stdout,
"\n longlong : %s (%ld)", llstr(longlong_value, llbuf),
6927 fprintf(stdout,
"\n tinyint : %d (%ld)", tiny_value, t_length);
6930 DIE_UNLESS(short_value == -128);
6931 DIE_UNLESS(s_length == 2);
6933 DIE_UNLESS(long_value == -127);
6934 DIE_UNLESS(l_length == 4);
6936 DIE_UNLESS(longlong_value == 255);
6937 DIE_UNLESS(ll_length == 8);
6939 DIE_UNLESS(tiny_value == 0);
6940 DIE_UNLESS(t_length == 1);
6942 rc= mysql_stmt_fetch(stmt);
6943 DIE_UNLESS(rc == MYSQL_NO_DATA);
6945 mysql_stmt_close(stmt);
6951 static void test_field_misc()
6957 myheader(
"test_field_misc");
6959 rc= mysql_query(mysql,
"SELECT @@autocommit");
6962 result= mysql_store_result(mysql);
6965 rc= my_process_result_set(result);
6966 DIE_UNLESS(rc == 1);
6968 verify_prepare_field(result, 0,
6970 MYSQL_TYPE_LONGLONG,
6974 mysql_free_result(result);
6976 stmt= mysql_simple_prepare(mysql,
"SELECT @@autocommit");
6979 rc= mysql_stmt_execute(stmt);
6980 check_execute(stmt, rc);
6982 result= mysql_stmt_result_metadata(stmt);
6985 rc= my_process_stmt_result(stmt);
6986 DIE_UNLESS(rc == 1);
6988 verify_prepare_field(result, 0,
6990 MYSQL_TYPE_LONGLONG,
6994 mysql_free_result(result);
6995 mysql_stmt_close(stmt);
6997 stmt= mysql_simple_prepare(mysql,
"SELECT @@max_error_count");
7000 result= mysql_stmt_result_metadata(stmt);
7003 rc= mysql_stmt_execute(stmt);
7004 check_execute(stmt, rc);
7006 rc= my_process_stmt_result(stmt);
7007 DIE_UNLESS(rc == 1);
7009 verify_prepare_field(result, 0,
7010 "@@max_error_count",
"",
7011 MYSQL_TYPE_LONGLONG,
7014 "", MY_INT64_NUM_DECIMAL_DIGITS , 0);
7016 mysql_free_result(result);
7017 mysql_stmt_close(stmt);
7019 stmt= mysql_simple_prepare(mysql,
"SELECT @@max_allowed_packet");
7022 result= mysql_stmt_result_metadata(stmt);
7025 rc= mysql_stmt_execute(stmt);
7026 check_execute(stmt, rc);
7028 DIE_UNLESS(1 == my_process_stmt_result(stmt));
7030 verify_prepare_field(result, 0,
7031 "@@max_allowed_packet",
"",
7032 MYSQL_TYPE_LONGLONG,
7035 "", MY_INT64_NUM_DECIMAL_DIGITS, 0);
7037 mysql_free_result(result);
7038 mysql_stmt_close(stmt);
7040 stmt= mysql_simple_prepare(mysql,
"SELECT @@sql_warnings");
7043 result= mysql_stmt_result_metadata(stmt);
7046 rc= mysql_stmt_execute(stmt);
7047 check_execute(stmt, rc);
7049 rc= my_process_stmt_result(stmt);
7050 DIE_UNLESS(rc == 1);
7052 verify_prepare_field(result, 0,
7053 "@@sql_warnings",
"",
7054 MYSQL_TYPE_LONGLONG,
7058 mysql_free_result(result);
7059 mysql_stmt_close(stmt);
7068 static void test_set_option()
7074 myheader(
"test_set_option");
7076 mysql_autocommit(mysql, TRUE);
7079 rc= mysql_query(mysql,
"SET SQL_SELECT_LIMIT= 2");
7082 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_limit");
7085 rc= mysql_query(mysql,
"CREATE TABLE test_limit(a tinyint)");
7088 rc= mysql_query(mysql,
"INSERT INTO test_limit VALUES(10), (20), (30), (40)");
7092 fprintf(stdout,
"\n with SQL_SELECT_LIMIT= 2 (direct)");
7093 rc= mysql_query(mysql,
"SELECT * FROM test_limit");
7096 result= mysql_store_result(mysql);
7099 rc= my_process_result_set(result);
7100 DIE_UNLESS(rc == 2);
7102 mysql_free_result(result);
7105 fprintf(stdout,
"\n with SQL_SELECT_LIMIT=2 (prepare)");
7106 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_limit");
7109 rc= mysql_stmt_execute(stmt);
7110 check_execute(stmt, rc);
7112 rc= my_process_stmt_result(stmt);
7113 DIE_UNLESS(rc == 2);
7115 mysql_stmt_close(stmt);
7119 fprintf(stdout,
"\n with SQL_SELECT_LIMIT=DEFAULT (prepare)");
7120 rc= mysql_query(mysql,
"SET SQL_SELECT_LIMIT=DEFAULT");
7123 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_limit");
7126 rc= mysql_stmt_execute(stmt);
7127 check_execute(stmt, rc);
7129 rc= my_process_stmt_result(stmt);
7130 DIE_UNLESS(rc == 4);
7132 mysql_stmt_close(stmt);
7136 #ifdef EMBEDDED_LIBRARY
7137 static void test_embedded_start_stop()
7139 MYSQL *mysql_emb=NULL;
7141 int argc= original_argc;
7142 char **argv, **my_argv;
7143 char test_name[]=
"test_embedded_start_stop";
7144 const unsigned int drop_db= opt_drop_db;
7145 #define EMBEDDED_RESTARTS 64
7147 myheader(
"test_embedded_start_stop");
7151 client_disconnect(mysql);
7152 free_defaults(defaults_argv);
7156 opt_drop_db= drop_db;
7163 my_argv= malloc((argc + 1) *
sizeof(
char*));
7168 for (i= 1; i <= EMBEDDED_RESTARTS; i++)
7172 for (j= 1; j < argc; j++)
7173 argv[j]= original_argv[j];
7179 if (load_defaults(
"my", client_test_load_default_groups, &argc, &argv))
7181 myerror(
"load_defaults failed");
7186 get_options(&argc, &argv);
7189 if (mysql_library_init(embedded_server_arg_count,
7190 embedded_server_args,
7191 (
char**) embedded_server_groups))
7193 myerror(
"mysql_library_init failed");
7198 if (!(mysql_emb= mysql_client_init(NULL)))
7200 myerror(
"mysql_client_init failed");
7205 if (!(mysql_real_connect(mysql_emb, opt_host, opt_user,
7206 opt_password, current_db, 0,
7209 myerror(
"mysql_real_connect failed");
7213 mysql_close(mysql_emb);
7216 free_defaults(defaults_argv);
7218 mysql_library_end();
7223 argc= original_argc;
7226 for (j= 1; j < argc; j++)
7227 argv[j]= original_argv[j];
7231 if (load_defaults(
"my", client_test_load_default_groups, &argc, &argv))
7233 myerror(
"load_defaults failed \n ");
7237 get_options(&argc, &argv);
7240 if (mysql_server_init(embedded_server_arg_count,
7241 embedded_server_args,
7242 (
char**) embedded_server_groups))
7243 DIE(
"Can't initialize MySQL server");
7246 mysql= client_connect(0, MYSQL_PROTOCOL_DEFAULT, 1);
7257 #ifndef EMBEDDED_LIBRARY
7258 static void test_prepare_grant()
7261 char query[MAX_TEST_QUERY_LENGTH];
7263 myheader(
"test_prepare_grant");
7265 mysql_autocommit(mysql, TRUE);
7267 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_grant");
7270 rc= mysql_query(mysql,
"CREATE TABLE test_grant(a tinyint primary key auto_increment)");
7273 strxmov(query,
"GRANT INSERT, UPDATE, SELECT ON ", current_db,
7274 ".test_grant TO 'test_grant'@",
7275 opt_host ? opt_host :
"'localhost'", NullS);
7277 if (mysql_query(mysql, query))
7279 myerror(
"GRANT failed");
7287 if (mysql_errno(mysql) != 1047)
7292 MYSQL *org_mysql= mysql, *lmysql;
7296 fprintf(stdout,
"\n Establishing a test connection ...");
7297 if (!(lmysql= mysql_client_init(NULL)))
7299 myerror(
"mysql_client_init() failed");
7302 if (!(mysql_real_connect(lmysql, opt_host,
"test_grant",
7303 "", current_db, opt_port,
7304 opt_unix_socket, 0)))
7306 myerror(
"connection failed");
7307 mysql_close(lmysql);
7310 lmysql->reconnect= 1;
7312 fprintf(stdout,
"OK");
7315 rc= mysql_query(mysql,
"INSERT INTO test_grant VALUES(NULL)");
7318 rc= mysql_query(mysql,
"INSERT INTO test_grant(a) VALUES(NULL)");
7321 execute_prepare_query(
"INSERT INTO test_grant(a) VALUES(NULL)", 1);
7322 execute_prepare_query(
"INSERT INTO test_grant VALUES(NULL)", 1);
7323 execute_prepare_query(
"UPDATE test_grant SET a=9 WHERE a=1", 1);
7324 rc= my_stmt_result(
"SELECT a FROM test_grant");
7325 DIE_UNLESS(rc == 4);
7329 rc= mysql_query(mysql,
"DELETE FROM test_grant");
7332 stmt= mysql_simple_prepare(mysql,
"DELETE FROM test_grant");
7335 rc= my_stmt_result(
"SELECT * FROM test_grant");
7336 DIE_UNLESS(rc == 4);
7338 mysql_close(lmysql);
7341 rc= mysql_query(mysql,
"delete from mysql.user where User='test_grant'");
7343 DIE_UNLESS(1 == mysql_affected_rows(mysql));
7345 rc= mysql_query(mysql,
"delete from mysql.tables_priv where User='test_grant'");
7347 DIE_UNLESS(1 == mysql_affected_rows(mysql));
7359 static void test_frm_bug()
7366 char data_dir[FN_REFLEN];
7367 char test_frm[FN_REFLEN];
7370 myheader(
"test_frm_bug");
7372 mysql_autocommit(mysql, TRUE);
7374 rc= mysql_query(mysql,
"drop table if exists test_frm_bug");
7377 rc= mysql_query(mysql,
"flush tables");
7380 stmt= mysql_simple_prepare(mysql,
"show variables like 'datadir'");
7383 rc= mysql_stmt_execute(stmt);
7384 check_execute(stmt, rc);
7386 memset(my_bind, 0,
sizeof(my_bind));
7387 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
7388 my_bind[0].buffer= data_dir;
7389 my_bind[0].buffer_length= FN_REFLEN;
7390 my_bind[1]= my_bind[0];
7392 rc= mysql_stmt_bind_result(stmt, my_bind);
7393 check_execute(stmt, rc);
7395 rc= mysql_stmt_fetch(stmt);
7396 check_execute(stmt, rc);
7399 fprintf(stdout,
"\n data directory: %s", data_dir);
7401 rc= mysql_stmt_fetch(stmt);
7402 DIE_UNLESS(rc == MYSQL_NO_DATA);
7404 strxmov(test_frm, data_dir,
"/", current_db,
"/",
"test_frm_bug.frm", NullS);
7407 fprintf(stdout,
"\n test_frm: %s", test_frm);
7409 if (!(test_file= my_fopen(test_frm, (
int) (O_RDWR | O_CREAT), MYF(MY_WME))))
7411 fprintf(stdout,
"\n ERROR: my_fopen failed for '%s'", test_frm);
7412 fprintf(stdout,
"\n test cancelled");
7416 fprintf(test_file,
"this is a junk file for test");
7418 rc= mysql_query(mysql,
"SHOW TABLE STATUS like 'test_frm_bug'");
7421 result= mysql_store_result(mysql);
7424 rc= my_process_result_set(result);
7425 DIE_UNLESS(rc == 1);
7427 mysql_data_seek(result, 0);
7429 row= mysql_fetch_row(result);
7433 fprintf(stdout,
"\n Comment: %s", row[17]);
7434 DIE_UNLESS(row[17] != 0);
7436 mysql_free_result(result);
7437 mysql_stmt_close(stmt);
7439 my_fclose(test_file, MYF(0));
7440 mysql_query(mysql,
"drop table if exists test_frm_bug");
7446 static void test_decimal_bug()
7454 myheader(
"test_decimal_bug");
7456 mysql_autocommit(mysql, TRUE);
7458 rc= mysql_query(mysql,
"drop table if exists test_decimal_bug");
7461 rc= mysql_query(mysql,
"create table test_decimal_bug(c1 decimal(10, 2))");
7464 rc= mysql_query(mysql,
"insert into test_decimal_bug value(8), (10.22), (5.61)");
7467 stmt= mysql_simple_prepare(mysql,
"select c1 from test_decimal_bug where c1= ?");
7474 memset(my_bind, 0,
sizeof(my_bind));
7476 my_bind[0].buffer_type= MYSQL_TYPE_NEWDECIMAL;
7477 my_bind[0].buffer= (
void *)data;
7478 my_bind[0].buffer_length= 25;
7479 my_bind[0].is_null= &is_null;
7482 rc= mysql_stmt_bind_param(stmt, my_bind);
7483 check_execute(stmt, rc);
7485 strmov(data,
"8.0");
7486 rc= mysql_stmt_execute(stmt);
7487 check_execute(stmt, rc);
7490 rc= mysql_stmt_bind_result(stmt, my_bind);
7491 check_execute(stmt, rc);
7493 rc= mysql_stmt_fetch(stmt);
7494 check_execute(stmt, rc);
7497 fprintf(stdout,
"\n data: %s", data);
7498 DIE_UNLESS(strcmp(data,
"8.00") == 0);
7500 rc= mysql_stmt_fetch(stmt);
7501 DIE_UNLESS(rc == MYSQL_NO_DATA);
7503 strmov(data,
"5.61");
7504 rc= mysql_stmt_execute(stmt);
7505 check_execute(stmt, rc);
7508 rc= mysql_stmt_bind_result(stmt, my_bind);
7509 check_execute(stmt, rc);
7511 rc= mysql_stmt_fetch(stmt);
7512 check_execute(stmt, rc);
7515 fprintf(stdout,
"\n data: %s", data);
7516 DIE_UNLESS(strcmp(data,
"5.61") == 0);
7518 rc= mysql_stmt_fetch(stmt);
7519 DIE_UNLESS(rc == MYSQL_NO_DATA);
7522 rc= mysql_stmt_execute(stmt);
7523 check_execute(stmt, rc);
7525 rc= mysql_stmt_fetch(stmt);
7526 DIE_UNLESS(rc == MYSQL_NO_DATA);
7528 strmov(data,
"10.22"); is_null= 0;
7529 rc= mysql_stmt_execute(stmt);
7530 check_execute(stmt, rc);
7533 rc= mysql_stmt_bind_result(stmt, my_bind);
7534 check_execute(stmt, rc);
7536 rc= mysql_stmt_fetch(stmt);
7537 check_execute(stmt, rc);
7540 fprintf(stdout,
"\n data: %s", data);
7541 DIE_UNLESS(strcmp(data,
"10.22") == 0);
7543 rc= mysql_stmt_fetch(stmt);
7544 DIE_UNLESS(rc == MYSQL_NO_DATA);
7546 mysql_stmt_close(stmt);
7552 static void test_explain_bug()
7558 myheader(
"test_explain_bug");
7560 mysql_autocommit(mysql, TRUE);
7562 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_explain");
7565 rc= mysql_query(mysql,
"CREATE TABLE test_explain(id int, name char(2))");
7568 stmt= mysql_simple_prepare(mysql,
"explain test_explain");
7571 rc= mysql_stmt_execute(stmt);
7572 check_execute(stmt, rc);
7574 rc= my_process_stmt_result(stmt);
7575 DIE_UNLESS(rc == 2);
7577 result= mysql_stmt_result_metadata(stmt);
7581 fprintf(stdout,
"\n total fields in the result: %d",
7582 mysql_num_fields(result));
7583 DIE_UNLESS(6 == mysql_num_fields(result));
7585 verify_prepare_field(result, 0,
"Field",
"COLUMN_NAME",
7586 mysql_get_server_version(mysql) <= 50000 ?
7587 MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
7588 0, 0,
"information_schema", 64, 0);
7590 verify_prepare_field(result, 1,
"Type",
"COLUMN_TYPE", MYSQL_TYPE_BLOB,
7591 0, 0,
"information_schema", 0, 0);
7593 verify_prepare_field(result, 2,
"Null",
"IS_NULLABLE",
7594 mysql_get_server_version(mysql) <= 50000 ?
7595 MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
7596 0, 0,
"information_schema", 3, 0);
7598 verify_prepare_field(result, 3,
"Key",
"COLUMN_KEY",
7599 mysql_get_server_version(mysql) <= 50000 ?
7600 MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
7601 0, 0,
"information_schema", 3, 0);
7603 if ( mysql_get_server_version(mysql) >= 50027 )
7606 verify_prepare_field(result, 4,
"Default",
"COLUMN_DEFAULT",
7607 MYSQL_TYPE_BLOB, 0, 0,
"information_schema", 0, 0);
7611 verify_prepare_field(result, 4,
"Default",
"COLUMN_DEFAULT",
7612 mysql_get_server_version(mysql) >= 50027 ?
7614 mysql_get_server_version(mysql) <= 50000 ?
7615 MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
7616 0, 0,
"information_schema",
7617 mysql_get_server_version(mysql) >= 50027 ? 0 :64, 0);
7620 verify_prepare_field(result, 5,
"Extra",
"EXTRA",
7621 mysql_get_server_version(mysql) <= 50000 ?
7622 MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
7623 0, 0,
"information_schema",
7624 mysql_get_server_version(mysql) <= 50602 ? 27 : 30,
7627 mysql_free_result(result);
7628 mysql_stmt_close(stmt);
7630 stmt= mysql_simple_prepare(mysql,
"explain select id, name FROM test_explain");
7633 rc= mysql_stmt_execute(stmt);
7634 check_execute(stmt, rc);
7636 rc= my_process_stmt_result(stmt);
7637 DIE_UNLESS(rc == 1);
7639 result= mysql_stmt_result_metadata(stmt);
7643 fprintf(stdout,
"\n total fields in the result: %d",
7644 mysql_num_fields(result));
7645 DIE_UNLESS(10 == mysql_num_fields(result));
7647 verify_prepare_field(result, 0,
"id",
"", MYSQL_TYPE_LONGLONG,
7650 verify_prepare_field(result, 1,
"select_type",
"", MYSQL_TYPE_VAR_STRING,
7653 verify_prepare_field(result, 2,
"table",
"", MYSQL_TYPE_VAR_STRING,
7654 "",
"",
"", NAME_CHAR_LEN, 0);
7656 verify_prepare_field(result, 3,
"type",
"", MYSQL_TYPE_VAR_STRING,
7659 verify_prepare_field(result, 4,
"possible_keys",
"", MYSQL_TYPE_VAR_STRING,
7660 "",
"",
"", NAME_CHAR_LEN*MAX_KEY, 0);
7662 verify_prepare_field(result, 5,
"key",
"", MYSQL_TYPE_VAR_STRING,
7663 "",
"",
"", NAME_CHAR_LEN, 0);
7665 if (mysql_get_server_version(mysql) <= 50000)
7667 verify_prepare_field(result, 6,
"key_len",
"", MYSQL_TYPE_LONGLONG,
"",
7672 verify_prepare_field(result, 6,
"key_len",
"", MYSQL_TYPE_VAR_STRING,
"",
7673 "",
"", NAME_CHAR_LEN*MAX_KEY, 0);
7676 verify_prepare_field(result, 7,
"ref",
"", MYSQL_TYPE_VAR_STRING,
7677 "",
"",
"", NAME_CHAR_LEN*16, 0);
7679 verify_prepare_field(result, 8,
"rows",
"", MYSQL_TYPE_LONGLONG,
7682 verify_prepare_field(result, 9,
"Extra",
"", MYSQL_TYPE_VAR_STRING,
7683 "",
"",
"", 255, 0);
7685 mysql_free_result(result);
7686 mysql_stmt_close(stmt);
7689 #ifdef NOT_YET_WORKING
7696 #define myerrno(n) check_errcode(n)
7698 static void check_errcode(
const unsigned int err)
7700 if (!opt_silent || mysql_errno(mysql) != err)
7702 if (mysql->server_version)
7703 fprintf(stdout,
"\n [MySQL-%s]", mysql->server_version);
7705 fprintf(stdout,
"\n [MySQL]");
7706 fprintf(stdout,
"[%d] %s\n", mysql_errno(mysql), mysql_error(mysql));
7708 DIE_UNLESS(mysql_errno(mysql) == err);
7712 static void test_drop_temp()
7716 myheader(
"test_drop_temp");
7718 rc= mysql_query(mysql,
"DROP DATABASE IF EXISTS test_drop_temp_db");
7721 rc= mysql_query(mysql,
"CREATE DATABASE test_drop_temp_db");
7724 rc= mysql_query(mysql,
"CREATE TABLE test_drop_temp_db.t1(c1 int, c2 char(1))");
7727 rc= mysql_query(mysql,
"delete from mysql.db where Db='test_drop_temp_db'");
7730 rc= mysql_query(mysql,
"delete from mysql.db where Db='test_drop_temp_db'");
7733 strxmov(query,
"GRANT SELECT, USAGE, DROP ON test_drop_temp_db.* TO test_temp@",
7734 opt_host ? opt_host :
"localhost", NullS);
7736 if (mysql_query(mysql, query))
7738 myerror(
"GRANT failed");
7746 if (mysql_errno(mysql) != 1047)
7751 MYSQL *org_mysql= mysql, *lmysql;
7754 fprintf(stdout,
"\n Establishing a test connection ...");
7755 if (!(lmysql= mysql_client_init(NULL)))
7757 myerror(
"mysql_client_init() failed");
7761 rc= mysql_query(mysql,
"flush privileges");
7764 if (!(mysql_real_connect(lmysql, opt_host ? opt_host :
"localhost",
"test_temp",
7765 "",
"test_drop_temp_db", opt_port,
7766 opt_unix_socket, 0)))
7769 myerror(
"connection failed");
7770 mysql_close(lmysql);
7773 lmysql->reconnect= 1;
7775 fprintf(stdout,
"OK");
7778 rc= mysql_query(mysql,
"INSERT INTO t1 VALUES(10, 'C')");
7779 myerrno((uint)1142);
7781 rc= mysql_query(mysql,
"DROP TABLE t1");
7782 myerrno((uint)1142);
7785 rc= mysql_query(mysql,
"CREATE TEMPORARY TABLE test_drop_temp_db.t1(c1 int)");
7788 rc= mysql_query(mysql,
"CREATE TEMPORARY TABLE test_drop_temp_db.t2 LIKE test_drop_temp_db.t1");
7793 rc= mysql_query(mysql,
"DROP TABLE t1, t2");
7796 rc= mysql_query(mysql,
"DROP TEMPORARY TABLE t1");
7799 rc= mysql_query(mysql,
"DROP TEMPORARY TABLE t2");
7802 mysql_close(lmysql);
7805 rc= mysql_query(mysql,
"drop database test_drop_temp_db");
7807 DIE_UNLESS(1 == mysql_affected_rows(mysql));
7809 rc= mysql_query(mysql,
"delete from mysql.user where User='test_temp'");
7811 DIE_UNLESS(1 == mysql_affected_rows(mysql));
7814 rc= mysql_query(mysql,
"delete from mysql.tables_priv where User='test_temp'");
7816 DIE_UNLESS(1 == mysql_affected_rows(mysql));
7824 static void test_cuted_rows()
7829 myheader(
"test_cuted_rows");
7831 mysql_query(mysql,
"DROP TABLE if exists t1");
7832 mysql_query(mysql,
"DROP TABLE if exists t2");
7834 rc= mysql_query(mysql,
"CREATE TABLE t1(c1 tinyint)");
7837 rc= mysql_query(mysql,
"CREATE TABLE t2(c1 int not null)");
7840 rc= mysql_query(mysql,
"INSERT INTO t1 values(10), (NULL), (NULL)");
7843 count= mysql_warning_count(mysql);
7845 fprintf(stdout,
"\n total warnings: %d", count);
7846 DIE_UNLESS(count == 0);
7848 rc= mysql_query(mysql,
"INSERT INTO t2 SELECT * FROM t1");
7851 count= mysql_warning_count(mysql);
7853 fprintf(stdout,
"\n total warnings: %d", count);
7854 DIE_UNLESS(count == 2);
7856 rc= mysql_query(mysql,
"SHOW WARNINGS");
7859 result= mysql_store_result(mysql);
7862 rc= my_process_result_set(result);
7863 DIE_UNLESS(rc == 2);
7864 mysql_free_result(result);
7866 rc= mysql_query(mysql,
"INSERT INTO t1 VALUES('junk'), (876789)");
7869 count= mysql_warning_count(mysql);
7871 fprintf(stdout,
"\n total warnings: %d", count);
7872 DIE_UNLESS(count == 2);
7874 rc= mysql_query(mysql,
"SHOW WARNINGS");
7877 result= mysql_store_result(mysql);
7880 rc= my_process_result_set(result);
7881 DIE_UNLESS(rc == 2);
7882 mysql_free_result(result);
7888 static void test_logs()
7897 myheader(
"test_logs");
7900 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_logs");
7903 rc= mysql_query(mysql,
"CREATE TABLE test_logs(id smallint, name varchar(20))");
7906 strmov((
char *)data,
"INSERT INTO test_logs VALUES(?, ?)");
7907 stmt= mysql_simple_prepare(mysql, data);
7914 memset(my_bind, 0,
sizeof(my_bind));
7916 my_bind[0].buffer_type= MYSQL_TYPE_SHORT;
7917 my_bind[0].buffer= (
void *)&
id;
7919 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
7920 my_bind[1].buffer= (
void *)&data;
7921 my_bind[1].buffer_length= 255;
7922 my_bind[1].length= &length;
7925 length= (ulong)(strmov((
char *)data,
"MySQL - Open Source Database")- data);
7927 rc= mysql_stmt_bind_param(stmt, my_bind);
7928 check_execute(stmt, rc);
7930 rc= mysql_stmt_execute(stmt);
7931 check_execute(stmt, rc);
7933 strmov((
char *)data,
"'");
7936 rc= mysql_stmt_execute(stmt);
7937 check_execute(stmt, rc);
7939 strmov((
char *)data,
"\"");
7942 rc= mysql_stmt_execute(stmt);
7943 check_execute(stmt, rc);
7945 length= (ulong)(strmov((
char *)data,
"my\'sql\'")-data);
7946 rc= mysql_stmt_execute(stmt);
7947 check_execute(stmt, rc);
7949 length= (ulong)(strmov((
char *)data,
"my\"sql\"")-data);
7950 rc= mysql_stmt_execute(stmt);
7951 check_execute(stmt, rc);
7953 mysql_stmt_close(stmt);
7955 strmov((
char *)data,
"INSERT INTO test_logs VALUES(20, 'mysql')");
7956 stmt= mysql_simple_prepare(mysql, data);
7959 rc= mysql_stmt_execute(stmt);
7960 check_execute(stmt, rc);
7962 rc= mysql_stmt_execute(stmt);
7963 check_execute(stmt, rc);
7965 mysql_stmt_close(stmt);
7967 strmov((
char *)data,
"SELECT * FROM test_logs WHERE id=?");
7968 stmt= mysql_simple_prepare(mysql, data);
7971 rc= mysql_stmt_bind_param(stmt, my_bind);
7972 check_execute(stmt, rc);
7974 rc= mysql_stmt_execute(stmt);
7975 check_execute(stmt, rc);
7977 my_bind[1].buffer_length= 255;
7978 rc= mysql_stmt_bind_result(stmt, my_bind);
7979 check_execute(stmt, rc);
7981 rc= mysql_stmt_fetch(stmt);
7982 check_execute(stmt, rc);
7986 fprintf(stdout,
"id : %d\n",
id);
7987 fprintf(stdout,
"name : %s(%ld)\n", data, length);
7990 DIE_UNLESS(
id == 9876);
7991 DIE_UNLESS(length == 19 || length == 20);
7992 DIE_UNLESS(is_prefix(data,
"MySQL - Open Source") == 1);
7994 rc= mysql_stmt_fetch(stmt);
7995 check_execute(stmt, rc);
7998 fprintf(stdout,
"\n name : %s(%ld)", data, length);
8000 DIE_UNLESS(length == 1);
8001 DIE_UNLESS(strcmp(data,
"'") == 0);
8003 rc= mysql_stmt_fetch(stmt);
8004 check_execute(stmt, rc);
8007 fprintf(stdout,
"\n name : %s(%ld)", data, length);
8009 DIE_UNLESS(length == 1);
8010 DIE_UNLESS(strcmp(data,
"\"") == 0);
8012 rc= mysql_stmt_fetch(stmt);
8013 check_execute(stmt, rc);
8016 fprintf(stdout,
"\n name : %s(%ld)", data, length);
8018 DIE_UNLESS(length == 7);
8019 DIE_UNLESS(strcmp(data,
"my\'sql\'") == 0);
8021 rc= mysql_stmt_fetch(stmt);
8022 check_execute(stmt, rc);
8025 fprintf(stdout,
"\n name : %s(%ld)", data, length);
8027 DIE_UNLESS(length == 7);
8030 rc= mysql_stmt_fetch(stmt);
8031 DIE_UNLESS(rc == MYSQL_NO_DATA);
8033 mysql_stmt_close(stmt);
8035 rc= mysql_query(mysql,
"DROP TABLE test_logs");
8042 static void test_nstmts()
8047 static uint
i, total_stmts= 2000;
8050 myheader(
"test_nstmts");
8052 mysql_autocommit(mysql, TRUE);
8054 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_nstmts");
8057 rc= mysql_query(mysql,
"CREATE TABLE test_nstmts(id int)");
8064 memset(my_bind, 0,
sizeof(my_bind));
8066 my_bind[0].buffer= (
void *)&i;
8067 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
8069 for (i= 0; i < total_stmts; i++)
8072 fprintf(stdout,
"\r stmt: %d", i);
8074 strmov(query,
"insert into test_nstmts values(?)");
8075 stmt= mysql_simple_prepare(mysql, query);
8078 rc= mysql_stmt_bind_param(stmt, my_bind);
8079 check_execute(stmt, rc);
8081 rc= mysql_stmt_execute(stmt);
8082 check_execute(stmt, rc);
8084 mysql_stmt_close(stmt);
8087 stmt= mysql_simple_prepare(mysql,
" select count(*) from test_nstmts");
8090 rc= mysql_stmt_execute(stmt);
8091 check_execute(stmt, rc);
8094 rc= mysql_stmt_bind_result(stmt, my_bind);
8095 check_execute(stmt, rc);
8097 rc= mysql_stmt_fetch(stmt);
8098 check_execute(stmt, rc);
8100 fprintf(stdout,
"\n total rows: %d", i);
8101 DIE_UNLESS( i == total_stmts);
8103 rc= mysql_stmt_fetch(stmt);
8104 DIE_UNLESS(rc == MYSQL_NO_DATA);
8106 mysql_stmt_close(stmt);
8108 rc= mysql_query(mysql,
"DROP TABLE test_nstmts");
8115 static void test_fetch_seek()
8122 char c2[11], c3[20];
8124 myheader(
"test_fetch_seek");
8125 rc= mysql_query(mysql,
"drop table if exists t1");
8129 rc= mysql_query(mysql,
"create table t1(c1 int primary key auto_increment, c2 char(10), c3 timestamp)");
8132 rc= mysql_query(mysql,
"insert into t1(c2) values('venu'), ('mysql'), ('open'), ('source')");
8135 stmt= mysql_simple_prepare(mysql,
"select * from t1");
8138 memset(my_bind, 0,
sizeof(my_bind));
8139 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
8140 my_bind[0].buffer= (
void *)&c1;
8142 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
8143 my_bind[1].buffer= (
void *)c2;
8144 my_bind[1].buffer_length=
sizeof(c2);
8146 my_bind[2]= my_bind[1];
8147 my_bind[2].buffer= (
void *)c3;
8148 my_bind[2].buffer_length=
sizeof(c3);
8150 rc= mysql_stmt_execute(stmt);
8151 check_execute(stmt, rc);
8153 rc= mysql_stmt_bind_result(stmt, my_bind);
8154 check_execute(stmt, rc);
8156 rc= mysql_stmt_store_result(stmt);
8157 check_execute(stmt, rc);
8159 rc= mysql_stmt_fetch(stmt);
8160 check_execute(stmt, rc);
8163 fprintf(stdout,
"\n row 0: %ld, %s, %s", (
long) c1, c2, c3);
8165 row= mysql_stmt_row_tell(stmt);
8167 row= mysql_stmt_row_seek(stmt, row);
8169 rc= mysql_stmt_fetch(stmt);
8170 check_execute(stmt, rc);
8173 fprintf(stdout,
"\n row 2: %ld, %s, %s", (
long) c1, c2, c3);
8175 row= mysql_stmt_row_seek(stmt, row);
8177 rc= mysql_stmt_fetch(stmt);
8178 check_execute(stmt, rc);
8181 fprintf(stdout,
"\n row 2: %ld, %s, %s", (
long) c1, c2, c3);
8183 mysql_stmt_data_seek(stmt, 0);
8185 rc= mysql_stmt_fetch(stmt);
8186 check_execute(stmt, rc);
8189 fprintf(stdout,
"\n row 0: %ld, %s, %s", (
long) c1, c2, c3);
8191 rc= mysql_stmt_fetch(stmt);
8192 check_execute(stmt, rc);
8194 rc= mysql_stmt_fetch(stmt);
8195 check_execute(stmt, rc);
8197 rc= mysql_stmt_fetch(stmt);
8198 check_execute(stmt, rc);
8200 rc= mysql_stmt_fetch(stmt);
8201 DIE_UNLESS(rc == MYSQL_NO_DATA);
8203 mysql_stmt_close(stmt);
8204 myquery(mysql_query(mysql,
"drop table t1"));
8210 static void test_fetch_offset()
8220 myheader(
"test_fetch_offset");
8222 rc= mysql_query(mysql,
"drop table if exists t1");
8225 rc= mysql_query(mysql,
"create table t1(a char(10))");
8228 rc= mysql_query(mysql,
"insert into t1 values('abcdefghij'), (null)");
8231 stmt= mysql_simple_prepare(mysql,
"select * from t1");
8234 memset(my_bind, 0,
sizeof(my_bind));
8235 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
8236 my_bind[0].buffer= (
void *)data;
8237 my_bind[0].buffer_length= 11;
8238 my_bind[0].is_null= &is_null;
8239 my_bind[0].length= &length;
8241 rc= mysql_stmt_execute(stmt);
8242 check_execute(stmt, rc);
8244 rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0);
8245 check_execute_r(stmt, rc);
8247 rc= mysql_stmt_execute(stmt);
8248 check_execute(stmt, rc);
8250 rc= mysql_stmt_bind_result(stmt, my_bind);
8251 check_execute(stmt, rc);
8253 rc= mysql_stmt_store_result(stmt);
8254 check_execute(stmt, rc);
8256 rc= mysql_stmt_fetch(stmt);
8257 check_execute(stmt, rc);
8260 rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0);
8261 check_execute(stmt, rc);
8263 fprintf(stdout,
"\n col 1: %s (%ld)", data, length);
8264 DIE_UNLESS(strncmp(data,
"abcd", 4) == 0 && length == 10);
8266 rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 5);
8267 check_execute(stmt, rc);
8269 fprintf(stdout,
"\n col 1: %s (%ld)", data, length);
8270 DIE_UNLESS(strncmp(data,
"fg", 2) == 0 && length == 10);
8272 rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 9);
8273 check_execute(stmt, rc);
8275 fprintf(stdout,
"\n col 0: %s (%ld)", data, length);
8276 DIE_UNLESS(strncmp(data,
"j", 1) == 0 && length == 10);
8278 rc= mysql_stmt_fetch(stmt);
8279 check_execute(stmt, rc);
8283 rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0);
8284 check_execute(stmt, rc);
8286 DIE_UNLESS(is_null == 1);
8288 rc= mysql_stmt_fetch(stmt);
8289 DIE_UNLESS(rc == MYSQL_NO_DATA);
8291 rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0);
8292 check_execute_r(stmt, rc);
8294 mysql_stmt_close(stmt);
8296 myquery(mysql_query(mysql,
"drop table t1"));
8302 static void test_fetch_column()
8306 char c2[20], bc2[20];
8307 ulong l1, l2, bl1, bl2;
8310 myheader(
"test_fetch_column");
8312 rc= mysql_query(mysql,
"drop table if exists t1");
8315 rc= mysql_query(mysql,
"create table t1(c1 int primary key auto_increment, c2 char(10))");
8318 rc= mysql_query(mysql,
"insert into t1(c2) values('venu'), ('mysql')");
8321 stmt= mysql_simple_prepare(mysql,
"select * from t1 order by c2 desc");
8324 memset(my_bind, 0,
sizeof(my_bind));
8325 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
8326 my_bind[0].buffer= (
void *)&bc1;
8327 my_bind[0].buffer_length= 0;
8328 my_bind[0].is_null= 0;
8329 my_bind[0].length= &bl1;
8330 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
8331 my_bind[1].buffer= (
void *)bc2;
8332 my_bind[1].buffer_length= 7;
8333 my_bind[1].is_null= 0;
8334 my_bind[1].length= &bl2;
8336 rc= mysql_stmt_execute(stmt);
8337 check_execute(stmt, rc);
8339 rc= mysql_stmt_bind_result(stmt, my_bind);
8340 check_execute(stmt, rc);
8342 rc= mysql_stmt_store_result(stmt);
8343 check_execute(stmt, rc);
8345 rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0);
8346 check_execute_r(stmt, rc);
8348 rc= mysql_stmt_fetch(stmt);
8349 check_execute(stmt, rc);
8352 fprintf(stdout,
"\n row 0: %d, %s", bc1, bc2);
8355 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
8356 my_bind[0].buffer= (
void *)c2;
8357 my_bind[0].buffer_length= 7;
8358 my_bind[0].is_null= 0;
8359 my_bind[0].length= &l2;
8361 rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0);
8362 check_execute(stmt, rc);
8364 fprintf(stdout,
"\n col 1: %s(%ld)", c2, l2);
8365 DIE_UNLESS(strncmp(c2,
"venu", 4) == 0 && l2 == 4);
8368 rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0);
8369 check_execute(stmt, rc);
8371 fprintf(stdout,
"\n col 1: %s(%ld)", c2, l2);
8372 DIE_UNLESS(strcmp(c2,
"venu") == 0 && l2 == 4);
8375 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
8376 my_bind[0].buffer= (
void *)&c1;
8377 my_bind[0].buffer_length= 0;
8378 my_bind[0].is_null= 0;
8379 my_bind[0].length= &l1;
8381 rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0);
8382 check_execute(stmt, rc);
8384 fprintf(stdout,
"\n col 0: %d(%ld)", c1, l1);
8385 DIE_UNLESS(c1 == 1 && l1 == 4);
8387 rc= mysql_stmt_fetch(stmt);
8388 check_execute(stmt, rc);
8391 fprintf(stdout,
"\n row 1: %d, %s", bc1, bc2);
8394 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
8395 my_bind[0].buffer= (
void *)c2;
8396 my_bind[0].buffer_length= 7;
8397 my_bind[0].is_null= 0;
8398 my_bind[0].length= &l2;
8400 rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0);
8401 check_execute(stmt, rc);
8403 fprintf(stdout,
"\n col 1: %s(%ld)", c2, l2);
8404 DIE_UNLESS(strncmp(c2,
"mysq", 4) == 0 && l2 == 5);
8407 rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0);
8408 check_execute(stmt, rc);
8410 fprintf(stdout,
"\n col 1: %si(%ld)", c2, l2);
8411 DIE_UNLESS(strcmp(c2,
"mysql") == 0 && l2 == 5);
8414 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
8415 my_bind[0].buffer= (
void *)&c1;
8416 my_bind[0].buffer_length= 0;
8417 my_bind[0].is_null= 0;
8418 my_bind[0].length= &l1;
8420 rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0);
8421 check_execute(stmt, rc);
8423 fprintf(stdout,
"\n col 0: %d(%ld)", c1, l1);
8424 DIE_UNLESS(c1 == 2 && l1 == 4);
8426 rc= mysql_stmt_fetch(stmt);
8427 DIE_UNLESS(rc == MYSQL_NO_DATA);
8429 rc= mysql_stmt_fetch_column(stmt, my_bind, 1, 0);
8430 check_execute_r(stmt, rc);
8432 mysql_stmt_close(stmt);
8433 myquery(mysql_query(mysql,
"drop table t1"));
8439 static void test_list_fields()
8443 myheader(
"test_list_fields");
8445 rc= mysql_query(mysql,
"drop table if exists t1");
8448 rc= mysql_query(mysql,
"create table t1(c1 int primary key auto_increment, c2 char(10) default 'mysql')");
8451 result= mysql_list_fields(mysql,
"t1", NULL);
8454 rc= my_process_result_set(result);
8455 DIE_UNLESS(rc == 0);
8457 verify_prepare_field(result, 0,
"c1",
"c1", MYSQL_TYPE_LONG,
8459 current_db, 11,
"0");
8461 verify_prepare_field(result, 1,
"c2",
"c2", MYSQL_TYPE_STRING,
8463 current_db, 10,
"mysql");
8465 mysql_free_result(result);
8466 myquery(mysql_query(mysql,
"drop table t1"));
8470 static void test_bug19671()
8474 myheader(
"test_bug19671");
8476 mysql_query(mysql,
"set sql_mode=''");
8477 rc= mysql_query(mysql,
"drop table if exists t1");
8480 rc= mysql_query(mysql,
"drop view if exists v1");
8483 rc= mysql_query(mysql,
"create table t1(f1 int)");
8486 rc= mysql_query(mysql,
"create view v1 as select va.* from t1 va");
8489 result= mysql_list_fields(mysql,
"v1", NULL);
8492 rc= my_process_result_set(result);
8493 DIE_UNLESS(rc == 0);
8495 verify_prepare_field(result, 0,
"f1",
"f1", MYSQL_TYPE_LONG,
8496 "v1",
"v1", current_db, 11,
"0");
8498 mysql_free_result(result);
8499 myquery(mysql_query(mysql,
"drop view v1"));
8500 myquery(mysql_query(mysql,
"drop table t1"));
8506 static void test_mem_overun()
8508 char buffer[10000], field[10];
8513 myheader(
"test_mem_overun");
8519 rc= mysql_query(mysql,
"drop table if exists t_mem_overun");
8522 strxmov(buffer,
"create table t_mem_overun(", NullS);
8523 for (i= 0; i < 1000; i++)
8525 sprintf(field,
"c%d int", i);
8526 strxmov(buffer, buffer, field,
", ", NullS);
8528 length= strlen(buffer);
8529 buffer[length-2]=
')';
8530 buffer[--length]=
'\0';
8532 rc= mysql_real_query(mysql, buffer, length);
8535 strxmov(buffer,
"insert into t_mem_overun values(", NullS);
8536 for (i= 0; i < 1000; i++)
8538 strxmov(buffer, buffer,
"1, ", NullS);
8540 length= strlen(buffer);
8541 buffer[length-2]=
')';
8542 buffer[--length]=
'\0';
8544 rc= mysql_real_query(mysql, buffer, length);
8547 rc= mysql_query(mysql,
"select * from t_mem_overun");
8550 rc= my_process_result(mysql);
8551 DIE_UNLESS(rc == 1);
8553 stmt= mysql_simple_prepare(mysql,
"select * from t_mem_overun");
8556 rc= mysql_stmt_execute(stmt);
8557 check_execute(stmt, rc);
8559 field_res= mysql_stmt_result_metadata(stmt);
8563 fprintf(stdout,
"\n total fields : %d", mysql_num_fields(field_res));
8564 DIE_UNLESS( 1000 == mysql_num_fields(field_res));
8566 rc= mysql_stmt_store_result(stmt);
8567 check_execute(stmt, rc);
8569 rc= mysql_stmt_fetch(stmt);
8570 check_execute(stmt, rc);
8572 rc= mysql_stmt_fetch(stmt);
8573 DIE_UNLESS(rc == MYSQL_NO_DATA);
8575 mysql_free_result(field_res);
8577 mysql_stmt_close(stmt);
8583 static void test_free_result()
8591 myheader(
"test_free_result");
8593 rc= mysql_query(mysql,
"drop table if exists test_free_result");
8596 rc= mysql_query(mysql,
"create table test_free_result("
8597 "c1 int primary key auto_increment)");
8600 rc= mysql_query(mysql,
"insert into test_free_result values(), (), ()");
8603 stmt= mysql_simple_prepare(mysql,
"select * from test_free_result");
8606 memset(my_bind, 0,
sizeof(my_bind));
8607 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
8608 my_bind[0].buffer= (
void *)&bc1;
8609 my_bind[0].length= &bl1;
8611 rc= mysql_stmt_execute(stmt);
8612 check_execute(stmt, rc);
8614 rc= mysql_stmt_bind_result(stmt, my_bind);
8615 check_execute(stmt, rc);
8617 rc= mysql_stmt_fetch(stmt);
8618 check_execute(stmt, rc);
8621 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
8622 my_bind[0].buffer= (
void *)c2;
8623 my_bind[0].buffer_length= 7;
8624 my_bind[0].is_null= 0;
8625 my_bind[0].length= &l2;
8627 rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0);
8628 check_execute(stmt, rc);
8630 fprintf(stdout,
"\n col 0: %s(%ld)", c2, l2);
8631 DIE_UNLESS(strncmp(c2,
"1", 1) == 0 && l2 == 1);
8633 rc= mysql_stmt_fetch(stmt);
8634 check_execute(stmt, rc);
8637 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
8638 my_bind[0].buffer= (
void *)&c1;
8639 my_bind[0].buffer_length= 0;
8640 my_bind[0].is_null= 0;
8641 my_bind[0].length= &l2;
8643 rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0);
8644 check_execute(stmt, rc);
8646 fprintf(stdout,
"\n col 0: %d(%ld)", c1, l2);
8647 DIE_UNLESS(c1 == 2 && l2 == 4);
8649 rc= mysql_query(mysql,
"drop table test_free_result");
8652 rc= mysql_stmt_free_result(stmt);
8653 check_execute(stmt, rc);
8655 rc= mysql_query(mysql,
"drop table test_free_result");
8658 mysql_stmt_close(stmt);
8664 static void test_free_store_result()
8672 myheader(
"test_free_store_result");
8674 rc= mysql_query(mysql,
"drop table if exists test_free_result");
8677 rc= mysql_query(mysql,
"create table test_free_result(c1 int primary key auto_increment)");
8680 rc= mysql_query(mysql,
"insert into test_free_result values(), (), ()");
8683 stmt= mysql_simple_prepare(mysql,
"select * from test_free_result");
8686 memset(my_bind, 0,
sizeof(my_bind));
8687 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
8688 my_bind[0].buffer= (
void *)&bc1;
8689 my_bind[0].buffer_length= 0;
8690 my_bind[0].is_null= 0;
8691 my_bind[0].length= &bl1;
8693 rc= mysql_stmt_execute(stmt);
8694 check_execute(stmt, rc);
8696 rc= mysql_stmt_bind_result(stmt, my_bind);
8697 check_execute(stmt, rc);
8699 rc= mysql_stmt_store_result(stmt);
8700 check_execute(stmt, rc);
8702 rc= mysql_stmt_fetch(stmt);
8703 check_execute(stmt, rc);
8706 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
8707 my_bind[0].buffer= (
void *)c2;
8708 my_bind[0].buffer_length= 7;
8709 my_bind[0].is_null= 0;
8710 my_bind[0].length= &l2;
8712 rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0);
8713 check_execute(stmt, rc);
8715 fprintf(stdout,
"\n col 1: %s(%ld)", c2, l2);
8716 DIE_UNLESS(strncmp(c2,
"1", 1) == 0 && l2 == 1);
8718 rc= mysql_stmt_fetch(stmt);
8719 check_execute(stmt, rc);
8722 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
8723 my_bind[0].buffer= (
void *)&c1;
8724 my_bind[0].buffer_length= 0;
8725 my_bind[0].is_null= 0;
8726 my_bind[0].length= &l2;
8728 rc= mysql_stmt_fetch_column(stmt, my_bind, 0, 0);
8729 check_execute(stmt, rc);
8731 fprintf(stdout,
"\n col 0: %d(%ld)", c1, l2);
8732 DIE_UNLESS(c1 == 2 && l2 == 4);
8734 rc= mysql_stmt_free_result(stmt);
8735 check_execute(stmt, rc);
8737 rc= mysql_query(mysql,
"drop table test_free_result");
8740 mysql_stmt_close(stmt);
8746 static void test_sqlmode()
8752 char query[MAX_TEST_QUERY_LENGTH];
8754 myheader(
"test_sqlmode");
8756 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_piping");
8759 rc= mysql_query(mysql,
"CREATE TABLE test_piping(name varchar(10))");
8763 strmov(query,
"SET SQL_MODE= \"PIPES_AS_CONCAT\"");
8765 fprintf(stdout,
"\n With %s", query);
8766 rc= mysql_query(mysql, query);
8769 strmov(query,
"INSERT INTO test_piping VALUES(?||?)");
8771 fprintf(stdout,
"\n query: %s", query);
8772 stmt= mysql_simple_prepare(mysql, query);
8776 fprintf(stdout,
"\n total parameters: %ld", mysql_stmt_param_count(stmt));
8782 memset(my_bind, 0,
sizeof(my_bind));
8784 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
8785 my_bind[0].buffer= (
void *)c1;
8786 my_bind[0].buffer_length= 2;
8788 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
8789 my_bind[1].buffer= (
void *)c2;
8790 my_bind[1].buffer_length= 3;
8792 rc= mysql_stmt_bind_param(stmt, my_bind);
8793 check_execute(stmt, rc);
8795 strmov(c1,
"My"); strmov(c2,
"SQL");
8796 rc= mysql_stmt_execute(stmt);
8797 check_execute(stmt, rc);
8798 mysql_stmt_close(stmt);
8800 verify_col_data(
"test_piping",
"name",
"MySQL");
8802 rc= mysql_query(mysql,
"DELETE FROM test_piping");
8805 strmov(query,
"SELECT connection_id ()");
8807 fprintf(stdout,
"\n query: %s", query);
8808 stmt= mysql_simple_prepare(mysql, query);
8810 mysql_stmt_close(stmt);
8813 strmov(query,
"SET SQL_MODE= \"ANSI\"");
8815 fprintf(stdout,
"\n With %s", query);
8816 rc= mysql_query(mysql, query);
8819 strmov(query,
"INSERT INTO test_piping VALUES(?||?)");
8821 fprintf(stdout,
"\n query: %s", query);
8822 stmt= mysql_simple_prepare(mysql, query);
8825 fprintf(stdout,
"\n total parameters: %ld", mysql_stmt_param_count(stmt));
8827 rc= mysql_stmt_bind_param(stmt, my_bind);
8828 check_execute(stmt, rc);
8830 strmov(c1,
"My"); strmov(c2,
"SQL");
8831 rc= mysql_stmt_execute(stmt);
8832 check_execute(stmt, rc);
8834 mysql_stmt_close(stmt);
8835 verify_col_data(
"test_piping",
"name",
"MySQL");
8838 strmov(query,
"SELECT connection_id ()");
8840 fprintf(stdout,
"\n query: %s", query);
8841 stmt= mysql_simple_prepare(mysql, query);
8844 rc= mysql_stmt_execute(stmt);
8845 check_execute(stmt, rc);
8847 rc= mysql_stmt_fetch(stmt);
8848 check_execute(stmt, rc);
8850 rc= mysql_stmt_fetch(stmt);
8851 DIE_UNLESS(rc == MYSQL_NO_DATA);
8853 fprintf(stdout,
"\n returned 1 row\n");
8855 mysql_stmt_close(stmt);
8858 strmov(query,
"SET SQL_MODE= \"IGNORE_SPACE\"");
8860 fprintf(stdout,
"\n With %s", query);
8861 rc= mysql_query(mysql, query);
8864 strmov(query,
"SELECT connection_id ()");
8866 fprintf(stdout,
"\n query: %s", query);
8867 stmt= mysql_simple_prepare(mysql, query);
8870 rc= mysql_stmt_execute(stmt);
8871 check_execute(stmt, rc);
8873 rc= mysql_stmt_fetch(stmt);
8874 check_execute(stmt, rc);
8876 rc= mysql_stmt_fetch(stmt);
8877 DIE_UNLESS(rc == MYSQL_NO_DATA);
8879 fprintf(stdout,
"\n returned 1 row");
8881 mysql_stmt_close(stmt);
8887 static void test_ts()
8895 int rc, field_count;
8897 char query[MAX_TEST_QUERY_LENGTH];
8898 const char *queries [3]= {
"SELECT a, b, c FROM test_ts WHERE %c=?",
8899 "SELECT a, b, c FROM test_ts WHERE %c=?",
8900 "SELECT a, b, c FROM test_ts WHERE %c=CAST(? AS DATE)"};
8901 myheader(
"test_ts");
8903 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_ts");
8906 rc= mysql_query(mysql,
"CREATE TABLE test_ts(a DATE, b TIME, c TIMESTAMP)");
8909 stmt= mysql_simple_prepare(mysql,
"INSERT INTO test_ts VALUES(?, ?, ?), (?, ?, ?)");
8919 length= (long)(strmov(strts,
"2003-07-12 21:07:46") - strts);
8925 memset(my_bind, 0,
sizeof(my_bind));
8927 my_bind[0].buffer_type= MYSQL_TYPE_TIMESTAMP;
8928 my_bind[0].buffer= (
void *)&ts;
8929 my_bind[0].buffer_length=
sizeof(ts);
8931 my_bind[2]= my_bind[1]= my_bind[0];
8933 my_bind[3].buffer_type= MYSQL_TYPE_STRING;
8934 my_bind[3].buffer= (
void *)strts;
8935 my_bind[3].buffer_length=
sizeof(strts);
8936 my_bind[3].length= &length;
8938 my_bind[5]= my_bind[4]= my_bind[3];
8940 rc= mysql_stmt_bind_param(stmt, my_bind);
8941 check_execute(stmt, rc);
8943 rc= mysql_stmt_execute(stmt);
8944 check_execute(stmt, rc);
8946 mysql_stmt_close(stmt);
8948 verify_col_data(
"test_ts",
"a",
"2003-07-12");
8949 verify_col_data(
"test_ts",
"b",
"21:07:46");
8950 verify_col_data(
"test_ts",
"c",
"2003-07-12 21:07:46");
8952 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM test_ts");
8955 prep_res= mysql_stmt_result_metadata(stmt);
8958 rc= mysql_stmt_execute(stmt);
8959 check_execute(stmt, rc);
8961 rc= my_process_stmt_result(stmt);
8962 DIE_UNLESS(rc == 2);
8963 field_count= mysql_num_fields(prep_res);
8965 mysql_free_result(prep_res);
8966 mysql_stmt_close(stmt);
8968 for (name=
'a'; field_count--; name++)
8972 sprintf(query, queries[field_count], name);
8975 fprintf(stdout,
"\n %s", query);
8976 stmt= mysql_simple_prepare(mysql, query);
8979 rc= mysql_stmt_bind_param(stmt, my_bind);
8980 check_execute(stmt, rc);
8982 rc= mysql_stmt_execute(stmt);
8983 check_execute(stmt, rc);
8985 while (mysql_stmt_fetch(stmt) == 0)
8989 fprintf(stdout,
"\n returned '%d' rows", row_count);
8990 DIE_UNLESS(row_count == 2);
8991 mysql_stmt_close(stmt);
8998 static void test_bug1500()
9003 int32 int_data[3]= {2, 3, 4};
9006 myheader(
"test_bug1500");
9008 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bg1500");
9011 rc= mysql_query(mysql,
"CREATE TABLE test_bg1500 (i INT)");
9014 rc= mysql_query(mysql,
"INSERT INTO test_bg1500 VALUES (1), (2)");
9017 rc= mysql_commit(mysql);
9020 stmt= mysql_simple_prepare(mysql,
"SELECT i FROM test_bg1500 WHERE i IN (?, ?, ?)");
9022 verify_param_count(stmt, 3);
9028 memset(my_bind, 0,
sizeof(my_bind));
9030 my_bind[0].buffer= (
void *)int_data;
9031 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
9032 my_bind[2]= my_bind[1]= my_bind[0];
9033 my_bind[1].buffer= (
void *)(int_data + 1);
9034 my_bind[2].buffer= (
void *)(int_data + 2);
9036 rc= mysql_stmt_bind_param(stmt, my_bind);
9037 check_execute(stmt, rc);
9039 rc= mysql_stmt_execute(stmt);
9040 check_execute(stmt, rc);
9042 rc= my_process_stmt_result(stmt);
9043 DIE_UNLESS(rc == 1);
9045 mysql_stmt_close(stmt);
9047 rc= mysql_query(mysql,
"DROP TABLE test_bg1500");
9050 rc= mysql_query(mysql,
"CREATE TABLE test_bg1500 (s VARCHAR(25), FULLTEXT(s)) engine=MyISAM");
9053 rc= mysql_query(mysql,
9054 "INSERT INTO test_bg1500 VALUES ('Gravedigger'), ('Greed'), ('Hollow Dogs')");
9057 rc= mysql_commit(mysql);
9060 stmt= mysql_simple_prepare(mysql,
9061 "SELECT s FROM test_bg1500 WHERE MATCH (s) AGAINST (?)");
9064 verify_param_count(stmt, 1);
9067 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
9068 my_bind[0].buffer= (
void *) data;
9069 my_bind[0].buffer_length= strlen(data);
9070 my_bind[0].is_null= 0;
9071 my_bind[0].length= 0;
9073 rc= mysql_stmt_bind_param(stmt, my_bind);
9074 check_execute(stmt, rc);
9076 rc= mysql_stmt_execute(stmt);
9077 check_execute(stmt, rc);
9079 rc= my_process_stmt_result(stmt);
9080 DIE_UNLESS(rc == 1);
9082 mysql_stmt_close(stmt);
9085 stmt= mysql_simple_prepare(mysql,
9086 "SELECT s FROM test_bg1500 WHERE MATCH (s) AGAINST (CONCAT(?, 'digger'))");
9089 verify_param_count(stmt, 1);
9092 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
9093 my_bind[0].buffer= (
void *) data;
9094 my_bind[0].buffer_length= strlen(data);
9096 rc= mysql_stmt_bind_param(stmt, my_bind);
9097 check_execute(stmt, rc);
9099 rc= mysql_stmt_execute(stmt);
9100 check_execute(stmt, rc);
9102 rc= my_process_stmt_result(stmt);
9103 DIE_UNLESS(rc == 1);
9105 mysql_stmt_close(stmt);
9109 static void test_bug1946()
9113 const char *query=
"INSERT INTO prepare_command VALUES (?)";
9115 myheader(
"test_bug1946");
9117 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS prepare_command");
9120 rc= mysql_query(mysql,
"CREATE TABLE prepare_command(ID INT)");
9123 stmt= mysql_simple_prepare(mysql, query);
9125 rc= mysql_real_query(mysql, query, strlen(query));
9126 DIE_UNLESS(rc != 0);
9128 fprintf(stdout,
"Got error (as expected):\n");
9131 mysql_stmt_close(stmt);
9132 rc= mysql_query(mysql,
"DROP TABLE prepare_command");
9136 static void test_parse_error_and_bad_length()
9142 myheader(
"test_parse_error_and_bad_length");
9144 rc= mysql_query(mysql,
"SHOW DATABAAAA");
9147 fprintf(stdout,
"Got error (as expected): '%s'\n", mysql_error(mysql));
9148 rc= mysql_real_query(mysql,
"SHOW DATABASES", 12);
9151 fprintf(stdout,
"Got error (as expected): '%s'\n", mysql_error(mysql));
9153 stmt= mysql_simple_prepare(mysql,
"SHOW DATABAAAA");
9156 fprintf(stdout,
"Got error (as expected): '%s'\n", mysql_error(mysql));
9157 stmt= mysql_stmt_init(mysql);
9159 rc= mysql_stmt_prepare(stmt,
"SHOW DATABASES", 12);
9160 DIE_UNLESS(rc != 0);
9162 fprintf(stdout,
"Got error (as expected): '%s'\n", mysql_stmt_error(stmt));
9163 mysql_stmt_close(stmt);
9167 static void test_bug2247()
9173 const char *create=
"CREATE TABLE bug2247(id INT UNIQUE AUTO_INCREMENT)";
9174 const char *insert=
"INSERT INTO bug2247 VALUES (NULL)";
9175 const char *SELECT=
"SELECT id FROM bug2247";
9176 const char *update=
"UPDATE bug2247 SET id=id+10";
9177 const char *drop=
"DROP TABLE IF EXISTS bug2247";
9178 ulonglong exp_count;
9179 enum { NUM_ROWS= 5 };
9181 myheader(
"test_bug2247");
9184 fprintf(stdout,
"\nChecking if stmt_affected_rows is not affected by\n"
9185 "mysql_query ... ");
9187 rc= mysql_query(mysql, drop);
9190 rc= mysql_query(mysql, create);
9193 stmt= mysql_simple_prepare(mysql, insert);
9195 for (i= 0; i < NUM_ROWS; ++
i)
9197 rc= mysql_stmt_execute(stmt);
9198 check_execute(stmt, rc);
9200 exp_count= mysql_stmt_affected_rows(stmt);
9201 DIE_UNLESS(exp_count == 1);
9203 rc= mysql_query(mysql, SELECT);
9210 res= mysql_store_result(mysql);
9213 DIE_UNLESS(mysql_affected_rows(mysql) == NUM_ROWS);
9214 DIE_UNLESS(exp_count == mysql_stmt_affected_rows(stmt));
9216 rc= mysql_query(mysql, update);
9218 DIE_UNLESS(mysql_affected_rows(mysql) == NUM_ROWS);
9219 DIE_UNLESS(exp_count == mysql_stmt_affected_rows(stmt));
9221 mysql_free_result(res);
9222 mysql_stmt_close(stmt);
9225 stmt= mysql_simple_prepare(mysql, SELECT);
9228 rc= mysql_stmt_execute(stmt);
9229 check_execute(stmt, rc);
9230 rc= mysql_stmt_store_result(stmt);
9231 check_execute(stmt, rc);
9232 exp_count= mysql_stmt_affected_rows(stmt);
9233 DIE_UNLESS(exp_count == NUM_ROWS);
9235 rc= mysql_query(mysql, insert);
9237 DIE_UNLESS(mysql_affected_rows(mysql) == 1);
9238 DIE_UNLESS(mysql_stmt_affected_rows(stmt) == exp_count);
9240 mysql_stmt_close(stmt);
9242 fprintf(stdout,
"OK");
9246 static void test_subqueries()
9250 const char *query=
"SELECT (SELECT SUM(a+b) FROM t2 where t1.b=t2.b GROUP BY t1.a LIMIT 1) as scalar_s, exists (select 1 from t2 where t2.a/2=t1.a) as exists_s, a in (select a+3 from t2) as in_s, (a-1, b-1) in (select a, b from t2) as in_row_s FROM t1, (select a x, b y from t2) tt WHERE x=a";
9252 myheader(
"test_subqueries");
9254 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1, t2");
9257 rc= mysql_query(mysql,
"CREATE TABLE t1 (a int , b int);");
9260 rc= mysql_query(mysql,
9261 "insert into t1 values (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);");
9264 rc= mysql_query(mysql,
"create table t2 select * from t1;");
9267 stmt= mysql_simple_prepare(mysql, query);
9269 for (i= 0; i < 3; i++)
9271 rc= mysql_stmt_execute(stmt);
9272 check_execute(stmt, rc);
9273 rc= my_process_stmt_result(stmt);
9274 DIE_UNLESS(rc == 5);
9276 mysql_stmt_close(stmt);
9278 rc= mysql_query(mysql,
"DROP TABLE t1, t2");
9283 static void test_bad_union()
9286 const char *query=
"SELECT 1, 2 union SELECT 1";
9288 myheader(
"test_bad_union");
9290 stmt= mysql_simple_prepare(mysql, query);
9291 DIE_UNLESS(stmt == 0);
9296 static void test_distinct()
9301 "SELECT 2+count(distinct b), group_concat(a) FROM t1 group by a";
9303 myheader(
"test_distinct");
9305 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
9308 rc= mysql_query(mysql,
"CREATE TABLE t1 (a int , b int);");
9311 rc= mysql_query(mysql,
9312 "insert into t1 values (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), \
9313 (1, 10), (2, 20), (3, 30), (4, 40), (5, 50);");
9316 for (i= 0; i < 3; i++)
9318 stmt= mysql_simple_prepare(mysql, query);
9320 rc= mysql_stmt_execute(stmt);
9321 check_execute(stmt, rc);
9322 rc= my_process_stmt_result(stmt);
9323 DIE_UNLESS(rc == 5);
9324 mysql_stmt_close(stmt);
9327 rc= mysql_query(mysql,
"DROP TABLE t1");
9336 static void test_bug2248()
9340 const char *query1=
"SELECT DATABASE()";
9341 const char *query2=
"INSERT INTO test_bug2248 VALUES (10)";
9343 myheader(
"test_bug2248");
9345 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_bug2248");
9348 rc= mysql_query(mysql,
"CREATE TABLE test_bug2248 (id int)");
9351 stmt= mysql_simple_prepare(mysql, query1);
9355 rc= mysql_stmt_fetch(stmt);
9356 check_execute_r(stmt, rc);
9359 rc= mysql_stmt_store_result(stmt);
9360 check_execute_r(stmt, rc);
9362 mysql_stmt_close(stmt);
9364 stmt= mysql_simple_prepare(mysql, query2);
9367 rc= mysql_stmt_execute(stmt);
9368 check_execute(stmt, rc);
9371 rc= mysql_stmt_fetch(stmt);
9372 DIE_UNLESS(rc == 1);
9375 rc= mysql_stmt_store_result(stmt);
9376 check_execute(stmt, rc);
9379 rc= mysql_stmt_fetch(stmt);
9380 check_execute_r(stmt, rc);
9381 DIE_UNLESS(rc == 1);
9383 mysql_stmt_close(stmt);
9385 rc= mysql_query(mysql,
"DROP TABLE test_bug2248");
9390 static void test_subqueries_ref()
9394 const char *query=
"SELECT a as ccc from t1 outr where a+1=(SELECT 1+outr.a from t1 where outr.a+1=a+1 and a=1)";
9396 myheader(
"test_subqueries_ref");
9398 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
9401 rc= mysql_query(mysql,
"CREATE TABLE t1 (a int);");
9404 rc= mysql_query(mysql,
9405 "insert into t1 values (1), (2), (3), (4), (5);");
9408 stmt= mysql_simple_prepare(mysql, query);
9410 for (i= 0; i < 3; i++)
9412 rc= mysql_stmt_execute(stmt);
9413 check_execute(stmt, rc);
9414 rc= my_process_stmt_result(stmt);
9415 DIE_UNLESS(rc == 1);
9417 mysql_stmt_close(stmt);
9419 rc= mysql_query(mysql,
"DROP TABLE t1");
9424 static void test_union()
9429 myheader(
"test_union");
9431 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1, t2");
9434 rc= mysql_query(mysql,
9436 "(id INTEGER NOT NULL PRIMARY KEY, "
9437 " name VARCHAR(20) NOT NULL)");
9439 rc= mysql_query(mysql,
9440 "INSERT INTO t1 (id, name) VALUES "
9441 "(2, 'Ja'), (3, 'Ede'), "
9442 "(4, 'Haag'), (5, 'Kabul'), "
9443 "(6, 'Almere'), (7, 'Utrecht'), "
9444 "(8, 'Qandahar'), (9, 'Amsterdam'), "
9445 "(10, 'Amersfoort'), (11, 'Constantine')");
9447 rc= mysql_query(mysql,
9449 "(id INTEGER NOT NULL PRIMARY KEY, "
9450 " name VARCHAR(20) NOT NULL)");
9452 rc= mysql_query(mysql,
9453 "INSERT INTO t2 (id, name) VALUES "
9454 "(4, 'Guam'), (5, 'Aruba'), "
9455 "(6, 'Angola'), (7, 'Albania'), "
9456 "(8, 'Anguilla'), (9, 'Argentina'), "
9457 "(10, 'Azerbaijan'), (11, 'Afghanistan'), "
9458 "(12, 'Burkina Faso'), (13, 'Faroe Islands')");
9461 stmt= mysql_simple_prepare(mysql,
9462 "SELECT t1.name FROM t1 UNION "
9463 "SELECT t2.name FROM t2");
9466 rc= mysql_stmt_execute(stmt);
9467 check_execute(stmt, rc);
9468 rc= my_process_stmt_result(stmt);
9469 DIE_UNLESS(rc == 20);
9470 mysql_stmt_close(stmt);
9472 rc= mysql_query(mysql,
"DROP TABLE t1, t2");
9477 static void test_bug3117()
9486 myheader(
"test_bug3117");
9488 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
9491 rc= mysql_query(mysql,
"CREATE TABLE t1 (id int auto_increment primary key)");
9494 stmt= mysql_simple_prepare(mysql,
"SELECT LAST_INSERT_ID()");
9497 rc= mysql_query(mysql,
"INSERT INTO t1 VALUES (NULL)");
9500 rc= mysql_stmt_execute(stmt);
9501 check_execute(stmt, rc);
9503 memset(&buffer, 0,
sizeof(buffer));
9504 buffer.buffer_type= MYSQL_TYPE_LONGLONG;
9505 buffer.buffer_length=
sizeof(lii);
9506 buffer.buffer= (
void *)&lii;
9507 buffer.length= &length;
9508 buffer.is_null= &is_null;
9510 rc= mysql_stmt_bind_result(stmt, &buffer);
9511 check_execute(stmt, rc);
9513 rc= mysql_stmt_store_result(stmt);
9514 check_execute(stmt, rc);
9516 rc= mysql_stmt_fetch(stmt);
9517 check_execute(stmt, rc);
9519 DIE_UNLESS(is_null == 0 && lii == 1);
9521 fprintf(stdout,
"\n\tLAST_INSERT_ID()= 1 ok\n");
9523 rc= mysql_query(mysql,
"INSERT INTO t1 VALUES (NULL)");
9526 rc= mysql_stmt_execute(stmt);
9527 check_execute(stmt, rc);
9529 rc= mysql_stmt_fetch(stmt);
9530 check_execute(stmt, rc);
9532 DIE_UNLESS(is_null == 0 && lii == 2);
9534 fprintf(stdout,
"\tLAST_INSERT_ID()= 2 ok\n");
9536 mysql_stmt_close(stmt);
9538 rc= mysql_query(mysql,
"DROP TABLE t1");
9543 static void test_join()
9547 const char *query[]= {
"SELECT * FROM t2 join t1 on (t1.a=t2.a)",
9548 "SELECT * FROM t2 natural join t1",
9549 "SELECT * FROM t2 join t1 using(a)",
9550 "SELECT * FROM t2 left join t1 on(t1.a=t2.a)",
9551 "SELECT * FROM t2 natural left join t1",
9552 "SELECT * FROM t2 left join t1 using(a)",
9553 "SELECT * FROM t2 right join t1 on(t1.a=t2.a)",
9554 "SELECT * FROM t2 natural right join t1",
9555 "SELECT * FROM t2 right join t1 using(a)"};
9557 myheader(
"test_join");
9559 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1, t2");
9562 rc= mysql_query(mysql,
"CREATE TABLE t1 (a int , b int);");
9565 rc= mysql_query(mysql,
9566 "insert into t1 values (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);");
9569 rc= mysql_query(mysql,
"CREATE TABLE t2 (a int , c int);");
9572 rc= mysql_query(mysql,
9573 "insert into t2 values (1, 1), (2, 2), (3, 3), (4, 4), (5, 5);");
9576 for (j= 0; j < 9; j++)
9578 stmt= mysql_simple_prepare(mysql, query[j]);
9580 for (i= 0; i < 3; i++)
9582 rc= mysql_stmt_execute(stmt);
9583 check_execute(stmt, rc);
9584 rc= my_process_stmt_result(stmt);
9585 DIE_UNLESS(rc == 5);
9587 mysql_stmt_close(stmt);
9590 rc= mysql_query(mysql,
"DROP TABLE t1, t2");
9595 static void test_selecttmp()
9599 const char *query=
"select a, (select count(distinct t1.b) as sum from t1, t2 where t1.a=t2.a and t2.b > 0 and t1.a <= t3.b group by t1.a order by sum limit 1) from t3";
9601 myheader(
"test_select_tmp");
9603 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1, t2, t3");
9606 rc= mysql_query(mysql,
"CREATE TABLE t1 (a int , b int);");
9609 rc= mysql_query(mysql,
"create table t2 (a int, b int);");
9612 rc= mysql_query(mysql,
"create table t3 (a int, b int);");
9615 rc= mysql_query(mysql,
9616 "insert into t1 values (0, 100), (1, 2), (1, 3), (2, 2), (2, 7), \
9617 (2, -1), (3, 10);");
9619 rc= mysql_query(mysql,
9620 "insert into t2 values (0, 0), (1, 1), (2, 1), (3, 1), (4, 1);");
9622 rc= mysql_query(mysql,
9623 "insert into t3 values (3, 3), (2, 2), (1, 1);");
9626 stmt= mysql_simple_prepare(mysql, query);
9628 for (i= 0; i < 3; i++)
9630 rc= mysql_stmt_execute(stmt);
9631 check_execute(stmt, rc);
9632 rc= my_process_stmt_result(stmt);
9633 DIE_UNLESS(rc == 3);
9635 mysql_stmt_close(stmt);
9637 rc= mysql_query(mysql,
"DROP TABLE t1, t2, t3");
9642 static void test_create_drop()
9644 MYSQL_STMT *stmt_create, *stmt_drop, *stmt_select, *stmt_create_select;
9647 myheader(
"test_table_manipulation");
9649 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1, t2");
9652 rc= mysql_query(mysql,
"create table t2 (a int);");
9655 rc= mysql_query(mysql,
"create table t1 (a int);");
9658 rc= mysql_query(mysql,
"insert into t2 values (3), (2), (1);");
9661 query= (
char*)
"create table t1 (a int)";
9662 stmt_create= mysql_simple_prepare(mysql, query);
9663 check_stmt(stmt_create);
9665 query= (
char*)
"drop table t1";
9666 stmt_drop= mysql_simple_prepare(mysql, query);
9667 check_stmt(stmt_drop);
9669 query= (
char*)
"select a in (select a from t2) from t1";
9670 stmt_select= mysql_simple_prepare(mysql, query);
9671 check_stmt(stmt_select);
9673 rc= mysql_query(mysql,
"DROP TABLE t1");
9676 query= (
char*)
"create table t1 select a from t2";
9677 stmt_create_select= mysql_simple_prepare(mysql, query);
9678 check_stmt(stmt_create_select);
9680 for (i= 0; i < 3; i++)
9682 rc= mysql_stmt_execute(stmt_create);
9683 check_execute(stmt_create, rc);
9685 fprintf(stdout,
"created %i\n", i);
9687 rc= mysql_stmt_execute(stmt_select);
9688 check_execute(stmt_select, rc);
9689 rc= my_process_stmt_result(stmt_select);
9690 DIE_UNLESS(rc == 0);
9692 rc= mysql_stmt_execute(stmt_drop);
9693 check_execute(stmt_drop, rc);
9695 fprintf(stdout,
"dropped %i\n", i);
9697 rc= mysql_stmt_execute(stmt_create_select);
9698 check_execute(stmt_create, rc);
9700 fprintf(stdout,
"created select %i\n", i);
9702 rc= mysql_stmt_execute(stmt_select);
9703 check_execute(stmt_select, rc);
9704 rc= my_process_stmt_result(stmt_select);
9705 DIE_UNLESS(rc == 3);
9707 rc= mysql_stmt_execute(stmt_drop);
9708 check_execute(stmt_drop, rc);
9710 fprintf(stdout,
"dropped %i\n", i);
9713 mysql_stmt_close(stmt_create);
9714 mysql_stmt_close(stmt_drop);
9715 mysql_stmt_close(stmt_select);
9716 mysql_stmt_close(stmt_create_select);
9718 rc= mysql_query(mysql,
"DROP TABLE t2");
9723 static void test_rename()
9726 const char *query=
"rename table t1 to t2, t3 to t4";
9728 myheader(
"test_table_rename");
9730 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1, t2, t3, t4");
9733 stmt= mysql_simple_prepare(mysql, query);
9736 rc= mysql_query(mysql,
"create table t1 (a int)");
9739 rc= mysql_stmt_execute(stmt);
9740 check_execute_r(stmt, rc);
9742 fprintf(stdout,
"rename without t3\n");
9744 rc= mysql_query(mysql,
"create table t3 (a int)");
9747 rc= mysql_stmt_execute(stmt);
9748 check_execute(stmt, rc);
9750 fprintf(stdout,
"rename with t3\n");
9752 rc= mysql_stmt_execute(stmt);
9753 check_execute_r(stmt, rc);
9755 fprintf(stdout,
"rename renamed\n");
9757 rc= mysql_query(mysql,
"rename table t2 to t1, t4 to t3");
9760 rc= mysql_stmt_execute(stmt);
9761 check_execute(stmt, rc);
9763 fprintf(stdout,
"rename reverted\n");
9765 mysql_stmt_close(stmt);
9767 rc= mysql_query(mysql,
"DROP TABLE t2, t4");
9772 static void test_do_set()
9777 myheader(
"test_do_set");
9779 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
9782 rc= mysql_query(mysql,
"create table t1 (a int)");
9785 query= (
char*)
"do @var:=(1 in (select * from t1))";
9786 stmt_do= mysql_simple_prepare(mysql, query);
9787 check_stmt(stmt_do);
9789 query= (
char*)
"set @var=(1 in (select * from t1))";
9790 stmt_set= mysql_simple_prepare(mysql, query);
9791 check_stmt(stmt_set);
9793 for (i= 0; i < 3; i++)
9795 rc= mysql_stmt_execute(stmt_do);
9796 check_execute(stmt_do, rc);
9798 fprintf(stdout,
"do %i\n", i);
9799 rc= mysql_stmt_execute(stmt_set);
9800 check_execute(stmt_set, rc);
9802 fprintf(stdout,
"set %i\n", i);
9805 mysql_stmt_close(stmt_do);
9806 mysql_stmt_close(stmt_set);
9810 static void test_multi()
9812 MYSQL_STMT *stmt_delete, *stmt_update, *stmt_select1, *stmt_select2;
9818 myheader(
"test_multi");
9824 memset(my_bind, 0,
sizeof(my_bind));
9826 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
9827 my_bind[0].buffer= (
void *)¶m;
9828 my_bind[0].length= &length;
9830 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1, t2");
9833 rc= mysql_query(mysql,
"create table t1 (a int, b int)");
9836 rc= mysql_query(mysql,
"create table t2 (a int, b int)");
9839 rc= mysql_query(mysql,
"insert into t1 values (3, 3), (2, 2), (1, 1)");
9842 rc= mysql_query(mysql,
"insert into t2 values (3, 3), (2, 2), (1, 1)");
9845 query= (
char*)
"delete t1, t2 from t1, t2 where t1.a=t2.a and t1.b=10";
9846 stmt_delete= mysql_simple_prepare(mysql, query);
9847 check_stmt(stmt_delete);
9849 query= (
char*)
"update t1, t2 set t1.b=10, t2.b=10 where t1.a=t2.a and t1.b=?";
9850 stmt_update= mysql_simple_prepare(mysql, query);
9851 check_stmt(stmt_update);
9853 query= (
char*)
"select * from t1";
9854 stmt_select1= mysql_simple_prepare(mysql, query);
9855 check_stmt(stmt_select1);
9857 query= (
char*)
"select * from t2";
9858 stmt_select2= mysql_simple_prepare(mysql, query);
9859 check_stmt(stmt_select2);
9861 for(i= 0; i < 3; i++)
9863 rc= mysql_stmt_bind_param(stmt_update, my_bind);
9864 check_execute(stmt_update, rc);
9866 rc= mysql_stmt_execute(stmt_update);
9867 check_execute(stmt_update, rc);
9869 fprintf(stdout,
"update %ld\n", (
long) param);
9871 rc= mysql_stmt_execute(stmt_delete);
9872 check_execute(stmt_delete, rc);
9874 fprintf(stdout,
"delete %ld\n", (
long) param);
9876 rc= mysql_stmt_execute(stmt_select1);
9877 check_execute(stmt_select1, rc);
9878 rc= my_process_stmt_result(stmt_select1);
9879 DIE_UNLESS(rc == 3-param);
9881 rc= mysql_stmt_execute(stmt_select2);
9882 check_execute(stmt_select2, rc);
9883 rc= my_process_stmt_result(stmt_select2);
9884 DIE_UNLESS(rc == 3-param);
9889 mysql_stmt_close(stmt_delete);
9890 mysql_stmt_close(stmt_update);
9891 mysql_stmt_close(stmt_select1);
9892 mysql_stmt_close(stmt_select2);
9893 rc= mysql_query(mysql,
"drop table t1, t2");
9898 static void test_insert_select()
9904 myheader(
"test_insert_select");
9906 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1, t2");
9909 rc= mysql_query(mysql,
"create table t1 (a int)");
9912 rc= mysql_query(mysql,
"create table t2 (a int)");
9915 rc= mysql_query(mysql,
"insert into t2 values (1)");
9918 query= (
char*)
"insert into t1 select a from t2";
9919 stmt_insert= mysql_simple_prepare(mysql, query);
9920 check_stmt(stmt_insert);
9922 query= (
char*)
"select * from t1";
9923 stmt_select= mysql_simple_prepare(mysql, query);
9924 check_stmt(stmt_select);
9926 for(i= 0; i < 3; i++)
9928 rc= mysql_stmt_execute(stmt_insert);
9929 check_execute(stmt_insert, rc);
9931 fprintf(stdout,
"insert %u\n", i);
9933 rc= mysql_stmt_execute(stmt_select);
9934 check_execute(stmt_select, rc);
9935 rc= my_process_stmt_result(stmt_select);
9936 DIE_UNLESS(rc == (
int)(i+1));
9939 mysql_stmt_close(stmt_insert);
9940 mysql_stmt_close(stmt_select);
9941 rc= mysql_query(mysql,
"drop table t1, t2");
9946 static void test_bind_nagative()
9953 ulong my_length= 0L;
9954 my_bool my_null= FALSE;
9955 myheader(
"test_insert_select");
9957 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
9960 rc= mysql_query(mysql,
"create temporary table t1 (c1 int unsigned)");
9963 rc= mysql_query(mysql,
"INSERT INTO t1 VALUES (1), (-1)");
9966 query= (
char*)
"INSERT INTO t1 VALUES (?)";
9967 stmt_insert= mysql_simple_prepare(mysql, query);
9968 check_stmt(stmt_insert);
9971 memset(my_bind, 0,
sizeof(my_bind));
9973 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
9974 my_bind[0].buffer= (
void *)&my_val;
9975 my_bind[0].length= &my_length;
9976 my_bind[0].is_null= (
char*)&my_null;
9978 rc= mysql_stmt_bind_param(stmt_insert, my_bind);
9979 check_execute(stmt_insert, rc);
9982 rc= mysql_stmt_execute(stmt_insert);
9983 check_execute(stmt_insert, rc);
9985 mysql_stmt_close(stmt_insert);
9986 rc= mysql_query(mysql,
"drop table t1");
9991 static void test_derived()
9997 ulong my_length= 0L;
9998 my_bool my_null= FALSE;
10000 "select count(1) from (select f.id from t1 f where f.id=?) as x";
10002 myheader(
"test_derived");
10004 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
10007 rc= mysql_query(mysql,
"create table t1 (id int(8), primary key (id)) \
10008 ENGINE=InnoDB DEFAULT CHARSET=utf8");
10011 rc= mysql_query(mysql,
"insert into t1 values (1)");
10014 stmt= mysql_simple_prepare(mysql, query);
10020 memset(my_bind, 0,
sizeof(my_bind));
10022 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
10023 my_bind[0].buffer= (
void *)&my_val;
10024 my_bind[0].length= &my_length;
10025 my_bind[0].is_null= (
char*)&my_null;
10027 rc= mysql_stmt_bind_param(stmt, my_bind);
10028 check_execute(stmt, rc);
10030 for (i= 0; i < 3; i++)
10032 rc= mysql_stmt_execute(stmt);
10033 check_execute(stmt, rc);
10034 rc= my_process_stmt_result(stmt);
10035 DIE_UNLESS(rc == 1);
10037 mysql_stmt_close(stmt);
10039 rc= mysql_query(mysql,
"DROP TABLE t1");
10044 static void test_xjoin()
10049 "select t.id, p1.value, n1.value, p2.value, n2.value from t3 t LEFT JOIN t1 p1 ON (p1.id=t.param1_id) LEFT JOIN t2 p2 ON (p2.id=t.param2_id) LEFT JOIN t4 n1 ON (n1.id=p1.name_id) LEFT JOIN t4 n2 ON (n2.id=p2.name_id) where t.id=1";
10051 myheader(
"test_xjoin");
10053 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1, t2, t3, t4");
10056 rc= mysql_query(mysql,
"create table t3 (id int(8), param1_id int(8), param2_id int(8)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
10059 rc= mysql_query(mysql,
"create table t1 ( id int(8), name_id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
10062 rc= mysql_query(mysql,
"create table t2 (id int(8), name_id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
10065 rc= mysql_query(mysql,
"create table t4(id int(8), value varchar(10)) ENGINE=InnoDB DEFAULT CHARSET=utf8");
10068 rc= mysql_query(mysql,
"insert into t3 values (1, 1, 1), (2, 2, null)");
10071 rc= mysql_query(mysql,
"insert into t1 values (1, 1, 'aaa'), (2, null, 'bbb')");
10074 rc= mysql_query(mysql,
"insert into t2 values (1, 2, 'ccc')");
10077 rc= mysql_query(mysql,
"insert into t4 values (1, 'Name1'), (2, null)");
10080 stmt= mysql_simple_prepare(mysql, query);
10083 for (i= 0; i < 3; i++)
10085 rc= mysql_stmt_execute(stmt);
10086 check_execute(stmt, rc);
10087 rc= my_process_stmt_result(stmt);
10088 DIE_UNLESS(rc == 1);
10090 mysql_stmt_close(stmt);
10092 rc= mysql_query(mysql,
"DROP TABLE t1, t2, t3, t4");
10097 static void test_bug3035()
10101 MYSQL_BIND bind_array[12], *my_bind= bind_array, *bind_end= my_bind + 12;
10108 longlong int64_val;
10109 ulonglong uint64_val;
10110 double double_val, udouble_val, double_tmp;
10111 char longlong_as_string[22], ulonglong_as_string[22];
10114 const int8 int8_min= -128;
10115 const int8 int8_max= 127;
10116 const uint8 uint8_min= 0;
10117 const uint8 uint8_max= 255;
10119 const int16 int16_min= -32768;
10120 const int16 int16_max= 32767;
10121 const uint16 uint16_min= 0;
10122 const uint16 uint16_max= 65535;
10124 const int32 int32_max= 2147483647L;
10125 const int32 int32_min= -int32_max - 1;
10126 const uint32 uint32_min= 0;
10127 const uint32 uint32_max= 4294967295
U;
10130 const longlong int64_max= LL(9223372036854775807);
10131 const longlong int64_min= -int64_max - 1;
10133 const ulonglong uint64_min= 0
U;
10134 const ulonglong uint64_max= ULL(18446744073709551615);
10136 const char *stmt_text;
10138 myheader(
"test_bug3035");
10140 stmt_text=
"DROP TABLE IF EXISTS t1";
10141 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10144 stmt_text=
"CREATE TABLE t1 (i8 TINYINT, ui8 TINYINT UNSIGNED, "
10145 "i16 SMALLINT, ui16 SMALLINT UNSIGNED, "
10146 "i32 INT, ui32 INT UNSIGNED, "
10147 "i64 BIGINT, ui64 BIGINT UNSIGNED, "
10148 "id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT)";
10149 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10152 memset(bind_array, 0,
sizeof(bind_array));
10154 for (my_bind= bind_array; my_bind < bind_end; my_bind++)
10155 my_bind->error= &my_bind->error_value;
10157 bind_array[0].buffer_type= MYSQL_TYPE_TINY;
10158 bind_array[0].buffer= (
void *) &int8_val;
10160 bind_array[1].buffer_type= MYSQL_TYPE_TINY;
10161 bind_array[1].buffer= (
void *) &uint8_val;
10162 bind_array[1].is_unsigned= 1;
10164 bind_array[2].buffer_type= MYSQL_TYPE_SHORT;
10165 bind_array[2].buffer= (
void *) &int16_val;
10167 bind_array[3].buffer_type= MYSQL_TYPE_SHORT;
10168 bind_array[3].buffer= (
void *) &uint16_val;
10169 bind_array[3].is_unsigned= 1;
10171 bind_array[4].buffer_type= MYSQL_TYPE_LONG;
10172 bind_array[4].buffer= (
void *) &int32_val;
10174 bind_array[5].buffer_type= MYSQL_TYPE_LONG;
10175 bind_array[5].buffer= (
void *) &uint32_val;
10176 bind_array[5].is_unsigned= 1;
10178 bind_array[6].buffer_type= MYSQL_TYPE_LONGLONG;
10179 bind_array[6].buffer= (
void *) &int64_val;
10181 bind_array[7].buffer_type= MYSQL_TYPE_LONGLONG;
10182 bind_array[7].buffer= (
void *) &uint64_val;
10183 bind_array[7].is_unsigned= 1;
10185 stmt= mysql_stmt_init(mysql);
10188 stmt_text=
"INSERT INTO t1 (i8, ui8, i16, ui16, i32, ui32, i64, ui64) "
10189 "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
10190 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
10191 check_execute(stmt, rc);
10193 mysql_stmt_bind_param(stmt, bind_array);
10195 int8_val= int8_min;
10196 uint8_val= uint8_min;
10197 int16_val= int16_min;
10198 uint16_val= uint16_min;
10199 int32_val= int32_min;
10200 uint32_val= uint32_min;
10201 int64_val= int64_min;
10202 uint64_val= uint64_min;
10204 rc= mysql_stmt_execute(stmt);
10205 check_execute(stmt, rc);
10207 int8_val= int8_max;
10208 uint8_val= uint8_max;
10209 int16_val= int16_max;
10210 uint16_val= uint16_max;
10211 int32_val= int32_max;
10212 uint32_val= uint32_max;
10213 int64_val= int64_max;
10214 uint64_val= uint64_max;
10216 rc= mysql_stmt_execute(stmt);
10217 check_execute(stmt, rc);
10219 stmt_text=
"SELECT i8, ui8, i16, ui16, i32, ui32, i64, ui64, ui64, "
10220 "cast(ui64 as signed), ui64, cast(ui64 as signed)"
10221 "FROM t1 ORDER BY id ASC";
10223 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
10224 check_execute(stmt, rc);
10226 rc= mysql_stmt_execute(stmt);
10227 check_execute(stmt, rc);
10229 bind_array[8].buffer_type= MYSQL_TYPE_DOUBLE;
10230 bind_array[8].buffer= (
void *) &udouble_val;
10232 bind_array[9].buffer_type= MYSQL_TYPE_DOUBLE;
10233 bind_array[9].buffer= (
void *) &double_val;
10235 bind_array[10].buffer_type= MYSQL_TYPE_STRING;
10236 bind_array[10].buffer= (
void *) &ulonglong_as_string;
10237 bind_array[10].buffer_length=
sizeof(ulonglong_as_string);
10239 bind_array[11].buffer_type= MYSQL_TYPE_STRING;
10240 bind_array[11].buffer= (
void *) &longlong_as_string;
10241 bind_array[11].buffer_length=
sizeof(longlong_as_string);
10243 mysql_stmt_bind_result(stmt, bind_array);
10245 rc= mysql_stmt_fetch(stmt);
10246 check_execute(stmt, rc);
10248 DIE_UNLESS(int8_val == int8_min);
10249 DIE_UNLESS(uint8_val == uint8_min);
10250 DIE_UNLESS(int16_val == int16_min);
10251 DIE_UNLESS(uint16_val == uint16_min);
10252 DIE_UNLESS(int32_val == int32_min);
10253 DIE_UNLESS(uint32_val == uint32_min);
10254 DIE_UNLESS(int64_val == int64_min);
10255 DIE_UNLESS(uint64_val == uint64_min);
10256 DIE_UNLESS(double_val == (longlong) uint64_min);
10257 double_tmp= ulonglong2double(uint64_val);
10258 DIE_UNLESS(cmp_double(&udouble_val, &double_tmp));
10259 DIE_UNLESS(!strcmp(longlong_as_string,
"0"));
10260 DIE_UNLESS(!strcmp(ulonglong_as_string,
"0"));
10262 rc= mysql_stmt_fetch(stmt);
10266 printf(
"Truncation mask: ");
10267 for (my_bind= bind_array; my_bind < bind_end; my_bind++)
10268 printf(
"%d", (
int) my_bind->error_value);
10271 DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED || rc == 0);
10273 DIE_UNLESS(int8_val == int8_max);
10274 DIE_UNLESS(uint8_val == uint8_max);
10275 DIE_UNLESS(int16_val == int16_max);
10276 DIE_UNLESS(uint16_val == uint16_max);
10277 DIE_UNLESS(int32_val == int32_max);
10278 DIE_UNLESS(uint32_val == uint32_max);
10279 DIE_UNLESS(int64_val == int64_max);
10280 DIE_UNLESS(uint64_val == uint64_max);
10281 DIE_UNLESS(double_val == (longlong) uint64_val);
10282 double_tmp= ulonglong2double(uint64_val);
10283 DIE_UNLESS(cmp_double(&udouble_val, &double_tmp));
10284 DIE_UNLESS(!strcmp(longlong_as_string,
"-1"));
10285 DIE_UNLESS(!strcmp(ulonglong_as_string,
"18446744073709551615"));
10287 rc= mysql_stmt_fetch(stmt);
10288 DIE_UNLESS(rc == MYSQL_NO_DATA);
10290 mysql_stmt_close(stmt);
10292 stmt_text=
"DROP TABLE t1";
10293 mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10297 static void test_union2()
10302 myheader(
"test_union2");
10304 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
10307 rc= mysql_query(mysql,
"CREATE TABLE t1(col1 INT, \
10308 col2 VARCHAR(40), \
10313 stmt= mysql_simple_prepare(mysql,
10314 "select col1 FROM t1 where col1=1 union distinct "
10315 "select col1 FROM t1 where col1=2");
10318 for (i= 0; i < 3; i++)
10320 rc= mysql_stmt_execute(stmt);
10321 check_execute(stmt, rc);
10322 rc= my_process_stmt_result(stmt);
10323 DIE_UNLESS(rc == 0);
10326 mysql_stmt_close(stmt);
10328 rc= mysql_query(mysql,
"DROP TABLE t1");
10337 static void test_bug1664()
10342 const char *str_data=
"Simple string";
10344 const char *query=
"INSERT INTO test_long_data(col2, col1) VALUES(?, ?)";
10346 myheader(
"test_bug1664");
10348 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS test_long_data");
10351 rc= mysql_query(mysql,
"CREATE TABLE test_long_data(col1 int, col2 long varchar)");
10354 stmt= mysql_stmt_init(mysql);
10356 rc= mysql_stmt_prepare(stmt, query, strlen(query));
10357 check_execute(stmt, rc);
10359 verify_param_count(stmt, 2);
10361 memset(my_bind, 0,
sizeof(my_bind));
10363 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
10364 my_bind[0].buffer= (
void *)str_data;
10365 my_bind[0].buffer_length= strlen(str_data);
10367 my_bind[1].buffer= (
void *)&int_data;
10368 my_bind[1].buffer_type= MYSQL_TYPE_LONG;
10370 rc= mysql_stmt_bind_param(stmt, my_bind);
10371 check_execute(stmt, rc);
10380 rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data));
10381 check_execute(stmt, rc);
10383 rc= mysql_stmt_execute(stmt);
10384 check_execute(stmt, rc);
10386 verify_col_data(
"test_long_data",
"col1",
"1");
10387 verify_col_data(
"test_long_data",
"col2",
"");
10389 rc= mysql_query(mysql,
"DELETE FROM test_long_data");
10393 data= (
char *)
"Data";
10394 rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data));
10395 check_execute(stmt, rc);
10397 rc= mysql_stmt_execute(stmt);
10398 check_execute(stmt, rc);
10400 verify_col_data(
"test_long_data",
"col1",
"1");
10401 verify_col_data(
"test_long_data",
"col2",
"Data");
10404 rc= mysql_query(mysql,
"DELETE FROM test_long_data");
10415 rc= mysql_stmt_execute(stmt);
10416 check_execute(stmt, rc);
10418 verify_col_data(
"test_long_data",
"col1",
"2");
10419 verify_col_data(
"test_long_data",
"col2", str_data);
10422 rc= mysql_query(mysql,
"DELETE FROM test_long_data");
10430 data= (
char *)
"SomeOtherData";
10431 rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data));
10432 check_execute(stmt, rc);
10434 rc= mysql_stmt_execute(stmt);
10435 check_execute(stmt, rc);
10437 verify_col_data(
"test_long_data",
"col1",
"2");
10438 verify_col_data(
"test_long_data",
"col2",
"SomeOtherData");
10440 mysql_stmt_close(stmt);
10443 rc= mysql_query(mysql,
"DELETE FROM test_long_data");
10447 stmt= mysql_stmt_init(mysql);
10449 rc= mysql_stmt_prepare(stmt, query, strlen(query));
10450 check_execute(stmt, rc);
10451 rc= mysql_stmt_bind_param(stmt, my_bind);
10452 check_execute(stmt, rc);
10454 data= (
char *)
"SomeData";
10455 rc= mysql_stmt_send_long_data(stmt, 0, data, strlen(data));
10456 check_execute(stmt, rc);
10458 rc= mysql_stmt_reset(stmt);
10459 check_execute(stmt, rc);
10461 rc= mysql_stmt_execute(stmt);
10462 check_execute(stmt, rc);
10464 verify_col_data(
"test_long_data",
"col1",
"2");
10465 verify_col_data(
"test_long_data",
"col2", str_data);
10467 mysql_stmt_close(stmt);
10470 rc= mysql_query(mysql,
"DROP TABLE test_long_data");
10475 static void test_order_param()
10480 myheader(
"test_order_param");
10482 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
10485 rc= mysql_query(mysql,
"CREATE TABLE t1(a INT, b char(10))");
10488 stmt= mysql_simple_prepare(mysql,
10489 "select sum(a) + 200, 1 from t1 "
10491 "select sum(a) + 200, 1 from t1 group by b ");
10493 mysql_stmt_close(stmt);
10495 stmt= mysql_simple_prepare(mysql,
10496 "select sum(a) + 200, ? from t1 group by b "
10498 "select sum(a) + 200, 1 from t1 group by b ");
10500 mysql_stmt_close(stmt);
10502 stmt= mysql_simple_prepare(mysql,
10503 "select sum(a) + 200, ? from t1 "
10505 "select sum(a) + 200, 1 from t1 group by b ");
10507 mysql_stmt_close(stmt);
10509 rc= mysql_query(mysql,
"DROP TABLE t1");
10514 static void test_union_param()
10521 ulong my_length= 3L;
10522 my_bool my_null= FALSE;
10523 myheader(
"test_union_param");
10525 strmov(my_val,
"abc");
10527 query= (
char*)
"select ? as my_col union distinct select ?";
10528 stmt= mysql_simple_prepare(mysql, query);
10535 memset(my_bind, 0,
sizeof(my_bind));
10538 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
10539 my_bind[0].buffer= (
char*) &my_val;
10540 my_bind[0].buffer_length= 4;
10541 my_bind[0].length= &my_length;
10542 my_bind[0].is_null= (
char*)&my_null;
10543 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
10544 my_bind[1].buffer= (
char*) &my_val;
10545 my_bind[1].buffer_length= 4;
10546 my_bind[1].length= &my_length;
10547 my_bind[1].is_null= (
char*)&my_null;
10549 rc= mysql_stmt_bind_param(stmt, my_bind);
10550 check_execute(stmt, rc);
10552 for (i= 0; i < 3; i++)
10554 rc= mysql_stmt_execute(stmt);
10555 check_execute(stmt, rc);
10556 rc= my_process_stmt_result(stmt);
10557 DIE_UNLESS(rc == 1);
10560 mysql_stmt_close(stmt);
10564 static void test_ps_i18n()
10568 const char *stmt_text;
10572 const char *koi8=
"\xee\xd5\x2c\x20\xda\xc1\x20\xd2\xd9\xc2\xc1\xcc\xcb\xd5";
10573 const char *cp1251=
"\xcd\xf3\x2c\x20\xe7\xe0\x20\xf0\xfb\xe1\xe0\xeb\xea\xf3";
10574 char buf1[16], buf2[16];
10575 ulong buf1_len, buf2_len;
10578 myheader(
"test_ps_i18n");
10580 stmt_text=
"DROP TABLE IF EXISTS t1";
10581 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10590 stmt_text=
"CREATE TABLE t1 (c1 VARBINARY(255), c2 VARBINARY(255))";
10592 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10595 stmt_text=
"SET CHARACTER_SET_CLIENT=koi8r, "
10596 "CHARACTER_SET_CONNECTION=cp1251, "
10597 "CHARACTER_SET_RESULTS=koi8r";
10599 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10602 memset(bind_array, 0,
sizeof(bind_array));
10604 bind_array[0].buffer_type= MYSQL_TYPE_STRING;
10605 bind_array[0].buffer= (
void *) koi8;
10606 bind_array[0].buffer_length= strlen(koi8);
10608 bind_array[1].buffer_type= MYSQL_TYPE_STRING;
10609 bind_array[1].buffer= (
void *) koi8;
10610 bind_array[1].buffer_length= strlen(koi8);
10612 stmt= mysql_stmt_init(mysql);
10615 stmt_text=
"INSERT INTO t1 (c1, c2) VALUES (?, ?)";
10617 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
10618 check_execute(stmt, rc);
10620 mysql_stmt_bind_param(stmt, bind_array);
10622 mysql_stmt_send_long_data(stmt, 0, koi8, strlen(koi8));
10624 rc= mysql_stmt_execute(stmt);
10625 check_execute(stmt, rc);
10627 stmt_text=
"SELECT c1, c2 FROM t1";
10630 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
10631 check_execute(stmt, rc);
10633 rc= mysql_stmt_execute(stmt);
10634 check_execute(stmt, rc);
10636 bind_array[0].buffer= buf1;
10637 bind_array[0].buffer_length=
sizeof(buf1);
10638 bind_array[0].length= &buf1_len;
10640 bind_array[1].buffer= buf2;
10641 bind_array[1].buffer_length=
sizeof(buf2);
10642 bind_array[1].length= &buf2_len;
10644 mysql_stmt_bind_result(stmt, bind_array);
10646 rc= mysql_stmt_fetch(stmt);
10647 check_execute(stmt, rc);
10649 DIE_UNLESS(buf1_len == strlen(cp1251));
10650 DIE_UNLESS(buf2_len == strlen(cp1251));
10651 DIE_UNLESS(!memcmp(buf1, cp1251, buf1_len));
10652 DIE_UNLESS(!memcmp(buf2, cp1251, buf1_len));
10654 rc= mysql_stmt_fetch(stmt);
10655 DIE_UNLESS(rc == MYSQL_NO_DATA);
10657 stmt_text=
"DROP TABLE IF EXISTS t1";
10658 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10668 stmt_text=
"CREATE TABLE t1 (c1 VARCHAR(255) CHARACTER SET cp1251, "
10669 "c2 VARCHAR(255) CHARACTER SET cp1251)";
10671 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10674 stmt_text=
"INSERT INTO t1 (c1, c2) VALUES (?, ?)";
10676 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
10677 check_execute(stmt, rc);
10680 bind_array[0].buffer_type= MYSQL_TYPE_STRING;
10681 bind_array[0].buffer= (
void *) koi8;
10682 bind_array[0].buffer_length= strlen(koi8);
10684 bind_array[1].buffer_type= MYSQL_TYPE_STRING;
10685 bind_array[1].buffer= (
void *) koi8;
10686 bind_array[1].buffer_length= strlen(koi8);
10688 mysql_stmt_bind_param(stmt, bind_array);
10690 mysql_stmt_send_long_data(stmt, 0, koi8, strlen(koi8));
10692 rc= mysql_stmt_execute(stmt);
10693 check_execute(stmt, rc);
10696 bind_array[0].buffer_type= MYSQL_TYPE_BLOB;
10697 bind_array[0].buffer= (
void *) cp1251;
10698 bind_array[0].buffer_length= strlen(cp1251);
10700 bind_array[1].buffer_type= MYSQL_TYPE_BLOB;
10701 bind_array[1].buffer= (
void *) cp1251;
10702 bind_array[1].buffer_length= strlen(cp1251);
10704 mysql_stmt_bind_param(stmt, bind_array);
10706 mysql_stmt_send_long_data(stmt, 0, cp1251, strlen(cp1251));
10708 rc= mysql_stmt_execute(stmt);
10709 check_execute(stmt, rc);
10713 stmt_text=
"SELECT c1, c2 FROM t1";
10716 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
10717 check_execute(stmt, rc);
10719 rc= mysql_stmt_execute(stmt);
10720 check_execute(stmt, rc);
10722 bind_array[0].buffer= buf1;
10723 bind_array[0].buffer_length=
sizeof(buf1);
10724 bind_array[0].length= &buf1_len;
10726 bind_array[1].buffer= buf2;
10727 bind_array[1].buffer_length=
sizeof(buf2);
10728 bind_array[1].length= &buf2_len;
10730 mysql_stmt_bind_result(stmt, bind_array);
10732 while ((rc= mysql_stmt_fetch(stmt)) == 0)
10734 DIE_UNLESS(buf1_len == strlen(koi8));
10735 DIE_UNLESS(buf2_len == strlen(koi8));
10736 DIE_UNLESS(!memcmp(buf1, koi8, buf1_len));
10737 DIE_UNLESS(!memcmp(buf2, koi8, buf1_len));
10739 DIE_UNLESS(rc == MYSQL_NO_DATA);
10740 mysql_stmt_close(stmt);
10742 stmt_text=
"DROP TABLE t1";
10743 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10745 stmt_text=
"SET NAMES DEFAULT";
10746 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10751 static void test_bug3796()
10755 const char *concat_arg0=
"concat_with_";
10756 enum { OUT_BUFF_SIZE= 30 };
10757 char out_buff[OUT_BUFF_SIZE];
10758 char canonical_buff[OUT_BUFF_SIZE];
10760 const char *stmt_text;
10763 myheader(
"test_bug3796");
10766 stmt_text=
"DROP TABLE IF EXISTS t1";
10767 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10770 stmt_text=
"CREATE TABLE t1 (a INT, b VARCHAR(30))";
10771 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10774 stmt_text=
"INSERT INTO t1 VALUES(1, 'ONE'), (2, 'TWO')";
10775 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10779 stmt= mysql_stmt_init(mysql);
10780 stmt_text=
"SELECT concat(?, b) FROM t1";
10782 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
10783 check_execute(stmt, rc);
10786 memset(my_bind, 0,
sizeof(my_bind));
10788 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
10789 my_bind[0].buffer= (
void *) concat_arg0;
10790 my_bind[0].buffer_length= strlen(concat_arg0);
10792 mysql_stmt_bind_param(stmt, my_bind);
10795 rc= mysql_stmt_execute(stmt);
10796 check_execute(stmt, rc);
10798 my_bind[0].buffer= (
void *) out_buff;
10799 my_bind[0].buffer_length= OUT_BUFF_SIZE;
10800 my_bind[0].length= &out_length;
10802 mysql_stmt_bind_result(stmt, my_bind);
10804 rc= mysql_stmt_fetch(stmt);
10806 printf(
"Concat result: '%s'\n", out_buff);
10807 check_execute(stmt, rc);
10808 strmov(canonical_buff, concat_arg0);
10809 strcat(canonical_buff,
"ONE");
10810 DIE_UNLESS(strlen(canonical_buff) == out_length &&
10811 strncmp(out_buff, canonical_buff, out_length) == 0);
10813 rc= mysql_stmt_fetch(stmt);
10814 check_execute(stmt, rc);
10815 strmov(canonical_buff + strlen(concat_arg0),
"TWO");
10816 DIE_UNLESS(strlen(canonical_buff) == out_length &&
10817 strncmp(out_buff, canonical_buff, out_length) == 0);
10819 printf(
"Concat result: '%s'\n", out_buff);
10821 rc= mysql_stmt_fetch(stmt);
10822 DIE_UNLESS(rc == MYSQL_NO_DATA);
10824 mysql_stmt_close(stmt);
10826 stmt_text=
"DROP TABLE IF EXISTS t1";
10827 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
10832 static void test_bug4026()
10838 const char *stmt_text;
10841 myheader(
"test_bug4026");
10846 stmt= mysql_stmt_init(mysql);
10847 stmt_text=
"SELECT ?, ?";
10849 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
10850 check_execute(stmt, rc);
10853 memset(my_bind, 0,
sizeof(my_bind));
10854 memset(&time_in, 0,
sizeof(time_in));
10855 memset(&time_out, 0,
sizeof(time_out));
10856 memset(&datetime_in, 0,
sizeof(datetime_in));
10857 memset(&datetime_out, 0,
sizeof(datetime_out));
10859 my_bind[0].buffer_type= MYSQL_TYPE_TIME;
10860 my_bind[0].buffer= (
void *) &time_in;
10861 my_bind[1].buffer_type= MYSQL_TYPE_DATETIME;
10862 my_bind[1].buffer= (
void *) &datetime_in;
10865 time_in.minute= 59;
10866 time_in.second= 59;
10872 time_in.time_type= MYSQL_TIMESTAMP_TIME;
10874 datetime_in= time_in;
10875 datetime_in.year= 2003;
10876 datetime_in.month= 12;
10877 datetime_in.day= 31;
10878 datetime_in.time_type= MYSQL_TIMESTAMP_DATETIME;
10880 mysql_stmt_bind_param(stmt, my_bind);
10883 rc= mysql_stmt_execute(stmt);
10884 check_execute(stmt, rc);
10886 my_bind[0].buffer= (
void *) &time_out;
10887 my_bind[1].buffer= (
void *) &datetime_out;
10889 mysql_stmt_bind_result(stmt, my_bind);
10891 rc= mysql_stmt_fetch(stmt);
10892 DIE_UNLESS(rc == 0);
10895 printf(
"%d:%d:%d.%lu\n", time_out.hour, time_out.minute, time_out.second,
10897 printf(
"%d-%d-%d %d:%d:%d.%lu\n", datetime_out.year, datetime_out.month,
10898 datetime_out.day, datetime_out.hour,
10899 datetime_out.minute, datetime_out.second,
10902 DIE_UNLESS(memcmp(&time_in, &time_out,
sizeof(time_in)) == 0);
10903 DIE_UNLESS(memcmp(&datetime_in, &datetime_out,
sizeof(datetime_in)) == 0);
10904 mysql_stmt_close(stmt);
10908 static void test_bug4079()
10912 const char *stmt_text;
10916 myheader(
"test_bug4079");
10919 mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
10920 mysql_query(mysql,
"CREATE TABLE t1 (a int)");
10921 mysql_query(mysql,
"INSERT INTO t1 VALUES (1), (2)");
10924 stmt= mysql_stmt_init(mysql);
10925 stmt_text=
"SELECT 1 < (SELECT a FROM t1)";
10927 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
10928 check_execute(stmt, rc);
10931 rc= mysql_stmt_execute(stmt);
10932 check_execute(stmt, rc);
10935 memset(my_bind, 0,
sizeof(my_bind));
10937 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
10938 my_bind[0].buffer= (
void *) &res;
10940 mysql_stmt_bind_result(stmt, my_bind);
10942 rc= mysql_stmt_fetch(stmt);
10943 DIE_UNLESS(rc != 0 && rc != MYSQL_NO_DATA);
10945 printf(
"Got error from mysql_stmt_fetch (as expected):\n%s\n",
10946 mysql_stmt_error(stmt));
10948 mysql_stmt_close(stmt);
10952 static void test_bug4236()
10955 const char *stmt_text;
10959 myheader(
"test_bug4236");
10961 stmt= mysql_stmt_init(mysql);
10964 stmt_text=
"SELECT 1";
10966 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
10967 check_execute(stmt, rc);
10969 backup.stmt_id= stmt->stmt_id;
10971 rc= mysql_stmt_execute(stmt);
10974 stmt->stmt_id= backup.stmt_id;
10976 mysql_stmt_close(stmt);
10980 static void test_bug4030()
10986 MYSQL_TIME datetime_canonical, datetime_out;
10987 const char *stmt_text;
10990 myheader(
"test_bug4030");
10995 stmt= mysql_stmt_init(mysql);
10996 stmt_text=
"SELECT '23:59:59.123456', '2003-12-31', "
10997 "'2003-12-31 23:59:59.123456'";
10998 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
10999 check_execute(stmt, rc);
11000 rc= mysql_stmt_execute(stmt);
11001 check_execute(stmt, rc);
11004 memset(my_bind, 0,
sizeof(my_bind));
11005 memset(&time_canonical, 0,
sizeof(time_canonical));
11006 memset(&time_out, 0,
sizeof(time_out));
11007 memset(&date_canonical, 0,
sizeof(date_canonical));
11008 memset(&date_out, 0,
sizeof(date_out));
11009 memset(&datetime_canonical, 0,
sizeof(datetime_canonical));
11010 memset(&datetime_out, 0,
sizeof(datetime_out));
11012 my_bind[0].buffer_type= MYSQL_TYPE_TIME;
11013 my_bind[0].buffer= (
void *) &time_out;
11014 my_bind[1].buffer_type= MYSQL_TYPE_DATE;
11015 my_bind[1].buffer= (
void *) &date_out;
11016 my_bind[2].buffer_type= MYSQL_TYPE_DATETIME;
11017 my_bind[2].buffer= (
void *) &datetime_out;
11019 time_canonical.hour= 23;
11020 time_canonical.minute= 59;
11021 time_canonical.second= 59;
11023 time_canonical.time_type= MYSQL_TIMESTAMP_TIME;
11025 date_canonical.year= 2003;
11026 date_canonical.month= 12;
11027 date_canonical.day= 31;
11028 date_canonical.time_type= MYSQL_TIMESTAMP_DATE;
11030 datetime_canonical= time_canonical;
11031 datetime_canonical.year= 2003;
11032 datetime_canonical.month= 12;
11033 datetime_canonical.day= 31;
11034 datetime_canonical.time_type= MYSQL_TIMESTAMP_DATETIME;
11036 mysql_stmt_bind_result(stmt, my_bind);
11038 rc= mysql_stmt_fetch(stmt);
11039 DIE_UNLESS(rc == 0);
11042 printf(
"%d:%d:%d.%lu\n", time_out.hour, time_out.minute, time_out.second,
11044 printf(
"%d-%d-%d\n", date_out.year, date_out.month, date_out.day);
11045 printf(
"%d-%d-%d %d:%d:%d.%lu\n", datetime_out.year, datetime_out.month,
11046 datetime_out.day, datetime_out.hour,
11047 datetime_out.minute, datetime_out.second,
11050 DIE_UNLESS(memcmp(&time_canonical, &time_out,
sizeof(time_out)) == 0);
11051 DIE_UNLESS(memcmp(&date_canonical, &date_out,
sizeof(date_out)) == 0);
11052 DIE_UNLESS(memcmp(&datetime_canonical, &datetime_out,
sizeof(datetime_out)) == 0);
11053 mysql_stmt_close(stmt);
11056 static void test_view()
11065 "SELECT COUNT(*) FROM v1 WHERE SERVERNAME=?";
11067 myheader(
"test_view");
11069 rc = mysql_query(mysql,
"DROP TABLE IF EXISTS t1,t2,t3,v1");
11072 rc = mysql_query(mysql,
"DROP VIEW IF EXISTS v1,t1,t2,t3");
11074 rc= mysql_query(mysql,
"CREATE TABLE t1 ("
11075 " SERVERGRP varchar(20) NOT NULL default '', "
11076 " DBINSTANCE varchar(20) NOT NULL default '', "
11077 " PRIMARY KEY (SERVERGRP)) "
11078 " CHARSET=latin1 collate=latin1_bin");
11080 rc= mysql_query(mysql,
"CREATE TABLE t2 ("
11081 " SERVERNAME varchar(20) NOT NULL, "
11082 " SERVERGRP varchar(20) NOT NULL, "
11083 " PRIMARY KEY (SERVERNAME)) "
11084 " CHARSET=latin1 COLLATE latin1_bin");
11086 rc= mysql_query(mysql,
11087 "CREATE TABLE t3 ("
11088 " SERVERGRP varchar(20) BINARY NOT NULL, "
11089 " TABNAME varchar(30) NOT NULL, MAPSTATE char(1) NOT NULL, "
11090 " ACTSTATE char(1) NOT NULL , "
11091 " LOCAL_NAME varchar(30) NOT NULL, "
11092 " CHG_DATE varchar(8) NOT NULL default '00000000', "
11093 " CHG_TIME varchar(6) NOT NULL default '000000', "
11094 " MXUSER varchar(12) NOT NULL default '', "
11095 " PRIMARY KEY (SERVERGRP, TABNAME, MAPSTATE, ACTSTATE, "
11096 " LOCAL_NAME)) CHARSET=latin1 COLLATE latin1_bin");
11098 rc= mysql_query(mysql,
"CREATE VIEW v1 AS select sql_no_cache"
11099 " T0001.SERVERNAME AS SERVERNAME, T0003.TABNAME AS"
11100 " TABNAME,T0003.LOCAL_NAME AS LOCAL_NAME,T0002.DBINSTANCE AS"
11101 " DBINSTANCE from t2 T0001 join t1 T0002 join t3 T0003 where"
11102 " ((T0002.SERVERGRP = T0001.SERVERGRP) and"
11103 " (T0002.SERVERGRP = T0003.SERVERGRP)"
11104 " and (T0003.MAPSTATE = _latin1'A') and"
11105 " (T0003.ACTSTATE = _latin1' '))");
11108 stmt= mysql_stmt_init(mysql);
11109 rc= mysql_stmt_prepare(stmt, query, strlen(query));
11110 check_execute(stmt, rc);
11112 strmov(str_data,
"TEST");
11113 memset(my_bind, 0,
sizeof(my_bind));
11114 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
11115 my_bind[0].buffer= (
char *)&str_data;
11116 my_bind[0].buffer_length= 50;
11117 my_bind[0].length= &length;
11119 my_bind[0].is_null= (
char*)&is_null;
11120 rc= mysql_stmt_bind_param(stmt, my_bind);
11121 check_execute(stmt,rc);
11123 for (i= 0; i < 3; i++)
11125 rc= mysql_stmt_execute(stmt);
11126 check_execute(stmt, rc);
11127 rc= my_process_stmt_result(stmt);
11128 DIE_UNLESS(1 == rc);
11130 mysql_stmt_close(stmt);
11132 rc= mysql_query(mysql,
"DROP TABLE t1,t2,t3");
11134 rc= mysql_query(mysql,
"DROP VIEW v1");
11139 static void test_view_where()
11144 "select v1.c,v2.c from v1, v2";
11146 myheader(
"test_view_where");
11148 rc = mysql_query(mysql,
"DROP TABLE IF EXISTS t1,v1,v2");
11151 rc = mysql_query(mysql,
"DROP VIEW IF EXISTS v1,v2,t1");
11153 rc= mysql_query(mysql,
"CREATE TABLE t1 (a int, b int)");
11155 rc= mysql_query(mysql,
"insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10)");
11157 rc= mysql_query(mysql,
"create view v1 (c) as select b from t1 where a<3");
11159 rc= mysql_query(mysql,
"create view v2 (c) as select b from t1 where a>=3");
11162 stmt= mysql_stmt_init(mysql);
11163 rc= mysql_stmt_prepare(stmt, query, strlen(query));
11164 check_execute(stmt, rc);
11166 for (i= 0; i < 3; i++)
11168 rc= mysql_stmt_execute(stmt);
11169 check_execute(stmt, rc);
11170 rc= my_process_stmt_result(stmt);
11171 DIE_UNLESS(4 == rc);
11173 mysql_stmt_close(stmt);
11175 rc= mysql_query(mysql,
"DROP TABLE t1");
11177 rc= mysql_query(mysql,
"DROP VIEW v1, v2");
11182 static void test_view_2where()
11187 char parms[8][100];
11190 "select relid, report, handle, log_group, username, variant, type, "
11191 "version, erfdat, erftime, erfname, aedat, aetime, aename, dependvars, "
11192 "inactive from V_LTDX where mandt = ? and relid = ? and report = ? and "
11193 "handle = ? and log_group = ? and username in ( ? , ? ) and type = ?";
11195 myheader(
"test_view_2where");
11197 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS LTDX");
11199 rc= mysql_query(mysql,
"DROP VIEW IF EXISTS V_LTDX");
11201 rc= mysql_query(mysql,
11202 "CREATE TABLE LTDX (MANDT char(3) NOT NULL default '000', "
11203 " RELID char(2) NOT NULL, REPORT varchar(40) NOT NULL,"
11204 " HANDLE varchar(4) NOT NULL, LOG_GROUP varchar(4) NOT NULL,"
11205 " USERNAME varchar(12) NOT NULL,"
11206 " VARIANT varchar(12) NOT NULL,"
11207 " TYPE char(1) NOT NULL, SRTF2 int(11) NOT NULL,"
11208 " VERSION varchar(6) NOT NULL default '000000',"
11209 " ERFDAT varchar(8) NOT NULL default '00000000',"
11210 " ERFTIME varchar(6) NOT NULL default '000000',"
11211 " ERFNAME varchar(12) NOT NULL,"
11212 " AEDAT varchar(8) NOT NULL default '00000000',"
11213 " AETIME varchar(6) NOT NULL default '000000',"
11214 " AENAME varchar(12) NOT NULL,"
11215 " DEPENDVARS varchar(10) NOT NULL,"
11216 " INACTIVE char(1) NOT NULL, CLUSTR smallint(6) NOT NULL,"
11218 " PRIMARY KEY (MANDT, RELID, REPORT, HANDLE, LOG_GROUP, "
11219 "USERNAME, VARIANT, TYPE, SRTF2))"
11220 " CHARSET=latin1 COLLATE latin1_bin");
11222 rc= mysql_query(mysql,
11223 "CREATE VIEW V_LTDX AS select T0001.MANDT AS "
11224 " MANDT,T0001.RELID AS RELID,T0001.REPORT AS "
11225 " REPORT,T0001.HANDLE AS HANDLE,T0001.LOG_GROUP AS "
11226 " LOG_GROUP,T0001.USERNAME AS USERNAME,T0001.VARIANT AS "
11227 " VARIANT,T0001.TYPE AS TYPE,T0001.VERSION AS "
11228 " VERSION,T0001.ERFDAT AS ERFDAT,T0001.ERFTIME AS "
11229 " ERFTIME,T0001.ERFNAME AS ERFNAME,T0001.AEDAT AS "
11230 " AEDAT,T0001.AETIME AS AETIME,T0001.AENAME AS "
11231 " AENAME,T0001.DEPENDVARS AS DEPENDVARS,T0001.INACTIVE AS "
11232 " INACTIVE from LTDX T0001 where (T0001.SRTF2 = 0)");
11234 memset(my_bind, 0,
sizeof(my_bind));
11235 for (i=0; i < 8; i++) {
11236 strmov(parms[i],
"1");
11237 my_bind[
i].buffer_type = MYSQL_TYPE_VAR_STRING;
11238 my_bind[
i].buffer = (
char *)&parms[i];
11239 my_bind[
i].buffer_length = 100;
11240 my_bind[
i].is_null = 0;
11241 my_bind[
i].length = &length[
i];
11244 stmt= mysql_stmt_init(mysql);
11245 rc= mysql_stmt_prepare(stmt, query, strlen(query));
11246 check_execute(stmt, rc);
11248 rc= mysql_stmt_bind_param(stmt, my_bind);
11249 check_execute(stmt,rc);
11251 rc= mysql_stmt_execute(stmt);
11252 check_execute(stmt, rc);
11253 rc= my_process_stmt_result(stmt);
11254 DIE_UNLESS(0 == rc);
11256 mysql_stmt_close(stmt);
11258 rc= mysql_query(mysql,
"DROP VIEW V_LTDX");
11260 rc= mysql_query(mysql,
"DROP TABLE LTDX");
11265 static void test_view_star()
11270 char parms[8][100];
11272 const char *query=
"SELECT * FROM vt1 WHERE a IN (?,?)";
11274 myheader(
"test_view_star");
11276 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1, vt1");
11278 rc= mysql_query(mysql,
"DROP VIEW IF EXISTS t1, vt1");
11280 rc= mysql_query(mysql,
"CREATE TABLE t1 (a int)");
11282 rc= mysql_query(mysql,
"CREATE VIEW vt1 AS SELECT a FROM t1");
11284 memset(my_bind, 0,
sizeof(my_bind));
11285 for (i= 0; i < 2; i++) {
11286 sprintf((
char *)&parms[i],
"%d", i);
11287 my_bind[
i].buffer_type = MYSQL_TYPE_VAR_STRING;
11288 my_bind[
i].buffer = (
char *)&parms[i];
11289 my_bind[
i].buffer_length = 100;
11290 my_bind[
i].is_null = 0;
11291 my_bind[
i].length = &length[
i];
11295 stmt= mysql_stmt_init(mysql);
11296 rc= mysql_stmt_prepare(stmt, query, strlen(query));
11297 check_execute(stmt, rc);
11299 rc= mysql_stmt_bind_param(stmt, my_bind);
11300 check_execute(stmt,rc);
11302 for (i= 0; i < 3; i++)
11304 rc= mysql_stmt_execute(stmt);
11305 check_execute(stmt, rc);
11306 rc= my_process_stmt_result(stmt);
11307 DIE_UNLESS(0 == rc);
11310 mysql_stmt_close(stmt);
11312 rc= mysql_query(mysql,
"DROP TABLE t1");
11314 rc= mysql_query(mysql,
"DROP VIEW vt1");
11319 static void test_view_insert()
11325 ulong my_length = 0L;
11328 "insert into v1 values (?)";
11330 myheader(
"test_view_insert");
11332 rc = mysql_query(mysql,
"DROP TABLE IF EXISTS t1,v1");
11334 rc = mysql_query(mysql,
"DROP VIEW IF EXISTS t1,v1");
11337 rc= mysql_query(mysql,
"create table t1 (a int, primary key (a))");
11340 rc= mysql_query(mysql,
"create view v1 as select a from t1 where a>=1");
11343 insert_stmt= mysql_stmt_init(mysql);
11344 rc= mysql_stmt_prepare(insert_stmt, query, strlen(query));
11345 check_execute(insert_stmt, rc);
11346 query=
"select * from t1";
11347 select_stmt= mysql_stmt_init(mysql);
11348 rc= mysql_stmt_prepare(select_stmt, query, strlen(query));
11349 check_execute(select_stmt, rc);
11351 memset(my_bind, 0,
sizeof(my_bind));
11352 my_bind[0].buffer_type = MYSQL_TYPE_LONG;
11353 my_bind[0].buffer = (
char *)&my_val;
11354 my_bind[0].length = &my_length;
11355 my_bind[0].is_null = (
char*)&my_null;
11356 rc= mysql_stmt_bind_param(insert_stmt, my_bind);
11357 check_execute(insert_stmt, rc);
11359 for (i= 0; i < 3; i++)
11364 rc= mysql_stmt_execute(insert_stmt);
11365 check_execute(insert_stmt, rc);
11367 rc= mysql_stmt_execute(select_stmt);
11368 check_execute(select_stmt, rc);
11369 rowcount= (int)my_process_stmt_result(select_stmt);
11370 DIE_UNLESS((i+1) == rowcount);
11372 mysql_stmt_close(insert_stmt);
11373 mysql_stmt_close(select_stmt);
11375 rc= mysql_query(mysql,
"DROP VIEW v1");
11377 rc= mysql_query(mysql,
"DROP TABLE t1");
11382 static void test_left_join_view()
11387 "select t1.a, v1.x from t1 left join v1 on (t1.a= v1.x);";
11389 myheader(
"test_left_join_view");
11391 rc = mysql_query(mysql,
"DROP TABLE IF EXISTS t1,v1");
11394 rc = mysql_query(mysql,
"DROP VIEW IF EXISTS v1,t1");
11396 rc= mysql_query(mysql,
"CREATE TABLE t1 (a int)");
11398 rc= mysql_query(mysql,
"insert into t1 values (1), (2), (3)");
11400 rc= mysql_query(mysql,
"create view v1 (x) as select a from t1 where a > 1");
11402 stmt= mysql_stmt_init(mysql);
11403 rc= mysql_stmt_prepare(stmt, query, strlen(query));
11404 check_execute(stmt, rc);
11406 for (i= 0; i < 3; i++)
11408 rc= mysql_stmt_execute(stmt);
11409 check_execute(stmt, rc);
11410 rc= my_process_stmt_result(stmt);
11411 DIE_UNLESS(3 == rc);
11413 mysql_stmt_close(stmt);
11415 rc= mysql_query(mysql,
"DROP VIEW v1");
11417 rc= mysql_query(mysql,
"DROP TABLE t1");
11422 static void test_view_insert_fields()
11425 char parm[11][1000];
11429 const char *query=
"INSERT INTO `v1` ( `K1C4` ,`K2C4` ,`K3C4` ,`K4N4` ,`F1C4` ,`F2I4` ,`F3N5` ,`F7F8` ,`F6N4` ,`F5C8` ,`F9D8` ) VALUES( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? )";
11431 myheader(
"test_view_insert_fields");
11433 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1, v1");
11435 rc= mysql_query(mysql,
"DROP VIEW IF EXISTS t1, v1");
11437 rc= mysql_query(mysql,
11438 "CREATE TABLE t1 (K1C4 varchar(4) NOT NULL,"
11439 "K2C4 varchar(4) NOT NULL, K3C4 varchar(4) NOT NULL,"
11440 "K4N4 varchar(4) NOT NULL default '0000',"
11441 "F1C4 varchar(4) NOT NULL, F2I4 int(11) NOT NULL,"
11442 "F3N5 varchar(5) NOT NULL default '00000',"
11443 "F4I4 int(11) NOT NULL default '0', F5C8 varchar(8) NOT NULL,"
11444 "F6N4 varchar(4) NOT NULL default '0000',"
11445 "F7F8 double NOT NULL default '0',"
11446 "F8F8 double NOT NULL default '0',"
11447 "F9D8 decimal(8,2) NOT NULL default '0.00',"
11448 "PRIMARY KEY (K1C4,K2C4,K3C4,K4N4)) "
11449 "CHARSET=latin1 COLLATE latin1_bin");
11451 rc= mysql_query(mysql,
11452 "CREATE VIEW v1 AS select sql_no_cache "
11453 " K1C4 AS K1C4, K2C4 AS K2C4, K3C4 AS K3C4, K4N4 AS K4N4, "
11454 " F1C4 AS F1C4, F2I4 AS F2I4, F3N5 AS F3N5,"
11455 " F7F8 AS F7F8, F6N4 AS F6N4, F5C8 AS F5C8, F9D8 AS F9D8"
11458 memset(my_bind, 0,
sizeof(my_bind));
11459 for (i= 0; i < 11; i++)
11462 my_bind[
i].buffer_type= MYSQL_TYPE_STRING;
11463 my_bind[
i].is_null= 0;
11464 my_bind[
i].buffer= (
char *)&parm[i];
11466 strmov(parm[i],
"1");
11467 my_bind[
i].buffer_length= 2;
11468 my_bind[
i].length= &l[
i];
11470 stmt= mysql_stmt_init(mysql);
11471 rc= mysql_stmt_prepare(stmt, query, strlen(query));
11472 check_execute(stmt, rc);
11473 rc= mysql_stmt_bind_param(stmt, my_bind);
11474 check_execute(stmt, rc);
11476 rc= mysql_stmt_execute(stmt);
11477 check_execute(stmt, rc);
11478 mysql_stmt_close(stmt);
11480 query=
"select * from t1";
11481 stmt= mysql_stmt_init(mysql);
11482 rc= mysql_stmt_prepare(stmt, query, strlen(query));
11483 check_execute(stmt, rc);
11484 rc= mysql_stmt_execute(stmt);
11485 check_execute(stmt, rc);
11486 rc= my_process_stmt_result(stmt);
11487 DIE_UNLESS(1 == rc);
11489 mysql_stmt_close(stmt);
11490 rc= mysql_query(mysql,
"DROP VIEW v1");
11492 rc= mysql_query(mysql,
"DROP TABLE t1");
11497 static void test_bug5126()
11502 const char *stmt_text;
11505 myheader(
"test_bug5126");
11507 stmt_text=
"DROP TABLE IF EXISTS t1";
11508 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11511 stmt_text=
"CREATE TABLE t1 (a mediumint, b int)";
11512 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11515 stmt_text=
"INSERT INTO t1 VALUES (8386608, 1)";
11516 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11519 stmt= mysql_stmt_init(mysql);
11520 stmt_text=
"SELECT a, b FROM t1";
11521 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
11522 check_execute(stmt, rc);
11523 rc= mysql_stmt_execute(stmt);
11524 check_execute(stmt, rc);
11527 memset(my_bind, 0,
sizeof(my_bind));
11529 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
11530 my_bind[0].buffer= &c1;
11531 my_bind[1].buffer_type= MYSQL_TYPE_LONG;
11532 my_bind[1].buffer= &c2;
11534 mysql_stmt_bind_result(stmt, my_bind);
11536 rc= mysql_stmt_fetch(stmt);
11537 DIE_UNLESS(rc == 0);
11538 DIE_UNLESS(c1 == 8386608 && c2 == 1);
11540 printf(
"%ld, %ld\n", (
long) c1, (
long) c2);
11541 mysql_stmt_close(stmt);
11545 static void test_bug4231()
11550 const char *stmt_text;
11553 myheader(
"test_bug4231");
11555 stmt_text=
"DROP TABLE IF EXISTS t1";
11556 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11559 stmt_text=
"CREATE TABLE t1 (a int)";
11560 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11563 stmt_text=
"INSERT INTO t1 VALUES (1)";
11564 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11567 stmt= mysql_stmt_init(mysql);
11568 stmt_text=
"SELECT a FROM t1 WHERE ? = ?";
11569 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
11570 check_execute(stmt, rc);
11573 memset(my_bind, 0,
sizeof(my_bind));
11574 memset(tm, 0,
sizeof(tm));
11576 my_bind[0].buffer_type= MYSQL_TYPE_DATE;
11577 my_bind[0].buffer= &tm[0];
11578 my_bind[1].buffer_type= MYSQL_TYPE_DATE;
11579 my_bind[1].buffer= &tm[1];
11581 mysql_stmt_bind_param(stmt, my_bind);
11582 check_execute(stmt, rc);
11589 tm[0].time_type = MYSQL_TIMESTAMP_DATE;
11596 rc= mysql_stmt_execute(stmt);
11597 check_execute(stmt, rc);
11599 rc= mysql_stmt_fetch(stmt);
11602 DIE_UNLESS(rc == MYSQL_NO_DATA);
11605 tm[0].year= tm[0].month= tm[0].day= 0;
11607 mysql_stmt_execute(stmt);
11608 rc= mysql_stmt_fetch(stmt);
11609 DIE_UNLESS(rc == 0);
11611 mysql_stmt_close(stmt);
11612 stmt_text=
"DROP TABLE t1";
11613 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11618 static void test_bug5399()
11624 #define NUM_OF_USED_STMT 97
11632 myheader(
"test_bug5399");
11634 memset(my_bind, 0,
sizeof(my_bind));
11635 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
11636 my_bind[0].buffer= &no;
11638 for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt)
11640 sprintf(buff,
"select %d", (
int) (stmt - stmt_list));
11641 *stmt= mysql_stmt_init(mysql);
11642 rc= mysql_stmt_prepare(*stmt, buff, strlen(buff));
11643 check_execute(*stmt, rc);
11644 mysql_stmt_bind_result(*stmt, my_bind);
11647 printf(
"%d statements prepared.\n", NUM_OF_USED_STMT);
11649 for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt)
11651 rc= mysql_stmt_execute(*stmt);
11652 check_execute(*stmt, rc);
11653 rc= mysql_stmt_store_result(*stmt);
11654 check_execute(*stmt, rc);
11655 rc= mysql_stmt_fetch(*stmt);
11656 DIE_UNLESS(rc == 0);
11657 DIE_UNLESS((int32) (stmt - stmt_list) == no);
11660 for (stmt= stmt_list; stmt != stmt_list + NUM_OF_USED_STMT; ++stmt)
11661 mysql_stmt_close(*stmt);
11662 #undef NUM_OF_USED_STMT
11666 static void test_bug5194()
11672 int param_str_length;
11673 const char *stmt_text;
11675 float float_array[250] =
11677 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11678 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11679 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11680 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11681 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11682 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11683 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11684 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11685 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11686 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11687 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11688 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11689 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
11690 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
11691 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
11692 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
11693 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
11694 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
11695 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
11696 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
11697 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
11698 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
11699 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
11700 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25,
11701 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25
11703 float *fa_ptr= float_array;
11705 const int COLUMN_COUNT=
sizeof(float_array)/
sizeof(*float_array);
11707 const int MIN_ROWS_PER_INSERT= 262;
11709 const int MAX_ROWS_PER_INSERT= 300;
11710 const int MAX_PARAM_COUNT= COLUMN_COUNT*MAX_ROWS_PER_INSERT;
11711 const char *query_template=
"insert into t1 values %s";
11712 const int CHARS_PER_PARAM= 5;
11713 const int uint16_max= 65535;
11716 myheader(
"test_bug5194");
11718 stmt_text=
"drop table if exists t1";
11719 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11721 stmt_text=
"create table if not exists t1"
11722 "(c1 float, c2 float, c3 float, c4 float, c5 float, c6 float, "
11723 "c7 float, c8 float, c9 float, c10 float, c11 float, c12 float, "
11724 "c13 float, c14 float, c15 float, c16 float, c17 float, c18 float, "
11725 "c19 float, c20 float, c21 float, c22 float, c23 float, c24 float, "
11726 "c25 float, c26 float, c27 float, c28 float, c29 float, c30 float, "
11727 "c31 float, c32 float, c33 float, c34 float, c35 float, c36 float, "
11728 "c37 float, c38 float, c39 float, c40 float, c41 float, c42 float, "
11729 "c43 float, c44 float, c45 float, c46 float, c47 float, c48 float, "
11730 "c49 float, c50 float, c51 float, c52 float, c53 float, c54 float, "
11731 "c55 float, c56 float, c57 float, c58 float, c59 float, c60 float, "
11732 "c61 float, c62 float, c63 float, c64 float, c65 float, c66 float, "
11733 "c67 float, c68 float, c69 float, c70 float, c71 float, c72 float, "
11734 "c73 float, c74 float, c75 float, c76 float, c77 float, c78 float, "
11735 "c79 float, c80 float, c81 float, c82 float, c83 float, c84 float, "
11736 "c85 float, c86 float, c87 float, c88 float, c89 float, c90 float, "
11737 "c91 float, c92 float, c93 float, c94 float, c95 float, c96 float, "
11738 "c97 float, c98 float, c99 float, c100 float, c101 float, c102 float, "
11739 "c103 float, c104 float, c105 float, c106 float, c107 float, c108 float, "
11740 "c109 float, c110 float, c111 float, c112 float, c113 float, c114 float, "
11741 "c115 float, c116 float, c117 float, c118 float, c119 float, c120 float, "
11742 "c121 float, c122 float, c123 float, c124 float, c125 float, c126 float, "
11743 "c127 float, c128 float, c129 float, c130 float, c131 float, c132 float, "
11744 "c133 float, c134 float, c135 float, c136 float, c137 float, c138 float, "
11745 "c139 float, c140 float, c141 float, c142 float, c143 float, c144 float, "
11746 "c145 float, c146 float, c147 float, c148 float, c149 float, c150 float, "
11747 "c151 float, c152 float, c153 float, c154 float, c155 float, c156 float, "
11748 "c157 float, c158 float, c159 float, c160 float, c161 float, c162 float, "
11749 "c163 float, c164 float, c165 float, c166 float, c167 float, c168 float, "
11750 "c169 float, c170 float, c171 float, c172 float, c173 float, c174 float, "
11751 "c175 float, c176 float, c177 float, c178 float, c179 float, c180 float, "
11752 "c181 float, c182 float, c183 float, c184 float, c185 float, c186 float, "
11753 "c187 float, c188 float, c189 float, c190 float, c191 float, c192 float, "
11754 "c193 float, c194 float, c195 float, c196 float, c197 float, c198 float, "
11755 "c199 float, c200 float, c201 float, c202 float, c203 float, c204 float, "
11756 "c205 float, c206 float, c207 float, c208 float, c209 float, c210 float, "
11757 "c211 float, c212 float, c213 float, c214 float, c215 float, c216 float, "
11758 "c217 float, c218 float, c219 float, c220 float, c221 float, c222 float, "
11759 "c223 float, c224 float, c225 float, c226 float, c227 float, c228 float, "
11760 "c229 float, c230 float, c231 float, c232 float, c233 float, c234 float, "
11761 "c235 float, c236 float, c237 float, c238 float, c239 float, c240 float, "
11762 "c241 float, c242 float, c243 float, c244 float, c245 float, c246 float, "
11763 "c247 float, c248 float, c249 float, c250 float)";
11764 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11768 query= (
char*) malloc(strlen(query_template) +
11769 MAX_PARAM_COUNT * CHARS_PER_PARAM + 1);
11770 param_str= (
char*) malloc(COLUMN_COUNT * CHARS_PER_PARAM);
11772 if (my_bind == 0 || query == 0 || param_str == 0)
11774 fprintf(stderr,
"Can't allocate enough memory for query structs\n");
11784 stmt= mysql_stmt_init(mysql);
11787 sprintf(param_str,
"(");
11788 for (i= 1; i < COLUMN_COUNT; ++
i)
11789 strcat(param_str,
"?, ");
11790 strcat(param_str,
"?)");
11791 param_str_length= strlen(param_str);
11794 memset(my_bind, 0, MAX_PARAM_COUNT *
sizeof(
MYSQL_BIND));
11795 for (i= 0; i < MAX_PARAM_COUNT; ++
i)
11797 my_bind[
i].buffer_type= MYSQL_TYPE_FLOAT;
11798 my_bind[
i].buffer= fa_ptr;
11799 if (++fa_ptr == float_array + COLUMN_COUNT)
11800 fa_ptr= float_array;
11807 for (nrows= MIN_ROWS_PER_INSERT; nrows <= MAX_ROWS_PER_INSERT; ++nrows)
11811 sprintf(query, query_template, param_str);
11812 query_ptr= query + strlen(query);
11813 for (i= 1; i < nrows; ++
i)
11815 memcpy(query_ptr,
", ", 2);
11817 memcpy(query_ptr, param_str, param_str_length);
11818 query_ptr+= param_str_length;
11822 rc= mysql_stmt_prepare(stmt, query, query_ptr - query);
11823 if (rc && nrows * COLUMN_COUNT > uint16_max)
11826 printf(
"Failed to prepare a statement with %d placeholders "
11827 "(as expected).\n", nrows * COLUMN_COUNT);
11831 check_execute(stmt, rc);
11834 printf(
"Insert: query length= %d, row count= %d, param count= %lu\n",
11835 (
int) strlen(query), nrows, mysql_stmt_param_count(stmt));
11838 rc= mysql_stmt_bind_param(stmt, my_bind);
11839 check_execute(stmt, rc);
11841 rc= mysql_stmt_execute(stmt);
11842 check_execute(stmt, rc);
11843 mysql_stmt_reset(stmt);
11846 mysql_stmt_close(stmt);
11850 stmt_text=
"drop table t1";
11851 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11856 static void test_bug5315()
11859 const char *stmt_text;
11862 myheader(
"test_bug5315");
11864 stmt_text=
"SELECT 1";
11865 stmt= mysql_stmt_init(mysql);
11866 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
11867 DIE_UNLESS(rc == 0);
11869 printf(
"Excuting mysql_change_user\n");
11870 mysql_change_user(mysql, opt_user, opt_password, current_db);
11872 printf(
"Excuting mysql_stmt_execute\n");
11873 rc= mysql_stmt_execute(stmt);
11874 DIE_UNLESS(rc != 0);
11878 printf(
"Got error (as expected): '%s'\n", mysql_stmt_error(stmt));
11882 printf(
"Excuting mysql_stmt_close\n");
11883 mysql_stmt_close(stmt);
11885 printf(
"Excuting mysql_stmt_init\n");
11886 stmt= mysql_stmt_init(mysql);
11887 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
11888 DIE_UNLESS(rc == 0);
11889 rc= mysql_stmt_execute(stmt);
11890 DIE_UNLESS(rc == 0);
11891 mysql_stmt_close(stmt);
11895 static void test_bug6049()
11901 const char *stmt_text;
11906 myheader(
"test_bug6049");
11908 stmt_text=
"SELECT MAKETIME(-25, 12, 12)";
11910 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11912 res= mysql_store_result(mysql);
11913 row= mysql_fetch_row(res);
11915 stmt= mysql_stmt_init(mysql);
11916 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
11917 check_execute(stmt, rc);
11918 rc= mysql_stmt_execute(stmt);
11919 check_execute(stmt, rc);
11921 memset(my_bind, 0,
sizeof(my_bind));
11922 my_bind[0].buffer_type = MYSQL_TYPE_STRING;
11923 my_bind[0].buffer = &buffer;
11924 my_bind[0].buffer_length =
sizeof(buffer);
11925 my_bind[0].length = &length;
11927 mysql_stmt_bind_result(stmt, my_bind);
11928 rc= mysql_stmt_fetch(stmt);
11929 DIE_UNLESS(rc == 0);
11933 printf(
"Result from query: %s\n", row[0]);
11934 printf(
"Result from prepared statement: %s\n", (
char*) buffer);
11937 DIE_UNLESS(strcmp(row[0], (
char*) buffer) == 0);
11939 mysql_free_result(res);
11940 mysql_stmt_close(stmt);
11944 static void test_bug6058()
11950 const char *stmt_text;
11955 myheader(
"test_bug6058");
11957 rc= mysql_query(mysql,
"SET SQL_MODE=''");
11960 stmt_text=
"SELECT CAST('0000-00-00' AS DATE)";
11962 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
11964 res= mysql_store_result(mysql);
11965 row= mysql_fetch_row(res);
11967 stmt= mysql_stmt_init(mysql);
11968 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
11969 check_execute(stmt, rc);
11970 rc= mysql_stmt_execute(stmt);
11971 check_execute(stmt, rc);
11973 memset(my_bind, 0,
sizeof(my_bind));
11974 my_bind[0].buffer_type = MYSQL_TYPE_STRING;
11975 my_bind[0].buffer = &buffer;
11976 my_bind[0].buffer_length =
sizeof(buffer);
11977 my_bind[0].length = &length;
11979 mysql_stmt_bind_result(stmt, my_bind);
11980 rc= mysql_stmt_fetch(stmt);
11981 DIE_UNLESS(rc == 0);
11985 printf(
"Result from query: %s\n", row[0]);
11986 printf(
"Result from prepared statement: %s\n", buffer);
11989 DIE_UNLESS(strcmp(row[0], buffer) == 0);
11991 mysql_free_result(res);
11992 mysql_stmt_close(stmt);
11996 static void test_bug6059()
11999 const char *stmt_text;
12001 myheader(
"test_bug6059");
12003 stmt_text=
"SELECT 'foo' INTO OUTFILE 'x.3'";
12005 stmt= mysql_stmt_init(mysql);
12006 (void) mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
12007 DIE_UNLESS(mysql_stmt_field_count(stmt) == 0);
12008 mysql_stmt_close(stmt);
12012 static void test_bug6046()
12015 const char *stmt_text;
12020 myheader(
"test_bug6046");
12022 stmt_text=
"DROP TABLE IF EXISTS t1";
12023 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12025 stmt_text=
"CREATE TABLE t1 (a int, b int)";
12026 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12028 stmt_text=
"INSERT INTO t1 VALUES (1,1),(2,2),(3,1),(4,2)";
12029 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12032 stmt= mysql_stmt_init(mysql);
12034 stmt_text=
"SELECT t1.a FROM t1 NATURAL JOIN t1 as X1 "
12035 "WHERE t1.b > ? ORDER BY t1.a";
12037 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
12038 check_execute(stmt, rc);
12041 memset(my_bind, 0,
sizeof(my_bind));
12042 my_bind[0].buffer= &b;
12043 my_bind[0].buffer_type= MYSQL_TYPE_SHORT;
12045 mysql_stmt_bind_param(stmt, my_bind);
12047 rc= mysql_stmt_execute(stmt);
12048 check_execute(stmt, rc);
12049 mysql_stmt_store_result(stmt);
12051 rc= mysql_stmt_execute(stmt);
12052 check_execute(stmt, rc);
12054 mysql_stmt_close(stmt);
12059 static void test_basic_cursors()
12061 const char *basic_tables[]=
12063 "DROP TABLE IF EXISTS t1, t2",
12066 "(id INTEGER NOT NULL PRIMARY KEY, "
12067 " name VARCHAR(20) NOT NULL)",
12069 "INSERT INTO t1 (id, name) VALUES "
12070 " (2, 'Ja'), (3, 'Ede'), "
12071 " (4, 'Haag'), (5, 'Kabul'), "
12072 " (6, 'Almere'), (7, 'Utrecht'), "
12073 " (8, 'Qandahar'), (9, 'Amsterdam'), "
12074 " (10, 'Amersfoort'), (11, 'Constantine')",
12077 "(id INTEGER NOT NULL PRIMARY KEY, "
12078 " name VARCHAR(20) NOT NULL)",
12080 "INSERT INTO t2 (id, name) VALUES "
12081 " (4, 'Guam'), (5, 'Aruba'), "
12082 " (6, 'Angola'), (7, 'Albania'), "
12083 " (8, 'Anguilla'), (9, 'Argentina'), "
12084 " (10, 'Azerbaijan'), (11, 'Afghanistan'), "
12085 " (12, 'Burkina Faso'), (13, 'Faroe Islands')"
12087 const char *queries[]=
12089 "SELECT * FROM t1",
12093 DBUG_ENTER(
"test_basic_cursors");
12094 myheader(
"test_basic_cursors");
12096 fill_tables(basic_tables,
sizeof(basic_tables)/
sizeof(*basic_tables));
12098 fetch_n(queries,
sizeof(queries)/
sizeof(*queries), USE_ROW_BY_ROW_FETCH);
12099 fetch_n(queries,
sizeof(queries)/
sizeof(*queries), USE_STORE_RESULT);
12104 static void test_cursors_with_union()
12106 const char *queries[]=
12108 "SELECT t1.name FROM t1 UNION SELECT t2.name FROM t2",
12109 "SELECT t1.id FROM t1 WHERE t1.id < 5"
12111 myheader(
"test_cursors_with_union");
12112 fetch_n(queries,
sizeof(queries)/
sizeof(*queries), USE_ROW_BY_ROW_FETCH);
12113 fetch_n(queries,
sizeof(queries)/
sizeof(*queries), USE_STORE_RESULT);
12117 static void test_cursors_with_procedure()
12119 const char *queries[]=
12121 "SELECT * FROM t1 procedure analyse()"
12123 myheader(
"test_cursors_with_procedure");
12124 fetch_n(queries,
sizeof(queries)/
sizeof(*queries), USE_ROW_BY_ROW_FETCH);
12125 fetch_n(queries,
sizeof(queries)/
sizeof(*queries), USE_STORE_RESULT);
12136 static void test_bug6081()
12139 myheader(
"test_bug6081");
12141 rc= simple_command(mysql, COM_DROP_DB, (uchar*) current_db,
12142 (ulong)strlen(current_db), 0);
12143 if (rc == 0 && mysql_errno(mysql) != ER_UNKNOWN_COM_ERROR)
12146 die(__FILE__, __LINE__,
"COM_DROP_DB failed");
12148 rc= simple_command(mysql, COM_DROP_DB, (uchar*) current_db,
12149 (ulong)strlen(current_db), 0);
12151 rc= simple_command(mysql, COM_CREATE_DB, (uchar*) current_db,
12152 (ulong)strlen(current_db), 0);
12153 if (rc == 0 && mysql_errno(mysql) != ER_UNKNOWN_COM_ERROR)
12156 die(__FILE__, __LINE__,
"COM_CREATE_DB failed");
12158 rc= simple_command(mysql, COM_CREATE_DB, (uchar*) current_db,
12159 (ulong)strlen(current_db), 0);
12161 rc= mysql_select_db(mysql, current_db);
12166 static void test_bug6096()
12169 MYSQL_RES *query_result, *stmt_metadata;
12170 const char *stmt_text;
12173 ulong query_field_count, stmt_field_count;
12175 my_bool update_max_length= TRUE;
12178 myheader(
"test_bug6096");
12180 stmt_text=
"drop table if exists t1";
12181 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12184 mysql_query(mysql,
"set sql_mode=''");
12185 stmt_text=
"create table t1 (c_tinyint tinyint, c_smallint smallint, "
12186 " c_mediumint mediumint, c_int int, "
12187 " c_bigint bigint, c_float float, "
12188 " c_double double, c_varchar varchar(20), "
12189 " c_char char(20), c_time time, c_date date, "
12190 " c_datetime datetime)";
12191 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12193 stmt_text=
"insert into t1 values (-100, -20000, 30000000, 4, 8, 1.0, "
12194 "2.0, 'abc', 'def', now(), now(), now())";
12195 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12198 stmt_text=
"select * from t1";
12201 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12203 query_result= mysql_store_result(mysql);
12204 query_field_list= mysql_fetch_fields(query_result);
12205 query_field_count= mysql_num_fields(query_result);
12207 stmt= mysql_stmt_init(mysql);
12208 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
12209 check_execute(stmt, rc);
12210 rc= mysql_stmt_execute(stmt);
12211 check_execute(stmt, rc);
12212 mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH,
12213 (
void*) &update_max_length);
12214 mysql_stmt_store_result(stmt);
12215 stmt_metadata= mysql_stmt_result_metadata(stmt);
12216 stmt_field_list= mysql_fetch_fields(stmt_metadata);
12217 stmt_field_count= mysql_num_fields(stmt_metadata);
12218 DIE_UNLESS(stmt_field_count == query_field_count);
12224 printf(
" ------------------------------------------------------------\n");
12225 printf(
" | Metadata \n");
12226 printf(
" ------------------------------------------------------------\n");
12227 printf(
" | Query | Prepared statement \n");
12228 printf(
" ------------------------------------------------------------\n");
12229 printf(
" field name | length | max_length | length | max_length\n");
12230 printf(
" ------------------------------------------------------------\n");
12232 for (i= 0; i < query_field_count; ++
i)
12234 MYSQL_FIELD *f1= &query_field_list[
i], *f2= &stmt_field_list[
i];
12235 printf(
" %-11s | %9lu | %10lu | %9lu | %10lu \n",
12236 f1->name, f1->length, f1->max_length, f2->length, f2->max_length);
12237 DIE_UNLESS(f1->length == f2->length);
12239 printf(
" ---------------------------------------------------------------\n");
12244 memset(my_bind, 0,
sizeof(my_bind));
12245 for (i= 0; i < stmt_field_count; ++
i)
12247 my_bind[
i].buffer_type= MYSQL_TYPE_STRING;
12248 my_bind[
i].buffer_length= stmt_field_list[
i].max_length + 1;
12249 my_bind[
i].buffer= malloc(my_bind[i].buffer_length);
12251 mysql_stmt_bind_result(stmt, my_bind);
12252 rc= mysql_stmt_fetch(stmt);
12253 check_execute(stmt, rc);
12254 rc= mysql_stmt_fetch(stmt);
12255 DIE_UNLESS(rc == MYSQL_NO_DATA);
12259 for (i= 0; i < stmt_field_count; ++
i)
12260 free(my_bind[i].buffer);
12261 mysql_stmt_close(stmt);
12262 mysql_free_result(query_result);
12263 mysql_free_result(stmt_metadata);
12264 stmt_text=
"drop table t1";
12265 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12275 static void test_datetime_ranges()
12277 const char *stmt_text;
12283 myheader(
"test_datetime_ranges");
12285 stmt_text=
"drop table if exists t1";
12286 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12289 stmt_text=
"create table t1 (year datetime, month datetime, day datetime, "
12290 "hour datetime, min datetime, sec datetime)";
12291 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12294 stmt= mysql_simple_prepare(mysql,
12295 "INSERT INTO t1 VALUES (?, ?, ?, ?, ?, ?)");
12297 verify_param_count(stmt, 6);
12299 memset(my_bind, 0,
sizeof(my_bind));
12300 for (i= 0; i < 6; i++)
12302 my_bind[
i].buffer_type= MYSQL_TYPE_DATETIME;
12303 my_bind[
i].buffer= &tm[
i];
12305 rc= mysql_stmt_bind_param(stmt, my_bind);
12306 check_execute(stmt, rc);
12308 tm[0].year= 2004; tm[0].month= 11; tm[0].day= 10;
12309 tm[0].hour= 12; tm[0].minute= 30; tm[0].second= 30;
12312 tm[5]= tm[4]= tm[3]= tm[2]= tm[1]= tm[0];
12313 tm[0].year= 10000; tm[1].month= 13; tm[2].day= 32;
12314 tm[3].hour= 24; tm[4].minute= 60; tm[5].second= 60;
12316 rc= mysql_stmt_execute(stmt);
12317 check_execute(stmt, rc);
12318 my_process_warnings(mysql, 12);
12320 verify_col_data(
"t1",
"year",
"0000-00-00 00:00:00");
12321 verify_col_data(
"t1",
"month",
"0000-00-00 00:00:00");
12322 verify_col_data(
"t1",
"day",
"0000-00-00 00:00:00");
12323 verify_col_data(
"t1",
"hour",
"0000-00-00 00:00:00");
12324 verify_col_data(
"t1",
"min",
"0000-00-00 00:00:00");
12325 verify_col_data(
"t1",
"sec",
"0000-00-00 00:00:00");
12327 mysql_stmt_close(stmt);
12329 stmt_text=
"delete from t1";
12330 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12333 stmt= mysql_simple_prepare(mysql,
"INSERT INTO t1 (year, month, day) "
12334 "VALUES (?, ?, ?)");
12336 verify_param_count(stmt, 3);
12341 for (i= 0; i < 3; i++)
12342 my_bind[i].buffer_type= MYSQL_TYPE_DATE;
12344 rc= mysql_stmt_bind_param(stmt, my_bind);
12345 check_execute(stmt, rc);
12347 rc= mysql_stmt_execute(stmt);
12348 check_execute(stmt, rc);
12349 my_process_warnings(mysql, 6);
12351 verify_col_data(
"t1",
"year",
"0000-00-00 00:00:00");
12352 verify_col_data(
"t1",
"month",
"0000-00-00 00:00:00");
12353 verify_col_data(
"t1",
"day",
"0000-00-00 00:00:00");
12355 mysql_stmt_close(stmt);
12357 stmt_text=
"drop table t1";
12358 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12361 stmt_text=
"create table t1 (day_ovfl time, day time, hour time, min time, sec time)";
12362 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12365 stmt= mysql_simple_prepare(mysql,
12366 "INSERT INTO t1 VALUES (?, ?, ?, ?, ?)");
12368 verify_param_count(stmt, 5);
12373 for (i= 0; i < 5; i++)
12374 my_bind[i].buffer_type= MYSQL_TYPE_TIME;
12376 rc= mysql_stmt_bind_param(stmt, my_bind);
12377 check_execute(stmt, rc);
12379 tm[0].year= 0; tm[0].month= 0; tm[0].day= 10;
12380 tm[0].hour= 12; tm[0].minute= 30; tm[0].second= 30;
12383 tm[4]= tm[3]= tm[2]= tm[1]= tm[0];
12384 tm[0].day= 35; tm[1].day= 34; tm[2].hour= 30; tm[3].minute= 60; tm[4].second= 60;
12386 rc= mysql_stmt_execute(stmt);
12387 check_execute(stmt, rc);
12388 my_process_warnings(mysql, 2);
12390 verify_col_data(
"t1",
"day_ovfl",
"838:59:59");
12391 verify_col_data(
"t1",
"day",
"828:30:30");
12392 verify_col_data(
"t1",
"hour",
"270:30:30");
12393 verify_col_data(
"t1",
"min",
"00:00:00");
12394 verify_col_data(
"t1",
"sec",
"00:00:00");
12396 mysql_stmt_close(stmt);
12398 stmt_text=
"drop table t1";
12399 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12404 static void test_bug4172()
12408 const char *stmt_text;
12412 char f[100], d[100], e[100];
12413 ulong f_len, d_len, e_len;
12415 myheader(
"test_bug4172");
12417 mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
12418 mysql_query(mysql,
"CREATE TABLE t1 (f float, d double, e decimal(10,4))");
12419 mysql_query(mysql,
"INSERT INTO t1 VALUES (12345.1234, 123456.123456, "
12422 stmt= mysql_stmt_init(mysql);
12423 stmt_text=
"SELECT f, d, e FROM t1";
12425 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
12426 check_execute(stmt, rc);
12427 rc= mysql_stmt_execute(stmt);
12428 check_execute(stmt, rc);
12430 memset(my_bind, 0,
sizeof(my_bind));
12431 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
12432 my_bind[0].buffer= f;
12433 my_bind[0].buffer_length=
sizeof(f);
12434 my_bind[0].length= &f_len;
12435 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
12436 my_bind[1].buffer= d;
12437 my_bind[1].buffer_length=
sizeof(d);
12438 my_bind[1].length= &d_len;
12439 my_bind[2].buffer_type= MYSQL_TYPE_STRING;
12440 my_bind[2].buffer= e;
12441 my_bind[2].buffer_length=
sizeof(e);
12442 my_bind[2].length= &e_len;
12444 mysql_stmt_bind_result(stmt, my_bind);
12446 mysql_stmt_store_result(stmt);
12447 rc= mysql_stmt_fetch(stmt);
12448 check_execute(stmt, rc);
12450 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12452 res= mysql_store_result(mysql);
12453 row= mysql_fetch_row(res);
12457 printf(
"Binary protocol: float=%s, double=%s, decimal(10,4)=%s\n",
12459 printf(
"Text protocol: float=%s, double=%s, decimal(10,4)=%s\n",
12460 row[0], row[1], row[2]);
12462 DIE_UNLESS(!strcmp(f, row[0]) && !strcmp(d, row[1]) && !strcmp(e, row[2]));
12464 mysql_free_result(res);
12465 mysql_stmt_close(stmt);
12469 static void test_conversion()
12472 const char *stmt_text;
12478 myheader(
"test_conversion");
12480 stmt_text=
"DROP TABLE IF EXISTS t1";
12481 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12483 stmt_text=
"CREATE TABLE t1 (a TEXT) DEFAULT CHARSET latin1";
12484 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12486 stmt_text=
"SET character_set_connection=utf8, character_set_client=utf8, "
12487 " character_set_results=latin1";
12488 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12491 stmt= mysql_stmt_init(mysql);
12493 stmt_text=
"INSERT INTO t1 (a) VALUES (?)";
12494 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
12495 check_execute(stmt, rc);
12497 memset(my_bind, 0,
sizeof(my_bind));
12498 my_bind[0].buffer= buff;
12499 my_bind[0].length= &length;
12500 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
12502 mysql_stmt_bind_param(stmt, my_bind);
12504 buff[0]= (uchar) 0xC3;
12505 buff[1]= (uchar) 0xA0;
12508 rc= mysql_stmt_execute(stmt);
12509 check_execute(stmt, rc);
12511 stmt_text=
"SELECT a FROM t1";
12512 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
12513 check_execute(stmt, rc);
12514 rc= mysql_stmt_execute(stmt);
12515 check_execute(stmt, rc);
12517 my_bind[0].buffer_length=
sizeof(buff);
12518 mysql_stmt_bind_result(stmt, my_bind);
12520 rc= mysql_stmt_fetch(stmt);
12521 DIE_UNLESS(rc == 0);
12522 DIE_UNLESS(length == 1);
12523 DIE_UNLESS((uchar) buff[0] == 0xE0);
12524 rc= mysql_stmt_fetch(stmt);
12525 DIE_UNLESS(rc == MYSQL_NO_DATA);
12527 mysql_stmt_close(stmt);
12528 stmt_text=
"DROP TABLE t1";
12529 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12531 stmt_text=
"SET NAMES DEFAULT";
12532 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12536 static void test_rewind(
void)
12541 const char *stmt_text;
12542 long unsigned int length=4,
Data=0;
12545 myheader(
"test_rewind");
12547 stmt_text=
"CREATE TABLE t1 (a int)";
12548 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12550 stmt_text=
"INSERT INTO t1 VALUES(2),(3),(4)";
12551 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12554 stmt= mysql_stmt_init(mysql);
12556 stmt_text=
"SELECT * FROM t1";
12557 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
12558 check_execute(stmt, rc);
12561 my_bind.buffer_type= MYSQL_TYPE_LONG;
12562 my_bind.buffer= (
void *)&
Data;
12563 my_bind.length= &length;
12564 my_bind.is_null= &isnull;
12566 rc= mysql_stmt_execute(stmt);
12567 check_execute(stmt, rc);
12569 rc= mysql_stmt_store_result(stmt);
12570 DIE_UNLESS(rc == 0);
12572 rc= mysql_stmt_bind_result(stmt, &my_bind);
12573 DIE_UNLESS(rc == 0);
12576 while(!mysql_stmt_fetch(stmt))
12578 printf(
"fetched result:%ld\n",
Data);
12580 DIE_UNLESS(rc != MYSQL_NO_DATA);
12583 mysql_stmt_data_seek(stmt, 0);
12587 while(!(rc= mysql_stmt_fetch(stmt)))
12589 printf(
"fetched result after seek:%ld\n",
Data);
12591 DIE_UNLESS(rc == MYSQL_NO_DATA);
12593 stmt_text=
"DROP TABLE t1";
12594 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12596 rc= mysql_stmt_free_result(stmt);
12597 rc= mysql_stmt_close(stmt);
12601 static void test_truncation()
12604 const char *stmt_text;
12609 myheader(
"test_truncation");
12612 rc= mysql_query(mysql,
"drop table if exists t1");
12615 stmt_text=
"create table t1 ("
12616 "i8 tinyint, ui8 tinyint unsigned, "
12617 "i16 smallint, i16_1 smallint, "
12618 "ui16 smallint unsigned, i32 int, i32_1 int, "
12619 "d double, d_1 double, ch char(30), ch_1 char(30), "
12620 "tx text, tx_1 text, ch_2 char(30) "
12622 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12626 const char insert_text[]=
12627 "insert into t1 VALUES ("
12637 "'111111111111111111111111111111',"
12643 rc= mysql_real_query(mysql, insert_text, strlen(insert_text));
12647 stmt_text=
"select i8 c1, i8 c2, ui8 c3, i16_1 c4, ui16 c5, "
12648 " i16 c6, ui16 c7, i32 c8, i32_1 c9, i32_1 c10, "
12649 " d c11, d_1 c12, d_1 c13, ch c14, ch_1 c15, tx c16, "
12650 " tx_1 c17, ch_2 c18 "
12653 stmt= mysql_stmt_init(mysql);
12654 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
12655 check_execute(stmt, rc);
12656 rc= mysql_stmt_execute(stmt);
12657 check_execute(stmt, rc);
12658 bind_count= (uint) mysql_stmt_field_count(stmt);
12661 bind_array= malloc(
sizeof(
MYSQL_BIND) * bind_count);
12662 memset(bind_array, 0,
sizeof(
MYSQL_BIND) * bind_count);
12663 for (my_bind= bind_array; my_bind < bind_array + bind_count; my_bind++)
12664 my_bind->error= &my_bind->error_value;
12665 my_bind= bind_array;
12667 my_bind->buffer= malloc(
sizeof(uint8));
12668 my_bind->buffer_type= MYSQL_TYPE_TINY;
12669 my_bind->is_unsigned= TRUE;
12671 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12672 my_bind->buffer= malloc(
sizeof(uint32));
12673 my_bind->buffer_type= MYSQL_TYPE_LONG;
12674 my_bind->is_unsigned= TRUE;
12676 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12677 my_bind->buffer= malloc(
sizeof(int8));
12678 my_bind->buffer_type= MYSQL_TYPE_TINY;
12680 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12681 my_bind->buffer= malloc(
sizeof(uint16));
12682 my_bind->buffer_type= MYSQL_TYPE_SHORT;
12683 my_bind->is_unsigned= TRUE;
12685 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12686 my_bind->buffer= malloc(
sizeof(int16));
12687 my_bind->buffer_type= MYSQL_TYPE_SHORT;
12689 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12690 my_bind->buffer= malloc(
sizeof(uint16));
12691 my_bind->buffer_type= MYSQL_TYPE_SHORT;
12692 my_bind->is_unsigned= TRUE;
12694 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12695 my_bind->buffer= malloc(
sizeof(int8));
12696 my_bind->buffer_type= MYSQL_TYPE_TINY;
12697 my_bind->is_unsigned= TRUE;
12699 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12700 my_bind->buffer= malloc(
sizeof(
float));
12701 my_bind->buffer_type= MYSQL_TYPE_FLOAT;
12703 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12704 my_bind->buffer= malloc(
sizeof(
float));
12705 my_bind->buffer_type= MYSQL_TYPE_FLOAT;
12707 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12708 my_bind->buffer= malloc(
sizeof(
double));
12709 my_bind->buffer_type= MYSQL_TYPE_DOUBLE;
12711 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12712 my_bind->buffer= malloc(
sizeof(longlong));
12713 my_bind->buffer_type= MYSQL_TYPE_LONGLONG;
12715 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12716 my_bind->buffer= malloc(
sizeof(ulonglong));
12717 my_bind->buffer_type= MYSQL_TYPE_LONGLONG;
12718 my_bind->is_unsigned= TRUE;
12720 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12721 my_bind->buffer= malloc(
sizeof(longlong));
12722 my_bind->buffer_type= MYSQL_TYPE_LONGLONG;
12724 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12725 my_bind->buffer= malloc(
sizeof(longlong));
12726 my_bind->buffer_type= MYSQL_TYPE_LONGLONG;
12728 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12729 my_bind->buffer= malloc(
sizeof(longlong));
12730 my_bind->buffer_type= MYSQL_TYPE_LONGLONG;
12732 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12733 my_bind->buffer= malloc(
sizeof(longlong));
12734 my_bind->buffer_type= MYSQL_TYPE_LONGLONG;
12736 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12737 my_bind->buffer= malloc(
sizeof(
double));
12738 my_bind->buffer_type= MYSQL_TYPE_DOUBLE;
12740 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12741 my_bind->buffer= malloc(
sizeof(
double));
12742 my_bind->buffer_type= MYSQL_TYPE_DOUBLE;
12744 rc= mysql_stmt_bind_result(stmt, bind_array);
12745 check_execute(stmt, rc);
12746 rc= mysql_stmt_fetch(stmt);
12747 DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED);
12750 my_bind= bind_array;
12753 DIE_UNLESS(*my_bind->error && * (int8*) my_bind->buffer == -10);
12756 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12757 DIE_UNLESS(*my_bind->error && * (int32*) my_bind->buffer == -10);
12760 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12761 DIE_UNLESS(*my_bind->error && * (uint8*) my_bind->buffer == 200);
12764 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12765 DIE_UNLESS(*my_bind->error && * (int16*) my_bind->buffer == -32767);
12768 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12769 DIE_UNLESS(*my_bind->error && * (uint16*) my_bind->buffer == 64000);
12772 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12773 DIE_UNLESS(! *my_bind->error && * (uint16*) my_bind->buffer == 32000);
12776 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12777 DIE_UNLESS(*my_bind->error && * (int8*) my_bind->buffer == 0);
12780 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12781 DIE_UNLESS(! *my_bind->error && * (
float*) my_bind->buffer == 1073741824);
12784 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12785 DIE_UNLESS(*my_bind->error);
12788 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12789 DIE_UNLESS(! *my_bind->error && * (
double*) my_bind->buffer == 1073741825);
12792 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12795 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12797 DIE_UNLESS(*my_bind->error);
12800 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12801 DIE_UNLESS(! *my_bind->error && * (longlong*) my_bind->buffer == LL(-12345678910));
12804 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12805 DIE_UNLESS(*my_bind->error);
12808 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12809 DIE_UNLESS(*my_bind->error && *(longlong*) my_bind->buffer == 0);
12812 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12813 DIE_UNLESS(! *my_bind->error && *(longlong*) my_bind->buffer == 12345);
12816 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12817 DIE_UNLESS(! *my_bind->error && *(
double*) my_bind->buffer == 12345.67);
12820 DIE_UNLESS(my_bind++ < bind_array + bind_count);
12825 DIE_UNLESS(*(
double*) my_bind->buffer == 12345.67);
12836 mysql_stmt_close(stmt);
12838 for (my_bind= bind_array; my_bind < bind_array + bind_count; my_bind++)
12839 free(my_bind->buffer);
12842 rc= mysql_query(mysql,
"drop table t1");
12846 static void test_truncation_option()
12849 const char *stmt_text;
12856 myheader(
"test_truncation_option");
12859 stmt_text=
"select -1";
12861 stmt= mysql_stmt_init(mysql);
12862 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
12863 check_execute(stmt, rc);
12864 rc= mysql_stmt_execute(stmt);
12865 check_execute(stmt, rc);
12867 memset(&my_bind, 0,
sizeof(my_bind));
12869 my_bind.buffer= (
void*) &buf;
12870 my_bind.buffer_type= MYSQL_TYPE_TINY;
12871 my_bind.is_unsigned= TRUE;
12872 my_bind.error= &error;
12874 rc= mysql_stmt_bind_result(stmt, &my_bind);
12875 check_execute(stmt, rc);
12876 rc= mysql_stmt_fetch(stmt);
12877 DIE_UNLESS(rc == MYSQL_DATA_TRUNCATED);
12879 rc= mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, (
char*) &option);
12882 rc= mysql_stmt_bind_result(stmt, &my_bind);
12883 check_execute(stmt, rc);
12884 rc= mysql_stmt_execute(stmt);
12885 check_execute(stmt, rc);
12886 rc= mysql_stmt_fetch(stmt);
12887 check_execute(stmt, rc);
12889 DIE_UNLESS(error == 1);
12892 mysql_options(mysql, MYSQL_REPORT_DATA_TRUNCATION, (
char*) &option);
12894 mysql_stmt_close(stmt);
12900 static void test_bug6761(
void)
12902 const char *stmt_text;
12905 myheader(
"test_bug6761");
12907 stmt_text=
"CREATE TABLE t1 (a int, b char(255), c decimal)";
12908 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12911 res= mysql_list_fields(mysql,
"t1",
"%");
12912 DIE_UNLESS(res && mysql_num_fields(res) == 3);
12913 mysql_free_result(res);
12915 stmt_text=
"DROP TABLE t1";
12916 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12923 static void test_bug8330()
12925 const char *stmt_text;
12928 const char *query=
"select a,b from t1 where a=?";
12932 myheader(
"test_bug8330");
12934 stmt_text=
"drop table if exists t1";
12936 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12938 stmt_text=
"create table t1 (a int, b int)";
12939 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12942 memset(my_bind, 0,
sizeof(my_bind));
12943 for (i=0; i < 2; i++)
12945 stmt[
i]= mysql_stmt_init(mysql);
12946 rc= mysql_stmt_prepare(stmt[i], query, strlen(query));
12947 check_execute(stmt[i], rc);
12949 my_bind[
i].buffer_type= MYSQL_TYPE_LONG;
12950 my_bind[
i].buffer= (
void*) &lval[i];
12951 my_bind[
i].is_null= 0;
12952 mysql_stmt_bind_param(stmt[i], &my_bind[i]);
12955 rc= mysql_stmt_execute(stmt[0]);
12956 check_execute(stmt[0], rc);
12958 rc= mysql_stmt_execute(stmt[1]);
12959 DIE_UNLESS(rc && mysql_stmt_errno(stmt[1]) == CR_COMMANDS_OUT_OF_SYNC);
12960 rc= mysql_stmt_execute(stmt[0]);
12961 check_execute(stmt[0], rc);
12963 mysql_stmt_close(stmt[0]);
12964 mysql_stmt_close(stmt[1]);
12966 stmt_text=
"drop table t1";
12967 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
12974 static void test_bug7990()
12978 myheader(
"test_bug7990");
12980 stmt= mysql_stmt_init(mysql);
12981 rc= mysql_stmt_prepare(stmt,
"foo", 3);
12986 DIE_UNLESS(rc && mysql_stmt_errno(stmt) && mysql_errno(mysql));
12987 mysql_stmt_close(stmt);
12988 DIE_UNLESS(!mysql_errno(mysql));
12996 static void test_bug15518()
13001 myheader(
"test_bug15518");
13003 mysql1= mysql_client_init(NULL);
13005 if (!mysql_real_connect(mysql1, opt_host, opt_user, opt_password,
13006 opt_db ? opt_db :
"test", opt_port, opt_unix_socket,
13007 CLIENT_MULTI_STATEMENTS))
13009 fprintf(stderr,
"Failed to connect to the database\n");
13013 stmt= mysql_stmt_init(mysql1);
13019 rc= mysql_stmt_prepare(stmt,
"foo", 3);
13021 fprintf(stdout,
"rc: %d, mysql_stmt_errno: %d, mysql_errno: %d\n",
13022 rc, mysql_stmt_errno(stmt), mysql_errno(mysql1));
13023 DIE_UNLESS(rc && mysql_stmt_errno(stmt) && mysql_errno(mysql1));
13029 rc= mysql_stmt_prepare(stmt,
"SHOW STATUS", 12);
13031 fprintf(stdout,
"rc: %d, mysql_stmt_errno: %d, mysql_errno: %d\n",
13032 rc, mysql_stmt_errno(stmt), mysql_errno(mysql1));
13033 DIE_UNLESS(!rc || mysql_stmt_errno(stmt) || mysql_errno(mysql1));
13035 mysql_stmt_close(stmt);
13036 DIE_UNLESS(!mysql_errno(mysql1));
13042 stmt= mysql_stmt_init(mysql1);
13043 rc= mysql_stmt_prepare(stmt,
"foo", 3);
13045 fprintf(stdout,
"rc: %d, mysql_stmt_errno: %d, mysql_errno: %d\n",
13046 rc, mysql_stmt_errno(stmt), mysql_errno(mysql1));
13047 DIE_UNLESS(rc && mysql_stmt_errno(stmt) && mysql_errno(mysql1));
13050 mysql_close(mysql1);
13057 rc= mysql_stmt_prepare(stmt,
"SHOW STATUS", 12);
13059 fprintf(stdout,
"rc: %d, mysql_stmt_errno: %d\n",
13060 rc, mysql_stmt_errno(stmt));
13061 DIE_UNLESS(rc && mysql_stmt_errno(stmt));
13063 mysql_stmt_close(stmt);
13067 static void disable_query_logs()
13070 rc= mysql_query(mysql,
"set @@global.general_log=off");
13072 rc= mysql_query(mysql,
"set @@global.slow_query_log=off");
13077 static void enable_query_logs(
int truncate)
13081 rc= mysql_query(mysql,
"set @save_global_general_log=@@global.general_log");
13084 rc= mysql_query(mysql,
"set @save_global_slow_query_log=@@global.slow_query_log");
13087 rc= mysql_query(mysql,
"set @@global.general_log=on");
13090 rc= mysql_query(mysql,
"set @@global.slow_query_log=on");
13096 rc= mysql_query(mysql,
"truncate mysql.general_log");
13099 rc= mysql_query(mysql,
"truncate mysql.slow_log");
13105 static void restore_query_logs()
13108 rc= mysql_query(mysql,
"set @@global.general_log=@save_global_general_log");
13111 rc= mysql_query(mysql,
"set @@global.slow_query_log=@save_global_slow_query_log");
13116 static void test_view_sp_list_fields()
13121 myheader(
"test_view_sp_list_fields");
13123 rc= mysql_query(mysql,
"DROP FUNCTION IF EXISTS f1");
13125 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS v1, t1, t2");
13127 rc= mysql_query(mysql,
"DROP VIEW IF EXISTS v1, t1, t2");
13129 rc= mysql_query(mysql,
"create function f1 () returns int return 5");
13131 rc= mysql_query(mysql,
"create table t1 (s1 char,s2 char)");
13133 rc= mysql_query(mysql,
"create table t2 (s1 int);");
13135 rc= mysql_query(mysql,
"create view v1 as select s2,sum(s1) - \
13136 count(s2) as vx from t1 group by s2 having sum(s1) - count(s2) < (select f1() \
13139 res= mysql_list_fields(mysql,
"v1", NullS);
13140 DIE_UNLESS(res != 0 && mysql_num_fields(res) != 0);
13141 rc= mysql_query(mysql,
"DROP FUNCTION f1");
13143 rc= mysql_query(mysql,
"DROP VIEW v1");
13145 rc= mysql_query(mysql,
"DROP TABLE t1, t2");
13146 mysql_free_result(res);
13159 #define TEST_BUG8378_IN "\xef\xbb\xbf\x27\xbf\x10"
13160 #define TEST_BUG8378_OUT "\xef\xbb\x5c\xbf\x5c\x27\x5c\xbf\x10"
13162 static void test_bug8378()
13164 #if defined(HAVE_CHARSET_gbk) && !defined(EMBEDDED_LIBRARY)
13170 myheader(
"test_bug8378");
13173 fprintf(stdout,
"\n Establishing a test connection ...");
13174 if (!(lmysql= mysql_client_init(NULL)))
13176 myerror(
"mysql_client_init() failed");
13179 if (mysql_options(lmysql, MYSQL_SET_CHARSET_NAME,
"gbk"))
13181 myerror(
"mysql_options() failed");
13184 if (!(mysql_real_connect(lmysql, opt_host, opt_user,
13185 opt_password, current_db, opt_port,
13186 opt_unix_socket, 0)))
13188 myerror(
"connection failed");
13192 fprintf(stdout,
"OK");
13194 rc= mysql_query(lmysql,
"SET SQL_MODE=''");
13197 len= mysql_real_escape_string(lmysql, out, TEST_BUG8378_IN, 4);
13200 DIE_UNLESS(memcmp(out, TEST_BUG8378_OUT, len) == 0);
13202 sprintf(buf,
"SELECT '%s'", out);
13204 rc=mysql_real_query(lmysql, buf, strlen(buf));
13207 mysql_close(lmysql);
13212 static void test_bug8722()
13216 const char *stmt_text;
13218 myheader(
"test_bug8722");
13220 stmt_text=
"drop table if exists t1, v1";
13221 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
13223 stmt_text=
"CREATE TABLE t1 (c1 varchar(10), c2 varchar(10), c3 varchar(10),"
13224 " c4 varchar(10), c5 varchar(10), c6 varchar(10),"
13225 " c7 varchar(10), c8 varchar(10), c9 varchar(10),"
13226 "c10 varchar(10))";
13227 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
13229 stmt_text=
"INSERT INTO t1 VALUES (1,2,3,4,5,6,7,8,9,10)";
13230 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
13232 stmt_text=
"CREATE VIEW v1 AS SELECT * FROM t1";
13233 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
13242 stmt= mysql_stmt_init(mysql);
13243 stmt_text=
"select * from v1";
13244 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
13245 check_execute(stmt, rc);
13246 mysql_stmt_close(stmt);
13247 stmt_text=
"drop table if exists t1, v1";
13248 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
13256 const ulong type= (ulong)CURSOR_TYPE_READ_ONLY;
13259 rc= mysql_stmt_prepare(stmt, query, strlen(query));
13260 check_execute(stmt, rc);
13262 mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
void*) &type);
13267 static void test_bug8880()
13273 myheader(
"test_bug8880");
13275 mysql_query(mysql,
"drop table if exists t1");
13276 mysql_query(mysql,
"create table t1 (a int not null primary key, b int)");
13277 rc= mysql_query(mysql,
"insert into t1 values (1,1)");
13283 for (stmt= stmt_list; stmt < stmt_list_end; stmt++)
13284 *stmt= open_cursor(
"select a from t1");
13285 for (stmt= stmt_list; stmt < stmt_list_end; stmt++)
13287 rc= mysql_stmt_execute(*stmt);
13288 check_execute(*stmt, rc);
13290 for (stmt= stmt_list; stmt < stmt_list_end; stmt++)
13291 mysql_stmt_close(*stmt);
13295 static void test_bug9159()
13299 const char *stmt_text=
"select a, b from t1";
13300 const unsigned long type= CURSOR_TYPE_READ_ONLY;
13302 myheader(
"test_bug9159");
13304 mysql_query(mysql,
"drop table if exists t1");
13305 mysql_query(mysql,
"create table t1 (a int not null primary key, b int)");
13306 rc= mysql_query(mysql,
"insert into t1 values (1,1)");
13309 stmt= mysql_stmt_init(mysql);
13310 mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
13311 mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
const void *)&type);
13313 mysql_stmt_execute(stmt);
13314 mysql_stmt_close(stmt);
13315 rc= mysql_query(mysql,
"drop table if exists t1");
13322 static void test_bug9520()
13328 int rc, row_count= 0;
13330 myheader(
"test_bug9520");
13332 mysql_query(mysql,
"drop table if exists t1");
13333 mysql_query(mysql,
"create table t1 (a char(5), b char(5), c char(5),"
13334 " primary key (a, b, c))");
13335 rc= mysql_query(mysql,
"insert into t1 values ('x', 'y', 'z'), "
13336 " ('a', 'b', 'c'), ('k', 'l', 'm')");
13339 stmt= open_cursor(
"select distinct b from t1");
13346 rc= mysql_stmt_execute(stmt);
13347 check_execute(stmt, rc);
13349 memset(my_bind, 0,
sizeof(my_bind));
13350 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
13351 my_bind[0].buffer= (
char*) a;
13352 my_bind[0].buffer_length=
sizeof(a);
13353 my_bind[0].length= &a_len;
13355 mysql_stmt_bind_result(stmt, my_bind);
13357 while (!(rc= mysql_stmt_fetch(stmt)))
13360 DIE_UNLESS(rc == MYSQL_NO_DATA);
13363 printf(
"Fetched %d rows\n", row_count);
13364 DBUG_ASSERT(row_count == 3);
13366 mysql_stmt_close(stmt);
13368 rc= mysql_query(mysql,
"drop table t1");
13379 static void test_bug9478()
13386 DBUG_ENTER(
"test_bug9478");
13388 myheader(
"test_bug9478");
13390 mysql_query(mysql,
"drop table if exists t1");
13391 mysql_query(mysql,
"create table t1 (id integer not null primary key, "
13392 " name varchar(20) not null)");
13393 rc= mysql_query(mysql,
"insert into t1 (id, name) values "
13394 " (1, 'aaa'), (2, 'bbb'), (3, 'ccc')");
13397 stmt= open_cursor(
"select name from t1 where id=2");
13399 memset(my_bind, 0,
sizeof(my_bind));
13400 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
13401 my_bind[0].buffer= (
char*) a;
13402 my_bind[0].buffer_length=
sizeof(a);
13403 my_bind[0].length= &a_len;
13404 mysql_stmt_bind_result(stmt, my_bind);
13406 for (i= 0; i < 5; i++)
13408 rc= mysql_stmt_execute(stmt);
13409 check_execute(stmt, rc);
13410 rc= mysql_stmt_fetch(stmt);
13411 check_execute(stmt, rc);
13412 if (!opt_silent && i == 0)
13413 printf(
"Fetched row: %s\n", a);
13424 rc= mysql_stmt_execute(stmt);
13425 check_execute(stmt, rc);
13427 rc= mysql_stmt_fetch(stmt);
13428 check_execute(stmt, rc);
13429 if (!opt_silent && i == 0)
13430 printf(
"Fetched row: %s\n", a);
13431 rc= mysql_stmt_fetch(stmt);
13432 DIE_UNLESS(rc == MYSQL_NO_DATA);
13437 int4store(buff, stmt->stmt_id);
13439 rc= ((*mysql->methods->advanced_command)(mysql, COM_STMT_FETCH,
13441 sizeof(buff), 0,0,1,NULL) ||
13442 (*mysql->methods->read_query_result)(mysql));
13444 if (!opt_silent && i == 0)
13445 printf(
"Got error (as expected): %s\n", mysql_error(mysql));
13448 rc= mysql_stmt_execute(stmt);
13449 check_execute(stmt, rc);
13451 rc= mysql_stmt_fetch(stmt);
13452 check_execute(stmt, rc);
13453 if (!opt_silent && i == 0)
13454 printf(
"Fetched row: %s\n", a);
13456 rc= mysql_stmt_reset(stmt);
13457 check_execute(stmt, rc);
13458 rc= mysql_stmt_fetch(stmt);
13459 DIE_UNLESS(rc && mysql_stmt_errno(stmt));
13460 if (!opt_silent && i == 0)
13461 printf(
"Got error (as expected): %s\n", mysql_stmt_error(stmt));
13463 rc= mysql_stmt_close(stmt);
13464 DIE_UNLESS(rc == 0);
13467 stmt= open_cursor(
"select name from t1");
13469 mysql_stmt_bind_result(stmt, my_bind);
13471 for (i= 0; i < 5; i++)
13473 DBUG_PRINT(
"loop",(
"i: %d", i));
13474 rc= mysql_stmt_execute(stmt);
13475 check_execute(stmt, rc);
13476 rc= mysql_stmt_fetch(stmt);
13477 check_execute(stmt, rc);
13478 if (!opt_silent && i == 0)
13479 printf(
"Fetched row: %s\n", a);
13480 rc= mysql_stmt_execute(stmt);
13481 check_execute(stmt, rc);
13483 while (! (rc= mysql_stmt_fetch(stmt)))
13485 if (!opt_silent && i == 0)
13486 printf(
"Fetched row: %s\n", a);
13488 DIE_UNLESS(rc == MYSQL_NO_DATA);
13490 rc= mysql_stmt_execute(stmt);
13491 check_execute(stmt, rc);
13493 rc= mysql_stmt_fetch(stmt);
13494 check_execute(stmt, rc);
13495 if (!opt_silent && i == 0)
13496 printf(
"Fetched row: %s\n", a);
13498 rc= mysql_stmt_reset(stmt);
13499 check_execute(stmt, rc);
13500 rc= mysql_stmt_fetch(stmt);
13501 DIE_UNLESS(rc && mysql_stmt_errno(stmt));
13502 if (!opt_silent && i == 0)
13503 printf(
"Got error (as expected): %s\n", mysql_stmt_error(stmt));
13506 rc= mysql_stmt_close(stmt);
13507 DIE_UNLESS(rc == 0);
13509 rc= mysql_query(mysql,
"drop table t1");
13520 static void test_bug9643()
13526 const char *stmt_text;
13529 ulong prefetch_rows= 5;
13531 myheader(
"test_bug9643");
13533 mysql_query(mysql,
"drop table if exists t1");
13534 mysql_query(mysql,
"create table t1 (id integer not null primary key)");
13535 rc= mysql_query(mysql,
"insert into t1 (id) values "
13536 " (1), (2), (3), (4), (5), (6), (7), (8), (9)");
13539 stmt= mysql_stmt_init(mysql);
13541 type= (ulong) CURSOR_TYPE_SCROLLABLE;
13542 rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
void*) &type);
13545 printf(
"Got error (as expected): %s\n", mysql_stmt_error(stmt));
13547 type= (ulong) CURSOR_TYPE_READ_ONLY;
13548 rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
void*) &type);
13549 check_execute(stmt, rc);
13550 rc= mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS,
13551 (
void*) &prefetch_rows);
13552 check_execute(stmt, rc);
13553 stmt_text=
"select * from t1";
13554 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
13555 check_execute(stmt, rc);
13557 memset(my_bind, 0,
sizeof(my_bind));
13558 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
13559 my_bind[0].buffer= (
void*) &a;
13560 my_bind[0].buffer_length=
sizeof(a);
13561 mysql_stmt_bind_result(stmt, my_bind);
13563 rc= mysql_stmt_execute(stmt);
13564 check_execute(stmt, rc);
13566 while ((rc= mysql_stmt_fetch(stmt)) == 0)
13568 DIE_UNLESS(num_rows == 9);
13570 rc= mysql_stmt_close(stmt);
13571 DIE_UNLESS(rc == 0);
13573 rc= mysql_query(mysql,
"drop table t1");
13581 static void test_bug11111()
13589 const char *query=
"SELECT DISTINCT f1,ff2 FROM v1";
13591 myheader(
"test_bug11111");
13593 rc= mysql_query(mysql,
"drop table if exists t1, t2, v1");
13595 rc= mysql_query(mysql,
"drop view if exists t1, t2, v1");
13597 rc= mysql_query(mysql,
"create table t1 (f1 int, f2 int)");
13599 rc= mysql_query(mysql,
"create table t2 (ff1 int, ff2 int)");
13601 rc= mysql_query(mysql,
"create view v1 as select * from t1, t2 where f1=ff1");
13603 rc= mysql_query(mysql,
"insert into t1 values (1,1), (2,2), (3,3)");
13605 rc= mysql_query(mysql,
"insert into t2 values (1,1), (2,2), (3,3)");
13608 stmt= mysql_stmt_init(mysql);
13610 mysql_stmt_prepare(stmt, query, strlen(query));
13611 mysql_stmt_execute(stmt);
13613 memset(my_bind, 0,
sizeof(my_bind));
13614 for (i=0; i < 2; i++)
13616 my_bind[
i].buffer_type= MYSQL_TYPE_STRING;
13617 my_bind[
i].buffer= (uchar* *)&buf[i];
13618 my_bind[
i].buffer_length= 20;
13619 my_bind[
i].length= &len[
i];
13622 rc= mysql_stmt_bind_result(stmt, my_bind);
13623 check_execute(stmt, rc);
13625 rc= mysql_stmt_fetch(stmt);
13626 check_execute(stmt, rc);
13628 printf(
"return: %s", buf[1]);
13629 DIE_UNLESS(!strcmp(buf[1],
"1"));
13630 mysql_stmt_close(stmt);
13631 rc= mysql_query(mysql,
"drop view v1");
13633 rc= mysql_query(mysql,
"drop table t1, t2");
13642 static void test_bug10729()
13648 const char *stmt_text;
13650 const char *name_array[3]= {
"aaa",
"bbb",
"ccc" };
13653 myheader(
"test_bug10729");
13655 mysql_query(mysql,
"drop table if exists t1");
13656 mysql_query(mysql,
"create table t1 (id integer not null primary key,"
13657 "name VARCHAR(20) NOT NULL)");
13658 rc= mysql_query(mysql,
"insert into t1 (id, name) values "
13659 "(1, 'aaa'), (2, 'bbb'), (3, 'ccc')");
13662 stmt= mysql_stmt_init(mysql);
13664 type= (ulong) CURSOR_TYPE_READ_ONLY;
13665 rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
void*) &type);
13666 check_execute(stmt, rc);
13667 stmt_text=
"select name from t1";
13668 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
13669 check_execute(stmt, rc);
13671 memset(my_bind, 0,
sizeof(my_bind));
13672 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
13673 my_bind[0].buffer= (
void*) a;
13674 my_bind[0].buffer_length=
sizeof(a);
13675 mysql_stmt_bind_result(stmt, my_bind);
13677 for (i= 0; i < 3; i++)
13680 rc= mysql_stmt_execute(stmt);
13681 check_execute(stmt, rc);
13682 while ((rc= mysql_stmt_fetch(stmt)) == 0)
13684 DIE_UNLESS(strcmp(a, name_array[row_no]) == 0);
13686 printf(
"%d: %s\n", row_no, a);
13689 DIE_UNLESS(rc == MYSQL_NO_DATA);
13691 rc= mysql_stmt_close(stmt);
13692 DIE_UNLESS(rc == 0);
13694 rc= mysql_query(mysql,
"drop table t1");
13704 static void test_bug9992()
13710 myheader(
"test_bug9992");
13713 printf(
"Establishing a connection with option CLIENT_MULTI_STATEMENTS..\n");
13715 mysql1= mysql_client_init(NULL);
13717 if (!mysql_real_connect(mysql1, opt_host, opt_user, opt_password,
13718 opt_db ? opt_db :
"test", opt_port, opt_unix_socket,
13719 CLIENT_MULTI_STATEMENTS))
13721 fprintf(stderr,
"Failed to connect to the database\n");
13727 rc= mysql_query(mysql1,
"SHOW TABLES; SHOW DATABASE; SELECT 1;");
13731 fprintf(stderr,
"[%d] %s\n", mysql_errno(mysql1), mysql_error(mysql1));
13736 printf(
"Testing mysql_store_result/mysql_next_result..\n");
13738 res= mysql_store_result(mysql1);
13740 mysql_free_result(res);
13741 rc= mysql_next_result(mysql1);
13742 DIE_UNLESS(rc == 1);
13745 fprintf(stdout,
"Got error, as expected:\n [%d] %s\n",
13746 mysql_errno(mysql1), mysql_error(mysql1));
13748 mysql_close(mysql1);
13753 static void test_bug10736()
13759 const char *stmt_text;
13763 myheader(
"test_bug10736");
13765 mysql_query(mysql,
"drop table if exists t1");
13766 mysql_query(mysql,
"create table t1 (id integer not null primary key,"
13767 "name VARCHAR(20) NOT NULL)");
13768 rc= mysql_query(mysql,
"insert into t1 (id, name) values "
13769 "(1, 'aaa'), (2, 'bbb'), (3, 'ccc')");
13772 stmt= mysql_stmt_init(mysql);
13774 type= (ulong) CURSOR_TYPE_READ_ONLY;
13775 rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
void*) &type);
13776 check_execute(stmt, rc);
13777 stmt_text=
"select name from t1 where name=(select name from t1 where id=2)";
13778 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
13779 check_execute(stmt, rc);
13781 memset(my_bind, 0,
sizeof(my_bind));
13782 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
13783 my_bind[0].buffer= (
void*) a;
13784 my_bind[0].buffer_length=
sizeof(a);
13785 mysql_stmt_bind_result(stmt, my_bind);
13787 for (i= 0; i < 3; i++)
13790 rc= mysql_stmt_execute(stmt);
13791 check_execute(stmt, rc);
13792 while ((rc= mysql_stmt_fetch(stmt)) == 0)
13795 printf(
"%d: %s\n", row_no, a);
13798 DIE_UNLESS(rc == MYSQL_NO_DATA);
13800 rc= mysql_stmt_close(stmt);
13801 DIE_UNLESS(rc == 0);
13803 rc= mysql_query(mysql,
"drop table t1");
13809 static void test_bug10794()
13817 const char *stmt_text;
13821 myheader(
"test_bug10794");
13823 mysql_query(mysql,
"drop table if exists t1");
13824 mysql_query(mysql,
"create table t1 (id integer not null primary key,"
13825 "name varchar(20) not null)");
13826 stmt= mysql_stmt_init(mysql);
13827 stmt_text=
"insert into t1 (id, name) values (?, ?)";
13828 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
13829 check_execute(stmt, rc);
13830 memset(my_bind, 0,
sizeof(my_bind));
13831 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
13832 my_bind[0].buffer= (
void*) &id_val;
13833 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
13834 my_bind[1].buffer= (
void*) a;
13835 my_bind[1].length= &a_len;
13836 rc= mysql_stmt_bind_param(stmt, my_bind);
13837 check_execute(stmt, rc);
13838 for (i= 0; i < 42; i++)
13841 sprintf(a,
"a%d", i);
13843 rc= mysql_stmt_execute(stmt);
13844 check_execute(stmt, rc);
13846 stmt_text=
"select name from t1";
13847 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
13848 type= (ulong) CURSOR_TYPE_READ_ONLY;
13849 mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
const void*) &type);
13850 stmt1= mysql_stmt_init(mysql);
13851 mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (
const void*) &type);
13852 memset(my_bind, 0,
sizeof(my_bind));
13853 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
13854 my_bind[0].buffer= (
void*) a;
13855 my_bind[0].buffer_length=
sizeof(a);
13856 my_bind[0].length= &a_len;
13857 rc= mysql_stmt_bind_result(stmt, my_bind);
13858 check_execute(stmt, rc);
13859 rc= mysql_stmt_execute(stmt);
13860 check_execute(stmt, rc);
13861 rc= mysql_stmt_fetch(stmt);
13862 check_execute(stmt, rc);
13864 printf(
"Fetched row from stmt: %s\n", a);
13866 mysql_stmt_free_result(stmt);
13867 mysql_stmt_reset(stmt);
13868 stmt_text=
"select name from t1 where id=10";
13869 rc= mysql_stmt_prepare(stmt1, stmt_text, strlen(stmt_text));
13870 check_execute(stmt1, rc);
13871 rc= mysql_stmt_bind_result(stmt1, my_bind);
13872 check_execute(stmt1, rc);
13873 rc= mysql_stmt_execute(stmt1);
13876 rc= mysql_stmt_fetch(stmt1);
13877 if (rc == MYSQL_NO_DATA)
13880 printf(
"End of data in stmt1\n");
13883 check_execute(stmt1, rc);
13885 printf(
"Fetched row from stmt1: %s\n", a);
13887 mysql_stmt_close(stmt);
13888 mysql_stmt_close(stmt1);
13890 rc= mysql_query(mysql,
"drop table t1");
13897 static void test_bug11172()
13903 const char *stmt_text;
13907 myheader(
"test_bug11172");
13909 mysql_query(mysql,
"drop table if exists t1");
13910 mysql_query(mysql,
"create table t1 (id integer not null primary key,"
13911 "hired date not null)");
13912 rc= mysql_query(mysql,
13913 "insert into t1 (id, hired) values (1, '1933-08-24'), "
13914 "(2, '1965-01-01'), (3, '1949-08-17'), (4, '1945-07-07'), "
13915 "(5, '1941-05-15'), (6, '1978-09-15'), (7, '1936-03-28')");
13917 stmt= mysql_stmt_init(mysql);
13918 stmt_text=
"SELECT id, hired FROM t1 WHERE hired=?";
13919 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
13920 check_execute(stmt, rc);
13922 type= (ulong) CURSOR_TYPE_READ_ONLY;
13923 mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
const void*) &type);
13925 memset(bind_in, 0,
sizeof(bind_in));
13926 memset(bind_out, 0,
sizeof(bind_out));
13927 memset(&hired, 0,
sizeof(hired));
13931 bind_in[0].buffer_type= MYSQL_TYPE_DATE;
13932 bind_in[0].buffer= (
void*) &hired;
13933 bind_in[0].buffer_length=
sizeof(hired);
13934 bind_out[0].buffer_type= MYSQL_TYPE_LONG;
13935 bind_out[0].buffer= (
void*) &
id;
13936 bind_out[1]= bind_in[0];
13938 for (i= 0; i < 3; i++)
13940 rc= mysql_stmt_bind_param(stmt, bind_in);
13941 check_execute(stmt, rc);
13942 rc= mysql_stmt_bind_result(stmt, bind_out);
13943 check_execute(stmt, rc);
13944 rc= mysql_stmt_execute(stmt);
13945 check_execute(stmt, rc);
13946 while ((rc= mysql_stmt_fetch(stmt)) == 0)
13949 printf(
"fetched data %d:%d-%d-%d\n",
id,
13950 hired.year, hired.month, hired.day);
13952 DIE_UNLESS(rc == MYSQL_NO_DATA);
13953 if (!mysql_stmt_free_result(stmt))
13954 mysql_stmt_reset(stmt);
13956 mysql_stmt_close(stmt);
13957 mysql_rollback(mysql);
13958 mysql_rollback(mysql);
13960 rc= mysql_query(mysql,
"drop table t1");
13967 static void test_bug11656()
13972 const char *stmt_text;
13977 myheader(
"test_bug11656");
13979 mysql_query(mysql,
"drop table if exists t1");
13981 rc= mysql_query(mysql,
"create table t1 ("
13982 "server varchar(40) not null, "
13983 "test_kind varchar(1) not null, "
13984 "test_id varchar(30) not null , "
13985 "primary key (server,test_kind,test_id))");
13988 stmt_text=
"select distinct test_kind, test_id from t1 "
13989 "where server in (?, ?)";
13990 stmt= mysql_stmt_init(mysql);
13991 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
13992 check_execute(stmt, rc);
13993 type= (ulong) CURSOR_TYPE_READ_ONLY;
13994 mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
const void*) &type);
13996 memset(my_bind, 0,
sizeof(my_bind));
13997 strmov(buf[0],
"pcint502_MY2");
13998 strmov(buf[1],
"*");
13999 for (i=0; i < 2; i++)
14001 my_bind[
i].buffer_type= MYSQL_TYPE_STRING;
14002 my_bind[
i].buffer= (uchar* *)&buf[i];
14003 my_bind[
i].buffer_length= strlen(buf[i]);
14005 mysql_stmt_bind_param(stmt, my_bind);
14007 rc= mysql_stmt_execute(stmt);
14008 check_execute(stmt, rc);
14010 rc= mysql_stmt_fetch(stmt);
14011 DIE_UNLESS(rc == MYSQL_NO_DATA);
14013 mysql_stmt_close(stmt);
14014 rc= mysql_query(mysql,
"drop table t1");
14024 static void test_bug10214()
14029 myheader(
"test_bug10214");
14031 DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES));
14033 len= mysql_real_escape_string(mysql, out,
"a'b\\c", 5);
14034 DIE_UNLESS(memcmp(out,
"a\\'b\\\\c", len) == 0);
14036 mysql_query(mysql,
"set sql_mode='NO_BACKSLASH_ESCAPES'");
14037 DIE_UNLESS(mysql->server_status & SERVER_STATUS_NO_BACKSLASH_ESCAPES);
14039 len= mysql_real_escape_string(mysql, out,
"a'b\\c", 5);
14040 DIE_UNLESS(memcmp(out,
"a''b\\c", len) == 0);
14042 mysql_query(mysql,
"set sql_mode=''");
14045 static void test_client_character_set()
14048 char *csname= (
char*)
"utf8";
14049 char *csdefault= (
char*)mysql_character_set_name(mysql);
14052 myheader(
"test_client_character_set");
14054 rc= mysql_set_character_set(mysql, csname);
14055 DIE_UNLESS(rc == 0);
14057 mysql_get_character_set_info(mysql, &cs);
14058 DIE_UNLESS(!strcmp(cs.csname,
"utf8"));
14059 DIE_UNLESS(!strcmp(cs.name,
"utf8_general_ci"));
14061 rc= mysql_set_character_set(mysql, csdefault);
14067 static void test_bug9735()
14072 myheader(
"test_bug9735");
14074 rc= mysql_query(mysql,
"drop table if exists t1");
14076 rc= mysql_query(mysql,
"create table t1 (a mediumtext, b longtext) "
14077 "character set latin1");
14079 rc= mysql_query(mysql,
"select * from t1");
14081 res= mysql_store_result(mysql);
14082 verify_prepare_field(res, 0,
"a",
"a", MYSQL_TYPE_BLOB,
14083 "t1",
"t1", current_db, (1
U << 24)-1, 0);
14084 verify_prepare_field(res, 1,
"b",
"b", MYSQL_TYPE_BLOB,
14085 "t1",
"t1", current_db, ~0
U, 0);
14086 mysql_free_result(res);
14087 rc= mysql_query(mysql,
"drop table t1");
14094 static void test_bug11183()
14098 char bug_statement[]=
"insert into t1 values (1)";
14100 myheader(
"test_bug11183");
14102 mysql_query(mysql,
"drop table t1 if exists");
14103 mysql_query(mysql,
"create table t1 (a int)");
14105 stmt= mysql_stmt_init(mysql);
14106 DIE_UNLESS(stmt != 0);
14108 rc= mysql_stmt_prepare(stmt, bug_statement, strlen(bug_statement));
14109 check_execute(stmt, rc);
14111 rc= mysql_query(mysql,
"drop table t1");
14115 rc= mysql_stmt_execute(stmt);
14118 mysql_stmt_reset(stmt);
14119 DIE_UNLESS(mysql_stmt_errno(stmt) == 0);
14121 mysql_query(mysql,
"create table t1 (a int)");
14124 if (mysql_stmt_execute(stmt))
14126 mysql_stmt_reset(stmt);
14127 DIE_UNLESS(mysql_stmt_errno(stmt) == 0);
14130 mysql_stmt_close(stmt);
14132 rc= mysql_query(mysql,
"drop table t1");
14136 static void test_bug11037()
14140 const char *stmt_text;
14142 myheader(
"test_bug11037");
14144 mysql_query(mysql,
"drop table if exists t1");
14146 rc= mysql_query(mysql,
"create table t1 (id int not null)");
14149 rc= mysql_query(mysql,
"insert into t1 values (1)");
14152 stmt_text=
"select id FROM t1";
14153 stmt= mysql_stmt_init(mysql);
14154 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
14157 rc = mysql_stmt_fetch(stmt);
14160 fprintf(stdout,
"Got error, as expected:\n [%d] %s\n",
14161 mysql_stmt_errno(stmt), mysql_stmt_error(stmt));
14163 rc= mysql_stmt_execute(stmt);
14164 check_execute(stmt, rc);
14166 rc= mysql_stmt_fetch(stmt);
14169 rc= mysql_stmt_fetch(stmt);
14170 DIE_UNLESS(rc==MYSQL_NO_DATA);
14172 rc= mysql_stmt_fetch(stmt);
14173 DIE_UNLESS(rc==MYSQL_NO_DATA);
14175 mysql_stmt_close(stmt);
14176 rc= mysql_query(mysql,
"drop table t1");
14182 static void test_bug10760()
14187 const char *stmt_text;
14193 myheader(
"test_bug10760");
14195 mysql_query(mysql,
"drop table if exists t1, t2");
14198 rc= mysql_query(mysql,
"create table t1 (id integer not null primary key)"
14201 for (; i < 42; ++
i)
14204 sprintf(buf,
"insert into t1 (id) values (%d)", i+1);
14205 rc= mysql_query(mysql, buf);
14208 mysql_autocommit(mysql, FALSE);
14210 stmt= mysql_stmt_init(mysql);
14211 type= (ulong) CURSOR_TYPE_READ_ONLY;
14212 mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
const void*) &type);
14221 stmt_text=
"select id from t1 order by 1";
14222 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
14223 check_execute(stmt, rc);
14224 rc= mysql_stmt_execute(stmt);
14225 check_execute(stmt, rc);
14226 rc= mysql_query(mysql,
"update t1 set id=id+100");
14231 if (rc && !opt_silent)
14232 printf(
"Got error (as expected): %s\n", mysql_error(mysql));
14237 rc= mysql_rollback(mysql);
14239 rc= mysql_stmt_fetch(stmt);
14240 check_execute(stmt, rc);
14249 printf(
"Testing that cursors are closed at COMMIT/ROLLBACK requires "
14254 stmt_text=
"select id from t1 order by 1";
14255 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
14256 check_execute(stmt, rc);
14258 rc= mysql_query(mysql,
"alter table t1 engine=InnoDB");
14261 memset(my_bind, 0,
sizeof(my_bind));
14262 my_bind[0].buffer_type= MYSQL_TYPE_STRING;
14263 my_bind[0].buffer= (
void*) id_buf;
14264 my_bind[0].buffer_length=
sizeof(id_buf);
14265 my_bind[0].length= &id_len;
14266 check_execute(stmt, rc);
14267 mysql_stmt_bind_result(stmt, my_bind);
14269 rc= mysql_stmt_execute(stmt);
14270 rc= mysql_stmt_fetch(stmt);
14271 DIE_UNLESS(rc == 0);
14273 printf(
"Fetched row %s\n", id_buf);
14274 rc= mysql_rollback(mysql);
14277 rc= mysql_stmt_fetch(stmt);
14280 printf(
"Got error (as expected): %s\n", mysql_error(mysql));
14284 mysql_stmt_close(stmt);
14285 rc= mysql_query(mysql,
"drop table t1");
14287 mysql_autocommit(mysql, TRUE);
14290 static void test_bug12001()
14292 MYSQL *mysql_local;
14294 const char *query=
"DROP TABLE IF EXISTS test_table;"
14295 "CREATE TABLE test_table(id INT);"
14296 "INSERT INTO test_table VALUES(10);"
14297 "UPDATE test_table SET id=20 WHERE id=10;"
14298 "SELECT * FROM test_table;"
14299 "INSERT INTO non_existent_table VALUES(11);";
14302 myheader(
"test_bug12001");
14304 if (!(mysql_local= mysql_client_init(NULL)))
14306 fprintf(stdout,
"\n mysql_client_init() failed");
14311 if (!mysql_real_connect(mysql_local, opt_host, opt_user,
14312 opt_password, current_db, opt_port,
14313 opt_unix_socket, CLIENT_MULTI_STATEMENTS))
14315 fprintf(stdout,
"\n mysql_real_connect() failed");
14319 rc= mysql_query(mysql_local, query);
14324 if (mysql_field_count(mysql_local) &&
14325 (result= mysql_use_result(mysql_local)))
14327 mysql_free_result(result);
14330 while (!(res= mysql_next_result(mysql_local)));
14332 rc= mysql_query(mysql_local,
"DROP TABLE IF EXISTS test_table");
14335 mysql_close(mysql_local);
14336 DIE_UNLESS(res==1);
14342 static void test_bug11909()
14347 char firstname[20], midinit[20], lastname[20], workdept[20];
14348 ulong firstname_len, midinit_len, lastname_len, workdept_len;
14352 const char *stmt_text;
14354 myheader(
"test_bug11909");
14356 stmt_text=
"drop table if exists t1";
14357 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
14360 stmt_text=
"create table t1 ("
14361 " empno int(11) not null, firstname varchar(20) not null,"
14362 " midinit varchar(20) not null, lastname varchar(20) not null,"
14363 " workdept varchar(6) not null, salary double not null,"
14364 " bonus float not null, primary key (empno)"
14365 ") default charset=latin1 collate=latin1_bin";
14366 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
14369 stmt_text=
"insert into t1 values "
14370 "(10, 'CHRISTINE', 'I', 'HAAS', 'A00', 52750, 1000), "
14371 "(20, 'MICHAEL', 'L', 'THOMPSON', 'B01', 41250, 800),"
14372 "(30, 'SALLY', 'A', 'KWAN', 'C01', 38250, 800),"
14373 "(50, 'JOHN', 'B', 'GEYER', 'E01', 40175, 800), "
14374 "(60, 'IRVING', 'F', 'STERN', 'D11', 32250, 500)";
14375 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
14380 stmt1= open_cursor(
"SELECT empno, firstname, midinit, lastname,"
14381 "workdept, salary, bonus FROM t1");
14383 memset(my_bind, 0,
sizeof(my_bind));
14384 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
14385 my_bind[0].buffer= (
void*) &empno;
14387 my_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
14388 my_bind[1].buffer= (
void*) firstname;
14389 my_bind[1].buffer_length=
sizeof(firstname);
14390 my_bind[1].length= &firstname_len;
14392 my_bind[2].buffer_type= MYSQL_TYPE_VAR_STRING;
14393 my_bind[2].buffer= (
void*) midinit;
14394 my_bind[2].buffer_length=
sizeof(midinit);
14395 my_bind[2].length= &midinit_len;
14397 my_bind[3].buffer_type= MYSQL_TYPE_VAR_STRING;
14398 my_bind[3].buffer= (
void*) lastname;
14399 my_bind[3].buffer_length=
sizeof(lastname);
14400 my_bind[3].length= &lastname_len;
14402 my_bind[4].buffer_type= MYSQL_TYPE_VAR_STRING;
14403 my_bind[4].buffer= (
void*) workdept;
14404 my_bind[4].buffer_length=
sizeof(workdept);
14405 my_bind[4].length= &workdept_len;
14407 my_bind[5].buffer_type= MYSQL_TYPE_DOUBLE;
14408 my_bind[5].buffer= (
void*) &salary;
14410 my_bind[6].buffer_type= MYSQL_TYPE_FLOAT;
14411 my_bind[6].buffer= (
void*) &bonus;
14412 rc= mysql_stmt_bind_result(stmt1, my_bind);
14413 check_execute(stmt1, rc);
14415 rc= mysql_stmt_execute(stmt1);
14416 check_execute(stmt1, rc);
14418 rc= mysql_stmt_fetch(stmt1);
14419 DIE_UNLESS(rc == 0);
14420 DIE_UNLESS(empno == 10);
14421 DIE_UNLESS(strcmp(firstname,
"CHRISTINE") == 0);
14422 DIE_UNLESS(strcmp(midinit,
"I") == 0);
14423 DIE_UNLESS(strcmp(lastname,
"HAAS") == 0);
14424 DIE_UNLESS(strcmp(workdept,
"A00") == 0);
14425 DIE_UNLESS(salary == (
double) 52750.0);
14426 DIE_UNLESS(bonus == (
float) 1000.0);
14428 stmt2= open_cursor(
"SELECT empno, firstname FROM t1");
14429 rc= mysql_stmt_bind_result(stmt2, my_bind);
14430 check_execute(stmt2, rc);
14432 rc= mysql_stmt_execute(stmt2);
14433 check_execute(stmt2, rc);
14435 rc= mysql_stmt_fetch(stmt2);
14436 DIE_UNLESS(rc == 0);
14438 DIE_UNLESS(empno == 10);
14439 DIE_UNLESS(strcmp(firstname,
"CHRISTINE") == 0);
14441 rc= mysql_stmt_reset(stmt2);
14442 check_execute(stmt2, rc);
14446 rc= mysql_stmt_fetch(stmt1);
14447 DIE_UNLESS(rc == 0);
14449 mysql_stmt_close(stmt1);
14450 mysql_stmt_close(stmt2);
14451 rc= mysql_rollback(mysql);
14454 rc= mysql_query(mysql,
"drop table t1");
14460 static void test_bug11901()
14468 const char *stmt_text;
14470 myheader(
"test_bug11901");
14472 stmt_text=
"drop table if exists t1, t2";
14473 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
14476 stmt_text=
"create table t1 ("
14477 " empno int(11) not null, firstname varchar(20) not null,"
14478 " midinit varchar(20) not null, lastname varchar(20) not null,"
14479 " workdept varchar(6) not null, salary double not null,"
14480 " bonus float not null, primary key (empno), "
14481 " unique key (workdept, empno) "
14482 ") default charset=latin1 collate=latin1_bin";
14483 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
14486 stmt_text=
"insert into t1 values "
14487 "(10, 'CHRISTINE', 'I', 'HAAS', 'A00', 52750, 1000),"
14488 "(20, 'MICHAEL', 'L', 'THOMPSON', 'B01', 41250, 800), "
14489 "(30, 'SALLY', 'A', 'KWAN', 'C01', 38250, 800), "
14490 "(50, 'JOHN', 'B', 'GEYER', 'E01', 40175, 800), "
14491 "(60, 'IRVING', 'F', 'STERN', 'D11', 32250, 500), "
14492 "(70, 'EVA', 'D', 'PULASKI', 'D21', 36170, 700), "
14493 "(90, 'EILEEN', 'W', 'HENDERSON', 'E11', 29750, 600), "
14494 "(100, 'THEODORE', 'Q', 'SPENSER', 'E21', 26150, 500), "
14495 "(110, 'VINCENZO', 'G', 'LUCCHESSI', 'A00', 46500, 900), "
14496 "(120, 'SEAN', '', 'O\\'CONNELL', 'A00', 29250, 600), "
14497 "(130, 'DOLORES', 'M', 'QUINTANA', 'C01', 23800, 500), "
14498 "(140, 'HEATHER', 'A', 'NICHOLLS', 'C01', 28420, 600), "
14499 "(150, 'BRUCE', '', 'ADAMSON', 'D11', 25280, 500), "
14500 "(160, 'ELIZABETH', 'R', 'PIANKA', 'D11', 22250, 400), "
14501 "(170, 'MASATOSHI', 'J', 'YOSHIMURA', 'D11', 24680, 500), "
14502 "(180, 'MARILYN', 'S', 'SCOUTTEN', 'D11', 21340, 500), "
14503 "(190, 'JAMES', 'H', 'WALKER', 'D11', 20450, 400), "
14504 "(200, 'DAVID', '', 'BROWN', 'D11', 27740, 600), "
14505 "(210, 'WILLIAM', 'T', 'JONES', 'D11', 18270, 400), "
14506 "(220, 'JENNIFER', 'K', 'LUTZ', 'D11', 29840, 600), "
14507 "(230, 'JAMES', 'J', 'JEFFERSON', 'D21', 22180, 400), "
14508 "(240, 'SALVATORE', 'M', 'MARINO', 'D21', 28760, 600), "
14509 "(250, 'DANIEL', 'S', 'SMITH', 'D21', 19180, 400), "
14510 "(260, 'SYBIL', 'P', 'JOHNSON', 'D21', 17250, 300), "
14511 "(270, 'MARIA', 'L', 'PEREZ', 'D21', 27380, 500), "
14512 "(280, 'ETHEL', 'R', 'SCHNEIDER', 'E11', 26250, 500), "
14513 "(290, 'JOHN', 'R', 'PARKER', 'E11', 15340, 300), "
14514 "(300, 'PHILIP', 'X', 'SMITH', 'E11', 17750, 400), "
14515 "(310, 'MAUDE', 'F', 'SETRIGHT', 'E11', 15900, 300), "
14516 "(320, 'RAMLAL', 'V', 'MEHTA', 'E21', 19950, 400), "
14517 "(330, 'WING', '', 'LEE', 'E21', 25370, 500), "
14518 "(340, 'JASON', 'R', 'GOUNOT', 'E21', 23840, 500)";
14520 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
14523 stmt_text=
"create table t2 ("
14524 " deptno varchar(6) not null, deptname varchar(20) not null,"
14525 " mgrno int(11) not null, location varchar(20) not null,"
14526 " admrdept varchar(6) not null, refcntd int(11) not null,"
14527 " refcntu int(11) not null, primary key (deptno)"
14528 ") default charset=latin1 collate=latin1_bin";
14529 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
14532 stmt_text=
"insert into t2 values "
14533 "('A00', 'SPIFFY COMPUTER SERV', 10, '', 'A00', 0, 0), "
14534 "('B01', 'PLANNING', 20, '', 'A00', 0, 0), "
14535 "('C01', 'INFORMATION CENTER', 30, '', 'A00', 0, 0), "
14536 "('D01', 'DEVELOPMENT CENTER', 0, '', 'A00', 0, 0),"
14537 "('D11', 'MANUFACTURING SYSTEM', 60, '', 'D01', 0, 0), "
14538 "('D21', 'ADMINISTRATION SYSTE', 70, '', 'D01', 0, 0), "
14539 "('E01', 'SUPPORT SERVICES', 50, '', 'A00', 0, 0), "
14540 "('E11', 'OPERATIONS', 90, '', 'E01', 0, 0), "
14541 "('E21', 'SOFTWARE SUPPORT', 100,'', 'E01', 0, 0)";
14542 rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
14586 static void test_bug11904()
14590 const char *stmt_text;
14591 const ulong type= (ulong)CURSOR_TYPE_READ_ONLY;
14594 char row_data[11]= {0};
14596 myheader(
"test_bug11904");
14599 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS bug11904b");
14601 rc= mysql_query(mysql,
"CREATE TABLE bug11904b (id int, name char(10), primary key(id, name))");
14604 rc= mysql_query(mysql,
"INSERT INTO bug11904b VALUES (1, 'sofia'), (1,'plovdiv'),"
14605 " (1,'varna'), (2,'LA'), (2,'new york'), (3,'heidelberg'),"
14606 " (3,'berlin'), (3, 'frankfurt')");
14609 mysql_commit(mysql);
14611 stmt1= mysql_stmt_init(mysql);
14612 mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (
const void*) &type);
14614 stmt_text=
"SELECT id, MIN(name) FROM bug11904b GROUP BY id";
14616 rc= mysql_stmt_prepare(stmt1, stmt_text, strlen(stmt_text));
14617 check_execute(stmt1, rc);
14619 memset(my_bind, 0,
sizeof(my_bind));
14620 my_bind[0].buffer_type= MYSQL_TYPE_LONG;
14621 my_bind[0].buffer=& country_id;
14622 my_bind[0].buffer_length= 0;
14623 my_bind[0].length= 0;
14625 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
14626 my_bind[1].buffer=& row_data;
14627 my_bind[1].buffer_length=
sizeof(row_data) - 1;
14628 my_bind[1].length= 0;
14630 rc= mysql_stmt_bind_result(stmt1, my_bind);
14631 check_execute(stmt1, rc);
14633 rc= mysql_stmt_execute(stmt1);
14634 check_execute(stmt1, rc);
14636 rc= mysql_stmt_fetch(stmt1);
14637 check_execute(stmt1, rc);
14638 DIE_UNLESS(country_id == 1);
14639 DIE_UNLESS(memcmp(row_data,
"plovdiv", 7) == 0);
14641 rc= mysql_stmt_fetch(stmt1);
14642 check_execute(stmt1, rc);
14643 DIE_UNLESS(country_id == 2);
14644 DIE_UNLESS(memcmp(row_data,
"LA", 2) == 0);
14646 rc= mysql_stmt_fetch(stmt1);
14647 check_execute(stmt1, rc);
14648 DIE_UNLESS(country_id == 3);
14649 DIE_UNLESS(memcmp(row_data,
"berlin", 6) == 0);
14651 rc= mysql_stmt_close(stmt1);
14652 check_execute(stmt1, rc);
14654 rc= mysql_query(mysql,
"drop table bug11904b");
14661 static void test_bug12243()
14665 const char *stmt_text;
14668 myheader(
"test_bug12243");
14673 printf(
"This test requires InnoDB.\n");
14678 mysql_query(mysql,
"drop table if exists t1");
14679 mysql_query(mysql,
"create table t1 (a int) engine=InnoDB");
14680 rc= mysql_query(mysql,
"insert into t1 (a) values (1), (2)");
14682 mysql_autocommit(mysql, FALSE);
14684 stmt1= mysql_stmt_init(mysql);
14685 stmt2= mysql_stmt_init(mysql);
14686 type= (ulong) CURSOR_TYPE_READ_ONLY;
14687 mysql_stmt_attr_set(stmt1, STMT_ATTR_CURSOR_TYPE, (
const void*) &type);
14688 mysql_stmt_attr_set(stmt2, STMT_ATTR_CURSOR_TYPE, (
const void*) &type);
14690 stmt_text=
"select a from t1";
14692 rc= mysql_stmt_prepare(stmt1, stmt_text, strlen(stmt_text));
14693 check_execute(stmt1, rc);
14694 rc= mysql_stmt_execute(stmt1);
14695 check_execute(stmt1, rc);
14696 rc= mysql_stmt_fetch(stmt1);
14697 check_execute(stmt1, rc);
14699 rc= mysql_stmt_prepare(stmt2, stmt_text, strlen(stmt_text));
14700 check_execute(stmt2, rc);
14701 rc= mysql_stmt_execute(stmt2);
14702 check_execute(stmt2, rc);
14703 rc= mysql_stmt_fetch(stmt2);
14704 check_execute(stmt2, rc);
14706 rc= mysql_stmt_close(stmt1);
14707 check_execute(stmt1, rc);
14708 rc= mysql_commit(mysql);
14710 rc= mysql_stmt_fetch(stmt2);
14711 check_execute(stmt2, rc);
14713 mysql_stmt_close(stmt2);
14714 rc= mysql_query(mysql,
"drop table t1");
14716 mysql_autocommit(mysql, TRUE);
14724 static void test_bug11718()
14728 const char *query=
"select str_to_date(concat(f3),'%Y%m%d') from t1,t2 "
14729 "where f1=f2 order by f1";
14731 myheader(
"test_bug11718");
14733 rc= mysql_query(mysql,
"drop table if exists t1, t2");
14735 rc= mysql_query(mysql,
"create table t1 (f1 int)");
14737 rc= mysql_query(mysql,
"create table t2 (f2 int, f3 numeric(8))");
14739 rc= mysql_query(mysql,
"insert into t1 values (1), (2)");
14741 rc= mysql_query(mysql,
"insert into t2 values (1,20050101), (2,20050202)");
14743 rc= mysql_query(mysql, query);
14745 res = mysql_store_result(mysql);
14748 printf(
"return type: %s", (res->fields[0].type == MYSQL_TYPE_DATE)?
"DATE":
14750 DIE_UNLESS(res->fields[0].type == MYSQL_TYPE_DATE);
14751 mysql_free_result(res);
14752 rc= mysql_query(mysql,
"drop table t1, t2");
14760 static void test_bug12925()
14762 myheader(
"test_bug12925");
14763 if (opt_getopt_ll_test)
14764 DIE_UNLESS(opt_getopt_ll_test == LL(25600*1024*1024));
14773 static void test_bug14210()
14777 const char *stmt_text;
14780 myheader(
"test_bug14210");
14782 mysql_query(mysql,
"drop table if exists t1");
14788 mysql_query(mysql,
"create table t1 (a varchar(255)) engine=InnoDB");
14789 rc= mysql_query(mysql,
"insert into t1 (a) values (repeat('a', 256))");
14791 rc= mysql_query(mysql,
"set @@session.max_heap_table_size=16384");
14793 for (i= 0; i < 8; i++)
14795 rc= mysql_query(mysql,
"insert into t1 (a) select a from t1");
14799 stmt= mysql_stmt_init(mysql);
14800 type= (ulong) CURSOR_TYPE_READ_ONLY;
14801 mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
const void*) &type);
14803 stmt_text=
"select a from t1";
14805 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
14806 check_execute(stmt, rc);
14807 rc= mysql_stmt_execute(stmt);
14808 while ((rc= mysql_stmt_fetch(stmt)) == 0)
14810 DIE_UNLESS(rc == MYSQL_NO_DATA);
14812 rc= mysql_stmt_close(stmt);
14814 rc= mysql_query(mysql,
"drop table t1");
14816 rc= mysql_query(mysql,
"set @@session.max_heap_table_size=default");
14822 static void test_bug13488()
14826 int rc, f1, f2, f3,
i;
14827 const ulong type= CURSOR_TYPE_READ_ONLY;
14828 const char *query=
"select * from t1 left join t2 on f1=f2 where f1=1";
14830 myheader(
"test_bug13488");
14832 rc= mysql_query(mysql,
"drop table if exists t1, t2");
14834 rc= mysql_query(mysql,
"create table t1 (f1 int not null primary key)");
14836 rc= mysql_query(mysql,
"create table t2 (f2 int not null primary key, "
14837 "f3 int not null)");
14839 rc= mysql_query(mysql,
"insert into t1 values (1), (2)");
14841 rc= mysql_query(mysql,
"insert into t2 values (1,2), (2,4)");
14844 memset(my_bind, 0,
sizeof(my_bind));
14845 for (i= 0; i < 3; i++)
14847 my_bind[
i].buffer_type= MYSQL_TYPE_LONG;
14848 my_bind[
i].buffer_length= 4;
14849 my_bind[
i].length= 0;
14851 my_bind[0].buffer=&f1;
14852 my_bind[1].buffer=&f2;
14853 my_bind[2].buffer=&f3;
14855 stmt1= mysql_stmt_init(mysql);
14856 rc= mysql_stmt_attr_set(stmt1,STMT_ATTR_CURSOR_TYPE, (
const void *)&type);
14857 check_execute(stmt1, rc);
14859 rc= mysql_stmt_prepare(stmt1, query, strlen(query));
14860 check_execute(stmt1, rc);
14862 rc= mysql_stmt_execute(stmt1);
14863 check_execute(stmt1, rc);
14865 rc= mysql_stmt_bind_result(stmt1, my_bind);
14866 check_execute(stmt1, rc);
14868 rc= mysql_stmt_fetch(stmt1);
14869 check_execute(stmt1, rc);
14871 rc= mysql_stmt_free_result(stmt1);
14872 check_execute(stmt1, rc);
14874 rc= mysql_stmt_reset(stmt1);
14875 check_execute(stmt1, rc);
14877 rc= mysql_stmt_close(stmt1);
14878 check_execute(stmt1, rc);
14882 printf(
"data: f1: %d; f2: %d; f3: %d\n", f1, f2, f3);
14883 printf(
"data is: %s\n",
14884 (f1 == 1 && f2 == 1 && f3 == 2) ?
"OK" :
"wrong");
14886 DIE_UNLESS(f1 == 1 && f2 == 1 && f3 == 2);
14887 rc= mysql_query(mysql,
"drop table t1, t2");
14896 static void test_bug13524()
14900 unsigned int warning_count;
14901 const ulong type= CURSOR_TYPE_READ_ONLY;
14902 const char *query=
"select * from t1";
14904 myheader(
"test_bug13524");
14906 rc= mysql_query(mysql,
"drop table if exists t1, t2");
14908 rc= mysql_query(mysql,
"create table t1 (a int not null primary key)");
14910 rc= mysql_query(mysql,
"insert into t1 values (1), (2), (3), (4)");
14913 stmt= mysql_stmt_init(mysql);
14914 rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
const void*) &type);
14915 check_execute(stmt, rc);
14917 rc= mysql_stmt_prepare(stmt, query, strlen(query));
14918 check_execute(stmt, rc);
14920 rc= mysql_stmt_execute(stmt);
14921 check_execute(stmt, rc);
14923 rc= mysql_stmt_fetch(stmt);
14924 check_execute(stmt, rc);
14926 warning_count= mysql_warning_count(mysql);
14927 DIE_UNLESS(warning_count == 0);
14930 rc= mysql_query(mysql,
"drop table if exists t2");
14932 warning_count= mysql_warning_count(mysql);
14933 DIE_UNLESS(warning_count == 1);
14939 rc= mysql_stmt_fetch(stmt);
14940 check_execute(stmt, rc);
14941 warning_count= mysql_warning_count(mysql);
14942 DIE_UNLESS(warning_count == 0);
14945 mysql_stmt_close(stmt);
14946 rc= mysql_query(mysql,
"drop table t1");
14954 static void test_bug14845()
14958 const ulong type= CURSOR_TYPE_READ_ONLY;
14959 const char *query=
"select count(*) from t1 where 1 = 0";
14961 myheader(
"test_bug14845");
14963 rc= mysql_query(mysql,
"drop table if exists t1");
14965 rc= mysql_query(mysql,
"create table t1 (id int(11) default null, "
14966 "name varchar(20) default null)"
14967 "engine=MyISAM DEFAULT CHARSET=utf8");
14969 rc= mysql_query(mysql,
"insert into t1 values (1,'abc'),(2,'def')");
14972 stmt= mysql_stmt_init(mysql);
14973 rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
const void*) &type);
14974 check_execute(stmt, rc);
14976 rc= mysql_stmt_prepare(stmt, query, strlen(query));
14977 check_execute(stmt, rc);
14979 rc= mysql_stmt_execute(stmt);
14980 check_execute(stmt, rc);
14982 rc= mysql_stmt_fetch(stmt);
14983 DIE_UNLESS(rc == 0);
14985 rc= mysql_stmt_fetch(stmt);
14986 DIE_UNLESS(rc == MYSQL_NO_DATA);
14989 mysql_stmt_close(stmt);
14990 rc= mysql_query(mysql,
"drop table t1");
14999 static void test_bug15510()
15003 const char *query=
"select 1 from dual where 1/0";
15005 myheader(
"test_bug15510");
15007 rc= mysql_query(mysql,
"set @@sql_mode='ERROR_FOR_DIVISION_BY_ZERO'");
15010 stmt= mysql_stmt_init(mysql);
15012 rc= mysql_stmt_prepare(stmt, query, strlen(query));
15013 check_execute(stmt, rc);
15015 rc= mysql_stmt_execute(stmt);
15016 check_execute(stmt, rc);
15018 rc= mysql_stmt_fetch(stmt);
15019 DIE_UNLESS(mysql_warning_count(mysql));
15022 mysql_stmt_close(stmt);
15023 rc= mysql_query(mysql,
"set @@sql_mode=''");
15030 static void test_opt_reconnect()
15033 my_bool my_true= TRUE;
15035 myheader(
"test_opt_reconnect");
15037 if (!(lmysql= mysql_client_init(NULL)))
15039 myerror(
"mysql_client_init() failed");
15044 fprintf(stdout,
"reconnect before mysql_options: %d\n", lmysql->reconnect);
15045 DIE_UNLESS(lmysql->reconnect == 0);
15047 if (mysql_options(lmysql, MYSQL_OPT_RECONNECT, &my_true))
15049 myerror(
"mysql_options failed: unknown option MYSQL_OPT_RECONNECT\n");
15055 fprintf(stdout,
"reconnect after mysql_options: %d\n", lmysql->reconnect);
15056 DIE_UNLESS(lmysql->reconnect == 1);
15058 if (!(mysql_real_connect(lmysql, opt_host, opt_user,
15059 opt_password, current_db, opt_port,
15060 opt_unix_socket, 0)))
15062 myerror(
"connection failed");
15068 fprintf(stdout,
"reconnect after mysql_real_connect: %d\n",
15069 lmysql->reconnect);
15070 DIE_UNLESS(lmysql->reconnect == 1);
15072 mysql_close(lmysql);
15074 if (!(lmysql= mysql_client_init(NULL)))
15076 myerror(
"mysql_client_init() failed");
15081 fprintf(stdout,
"reconnect before mysql_real_connect: %d\n", lmysql->reconnect);
15082 DIE_UNLESS(lmysql->reconnect == 0);
15084 if (!(mysql_real_connect(lmysql, opt_host, opt_user,
15085 opt_password, current_db, opt_port,
15086 opt_unix_socket, 0)))
15088 myerror(
"connection failed");
15094 fprintf(stdout,
"reconnect after mysql_real_connect: %d\n",
15095 lmysql->reconnect);
15096 DIE_UNLESS(lmysql->reconnect == 0);
15098 mysql_close(lmysql);
15102 #ifndef EMBEDDED_LIBRARY
15104 static void test_bug12744()
15109 myheader(
"test_bug12744");
15111 lmysql= mysql_client_init(NULL);
15112 DIE_UNLESS(lmysql);
15114 if (!mysql_real_connect(lmysql, opt_host, opt_user, opt_password,
15115 current_db, opt_port, opt_unix_socket, 0))
15117 fprintf(stderr,
"Failed to connect to the database\n");
15121 prep_stmt= mysql_stmt_init(lmysql);
15122 rc= mysql_stmt_prepare(prep_stmt,
"SELECT 1", 8);
15123 DIE_UNLESS(rc == 0);
15125 mysql_close(lmysql);
15127 rc= mysql_stmt_execute(prep_stmt);
15129 rc= mysql_stmt_reset(prep_stmt);
15131 rc= mysql_stmt_close(prep_stmt);
15132 DIE_UNLESS(rc == 0);
15139 static void test_bug16143()
15142 myheader(
"test_bug16143");
15144 stmt= mysql_stmt_init(mysql);
15146 DIE_UNLESS(strcmp(mysql_stmt_sqlstate(stmt),
"00000") == 0);
15148 mysql_stmt_close(stmt);
15154 static void test_bug16144()
15156 const my_bool flag_orig= (my_bool) 0xde;
15157 my_bool flag= flag_orig;
15159 myheader(
"test_bug16144");
15162 stmt= mysql_stmt_init(mysql);
15163 mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (
const void*) &flag);
15164 mysql_stmt_attr_get(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (
void*) &flag);
15165 DIE_UNLESS(flag == flag_orig);
15167 mysql_stmt_close(stmt);
15175 static void test_bug15613()
15178 const char *stmt_text;
15182 myheader(
"test_bug15613");
15185 rc= mysql_query(mysql,
"set names latin1");
15187 mysql_query(mysql,
"drop table if exists t1");
15188 rc= mysql_query(mysql,
15189 "create table t1 (t text character set utf8, "
15190 "tt tinytext character set utf8, "
15191 "mt mediumtext character set utf8, "
15192 "lt longtext character set utf8, "
15193 "vl varchar(255) character set latin1,"
15194 "vb varchar(255) character set binary,"
15195 "vu varchar(255) character set utf8)");
15198 stmt= mysql_stmt_init(mysql);
15201 stmt_text= (
"select t, tt, mt, lt, vl, vb, vu from t1");
15202 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
15203 metadata= mysql_stmt_result_metadata(stmt);
15204 field= mysql_fetch_fields(metadata);
15207 printf(
"Field lengths (client character set is latin1):\n"
15208 "text character set utf8:\t\t%lu\n"
15209 "tinytext character set utf8:\t\t%lu\n"
15210 "mediumtext character set utf8:\t\t%lu\n"
15211 "longtext character set utf8:\t\t%lu\n"
15212 "varchar(255) character set latin1:\t%lu\n"
15213 "varchar(255) character set binary:\t%lu\n"
15214 "varchar(255) character set utf8:\t%lu\n",
15215 field[0].length, field[1].length, field[2].length, field[3].length,
15216 field[4].length, field[5].length, field[6].length);
15218 DIE_UNLESS(field[0].length == 65535);
15219 DIE_UNLESS(field[1].length == 255);
15220 DIE_UNLESS(field[2].length == 16777215);
15221 DIE_UNLESS(field[3].length == 4294967295UL);
15222 DIE_UNLESS(field[4].length == 255);
15223 DIE_UNLESS(field[5].length == 255);
15224 DIE_UNLESS(field[6].length == 255);
15225 mysql_free_result(metadata);
15226 mysql_stmt_free_result(stmt);
15229 rc= mysql_query(mysql,
"drop table t1");
15231 rc= mysql_query(mysql,
"set names default");
15233 mysql_stmt_close(stmt);
15242 static void test_bug17667()
15246 enum query_type { QT_NORMAL, QT_PREPARED};
15247 struct buffer_and_length {
15248 enum query_type qt;
15249 const char *buffer;
15252 { QT_NORMAL,
"drop table if exists bug17667", 29 },
15253 { QT_NORMAL,
"create table bug17667 (c varchar(20))", 37 },
15254 { QT_NORMAL,
"insert into bug17667 (c) values ('regular') /* NUL=\0 with comment */", 68 },
15256 "insert into bug17667 (c) values ('prepared') /* NUL=\0 with comment */", 69, },
15257 { QT_NORMAL,
"insert into bug17667 (c) values ('NUL=\0 in value')", 50 },
15258 { QT_NORMAL,
"insert into bug17667 (c) values ('5 NULs=\0\0\0\0\0')", 48 },
15259 { QT_PREPARED,
"insert into bug17667 (c) values ('6 NULs=\0\0\0\0\0\0')", 50 },
15260 { QT_NORMAL,
"/* NUL=\0 with comment */ insert into bug17667 (c) values ('encore')", 67 },
15261 { QT_NORMAL,
"drop table bug17667", 19 },
15262 { QT_NORMAL, NULL, 0 } };
15264 struct buffer_and_length *statement_cursor;
15266 char *master_log_filename;
15268 myheader(
"test_bug17667");
15270 master_log_filename = (
char *) malloc(strlen(opt_vardir) + strlen(
"/log/master.log") + 1);
15271 strxmov(master_log_filename, opt_vardir,
"/log/master.log", NullS);
15273 printf(
"Opening '%s'\n", master_log_filename);
15274 log_file= my_fopen(master_log_filename, (
int) (O_RDONLY | O_BINARY), MYF(0));
15275 free(master_log_filename);
15277 if (log_file == NULL)
15281 printf(
"Could not find the log file, VARDIR/log/master.log, so "
15282 "test_bug17667 is not run.\n"
15283 "Run test from the mysql-test/mysql-test-run* program to set up "
15284 "correct environment for this test.\n\n");
15289 enable_query_logs(1);
15291 for (statement_cursor= statements; statement_cursor->buffer != NULL;
15292 statement_cursor++)
15294 if (statement_cursor->qt == QT_NORMAL)
15297 rc= mysql_real_query(mysql, statement_cursor->buffer,
15298 statement_cursor->length);
15301 else if (statement_cursor->qt == QT_PREPARED)
15309 stmt= mysql_stmt_init(mysql);
15311 rc= mysql_stmt_prepare(stmt, statement_cursor->buffer,
15312 statement_cursor->length);
15313 check_execute(stmt, rc);
15315 rc= mysql_stmt_execute(stmt);
15316 check_execute(stmt, rc);
15318 mysql_stmt_close(stmt);
15327 rc= mysql_query(mysql,
"flush logs");
15330 for (statement_cursor= statements; statement_cursor->buffer != NULL;
15331 statement_cursor++)
15333 int expected_hits= 1, hits= 0;
15334 char line_buffer[MAX_TEST_QUERY_LENGTH*2];
15338 if (statement_cursor->qt == QT_PREPARED)
15345 memset(line_buffer,
'/', MAX_TEST_QUERY_LENGTH*2);
15347 if(fgets(line_buffer, MAX_TEST_QUERY_LENGTH*2, log_file) == NULL)
15350 if (feof(log_file))
15351 DIE(
"Found EOF before all statements where found");
15353 fprintf(stderr,
"Got error %d while reading from file\n",
15358 }
while (my_memmem(line_buffer, MAX_TEST_QUERY_LENGTH*2,
15359 statement_cursor->buffer,
15360 statement_cursor->length) == NULL);
15362 }
while (hits < expected_hits);
15365 printf(
"Found statement starting with \"%s\"\n",
15366 statement_cursor->buffer);
15369 restore_query_logs();
15372 printf(
"success. All queries found intact in the log.\n");
15374 my_fclose(log_file, MYF(0));
15382 static void test_bug14169()
15385 const char *stmt_text;
15390 myheader(
"test_bug14169");
15392 rc= mysql_query(mysql,
"drop table if exists t1");
15394 rc= mysql_query(mysql,
"set session group_concat_max_len=1024");
15396 rc= mysql_query(mysql,
"create table t1 (f1 int unsigned, f2 varchar(255))");
15398 rc= mysql_query(mysql,
"insert into t1 values (1,repeat('a',255)),"
15399 "(2,repeat('b',255))");
15401 stmt= mysql_stmt_init(mysql);
15402 stmt_text=
"select f2,group_concat(f1) from t1 group by f2";
15403 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
15405 res= mysql_stmt_result_metadata(stmt);
15406 field= mysql_fetch_fields(res);
15408 printf(
"GROUP_CONCAT() result type %i", field[1].type);
15409 DIE_UNLESS(field[1].type == MYSQL_TYPE_BLOB);
15410 mysql_free_result(res);
15411 mysql_stmt_free_result(stmt);
15412 mysql_stmt_close(stmt);
15414 rc= mysql_query(mysql,
"drop table t1");
15421 static void test_mysql_insert_id()
15426 myheader(
"test_mysql_insert_id");
15428 rc= mysql_query(mysql,
"drop table if exists t1");
15431 rc= mysql_query(mysql,
"create table t1 (f1 int, f2 varchar(255), key(f1))");
15433 rc= mysql_query(mysql,
"insert into t1 values (1,'a')");
15435 res= mysql_insert_id(mysql);
15436 DIE_UNLESS(res == 0);
15437 rc= mysql_query(mysql,
"insert into t1 values (null,'b')");
15439 res= mysql_insert_id(mysql);
15440 DIE_UNLESS(res == 0);
15441 rc= mysql_query(mysql,
"insert into t1 select 5,'c'");
15443 res= mysql_insert_id(mysql);
15444 DIE_UNLESS(res == 0);
15450 rc= mysql_query(mysql,
"create table t2 (f1 int not null primary key auto_increment, f2 varchar(255))");
15452 rc= mysql_query(mysql,
"insert into t2 values (null,'b')");
15454 rc= mysql_query(mysql,
"insert into t1 select 5,'c'");
15456 res= mysql_insert_id(mysql);
15457 DIE_UNLESS(res == 0);
15458 rc= mysql_query(mysql,
"drop table t2");
15461 rc= mysql_query(mysql,
"insert into t1 select null,'d'");
15463 res= mysql_insert_id(mysql);
15464 DIE_UNLESS(res == 0);
15465 rc= mysql_query(mysql,
"insert into t1 values (null,last_insert_id(300))");
15467 res= mysql_insert_id(mysql);
15468 DIE_UNLESS(res == 300);
15469 rc= mysql_query(mysql,
"insert into t1 select null,last_insert_id(400)");
15471 res= mysql_insert_id(mysql);
15477 DIE_UNLESS(res == 400);
15480 rc= mysql_query(mysql,
"create table t2 (f1 int not null primary key auto_increment, f2 varchar(255))");
15482 rc= mysql_query(mysql,
"insert into t2 values (1,'a')");
15484 res= mysql_insert_id(mysql);
15485 DIE_UNLESS(res == 1);
15487 rc= mysql_query(mysql,
"insert into t1 values (10,'e')");
15489 res= mysql_insert_id(mysql);
15490 DIE_UNLESS(res == 0);
15492 rc= mysql_query(mysql,
"insert into t2 values (null,'b')");
15494 res= mysql_insert_id(mysql);
15495 DIE_UNLESS(res == 2);
15496 rc= mysql_query(mysql,
"insert into t2 select 5,'c'");
15498 res= mysql_insert_id(mysql);
15504 DIE_UNLESS(res == 5);
15505 rc= mysql_query(mysql,
"insert into t2 select null,'d'");
15507 res= mysql_insert_id(mysql);
15508 DIE_UNLESS(res == 6);
15510 rc= mysql_query(mysql,
"insert into t2 values (10,'a'),(11,'b')");
15512 res= mysql_insert_id(mysql);
15513 DIE_UNLESS(res == 11);
15514 rc= mysql_query(mysql,
"insert into t2 select 12,'a' union select 13,'b'");
15516 res= mysql_insert_id(mysql);
15522 DIE_UNLESS(res == 13);
15523 rc= mysql_query(mysql,
"insert into t2 values (null,'a'),(null,'b')");
15525 res= mysql_insert_id(mysql);
15526 DIE_UNLESS(res == 14);
15527 rc= mysql_query(mysql,
"insert into t2 select null,'a' union select null,'b'");
15529 res= mysql_insert_id(mysql);
15530 DIE_UNLESS(res == 16);
15531 rc= mysql_query(mysql,
"insert into t2 select 12,'a' union select 13,'b'");
15533 rc= mysql_query(mysql,
"insert ignore into t2 select 12,'a' union select 13,'b'");
15535 res= mysql_insert_id(mysql);
15536 DIE_UNLESS(res == 0);
15537 rc= mysql_query(mysql,
"insert into t2 values (12,'a'),(13,'b')");
15539 res= mysql_insert_id(mysql);
15540 DIE_UNLESS(res == 0);
15541 rc= mysql_query(mysql,
"insert ignore into t2 values (12,'a'),(13,'b')");
15543 res= mysql_insert_id(mysql);
15544 DIE_UNLESS(res == 0);
15546 rc= mysql_query(mysql,
"insert into t2 values (null,'e'),(12,'a'),(13,'b')");
15548 rc= mysql_query(mysql,
"insert into t2 values (null,'e'),(12,'a'),(13,'b'),(25,'g')");
15550 rc= mysql_query(mysql,
"insert into t2 values (null,last_insert_id(300))");
15552 res= mysql_insert_id(mysql);
15557 DIE_UNLESS(res == 20);
15559 rc= mysql_query(mysql,
"drop table t2");
15561 rc= mysql_query(mysql,
"create table t2 (f1 int not null primary key "
15562 "auto_increment, f2 varchar(255), unique (f2))");
15564 rc= mysql_query(mysql,
"insert into t2 values (null,'e')");
15565 res= mysql_insert_id(mysql);
15566 DIE_UNLESS(res == 1);
15567 rc= mysql_query(mysql,
"insert ignore into t2 values (null,'e'),(null,'a'),(null,'e')");
15569 res= mysql_insert_id(mysql);
15570 DIE_UNLESS(res == 2);
15572 rc= mysql_query(mysql,
"insert ignore into t2 values (null,'e'),(12,'c'),(null,'d')");
15574 res= mysql_insert_id(mysql);
15579 DIE_UNLESS(res == 13);
15581 rc= mysql_query(mysql,
"update t2 set f1=14 where f1=12");
15583 res= mysql_insert_id(mysql);
15584 DIE_UNLESS(res == 0);
15585 rc= mysql_query(mysql,
"update t2 set f1=0 where f1=14");
15587 res= mysql_insert_id(mysql);
15588 DIE_UNLESS(res == 0);
15589 rc= mysql_query(mysql,
"update t2 set f2=last_insert_id(372) where f1=0");
15591 res= mysql_insert_id(mysql);
15592 DIE_UNLESS(res == 372);
15594 rc= mysql_query(mysql,
"insert into t2 values (null,'g')");
15596 res= mysql_insert_id(mysql);
15597 DIE_UNLESS(res == 15);
15598 rc= mysql_query(mysql,
"update t2 set f2=(@li:=last_insert_id()) where f1=15");
15600 res= mysql_insert_id(mysql);
15601 DIE_UNLESS(res == 0);
15607 rc= mysql_query(mysql,
"insert into t2 values (null,@li) on duplicate key "
15608 "update f2=concat('we updated ',f2)");
15610 res= mysql_insert_id(mysql);
15611 DIE_UNLESS(res == 15);
15613 rc= mysql_query(mysql,
"drop table t1,t2");
15621 static void test_bug20152()
15627 const char *query=
"INSERT INTO t1 (f1) VALUES (?)";
15629 myheader(
"test_bug20152");
15631 memset(my_bind, 0,
sizeof(my_bind));
15632 my_bind[0].buffer_type= MYSQL_TYPE_DATE;
15633 my_bind[0].buffer= (
void*)&tm;
15642 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
15644 rc= mysql_query(mysql,
"CREATE TABLE t1 (f1 DATE)");
15647 stmt= mysql_stmt_init(mysql);
15648 rc= mysql_stmt_prepare(stmt, query, strlen(query));
15649 check_execute(stmt, rc);
15650 rc= mysql_stmt_bind_param(stmt, my_bind);
15651 check_execute(stmt, rc);
15652 rc= mysql_stmt_execute(stmt);
15653 check_execute(stmt, rc);
15654 rc= mysql_stmt_close(stmt);
15655 check_execute(stmt, rc);
15656 rc= mysql_query(mysql,
"DROP TABLE t1");
15659 if (tm.hour == 14 && tm.minute == 9 && tm.second == 42) {
15663 printf(
"[14:09:42] != [%02d:%02d:%02d]\n", tm.hour, tm.minute, tm.second);
15670 static void test_bug15752()
15674 const int ITERATION_COUNT= 100;
15675 const char *query=
"CALL p1()";
15677 myheader(
"test_bug15752");
15679 rc= mysql_query(mysql,
"drop procedure if exists p1");
15681 rc= mysql_query(mysql,
"create procedure p1() select 1");
15684 mysql_client_init(&mysql_local);
15685 if (! mysql_real_connect(&mysql_local, opt_host, opt_user,
15686 opt_password, current_db, opt_port,
15688 CLIENT_MULTI_STATEMENTS))
15690 printf(
"Unable connect to MySQL server: %s\n", mysql_error(&mysql_local));
15693 rc= mysql_real_query(&mysql_local, query, strlen(query));
15695 mysql_free_result(mysql_store_result(&mysql_local));
15697 rc= mysql_real_query(&mysql_local, query, strlen(query));
15698 DIE_UNLESS(rc && mysql_errno(&mysql_local) == CR_COMMANDS_OUT_OF_SYNC);
15701 printf(
"Got error (as expected): %s\n", mysql_error(&mysql_local));
15705 DIE_UNLESS(mysql_next_result(&mysql_local) == 0);
15706 mysql_free_result(mysql_store_result(&mysql_local));
15707 DIE_UNLESS(mysql_next_result(&mysql_local) == -1);
15710 for (i = 0; i < ITERATION_COUNT; i++)
15712 if (mysql_real_query(&mysql_local, query, strlen(query)))
15714 printf(
"\ni=%d %s failed: %s\n", i, query, mysql_error(&mysql_local));
15717 mysql_free_result(mysql_store_result(&mysql_local));
15718 DIE_UNLESS(mysql_next_result(&mysql_local) == 0);
15719 mysql_free_result(mysql_store_result(&mysql_local));
15720 DIE_UNLESS(mysql_next_result(&mysql_local) == -1);
15723 mysql_close(&mysql_local);
15724 rc= mysql_query(mysql,
"drop procedure p1");
15734 static void test_bug21206()
15736 const size_t cursor_count= 1025;
15740 "DROP TABLE IF EXISTS t1",
15741 "CREATE TABLE t1 (i INT)",
15742 "INSERT INTO t1 VALUES (1), (2), (3)"
15744 const char *query=
"SELECT * FROM t1";
15751 DBUG_ENTER(
"test_bug21206");
15752 myheader(
"test_bug21206");
15754 fill_tables(create_table,
sizeof(create_table) /
sizeof(*create_table));
15756 for (fetch= fetch_array; fetch < fetch_array + cursor_count; ++fetch)
15759 stmt_fetch_init(fetch, fetch - fetch_array, query);
15762 for (fetch= fetch_array; fetch < fetch_array + cursor_count; ++fetch)
15763 stmt_fetch_close(fetch);
15774 static void test_status()
15776 const char *status;
15777 DBUG_ENTER(
"test_status");
15778 myheader(
"test_status");
15780 if (!(status= mysql_stat(mysql)))
15782 myerror(
"mysql_stat failed");
15783 die(__FILE__, __LINE__,
"mysql_stat failed");
15797 static void test_bug21726()
15799 const char *create_table[]=
15801 "DROP TABLE IF EXISTS t1",
15802 "CREATE TABLE t1 (i INT)",
15803 "INSERT INTO t1 VALUES (1)",
15805 const char *update_query=
"UPDATE t1 SET i= LAST_INSERT_ID(i + 1)";
15807 my_ulonglong insert_id;
15808 const char *select_query=
"SELECT * FROM t1";
15811 DBUG_ENTER(
"test_bug21726");
15812 myheader(
"test_bug21726");
15814 fill_tables(create_table,
sizeof(create_table) /
sizeof(*create_table));
15816 rc= mysql_query(mysql, update_query);
15818 insert_id= mysql_insert_id(mysql);
15819 DIE_UNLESS(insert_id == 2);
15821 rc= mysql_query(mysql, update_query);
15823 insert_id= mysql_insert_id(mysql);
15824 DIE_UNLESS(insert_id == 3);
15826 rc= mysql_query(mysql, select_query);
15828 insert_id= mysql_insert_id(mysql);
15829 DIE_UNLESS(insert_id == 3);
15830 result= mysql_store_result(mysql);
15831 mysql_free_result(result);
15845 static void test_bug23383()
15847 const char *insert_query=
"INSERT INTO t1 VALUES (1), (2)";
15848 const char *update_query=
"UPDATE t1 SET i= 4 WHERE i = 3";
15850 my_ulonglong row_count;
15853 DBUG_ENTER(
"test_bug23383");
15854 myheader(
"test_bug23383");
15856 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
15859 rc= mysql_query(mysql,
"CREATE TABLE t1 (i INT UNIQUE)");
15862 rc= mysql_query(mysql, insert_query);
15864 row_count= mysql_affected_rows(mysql);
15865 DIE_UNLESS(row_count == 2);
15867 rc= mysql_query(mysql, insert_query);
15868 DIE_UNLESS(rc != 0);
15869 row_count= mysql_affected_rows(mysql);
15870 DIE_UNLESS(row_count == (my_ulonglong)-1);
15872 rc= mysql_query(mysql, update_query);
15874 row_count= mysql_affected_rows(mysql);
15875 DIE_UNLESS(row_count == 0);
15877 rc= mysql_query(mysql,
"DELETE FROM t1");
15880 stmt= mysql_stmt_init(mysql);
15881 DIE_UNLESS(stmt != 0);
15883 rc= mysql_stmt_prepare(stmt, insert_query, strlen(insert_query));
15884 check_execute(stmt, rc);
15886 rc= mysql_stmt_execute(stmt);
15887 check_execute(stmt, rc);
15888 row_count= mysql_stmt_affected_rows(stmt);
15889 DIE_UNLESS(row_count == 2);
15891 rc= mysql_stmt_execute(stmt);
15892 DIE_UNLESS(rc != 0);
15893 row_count= mysql_stmt_affected_rows(stmt);
15894 DIE_UNLESS(row_count == (my_ulonglong)-1);
15896 rc= mysql_stmt_prepare(stmt, update_query, strlen(update_query));
15897 check_execute(stmt, rc);
15899 rc= mysql_stmt_execute(stmt);
15900 check_execute(stmt, rc);
15901 row_count= mysql_stmt_affected_rows(stmt);
15902 DIE_UNLESS(row_count == 0);
15904 rc= mysql_stmt_close(stmt);
15905 check_execute(stmt, rc);
15907 rc= mysql_query(mysql,
"DROP TABLE t1");
15922 static void test_bug21635()
15924 const char *expr[]=
15926 "MIN(i)",
"MIN(i)",
15927 "MIN(i) AS A1",
"A1",
15928 "MAX(i)",
"MAX(i)",
15929 "MAX(i) AS A2",
"A2",
15930 "COUNT(i)",
"COUNT(i)",
15931 "COUNT(i) AS A3",
"A3",
15933 char query[MAX_TEST_QUERY_LENGTH];
15937 unsigned int field_count,
i, j;
15940 DBUG_ENTER(
"test_bug21635");
15941 myheader(
"test_bug21635");
15943 query_end= strxmov(query,
"SELECT ", NullS);
15944 for (i= 0; i <
sizeof(expr) /
sizeof(*expr) / 2; ++
i)
15945 query_end= strxmov(query_end, expr[i * 2],
", ", NullS);
15946 query_end= strxmov(query_end - 2,
" FROM t1 GROUP BY i", NullS);
15947 DIE_UNLESS(query_end - query < MAX_TEST_QUERY_LENGTH);
15949 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
15951 rc= mysql_query(mysql,
"CREATE TABLE t1 (i INT)");
15957 for (j= 0; j < 2 ; j++)
15959 rc= mysql_query(mysql,
"INSERT INTO t1 VALUES (1)");
15962 rc= mysql_real_query(mysql, query, query_end - query);
15965 result= mysql_use_result(mysql);
15966 DIE_UNLESS(result);
15968 field_count= mysql_field_count(mysql);
15969 for (i= 0; i < field_count; ++
i)
15971 field= mysql_fetch_field_direct(result, i);
15974 printf(
"%s -> %s ... ", expr[i * 2], field->name);
15976 DIE_UNLESS(field->db[0] == 0 && field->org_table[0] == 0 &&
15977 field->table[0] == 0 && field->org_name[0] == 0);
15978 DIE_UNLESS(strcmp(field->name, expr[i * 2 + 1]) == 0);
15984 mysql_free_result(result);
15986 rc= mysql_query(mysql,
"DROP TABLE t1");
15997 static void test_bug24179()
16002 DBUG_ENTER(
"test_bug24179");
16003 myheader(
"test_bug24179");
16005 stmt= open_cursor(
"select 1 into @a");
16006 rc= mysql_stmt_execute(stmt);
16010 printf(
"Got error (as expected): %d %s\n",
16011 mysql_stmt_errno(stmt),
16012 mysql_stmt_error(stmt));
16014 DIE_UNLESS(mysql_stmt_errno(stmt) == 1323);
16015 mysql_stmt_close(stmt);
16025 static void test_bug32265()
16032 DBUG_ENTER(
"test_bug32265");
16033 myheader(
"test_bug32265");
16035 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
16037 rc= mysql_query(mysql,
"CREATE TABLE t1 (a INTEGER)");
16039 rc= mysql_query(mysql,
"INSERT INTO t1 VALUES (1)");
16041 rc= mysql_query(mysql,
"CREATE VIEW v1 AS SELECT * FROM t1");
16044 stmt= open_cursor(
"SELECT * FROM t1");
16045 rc= mysql_stmt_execute(stmt);
16046 check_execute(stmt, rc);
16048 metadata= mysql_stmt_result_metadata(stmt);
16049 field= mysql_fetch_field(metadata);
16051 DIE_UNLESS(strcmp(field->table,
"t1") == 0);
16052 DIE_UNLESS(strcmp(field->org_table,
"t1") == 0);
16053 DIE_UNLESS(strcmp(field->db,
"client_test_db") == 0);
16054 mysql_free_result(metadata);
16055 mysql_stmt_close(stmt);
16057 stmt= open_cursor(
"SELECT a '' FROM t1 ``");
16058 rc= mysql_stmt_execute(stmt);
16059 check_execute(stmt, rc);
16061 metadata= mysql_stmt_result_metadata(stmt);
16062 field= mysql_fetch_field(metadata);
16063 DIE_UNLESS(strcmp(field->table,
"") == 0);
16064 DIE_UNLESS(strcmp(field->org_table,
"t1") == 0);
16065 DIE_UNLESS(strcmp(field->db,
"client_test_db") == 0);
16066 mysql_free_result(metadata);
16067 mysql_stmt_close(stmt);
16069 stmt= open_cursor(
"SELECT a '' FROM t1 ``");
16070 rc= mysql_stmt_execute(stmt);
16071 check_execute(stmt, rc);
16073 metadata= mysql_stmt_result_metadata(stmt);
16074 field= mysql_fetch_field(metadata);
16075 DIE_UNLESS(strcmp(field->table,
"") == 0);
16076 DIE_UNLESS(strcmp(field->org_table,
"t1") == 0);
16077 DIE_UNLESS(strcmp(field->db,
"client_test_db") == 0);
16078 mysql_free_result(metadata);
16079 mysql_stmt_close(stmt);
16081 stmt= open_cursor(
"SELECT * FROM v1");
16082 rc= mysql_stmt_execute(stmt);
16083 check_execute(stmt, rc);
16085 metadata= mysql_stmt_result_metadata(stmt);
16086 field= mysql_fetch_field(metadata);
16087 DIE_UNLESS(strcmp(field->table,
"v1") == 0);
16088 DIE_UNLESS(strcmp(field->org_table,
"v1") == 0);
16089 DIE_UNLESS(strcmp(field->db,
"client_test_db") == 0);
16090 mysql_free_result(metadata);
16091 mysql_stmt_close(stmt);
16093 stmt= open_cursor(
"SELECT * FROM v1 /* SIC */ GROUP BY 1");
16094 rc= mysql_stmt_execute(stmt);
16095 check_execute(stmt, rc);
16097 metadata= mysql_stmt_result_metadata(stmt);
16098 field= mysql_fetch_field(metadata);
16099 DIE_UNLESS(strcmp(field->table,
"v1") == 0);
16100 DIE_UNLESS(strcmp(field->org_table,
"v1") == 0);
16101 DIE_UNLESS(strcmp(field->db,
"client_test_db") == 0);
16102 mysql_free_result(metadata);
16103 mysql_stmt_close(stmt);
16105 rc= mysql_query(mysql,
"DROP VIEW v1");
16107 rc= mysql_query(mysql,
"DROP TABLE t1");
16117 static void test_bug28075()
16121 DBUG_ENTER(
"test_bug28075");
16122 myheader(
"test_bug28075");
16124 rc= mysql_dump_debug_info(mysql);
16125 DIE_UNLESS(rc == 0);
16127 rc= mysql_ping(mysql);
16128 DIE_UNLESS(rc == 0);
16138 static void test_bug27876()
16143 uchar utf8_func[] =
16145 0xd1, 0x84, 0xd1, 0x83, 0xd0, 0xbd, 0xd0, 0xba,
16146 0xd1, 0x86, 0xd0, 0xb8, 0xd0, 0xb9, 0xd0, 0xba,
16151 uchar utf8_param[] =
16153 0xd0, 0xbf, 0xd0, 0xb0, 0xd1, 0x80, 0xd0, 0xb0,
16154 0xd0, 0xbc, 0xd0, 0xb5, 0xd1, 0x82, 0xd1, 0x8a,
16155 0xd1, 0x80, 0x5f, 0xd0, 0xb2, 0xd0, 0xb5, 0xd1,
16156 0x80, 0xd1, 0x81, 0xd0, 0xb8, 0xd1, 0x8f,
16162 DBUG_ENTER(
"test_bug27876");
16163 myheader(
"test_bug27876");
16165 rc= mysql_query(mysql,
"set names utf8");
16168 rc= mysql_query(mysql,
"select version()");
16170 result= mysql_store_result(mysql);
16172 mysql_free_result(result);
16174 sprintf(query,
"DROP FUNCTION IF EXISTS %s", (
char*) utf8_func);
16175 rc= mysql_query(mysql, query);
16179 "CREATE FUNCTION %s( %s VARCHAR(25))"
16180 " RETURNS VARCHAR(25) DETERMINISTIC RETURN %s",
16181 (
char*) utf8_func, (
char*) utf8_param, (
char*) utf8_param);
16182 rc= mysql_query(mysql, query);
16184 sprintf(query,
"SELECT %s(VERSION())", (
char*) utf8_func);
16185 rc= mysql_query(mysql, query);
16187 result= mysql_store_result(mysql);
16189 mysql_free_result(result);
16191 sprintf(query,
"DROP FUNCTION %s", (
char*) utf8_func);
16192 rc= mysql_query(mysql, query);
16195 rc= mysql_query(mysql,
"set names default");
16206 static void test_bug28505()
16210 myquery(mysql_query(mysql,
"drop table if exists t1"));
16211 myquery(mysql_query(mysql,
"create table t1(f1 int primary key)"));
16212 myquery(mysql_query(mysql,
"insert into t1 values(1)"));
16213 myquery(mysql_query(mysql,
16214 "insert into t1 values(1) on duplicate key update f1=1"));
16215 res= mysql_affected_rows(mysql);
16217 myquery(mysql_query(mysql,
"drop table t1"));
16225 static void test_bug28934()
16232 myquery(mysql_query(mysql,
"drop table if exists t1"));
16233 myquery(mysql_query(mysql,
"create table t1(id int)"));
16235 myquery(mysql_query(mysql,
"insert into t1 values(1),(2),(3),(4),(5)"));
16236 stmt= mysql_simple_prepare(mysql,
"select * from t1 where id in(?,?,?,?,?)");
16239 memset (&bind, 0,
sizeof (bind));
16240 for (cnt= 0; cnt < 5; cnt++)
16242 bind[cnt].buffer_type= MYSQL_TYPE_LONG;
16243 bind[cnt].buffer= (
char*)&cnt;
16244 bind[cnt].buffer_length= 0;
16246 myquery(mysql_stmt_bind_param(stmt, bind));
16248 stmt->param_count=2;
16249 error= mysql_stmt_execute(stmt);
16250 DIE_UNLESS(error != 0);
16252 mysql_stmt_close(stmt);
16254 myquery(mysql_query(mysql,
"drop table t1"));
16261 static void reconnect(
MYSQL **mysql)
16263 mysql_close(*mysql);
16264 *mysql= mysql_client_init(NULL);
16265 DIE_UNLESS(*mysql != 0);
16266 *mysql= mysql_real_connect(*mysql, opt_host, opt_user,
16267 opt_password, current_db, opt_port,
16268 opt_unix_socket, 0);
16269 DIE_UNLESS(*mysql != 0);
16273 static void test_change_user()
16276 const char *user_pw=
"mysqltest_pw";
16277 const char *user_no_pw=
"mysqltest_no_pw";
16278 const char *pw=
"password";
16279 const char *db=
"mysqltest_user_test_database";
16283 DBUG_ENTER(
"test_change_user");
16284 myheader(
"test_change_user");
16286 l_mysql= mysql_client_init(NULL);
16287 DIE_UNLESS(l_mysql != NULL);
16289 l_mysql= mysql_real_connect(l_mysql, opt_host, opt_user,
16290 opt_password, current_db, opt_port,
16291 opt_unix_socket, 0);
16292 DIE_UNLESS(l_mysql != 0);
16296 sprintf(buff,
"drop database if exists %s", db);
16297 rc= mysql_query(l_mysql, buff);
16298 myquery2(l_mysql, rc);
16300 sprintf(buff,
"create database %s", db);
16301 rc= mysql_query(l_mysql, buff);
16302 myquery2(l_mysql, rc);
16305 "grant select on %s.* to %s@'%%' identified by '%s'",
16309 rc= mysql_query(l_mysql, buff);
16310 myquery2(l_mysql, rc);
16313 "grant select on %s.* to %s@'localhost' identified by '%s'",
16317 rc= mysql_query(l_mysql, buff);
16318 myquery2(l_mysql, rc);
16321 "grant select on %s.* to %s@'%%'",
16324 rc= mysql_query(l_mysql, buff);
16325 myquery2(l_mysql, rc);
16328 "grant select on %s.* to %s@'localhost'",
16331 rc= mysql_query(l_mysql, buff);
16332 myquery2(l_mysql, rc);
16335 rc= mysql_change_user(l_mysql, NULL, NULL, NULL);
16338 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16339 reconnect(&l_mysql);
16341 rc= mysql_change_user(l_mysql,
"", NULL, NULL);
16344 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16345 reconnect(&l_mysql);
16347 rc= mysql_change_user(l_mysql,
"",
"", NULL);
16350 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16351 reconnect(&l_mysql);
16354 rc= mysql_change_user(l_mysql,
"",
"",
"");
16357 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16358 reconnect(&l_mysql);
16360 rc= mysql_change_user(l_mysql, NULL,
"",
"");
16363 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16364 reconnect(&l_mysql);
16367 rc= mysql_change_user(l_mysql, NULL, NULL,
"");
16370 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16371 reconnect(&l_mysql);
16373 rc= mysql_change_user(l_mysql,
"", NULL,
"");
16376 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16377 reconnect(&l_mysql);
16379 rc= mysql_change_user(l_mysql, user_pw, NULL,
"");
16382 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16383 reconnect(&l_mysql);
16385 rc= mysql_change_user(l_mysql, user_pw,
"",
"");
16388 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16389 reconnect(&l_mysql);
16391 rc= mysql_change_user(l_mysql, user_pw,
"", NULL);
16394 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16395 reconnect(&l_mysql);
16397 rc= mysql_change_user(l_mysql, user_pw, NULL, NULL);
16400 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16401 reconnect(&l_mysql);
16403 rc= mysql_change_user(l_mysql, user_pw,
"", db);
16406 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16407 reconnect(&l_mysql);
16409 rc= mysql_change_user(l_mysql, user_pw, NULL, db);
16412 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16413 reconnect(&l_mysql);
16415 rc= mysql_change_user(l_mysql, user_pw, pw, db);
16416 myquery2(l_mysql, rc);
16418 rc= mysql_change_user(l_mysql, user_pw, pw, NULL);
16419 myquery2(l_mysql, rc);
16421 rc= mysql_change_user(l_mysql, user_pw, pw,
"");
16422 myquery2(l_mysql, rc);
16424 rc= mysql_change_user(l_mysql, user_no_pw, pw, db);
16427 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16429 rc= mysql_change_user(l_mysql, user_no_pw, pw,
"");
16432 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16433 reconnect(&l_mysql);
16435 rc= mysql_change_user(l_mysql, user_no_pw, pw, NULL);
16438 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16439 reconnect(&l_mysql);
16441 rc= mysql_change_user(l_mysql, user_no_pw,
"", NULL);
16442 myquery2(l_mysql, rc);
16444 rc= mysql_change_user(l_mysql, user_no_pw,
"",
"");
16445 myquery2(l_mysql, rc);
16447 rc= mysql_change_user(l_mysql, user_no_pw,
"", db);
16448 myquery2(l_mysql, rc);
16450 rc= mysql_change_user(l_mysql, user_no_pw, NULL, db);
16451 myquery2(l_mysql, rc);
16453 rc= mysql_change_user(l_mysql,
"", pw, db);
16456 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16457 reconnect(&l_mysql);
16459 rc= mysql_change_user(l_mysql,
"", pw,
"");
16462 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16463 reconnect(&l_mysql);
16465 rc= mysql_change_user(l_mysql,
"", pw, NULL);
16468 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16470 rc= mysql_change_user(l_mysql, NULL, pw, NULL);
16473 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16474 reconnect(&l_mysql);
16476 rc= mysql_change_user(l_mysql, NULL, NULL, db);
16479 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16480 reconnect(&l_mysql);
16482 rc= mysql_change_user(l_mysql, NULL,
"", db);
16485 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16486 reconnect(&l_mysql);
16488 rc= mysql_change_user(l_mysql,
"",
"", db);
16491 printf(
"Got error (as expected): %s\n", mysql_error(l_mysql));
16492 reconnect(&l_mysql);
16496 mysql_close(l_mysql);
16498 sprintf(buff,
"drop database %s", db);
16499 rc= mysql_query(mysql, buff);
16502 sprintf(buff,
"drop user %s@'%%'", user_pw);
16503 rc= mysql_query(mysql, buff);
16506 sprintf(buff,
"drop user %s@'%%'", user_no_pw);
16507 rc= mysql_query(mysql, buff);
16510 sprintf(buff,
"drop user %s@'localhost'", user_pw);
16511 rc= mysql_query(mysql, buff);
16514 sprintf(buff,
"drop user %s@'localhost'", user_no_pw);
16515 rc= mysql_query(mysql, buff);
16525 static void test_bug27592()
16527 const int NUM_ITERATIONS= 40;
16534 DBUG_ENTER(
"test_bug27592");
16535 myheader(
"test_bug27592");
16537 mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
16538 mysql_query(mysql,
"CREATE TABLE t1(c2 DATETIME)");
16540 stmt= mysql_simple_prepare(mysql,
"INSERT INTO t1 VALUES (?)");
16543 memset(bind, 0,
sizeof(bind));
16545 bind[0].buffer_type= MYSQL_TYPE_DATETIME;
16546 bind[0].buffer= (
char *) &time_val;
16547 bind[0].length= NULL;
16549 for (i= 0; i < NUM_ITERATIONS; i++)
16551 time_val.year= 2007;
16555 time_val.minute= 41;
16556 time_val.second= 3;
16561 rc= mysql_stmt_bind_param(stmt, bind);
16562 check_execute(stmt, rc);
16564 rc= mysql_stmt_execute(stmt);
16565 check_execute(stmt, rc);
16568 mysql_stmt_close(stmt);
16577 static void test_bug29687()
16579 const int NUM_ITERATIONS= 40;
16584 DBUG_ENTER(
"test_bug29687");
16585 myheader(
"test_bug29687");
16587 stmt= mysql_simple_prepare(mysql,
"SELECT 1 FROM dual WHERE 0=2");
16590 for (i= 0; i < NUM_ITERATIONS; i++)
16592 rc= mysql_stmt_execute(stmt);
16593 check_execute(stmt, rc);
16594 mysql_stmt_store_result(stmt);
16595 while (mysql_stmt_fetch(stmt)==0);
16596 mysql_stmt_free_result(stmt);
16599 mysql_stmt_close(stmt);
16609 static void test_bug29692()
16613 if (!(conn= mysql_client_init(NULL)))
16615 myerror(
"test_bug29692 init failed");
16619 if (!(mysql_real_connect(conn, opt_host, opt_user,
16620 opt_password, opt_db ? opt_db:
"test", opt_port,
16621 opt_unix_socket, CLIENT_FOUND_ROWS)))
16623 myerror(
"test_bug29692 connection failed");
16624 mysql_close(mysql);
16627 myquery(mysql_query(conn,
"drop table if exists t1"));
16628 myquery(mysql_query(conn,
"create table t1(f1 int)"));
16629 myquery(mysql_query(conn,
"insert into t1 values(1)"));
16630 DIE_UNLESS(1 == mysql_affected_rows(conn));
16631 myquery(mysql_query(conn,
"drop table t1"));
16639 static void test_bug29306()
16645 DBUG_ENTER(
"test_bug29306");
16646 myheader(
"test_bug29306");
16648 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS tab17557");
16650 rc= mysql_query(mysql,
"DROP VIEW IF EXISTS view17557");
16652 rc= mysql_query(mysql,
"CREATE TABLE tab17557 (dd decimal (3,1))");
16654 rc= mysql_query(mysql,
"CREATE VIEW view17557 as SELECT dd FROM tab17557");
16656 rc= mysql_query(mysql,
"INSERT INTO tab17557 VALUES (7.6)");
16660 res= mysql_list_fields(mysql,
"view17557", NULL);
16661 while ((field= mysql_fetch_field(res)))
16665 printf(
"field name %s\n", field->name);
16666 printf(
"field table %s\n", field->table);
16667 printf(
"field decimals %d\n", field->decimals);
16668 if (field->decimals < 1)
16669 printf(
"Error! No decimals! \n");
16672 DIE_UNLESS(field->decimals == 1);
16674 mysql_free_result(res);
16676 rc= mysql_query(mysql,
"DROP TABLE tab17557");
16678 rc= mysql_query(mysql,
"DROP VIEW view17557");
16688 static void bug30472_retrieve_charset_info(
MYSQL *con,
16689 char *character_set_name,
16690 char *character_set_client,
16691 char *character_set_results,
16692 char *collation_connection)
16699 strcpy(character_set_name, mysql_character_set_name(con));
16703 DIE_IF(mysql_query(con,
"SHOW VARIABLES LIKE 'character_set_client'"));
16704 DIE_UNLESS(rs= mysql_store_result(con));
16705 DIE_UNLESS(row= mysql_fetch_row(rs));
16706 strcpy(character_set_client, row[1]);
16707 mysql_free_result(rs);
16709 DIE_IF(mysql_query(con,
"SHOW VARIABLES LIKE 'character_set_results'"));
16710 DIE_UNLESS(rs= mysql_store_result(con));
16711 DIE_UNLESS(row= mysql_fetch_row(rs));
16712 strcpy(character_set_results, row[1]);
16713 mysql_free_result(rs);
16715 DIE_IF(mysql_query(con,
"SHOW VARIABLES LIKE 'collation_connection'"));
16716 DIE_UNLESS(rs= mysql_store_result(con));
16717 DIE_UNLESS(row= mysql_fetch_row(rs));
16718 strcpy(collation_connection, row[1]);
16719 mysql_free_result(rs);
16722 static void test_bug30472()
16726 char character_set_name_1[MY_CS_NAME_SIZE];
16727 char character_set_client_1[MY_CS_NAME_SIZE];
16728 char character_set_results_1[MY_CS_NAME_SIZE];
16729 char collation_connnection_1[MY_CS_NAME_SIZE];
16731 char character_set_name_2[MY_CS_NAME_SIZE];
16732 char character_set_client_2[MY_CS_NAME_SIZE];
16733 char character_set_results_2[MY_CS_NAME_SIZE];
16734 char collation_connnection_2[MY_CS_NAME_SIZE];
16736 char character_set_name_3[MY_CS_NAME_SIZE];
16737 char character_set_client_3[MY_CS_NAME_SIZE];
16738 char character_set_results_3[MY_CS_NAME_SIZE];
16739 char collation_connnection_3[MY_CS_NAME_SIZE];
16741 char character_set_name_4[MY_CS_NAME_SIZE];
16742 char character_set_client_4[MY_CS_NAME_SIZE];
16743 char character_set_results_4[MY_CS_NAME_SIZE];
16744 char collation_connnection_4[MY_CS_NAME_SIZE];
16748 DIE_UNLESS(mysql_client_init(&con));
16750 DIE_UNLESS(mysql_real_connect(&con,
16754 opt_db ? opt_db :
"test",
16757 CLIENT_FOUND_ROWS));
16761 bug30472_retrieve_charset_info(&con,
16762 character_set_name_1,
16763 character_set_client_1,
16764 character_set_results_1,
16765 collation_connnection_1);
16769 DIE_IF(mysql_set_character_set(&con,
"utf8"));
16773 bug30472_retrieve_charset_info(&con,
16774 character_set_name_2,
16775 character_set_client_2,
16776 character_set_results_2,
16777 collation_connnection_2);
16785 DIE_UNLESS(strcmp(character_set_name_2,
"utf8") == 0);
16786 DIE_UNLESS(strcmp(character_set_client_2,
"utf8") == 0);
16787 DIE_UNLESS(strcmp(character_set_results_2,
"utf8") == 0);
16788 DIE_UNLESS(strcmp(collation_connnection_2,
"utf8_general_ci") == 0);
16790 DIE_UNLESS(strcmp(character_set_name_1, character_set_name_2) != 0);
16791 DIE_UNLESS(strcmp(character_set_client_1, character_set_client_2) != 0);
16792 DIE_UNLESS(strcmp(character_set_results_1, character_set_results_2) != 0);
16793 DIE_UNLESS(strcmp(collation_connnection_1, collation_connnection_2) != 0);
16797 DIE_IF(mysql_change_user(&con,
16800 opt_db ? opt_db :
"test"));
16804 bug30472_retrieve_charset_info(&con,
16805 character_set_name_3,
16806 character_set_client_3,
16807 character_set_results_3,
16808 collation_connnection_3);
16812 DIE_UNLESS(strcmp(character_set_name_1, character_set_name_3) == 0);
16813 DIE_UNLESS(strcmp(character_set_client_1, character_set_client_3) == 0);
16814 DIE_UNLESS(strcmp(character_set_results_1, character_set_results_3) == 0);
16815 DIE_UNLESS(strcmp(collation_connnection_1, collation_connnection_3) == 0);
16819 mysql_options(&con, MYSQL_SET_CHARSET_NAME,
"utf8");
16826 DIE_IF(mysql_change_user(&con,
16829 opt_db ? opt_db :
"test"));
16833 bug30472_retrieve_charset_info(&con,
16834 character_set_name_4,
16835 character_set_client_4,
16836 character_set_results_4,
16837 collation_connnection_4);
16841 DIE_UNLESS(strcmp(character_set_name_4,
"utf8") == 0);
16842 DIE_UNLESS(strcmp(character_set_client_4,
"utf8") == 0);
16843 DIE_UNLESS(strcmp(character_set_results_4,
"utf8") == 0);
16844 DIE_UNLESS(strcmp(collation_connnection_4,
"utf8_general_ci") == 0);
16851 static void bug20023_change_user(
MYSQL *con)
16853 DIE_IF(mysql_change_user(con,
16856 opt_db ? opt_db :
"test"));
16859 static my_bool query_str_variable(
MYSQL *con,
16860 const char *var_name,
16867 char query_buffer[MAX_TEST_QUERY_LENGTH];
16871 my_snprintf(query_buffer,
sizeof (query_buffer),
16872 "SELECT %s", var_name);
16874 DIE_IF(mysql_query(con, query_buffer));
16875 DIE_UNLESS(rs= mysql_store_result(con));
16876 DIE_UNLESS(row= mysql_fetch_row(rs));
16878 is_null= row[0] == NULL;
16881 my_snprintf(str, len,
"%s", row[0]);
16883 mysql_free_result(rs);
16888 static my_bool query_int_variable(
MYSQL *con,
16889 const char *var_name,
16893 my_bool is_null= query_str_variable(con, var_name, str,
sizeof(str));
16896 *var_value= atoi(str);
16901 static void test_bug20023()
16905 int sql_big_selects_orig= 0;
16911 char max_join_size_orig[32];
16913 int sql_big_selects_2= 0;
16914 int sql_big_selects_3= 0;
16915 int sql_big_selects_4= 0;
16916 int sql_big_selects_5= 0;
16918 char query_buffer[MAX_TEST_QUERY_LENGTH];
16922 DIE_UNLESS(mysql_client_init(&con));
16924 DIE_UNLESS(mysql_real_connect(&con,
16928 opt_db ? opt_db :
"test",
16931 CLIENT_FOUND_ROWS));
16937 query_int_variable(&con,
16938 "@@session.sql_big_selects",
16939 &sql_big_selects_orig);
16941 query_str_variable(&con,
16942 "@@global.max_join_size",
16943 max_join_size_orig,
16944 sizeof(max_join_size_orig));
16952 bug20023_change_user(&con);
16956 query_int_variable(&con,
16957 "@@session.sql_big_selects",
16958 &sql_big_selects_2);
16962 DIE_UNLESS(sql_big_selects_orig == sql_big_selects_2);
16971 DIE_IF(mysql_query(&con,
"SET @@global.max_join_size = 10000"));
16972 DIE_IF(mysql_query(&con,
"SET @@session.max_join_size = default"));
16976 bug20023_change_user(&con);
16980 query_int_variable(&con,
16981 "@@session.sql_big_selects",
16982 &sql_big_selects_3);
16986 DIE_UNLESS(sql_big_selects_3 == 0);
16995 DIE_IF(mysql_query(&con,
"SET @@global.max_join_size = cast(-1 as unsigned int)"));
16996 DIE_IF(mysql_query(&con,
"SET @@session.max_join_size = default"));
17000 bug20023_change_user(&con);
17004 query_int_variable(&con,
17005 "@@session.sql_big_selects",
17006 &sql_big_selects_4);
17010 DIE_UNLESS(sql_big_selects_4 == 1);
17019 my_snprintf(query_buffer,
17020 sizeof (query_buffer),
17021 "SET @@global.max_join_size = %s",
17022 max_join_size_orig);
17024 DIE_IF(mysql_query(&con, query_buffer));
17026 DIE_IF(mysql_query(&con,
"SET @@global.max_join_size = cast(-1 as unsigned int)"));
17027 DIE_IF(mysql_query(&con,
"SET @@session.max_join_size = default"));
17031 bug20023_change_user(&con);
17035 query_int_variable(&con,
17036 "@@session.sql_big_selects",
17037 &sql_big_selects_5);
17041 DIE_UNLESS(sql_big_selects_5 == sql_big_selects_orig);
17050 static void bug31418_impl()
17059 DIE_UNLESS(mysql_client_init(&con));
17061 DIE_UNLESS(mysql_real_connect(&con,
17065 opt_db ? opt_db :
"test",
17068 CLIENT_FOUND_ROWS));
17076 is_null= query_int_variable(&con,
17077 "IS_FREE_LOCK('bug31418')",
17079 DIE_UNLESS(!is_null && rc);
17081 is_null= query_int_variable(&con,
17082 "IS_USED_LOCK('bug31418')",
17084 DIE_UNLESS(is_null);
17092 query_int_variable(&con,
"GET_LOCK('bug31418', 1)", &rc);
17095 is_null= query_int_variable(&con,
17096 "IS_FREE_LOCK('bug31418')",
17098 DIE_UNLESS(!is_null && !rc);
17100 is_null= query_int_variable(&con,
17101 "IS_USED_LOCK('bug31418')",
17103 DIE_UNLESS(!is_null && rc);
17112 bug20023_change_user(&con);
17114 is_null= query_int_variable(&con,
17115 "IS_FREE_LOCK('bug31418')",
17117 DIE_UNLESS(!is_null && rc);
17119 is_null= query_int_variable(&con,
17120 "IS_USED_LOCK('bug31418')",
17122 DIE_UNLESS(is_null);
17131 static void test_bug31418()
17148 #define LARGE_BUFFER_SIZE 2048
17150 static void test_bug31669()
17153 static char buff[LARGE_BUFFER_SIZE+1];
17154 #ifndef EMBEDDED_LIBRARY
17155 static char user[USERNAME_CHAR_LENGTH+1];
17156 static char db[NAME_CHAR_LEN+1];
17157 static char query[LARGE_BUFFER_SIZE*2];
17162 DBUG_ENTER(
"test_bug31669");
17163 myheader(
"test_bug31669");
17165 l_mysql= mysql_client_init(NULL);
17166 DIE_UNLESS(l_mysql != NULL);
17168 l_mysql= mysql_real_connect(l_mysql, opt_host, opt_user,
17169 opt_password, current_db, opt_port,
17170 opt_unix_socket, 0);
17171 DIE_UNLESS(l_mysql != 0);
17174 rc= mysql_change_user(l_mysql, NULL, NULL, NULL);
17177 reconnect(&l_mysql);
17179 rc= mysql_change_user(l_mysql,
"",
"",
"");
17181 reconnect(&l_mysql);
17183 memset(buff,
'a',
sizeof(buff));
17184 buff[
sizeof(buff) - 1] =
'\0';
17186 rc= mysql_change_user(l_mysql, buff, buff, buff);
17188 reconnect(&l_mysql);
17190 rc = mysql_change_user(mysql, opt_user, opt_password, current_db);
17193 #ifndef EMBEDDED_LIBRARY
17194 memset(db,
'a',
sizeof(db));
17195 db[NAME_CHAR_LEN]= 0;
17196 strxmov(query,
"CREATE DATABASE IF NOT EXISTS ", db, NullS);
17197 rc= mysql_query(mysql, query);
17200 memset(user,
'b',
sizeof(user));
17201 user[USERNAME_CHAR_LENGTH]= 0;
17202 memset(buff,
'c',
sizeof(buff));
17203 buff[LARGE_BUFFER_SIZE]= 0;
17204 strxmov(query,
"GRANT ALL PRIVILEGES ON *.* TO '", user,
"'@'%' IDENTIFIED BY "
17205 "'", buff,
"' WITH GRANT OPTION", NullS);
17206 rc= mysql_query(mysql, query);
17209 strxmov(query,
"GRANT ALL PRIVILEGES ON *.* TO '", user,
"'@'localhost' IDENTIFIED BY "
17210 "'", buff,
"' WITH GRANT OPTION", NullS);
17211 rc= mysql_query(mysql, query);
17214 rc= mysql_query(mysql,
"FLUSH PRIVILEGES");
17217 rc= mysql_change_user(l_mysql, user, buff, db);
17220 user[USERNAME_CHAR_LENGTH-1]=
'a';
17221 rc= mysql_change_user(l_mysql, user, buff, db);
17223 reconnect(&l_mysql);
17225 user[USERNAME_CHAR_LENGTH-1]=
'b';
17226 buff[LARGE_BUFFER_SIZE-1]=
'd';
17227 rc= mysql_change_user(l_mysql, user, buff, db);
17229 reconnect(&l_mysql);
17231 buff[LARGE_BUFFER_SIZE-1]=
'c';
17232 db[NAME_CHAR_LEN-1]=
'e';
17233 rc= mysql_change_user(l_mysql, user, buff, db);
17235 reconnect(&l_mysql);
17237 db[NAME_CHAR_LEN-1]=
'a';
17238 rc= mysql_change_user(l_mysql, user, buff, db);
17241 rc= mysql_change_user(l_mysql, user + 1, buff + 1, db + 1);
17243 reconnect(&l_mysql);
17245 rc = mysql_change_user(mysql, opt_user, opt_password, current_db);
17248 strxmov(query,
"DROP DATABASE ", db, NullS);
17249 rc= mysql_query(mysql, query);
17252 strxmov(query,
"DELETE FROM mysql.user WHERE User='", user,
"'", NullS);
17253 rc= mysql_query(mysql, query);
17255 DIE_UNLESS(mysql_affected_rows(mysql) == 2);
17257 mysql_close(l_mysql);
17268 static void test_bug28386()
17275 const char hello[]=
"hello world!";
17277 DBUG_ENTER(
"test_bug28386");
17278 myheader(
"test_bug28386");
17280 rc= mysql_query(mysql,
"select @@global.log_output");
17283 result= mysql_store_result(mysql);
17284 DIE_UNLESS(result);
17286 row= mysql_fetch_row(result);
17287 if (! strstr(row[0],
"TABLE"))
17289 mysql_free_result(result);
17291 printf(
"Skipping the test since logging to tables is not enabled\n");
17295 mysql_free_result(result);
17297 enable_query_logs(1);
17299 stmt= mysql_simple_prepare(mysql,
"SELECT ?");
17302 memset(&bind, 0,
sizeof(bind));
17304 bind.buffer_type= MYSQL_TYPE_STRING;
17305 bind.buffer= (
void *) hello;
17306 bind.buffer_length=
sizeof(hello);
17308 mysql_stmt_bind_param(stmt, &bind);
17309 mysql_stmt_send_long_data(stmt, 0, hello,
sizeof(hello));
17311 rc= mysql_stmt_execute(stmt);
17312 check_execute(stmt, rc);
17314 rc= my_process_stmt_result(stmt);
17315 DIE_UNLESS(rc == 1);
17317 rc= mysql_stmt_reset(stmt);
17318 check_execute(stmt, rc);
17320 rc= mysql_stmt_close(stmt);
17323 rc= mysql_query(mysql,
"select * from mysql.general_log where "
17324 "command_type='Close stmt' or "
17325 "command_type='Reset stmt' or "
17326 "command_type='Long Data'");
17329 result= mysql_store_result(mysql);
17332 DIE_UNLESS(mysql_num_rows(result) == 3);
17334 mysql_free_result(result);
17336 restore_query_logs();
17342 static void test_wl4166_1()
17351 double double_data;
17353 my_bool is_null[7];
17358 myheader(
"test_wl4166_1");
17360 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS table_4166");
17363 rc= mysql_query(mysql,
"CREATE TABLE table_4166(col1 tinyint NOT NULL, "
17364 "col2 varchar(15), col3 int, "
17365 "col4 smallint, col5 bigint, "
17366 "col6 float, col7 double, "
17367 "colX varchar(10) default NULL)");
17370 stmt= mysql_simple_prepare(mysql,
17371 "INSERT INTO table_4166(col1, col2, col3, col4, col5, col6, col7) "
17372 "VALUES(?, ?, ?, ?, ?, ?, ?)");
17375 verify_param_count(stmt, 7);
17377 memset(my_bind, 0,
sizeof(my_bind));
17379 my_bind[0].buffer_type= MYSQL_TYPE_TINY;
17380 my_bind[0].buffer= (
void *)&tiny_data;
17382 my_bind[1].buffer_type= MYSQL_TYPE_STRING;
17383 my_bind[1].buffer= (
void *)str_data;
17384 my_bind[1].buffer_length= 1000;
17386 my_bind[2].buffer_type= MYSQL_TYPE_LONG;
17387 my_bind[2].buffer= (
void *)&int_data;
17389 my_bind[3].buffer_type= MYSQL_TYPE_SHORT;
17390 my_bind[3].buffer= (
void *)&small_data;
17392 my_bind[4].buffer_type= MYSQL_TYPE_LONGLONG;
17393 my_bind[4].buffer= (
void *)&big_data;
17395 my_bind[5].buffer_type= MYSQL_TYPE_FLOAT;
17396 my_bind[5].buffer= (
void *)&real_data;
17398 my_bind[6].buffer_type= MYSQL_TYPE_DOUBLE;
17399 my_bind[6].buffer= (
void *)&double_data;
17401 for (i= 0; i < (int) array_elements(my_bind); i++)
17403 my_bind[
i].length= &length[
i];
17404 my_bind[
i].is_null= &is_null[
i];
17408 rc= mysql_stmt_bind_param(stmt, my_bind);
17409 check_execute(stmt, rc);
17415 double_data= 6578.001;
17418 for (tiny_data= 0; tiny_data < 10; tiny_data++)
17420 length[1]= sprintf(str_data,
"MySQL%d", int_data);
17421 rc= mysql_stmt_execute(stmt);
17422 check_execute(stmt, rc);
17427 double_data += 10.09;
17432 rc= mysql_query(mysql,
17433 "ALTER TABLE table_4166 change colX colX varchar(20) default NULL");
17441 for (tiny_data= 50; tiny_data < 60; tiny_data++)
17443 length[1]= sprintf(str_data,
"MySQL%d", int_data);
17444 rc= mysql_stmt_execute(stmt);
17445 check_execute(stmt, rc);
17450 double_data += 10.09;
17453 mysql_stmt_close(stmt);
17455 rc= mysql_query(mysql,
"DROP TABLE table_4166");
17460 static void test_wl4166_2()
17468 myheader(
"test_wl4166_2");
17470 rc= mysql_query(mysql,
"SET SQL_MODE=''");
17473 rc= mysql_query(mysql,
"drop table if exists t1");
17475 rc= mysql_query(mysql,
"create table t1 (c_int int, d_date date)");
17477 rc= mysql_query(mysql,
17478 "insert into t1 (c_int, d_date) values (42, '1948-05-15')");
17481 stmt= mysql_simple_prepare(mysql,
"select * from t1");
17484 memset(bind_out, 0,
sizeof(bind_out));
17485 bind_out[0].buffer_type= MYSQL_TYPE_LONG;
17486 bind_out[0].buffer= (
void*) &c_int;
17488 bind_out[1].buffer_type= MYSQL_TYPE_DATE;
17489 bind_out[1].buffer= (
void*) &d_date;
17491 rc= mysql_stmt_bind_result(stmt, bind_out);
17492 check_execute(stmt, rc);
17496 rc= mysql_query(mysql,
17497 "alter table t1 change column c_int c_int varchar(11)");
17500 rc= mysql_stmt_execute(stmt);
17501 check_execute(stmt, rc);
17503 rc= mysql_stmt_fetch(stmt);
17504 check_execute(stmt, rc);
17506 DIE_UNLESS(c_int == 42);
17507 DIE_UNLESS(d_date.year == 1948);
17508 DIE_UNLESS(d_date.month == 5);
17509 DIE_UNLESS(d_date.day == 15);
17511 rc= mysql_stmt_fetch(stmt);
17512 DIE_UNLESS(rc == MYSQL_NO_DATA);
17516 rc= mysql_query(mysql,
"update t1 set c_int='abcde'");
17519 rc= mysql_stmt_execute(stmt);
17520 check_execute(stmt, rc);
17522 rc= mysql_stmt_fetch(stmt);
17523 check_execute_r(stmt, rc);
17525 DIE_UNLESS(c_int == 0);
17527 rc= mysql_stmt_fetch(stmt);
17528 DIE_UNLESS(rc == MYSQL_NO_DATA);
17531 rc= mysql_query(mysql,
"alter table t1 add column d_int int");
17534 rc= mysql_stmt_execute(stmt);
17535 check_execute_r(stmt, rc);
17537 rc= mysql_stmt_reset(stmt);
17538 check_execute(stmt, rc);
17541 rc= mysql_query(mysql,
"alter table t1 drop d_date, drop d_int");
17544 rc= mysql_stmt_execute(stmt);
17545 check_execute_r(stmt, rc);
17547 mysql_stmt_close(stmt);
17548 rc= mysql_query(mysql,
"drop table t1");
17559 static void test_wl4166_3()
17566 myheader(
"test_wl4166_3");
17568 rc= mysql_query(mysql,
"drop table if exists t1");
17571 rc= mysql_query(mysql,
"create table t1 (year datetime)");
17574 stmt= mysql_simple_prepare(mysql,
"insert into t1 (year) values (?)");
17576 verify_param_count(stmt, 1);
17578 memset(my_bind, 0,
sizeof(my_bind));
17579 my_bind[0].buffer_type= MYSQL_TYPE_DATETIME;
17580 my_bind[0].buffer= &tm[0];
17582 rc= mysql_stmt_bind_param(stmt, my_bind);
17583 check_execute(stmt, rc);
17586 tm[0].month= 1; tm[0].day= 1;
17587 tm[0].hour= 1; tm[0].minute= 1; tm[0].second= 1;
17591 rc= mysql_query(mysql,
"alter table t1 add column c int");
17594 rc= mysql_stmt_execute(stmt);
17595 check_execute(stmt, rc);
17601 my_process_warnings(mysql, 1);
17603 verify_col_data(
"t1",
"year",
"0000-00-00 00:00:00");
17605 mysql_stmt_close(stmt);
17607 rc= mysql_query(mysql,
"drop table t1");
17618 static void test_wl4166_4()
17622 const char *stmt_text;
17626 const char *koi8=
"\xee\xd5\x2c\x20\xda\xc1\x20\xd2\xd9\xc2\xc1\xcc\xcb\xd5";
17627 const char *cp1251=
"\xcd\xf3\x2c\x20\xe7\xe0\x20\xf0\xfb\xe1\xe0\xeb\xea\xf3";
17628 char buf1[16], buf2[16];
17629 ulong buf1_len, buf2_len;
17631 myheader(
"test_wl4166_4");
17633 rc= mysql_query(mysql,
"drop table if exists t1");
17641 rc= mysql_query(mysql,
17642 "create table t1 (c1 varbinary(255), c2 varbinary(255))");
17644 rc= mysql_query(mysql,
"set character_set_client=koi8r, "
17645 "character_set_connection=cp1251, "
17646 "character_set_results=koi8r");
17649 memset(bind_array, 0,
sizeof(bind_array));
17651 bind_array[0].buffer_type= MYSQL_TYPE_STRING;
17653 bind_array[1].buffer_type= MYSQL_TYPE_STRING;
17654 bind_array[1].buffer= (
void *) koi8;
17655 bind_array[1].buffer_length= strlen(koi8);
17657 stmt= mysql_stmt_init(mysql);
17660 stmt_text=
"insert into t1 (c1, c2) values (?, ?)";
17662 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
17663 check_execute(stmt, rc);
17665 mysql_stmt_bind_param(stmt, bind_array);
17667 mysql_stmt_send_long_data(stmt, 0, koi8, strlen(koi8));
17670 rc= mysql_query(mysql,
"alter table t1 add column d int");
17673 rc= mysql_stmt_execute(stmt);
17674 check_execute(stmt, rc);
17676 stmt_text=
"select c1, c2 from t1";
17679 rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
17680 check_execute(stmt, rc);
17682 rc= mysql_stmt_execute(stmt);
17683 check_execute(stmt, rc);
17685 bind_array[0].buffer= buf1;
17686 bind_array[0].buffer_length=
sizeof(buf1);
17687 bind_array[0].length= &buf1_len;
17689 bind_array[1].buffer= buf2;
17690 bind_array[1].buffer_length=
sizeof(buf2);
17691 bind_array[1].length= &buf2_len;
17693 mysql_stmt_bind_result(stmt, bind_array);
17695 rc= mysql_stmt_fetch(stmt);
17696 check_execute(stmt, rc);
17698 DIE_UNLESS(buf1_len == strlen(cp1251));
17699 DIE_UNLESS(buf2_len == strlen(cp1251));
17700 DIE_UNLESS(!memcmp(buf1, cp1251, buf1_len));
17701 DIE_UNLESS(!memcmp(buf2, cp1251, buf1_len));
17703 rc= mysql_stmt_fetch(stmt);
17704 DIE_UNLESS(rc == MYSQL_NO_DATA);
17706 mysql_stmt_close(stmt);
17708 rc= mysql_query(mysql,
"drop table t1");
17710 rc= mysql_query(mysql,
"set names default");
17718 static void test_bug36004()
17720 int rc, warning_count= 0;
17723 DBUG_ENTER(
"test_bug36004");
17724 myheader(
"test_bug36004");
17726 rc= mysql_query(mysql,
"drop table if exists inexistant");
17729 DIE_UNLESS(mysql_warning_count(mysql) == 1);
17730 query_int_variable(mysql,
"@@warning_count", &warning_count);
17731 DIE_UNLESS(warning_count);
17733 stmt= mysql_simple_prepare(mysql,
"select 1");
17736 DIE_UNLESS(mysql_warning_count(mysql) == 0);
17737 query_int_variable(mysql,
"@@warning_count", &warning_count);
17738 DIE_UNLESS(warning_count);
17740 rc= mysql_stmt_execute(stmt);
17741 check_execute(stmt, rc);
17743 DIE_UNLESS(mysql_warning_count(mysql) == 0);
17744 mysql_stmt_close(stmt);
17746 query_int_variable(mysql,
"@@warning_count", &warning_count);
17747 DIE_UNLESS(warning_count);
17749 stmt= mysql_simple_prepare(mysql,
"drop table if exists inexistant");
17752 query_int_variable(mysql,
"@@warning_count", &warning_count);
17753 DIE_UNLESS(warning_count == 0);
17754 mysql_stmt_close(stmt);
17763 static void test_wl4284_1()
17769 DBUG_ENTER(
"test_wl4284_1");
17770 myheader(
"test_wl4284_1");
17773 rc= mysql_autocommit(mysql, FALSE);
17776 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS trans");
17779 rc= mysql_query(mysql,
"CREATE TABLE trans (a INT) ENGINE= InnoDB");
17782 rc= mysql_query(mysql,
"INSERT INTO trans VALUES(1)");
17785 rc= mysql_refresh(mysql, REFRESH_GRANT | REFRESH_TABLES);
17788 rc= mysql_rollback(mysql);
17791 rc= mysql_query(mysql,
"SELECT * FROM trans");
17794 result= mysql_use_result(mysql);
17797 row= mysql_fetch_row(result);
17800 mysql_free_result(result);
17803 rc= mysql_autocommit(mysql, TRUE);
17806 rc= mysql_query(mysql,
"DROP TABLE trans");
17813 static void test_bug38486(
void)
17816 const char *stmt_text;
17817 unsigned long type= CURSOR_TYPE_READ_ONLY;
17819 DBUG_ENTER(
"test_bug38486");
17820 myheader(
"test_bug38486");
17822 stmt= mysql_stmt_init(mysql);
17823 mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
void*)&type);
17824 stmt_text=
"CREATE TABLE t1 (a INT)";
17825 mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
17826 mysql_stmt_execute(stmt);
17827 mysql_stmt_close(stmt);
17829 stmt= mysql_stmt_init(mysql);
17830 mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (
void*)&type);
17831 stmt_text=
"INSERT INTO t1 VALUES (1)";
17832 mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
17833 mysql_stmt_execute(stmt);
17834 mysql_stmt_close(stmt);
17845 static void test_bug33831(
void)
17849 DBUG_ENTER(
"test_bug33831");
17851 if (!(l_mysql= mysql_client_init(NULL)))
17853 myerror(
"mysql_client_init() failed");
17856 if (!(mysql_real_connect(l_mysql, opt_host, opt_user,
17857 opt_password, current_db, opt_port,
17858 opt_unix_socket, 0)))
17860 myerror(
"connection failed");
17864 if (mysql_real_connect(l_mysql, opt_host, opt_user,
17865 opt_password, current_db, opt_port,
17866 opt_unix_socket, 0))
17868 myerror(
"connection should have failed");
17872 mysql_close(l_mysql);
17878 static void test_bug40365(
void)
17883 my_bool is_null[2]= {0};
17886 DBUG_ENTER(
"test_bug40365");
17888 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
17890 rc= mysql_query(mysql,
"CREATE TABLE t1(c1 DATETIME, \
17894 stmt= mysql_simple_prepare(mysql,
"INSERT INTO t1 VALUES(?, ?)");
17896 verify_param_count(stmt, 2);
17898 memset(my_bind, 0,
sizeof(my_bind));
17899 my_bind[0].buffer_type= MYSQL_TYPE_DATETIME;
17900 my_bind[1].buffer_type= MYSQL_TYPE_DATE;
17901 for (i= 0; i < (int) array_elements(my_bind); i++)
17903 my_bind[
i].buffer= (
void *) &tm[i];
17904 my_bind[
i].is_null= &is_null[
i];
17907 rc= mysql_stmt_bind_param(stmt, my_bind);
17908 check_execute(stmt, rc);
17910 for (i= 0; i < (int) array_elements(my_bind); i++)
17921 rc= mysql_stmt_execute(stmt);
17922 check_execute(stmt, rc);
17924 rc= mysql_commit(mysql);
17926 mysql_stmt_close(stmt);
17928 stmt= mysql_simple_prepare(mysql,
"SELECT * FROM t1");
17931 rc= mysql_stmt_bind_result(stmt, my_bind);
17932 check_execute(stmt, rc);
17934 rc= mysql_stmt_execute(stmt);
17935 check_execute(stmt, rc);
17937 rc= mysql_stmt_store_result(stmt);
17938 check_execute(stmt, rc);
17940 rc= mysql_stmt_fetch(stmt);
17941 check_execute(stmt, rc);
17944 fprintf(stdout,
"\n");
17946 for (i= 0; i < array_elements(my_bind); i++)
17949 fprintf(stdout,
"\ntime[%d]: %02d-%02d-%02d ",
17950 i, tm[i].year, tm[i].month, tm[i].day);
17951 DIE_UNLESS(tm[i].year == 0);
17952 DIE_UNLESS(tm[i].month == 0);
17953 DIE_UNLESS(tm[i].day == 0);
17955 mysql_stmt_close(stmt);
17956 rc= mysql_commit(mysql);
17972 static void test_bug43560(
void)
17978 my_bool is_null= 0;
17980 const uint BUFSIZE=
sizeof(buffer);
17981 const char* values[] = {
"eins",
"zwei",
"drei",
"viele", NULL};
17982 const char insert_str[] =
"INSERT INTO t1 (c2) VALUES (?)";
17983 unsigned long length;
17984 const unsigned int drop_db= opt_drop_db;
17986 DBUG_ENTER(
"test_bug43560");
17987 myheader(
"test_bug43560");
17990 if (!strstr(mysql->server_version,
"debug"))
17992 fprintf(stdout,
"Skipping test_bug43560: server not DEBUG version\n");
18001 conn= client_connect(0, MYSQL_PROTOCOL_TCP, 0);
18003 rc= mysql_query(conn,
"DROP TABLE IF EXISTS t1");
18005 rc= mysql_query(conn,
18006 "CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 CHAR(10))");
18009 stmt= mysql_stmt_init(conn);
18011 rc= mysql_stmt_prepare(stmt, insert_str, strlen(insert_str));
18012 check_execute(stmt, rc);
18014 memset(&bind, 0,
sizeof(bind));
18015 bind.buffer_type= MYSQL_TYPE_STRING;
18016 bind.buffer_length= BUFSIZE;
18017 bind.buffer= buffer;
18018 bind.is_null= &is_null;
18019 bind.length= &length;
18020 rc= mysql_stmt_bind_param(stmt, &bind);
18021 check_execute(stmt, rc);
18024 strncpy(buffer, values[0], BUFSIZE);
18025 length= strlen(buffer);
18026 rc= mysql_stmt_execute(stmt);
18027 check_execute(stmt, rc);
18033 rc= mysql_query(conn,
"SET SESSION debug='+d,close_conn_after_stmt_execute'");
18037 strncpy(buffer, values[1], BUFSIZE);
18038 length= strlen(buffer);
18039 rc= mysql_stmt_execute(stmt);
18040 DIE_UNLESS(rc && mysql_stmt_errno(stmt) == CR_SERVER_LOST);
18046 strncpy(buffer, values[2], BUFSIZE);
18047 length= strlen(buffer);
18048 rc= mysql_stmt_execute(stmt);
18049 DIE_UNLESS(rc && mysql_stmt_errno(stmt) == CR_SERVER_LOST);
18051 mysql_stmt_close(stmt);
18054 client_disconnect(conn);
18055 rc= mysql_query(mysql,
"DROP TABLE t1");
18057 opt_drop_db= drop_db;
18067 #ifdef HAVE_QUERY_CACHE
18069 static void test_bug36326()
18073 DBUG_ENTER(
"test_bug36326");
18074 myheader(
"test_bug36326");
18076 rc= mysql_autocommit(mysql, TRUE);
18078 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
18080 rc= mysql_query(mysql,
"CREATE TABLE t1 (a INTEGER)");
18082 rc= mysql_query(mysql,
"INSERT INTO t1 VALUES (1)");
18084 rc= mysql_query(mysql,
"SET GLOBAL query_cache_type = 1");
18086 rc= mysql_query(mysql,
"SET GLOBAL query_cache_size = 1048576");
18088 DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS));
18089 DIE_UNLESS(mysql->server_status & SERVER_STATUS_AUTOCOMMIT);
18090 rc= mysql_query(mysql,
"BEGIN");
18092 DIE_UNLESS(mysql->server_status & SERVER_STATUS_IN_TRANS);
18093 rc= mysql_query(mysql,
"SELECT * FROM t1");
18095 rc= my_process_result(mysql);
18096 DIE_UNLESS(rc == 1);
18097 rc= mysql_rollback(mysql);
18099 rc= mysql_query(mysql,
"ROLLBACK");
18101 DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS));
18102 rc= mysql_query(mysql,
"SELECT * FROM t1");
18104 DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS));
18105 rc= my_process_result(mysql);
18106 DIE_UNLESS(rc == 1);
18107 rc= mysql_query(mysql,
"DROP TABLE t1");
18109 rc= mysql_query(mysql,
"SET GLOBAL query_cache_size = DEFAULT");
18122 static void test_bug41078(
void)
18127 ulong cursor_type= CURSOR_TYPE_READ_ONLY;
18130 const char param_str[]=
"abcdefghijklmn";
18131 my_bool is_null, error;
18133 DBUG_ENTER(
"test_bug41078");
18135 rc= mysql_query(mysql,
"SET NAMES UTF8");
18138 stmt= mysql_simple_prepare(mysql,
"SELECT ?");
18140 verify_param_count(stmt, 1);
18142 rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &cursor_type);
18143 check_execute(stmt, rc);
18145 memset(¶m, 0,
sizeof(param));
18146 param.buffer_type= MYSQL_TYPE_STRING;
18147 param.buffer= (
void *) param_str;
18148 len=
sizeof(param_str) - 1;
18149 param.length= &len;
18151 rc= mysql_stmt_bind_param(stmt, ¶m);
18152 check_execute(stmt, rc);
18154 rc= mysql_stmt_execute(stmt);
18155 check_execute(stmt, rc);
18157 memset(&result, 0,
sizeof(result));
18158 result.buffer_type= MYSQL_TYPE_STRING;
18159 result.buffer= str;
18160 result.buffer_length=
sizeof(str);
18161 result.is_null= &is_null;
18162 result.length= &len;
18163 result.error= &error;
18165 rc= mysql_stmt_bind_result(stmt, &result);
18166 check_execute(stmt, rc);
18168 rc= mysql_stmt_store_result(stmt);
18169 check_execute(stmt, rc);
18171 rc= mysql_stmt_fetch(stmt);
18172 check_execute(stmt, rc);
18174 DIE_UNLESS(len ==
sizeof(param_str) - 1 && !strcmp(str, param_str));
18176 mysql_stmt_close(stmt);
18184 static void test_bug45010()
18187 const char query1[]=
"select a.\x80",
18188 query2[]=
"describe `table\xef";
18190 DBUG_ENTER(
"test_bug45010");
18191 myheader(
"test_bug45010");
18193 rc= mysql_query(mysql,
"set names utf8");
18197 rc= mysql_real_query(mysql, query1,
sizeof(query1) - 1);
18201 rc= mysql_real_query(mysql, query2,
sizeof(query2) - 1);
18204 rc= mysql_query(mysql,
"set names default");
18215 static void test_bug44495()
18221 DBUG_ENTER(
"test_bug44495");
18222 myheader(
"test_44495");
18224 rc= mysql_query(mysql,
"DROP PROCEDURE IF EXISTS p1");
18227 rc= mysql_query(mysql,
"CREATE PROCEDURE p1(IN arg VARCHAR(25))"
18228 " BEGIN SET @stmt = CONCAT('SELECT \"', arg, '\"');"
18229 " PREPARE ps1 FROM @stmt;"
18231 " DROP PREPARE ps1;"
18235 DIE_UNLESS(mysql_client_init(&con));
18237 DIE_UNLESS(mysql_real_connect(&con, opt_host, opt_user, opt_password,
18238 current_db, opt_port, opt_unix_socket,
18239 CLIENT_MULTI_RESULTS));
18241 stmt= mysql_simple_prepare(&con,
"CALL p1('abc')");
18244 rc= mysql_stmt_execute(stmt);
18245 check_execute(stmt, rc);
18247 rc= my_process_stmt_result(stmt);
18248 DIE_UNLESS(rc == 1);
18250 mysql_stmt_close(stmt);
18254 rc= mysql_query(mysql,
"DROP PROCEDURE p1");
18260 static void test_bug53371()
18265 myheader(
"test_bug53371");
18267 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
18269 rc= mysql_query(mysql,
"DROP DATABASE IF EXISTS bug53371");
18271 rc= mysql_query(mysql,
"DROP USER 'testbug'@localhost");
18273 rc= mysql_query(mysql,
"CREATE TABLE t1 (a INT)");
18275 rc= mysql_query(mysql,
"CREATE DATABASE bug53371");
18277 rc= mysql_query(mysql,
"GRANT SELECT ON bug53371.* to 'testbug'@localhost");
18280 rc= mysql_change_user(mysql,
"testbug", NULL,
"bug53371");
18283 rc= mysql_query(mysql,
"SHOW COLUMNS FROM client_test_db.t1");
18285 DIE_UNLESS(mysql_errno(mysql) == 1142);
18287 result= mysql_list_fields(mysql,
"../client_test_db/t1", NULL);
18290 result= mysql_list_fields(mysql,
"#mysql50#/../client_test_db/t1", NULL);
18293 rc= mysql_change_user(mysql, opt_user, opt_password, current_db);
18295 rc= mysql_query(mysql,
"DROP TABLE t1");
18297 rc= mysql_query(mysql,
"DROP DATABASE bug53371");
18299 rc= mysql_query(mysql,
"DROP USER 'testbug'@localhost");
18308 static void test_bug42373()
18314 DBUG_ENTER(
"test_bug42373");
18315 myheader(
"test_42373");
18317 rc= mysql_query(mysql,
"DROP PROCEDURE IF EXISTS p1");
18320 rc= mysql_query(mysql,
"CREATE PROCEDURE p1()"
18323 " INSERT INTO t1 VALUES (2);"
18327 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
18330 rc= mysql_query(mysql,
"CREATE TABLE t1 (a INT)");
18334 DIE_UNLESS(mysql_client_init(&con));
18336 mysql_options(&con, MYSQL_INIT_COMMAND,
"CALL p1()");
18338 DIE_UNLESS(mysql_real_connect(&con, opt_host, opt_user, opt_password,
18339 current_db, opt_port, opt_unix_socket,
18340 CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS));
18342 stmt= mysql_simple_prepare(&con,
"SELECT a FROM t1");
18345 rc= mysql_stmt_execute(stmt);
18346 check_execute(stmt, rc);
18348 rc= my_process_stmt_result(stmt);
18349 DIE_UNLESS(rc == 1);
18351 mysql_stmt_close(stmt);
18355 DIE_UNLESS(mysql_client_init(&con));
18357 mysql_options(&con, MYSQL_INIT_COMMAND,
18358 "SELECT 3; INSERT INTO t1 VALUES (4)");
18360 DIE_UNLESS(mysql_real_connect(&con, opt_host, opt_user, opt_password,
18361 current_db, opt_port, opt_unix_socket,
18362 CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS));
18364 stmt= mysql_simple_prepare(&con,
"SELECT a FROM t1");
18367 rc= mysql_stmt_execute(stmt);
18368 check_execute(stmt, rc);
18370 rc= my_process_stmt_result(stmt);
18371 DIE_UNLESS(rc == 2);
18373 mysql_stmt_close(stmt);
18376 rc= mysql_query(mysql,
"DROP TABLE t1");
18379 rc= mysql_query(mysql,
"DROP PROCEDURE p1");
18390 static void test_bug54041_impl()
18396 DBUG_ENTER(
"test_bug54041");
18397 myheader(
"test_bug54041");
18399 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
18402 rc= mysql_query(mysql,
"CREATE TABLE t1 (a INT)");
18405 stmt= mysql_simple_prepare(mysql,
"SELECT a FROM t1 WHERE a > ?");
18407 verify_param_count(stmt, 1);
18409 memset(&bind, 0,
sizeof(bind));
18412 bind.buffer_type= MYSQL_TYPE_LONG;
18414 rc= mysql_stmt_bind_param(stmt, &bind);
18415 check_execute(stmt, rc);
18422 stmt->params[0].buffer_type= MYSQL_TYPE_STRING;
18424 rc= mysql_stmt_send_long_data(stmt, 0,
"data", 5);
18425 check_execute(stmt, rc);
18428 stmt->params[0].buffer_type= MYSQL_TYPE_LONG;
18430 rc= mysql_stmt_execute(stmt);
18432 check_execute_r(stmt, rc);
18434 mysql_stmt_close(stmt);
18436 rc= mysql_query(mysql,
"DROP TABLE IF EXISTS t1");
18447 static void test_bug54041()
18449 enable_query_logs(0);
18450 test_bug54041_impl();
18451 disable_query_logs();
18452 test_bug54041_impl();
18453 restore_query_logs();
18460 static void test_bug47485()
18466 const char* sql_select =
"SELECT 1, 'a'";
18469 my_bool is_null[2];
18471 unsigned long length[2];
18473 DBUG_ENTER(
"test_bug47485");
18474 myheader(
"test_bug47485");
18476 stmt= mysql_stmt_init(mysql);
18478 rc= mysql_stmt_prepare(stmt, sql_select, strlen(sql_select));
18479 check_execute(stmt, rc);
18481 rc= mysql_stmt_execute(stmt);
18482 check_execute(stmt, rc);
18484 res = mysql_store_result(mysql);
18485 DIE_UNLESS(res == NULL);
18487 mysql_stmt_reset(stmt);
18489 rc= mysql_stmt_execute(stmt);
18490 check_execute(stmt, rc);
18492 res = mysql_use_result(mysql);
18493 DIE_UNLESS(res == NULL);
18495 mysql_stmt_reset(stmt);
18497 memset(bind, 0,
sizeof(bind));
18498 bind[0].buffer_type= MYSQL_TYPE_LONG;
18499 bind[0].buffer= (
char *)&int_data;
18500 bind[0].is_null= &is_null[0];
18501 bind[0].length= &length[0];
18502 bind[0].error= &error[0];
18504 bind[1].buffer_type= MYSQL_TYPE_STRING;
18505 bind[1].buffer= (
char *)str_data;
18506 bind[1].buffer_length=
sizeof(str_data);
18507 bind[1].is_null= &is_null[1];
18508 bind[1].length= &length[1];
18509 bind[1].error= &error[1];
18511 rc= mysql_stmt_bind_result(stmt, bind);
18512 check_execute(stmt, rc);
18514 rc= mysql_stmt_execute(stmt);
18515 check_execute(stmt, rc);
18517 rc= mysql_stmt_store_result(stmt);
18518 check_execute(stmt, rc);
18520 while (!(rc= mysql_stmt_fetch(stmt)))
18523 DIE_UNLESS(rc == MYSQL_NO_DATA);
18525 mysql_stmt_reset(stmt);
18527 memset(bind, 0,
sizeof(bind));
18528 bind[0].buffer_type= MYSQL_TYPE_LONG;
18529 bind[0].buffer= (
char *)&int_data;
18530 bind[0].is_null= &is_null[0];
18531 bind[0].length= &length[0];
18532 bind[0].error= &error[0];
18534 bind[1].buffer_type= MYSQL_TYPE_STRING;
18535 bind[1].buffer= (
char *)str_data;
18536 bind[1].buffer_length=
sizeof(str_data);
18537 bind[1].is_null= &is_null[1];
18538 bind[1].length= &length[1];
18539 bind[1].error= &error[1];
18541 rc= mysql_stmt_bind_result(stmt, bind);
18542 check_execute(stmt, rc);
18544 rc= mysql_stmt_execute(stmt);
18545 check_execute(stmt, rc);
18547 while (!(rc= mysql_stmt_fetch(stmt)))
18550 DIE_UNLESS(rc == MYSQL_NO_DATA);
18552 mysql_stmt_close(stmt);
18561 static void test_bug58036()
18564 DBUG_ENTER(
"test_bug47485");
18565 myheader(
"test_bug58036");
18568 conn= mysql_client_init(NULL);
18569 mysql_options(conn, MYSQL_SET_CHARSET_NAME,
"ucs2");
18570 if (mysql_real_connect(conn, opt_host, opt_user,
18571 opt_password, opt_db ? opt_db :
"test",
18572 opt_port, opt_unix_socket, 0))
18575 printf(
"mysql_real_connect() succeeded (failure expected)\n");
18581 printf(
"Got mysql_real_connect() error (expected): %s (%d)\n",
18582 mysql_error(conn), mysql_errno(conn));
18583 DIE_UNLESS(mysql_errno(conn) == ER_WRONG_VALUE_FOR_VAR);
18593 conn= mysql_client_init(NULL);
18594 mysql_options(conn, MYSQL_SET_CHARSET_NAME,
"latin1");
18595 if (!mysql_real_connect(conn, opt_host, opt_user,
18596 opt_password, opt_db ? opt_db :
"test",
18597 opt_port, opt_unix_socket, 0))
18600 printf(
"mysql_real_connect() failed: %s (%d)\n",
18601 mysql_error(conn), mysql_errno(conn));
18606 mysql_options(conn, MYSQL_SET_CHARSET_NAME,
"ucs2");
18607 if (!mysql_change_user(conn, opt_user, opt_password, NULL))
18610 printf(
"mysql_change_user() succedded, error expected!");
18616 printf(
"Got mysql_change_user() error (expected): %s (%d)\n",
18617 mysql_error(conn), mysql_errno(conn));
18635 static void test_bug49972()
18645 DBUG_ENTER(
"test_bug49972");
18646 myheader(
"test_bug49972");
18648 rc= mysql_query(mysql,
"DROP FUNCTION IF EXISTS f1");
18651 rc= mysql_query(mysql,
"DROP PROCEDURE IF EXISTS p1");
18654 rc= mysql_query(mysql,
"CREATE FUNCTION f1() RETURNS INT RETURN 1");
18657 rc= mysql_query(mysql,
"CREATE PROCEDURE p1(IN a INT, OUT b INT) SET b = a");
18660 stmt= mysql_simple_prepare(mysql,
"CALL p1((SELECT f1()), ?)");
18663 memset(&in_param_bind, 0,
sizeof (in_param_bind));
18665 in_param_bind.buffer_type= MYSQL_TYPE_LONG;
18666 in_param_bind.buffer= (
char *) &int_data;
18667 in_param_bind.length= 0;
18668 in_param_bind.is_null= 0;
18670 rc= mysql_stmt_bind_param(stmt, &in_param_bind);
18672 rc= mysql_stmt_execute(stmt);
18673 check_execute(stmt, rc);
18676 memset(&out_param_bind, 0,
sizeof (out_param_bind));
18678 out_param_bind.buffer_type= MYSQL_TYPE_LONG;
18679 out_param_bind.is_null= &is_null;
18680 out_param_bind.buffer= &int_data;
18681 out_param_bind.buffer_length=
sizeof (int_data);
18683 rc= mysql_stmt_bind_result(stmt, &out_param_bind);
18684 check_execute(stmt, rc);
18686 rc= mysql_stmt_fetch(stmt);
18687 rc= mysql_stmt_fetch(stmt);
18688 DBUG_ASSERT(rc == MYSQL_NO_DATA);
18690 mysql_stmt_next_result(stmt);
18691 mysql_stmt_fetch(stmt);
18694 rc= mysql_query(mysql,
"DROP FUNCTION f1");
18697 rc= mysql_query(mysql,
"CREATE FUNCTION f1() RETURNS INT RETURN 1");
18700 rc= mysql_stmt_execute(stmt);
18701 check_execute(stmt, rc);
18704 memset(&out_param_bind, 0,
sizeof (out_param_bind));
18706 out_param_bind.buffer_type= MYSQL_TYPE_LONG;
18707 out_param_bind.is_null= &is_null;
18708 out_param_bind.buffer= &int_data;
18709 out_param_bind.buffer_length=
sizeof (int_data);
18711 rc= mysql_stmt_bind_result(stmt, &out_param_bind);
18712 check_execute(stmt, rc);
18714 rc= mysql_stmt_fetch(stmt);
18715 rc= mysql_stmt_fetch(stmt);
18716 DBUG_ASSERT(rc == MYSQL_NO_DATA);
18718 mysql_stmt_next_result(stmt);
18719 mysql_stmt_fetch(stmt);
18722 mysql_stmt_close(stmt);
18724 rc= mysql_query(mysql,
"DROP PROCEDURE p1");
18727 rc= mysql_query(mysql,
"DROP FUNCTION f1");
18737 static void test_bug56976()
18742 const char* query =
"SELECT LENGTH(?)";
18744 unsigned long i, packet_len = 256 * 1024L;
18745 unsigned long dos_len = 8 * 1024 * 1024L;
18747 DBUG_ENTER(
"test_bug56976");
18748 myheader(
"test_bug56976");
18750 stmt= mysql_stmt_init(mysql);
18753 rc= mysql_stmt_prepare(stmt, query, strlen(query));
18754 check_execute(stmt, rc);
18756 memset(bind, 0,
sizeof(bind));
18757 bind[0].buffer_type = MYSQL_TYPE_TINY_BLOB;
18759 rc= mysql_stmt_bind_param(stmt, bind);
18760 check_execute(stmt, rc);
18762 long_buffer= (
char*) my_malloc(packet_len, MYF(0));
18763 DIE_UNLESS(long_buffer);
18765 memset(long_buffer,
'a', packet_len);
18767 for (i= 0; i < dos_len / packet_len; i++)
18769 rc= mysql_stmt_send_long_data(stmt, 0, long_buffer, packet_len);
18770 check_execute(stmt, rc);
18773 my_free(long_buffer);
18774 rc= mysql_stmt_execute(stmt);
18776 DIE_UNLESS(rc && mysql_stmt_errno(stmt) == ER_UNKNOWN_ERROR);
18778 mysql_stmt_close(stmt);
18788 static void test_bug57058()
18793 DBUG_ENTER(
"test_bug57058");
18794 myheader(
"test_bug57058");
18796 rc= mysql_query(mysql,
"set @@session.long_query_time=0.1");
18799 DIE_UNLESS(!(mysql->server_status & SERVER_QUERY_WAS_SLOW));
18801 rc= mysql_query(mysql,
"select sleep(1)");
18809 res= mysql_store_result(mysql);
18811 DIE_UNLESS(mysql->server_status & SERVER_QUERY_WAS_SLOW);
18813 mysql_free_result(res);
18815 rc= mysql_query(mysql,
"set @@session.long_query_time=default");
18826 static void test_bug11766854()
18830 DBUG_ENTER(
"test_bug11766854");
18831 myheader(
"test_bug11766854");
18834 DIE_UNLESS(plugin == 0);
18837 DIE_UNLESS(plugin != 0);
18838 DIE_IF(mysql_errno(mysql));
18847 static void test_bug12337762()
18852 unsigned int tab_charsetnr[3]= {0};
18854 DBUG_ENTER(
"test_bug12337762");
18855 myheader(
"test_bug12337762");
18860 rc= mysql_query(mysql,
"drop table if exists charset_tab");
18861 rc= mysql_query(mysql,
"create table charset_tab("\
18862 "txt1 varchar(32) character set Latin1,"\
18863 "txt2 varchar(32) character set Latin1 collate latin1_bin,"\
18864 "txt3 varchar(32) character set utf8 collate utf8_bin"\
18867 DIE_UNLESS(rc == 0);
18868 DIE_IF(mysql_errno(mysql));
18873 rc= mysql_query(mysql,
"drop view if exists charset_view");
18874 rc= mysql_query(mysql,
"create view charset_view as "\
18875 "select * from charset_tab;");
18876 DIE_UNLESS(rc == 0);
18877 DIE_IF(mysql_errno(mysql));
18882 result= mysql_list_fields(mysql,
"charset_tab", NULL);
18883 DIE_IF(mysql_errno(mysql));
18885 while((field= mysql_fetch_field(result)))
18887 printf(
"field name %s\n", field->name);
18888 printf(
"field table %s\n", field->table);
18889 printf(
"field type %d\n", field->type);
18890 printf(
"field charset %d\n", field->charsetnr);
18891 tab_charsetnr[i++]= field->charsetnr;
18894 mysql_free_result(result);
18899 result= mysql_list_fields(mysql,
"charset_view", NULL);
18900 DIE_IF(mysql_errno(mysql));
18902 while((field= mysql_fetch_field(result)))
18904 printf(
"field name %s\n", field->name);
18905 printf(
"field table %s\n", field->table);
18906 printf(
"field type %d\n", field->type);
18907 printf(
"field charset %d\n", field->charsetnr);
18912 DIE_UNLESS(field->charsetnr == tab_charsetnr[i++]);
18914 mysql_free_result(result);
18923 static void test_bug54790()
18929 DBUG_ENTER(
"test_bug54790");
18930 myheader(
"test_bug54790");
18932 lmysql= mysql_client_init(NULL);
18933 DIE_UNLESS(lmysql);
18935 rc= mysql_options(lmysql, MYSQL_OPT_READ_TIMEOUT, &timeout);
18938 if (!mysql_real_connect(lmysql, opt_host, opt_user, opt_password,
18939 opt_db ? opt_db :
"test", opt_port,
18940 opt_unix_socket, 0))
18943 myerror(
"mysql_real_connect failed");
18944 mysql_close(lmysql);
18948 rc= mysql_query(lmysql,
"SELECT SLEEP(100);");
18952 DIE_UNLESS(mysql_errno(lmysql) == CR_SERVER_LOST);
18954 mysql_close(lmysql);
18964 static void test_bug11754979()
18967 DBUG_ENTER(
"test_bug11754979");
18969 myheader(
"test_bug11754979");
18970 DIE_UNLESS((conn= mysql_client_init(NULL)));
18971 DIE_UNLESS(mysql_real_connect(conn, opt_host, opt_user,
18972 opt_password, opt_db ? opt_db:
"test", opt_port,
18973 opt_unix_socket, CLIENT_FOUND_ROWS));
18974 myquery(mysql_query(conn,
"DROP TABLE IF EXISTS t1"));
18975 myquery(mysql_query(conn,
"CREATE TABLE t1(id INT, label CHAR(1), PRIMARY KEY(id))"));
18976 myquery(mysql_query(conn,
"INSERT INTO t1(id, label) VALUES (1, 'a')"));
18977 myquery(mysql_query(conn,
"INSERT INTO t1(id, label) VALUES (1, 'a') "
18978 "ON DUPLICATE KEY UPDATE id = 4"));
18979 DIE_UNLESS(mysql_affected_rows(conn) == 2);
18980 myquery(mysql_query(conn,
"DROP TABLE t1"));
18990 static void test_bug13001491()
18993 char query[MAX_TEST_QUERY_LENGTH];
18996 myheader(
"test_bug13001491");
18998 my_snprintf(query, MAX_TEST_QUERY_LENGTH,
18999 "GRANT ALL PRIVILEGES ON *.* TO mysqltest_u1@%s",
19000 opt_host ? opt_host :
"'localhost'");
19002 rc= mysql_query(mysql, query);
19005 my_snprintf(query, MAX_TEST_QUERY_LENGTH,
19006 "GRANT RELOAD ON *.* TO mysqltest_u1@%s",
19007 opt_host ? opt_host :
"'localhost'");
19009 rc= mysql_query(mysql, query);
19012 c= mysql_client_init(NULL);
19014 DIE_UNLESS(mysql_real_connect(c, opt_host,
"mysqltest_u1", NULL,
19015 current_db, opt_port, opt_unix_socket,
19016 CLIENT_MULTI_STATEMENTS |
19017 CLIENT_MULTI_RESULTS));
19019 rc= mysql_query(c,
"DROP PROCEDURE IF EXISTS p1");
19023 "CREATE PROCEDURE p1() "
19025 " DECLARE CONTINUE HANDLER FOR SQLEXCEPTION BEGIN END; "
19026 " SELECT COUNT(*) "
19027 " FROM INFORMATION_SCHEMA.PROCESSLIST "
19034 rc= mysql_query(c,
"CALL p1()");
19037 mysql_free_result(mysql_store_result(c));
19040 rc= mysql_refresh(c, REFRESH_GRANT |
19041 REFRESH_TABLES | REFRESH_HOSTS |
19042 REFRESH_STATUS | REFRESH_THREADS);
19050 mysql_refresh(c, REFRESH_LOG);
19052 rc= mysql_query(c,
"DROP PROCEDURE p1");
19058 my_snprintf(query, MAX_TEST_QUERY_LENGTH,
19059 "DROP USER mysqltest_u1@%s",
19060 opt_host ? opt_host :
"'localhost'");
19062 rc= mysql_query(mysql, query);
19071 static void test_wl5968()
19075 myheader(
"test_wl5968");
19077 rc= mysql_query(mysql,
"START TRANSACTION");
19079 DIE_UNLESS(mysql->server_status & SERVER_STATUS_IN_TRANS);
19080 DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS_READONLY));
19081 rc= mysql_query(mysql,
"COMMIT");
19083 rc= mysql_query(mysql,
"START TRANSACTION READ ONLY");
19085 DIE_UNLESS(mysql->server_status & SERVER_STATUS_IN_TRANS);
19086 DIE_UNLESS(mysql->server_status & SERVER_STATUS_IN_TRANS_READONLY);
19087 rc= mysql_query(mysql,
"COMMIT");
19089 DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS));
19090 DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS_READONLY));
19091 rc= mysql_query(mysql,
"START TRANSACTION");
19093 DIE_UNLESS(mysql->server_status & SERVER_STATUS_IN_TRANS);
19094 DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS_READONLY));
19095 rc= mysql_query(mysql,
"COMMIT");
19103 static void test_wl5924()
19110 myheader(
"test_wl5924");
19111 l_mysql= mysql_client_init(NULL);
19112 DIE_UNLESS(l_mysql != NULL);
19115 rc= mysql_set_character_set(l_mysql,
"cp1251");
19116 DIE_UNLESS(rc == 0);
19119 rc= mysql_options4(l_mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
19121 DIE_UNLESS(rc == 0);
19124 rc= mysql_options4(l_mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
19126 DIE_UNLESS(rc == 0);
19129 rc= mysql_options4(l_mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
19131 DIE_UNLESS(rc != 0);
19134 rc= mysql_options(l_mysql, MYSQL_OPT_CONNECT_ATTR_DELETE,
19136 DIE_UNLESS(rc == 0);
19139 rc= mysql_options4(l_mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
19141 DIE_UNLESS(rc == 0);
19144 rc= mysql_options(l_mysql, MYSQL_OPT_CONNECT_ATTR_RESET, NULL);
19145 DIE_UNLESS(rc == 0);
19148 rc= mysql_options4(l_mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
19150 DIE_UNLESS(rc == 0);
19153 rc= mysql_options(l_mysql, MYSQL_OPT_CONNECT_ATTR_RESET, NULL);
19154 DIE_UNLESS(rc == 0);
19157 rc= mysql_options4(l_mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
19159 DIE_UNLESS(rc == 0);
19162 rc= mysql_options4(l_mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
19164 DIE_UNLESS(rc == 0);
19168 rc= mysql_options4(l_mysql, MYSQL_OPT_CONNECT_ATTR_ADD,
19169 "\xc3\xe5\xee\xf0\xe3\xe8",
19170 "\xca\xee\xe4\xe8\xed\xee\xe2");
19171 DIE_UNLESS(rc == 0);
19173 l_mysql= mysql_real_connect(l_mysql, opt_host, opt_user,
19174 opt_password, current_db, opt_port,
19175 opt_unix_socket, 0);
19176 DIE_UNLESS(l_mysql != 0);
19178 rc= mysql_query(l_mysql,
19179 "SELECT ATTR_NAME, ATTR_VALUE "
19180 " FROM performance_schema.session_account_connect_attrs"
19181 " WHERE ATTR_NAME IN ('key1','key2','key3','key4',"
19182 " '\xc3\xe5\xee\xf0\xe3\xe8') AND"
19183 " PROCESSLIST_ID = CONNECTION_ID() ORDER BY ATTR_NAME");
19184 myquery2(l_mysql,rc);
19185 res= mysql_use_result(l_mysql);
19188 row= mysql_fetch_row(res);
19190 DIE_UNLESS(0 == strcmp(row[0],
"key3"));
19191 DIE_UNLESS(0 == strcmp(row[1],
"value3"));
19193 row= mysql_fetch_row(res);
19195 DIE_UNLESS(0 == strcmp(row[0],
"key4"));
19196 DIE_UNLESS(0 == strcmp(row[1],
"value4"));
19198 row= mysql_fetch_row(res);
19200 DIE_UNLESS(0 == strcmp(row[0],
"\xc3\xe5\xee\xf0\xe3\xe8"));
19201 DIE_UNLESS(0 == strcmp(row[1],
"\xca\xee\xe4\xe8\xed\xee\xe2"));
19203 mysql_free_result(res);
19205 l_mysql->reconnect= 1;
19206 rc= mysql_reconnect(l_mysql);
19207 myquery2(l_mysql,rc);
19209 mysql_close(l_mysql);
19216 static void test_wl6587()
19222 myheader(
"test_wl6587");
19225 rc= mysql_query(mysql,
19226 "CREATE USER wl6587_cli@localhost IDENTIFIED BY 'wl6587'");
19228 rc= mysql_query(mysql,
"ALTER USER wl6587_cli@localhost PASSWORD EXPIRE");
19232 l_mysql= mysql_client_init(NULL);
19233 DIE_UNLESS(l_mysql != NULL);
19236 l_mysql= mysql_real_connect(l_mysql, opt_host,
"wl6587_cli",
19237 "wl6587",
"test", opt_port,
19238 opt_unix_socket, 0);
19239 DIE_UNLESS(l_mysql == 0);
19241 l_mysql= mysql_client_init(NULL);
19242 DIE_UNLESS(l_mysql != NULL);
19245 l_mysql= mysql_real_connect(l_mysql, opt_host,
"wl6587_cli",
19246 "wl6587",
"test", opt_port,
19248 CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS);
19249 DIE_UNLESS(l_mysql != 0);
19252 rc= mysql_query(l_mysql,
"SELECT USER()");
19253 myerror2(l_mysql,NULL);
19254 DIE_UNLESS(rc != 0);
19256 mysql_close(l_mysql);
19260 l_mysql= mysql_client_init(NULL);
19261 DIE_UNLESS(l_mysql != NULL);
19264 rc= mysql_options(l_mysql, MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, &can);
19265 DIE_UNLESS(rc == 0);
19267 l_mysql= mysql_real_connect(l_mysql, opt_host,
"wl6587_cli",
19268 "wl6587",
"test", opt_port,
19269 opt_unix_socket, 0);
19270 DIE_UNLESS(l_mysql != 0);
19273 rc= mysql_query(l_mysql,
"SELECT USER()");
19274 myerror2(l_mysql,NULL);
19275 DIE_UNLESS(rc != 0);
19277 mysql_close(l_mysql);
19281 l_mysql= mysql_client_init(NULL);
19282 DIE_UNLESS(l_mysql != NULL);
19285 rc= mysql_options(l_mysql, MYSQL_OPT_CAN_HANDLE_EXPIRED_PASSWORDS, &can);
19286 DIE_UNLESS(rc == 0);
19289 l_mysql= mysql_real_connect(l_mysql, opt_host, opt_user,
19290 opt_password, current_db, opt_port,
19291 opt_unix_socket, 0);
19292 DIE_UNLESS(l_mysql != 0);
19294 rc= mysql_change_user(l_mysql,
"wl6587_cli",
"wl6587",
"test");
19295 DIE_UNLESS(rc == TRUE);
19297 mysql_close(l_mysql);
19300 rc= mysql_query(mysql,
"DROP USER wl6587_cli@localhost");
19306 {
"disable_query_logs", disable_query_logs },
19307 {
"test_view_sp_list_fields", test_view_sp_list_fields },
19308 {
"client_query", client_query },
19309 {
"test_prepare_insert_update", test_prepare_insert_update},
19310 #if NOT_YET_WORKING
19311 {
"test_drop_temp", test_drop_temp },
19313 {
"test_fetch_seek", test_fetch_seek },
19314 {
"test_fetch_nobuffs", test_fetch_nobuffs },
19315 {
"test_open_direct", test_open_direct },
19316 {
"test_fetch_null", test_fetch_null },
19317 {
"test_ps_null_param", test_ps_null_param },
19318 {
"test_fetch_date", test_fetch_date },
19319 {
"test_fetch_str", test_fetch_str },
19320 {
"test_fetch_long", test_fetch_long },
19321 {
"test_fetch_short", test_fetch_short },
19322 {
"test_fetch_tiny", test_fetch_tiny },
19323 {
"test_fetch_bigint", test_fetch_bigint },
19324 {
"test_fetch_float", test_fetch_float },
19325 {
"test_fetch_double", test_fetch_double },
19326 {
"test_bind_result_ext", test_bind_result_ext },
19327 {
"test_bind_result_ext1", test_bind_result_ext1 },
19328 {
"test_select_direct", test_select_direct },
19329 {
"test_select_prepare", test_select_prepare },
19330 {
"test_select", test_select },
19331 {
"test_select_version", test_select_version },
19332 {
"test_ps_conj_select", test_ps_conj_select },
19333 {
"test_select_show_table", test_select_show_table },
19334 {
"test_func_fields", test_func_fields },
19335 {
"test_long_data", test_long_data },
19336 {
"test_insert", test_insert },
19337 {
"test_set_variable", test_set_variable },
19338 {
"test_select_show", test_select_show },
19339 {
"test_prepare_noparam", test_prepare_noparam },
19340 {
"test_bind_result", test_bind_result },
19341 {
"test_prepare_simple", test_prepare_simple },
19342 {
"test_prepare", test_prepare },
19343 {
"test_null", test_null },
19344 {
"test_debug_example", test_debug_example },
19345 {
"test_update", test_update },
19346 {
"test_simple_update", test_simple_update },
19347 {
"test_simple_delete", test_simple_delete },
19348 {
"test_double_compare", test_double_compare },
19349 {
"client_store_result", client_store_result },
19350 {
"client_use_result", client_use_result },
19351 {
"test_tran_bdb", test_tran_bdb },
19352 {
"test_tran_innodb", test_tran_innodb },
19353 {
"test_prepare_ext", test_prepare_ext },
19354 {
"test_prepare_syntax", test_prepare_syntax },
19355 {
"test_field_names", test_field_names },
19356 {
"test_field_flags", test_field_flags },
19357 {
"test_long_data_str", test_long_data_str },
19358 {
"test_long_data_str1", test_long_data_str1 },
19359 {
"test_long_data_bin", test_long_data_bin },
19360 {
"test_warnings", test_warnings },
19361 {
"test_errors", test_errors },
19362 {
"test_prepare_resultset", test_prepare_resultset },
19363 {
"test_stmt_close", test_stmt_close },
19364 {
"test_prepare_field_result", test_prepare_field_result },
19365 {
"test_multi_stmt", test_multi_stmt },
19366 {
"test_multi_statements", test_multi_statements },
19367 {
"test_prepare_multi_statements", test_prepare_multi_statements },
19368 {
"test_store_result", test_store_result },
19369 {
"test_store_result1", test_store_result1 },
19370 {
"test_store_result2", test_store_result2 },
19371 {
"test_subselect", test_subselect },
19372 {
"test_date", test_date },
19373 {
"test_date_frac", test_date_frac },
19374 {
"test_temporal_param", test_temporal_param },
19375 {
"test_date_date", test_date_date },
19376 {
"test_date_time", test_date_time },
19377 {
"test_date_ts", test_date_ts },
19378 {
"test_date_dt", test_date_dt },
19379 {
"test_prepare_alter", test_prepare_alter },
19380 {
"test_manual_sample", test_manual_sample },
19381 {
"test_pure_coverage", test_pure_coverage },
19382 {
"test_buffers", test_buffers },
19383 {
"test_ushort_bug", test_ushort_bug },
19384 {
"test_sshort_bug", test_sshort_bug },
19385 {
"test_stiny_bug", test_stiny_bug },
19386 {
"test_field_misc", test_field_misc },
19387 {
"test_set_option", test_set_option },
19388 #ifdef EMBEDDED_LIBRARY
19389 {
"test_embedded_start_stop", test_embedded_start_stop },
19391 #ifndef EMBEDDED_LIBRARY
19392 {
"test_prepare_grant", test_prepare_grant },
19394 {
"test_frm_bug", test_frm_bug },
19395 {
"test_explain_bug", test_explain_bug },
19396 {
"test_decimal_bug", test_decimal_bug },
19397 {
"test_nstmts", test_nstmts },
19398 {
"test_logs;", test_logs },
19399 {
"test_cuted_rows", test_cuted_rows },
19400 {
"test_fetch_offset", test_fetch_offset },
19401 {
"test_fetch_column", test_fetch_column },
19402 {
"test_mem_overun", test_mem_overun },
19403 {
"test_list_fields", test_list_fields },
19404 {
"test_free_result", test_free_result },
19405 {
"test_free_store_result", test_free_store_result },
19406 {
"test_sqlmode", test_sqlmode },
19407 {
"test_ts", test_ts },
19408 {
"test_bug1115", test_bug1115 },
19409 {
"test_bug1180", test_bug1180 },
19410 {
"test_bug1500", test_bug1500 },
19411 {
"test_bug1644", test_bug1644 },
19412 {
"test_bug1946", test_bug1946 },
19413 {
"test_bug2248", test_bug2248 },
19414 {
"test_parse_error_and_bad_length", test_parse_error_and_bad_length },
19415 {
"test_bug2247", test_bug2247 },
19416 {
"test_subqueries", test_subqueries },
19417 {
"test_bad_union", test_bad_union },
19418 {
"test_distinct", test_distinct },
19419 {
"test_subqueries_ref", test_subqueries_ref },
19420 {
"test_union", test_union },
19421 {
"test_bug3117", test_bug3117 },
19422 {
"test_join", test_join },
19423 {
"test_selecttmp", test_selecttmp },
19424 {
"test_create_drop", test_create_drop },
19425 {
"test_rename", test_rename },
19426 {
"test_do_set", test_do_set },
19427 {
"test_multi", test_multi },
19428 {
"test_insert_select", test_insert_select },
19429 {
"test_bind_nagative", test_bind_nagative },
19430 {
"test_derived", test_derived },
19431 {
"test_xjoin", test_xjoin },
19432 {
"test_bug3035", test_bug3035 },
19433 {
"test_union2", test_union2 },
19434 {
"test_bug1664", test_bug1664 },
19435 {
"test_union_param", test_union_param },
19436 {
"test_order_param", test_order_param },
19437 {
"test_ps_i18n", test_ps_i18n },
19438 {
"test_bug3796", test_bug3796 },
19439 {
"test_bug4026", test_bug4026 },
19440 {
"test_bug4079", test_bug4079 },
19441 {
"test_bug4236", test_bug4236 },
19442 {
"test_bug4030", test_bug4030 },
19443 {
"test_bug5126", test_bug5126 },
19444 {
"test_bug4231", test_bug4231 },
19445 {
"test_bug5399", test_bug5399 },
19446 {
"test_bug5194", test_bug5194 },
19447 {
"test_bug5315", test_bug5315 },
19448 {
"test_bug6049", test_bug6049 },
19449 {
"test_bug6058", test_bug6058 },
19450 {
"test_bug6059", test_bug6059 },
19451 {
"test_bug6046", test_bug6046 },
19452 {
"test_bug6081", test_bug6081 },
19453 {
"test_bug6096", test_bug6096 },
19454 {
"test_datetime_ranges", test_datetime_ranges },
19455 {
"test_bug4172", test_bug4172 },
19456 {
"test_conversion", test_conversion },
19457 {
"test_rewind", test_rewind },
19458 {
"test_bug6761", test_bug6761 },
19459 {
"test_view", test_view },
19460 {
"test_view_where", test_view_where },
19461 {
"test_view_2where", test_view_2where },
19462 {
"test_view_star", test_view_star },
19463 {
"test_view_insert", test_view_insert },
19464 {
"test_left_join_view", test_left_join_view },
19465 {
"test_view_insert_fields", test_view_insert_fields },
19466 {
"test_basic_cursors", test_basic_cursors },
19467 {
"test_cursors_with_union", test_cursors_with_union },
19468 {
"test_cursors_with_procedure", test_cursors_with_procedure },
19469 {
"test_truncation", test_truncation },
19470 {
"test_truncation_option", test_truncation_option },
19471 {
"test_client_character_set", test_client_character_set },
19472 {
"test_bug8330", test_bug8330 },
19473 {
"test_bug7990", test_bug7990 },
19474 {
"test_bug8378", test_bug8378 },
19475 {
"test_bug8722", test_bug8722 },
19476 {
"test_bug8880", test_bug8880 },
19477 {
"test_bug9159", test_bug9159 },
19478 {
"test_bug9520", test_bug9520 },
19479 {
"test_bug9478", test_bug9478 },
19480 {
"test_bug9643", test_bug9643 },
19481 {
"test_bug10729", test_bug10729 },
19482 {
"test_bug11111", test_bug11111 },
19483 {
"test_bug9992", test_bug9992 },
19484 {
"test_bug10736", test_bug10736 },
19485 {
"test_bug10794", test_bug10794 },
19486 {
"test_bug11172", test_bug11172 },
19487 {
"test_bug11656", test_bug11656 },
19488 {
"test_bug10214", test_bug10214 },
19489 {
"test_bug9735", test_bug9735 },
19490 {
"test_bug11183", test_bug11183 },
19491 {
"test_bug11037", test_bug11037 },
19492 {
"test_bug10760", test_bug10760 },
19493 {
"test_bug12001", test_bug12001 },
19494 {
"test_bug11718", test_bug11718 },
19495 {
"test_bug12925", test_bug12925 },
19496 {
"test_bug11909", test_bug11909 },
19497 {
"test_bug11901", test_bug11901 },
19498 {
"test_bug11904", test_bug11904 },
19499 {
"test_bug12243", test_bug12243 },
19500 {
"test_bug14210", test_bug14210 },
19501 {
"test_bug13488", test_bug13488 },
19502 {
"test_bug13524", test_bug13524 },
19503 {
"test_bug14845", test_bug14845 },
19504 {
"test_opt_reconnect", test_opt_reconnect },
19505 {
"test_bug15510", test_bug15510},
19506 #ifndef EMBEDDED_LIBRARY
19507 {
"test_bug12744", test_bug12744 },
19509 {
"test_bug16143", test_bug16143 },
19510 {
"test_bug16144", test_bug16144 },
19511 {
"test_bug15613", test_bug15613 },
19512 {
"test_bug20152", test_bug20152 },
19513 {
"test_bug14169", test_bug14169 },
19514 {
"test_bug17667", test_bug17667 },
19515 {
"test_bug15752", test_bug15752 },
19516 {
"test_mysql_insert_id", test_mysql_insert_id },
19517 {
"test_bug19671", test_bug19671 },
19518 {
"test_bug21206", test_bug21206 },
19519 {
"test_bug21726", test_bug21726 },
19520 {
"test_bug15518", test_bug15518 },
19521 {
"test_bug23383", test_bug23383 },
19522 {
"test_bug32265", test_bug32265 },
19523 {
"test_bug21635", test_bug21635 },
19524 {
"test_status", test_status },
19525 {
"test_bug24179", test_bug24179 },
19526 {
"test_ps_query_cache", test_ps_query_cache },
19527 {
"test_bug28075", test_bug28075 },
19528 {
"test_bug27876", test_bug27876 },
19529 {
"test_bug28505", test_bug28505 },
19530 {
"test_bug28934", test_bug28934 },
19531 {
"test_bug27592", test_bug27592 },
19532 {
"test_bug29687", test_bug29687 },
19533 {
"test_bug29692", test_bug29692 },
19534 {
"test_bug29306", test_bug29306 },
19535 {
"test_change_user", test_change_user },
19536 {
"test_bug30472", test_bug30472 },
19537 {
"test_bug20023", test_bug20023 },
19538 {
"test_bug45010", test_bug45010 },
19539 {
"test_bug53371", test_bug53371 },
19540 {
"test_bug31418", test_bug31418 },
19541 {
"test_bug31669", test_bug31669 },
19542 {
"test_bug28386", test_bug28386 },
19543 {
"test_wl4166_1", test_wl4166_1 },
19544 {
"test_wl4166_2", test_wl4166_2 },
19545 {
"test_wl4166_3", test_wl4166_3 },
19546 {
"test_wl4166_4", test_wl4166_4 },
19547 {
"test_bug36004", test_bug36004 },
19548 {
"test_wl4284_1", test_wl4284_1 },
19549 {
"test_wl4435", test_wl4435 },
19550 {
"test_wl4435_2", test_wl4435_2 },
19551 {
"test_wl4435_3", test_wl4435_3 },
19552 {
"test_bug38486", test_bug38486 },
19553 {
"test_bug33831", test_bug33831 },
19554 {
"test_bug40365", test_bug40365 },
19555 {
"test_bug43560", test_bug43560 },
19556 #ifdef HAVE_QUERY_CACHE
19557 {
"test_bug36326", test_bug36326 },
19559 {
"test_bug41078", test_bug41078 },
19560 {
"test_bug44495", test_bug44495 },
19561 {
"test_bug49972", test_bug49972 },
19562 {
"test_bug42373", test_bug42373 },
19563 {
"test_bug54041", test_bug54041 },
19564 {
"test_bug47485", test_bug47485 },
19565 {
"test_bug58036", test_bug58036 },
19566 {
"test_bug57058", test_bug57058 },
19567 {
"test_bug56976", test_bug56976 },
19568 {
"test_bug11766854", test_bug11766854 },
19569 {
"test_bug54790", test_bug54790 },
19570 {
"test_bug12337762", test_bug12337762 },
19571 {
"test_bug11754979", test_bug11754979 },
19572 {
"test_bug13001491", test_bug13001491 },
19573 {
"test_wl5968", test_wl5968 },
19574 {
"test_wl5924", test_wl5924 },
19575 {
"test_wl6587", test_wl6587 },
19580 static struct my_tests_st *get_my_tests() {
return my_tests; }