summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rwxr-xr-xtests/CMakeLists.txt11
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/bug25714.c71
-rw-r--r--tests/mysql_client_test.c325
4 files changed, 397 insertions, 15 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 5eade93621b..2093fc0da36 100755
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -13,12 +13,15 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
-SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
+# 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)
-TARGET_LINK_LIBRARIES(mysql_client_test dbug mysys mysqlclient yassl taocrypt zlib wsock32)
+ADD_EXECUTABLE(mysql_client_test mysql_client_test.c ../mysys/my_memmem.c)
+TARGET_LINK_LIBRARIES(mysql_client_test mysqlclient_notls wsock32)
+
+ADD_EXECUTABLE(bug25714 bug25714.c)
+TARGET_LINK_LIBRARIES(bug25714 mysqlclient_notls wsock32)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index bd56570d8d4..1c39a3630dd 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -28,7 +28,7 @@ EXTRA_DIST = auto_increment.res auto_increment.tst \
CMakeLists.txt
bin_PROGRAMS = mysql_client_test
-noinst_PROGRAMS = insert_test select_test thread_test
+noinst_PROGRAMS = insert_test select_test thread_test bug25714
INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \
$(openssl_includes)
@@ -45,6 +45,9 @@ 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 = -DUNDEF_THREADS_HACK
diff --git a/tests/bug25714.c b/tests/bug25714.c
new file mode 100644
index 00000000000..e9b2be44209
--- /dev/null
+++ b/tests/bug25714.c
@@ -0,0 +1,71 @@
+/* Copyright (C) 2007 MySQL AB
+
+ 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
+ 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 General Public License for more details.
+
+ 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 */
+
+#include <my_global.h>
+#include <my_sys.h>
+#include <mysql.h>
+#include <m_string.h>
+#include <assert.h>
+
+int main (int argc, char **argv)
+{
+ MYSQL conn;
+ int OK;
+
+ const char* query4= "INSERT INTO federated.t1 SET Value=54";
+ const char* query5= "INSERT INTO federated.t1 SET Value=55";
+
+ MY_INIT(argv[0]);
+
+ if (argc != 2)
+ return -1;
+
+ mysql_init(&conn);
+ if (!mysql_real_connect(
+ &conn,
+ "127.0.0.1",
+ "root",
+ "",
+ "test",
+ atoi(argv[1]),
+ NULL,
+ CLIENT_FOUND_ROWS))
+ {
+ fprintf(stderr, "Failed to connect to database: Error: %s\n",
+ mysql_error(&conn));
+ return 1;
+ } else {
+ printf("%s\n", mysql_error(&conn));
+ }
+
+ OK = mysql_real_query (&conn, query4, strlen(query4));
+
+ assert(0 == OK);
+
+ printf("%ld inserted\n",
+ (long) mysql_insert_id(&conn));
+
+ OK = mysql_real_query (&conn, query5, strlen(query5));
+
+ assert(0 == OK);
+
+ printf("%ld inserted\n",
+ (long) mysql_insert_id(&conn));
+
+ mysql_close(&conn);
+ my_end(0);
+
+ return 0;
+};
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 3e50e1ede84..b9f39021114 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -85,7 +85,7 @@ struct my_tests_st
if (opt_silent < 2) \
{ \
fprintf(stdout, "\n\n#####################################\n"); \
- fprintf(stdout, "%d of (%d/%d): %s", test_count++, iter_count, \
+ fprintf(stdout, "%u of (%u/%u): %s", test_count++, iter_count, \
opt_count, str); \
fprintf(stdout, " \n#####################################\n"); \
}
@@ -99,7 +99,7 @@ if (!opt_silent) \
static void print_error(const char *msg);
static void print_st_error(MYSQL_STMT *stmt, const char *msg);
-static void client_disconnect();
+static void client_disconnect(void);
/*
@@ -118,7 +118,7 @@ static void client_disconnect();
#define DIE(expr) \
die(__FILE__, __LINE__, #expr)
-void die(const char *file, int line, const char *expr)
+static void die(const char *file, int line, const char *expr)
{
fflush(stdout);
fprintf(stderr, "%s:%d: check failed: '%s'\n", file, line, expr);
@@ -252,7 +252,7 @@ static my_bool check_have_innodb(MYSQL *conn)
mysql_simple_prepare(): a variant without the 'length' parameter.
*/
-MYSQL_STMT *STDCALL
+static MYSQL_STMT *STDCALL
mysql_simple_prepare(MYSQL *mysql_arg, const char *query)
{
MYSQL_STMT *stmt= mysql_stmt_init(mysql_arg);
@@ -467,7 +467,7 @@ static void my_print_result_metadata(MYSQL_RES *result)
/* Process the result set */
-int my_process_result_set(MYSQL_RES *result)
+static int my_process_result_set(MYSQL_RES *result)
{
MYSQL_ROW row;
MYSQL_FIELD *field;
@@ -523,7 +523,7 @@ int my_process_result_set(MYSQL_RES *result)
}
-int my_process_result(MYSQL *mysql_arg)
+static int my_process_result(MYSQL *mysql_arg)
{
MYSQL_RES *result;
int row_count;
@@ -543,7 +543,7 @@ int my_process_result(MYSQL *mysql_arg)
#define MAX_RES_FIELDS 50
#define MAX_FIELD_DATA_SIZE 255
-int my_process_stmt_result(MYSQL_STMT *stmt)
+static int my_process_stmt_result(MYSQL_STMT *stmt)
{
int field_count;
int row_count= 0;
@@ -7564,7 +7564,9 @@ static void test_explain_bug()
else
{
verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_VAR_STRING, "",
- "", "", NAME_LEN*MAX_KEY, 0);
+ "", "",
+ NAME_LEN*MAX_KEY / my_charset_utf8_general_ci.mbmaxlen,
+ 0);
}
verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_VAR_STRING,
@@ -8785,7 +8787,9 @@ static void test_ts()
int rc, field_count;
char name;
char query[MAX_TEST_QUERY_LENGTH];
-
+ const char *queries [3]= {"SELECT a, b, c FROM test_ts WHERE %c=?",
+ "SELECT a, b, c FROM test_ts WHERE %c=?",
+ "SELECT a, b, c FROM test_ts WHERE %c=CAST(? AS DATE)"};
myheader("test_ts");
rc= mysql_query(mysql, "DROP TABLE IF EXISTS test_ts");
@@ -8857,7 +8861,7 @@ static void test_ts()
{
int row_count= 0;
- sprintf(query, "SELECT a, b, c FROM test_ts WHERE %c=?", name);
+ sprintf(query, queries[field_count], name);
if (!opt_silent)
fprintf(stdout, "\n %s", query);
@@ -15566,6 +15570,301 @@ static void test_bug24179()
/*
+ Bug#27876 (SF with cyrillic variable name fails during execution (regression))
+*/
+static void test_bug27876()
+{
+ int rc;
+ MYSQL_RES *result;
+
+ unsigned char utf8_func[] =
+ {
+ 0xd1, 0x84, 0xd1, 0x83, 0xd0, 0xbd, 0xd0, 0xba,
+ 0xd1, 0x86, 0xd0, 0xb8, 0xd0, 0xb9, 0xd0, 0xba,
+ 0xd0, 0xb0,
+ 0x00
+ };
+
+ unsigned char utf8_param[] =
+ {
+ 0xd0, 0xbf, 0xd0, 0xb0, 0xd1, 0x80, 0xd0, 0xb0,
+ 0xd0, 0xbc, 0xd0, 0xb5, 0xd1, 0x82, 0xd1, 0x8a,
+ 0xd1, 0x80, 0x5f, 0xd0, 0xb2, 0xd0, 0xb5, 0xd1,
+ 0x80, 0xd1, 0x81, 0xd0, 0xb8, 0xd1, 0x8f,
+ 0x00
+ };
+
+ char query[500];
+
+ DBUG_ENTER("test_bug27876");
+ myheader("test_bug27876");
+
+ rc= mysql_query(mysql, "set names utf8");
+ myquery(rc);
+
+ rc= mysql_query(mysql, "select version()");
+ myquery(rc);
+ result= mysql_store_result(mysql);
+ mytest(result);
+
+ sprintf(query, "DROP FUNCTION IF EXISTS %s", utf8_func);
+ rc= mysql_query(mysql, query);
+ myquery(rc);
+
+ sprintf(query,
+ "CREATE FUNCTION %s( %s VARCHAR(25))"
+ " RETURNS VARCHAR(25) DETERMINISTIC RETURN %s",
+ utf8_func, utf8_param, utf8_param);
+ rc= mysql_query(mysql, query);
+ myquery(rc);
+ sprintf(query, "SELECT %s(VERSION())", utf8_func);
+ rc= mysql_query(mysql, query);
+ myquery(rc);
+ result= mysql_store_result(mysql);
+ mytest(result);
+
+ sprintf(query, "DROP FUNCTION %s", utf8_func);
+ rc= mysql_query(mysql, query);
+ myquery(rc);
+
+ rc= mysql_query(mysql, "set names default");
+ myquery(rc);
+}
+
+
+/*
+ Bug#28505: mysql_affected_rows() returns wrong value if CLIENT_FOUND_ROWS
+ flag is set.
+*/
+
+static void test_bug28505()
+{
+ my_ulonglong res;
+
+ myquery(mysql_query(mysql, "drop table if exists t1"));
+ myquery(mysql_query(mysql, "create table t1(f1 int primary key)"));
+ myquery(mysql_query(mysql, "insert into t1 values(1)"));
+ myquery(mysql_query(mysql,
+ "insert into t1 values(1) on duplicate key update f1=1"));
+ res= mysql_affected_rows(mysql);
+ DIE_UNLESS(!res);
+ myquery(mysql_query(mysql, "drop table t1"));
+}
+
+
+/*
+ Bug#28934: server crash when receiving malformed com_execute packets
+*/
+
+static void test_bug28934()
+{
+ my_bool error= 0;
+ MYSQL_BIND bind[5];
+ MYSQL_STMT *stmt;
+ int cnt;
+
+ myquery(mysql_query(mysql, "drop table if exists t1"));
+ myquery(mysql_query(mysql, "create table t1(id int)"));
+
+ myquery(mysql_query(mysql, "insert into t1 values(1),(2),(3),(4),(5)"));
+ stmt= mysql_simple_prepare(mysql,"select * from t1 where id in(?,?,?,?,?)");
+ check_stmt(stmt);
+
+ memset (&bind, 0, sizeof (bind));
+ for (cnt= 0; cnt < 5; cnt++)
+ {
+ bind[cnt].buffer_type= MYSQL_TYPE_LONG;
+ bind[cnt].buffer= (char*)&cnt;
+ bind[cnt].buffer_length= 0;
+ }
+ myquery(mysql_stmt_bind_param(stmt, bind));
+
+ stmt->param_count=2;
+ error= mysql_stmt_execute(stmt);
+ DIE_UNLESS(error != 0);
+ myerror(NULL);
+ mysql_stmt_close(stmt);
+
+ myquery(mysql_query(mysql, "drop table t1"));
+}
+
+
+/*
+ Bug#27592 (stack overrun when storing datetime value using prepared statements)
+*/
+
+static void test_bug27592()
+{
+ const int NUM_ITERATIONS= 40;
+ int i;
+ int rc;
+ MYSQL_STMT *stmt= NULL;
+ MYSQL_BIND bind[1];
+ MYSQL_TIME time_val;
+
+ DBUG_ENTER("test_bug27592");
+ myheader("test_bug27592");
+
+ mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+ mysql_query(mysql, "CREATE TABLE t1(c2 DATETIME)");
+
+ stmt= mysql_simple_prepare(mysql, "INSERT INTO t1 VALUES (?)");
+ DIE_UNLESS(stmt);
+
+ memset(bind, 0, sizeof(bind));
+
+ bind[0].buffer_type= MYSQL_TYPE_DATETIME;
+ bind[0].buffer= (char *) &time_val;
+ bind[0].length= NULL;
+
+ for (i= 0; i < NUM_ITERATIONS; i++)
+ {
+ time_val.year= 2007;
+ time_val.month= 6;
+ time_val.day= 7;
+ time_val.hour= 18;
+ time_val.minute= 41;
+ time_val.second= 3;
+
+ time_val.second_part=0;
+ time_val.neg=0;
+
+ rc= mysql_stmt_bind_param(stmt, bind);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ }
+
+ mysql_stmt_close(stmt);
+
+ DBUG_VOID_RETURN;
+}
+
+
+static void test_bug29948()
+{
+ MYSQL *dbc=NULL;
+ MYSQL_STMT *stmt=NULL;
+ MYSQL_BIND bind;
+
+ int res=0;
+ my_bool auto_reconnect=1, error=0, is_null=0;
+ char kill_buf[20];
+ const char *query;
+ int buf;
+ unsigned long length, cursor_type;
+
+ dbc = mysql_init(NULL);
+ DIE_UNLESS(dbc);
+
+ mysql_options(dbc, MYSQL_OPT_RECONNECT, (char*)&auto_reconnect);
+ if (!mysql_real_connect(dbc, opt_host, opt_user,
+ opt_password, current_db, opt_port,
+ opt_unix_socket,
+ (CLIENT_FOUND_ROWS | CLIENT_MULTI_STATEMENTS |
+ CLIENT_MULTI_RESULTS)))
+ {
+ printf("connection failed: %s (%d)", mysql_error(dbc),
+ mysql_errno(dbc));
+ exit(1);
+ }
+
+ bind.buffer_type= MYSQL_TYPE_LONG;
+ bind.buffer= (char *)&buf;
+ bind.is_null= &is_null;
+ bind.error= &error;
+ bind.length= &length;
+
+ res= mysql_query(dbc, "DROP TABLE IF EXISTS t1");
+ myquery(res);
+ res= mysql_query(dbc, "CREATE TABLE t1 (a INT)");
+ myquery(res);
+ res= mysql_query(dbc, "INSERT INTO t1 VALUES(1)");
+ myquery(res);
+
+ stmt= mysql_stmt_init(dbc);
+ check_stmt(stmt);
+
+ cursor_type= CURSOR_TYPE_READ_ONLY;
+ res= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void *)&cursor_type);
+ myquery(res);
+
+ query= "SELECT * from t1 where a=?";
+ res= mysql_stmt_prepare(stmt, query, strlen(query));
+ myquery(res);
+
+ res= mysql_stmt_bind_param(stmt, &bind);
+ myquery(res);
+
+ res= mysql_stmt_execute(stmt);
+ check_execute(stmt, res);
+
+ res= mysql_stmt_bind_result(stmt,&bind);
+ check_execute(stmt, res);
+
+ sprintf(kill_buf, "kill %ld", dbc->thread_id);
+ mysql_query(dbc, kill_buf);
+
+ res= mysql_stmt_store_result(stmt);
+ DIE_UNLESS(res);
+
+ mysql_stmt_free_result(stmt);
+ mysql_stmt_close(stmt);
+ mysql_query(dbc, "DROP TABLE t1");
+ mysql_close(dbc);
+}
+
+/**
+ Bug#29306 Truncated data in MS Access with decimal (3,1) columns in a VIEW
+*/
+
+static void test_bug29306()
+{
+ MYSQL_FIELD *field;
+ int rc;
+ MYSQL_RES *res;
+
+ DBUG_ENTER("test_bug29306");
+ myheader("test_bug29306");
+
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS tab17557");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP VIEW IF EXISTS view17557");
+ myquery(rc);
+ rc= mysql_query(mysql, "CREATE TABLE tab17557 (dd decimal (3,1))");
+ myquery(rc);
+ rc= mysql_query(mysql, "CREATE VIEW view17557 as SELECT dd FROM tab17557");
+ myquery(rc);
+ rc= mysql_query(mysql, "INSERT INTO tab17557 VALUES (7.6)");
+ myquery(rc);
+
+ /* Checking the view */
+ res= mysql_list_fields(mysql, "view17557", NULL);
+ while ((field= mysql_fetch_field(res)))
+ {
+ if (! opt_silent)
+ {
+ printf("field name %s\n", field->name);
+ printf("field table %s\n", field->table);
+ printf("field decimals %d\n", field->decimals);
+ if (field->decimals < 1)
+ printf("Error! No decimals! \n");
+ printf("\n\n");
+ }
+ DIE_UNLESS(field->decimals == 1);
+ }
+ mysql_free_result(res);
+
+ rc= mysql_query(mysql, "DROP TABLE tab17557");
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP VIEW view17557");
+ myquery(rc);
+
+ DBUG_VOID_RETURN;
+}
+
+/*
Read and parse arguments and MySQL options from my.cnf
*/
@@ -15845,6 +16144,12 @@ static struct my_tests_st my_tests[]= {
{ "test_bug23383", test_bug23383 },
{ "test_bug21635", test_bug21635 },
{ "test_bug24179", test_bug24179 },
+ { "test_bug27876", test_bug27876 },
+ { "test_bug28505", test_bug28505 },
+ { "test_bug28934", test_bug28934 },
+ { "test_bug27592", test_bug27592 },
+ { "test_bug29948", test_bug29948 },
+ { "test_bug29306", test_bug29306 },
{ 0, 0 }
};