summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKristofer Pettersson <kristofer.pettersson@sun.com>2009-03-06 11:49:39 +0100
committerKristofer Pettersson <kristofer.pettersson@sun.com>2009-03-06 11:49:39 +0100
commit55c779cdbf0e402338bb32253a2fc1db7fa02129 (patch)
treea2136f93bb28c0e655cf133c9245ead5bf039ae9 /tests
parentac821c65701d38ced2d3167cf9c54559599d4f52 (diff)
parentb4fdb8aec14b533db4a5ea2f99c1a9f3ce07946c (diff)
downloadmariadb-git-55c779cdbf0e402338bb32253a2fc1db7fa02129.tar.gz
Manual merge
Diffstat (limited to 'tests')
-rw-r--r--tests/mysql_client_test.c278
1 files changed, 272 insertions, 6 deletions
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 4b23fa23511..32c39b149d4 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -716,6 +716,7 @@ static void do_verify_prepare_field(MYSQL_RES *result,
{
MYSQL_FIELD *field;
CHARSET_INFO *cs;
+ ulonglong expected_field_length;
if (!(field= mysql_fetch_field_direct(result, no)))
{
@@ -724,6 +725,8 @@ static void do_verify_prepare_field(MYSQL_RES *result,
}
cs= get_charset(field->charsetnr, 0);
DIE_UNLESS(cs);
+ if ((expected_field_length= length * cs->mbmaxlen) > UINT_MAX32)
+ expected_field_length= UINT_MAX32;
if (!opt_silent)
{
fprintf(stdout, "\n field[%d]:", no);
@@ -738,8 +741,8 @@ static void do_verify_prepare_field(MYSQL_RES *result,
fprintf(stdout, "\n org_table:`%s`\t(expected: `%s`)",
field->org_table, org_table);
fprintf(stdout, "\n database :`%s`\t(expected: `%s`)", field->db, db);
- fprintf(stdout, "\n length :`%lu`\t(expected: `%lu`)",
- field->length, length * cs->mbmaxlen);
+ fprintf(stdout, "\n length :`%lu`\t(expected: `%llu`)",
+ field->length, expected_field_length);
fprintf(stdout, "\n maxlength:`%ld`", field->max_length);
fprintf(stdout, "\n charsetnr:`%d`", field->charsetnr);
fprintf(stdout, "\n default :`%s`\t(expected: `%s`)",
@@ -775,11 +778,11 @@ static void do_verify_prepare_field(MYSQL_RES *result,
as utf8. Field length is calculated as number of characters * maximum
number of bytes a character can occupy.
*/
- if (length && field->length != length * cs->mbmaxlen)
+ if (length && (field->length != expected_field_length))
{
- fprintf(stderr, "Expected field length: %d, got length: %d\n",
- (int) (length * cs->mbmaxlen), (int) field->length);
- DIE_UNLESS(field->length == length * cs->mbmaxlen);
+ fprintf(stderr, "Expected field length: %llu, got length: %lu\n",
+ expected_field_length, field->length);
+ DIE_UNLESS(field->length == expected_field_length);
}
if (def)
DIE_UNLESS(strcmp(field->def, def) == 0);
@@ -15901,6 +15904,61 @@ static void test_bug28934()
}
+#ifdef HAVE_SPATIAL
+/**
+ Bug#37956 memory leak and / or crash with geometry and prepared statements!
+*/
+
+static void test_bug37956(void)
+{
+ const char *query="select point(?,?)";
+ MYSQL_STMT *stmt=NULL;
+ ulong val=0;
+ MYSQL_BIND bind_param[2];
+ unsigned char buff[2]= { 134, 211 };
+ DBUG_ENTER("test_bug37956");
+ myheader("test_bug37956");
+
+ stmt= mysql_simple_prepare(mysql, query);
+ check_stmt(stmt);
+
+ val=1;
+ mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void *)&val);
+ val=CURSOR_TYPE_READ_ONLY;
+ mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, (void *)&val);
+ val=0;
+ mysql_stmt_attr_set(stmt, STMT_ATTR_PREFETCH_ROWS, (void *)&val);
+
+ memset(bind_param, 0, sizeof(bind_param));
+ bind_param[0].buffer_type=MYSQL_TYPE_TINY;
+ bind_param[0].buffer= (void *)buff;
+ bind_param[0].is_null=NULL;
+ bind_param[0].error=NULL;
+ bind_param[0].is_unsigned=1;
+ bind_param[1].buffer_type=MYSQL_TYPE_TINY;
+ bind_param[1].buffer= (void *)(buff+1);
+ bind_param[1].is_null=NULL;
+ bind_param[1].error=NULL;
+ bind_param[1].is_unsigned=1;
+
+ if (mysql_stmt_bind_param(stmt, bind_param))
+ {
+ mysql_stmt_close(stmt);
+ DIE_UNLESS(0);
+ }
+
+ if (mysql_stmt_execute(stmt))
+ {
+ mysql_stmt_close(stmt);
+ DBUG_VOID_RETURN;
+ }
+ /* Should never reach here: execution returns an error. */
+ mysql_stmt_close(stmt);
+ DIE_UNLESS(0);
+ DBUG_VOID_RETURN;
+}
+#endif
+
/*
Bug#27592 (stack overrun when storing datetime value using prepared statements)
*/
@@ -16390,6 +16448,206 @@ static void test_bug20023()
mysql_close(&con);
}
+static void test_bug40365(void)
+{
+ uint rc, i;
+ MYSQL_STMT *stmt= 0;
+ MYSQL_BIND my_bind[2];
+ my_bool is_null[2]= {0};
+ MYSQL_TIME tm[2];
+
+ DBUG_ENTER("test_bug40365");
+
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+ myquery(rc);
+ rc= mysql_query(mysql, "CREATE TABLE t1(c1 DATETIME, \
+ c2 DATE)");
+ myquery(rc);
+
+ stmt= mysql_simple_prepare(mysql, "INSERT INTO t1 VALUES(?, ?)");
+ check_stmt(stmt);
+ verify_param_count(stmt, 2);
+
+ bzero((char*) my_bind, sizeof(my_bind));
+ my_bind[0].buffer_type= MYSQL_TYPE_DATETIME;
+ my_bind[1].buffer_type= MYSQL_TYPE_DATE;
+ for (i= 0; i < (int) array_elements(my_bind); i++)
+ {
+ my_bind[i].buffer= (void *) &tm[i];
+ my_bind[i].is_null= &is_null[i];
+ }
+
+ rc= mysql_stmt_bind_param(stmt, my_bind);
+ check_execute(stmt, rc);
+
+ for (i= 0; i < (int) array_elements(my_bind); i++)
+ {
+ tm[i].neg= 0;
+ tm[i].second_part= 0;
+ tm[i].year= 2009;
+ tm[i].month= 2;
+ tm[i].day= 29;
+ tm[i].hour= 0;
+ tm[i].minute= 0;
+ tm[i].second= 0;
+ }
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ rc= mysql_commit(mysql);
+ myquery(rc);
+ mysql_stmt_close(stmt);
+
+ stmt= mysql_simple_prepare(mysql, "SELECT * FROM t1");
+ check_stmt(stmt);
+
+ rc= mysql_stmt_bind_result(stmt, my_bind);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_store_result(stmt);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+
+ if (!opt_silent)
+ fprintf(stdout, "\n");
+
+ for (i= 0; i < array_elements(my_bind); i++)
+ {
+ if (!opt_silent)
+ fprintf(stdout, "\ntime[%d]: %02d-%02d-%02d ",
+ i, tm[i].year, tm[i].month, tm[i].day);
+ DIE_UNLESS(tm[i].year == 0);
+ DIE_UNLESS(tm[i].month == 0);
+ DIE_UNLESS(tm[i].day == 0);
+ }
+ mysql_stmt_close(stmt);
+
+ DBUG_VOID_RETURN;
+}
+
+
+/**
+ Bug#36326: nested transaction and select
+*/
+
+#ifdef HAVE_QUERY_CACHE
+
+static void test_bug36326()
+{
+ int rc;
+
+ DBUG_ENTER("test_bug36326");
+ myheader("test_bug36326");
+
+ rc= mysql_autocommit(mysql, TRUE);
+ myquery(rc);
+ rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1");
+ myquery(rc);
+ rc= mysql_query(mysql, "CREATE TABLE t1 (a INTEGER)");
+ myquery(rc);
+ rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)");
+ myquery(rc);
+ rc= mysql_query(mysql, "SET GLOBAL query_cache_type = 1");
+ myquery(rc);
+ rc= mysql_query(mysql, "SET GLOBAL query_cache_size = 1048576");
+ myquery(rc);
+ DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS));
+ DIE_UNLESS(mysql->server_status & SERVER_STATUS_AUTOCOMMIT);
+ rc= mysql_query(mysql, "BEGIN");
+ myquery(rc);
+ DIE_UNLESS(mysql->server_status & SERVER_STATUS_IN_TRANS);
+ rc= mysql_query(mysql, "SELECT * FROM t1");
+ myquery(rc);
+ rc= my_process_result(mysql);
+ DIE_UNLESS(rc == 1);
+ rc= mysql_rollback(mysql);
+ myquery(rc);
+ rc= mysql_query(mysql, "ROLLBACK");
+ myquery(rc);
+ DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS));
+ rc= mysql_query(mysql, "SELECT * FROM t1");
+ myquery(rc);
+ DIE_UNLESS(!(mysql->server_status & SERVER_STATUS_IN_TRANS));
+ rc= my_process_result(mysql);
+ DIE_UNLESS(rc == 1);
+ rc= mysql_query(mysql, "DROP TABLE t1");
+ myquery(rc);
+ rc= mysql_query(mysql, "SET GLOBAL query_cache_size = 0");
+ myquery(rc);
+
+ DBUG_VOID_RETURN;
+}
+
+#endif
+
+/**
+ Bug#41078: With CURSOR_TYPE_READ_ONLY mysql_stmt_fetch() returns short
+ string value.
+*/
+
+static void test_bug41078(void)
+{
+ uint rc;
+ MYSQL_STMT *stmt= 0;
+ MYSQL_BIND param, result;
+ ulong cursor_type= CURSOR_TYPE_READ_ONLY;
+ ulong len;
+ char str[64];
+ const char param_str[]= "abcdefghijklmn";
+ my_bool is_null, error;
+
+ DBUG_ENTER("test_bug41078");
+
+ rc= mysql_query(mysql, "SET NAMES UTF8");
+ myquery(rc);
+
+ stmt= mysql_simple_prepare(mysql, "SELECT ?");
+ check_stmt(stmt);
+ verify_param_count(stmt, 1);
+
+ rc= mysql_stmt_attr_set(stmt, STMT_ATTR_CURSOR_TYPE, &cursor_type);
+ check_execute(stmt, rc);
+
+ bzero(&param, sizeof(param));
+ param.buffer_type= MYSQL_TYPE_STRING;
+ param.buffer= (void *) param_str;
+ len= sizeof(param_str) - 1;
+ param.length= &len;
+
+ rc= mysql_stmt_bind_param(stmt, &param);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ bzero(&result, sizeof(result));
+ result.buffer_type= MYSQL_TYPE_STRING;
+ result.buffer= str;
+ result.buffer_length= sizeof(str);
+ result.is_null= &is_null;
+ result.length= &len;
+ result.error= &error;
+
+ rc= mysql_stmt_bind_result(stmt, &result);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_store_result(stmt);
+ check_execute(stmt, rc);
+
+ rc= mysql_stmt_fetch(stmt);
+ check_execute(stmt, rc);
+
+ DIE_UNLESS(len == sizeof(param_str) - 1 && !strcmp(str, param_str));
+
+ mysql_stmt_close(stmt);
+
+ DBUG_VOID_RETURN;
+}
/*
Read and parse arguments and MySQL options from my.cnf
@@ -16686,6 +16944,14 @@ static struct my_tests_st my_tests[]= {
{ "test_bug31669", test_bug31669 },
{ "test_bug32265", test_bug32265 },
{ "test_bug38486", test_bug38486 },
+ { "test_bug40365", test_bug40365 },
+#ifdef HAVE_SPATIAL
+ { "test_bug37956", test_bug37956 },
+#endif
+#ifdef HAVE_QUERY_CACHE
+ { "test_bug36326", test_bug36326 },
+#endif
+ { "test_bug41078", test_bug41078 },
{ "test_bug20023", test_bug20023 },
{ 0, 0 }
};