summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorunknown <konstantin@mysql.com>2004-11-05 21:02:12 +0300
committerunknown <konstantin@mysql.com>2004-11-05 21:02:12 +0300
commitb3d84df165fbc3d2ec0b1aab27f3e2e20ac49f2e (patch)
tree6738b37fb296ec7a84e8500b9844819a5485af6b /tests
parent7bcd40bd32df675d9c2f84191015915aafa20ee2 (diff)
downloadmariadb-git-b3d84df165fbc3d2ec0b1aab27f3e2e20ac49f2e.tar.gz
A fix and test case for the bug reported by Reggie: if character set
of client equals to character set of connection, possibly required conversion to character set of column is not performed (prepared statements, data is supplied using placeholders). sql/item.cc: Fix for the bug reported by Reggie: if character_set_connection is equal to character_set_client, placeholder's value is not converted furhter to character set of column when it's different. This is because the original implementation left placeholder's character set intact (binary) if there were no need for client->connection conversion. tests/client_test.c: A test case for the conversion bug.
Diffstat (limited to 'tests')
-rw-r--r--tests/client_test.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/client_test.c b/tests/client_test.c
index 004f076c6df..d373f57c1de 100644
--- a/tests/client_test.c
+++ b/tests/client_test.c
@@ -11152,6 +11152,73 @@ static void test_bug4172()
}
+static void test_conversion()
+{
+ MYSQL_STMT *stmt;
+ const char *stmt_text;
+ int rc;
+ MYSQL_BIND bind[1];
+ char buff[4];
+ ulong length;
+
+ myheader("test_conversion");
+
+ stmt_text= "DROP TABLE IF EXISTS t1";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+ stmt_text= "CREATE TABLE t1 (a TEXT) DEFAULT CHARSET latin1";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+ stmt_text= "SET character_set_connection=utf8, character_set_client=utf8, "
+ " character_set_results=latin1";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+
+ stmt= mysql_stmt_init(mysql);
+
+ stmt_text= "INSERT INTO t1 (a) VALUES (?)";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+
+ bzero(bind, sizeof(bind));
+ bind[0].buffer= buff;
+ bind[0].length= &length;
+ bind[0].buffer_type= MYSQL_TYPE_STRING;
+
+ mysql_stmt_bind_param(stmt, bind);
+
+ buff[0]= 0xC3;
+ buff[1]= 0xA0;
+ length= 2;
+
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ stmt_text= "SELECT a FROM t1";
+ rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
+ check_execute(stmt, rc);
+ rc= mysql_stmt_execute(stmt);
+ check_execute(stmt, rc);
+
+ bind[0].buffer_length= sizeof(buff);
+ mysql_stmt_bind_result(stmt, bind);
+
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc == 0);
+ DIE_UNLESS(length == 1);
+ DIE_UNLESS((uchar) buff[0] == 0xE0);
+ rc= mysql_stmt_fetch(stmt);
+ DIE_UNLESS(rc == MYSQL_NO_DATA);
+
+ mysql_stmt_close(stmt);
+ stmt_text= "DROP TABLE t1";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+ stmt_text= "SET NAMES DEFAULT";
+ rc= mysql_real_query(mysql, stmt_text, strlen(stmt_text));
+ myquery(rc);
+}
+
/*
Read and parse arguments and MySQL options from my.cnf
@@ -11471,6 +11538,10 @@ int main(int argc, char **argv)
test_bug6096(); /* max_length for numeric columns */
test_bug4172(); /* floating point conversions in libmysql */
+ test_conversion(); /* placeholder value is not converted to
+ character set of column if character set
+ of connection equals to character set of
+ client */
/*
XXX: PLEASE RUN THIS PROGRAM UNDER VALGRIND AND VERIFY THAT YOUR TEST
DOESN'T CONTAIN WARNINGS/ERRORS BEFORE YOU PUSH.