summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.cvsignore2
-rw-r--r--[-rwxr-xr-x]tests/CMakeLists.txt21
-rw-r--r--tests/Makefile.am66
-rwxr-xr-xtests/big_record.pl6
-rw-r--r--tests/bug25714.c6
-rw-r--r--tests/myisam-big-rows.tst2
-rw-r--r--tests/mysql_client_test.c1797
-rw-r--r--tests/thread_test.c51
8 files changed, 1534 insertions, 417 deletions
diff --git a/tests/.cvsignore b/tests/.cvsignore
deleted file mode 100644
index 282522db034..00000000000
--- a/tests/.cvsignore
+++ /dev/null
@@ -1,2 +0,0 @@
-Makefile
-Makefile.in
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 2093fc0da36..8bd6320ba62 100755..100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (C) 2006 MySQL AB
+# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -11,17 +11,20 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-# About "mysqlclient_notls", see note in "client/CMakeLists.txt"
-
-SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
ADD_DEFINITIONS("-DMYSQL_CLIENT")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
-ADD_EXECUTABLE(mysql_client_test mysql_client_test.c ../mysys/my_memmem.c)
-TARGET_LINK_LIBRARIES(mysql_client_test mysqlclient_notls wsock32)
+ADD_EXECUTABLE(mysql_client_test mysql_client_test.c)
+TARGET_LINK_LIBRARIES(mysql_client_test mysqlclient)
+SET_TARGET_PROPERTIES(mysql_client_test PROPERTIES LINKER_LANGUAGE CXX)
+
+IF(WITH_UNIT_TESTS)
+ ADD_EXECUTABLE(bug25714 bug25714.c)
+ TARGET_LINK_LIBRARIES(bug25714 mysqlclient)
+ SET_TARGET_PROPERTIES(bug25714 PROPERTIES LINKER_LANGUAGE CXX)
+ENDIF()
-ADD_EXECUTABLE(bug25714 bug25714.c)
-TARGET_LINK_LIBRARIES(bug25714 mysqlclient_notls wsock32)
+INSTALL(TARGETS mysql_client_test DESTINATION ${INSTALL_BINDIR} COMPONENT Test)
diff --git a/tests/Makefile.am b/tests/Makefile.am
deleted file mode 100644
index 876db7e8475..00000000000
--- a/tests/Makefile.am
+++ /dev/null
@@ -1,66 +0,0 @@
-# Copyright (c) 2000-2007 MySQL AB, 2009 Sun Microsystems, Inc.
-# Use is subject to license terms.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Library General Public
-# License as published by the Free Software Foundation; version 2
-# of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Library General Public License for more details.
-#
-# You should have received a copy of the GNU Library General Public
-# License along with this library; if not, write to the Free
-# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
-# MA 02110-1301, USA
-
-## Process this file with automake to create Makefile.in
-
-
-if THREAD_SAFE_CLIENT
-LIBMYSQLCLIENT_LA = $(top_builddir)/libmysql_r/libmysqlclient_r.la
-else
-LIBMYSQLCLIENT_LA = $(top_builddir)/libmysql/libmysqlclient.la
-endif
-
-EXTRA_DIST = auto_increment.res auto_increment.tst \
- function.res function.tst lock_test.pl lock_test.res \
- export.pl big_record.pl \
- fork2_test.pl fork_big.pl \
- insert_and_repair.pl \
- grant.pl grant.res test_delayed_insert.pl \
- pmail.pl mail_to_db.pl table_types.pl \
- myisam-big-rows.tst \
- CMakeLists.txt
-
-bin_PROGRAMS = mysql_client_test
-noinst_PROGRAMS = insert_test select_test thread_test bug25714
-
-INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \
- $(openssl_includes)
-LIBS = @CLIENT_LIBS@
-LDADD = @CLIENT_EXTRA_LDFLAGS@ \
- $(LIBMYSQLCLIENT_LA)
-
-mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS)
-mysql_client_test_SOURCES= mysql_client_test.c\
- $(top_srcdir)/mysys/my_memmem.c
-
-insert_test_SOURCES= insert_test.c
-select_test_SOURCES= select_test.c
-insert_test_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
-select_test_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
-
-bug25714_SOURCES= bug25714.c
-bug25714_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES)
-
-# Fix for mit-threads
-DEFS = -DMYSQL_CLIENT_NO_THREADS
-
-thread_test.o: thread_test.c
- $(COMPILE) -c $(INCLUDES) $<
-
-# Don't update the files from bitkeeper
-%::SCCS/s.%
diff --git a/tests/big_record.pl b/tests/big_record.pl
index 77d1e613193..0d5766e5f5d 100755
--- a/tests/big_record.pl
+++ b/tests/big_record.pl
@@ -1,6 +1,6 @@
#!/usr/bin/perl
-# Copyright (C) 2000, 2003 MySQL AB
+# Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -13,11 +13,11 @@
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# This is a test with stores big records in a blob.
# Note that for the default test the mysql server should have been
-# started with at least 'mysqld -O max_allowed_packet=30M' and you should have
+# started with at least 'mysqld --max_allowed_packet=30M' and you should have
# at least 256M memory in your computer.
use DBI;
diff --git a/tests/bug25714.c b/tests/bug25714.c
index ad3b863dd75..40c631d76a5 100644
--- a/tests/bug25714.c
+++ b/tests/bug25714.c
@@ -1,5 +1,4 @@
-/*
- Copyright (c) 2007 MySQL AB, 2009 Sun Microsystems, Inc.
+/* Copyright (c) 2007 MySQL AB, 2009 Sun Microsystems, Inc.
Use is subject to license terms.
This program is free software; you can redistribute it and/or modify
@@ -13,8 +12,7 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-*/
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include <my_global.h>
#include <my_sys.h>
diff --git a/tests/myisam-big-rows.tst b/tests/myisam-big-rows.tst
index 56c06f4820f..97147999f87 100644
--- a/tests/myisam-big-rows.tst
+++ b/tests/myisam-big-rows.tst
@@ -1,7 +1,7 @@
#
# Test rows with length above > 16M
# Note that for this to work, you should start mysqld with
-# -O max_allowed_packet=32M
+# --max_allowed_packet=32M
#
drop table if exists t1;
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 2472a0b6df6..ac6af1dc93d 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -33,6 +33,8 @@
#include <my_getopt.h>
#include <m_string.h>
#include <mysqld_error.h>
+#include <sql_common.h>
+#include <mysql/client_plugin.h>
#define VER "2.1"
#define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */
@@ -58,6 +60,7 @@ static unsigned int test_count= 0;
static unsigned int opt_count= 0;
static unsigned int iter_count= 0;
static my_bool have_innodb= FALSE;
+static char *opt_plugin_dir= 0, *opt_default_auth= 0;
static const char *opt_basedir= "./";
static const char *opt_vardir= "mysql-test/var";
@@ -244,6 +247,11 @@ static MYSQL *mysql_client_init(MYSQL* con)
if (res && shared_memory_base_name)
mysql_options(res, MYSQL_SHARED_MEMORY_BASE_NAME, shared_memory_base_name);
#endif
+ if (opt_plugin_dir && *opt_plugin_dir)
+ mysql_options(res, MYSQL_PLUGIN_DIR, opt_plugin_dir);
+
+ if (opt_default_auth && *opt_default_auth)
+ mysql_options(res, MYSQL_DEFAULT_AUTH, opt_default_auth);
return res;
}
@@ -325,6 +333,11 @@ static MYSQL* client_connect(ulong flag, uint protocol, my_bool auto_reconnect)
/* enable local infile, in non-binary builds often disabled by default */
mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, 0);
mysql_options(mysql, MYSQL_OPT_PROTOCOL, &protocol);
+ if (opt_plugin_dir && *opt_plugin_dir)
+ mysql_options(mysql, MYSQL_PLUGIN_DIR, opt_plugin_dir);
+
+ if (opt_default_auth && *opt_default_auth)
+ mysql_options(mysql, MYSQL_DEFAULT_AUTH, opt_default_auth);
if (!(mysql_real_connect(mysql, opt_host, opt_user,
opt_password, opt_db ? opt_db:"test", opt_port,
@@ -703,6 +716,29 @@ int my_stmt_result(const char *buff)
return row_count;
}
+/* Print the total number of warnings and the warnings themselves. */
+
+void my_process_warnings(MYSQL *conn, unsigned expected_warning_count)
+{
+ MYSQL_RES *result;
+ int rc;
+
+ if (!opt_silent)
+ fprintf(stdout, "\n total warnings: %u (expected: %u)\n",
+ mysql_warning_count(conn), expected_warning_count);
+
+ DIE_UNLESS(mysql_warning_count(mysql) == expected_warning_count);
+
+ rc= mysql_query(conn, "SHOW WARNINGS");
+ DIE_UNLESS(rc == 0);
+
+ result= mysql_store_result(conn);
+ mytest(result);
+
+ rc= my_process_result_set(result);
+ mysql_free_result(result);
+}
+
/* Utility function to verify a particular column data */
@@ -1516,6 +1552,817 @@ static void test_prepare_simple()
myquery(rc);
}
+/************************************************************************/
+
+#define FILE_PATH_SIZE 4096
+
+char mct_log_file_path[FILE_PATH_SIZE];
+FILE *mct_log_file= NULL;
+
+void mct_start_logging(const char *test_case_name)
+{
+ const char *tmp_dir= getenv("MYSQL_TMP_DIR");
+
+ if (!tmp_dir)
+ {
+ printf("Warning: MYSQL_TMP_DIR is not set. Logging is disabled.\n");
+ return;
+ }
+
+ if (mct_log_file)
+ {
+ printf("Warning: can not start logging for test case '%s' "
+ "because log is already open\n",
+ (const char *) test_case_name);
+ return;
+ }
+
+ /*
+ Path is: <tmp_dir>/<test_case_name>.out.log
+ 10 is length of '/' + '.out.log' + \0
+ */
+
+ if (strlen(tmp_dir) + strlen(test_case_name) + 10 > FILE_PATH_SIZE)
+ {
+ printf("Warning: MYSQL_TMP_DIR is too long. Logging is disabled.\n");
+ return;
+ }
+
+ my_snprintf(mct_log_file_path, FILE_PATH_SIZE,
+ "%s/%s.out.log",
+ (const char *) tmp_dir,
+ (const char *) test_case_name);
+
+ mct_log_file= my_fopen(mct_log_file_path, O_WRONLY | O_BINARY, MYF(MY_WME));
+
+ if (!mct_log_file)
+ {
+ printf("Warning: can not open log file (%s): %s. Logging is disabled.\n",
+ (const char *) mct_log_file_path,
+ (const char *) strerror(errno));
+ return;
+ }
+}
+
+void mct_log(const char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ vprintf(format, args);
+ va_end(args);
+
+ if (mct_log_file)
+ {
+ va_list args;
+ va_start(args, format);
+ vfprintf(mct_log_file, format, args);
+ va_end(args);
+ }
+}
+
+void mct_close_log()
+{
+ if (!mct_log_file)
+ return;
+
+ my_fclose(mct_log_file, MYF(0));
+ mct_log_file= NULL;
+}
+
+#define WL4435_NUM_PARAMS 10
+#define WL4435_STRING_SIZE 30
+
+static void test_wl4435()
+{
+ MYSQL_STMT *stmt;
+ int rc;
+ char query[MAX_TEST_QUERY_LENGTH];
+
+ char str_data[20][WL4435_STRING_SIZE];
+ double dbl_data[20];
+ char dec_data[20][WL4435_STRING_SIZE];
+ int int_data[20];
+ ulong str_length= WL4435_STRING_SIZE;
+ my_bool is_null;
+ MYSQL_BIND ps_params[WL4435_NUM_PARAMS];
+
+ int exec_counter;
+
+ myheader("test_wl4435");
+ mct_start_logging("test_wl4435");
+
+ rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p2");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS t2");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "CREATE TABLE t1(a1 INT, a2 CHAR(32), "
+ " a3 DOUBLE(4, 2), a4 DECIMAL(3, 1))");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "CREATE TABLE t2(b0 INT, b1 INT, b2 CHAR(32), "
+ " b3 DOUBLE(4, 2), b4 DECIMAL(3, 1))");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "INSERT INTO t1 VALUES"
+ "(1, '11', 12.34, 56.7), "
+ "(2, '12', 56.78, 90.1), "
+ "(3, '13', 23.45, 67.8)");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "INSERT INTO t2 VALUES"
+ "(100, 10, '110', 70.70, 10.1), "
+ "(200, 20, '120', 80.80, 20.2), "
+ "(300, 30, '130', 90.90, 30.3)");
+ myquery(rc);
+
+ rc= mysql_query(mysql,
+ "CREATE PROCEDURE p1("
+ " IN v0 INT, "
+ " OUT v_str_1 CHAR(32), "
+ " OUT v_dbl_1 DOUBLE(4, 2), "
+ " OUT v_dec_1 DECIMAL(6, 3), "
+ " OUT v_int_1 INT, "
+ " IN v1 INT, "
+ " INOUT v_str_2 CHAR(64), "
+ " INOUT v_dbl_2 DOUBLE(5, 3), "
+ " INOUT v_dec_2 DECIMAL(7, 4), "
+ " INOUT v_int_2 INT)"
+ "BEGIN "
+ " SET v0 = -1; "
+ " SET v1 = -1; "
+ " SET v_str_1 = 'test_1'; "
+ " SET v_dbl_1 = 12.34; "
+ " SET v_dec_1 = 567.891; "
+ " SET v_int_1 = 2345; "
+ " SET v_str_2 = 'test_2'; "
+ " SET v_dbl_2 = 67.891; "
+ " SET v_dec_2 = 234.6789; "
+ " SET v_int_2 = 6789; "
+ " SELECT * FROM t1; "
+ " SELECT * FROM t2; "
+ "END");
+ myquery(rc);
+
+ rc= mysql_query(mysql,
+ "CREATE PROCEDURE p2("
+ " IN i1 VARCHAR(255) CHARACTER SET koi8r, "
+ " OUT o1 VARCHAR(255) CHARACTER SET cp1251, "
+ " OUT o2 VARBINARY(255)) "
+ "BEGIN "
+ " SET o1 = i1; "
+ " SET o2 = i1; "
+ "END");
+ myquery(rc);
+
+ strmov(query, "CALL p1(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
+ stmt= mysql_simple_prepare(mysql, query);
+ check_stmt(stmt);
+
+ /* Init PS-parameters. */
+
+ bzero((char *) ps_params, sizeof (ps_params));
+
+ /* - v0 -- INT */
+
+ ps_params[0].buffer_type= MYSQL_TYPE_LONG;
+ ps_params[0].buffer= (char *) &int_data[0];
+ ps_params[0].length= 0;
+ ps_params[0].is_null= 0;
+
+ /* - v_str_1 -- CHAR(32) */
+
+ ps_params[1].buffer_type= MYSQL_TYPE_STRING;
+ ps_params[1].buffer= (char *) str_data[0];
+ ps_params[1].buffer_length= WL4435_STRING_SIZE;
+ ps_params[1].length= &str_length;
+ ps_params[1].is_null= 0;
+
+ /* - v_dbl_1 -- DOUBLE */
+
+ ps_params[2].buffer_type= MYSQL_TYPE_DOUBLE;
+ ps_params[2].buffer= (char *) &dbl_data[0];
+ ps_params[2].length= 0;
+ ps_params[2].is_null= 0;
+
+ /* - v_dec_1 -- DECIMAL */
+
+ ps_params[3].buffer_type= MYSQL_TYPE_NEWDECIMAL;
+ ps_params[3].buffer= (char *) dec_data[0];
+ ps_params[3].buffer_length= WL4435_STRING_SIZE;
+ ps_params[3].length= 0;
+ ps_params[3].is_null= 0;
+
+ /* - v_int_1 -- INT */
+
+ ps_params[4].buffer_type= MYSQL_TYPE_LONG;
+ ps_params[4].buffer= (char *) &int_data[0];
+ ps_params[4].length= 0;
+ ps_params[4].is_null= 0;
+
+ /* - v1 -- INT */
+
+ ps_params[5].buffer_type= MYSQL_TYPE_LONG;
+ ps_params[5].buffer= (char *) &int_data[0];
+ ps_params[5].length= 0;
+ ps_params[5].is_null= 0;
+
+ /* - v_str_2 -- CHAR(32) */
+
+ ps_params[6].buffer_type= MYSQL_TYPE_STRING;
+ ps_params[6].buffer= (char *) str_data[0];
+ ps_params[6].buffer_length= WL4435_STRING_SIZE;
+ ps_params[6].length= &str_length;
+ ps_params[6].is_null= 0;
+
+ /* - v_dbl_2 -- DOUBLE */
+
+ ps_params[7].buffer_type= MYSQL_TYPE_DOUBLE;
+ ps_params[7].buffer= (char *) &dbl_data[0];
+ ps_params[7].length= 0;
+ ps_params[7].is_null= 0;
+
+ /* - v_dec_2 -- DECIMAL */
+
+ ps_params[8].buffer_type= MYSQL_TYPE_DECIMAL;
+ ps_params[8].buffer= (char *) dec_data[0];
+ ps_params[8].buffer_length= WL4435_STRING_SIZE;
+ ps_params[8].length= 0;
+ ps_params[8].is_null= 0;
+
+ /* - v_int_2 -- INT */
+
+ ps_params[9].buffer_type= MYSQL_TYPE_LONG;
+ ps_params[9].buffer= (char *) &int_data[0];
+ ps_params[9].length= 0;
+ ps_params[9].is_null= 0;
+
+ /* Bind parameters. */
+
+ rc= mysql_stmt_bind_param(stmt, ps_params);
+
+ /* Execute! */
+
+ for (exec_counter= 0; exec_counter < 3; ++exec_counter)
+ {
+ int i;
+ int num_fields;
+ MYSQL_BIND *rs_bind;
+
+ mct_log("\nexec_counter: %d\n", (int) exec_counter);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ while (1)
+ {
+ MYSQL_FIELD *fields;
+
+ MYSQL_RES *rs_metadata= mysql_stmt_result_metadata(stmt);
+
+ num_fields= mysql_stmt_field_count(stmt);
+ fields= mysql_fetch_fields(rs_metadata);
+
+ rs_bind= (MYSQL_BIND *) malloc(sizeof (MYSQL_BIND) * num_fields);
+ bzero(rs_bind, sizeof (MYSQL_BIND) * num_fields);
+
+ mct_log("num_fields: %d\n", (int) num_fields);
+
+ for (i = 0; i < num_fields; ++i)
+ {
+ mct_log(" - %d: name: '%s'/'%s'; table: '%s'/'%s'; "
+ "db: '%s'; catalog: '%s'; length: %d; max_length: %d; "
+ "type: %d; decimals: %d\n",
+ (int) i,
+ (const char *) fields[i].name,
+ (const char *) fields[i].org_name,
+ (const char *) fields[i].table,
+ (const char *) fields[i].org_table,
+ (const char *) fields[i].db,
+ (const char *) fields[i].catalog,
+ (int) fields[i].length,
+ (int) fields[i].max_length,
+ (int) fields[i].type,
+ (int) fields[i].decimals);
+
+ rs_bind[i].buffer_type= fields[i].type;
+ rs_bind[i].is_null= &is_null;
+
+ switch (fields[i].type)
+ {
+ case MYSQL_TYPE_LONG:
+ rs_bind[i].buffer= (char *) &(int_data[i]);
+ rs_bind[i].buffer_length= sizeof (int_data);
+ break;
+
+ case MYSQL_TYPE_STRING:
+ rs_bind[i].buffer= (char *) str_data[i];
+ rs_bind[i].buffer_length= WL4435_STRING_SIZE;
+ rs_bind[i].length= &str_length;
+ break;
+
+ case MYSQL_TYPE_DOUBLE:
+ rs_bind[i].buffer= (char *) &dbl_data[i];
+ rs_bind[i].buffer_length= sizeof (dbl_data);
+ break;
+
+ case MYSQL_TYPE_NEWDECIMAL:
+ rs_bind[i].buffer= (char *) dec_data[i];
+ rs_bind[i].buffer_length= WL4435_STRING_SIZE;
+ rs_bind[i].length= &str_length;
+ break;
+
+ default:
+ fprintf(stderr, "ERROR: unexpected type: %d.\n", fields[i].type);
+ exit(1);
+ }
+ }
+
+ rc= mysql_stmt_bind_result(stmt, rs_bind);
+ check_execute(stmt, rc);
+
+ mct_log("Data:\n");
+
+ while (1)
+ {
+ int rc= mysql_stmt_fetch(stmt);
+
+ if (rc == 1 || rc == MYSQL_NO_DATA)
+ break;
+
+ mct_log(" ");
+
+ for (i = 0; i < num_fields; ++i)
+ {
+ switch (rs_bind[i].buffer_type)
+ {
+ case MYSQL_TYPE_LONG:
+ mct_log(" int: %ld;",
+ (long) *((int *) rs_bind[i].buffer));
+ break;
+
+ case MYSQL_TYPE_STRING:
+ mct_log(" str: '%s';",
+ (char *) rs_bind[i].buffer);
+ break;
+
+ case MYSQL_TYPE_DOUBLE:
+ mct_log(" dbl: %lf;",
+ (double) *((double *) rs_bind[i].buffer));
+ break;
+
+ case MYSQL_TYPE_NEWDECIMAL:
+ mct_log(" dec: '%s';",
+ (char *) rs_bind[i].buffer);
+ break;
+
+ default:
+ printf(" unexpected type (%d)\n",
+ rs_bind[i].buffer_type);
+ }
+ }
+ mct_log("\n");
+ }
+
+ mct_log("EOF\n");
+
+ rc= mysql_stmt_next_result(stmt);
+ mct_log("mysql_stmt_next_result(): %d; field_count: %d\n",
+ (int) rc, (int) mysql->field_count);
+
+ free(rs_bind);
+ mysql_free_result(rs_metadata);
+
+ if (rc > 0)
+ {
+ printf("Error: %s (errno: %d)\n",
+ mysql_stmt_error(stmt), mysql_stmt_errno(stmt));
+ DIE(rc > 0);
+ }
+
+ if (rc)
+ break;
+
+ if (!mysql->field_count)
+ {
+ /* This is the last OK-packet. No more resultsets. */
+ break;
+ }
+ }
+
+ }
+
+ mysql_stmt_close(stmt);
+
+ mct_close_log();
+
+ rc= mysql_commit(mysql);
+ myquery(rc);
+
+ /* i18n part of test case. */
+
+ {
+ const char *str_koi8r= "\xee\xd5\x2c\x20\xda\xc1\x20\xd2\xd9\xc2\xc1\xcc\xcb\xd5";
+ const char *str_cp1251= "\xcd\xf3\x2c\x20\xe7\xe0\x20\xf0\xfb\xe1\xe0\xeb\xea\xf3";
+ char o1_buffer[255];
+ ulong o1_length;
+ char o2_buffer[255];
+ ulong o2_length;
+
+ MYSQL_BIND rs_bind[2];
+
+ strmov(query, "CALL p2(?, ?, ?)");
+ stmt= mysql_simple_prepare(mysql, query);
+ check_stmt(stmt);
+
+ /* Init PS-parameters. */
+
+ bzero((char *) ps_params, sizeof (ps_params));
+
+ ps_params[0].buffer_type= MYSQL_TYPE_STRING;
+ ps_params[0].buffer= (char *) str_koi8r;
+ ps_params[0].buffer_length= strlen(str_koi8r);
+
+ ps_params[1].buffer_type= MYSQL_TYPE_STRING;
+ ps_params[1].buffer= o1_buffer;
+ ps_params[1].buffer_length= 0;
+
+ ps_params[2].buffer_type= MYSQL_TYPE_STRING;
+ ps_params[2].buffer= o2_buffer;
+ ps_params[2].buffer_length= 0;
+
+ /* Bind parameters. */
+
+ rc= mysql_stmt_bind_param(stmt, ps_params);
+ check_execute(stmt, rc);
+
+ /* Prevent converting to character_set_results. */
+
+ rc= mysql_query(mysql, "SET NAMES binary");
+ myquery(rc);
+
+ /* Execute statement. */
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ /* Bind result. */
+
+ bzero(rs_bind, sizeof (rs_bind));
+
+ rs_bind[0].buffer_type= MYSQL_TYPE_STRING;
+ rs_bind[0].buffer= o1_buffer;
+ rs_bind[0].buffer_length= sizeof (o1_buffer);
+ rs_bind[0].length= &o1_length;
+
+ rs_bind[1].buffer_type= MYSQL_TYPE_BLOB;
+ rs_bind[1].buffer= o2_buffer;
+ rs_bind[1].buffer_length= sizeof (o2_buffer);
+ rs_bind[1].length= &o2_length;
+
+ rc= mysql_stmt_bind_result(stmt, rs_bind);
+ check_execute(stmt, rc);
+
+ /* Fetch result. */
+
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+
+ /* Check result. */
+
+ DIE_UNLESS(o1_length == strlen(str_cp1251));
+ DIE_UNLESS(o2_length == strlen(str_koi8r));
+ DIE_UNLESS(!memcmp(o1_buffer, str_cp1251, o1_length));
+ DIE_UNLESS(!memcmp(o2_buffer, str_koi8r, o2_length));
+
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+
+ rc= mysql_stmt_next_result(stmt);
+ DIE_UNLESS(rc == 0 && mysql->field_count == 0);
+
+ mysql_stmt_close(stmt);
+
+ rc= mysql_commit(mysql);
+ myquery(rc);
+ }
+}
+
+static void test_wl4435_2()
+{
+ MYSQL_STMT *stmt;
+ int i;
+ int rc;
+ char query[MAX_TEST_QUERY_LENGTH];
+
+ myheader("test_wl4435_2");
+ mct_start_logging("test_wl4435_2");
+
+ /*
+ Do a few iterations so that we catch any problem with incorrect
+ handling/flushing prepared statement results.
+ */
+
+ for (i= 0; i < 10; ++i)
+ {
+ /*
+ Prepare a procedure. That can be moved out of the loop, but it was
+ left in the loop for the sake of having as many statements as
+ possible.
+ */
+
+ rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1");
+ myquery(rc);
+
+ rc= mysql_query(mysql,
+ "CREATE PROCEDURE p1()"
+ "BEGIN "
+ " SELECT 1; "
+ " SELECT 2, 3 UNION SELECT 4, 5; "
+ " SELECT 6, 7, 8; "
+ "END");
+ myquery(rc);
+
+ /* Invoke a procedure, that returns several result sets. */
+
+ strmov(query, "CALL p1()");
+ stmt= mysql_simple_prepare(mysql, query);
+ check_stmt(stmt);
+
+ /* Execute! */
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ /* Flush all the results. */
+
+ mysql_stmt_close(stmt);
+
+ /* Clean up. */
+ rc= mysql_commit(mysql);
+ myquery(rc);
+
+ rc= mysql_query(mysql, "DROP PROCEDURE p1");
+ myquery(rc);
+ }
+}
+
+
+#define WL4435_TEST(sql_type, sql_value, \
+ c_api_in_type, c_api_out_type, \
+ c_type, c_type_ext, \
+ printf_args, assert_condition) \
+\
+ do { \
+ int rc; \
+ MYSQL_STMT *ps; \
+ MYSQL_BIND psp; \
+ MYSQL_RES *rs_metadata; \
+ MYSQL_FIELD *fields; \
+ c_type pspv c_type_ext; \
+ my_bool psp_null; \
+ \
+ bzero(&pspv, sizeof (pspv)); \
+ \
+ rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1"); \
+ myquery(rc); \
+ \
+ rc= mysql_query(mysql, \
+ "CREATE PROCEDURE p1(OUT v " sql_type ") SET v = " sql_value ";"); \
+ myquery(rc); \
+ \
+ ps = mysql_simple_prepare(mysql, "CALL p1(?)"); \
+ check_stmt(ps); \
+ \
+ bzero(&psp, sizeof (psp)); \
+ psp.buffer_type= c_api_in_type; \
+ psp.is_null= &psp_null; \
+ psp.buffer= (char *) &pspv; \
+ psp.buffer_length= sizeof (psp); \
+ \
+ rc= mysql_stmt_bind_param(ps, &psp); \
+ check_execute(ps, rc); \
+ \
+ rc= mysql_stmt_execute(ps); \
+ check_execute(ps, rc); \
+ \
+ DIE_UNLESS(mysql->server_status & SERVER_PS_OUT_PARAMS); \
+ DIE_UNLESS(mysql_stmt_field_count(ps) == 1); \
+ \
+ rs_metadata= mysql_stmt_result_metadata(ps); \
+ fields= mysql_fetch_fields(rs_metadata); \
+ \
+ rc= mysql_stmt_bind_result(ps, &psp); \
+ check_execute(ps, rc); \
+ \
+ rc= mysql_stmt_fetch(ps); \
+ DIE_UNLESS(rc == 0); \
+ \
+ DIE_UNLESS(fields[0].type == c_api_out_type); \
+ printf printf_args; \
+ printf("; in type: %d; out type: %d\n", \
+ (int) c_api_in_type, (int) c_api_out_type); \
+ \
+ rc= mysql_stmt_fetch(ps); \
+ DIE_UNLESS(rc == MYSQL_NO_DATA); \
+ \
+ rc= mysql_stmt_next_result(ps); \
+ DIE_UNLESS(rc == 0); \
+ \
+ mysql_stmt_free_result(ps); \
+ mysql_stmt_close(ps); \
+ \
+ DIE_UNLESS(assert_condition); \
+ \
+ } while (0)
+
+static void test_wl4435_3()
+{
+ char tmp[255];
+
+ puts("");
+
+ // The following types are not supported:
+ // - ENUM
+ // - SET
+ //
+ // The following types are supported but can not be used for
+ // OUT-parameters:
+ // - MEDIUMINT;
+ // - BIT(..);
+ //
+ // The problem is that those types are not supported for IN-parameters,
+ // and OUT-parameters should be bound as IN-parameters before execution.
+ //
+ // The following types should not be used:
+ // - MYSQL_TYPE_YEAR (use MYSQL_TYPE_SHORT instead);
+ // - MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB
+ // (use MYSQL_TYPE_BLOB instead);
+
+ WL4435_TEST("TINYINT", "127",
+ MYSQL_TYPE_TINY, MYSQL_TYPE_TINY,
+ char, ,
+ (" - TINYINT / char / MYSQL_TYPE_TINY:\t\t\t %d", (int) pspv),
+ pspv == 127);
+
+ WL4435_TEST("SMALLINT", "32767",
+ MYSQL_TYPE_SHORT, MYSQL_TYPE_SHORT,
+ short, ,
+ (" - SMALLINT / short / MYSQL_TYPE_SHORT:\t\t %d", (int) pspv),
+ pspv == 32767);
+
+ WL4435_TEST("INT", "2147483647",
+ MYSQL_TYPE_LONG, MYSQL_TYPE_LONG,
+ int, ,
+ (" - INT / int / MYSQL_TYPE_LONG:\t\t\t %d", pspv),
+ pspv == 2147483647l);
+
+ WL4435_TEST("BIGINT", "9223372036854775807",
+ MYSQL_TYPE_LONGLONG, MYSQL_TYPE_LONGLONG,
+ long long, ,
+ (" - BIGINT / long long / MYSQL_TYPE_LONGLONG:\t\t %lld", pspv),
+ pspv == 9223372036854775807ll);
+
+ WL4435_TEST("TIMESTAMP", "'2007-11-18 15:01:02'",
+ MYSQL_TYPE_TIMESTAMP, MYSQL_TYPE_TIMESTAMP,
+ MYSQL_TIME, ,
+ (" - TIMESTAMP / MYSQL_TIME / MYSQL_TYPE_TIMESTAMP:\t "
+ "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
+ (int) pspv.year, (int) pspv.month, (int) pspv.day,
+ (int) pspv.hour, (int) pspv.minute, (int) pspv.second),
+ pspv.year == 2007 && pspv.month == 11 && pspv.day == 18 &&
+ pspv.hour == 15 && pspv.minute == 1 && pspv.second == 2);
+
+ WL4435_TEST("DATETIME", "'1234-11-12 12:34:59'",
+ MYSQL_TYPE_DATETIME, MYSQL_TYPE_DATETIME,
+ MYSQL_TIME, ,
+ (" - DATETIME / MYSQL_TIME / MYSQL_TYPE_DATETIME:\t "
+ "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",
+ (int) pspv.year, (int) pspv.month, (int) pspv.day,
+ (int) pspv.hour, (int) pspv.minute, (int) pspv.second),
+ pspv.year == 1234 && pspv.month == 11 && pspv.day == 12 &&
+ pspv.hour == 12 && pspv.minute == 34 && pspv.second == 59);
+
+ WL4435_TEST("TIME", "'123:45:01'",
+ MYSQL_TYPE_TIME, MYSQL_TYPE_TIME,
+ MYSQL_TIME, ,
+ (" - TIME / MYSQL_TIME / MYSQL_TYPE_TIME:\t\t "
+ "%.3d:%.2d:%.2d",
+ (int) pspv.hour, (int) pspv.minute, (int) pspv.second),
+ pspv.hour == 123 && pspv.minute == 45 && pspv.second == 1);
+
+ WL4435_TEST("DATE", "'1234-11-12'",
+ MYSQL_TYPE_DATE, MYSQL_TYPE_DATE,
+ MYSQL_TIME, ,
+ (" - DATE / MYSQL_TIME / MYSQL_TYPE_DATE:\t\t "
+ "%.4d-%.2d-%.2d",
+ (int) pspv.year, (int) pspv.month, (int) pspv.day),
+ pspv.year == 1234 && pspv.month == 11 && pspv.day == 12);
+
+ WL4435_TEST("YEAR", "'2010'",
+ MYSQL_TYPE_SHORT, MYSQL_TYPE_YEAR,
+ short, ,
+ (" - YEAR / short / MYSQL_TYPE_SHORT:\t\t\t %.4d", (int) pspv),
+ pspv == 2010);
+
+ WL4435_TEST("FLOAT(7, 4)", "123.4567",
+ MYSQL_TYPE_FLOAT, MYSQL_TYPE_FLOAT,
+ float, ,
+ (" - FLOAT / float / MYSQL_TYPE_FLOAT:\t\t\t %g", (double) pspv),
+ pspv - 123.4567 < 0.0001);
+
+ WL4435_TEST("DOUBLE(8, 5)", "123.45678",
+ MYSQL_TYPE_DOUBLE, MYSQL_TYPE_DOUBLE,
+ double, ,
+ (" - DOUBLE / double / MYSQL_TYPE_DOUBLE:\t\t %g", (double) pspv),
+ pspv - 123.45678 < 0.00001);
+
+ WL4435_TEST("DECIMAL(9, 6)", "123.456789",
+ MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NEWDECIMAL,
+ char, [255],
+ (" - DECIMAL / char[] / MYSQL_TYPE_NEWDECIMAL:\t\t '%s'", (char *) pspv),
+ !strcmp(pspv, "123.456789"));
+
+ WL4435_TEST("CHAR(32)", "REPEAT('C', 16)",
+ MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
+ char, [255],
+ (" - CHAR(32) / char[] / MYSQL_TYPE_STRING:\t\t '%s'", (char *) pspv),
+ !strcmp(pspv, "CCCCCCCCCCCCCCCC"));
+
+ WL4435_TEST("VARCHAR(32)", "REPEAT('V', 16)",
+ MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_VAR_STRING,
+ char, [255],
+ (" - VARCHAR(32) / char[] / MYSQL_TYPE_VAR_STRING:\t '%s'", (char *) pspv),
+ !strcmp(pspv, "VVVVVVVVVVVVVVVV"));
+
+ WL4435_TEST("TINYTEXT", "REPEAT('t', 16)",
+ MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_BLOB,
+ char, [255],
+ (" - TINYTEXT / char[] / MYSQL_TYPE_TINY_BLOB:\t\t '%s'", (char *) pspv),
+ !strcmp(pspv, "tttttttttttttttt"));
+
+ WL4435_TEST("TEXT", "REPEAT('t', 16)",
+ MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
+ char, [255],
+ (" - TEXT / char[] / MYSQL_TYPE_BLOB:\t\t\t '%s'", (char *) pspv),
+ !strcmp(pspv, "tttttttttttttttt"));
+
+ WL4435_TEST("MEDIUMTEXT", "REPEAT('t', 16)",
+ MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_BLOB,
+ char, [255],
+ (" - MEDIUMTEXT / char[] / MYSQL_TYPE_MEDIUM_BLOB:\t '%s'", (char *) pspv),
+ !strcmp(pspv, "tttttttttttttttt"));
+
+ WL4435_TEST("LONGTEXT", "REPEAT('t', 16)",
+ MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_BLOB,
+ char, [255],
+ (" - LONGTEXT / char[] / MYSQL_TYPE_LONG_BLOB:\t\t '%s'", (char *) pspv),
+ !strcmp(pspv, "tttttttttttttttt"));
+
+ WL4435_TEST("BINARY(32)", "REPEAT('\1', 16)",
+ MYSQL_TYPE_STRING, MYSQL_TYPE_STRING,
+ char, [255],
+ (" - BINARY(32) / char[] / MYSQL_TYPE_STRING:\t\t '%s'", (char *) pspv),
+ memset(tmp, 1, 16) && !memcmp(tmp, pspv, 16));
+
+ WL4435_TEST("VARBINARY(32)", "REPEAT('\1', 16)",
+ MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_VAR_STRING,
+ char, [255],
+ (" - VARBINARY(32) / char[] / MYSQL_TYPE_VAR_STRING:\t '%s'", (char *) pspv),
+ memset(tmp, 1, 16) && !memcmp(tmp, pspv, 16));
+
+ WL4435_TEST("TINYBLOB", "REPEAT('\2', 16)",
+ MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_BLOB,
+ char, [255],
+ (" - TINYBLOB / char[] / MYSQL_TYPE_TINY_BLOB:\t\t '%s'", (char *) pspv),
+ memset(tmp, 2, 16) && !memcmp(tmp, pspv, 16));
+
+ WL4435_TEST("BLOB", "REPEAT('\2', 16)",
+ MYSQL_TYPE_BLOB, MYSQL_TYPE_BLOB,
+ char, [255],
+ (" - BLOB / char[] / MYSQL_TYPE_BLOB:\t\t\t '%s'", (char *) pspv),
+ memset(tmp, 2, 16) && !memcmp(tmp, pspv, 16));
+
+ WL4435_TEST("MEDIUMBLOB", "REPEAT('\2', 16)",
+ MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_BLOB,
+ char, [255],
+ (" - MEDIUMBLOB / char[] / MYSQL_TYPE_MEDIUM_BLOB:\t '%s'", (char *) pspv),
+ memset(tmp, 2, 16) && !memcmp(tmp, pspv, 16));
+
+ WL4435_TEST("LONGBLOB", "REPEAT('\2', 16)",
+ MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_BLOB,
+ char, [255],
+ (" - LONGBLOB / char[] / MYSQL_TYPE_LONG_BLOB:\t\t '%s'", (char *) pspv),
+ memset(tmp, 2, 16) && !memcmp(tmp, pspv, 16));
+}
+
/* Test simple prepare field results */
@@ -1532,7 +2379,7 @@ static void test_prepare_field_result()
myquery(rc);
rc= mysql_query(mysql, "CREATE TABLE test_prepare_field_result(int_c int, "
- "var_c varchar(50), ts_c timestamp(14), "
+ "var_c varchar(50), ts_c timestamp, "
"char_c char(4), date_c date, extra tinyint)");
myquery(rc);
@@ -4293,11 +5140,11 @@ static void test_fetch_date()
myquery(rc);
rc= mysql_query(mysql, "CREATE TABLE test_bind_result(c1 date, c2 time, \
- c3 timestamp(14), \
+ c3 timestamp, \
c4 year, \
c5 datetime, \
- c6 timestamp(4), \
- c7 timestamp(6))");
+ c6 timestamp, \
+ c7 timestamp)");
myquery(rc);
rc= mysql_query(mysql, "SET SQL_MODE=''");
@@ -4611,7 +5458,7 @@ static void test_prepare_ext()
" c12 numeric(8, 4),"
" c13 date,"
" c14 datetime,"
- " c15 timestamp(14),"
+ " c15 timestamp,"
" c16 time,"
" c17 year,"
" c18 bit,"
@@ -5088,7 +5935,7 @@ static void test_stmt_close()
}
-/* Test simple set-variable prepare */
+/* Test simple set variable prepare */
static void test_set_variable()
{
@@ -5190,215 +6037,6 @@ static void test_set_variable()
mysql_stmt_close(stmt1);
}
-#if NOT_USED
-
-/* Insert meta info .. */
-
-static void test_insert_meta()
-{
- MYSQL_STMT *stmt;
- int rc;
- MYSQL_RES *result;
- MYSQL_FIELD *field;
-
- myheader("test_insert_meta");
-
- rc= mysql_autocommit(mysql, TRUE);
- myquery(rc);
-
- rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prep_insert");
- myquery(rc);
-
- rc= mysql_query(mysql, "CREATE TABLE test_prep_insert(col1 tinyint, \
- col2 varchar(50), col3 varchar(30))");
- myquery(rc);
-
- strmov(query, "INSERT INTO test_prep_insert VALUES(10, 'venu1', 'test')");
- stmt= mysql_simple_prepare(mysql, query);
- check_stmt(stmt);
-
- verify_param_count(stmt, 0);
-
- result= mysql_param_result(stmt);
- mytest_r(result);
-
- mysql_stmt_close(stmt);
-
- strmov(query, "INSERT INTO test_prep_insert VALUES(?, 'venu', ?)");
- stmt= mysql_simple_prepare(mysql, query);
- check_stmt(stmt);
-
- verify_param_count(stmt, 2);
-
- result= mysql_param_result(stmt);
- mytest(result);
-
- my_print_result_metadata(result);
-
- mysql_field_seek(result, 0);
- field= mysql_fetch_field(result);
- mytest(field);
- if (!opt_silent)
- fprintf(stdout, "\n obtained: `%s` (expected: `%s`)", field->name, "col1");
- DIE_UNLESS(strcmp(field->name, "col1") == 0);
-
- field= mysql_fetch_field(result);
- mytest(field);
- if (!opt_silent)
- fprintf(stdout, "\n obtained: `%s` (expected: `%s`)", field->name, "col3");
- DIE_UNLESS(strcmp(field->name, "col3") == 0);
-
- field= mysql_fetch_field(result);
- mytest_r(field);
-
- mysql_free_result(result);
- mysql_stmt_close(stmt);
-}
-
-
-/* Update meta info .. */
-
-static void test_update_meta()
-{
- MYSQL_STMT *stmt;
- int rc;
- MYSQL_RES *result;
- MYSQL_FIELD *field;
-
- myheader("test_update_meta");
-
- rc= mysql_autocommit(mysql, TRUE);
- myquery(rc);
-
- rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prep_update");
- myquery(rc);
-
- rc= mysql_query(mysql, "CREATE TABLE test_prep_update(col1 tinyint, \
- col2 varchar(50), col3 varchar(30))");
- myquery(rc);
-
- strmov(query, "UPDATE test_prep_update SET col1=10, col2='venu1' WHERE col3='test'");
- stmt= mysql_simple_prepare(mysql, query);
- check_stmt(stmt);
-
- verify_param_count(stmt, 0);
-
- result= mysql_param_result(stmt);
- mytest_r(result);
-
- mysql_stmt_close(stmt);
-
- strmov(query, "UPDATE test_prep_update SET col1=?, col2='venu' WHERE col3=?");
- stmt= mysql_simple_prepare(mysql, query);
- check_stmt(stmt);
-
- verify_param_count(stmt, 2);
-
- result= mysql_param_result(stmt);
- mytest(result);
-
- my_print_result_metadata(result);
-
- mysql_field_seek(result, 0);
- field= mysql_fetch_field(result);
- mytest(field);
- if (!opt_silent)
- {
- fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col1");
- fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_update");
- }
- DIE_UNLESS(strcmp(field->name, "col1") == 0);
- DIE_UNLESS(strcmp(field->table, "test_prep_update") == 0);
-
- field= mysql_fetch_field(result);
- mytest(field);
- if (!opt_silent)
- {
- fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col3");
- fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_update");
- }
- DIE_UNLESS(strcmp(field->name, "col3") == 0);
- DIE_UNLESS(strcmp(field->table, "test_prep_update") == 0);
-
- field= mysql_fetch_field(result);
- mytest_r(field);
-
- mysql_free_result(result);
- mysql_stmt_close(stmt);
-}
-
-
-/* Select meta info .. */
-
-static void test_select_meta()
-{
- MYSQL_STMT *stmt;
- int rc;
- MYSQL_RES *result;
- MYSQL_FIELD *field;
-
- myheader("test_select_meta");
-
- rc= mysql_autocommit(mysql, TRUE);
- myquery(rc);
-
- rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_prep_select");
- myquery(rc);
-
- rc= mysql_query(mysql, "CREATE TABLE test_prep_select(col1 tinyint, \
- col2 varchar(50), col3 varchar(30))");
- myquery(rc);
-
- strmov(query, "SELECT * FROM test_prep_select WHERE col1=10");
- stmt= mysql_simple_prepare(mysql, query);
- check_stmt(stmt);
-
- verify_param_count(stmt, 0);
-
- result= mysql_param_result(stmt);
- mytest_r(result);
-
- strmov(query, "SELECT col1, col3 from test_prep_select WHERE col1=? AND col3='test' AND col2= ?");
- stmt= mysql_simple_prepare(mysql, query);
- check_stmt(stmt);
-
- verify_param_count(stmt, 2);
-
- result= mysql_param_result(stmt);
- mytest(result);
-
- my_print_result_metadata(result);
-
- mysql_field_seek(result, 0);
- field= mysql_fetch_field(result);
- mytest(field);
- if (!opt_silent)
- {
- fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col1");
- fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_select");
- }
- DIE_UNLESS(strcmp(field->name, "col1") == 0);
- DIE_UNLESS(strcmp(field->table, "test_prep_select") == 0);
-
- field= mysql_fetch_field(result);
- mytest(field);
- if (!opt_silent)
- {
- fprintf(stdout, "\n col obtained: `%s` (expected: `%s`)", field->name, "col2");
- fprintf(stdout, "\n tab obtained: `%s` (expected: `%s`)", field->table, "test_prep_select");
- }
- DIE_UNLESS(strcmp(field->name, "col2") == 0);
- DIE_UNLESS(strcmp(field->table, "test_prep_select") == 0);
-
- field= mysql_fetch_field(result);
- mytest_r(field);
-
- mysql_free_result(result);
- mysql_stmt_close(stmt);
-}
-#endif
-
-
/* Test FUNCTION field info / DATE_FORMAT() table_name . */
static void test_func_fields()
@@ -5645,7 +6283,7 @@ static void test_manual_sample()
}
if (mysql_query(mysql, "CREATE TABLE test_table(col1 int, col2 varchar(50), \
col3 smallint, \
- col4 timestamp(14))"))
+ col4 timestamp)"))
{
fprintf(stderr, "\n create table failed");
fprintf(stderr, "\n %s", mysql_error(mysql));
@@ -6555,7 +7193,7 @@ static void test_date()
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_date");
myquery(rc);
- rc= mysql_query(mysql, "CREATE TABLE test_date(c1 TIMESTAMP(14), \
+ rc= mysql_query(mysql, "CREATE TABLE test_date(c1 TIMESTAMP, \
c2 TIME, \
c3 DATETIME, \
c4 DATE)");
@@ -6621,10 +7259,10 @@ static void test_date_ts()
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_date");
myquery(rc);
- rc= mysql_query(mysql, "CREATE TABLE test_date(c1 TIMESTAMP(10), \
- c2 TIMESTAMP(14), \
+ rc= mysql_query(mysql, "CREATE TABLE test_date(c1 TIMESTAMP, \
+ c2 TIMESTAMP, \
c3 TIMESTAMP, \
- c4 TIMESTAMP(6))");
+ c4 TIMESTAMP)");
myquery(rc);
@@ -7773,26 +8411,26 @@ static void test_explain_bug()
verify_prepare_field(result, 0, "Field", "COLUMN_NAME",
mysql_get_server_version(mysql) <= 50000 ?
MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
- 0, 0, "", 64, 0);
+ 0, 0, "information_schema", 64, 0);
verify_prepare_field(result, 1, "Type", "COLUMN_TYPE", MYSQL_TYPE_BLOB,
- 0, 0, "", 0, 0);
+ 0, 0, "information_schema", 0, 0);
verify_prepare_field(result, 2, "Null", "IS_NULLABLE",
mysql_get_server_version(mysql) <= 50000 ?
MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
- 0, 0, "", 3, 0);
+ 0, 0, "information_schema", 3, 0);
verify_prepare_field(result, 3, "Key", "COLUMN_KEY",
mysql_get_server_version(mysql) <= 50000 ?
MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
- 0, 0, "", 3, 0);
+ 0, 0, "information_schema", 3, 0);
if ( mysql_get_server_version(mysql) >= 50027 )
{
/* The patch for bug#23037 changes column type of DEAULT to blob */
verify_prepare_field(result, 4, "Default", "COLUMN_DEFAULT",
- MYSQL_TYPE_BLOB, 0, 0, "", 0, 0);
+ MYSQL_TYPE_BLOB, 0, 0, "information_schema", 0, 0);
}
else
{
@@ -7801,14 +8439,14 @@ static void test_explain_bug()
MYSQL_TYPE_BLOB :
mysql_get_server_version(mysql) <= 50000 ?
MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
- 0, 0, "",
+ 0, 0, "information_schema",
mysql_get_server_version(mysql) >= 50027 ? 0 :64, 0);
}
verify_prepare_field(result, 5, "Extra", "EXTRA",
mysql_get_server_version(mysql) <= 50000 ?
MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
- 0, 0, "", 27, 0);
+ 0, 0, "information_schema", 27, 0);
mysql_free_result(result);
mysql_stmt_close(stmt);
@@ -8312,7 +8950,7 @@ static void test_fetch_seek()
myquery(rc);
- rc= mysql_query(mysql, "create table t1(c1 int primary key auto_increment, c2 char(10), c3 timestamp(14))");
+ rc= mysql_query(mysql, "create table t1(c1 int primary key auto_increment, c2 char(10), c3 timestamp)");
myquery(rc);
rc= mysql_query(mysql, "insert into t1(c2) values('venu'), ('mysql'), ('open'), ('source')");
@@ -12501,7 +13139,7 @@ static void test_datetime_ranges()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
- DIE_UNLESS(mysql_warning_count(mysql) != 6);
+ my_process_warnings(mysql, 12);
verify_col_data("t1", "year", "0000-00-00 00:00:00");
verify_col_data("t1", "month", "0000-00-00 00:00:00");
@@ -12532,7 +13170,7 @@ static void test_datetime_ranges()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
- DIE_UNLESS(mysql_warning_count(mysql) != 3);
+ my_process_warnings(mysql, 6);
verify_col_data("t1", "year", "0000-00-00 00:00:00");
verify_col_data("t1", "month", "0000-00-00 00:00:00");
@@ -12571,7 +13209,7 @@ static void test_datetime_ranges()
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
- DIE_UNLESS(mysql_warning_count(mysql) == 2);
+ my_process_warnings(mysql, 2);
verify_col_data("t1", "day_ovfl", "838:59:59");
verify_col_data("t1", "day", "828:30:30");
@@ -14491,9 +15129,8 @@ static void test_bug12001()
/* Create connection that supports multi statements */
if (!mysql_real_connect(mysql_local, opt_host, opt_user,
- opt_password, current_db, opt_port,
- opt_unix_socket, CLIENT_MULTI_STATEMENTS |
- CLIENT_MULTI_RESULTS))
+ opt_password, current_db, opt_port,
+ opt_unix_socket, CLIENT_MULTI_STATEMENTS))
{
fprintf(stdout, "\n mysql_real_connect() failed");
exit(1);
@@ -15057,8 +15694,11 @@ static void test_bug13488()
check_execute(stmt1, rc);
if (!opt_silent)
- printf("data is: %s", (f1 == 1 && f2 == 1 && f3 == 2)?"OK":
- "wrong");
+ {
+ printf("data: f1: %d; f2: %d; f3: %d\n", f1, f2, f3);
+ printf("data is: %s\n",
+ (f1 == 1 && f2 == 1 && f3 == 2) ? "OK" : "wrong");
+ }
DIE_UNLESS(f1 == 1 && f2 == 1 && f3 == 2);
rc= mysql_query(mysql, "drop table t1, t2");
myquery(rc);
@@ -15861,7 +16501,7 @@ static void test_bug15752()
if (! mysql_real_connect(&mysql_local, opt_host, opt_user,
opt_password, current_db, opt_port,
opt_unix_socket,
- CLIENT_MULTI_STATEMENTS|CLIENT_MULTI_RESULTS))
+ CLIENT_MULTI_STATEMENTS))
{
printf("Unable connect to MySQL server: %s\n", mysql_error(&mysql_local));
DIE_UNLESS(0);
@@ -17123,9 +17763,9 @@ static void test_bug20023()
SQL_BIG_SELECTS will be 1.
***********************************************************************/
- /* Set MAX_JOIN_SIZE to the default value (-1). */
+ /* Set MAX_JOIN_SIZE to the default value (2^64-1). */
- DIE_IF(mysql_query(&con, "SET @@global.max_join_size = 18446744073709551615"));
+ DIE_IF(mysql_query(&con, "SET @@global.max_join_size = cast(-1 as unsigned int)"));
DIE_IF(mysql_query(&con, "SET @@session.max_join_size = default"));
/* Issue COM_CHANGE_USER. */
@@ -17156,7 +17796,7 @@ static void test_bug20023()
DIE_IF(mysql_query(&con, query_buffer));
- DIE_IF(mysql_query(&con, "SET @@global.max_join_size = 18446744073709551615"));
+ DIE_IF(mysql_query(&con, "SET @@global.max_join_size = cast(-1 as unsigned int)"));
DIE_IF(mysql_query(&con, "SET @@session.max_join_size = default"));
/* Issue COM_CHANGE_USER. */
@@ -17449,6 +18089,7 @@ static void test_bug28386()
DBUG_VOID_RETURN;
}
+
static void test_wl4166_1()
{
MYSQL_STMT *stmt;
@@ -17660,10 +18301,266 @@ static void test_wl4166_2()
}
+
/**
- Bug#38486 Crash when using cursor protocol
+ Test how warnings generated during assignment of parameters
+ are (currently not) preserve in case of reprepare.
*/
+static void test_wl4166_3()
+{
+ int rc;
+ MYSQL_STMT *stmt;
+ MYSQL_BIND my_bind[1];
+ MYSQL_TIME tm[1];
+
+ myheader("test_wl4166_3");
+
+ rc= mysql_query(mysql, "drop table if exists t1");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "create table t1 (year datetime)");
+ myquery(rc);
+
+ stmt= mysql_simple_prepare(mysql, "insert into t1 (year) values (?)");
+ check_stmt(stmt);
+ verify_param_count(stmt, 1);
+
+ bzero((char*) my_bind, sizeof(my_bind));
+ my_bind[0].buffer_type= MYSQL_TYPE_DATETIME;
+ my_bind[0].buffer= &tm[0];
+
+ rc= mysql_stmt_bind_param(stmt, my_bind);
+ check_execute(stmt, rc);
+
+ tm[0].year= 10000;
+ tm[0].month= 1; tm[0].day= 1;
+ tm[0].hour= 1; tm[0].minute= 1; tm[0].second= 1;
+ tm[0].second_part= 0; tm[0].neg= 0;
+
+ /* Cause a statement reprepare */
+ rc= mysql_query(mysql, "alter table t1 add column c int");
+ myquery(rc);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ /*
+ Sic: only one warning, instead of two. The warning
+ about data truncation when assigning a parameter is lost.
+ This is a bug.
+ */
+ my_process_warnings(mysql, 1);
+
+ verify_col_data("t1", "year", "0000-00-00 00:00:00");
+
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+}
+
+
+/**
+ Test that long data parameters, as well as parameters
+ that were originally in a different character set, are
+ preserved in case of reprepare.
+*/
+
+static void test_wl4166_4()
+{
+ MYSQL_STMT *stmt;
+ int rc;
+ const char *stmt_text;
+ MYSQL_BIND bind_array[2];
+
+ /* Represented as numbers to keep UTF8 tools from clobbering them. */
+ const char *koi8= "\xee\xd5\x2c\x20\xda\xc1\x20\xd2\xd9\xc2\xc1\xcc\xcb\xd5";
+ const char *cp1251= "\xcd\xf3\x2c\x20\xe7\xe0\x20\xf0\xfb\xe1\xe0\xeb\xea\xf3";
+ char buf1[16], buf2[16];
+ ulong buf1_len, buf2_len;
+
+ myheader("test_wl4166_4");
+
+ rc= mysql_query(mysql, "drop table if exists t1");
+ myquery(rc);
+
+ /*
+ Create table with binary columns, set session character set to cp1251,
+ client character set to koi8, and make sure that there is conversion
+ on insert and no conversion on select
+ */
+ rc= mysql_query(mysql,
+ "create table t1 (c1 varbinary(255), c2 varbinary(255))");
+ myquery(rc);
+ rc= mysql_query(mysql, "set character_set_client=koi8r, "
+ "character_set_connection=cp1251, "
+ "character_set_results=koi8r");
+ myquery(rc);
+
+ bzero((char*) bind_array, sizeof(bind_array));
+
+ bind_array[0].buffer_type= MYSQL_TYPE_STRING;
+
+ bind_array[1].buffer_type= MYSQL_TYPE_STRING;
+ bind_array[1].buffer= (void *) koi8;
+ bind_array[1].buffer_length= strlen(koi8);
+
+ stmt= mysql_stmt_init(mysql);
+ check_stmt(stmt);
+
+ stmt_text= "insert into t1 (c1, c2) values (?, ?)";
+
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+
+ mysql_stmt_bind_param(stmt, bind_array);
+
+ mysql_stmt_send_long_data(stmt, 0, koi8, strlen(koi8));
+
+ /* Cause a reprepare at statement execute */
+ rc= mysql_query(mysql, "alter table t1 add column d int");
+ myquery(rc);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ stmt_text= "select c1, c2 from t1";
+
+ /* c1 and c2 are binary so no conversion will be done on select */
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ bind_array[0].buffer= buf1;
+ bind_array[0].buffer_length= sizeof(buf1);
+ bind_array[0].length= &buf1_len;
+
+ bind_array[1].buffer= buf2;
+ bind_array[1].buffer_length= sizeof(buf2);
+ bind_array[1].length= &buf2_len;
+
+ mysql_stmt_bind_result(stmt, bind_array);
+
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+
+ DIE_UNLESS(buf1_len == strlen(cp1251));
+ DIE_UNLESS(buf2_len == strlen(cp1251));
+ DIE_UNLESS(!memcmp(buf1, cp1251, buf1_len));
+ DIE_UNLESS(!memcmp(buf2, cp1251, buf1_len));
+
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "drop table t1");
+ myquery(rc);
+ rc= mysql_query(mysql, "set names default");
+ myquery(rc);
+}
+
+/**
+ Bug#36004 mysql_stmt_prepare resets the list of warnings
+*/
+
+static void test_bug36004()
+{
+ int rc, warning_count= 0;
+ MYSQL_STMT *stmt;
+
+ DBUG_ENTER("test_bug36004");
+ myheader("test_bug36004");
+
+ rc= mysql_query(mysql, "drop table if exists inexistant");
+ myquery(rc);
+
+ DIE_UNLESS(mysql_warning_count(mysql) == 1);
+ query_int_variable(mysql, "@@warning_count", &warning_count);
+ DIE_UNLESS(warning_count);
+
+ stmt= mysql_simple_prepare(mysql, "select 1");
+ check_stmt(stmt);
+
+ DIE_UNLESS(mysql_warning_count(mysql) == 0);
+ query_int_variable(mysql, "@@warning_count", &warning_count);
+ DIE_UNLESS(warning_count);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ DIE_UNLESS(mysql_warning_count(mysql) == 0);
+ mysql_stmt_close(stmt);
+
+ query_int_variable(mysql, "@@warning_count", &warning_count);
+ DIE_UNLESS(warning_count);
+
+ stmt= mysql_simple_prepare(mysql, "drop table if exists inexistant");
+ check_stmt(stmt);
+
+ query_int_variable(mysql, "@@warning_count", &warning_count);
+ DIE_UNLESS(warning_count == 0);
+ mysql_stmt_close(stmt);
+
+ DBUG_VOID_RETURN;
+}
+
+/**
+ Test that COM_REFRESH issues a implicit commit.
+*/
+
+static void test_wl4284_1()
+{
+ int rc;
+ MYSQL_ROW row;
+ MYSQL_RES *result;
+
+ DBUG_ENTER("test_wl4284_1");
+ myheader("test_wl4284_1");
+
+ /* set AUTOCOMMIT to OFF */
+ rc= mysql_autocommit(mysql, FALSE);
+ myquery(rc);
+
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS trans");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "CREATE TABLE trans (a INT) ENGINE= InnoDB");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "INSERT INTO trans VALUES(1)");
+ myquery(rc);
+
+ rc= mysql_refresh(mysql, REFRESH_GRANT | REFRESH_TABLES);
+ myquery(rc);
+
+ rc= mysql_rollback(mysql);
+ myquery(rc);
+
+ rc= mysql_query(mysql, "SELECT * FROM trans");
+ myquery(rc);
+
+ result= mysql_use_result(mysql);
+ mytest(result);
+
+ row= mysql_fetch_row(result);
+ mytest(row);
+
+ mysql_free_result(result);
+
+ /* set AUTOCOMMIT to ON */
+ rc= mysql_autocommit(mysql, TRUE);
+ myquery(rc);
+
+ rc= mysql_query(mysql, "DROP TABLE trans");
+ myquery(rc);
+
+ DBUG_VOID_RETURN;
+}
+
+
static void test_bug38486(void)
{
MYSQL_STMT *stmt;
@@ -17690,6 +18587,45 @@ static void test_bug38486(void)
DBUG_VOID_RETURN;
}
+
+/**
+ Bug# 33831 mysql_real_connect() should fail if
+ given an already connected MYSQL handle.
+*/
+
+static void test_bug33831(void)
+{
+ MYSQL *l_mysql;
+
+ DBUG_ENTER("test_bug33831");
+
+ if (!(l_mysql= mysql_client_init(NULL)))
+ {
+ myerror("mysql_client_init() failed");
+ DIE_UNLESS(0);
+ }
+ if (!(mysql_real_connect(l_mysql, opt_host, opt_user,
+ opt_password, current_db, opt_port,
+ opt_unix_socket, 0)))
+ {
+ myerror("connection failed");
+ DIE_UNLESS(0);
+ }
+
+ if (mysql_real_connect(l_mysql, opt_host, opt_user,
+ opt_password, current_db, opt_port,
+ opt_unix_socket, 0))
+ {
+ myerror("connection should have failed");
+ DIE_UNLESS(0);
+ }
+
+ mysql_close(l_mysql);
+
+ DBUG_VOID_RETURN;
+}
+
+
static void test_bug40365(void)
{
uint rc, i;
@@ -17768,6 +18704,8 @@ static void test_bug40365(void)
DIE_UNLESS(tm[i].day == 0);
}
mysql_stmt_close(stmt);
+ rc= mysql_commit(mysql);
+ myquery(rc);
DBUG_VOID_RETURN;
}
@@ -18108,43 +19046,6 @@ static void test_bug53371()
}
-static void test_bug53907()
-{
- int rc;
- uchar buf[] = "\x4test\x14../client_test_db/t1";
-
- myheader("test_bug53907");
-
- rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
- myquery(rc);
- rc= mysql_query(mysql, "DROP DATABASE IF EXISTS bug53907");
- myquery(rc);
- rc= mysql_query(mysql, "DROP USER 'testbug'@localhost");
-
- rc= mysql_query(mysql, "CREATE TABLE t1 (a INT)");
- myquery(rc);
- rc= mysql_query(mysql, "CREATE DATABASE bug53907");
- myquery(rc);
- rc= mysql_query(mysql, "GRANT SELECT ON bug53907.* to 'testbug'@localhost");
- myquery(rc);
-
- rc= mysql_change_user(mysql, "testbug", NULL, "bug53907");
- myquery(rc);
-
- rc= simple_command(mysql, COM_TABLE_DUMP, buf, sizeof(buf), 0);
- fprintf(stderr, ">>>>>>>>> %d\n", mysql_errno(mysql));
- DIE_UNLESS(mysql_errno(mysql) == 1103); /* ER_WRONG_TABLE_NAME */
-
- rc= mysql_change_user(mysql, opt_user, opt_password, current_db);
- myquery(rc);
- rc= mysql_query(mysql, "DROP TABLE t1");
- myquery(rc);
- rc= mysql_query(mysql, "DROP DATABASE bug53907");
- myquery(rc);
- rc= mysql_query(mysql, "DROP USER 'testbug'@localhost");
- myquery(rc);
-}
-
/**
Bug#42373: libmysql can mess a connection at connect
@@ -18465,6 +19366,116 @@ static void test_bug58036()
/*
+ Bug#49972: Crash in prepared statements.
+
+ The following case lead to a server crash:
+ - Use binary protocol;
+ - Prepare a statement with OUT-parameter;
+ - Execute the statement;
+ - Cause re-prepare of the statement (change dependencies);
+ - Execute the statement again -- crash here.
+*/
+
+static void test_bug49972()
+{
+ int rc;
+ MYSQL_STMT *stmt;
+
+ MYSQL_BIND in_param_bind;
+ MYSQL_BIND out_param_bind;
+ int int_data;
+ my_bool is_null;
+
+ DBUG_ENTER("test_bug49972");
+ myheader("test_bug49972");
+
+ rc= mysql_query(mysql, "DROP FUNCTION IF EXISTS f1");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "DROP PROCEDURE IF EXISTS p1");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "CREATE FUNCTION f1() RETURNS INT RETURN 1");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "CREATE PROCEDURE p1(IN a INT, OUT b INT) SET b = a");
+ myquery(rc);
+
+ stmt= mysql_simple_prepare(mysql, "CALL p1((SELECT f1()), ?)");
+ check_stmt(stmt);
+
+ bzero((char *) &in_param_bind, sizeof (in_param_bind));
+
+ in_param_bind.buffer_type= MYSQL_TYPE_LONG;
+ in_param_bind.buffer= (char *) &int_data;
+ in_param_bind.length= 0;
+ in_param_bind.is_null= 0;
+
+ rc= mysql_stmt_bind_param(stmt, &in_param_bind);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ {
+ bzero(&out_param_bind, sizeof (out_param_bind));
+
+ out_param_bind.buffer_type= MYSQL_TYPE_LONG;
+ out_param_bind.is_null= &is_null;
+ out_param_bind.buffer= &int_data;
+ out_param_bind.buffer_length= sizeof (int_data);
+
+ rc= mysql_stmt_bind_result(stmt, &out_param_bind);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_fetch(stmt);
+ rc= mysql_stmt_fetch(stmt);
+ DBUG_ASSERT(rc == MYSQL_NO_DATA);
+
+ mysql_stmt_next_result(stmt);
+ mysql_stmt_fetch(stmt);
+ }
+
+ rc= mysql_query(mysql, "DROP FUNCTION f1");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "CREATE FUNCTION f1() RETURNS INT RETURN 1");
+ myquery(rc);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ {
+ bzero(&out_param_bind, sizeof (out_param_bind));
+
+ out_param_bind.buffer_type= MYSQL_TYPE_LONG;
+ out_param_bind.is_null= &is_null;
+ out_param_bind.buffer= &int_data;
+ out_param_bind.buffer_length= sizeof (int_data);
+
+ rc= mysql_stmt_bind_result(stmt, &out_param_bind);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_fetch(stmt);
+ rc= mysql_stmt_fetch(stmt);
+ DBUG_ASSERT(rc == MYSQL_NO_DATA);
+
+ mysql_stmt_next_result(stmt);
+ mysql_stmt_fetch(stmt);
+ }
+
+ mysql_stmt_close(stmt);
+
+ rc= mysql_query(mysql, "DROP PROCEDURE p1");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "DROP FUNCTION f1");
+ myquery(rc);
+
+ DBUG_VOID_RETURN;
+}
+
+
+/*
Bug #56976: Severe Denial Of Service in prepared statements
*/
static void test_bug56976()
@@ -18503,7 +19514,7 @@ static void test_bug56976()
check_execute(stmt, rc);
}
- my_free(long_buffer, MYF(0));
+ my_free(long_buffer);
rc= mysql_stmt_execute(stmt);
DIE_UNLESS(rc && mysql_stmt_errno(stmt) == ER_UNKNOWN_ERROR);
@@ -18513,6 +19524,170 @@ static void test_bug56976()
DBUG_VOID_RETURN;
}
+
+/**
+ Bug#57058 SERVER_QUERY_WAS_SLOW not wired up.
+*/
+
+static void test_bug57058()
+{
+ MYSQL_RES *res;
+ int rc;
+
+ DBUG_ENTER("test_bug57058");
+ myheader("test_bug57058");
+
+ rc= mysql_query(mysql, "set @@session.long_query_time=0.1");
+ myquery(rc);
+
+ DIE_UNLESS(!(mysql->server_status & SERVER_QUERY_WAS_SLOW));
+
+ rc= mysql_query(mysql, "select sleep(1)");
+ myquery(rc);
+
+ /*
+ Important: the flag is sent in the last EOF packet of
+ the query, the one which ends the result. Read the
+ result to see the "slow" status.
+ */
+ res= mysql_store_result(mysql);
+
+ DIE_UNLESS(mysql->server_status & SERVER_QUERY_WAS_SLOW);
+
+ mysql_free_result(res);
+
+ rc= mysql_query(mysql, "set @@session.long_query_time=default");
+ myquery(rc);
+
+ DBUG_VOID_RETURN;
+}
+
+
+/**
+ Bug#11766854: 60075: MYSQL_LOAD_CLIENT_PLUGIN DOESN'T CLEAR ERROR
+*/
+
+static void test_bug11766854()
+{
+ struct st_mysql_client_plugin *plugin;
+
+ DBUG_ENTER("test_bug11766854");
+ myheader("test_bug11766854");
+
+ plugin= mysql_load_plugin(mysql, "foo", -1, 0);
+ DIE_UNLESS(plugin == 0);
+
+ plugin= mysql_load_plugin(mysql, "qa_auth_client", -1, 0);
+ DIE_UNLESS(plugin != 0);
+ DIE_IF(mysql_errno(mysql));
+
+ DBUG_VOID_RETURN;
+}
+
+/**
+ Bug#12337762: 60075: MYSQL_LIST_FIELDS() RETURNS WRONG CHARSET FOR
+ CHAR/VARCHAR/TEXT COLUMNS IN VIEWS
+*/
+static void test_bug12337762()
+{
+ int rc,i=0;
+ MYSQL_RES *result;
+ MYSQL_FIELD *field;
+ unsigned int tab_charsetnr[3]= {0};
+
+ DBUG_ENTER("test_bug12337762");
+ myheader("test_bug12337762");
+
+ /*
+ Creating table with specific charset.
+ */
+ rc= mysql_query(mysql, "drop table if exists charset_tab");
+ rc= mysql_query(mysql, "create table charset_tab("\
+ "txt1 varchar(32) character set Latin1,"\
+ "txt2 varchar(32) character set Latin1 collate latin1_bin,"\
+ "txt3 varchar(32) character set utf8 collate utf8_bin"\
+ ")");
+
+ DIE_UNLESS(rc == 0);
+ DIE_IF(mysql_errno(mysql));
+
+ /*
+ Creating view from table created earlier.
+ */
+ rc= mysql_query(mysql, "drop view if exists charset_view");
+ rc= mysql_query(mysql, "create view charset_view as "\
+ "select * from charset_tab;");
+ DIE_UNLESS(rc == 0);
+ DIE_IF(mysql_errno(mysql));
+
+ /*
+ Checking field information for table.
+ */
+ result= mysql_list_fields(mysql, "charset_tab", NULL);
+ DIE_IF(mysql_errno(mysql));
+ i=0;
+ while((field= mysql_fetch_field(result)))
+ {
+ printf("field name %s\n", field->name);
+ printf("field table %s\n", field->table);
+ printf("field type %d\n", field->type);
+ printf("field charset %d\n", field->charsetnr);
+ tab_charsetnr[i++]= field->charsetnr;
+ printf("\n");
+ }
+ mysql_free_result(result);
+
+ /*
+ Checking field information for view.
+ */
+ result= mysql_list_fields(mysql, "charset_view", NULL);
+ DIE_IF(mysql_errno(mysql));
+ i=0;
+ while((field= mysql_fetch_field(result)))
+ {
+ printf("field name %s\n", field->name);
+ printf("field table %s\n", field->table);
+ printf("field type %d\n", field->type);
+ printf("field charset %d\n", field->charsetnr);
+ printf("\n");
+ /*
+ charset value for field must be same for both, view and table.
+ */
+ DIE_UNLESS(field->charsetnr == tab_charsetnr[i++]);
+ }
+ mysql_free_result(result);
+
+ DBUG_VOID_RETURN;
+}
+
+
+/*
+ BUG 11754979 - 46675: ON DUPLICATE KEY UPDATE AND UPDATECOUNT() POSSIBLY WRONG
+*/
+
+static void test_bug11754979()
+{
+ MYSQL* conn;
+ DBUG_ENTER("test_bug11754979");
+
+ myheader("test_bug11754979");
+ DIE_UNLESS((conn= mysql_client_init(NULL)));
+ DIE_UNLESS(mysql_real_connect(conn, opt_host, opt_user,
+ opt_password, opt_db ? opt_db:"test", opt_port,
+ opt_unix_socket, CLIENT_FOUND_ROWS));
+ myquery(mysql_query(conn, "DROP TABLE IF EXISTS t1"));
+ myquery(mysql_query(conn, "CREATE TABLE t1(id INT, label CHAR(1), PRIMARY KEY(id))"));
+ myquery(mysql_query(conn, "INSERT INTO t1(id, label) VALUES (1, 'a')"));
+ myquery(mysql_query(conn, "INSERT INTO t1(id, label) VALUES (1, 'a') "
+ "ON DUPLICATE KEY UPDATE id = 4"));
+ DIE_UNLESS(mysql_affected_rows(conn) == 2);
+ myquery(mysql_query(conn, "DROP TABLE t1"));
+ mysql_close(conn);
+
+ DBUG_VOID_RETURN;
+}
+
+
/*
Bug#13001491: MYSQL_REFRESH CRASHES WHEN STORED ROUTINES ARE RUN CONCURRENTLY.
*/
@@ -18650,6 +19825,12 @@ static struct my_option client_test_long_options[] =
{"getopt-ll-test", 'g', "Option for testing bug in getopt library",
&opt_getopt_ll_test, &opt_getopt_ll_test, 0,
GET_LL, REQUIRED_ARG, 0, 0, LONGLONG_MAX, 0, 0, 0},
+ {"plugin_dir", 0, "Directory for client-side plugins.",
+ &opt_plugin_dir, &opt_plugin_dir, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"default_auth", 0, "Default authentication client-side plugin to use.",
+ &opt_default_auth, &opt_default_auth, 0,
+ GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
@@ -18902,13 +20083,20 @@ static struct my_tests_st my_tests[]= {
{ "test_bug20023", test_bug20023 },
{ "test_bug45010", test_bug45010 },
{ "test_bug53371", test_bug53371 },
- { "test_bug53907", test_bug53907 },
{ "test_bug31418", test_bug31418 },
{ "test_bug31669", test_bug31669 },
{ "test_bug28386", test_bug28386 },
{ "test_wl4166_1", test_wl4166_1 },
{ "test_wl4166_2", test_wl4166_2 },
+ { "test_wl4166_3", test_wl4166_3 },
+ { "test_wl4166_4", test_wl4166_4 },
+ { "test_bug36004", test_bug36004 },
+ { "test_wl4284_1", test_wl4284_1 },
+ { "test_wl4435", test_wl4435 },
+ { "test_wl4435_2", test_wl4435_2 },
+ { "test_wl4435_3", test_wl4435_3 },
{ "test_bug38486", test_bug38486 },
+ { "test_bug33831", test_bug33831 },
{ "test_bug40365", test_bug40365 },
{ "test_bug43560", test_bug43560 },
#ifdef HAVE_QUERY_CACHE
@@ -18916,11 +20104,16 @@ static struct my_tests_st my_tests[]= {
#endif
{ "test_bug41078", test_bug41078 },
{ "test_bug44495", test_bug44495 },
+ { "test_bug49972", test_bug49972 },
{ "test_bug42373", test_bug42373 },
{ "test_bug54041", test_bug54041 },
{ "test_bug47485", test_bug47485 },
{ "test_bug58036", test_bug58036 },
+ { "test_bug57058", test_bug57058 },
{ "test_bug56976", test_bug56976 },
+ { "test_bug11766854", test_bug11766854 },
+ { "test_bug12337762", test_bug12337762 },
+ { "test_bug11754979", test_bug11754979 },
{ "test_bug13001491", test_bug13001491 },
{ 0, 0 }
};
@@ -18941,7 +20134,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
if (argument)
{
char *start=argument;
- my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(opt_password);
opt_password= my_strdup(argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
if (*start)
@@ -19037,7 +20230,9 @@ int main(int argc, char **argv)
MY_INIT(argv[0]);
- load_defaults("my", client_test_load_default_groups, &argc, &argv);
+ if (load_defaults("my", client_test_load_default_groups, &argc, &argv))
+ exit(1);
+
defaults_argv= argv;
get_options(&argc, &argv);
@@ -19058,29 +20253,29 @@ int main(int argc, char **argv)
if (!argc)
{
for (fptr= my_tests; fptr->name; fptr++)
- (*fptr->function)();
+ (*fptr->function)();
}
else
{
for ( ; *argv ; argv++)
{
- for (fptr= my_tests; fptr->name; fptr++)
- {
- if (!strcmp(fptr->name, *argv))
- {
- (*fptr->function)();
- break;
- }
- }
- if (!fptr->name)
- {
- fprintf(stderr, "\n\nGiven test not found: '%s'\n", *argv);
- fprintf(stderr, "See legal test names with %s -T\n\nAborting!\n",
- my_progname);
- client_disconnect(mysql, 1);
- free_defaults(defaults_argv);
- exit(1);
- }
+ for (fptr= my_tests; fptr->name; fptr++)
+ {
+ if (!strcmp(fptr->name, *argv))
+ {
+ (*fptr->function)();
+ break;
+ }
+ }
+ if (!fptr->name)
+ {
+ fprintf(stderr, "\n\nGiven test not found: '%s'\n", *argv);
+ fprintf(stderr, "See legal test names with %s -T\n\nAborting!\n",
+ my_progname);
+ client_disconnect(mysql, 1);
+ free_defaults(defaults_argv);
+ exit(1);
+ }
}
}
@@ -19096,7 +20291,7 @@ int main(int argc, char **argv)
print_test_output();
while (embedded_server_arg_count > 1)
- my_free(embedded_server_args[--embedded_server_arg_count],MYF(0));
+ my_free(embedded_server_args[--embedded_server_arg_count]);
mysql_server_end();
diff --git a/tests/thread_test.c b/tests/thread_test.c
index 8e1c58ebbec..5d79fb17c08 100644
--- a/tests/thread_test.c
+++ b/tests/thread_test.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -11,19 +11,10 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include <my_global.h>
-#ifndef THREAD
-
-int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
-{
- printf("This test must be compiled with multithread support to work\n");
- exit(1);
-}
-#else
-
#include <my_sys.h>
#include <my_pthread.h>
#include "mysql.h"
@@ -77,7 +68,7 @@ end:
mysql_close(mysql);
pthread_mutex_lock(&LOCK_thread_count);
thread_count--;
- VOID(pthread_cond_signal(&COND_thread_count)); /* Tell main we are ready */
+ pthread_cond_signal(&COND_thread_count); /* Tell main we are ready */
pthread_mutex_unlock(&LOCK_thread_count);
pthread_exit(0);
return 0;
@@ -88,36 +79,36 @@ static struct my_option my_long_options[] =
{
{"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0,
0, 0, 0, 0, 0},
- {"database", 'D', "Database to use", (uchar**) &database, (uchar**) &database,
+ {"database", 'D', "Database to use", &database, &database,
0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
- {"host", 'h', "Connect to host", (uchar**) &host, (uchar**) &host, 0, GET_STR,
+ {"host", 'h', "Connect to host", &host, &host, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p',
"Password to use when connecting to server. If password is not given it's asked from the tty.",
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
- {"user", 'u', "User for login if not current user", (uchar**) &user,
- (uchar**) &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"user", 'u', "User for login if not current user", &user,
+ &user, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"version", 'V', "Output version information and exit",
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
- {"verbose", 'v', "Write some progress indicators", (uchar**) &verbose,
- (uchar**) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
- {"query", 'Q', "Query to execute in each threads", (uchar**) &query,
- (uchar**) &query, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ {"verbose", 'v', "Write some progress indicators", &verbose,
+ &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"query", 'Q', "Query to execute in each threads", &query,
+ &query, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"port", 'P', "Port number to use for connection or 0 for default to, in "
"order of preference, my.cnf, $MYSQL_TCP_PORT, "
#if MYSQL_PORT_DEFAULT == 0
"/etc/services, "
#endif
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
- (uchar**) &tcp_port,
- (uchar**) &tcp_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0, 0},
- {"socket", 'S', "Socket file to use for connection", (uchar**) &unix_socket,
- (uchar**) &unix_socket, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
+ &tcp_port,
+ &tcp_port, 0, GET_UINT, REQUIRED_ARG, MYSQL_PORT, 0, 0, 0, 0, 0},
+ {"socket", 'S', "Socket file to use for connection", &unix_socket,
+ &unix_socket, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"test-count", 'c', "Run test count times (default %d)",
- (uchar**) &number_of_tests, (uchar**) &number_of_tests, 0, GET_UINT,
+ &number_of_tests, &number_of_tests, 0, GET_UINT,
REQUIRED_ARG, 1000, 0, 0, 0, 0, 0},
{"thread-count", 't', "Number of threads to start",
- (uchar**) &number_of_threads, (uchar**) &number_of_threads, 0, GET_UINT,
+ &number_of_threads, &number_of_threads, 0, GET_UINT,
REQUIRED_ARG, 2, 0, 0, 0, 0, 0},
{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
@@ -150,7 +141,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
case 'p':
if (argument)
{
- my_free(password, MYF(MY_ALLOW_ZERO_PTR));
+ my_free(password);
password= my_strdup(argument, MYF(MY_FAE));
while (*argument) *argument++= 'x'; /* Destroy argument */
}
@@ -176,9 +167,8 @@ static void get_options(int argc, char **argv)
{
int ho_error;
- load_defaults("my",load_default_groups,&argc,&argv);
-
- if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option)))
+ if ((ho_error= load_defaults("my",load_default_groups,&argc,&argv)) ||
+ (ho_error= handle_options(&argc, &argv, my_long_options, get_one_option)))
exit(ho_error);
free_defaults(argv);
@@ -255,4 +245,3 @@ int main(int argc, char **argv)
return 0; /* Keep some compilers happy */
}
-#endif /* THREAD */