summaryrefslogtreecommitdiff
path: root/tests/client_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/client_test.c')
-rw-r--r--tests/client_test.c148
1 files changed, 131 insertions, 17 deletions
diff --git a/tests/client_test.c b/tests/client_test.c
index 25dcb951d3a..1a6b9525f87 100644
--- a/tests/client_test.c
+++ b/tests/client_test.c
@@ -705,10 +705,8 @@ static void verify_prepare_field(MYSQL_RES *result,
as utf8. Field length is calculated as number of characters * maximum
number of bytes a character can occupy.
*/
-#ifndef EMBEDDED_LIBRARY
if (length)
DIE_UNLESS(field->length == length * cs->mbmaxlen);
-#endif
if (def)
DIE_UNLESS(strcmp(field->def, def) == 0);
}
@@ -1261,6 +1259,56 @@ static void test_tran_innodb()
}
+/* Test for BUG#7242 */
+
+static void test_prepare_insert_update()
+{
+ MYSQL_STMT *stmt;
+ int rc;
+ int i;
+ const char *testcase[]= {
+ "CREATE TABLE t1 (a INT, b INT, c INT, UNIQUE (A), UNIQUE(B))",
+ "INSERT t1 VALUES (1,2,10), (3,4,20)",
+ "INSERT t1 VALUES (5,6,30), (7,4,40), (8,9,60) ON DUPLICATE KEY UPDATE c=c+100",
+ "SELECT * FROM t1",
+ "INSERT t1 SET a=5 ON DUPLICATE KEY UPDATE b=0",
+ "SELECT * FROM t1",
+ "INSERT t1 VALUES (2,1,11), (7,4,40) ON DUPLICATE KEY UPDATE c=c+VALUES(a)",
+ NULL};
+ const char **cur_query;
+
+ myheader("test_prepare_insert_update");
+
+ for (cur_query= testcase; *cur_query; cur_query++)
+ {
+ printf("\nRunning query: %s", *cur_query);
+ strmov(query, *cur_query);
+ stmt= mysql_simple_prepare(mysql, query);
+ check_stmt(stmt);
+
+ verify_param_count(stmt, 0);
+ rc= mysql_stmt_execute(stmt);
+
+ check_execute(stmt, rc);
+ /* try the last query several times */
+ if (!cur_query[1])
+ {
+ for (i=0; i < 3;i++)
+ {
+ printf("\nExecuting last statement again");
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+ }
+ }
+ mysql_stmt_close(stmt);
+ }
+
+ rc= mysql_commit(mysql);
+ myquery(rc);
+}
+
/* Test simple prepares of all DML statements */
static void test_prepare_simple()
@@ -1286,7 +1334,8 @@ static void test_prepare_simple()
mysql_stmt_close(stmt);
/* update */
- strmov(query, "UPDATE test_prepare_simple SET id=? WHERE id=? AND name= ?");
+ strmov(query, "UPDATE test_prepare_simple SET id=? "
+ "WHERE id=? AND CONVERT(name USING utf8)= ?");
stmt= mysql_simple_prepare(mysql, query);
check_stmt(stmt);
@@ -1314,7 +1363,8 @@ static void test_prepare_simple()
mysql_stmt_close(stmt);
/* select */
- strmov(query, "SELECT * FROM test_prepare_simple WHERE id=? AND name= ?");
+ strmov(query, "SELECT * FROM test_prepare_simple WHERE id=? "
+ "AND CONVERT(name USING utf8)= ?");
stmt= mysql_simple_prepare(mysql, query);
check_stmt(stmt);
@@ -1343,7 +1393,7 @@ static void test_prepare_field_result()
rc= mysql_query(mysql, "CREATE TABLE test_prepare_field_result(int_c int, "
"var_c varchar(50), ts_c timestamp(14), "
- "char_c char(3), date_c date, extra tinyint)");
+ "char_c char(4), date_c date, extra tinyint)");
myquery(rc);
/* insert */
@@ -1369,8 +1419,8 @@ static void test_prepare_field_result()
"t1", "test_prepare_field_result", current_db, 10, 0);
verify_prepare_field(result, 3, "ts_c", "ts_c", MYSQL_TYPE_TIMESTAMP,
"t1", "test_prepare_field_result", current_db, 19, 0);
- verify_prepare_field(result, 4, "char_c", "char_c", MYSQL_TYPE_STRING,
- "t1", "test_prepare_field_result", current_db, 3, 0);
+ verify_prepare_field(result, 4, "char_c", "char_c", MYSQL_TYPE_VAR_STRING,
+ "t1", "test_prepare_field_result", current_db, 4, 0);
verify_field_count(result, 5);
mysql_free_result(result);
@@ -2106,7 +2156,8 @@ static void test_select()
rc= mysql_commit(mysql);
myquery(rc);
- strmov(query, "SELECT * FROM test_select WHERE id= ? AND name=?");
+ strmov(query, "SELECT * FROM test_select WHERE id= ? "
+ "AND CONVERT(name USING utf8) =?");
stmt= mysql_simple_prepare(mysql, query);
check_stmt(stmt);
@@ -2166,7 +2217,8 @@ static void test_ps_conj_select()
"(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')");
myquery(rc);
- strmov(query, "select id1, value1 from t1 where id1= ? or value1= ?");
+ strmov(query, "select id1, value1 from t1 where id1= ? or "
+ "CONVERT(value1 USING utf8)= ?");
stmt= mysql_simple_prepare(mysql, query);
check_stmt(stmt);
@@ -2245,7 +2297,8 @@ session_id char(9) NOT NULL, \
"(\"abx\", 1, 2, 3, 2003-08-30)");
myquery(rc);
- strmov(query, "SELECT * FROM test_select WHERE session_id= ?");
+ strmov(query, "SELECT * FROM test_select WHERE "
+ "CONVERT(session_id USING utf8)= ?");
stmt= mysql_simple_prepare(mysql, query);
check_stmt(stmt);
@@ -3085,7 +3138,8 @@ static void test_simple_delete()
myquery(rc);
/* insert by prepare */
- strmov(query, "DELETE FROM test_simple_delete WHERE col1= ? AND col2= ? AND col3= 100");
+ strmov(query, "DELETE FROM test_simple_delete WHERE col1= ? AND "
+ "CONVERT(col2 USING utf8)= ? AND col3= 100");
stmt= mysql_simple_prepare(mysql, query);
check_stmt(stmt);
@@ -5064,7 +5118,8 @@ static void test_multi_stmt()
/* alter the table schema now */
stmt1= mysql_simple_prepare(mysql, "DELETE FROM test_multi_table "
- "WHERE id= ? AND name=?");
+ "WHERE id= ? AND "
+ "CONVERT(name USING utf8)=?");
check_stmt(stmt1);
verify_param_count(stmt1, 2);
@@ -5831,9 +5886,6 @@ static void test_subselect()
rc= mysql_stmt_bind_param(stmt, bind);
check_execute(stmt, rc);
- rc= mysql_stmt_bind_result(stmt, bind);
- check_execute(stmt, rc);
-
id= 2;
rc= mysql_stmt_execute(stmt);
check_execute(stmt, rc);
@@ -6172,7 +6224,7 @@ static void test_pure_coverage()
check_execute(stmt, rc);
rc= mysql_stmt_bind_result(stmt, (MYSQL_BIND*)0);
- check_execute(stmt, rc);
+ DIE_UNLESS(rc == 1);
mysql_stmt_close(stmt);
@@ -6828,7 +6880,7 @@ static void test_field_misc()
mysql_get_server_version(mysql) <= 50000 ?
MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING,
"", "", /* table and its org name */
- "", type_length*3, 0); /* db name, length */
+ "", type_length, 0); /* db name, length */
mysql_free_result(result);
mysql_stmt_close(stmt);
@@ -12059,6 +12111,66 @@ static void test_conversion()
myquery(rc);
}
+static void test_rewind(void)
+{
+ MYSQL_STMT *stmt;
+ MYSQL_BIND bind;
+ int rc = 0;
+ const char *stmt_text;
+ long unsigned int length=4, Data=0;
+ my_bool isnull=0;
+
+ myheader("test_rewind");
+
+ stmt_text= "CREATE TABLE t1 (a int)";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+ stmt_text= "INSERT INTO t1 VALUES(2),(3),(4)";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+
+ stmt= mysql_stmt_init(mysql);
+
+ stmt_text= "SELECT * FROM t1";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+
+ bzero(&bind,sizeof(MYSQL_BIND));
+ bind.buffer_type= MYSQL_TYPE_LONG;
+ bind.buffer= (void *)&Data; /* this buffer won't be altered */
+ bind.length= &length;
+ bind.is_null= &isnull;
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_store_result(stmt);
+ DIE_UNLESS(rc == 0);
+
+ rc= mysql_stmt_bind_result(stmt, &bind);
+ DIE_UNLESS(rc == 0);
+
+ /* retreive all result sets till we are at the end */
+ while(!mysql_stmt_fetch(stmt))
+ printf("fetched result:%ld\n", Data);
+
+ DIE_UNLESS(rc != MYSQL_NO_DATA);
+
+ /* seek to the first row */
+ mysql_stmt_data_seek(stmt, 0);
+
+ /* now we should be able to fetch the results again */
+ /* but mysql_stmt_fetch returns MYSQL_NO_DATA */
+ while(!(rc= mysql_stmt_fetch(stmt)))
+ printf("fetched result after seek:%ld\n", Data);
+
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+
+ stmt_text= "DROP TABLE t1";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+ rc= mysql_stmt_free_result(stmt);
+ rc= mysql_stmt_close(stmt);
static void test_truncation()
{
@@ -12415,6 +12527,7 @@ and you are welcome to modify and redistribute it under the GPL license\n");
static struct my_tests_st my_tests[]= {
{ "client_query", client_query },
+ { "test_prepare_insert_update", test_prepare_insert_update},
#if NOT_YET_WORKING
{ "test_drop_temp", test_drop_temp },
#endif
@@ -12557,6 +12670,7 @@ static struct my_tests_st my_tests[]= {
{ "test_datetime_ranges", test_datetime_ranges },
{ "test_bug4172", test_bug4172 },
{ "test_conversion", test_conversion },
+ { "test_rewind", test_rewind },
{ "test_view", test_view },
{ "test_view_where", test_view_where },
{ "test_view_2where", test_view_2where },