Added:
trunk/testsuites/t_charset_bug/
trunk/testsuites/t_charset_bug/charsettest.c
trunk/testsuites/t_charset_bug/t_charset_bug.h
trunk/testsuites/t_charset_bug/t_charset_bug_suite.c
Log:
new testsuite for charset bug in v5
Added: trunk/testsuites/t_charset_bug/charsettest.c
===================================================================
--- trunk/testsuites/t_charset_bug/charsettest.c 2007-04-26 01:14:37 UTC (rev 80)
+++ trunk/testsuites/t_charset_bug/charsettest.c 2007-04-26 08:27:00 UTC (rev 81)
@@ -0,0 +1,1046 @@
+/* ******************************************
+ * This test shows, if all iso encoded letters
+ * are stored in the right way into an utf8
+ * database, and if you can get this values
+ * out of the database and work with it.
+ *
+ * created: 04/26/2007 susanne
+
+ ****************************************** */
+
+#include "t_charset_bug.h"
+
+/* ******************************************
+ * create new databases with charset utf8
+ * look if database exist
+ * if database exist, drop it before creating
+
+ ****************************************** */
+
+OT_TEST_METHOD(createdatabase)
+{
+ SQLHANDLE stmt;
+ char *qry;
+ stmt = get_statement();
+
+ CHECK_SQL_S(SQLExecDirect(stmt,
+ "drop database if exists encodingtest",
+ SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ qry = "create database encodingtest "
+ "character set utf8 collate utf8_unicode_ci";
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry, SQL_NTS), stmt);
+ free_statement(stmt);
+}
+
+
+/* ******************************************
+ * create new table
+ * look if table exist
+ * if table exist, drop it before creating
+
+ ****************************************** */
+
+OT_TEST_METHOD(createtable)
+{
+ SQLHANDLE stmt;
+ char *qry;
+ stmt = get_statement();
+
+ CHECK_SQL_S(SQLExecDirect(stmt,
+ "drop table if exists germantext",
+ SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ qry = "create table encodingtest.germantext ("
+ "id integer auto_increment, german text, primary key(id))";
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry, SQL_NTS), stmt);
+ free_statement(stmt);
+}
+
+/* ******************************************
+ * insert some data with german letters
+ * into the table.
+
+ ****************************************** */
+
+OT_TEST_METHOD(insertdata)
+{
+ char *qry;
+ char *qry1;
+ char *qry2;
+ char *qry3;
+ char *qry4;
+ char *qry5;
+ char *qry6;
+ char *qry7;
+ char *qry8;
+ char *qry9;
+ char *qry10;
+ char *qry11;
+ char *qry12;
+ char *qry13;
+ SQLHANDLE stmt = get_statement();
+
+ qry = "delete from encodingtest.germantext";
+
+ qry1 = "insert into encodingtest.germantext (german)"
+ "values ('S+
+ qry2 = "insert into encodingtest.germantext (german)"
+ "values ('R+
+ qry3 = "insert into encodingtest.germantext (german)"
+ "values ('M+
+ qry4 = "insert into encodingtest.germantext (german)"
+ "values ('Stra+
+ qry5 = "insert into encodingtest.germantext (german)"
+ "values ('+
+ qry6 = "insert into encodingtest.germantext (german)"
+ "values ('+
+ qry7 = "insert into encodingtest.germantext (german)"
+ "values ('+
+ qry8 = "insert into encodingtest.germantext (german)"
+ "values ('+
+ qry9 = "insert into encodingtest.germantext (german)"
+ "values ('Bang+
+ qry10 = "insert into encodingtest.germantext (german)"
+ "values ('gr+
+ qry11 = "insert into encodingtest.germantext (german)"
+ "values ('fen+
+ qry12 = "insert into encodingtest.germantext (german)"
+ "values ('gr+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry1, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry2, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry3, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry4, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry5, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry6, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry7, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry8, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry9, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry10, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry11, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry12, SQL_NTS), stmt);
+ free_statement(stmt);
+}
+
+
+/* ******************************************
+ * select three words from the database by
+ * using _latin1. After selecting, delete
+ * the three words by using _latin1.
+ * Check via select, if delete didn't fail.
+
+ ****************************************** */
+
+OT_TEST_METHOD(selectdelete)
+{
+ SQLHANDLE stmt;
+ SQLRETURN rc;
+ SQLCHAR rslt[3][STRLEN];
+ SQLINTEGER *len;
+ char delqry[1024];
+ char *delor;
+ char *word1;
+ char *word2;
+ char *word3;
+ char *qry;
+ char *qrytmp;
+ char *qryquote;
+ char *lower;
+ char *upper;
+ char *delqrytmp;
+ char *checkqry;
+ int i;
+ int cnt;
+
+ stmt= get_statement();
+
+ len= (SQLINTEGER *)malloc(sizeof(SQLINTEGER));
+
+ i= 0;
+ cnt= 0;
+
+ word1= "Stra+ word2= "BANG+ word3= "+
+ /* Build and execute select query for existing users*/
+
+ qrytmp= "select german "
+ "from encodingtest.germantext "
+ "where german like _latin1'";
+
+ lower= " or lower(german) like _latin1'";
+
+ upper= " or upper(german) like _latin1'";
+
+ qryquote= "'";
+
+ delqrytmp= "delete from encodingtest.germantext "
+ " where german like _latin1'";
+
+ delor= " or german like _latin1'";
+
+ checkqry= "select count(german) from encodingtest.germantext "
+ "where german like _latin1'Stra+ "or german like _latin1'Bang+ "or german like _latin1'+
+ qry= (char *)malloc(strlen(qrytmp) +
+ strlen(word1) +
+ strlen(word2) +
+ strlen(word3) +
+ strlen(upper) +
+ strlen(lower) +
+ strlen(qryquote) * 3 + 1);
+ strcpy(qry, qrytmp);
+ strcat(qry, word1);
+ strcat(qry, qryquote);
+ strcat(qry, upper);
+ strcat(qry, word2);
+ strcat(qry, qryquote);
+ strcat(qry, lower);
+ strcat(qry, word3);
+ strcat(qry, qryquote);
+
+ test_printf("the select query is:\n%s\n", qry);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry, SQL_NTS), stmt);
+
+ /* Fetch data from result of select statement */
+
+ for (i= 0; (rc = SQLFetch(stmt)) == SQL_SUCCESS; ++i)
+ {
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_CHAR,
+ rslt[i], STRLEN, &len[i]), stmt);
+ test_printf("text found: %s\n", rslt[i]);
+ }
+ test_printf("%d rows selected\n", i);
+
+ reset_statement(stmt);
+
+ /* if less then 3 rows selected, the test failed */
+
+ if (i < 3)
+ OT_FAIL("The select failed, no or not enough rows were selected");
+
+ /* delete rows */
+
+ strcpy(delqry, delqrytmp);
+ strcat(delqry, rslt[0]);
+ strcat(delqry, qryquote);
+ strcat(delqry, delor);
+ strcat(delqry, rslt[1]);
+ strcat(delqry, qryquote);
+ strcat(delqry, delor);
+ strcat(delqry, rslt[2]);
+ strcat(delqry, qryquote);
+
+ test_printf("the delete query is:\n%s\n", delqry);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)delqry, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)checkqry, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &cnt, 0, &len[0]), stmt);
+
+ if (cnt > 0)
+ {
+ switch (cnt) {
+ case 1:
+ free_statement(stmt);
+ OT_FAIL("The delete failed. There is one row left in the database");
+ break;
+ case 2:
+ free_statement(stmt);
+ OT_FAIL("The delete failed. 2 rows are still in the database");
+ break;
+ case 3:
+ free_statement(stmt);
+ OT_FAIL("The delete failed. All rows are still in the database");
+ break;
+ default:
+ free_statement(stmt);
+ OT_FAIL("Maybe the programmer needs a coffee or it's a bug");
+ break;
+ }
+ }
+ test_printf("3 rows deleted\n");
+ free_statement(stmt);
+}
+
+
+/* ******************************************
+ * select three words from the database by
+ * using set names or nothing. After selecting,
+ * delete the three words by using set names
+ * or nothing. This test works with v3 by
+ * using nothing.
+ * Check via select, if delete didn't fail.
+
+ ****************************************** */
+
+OT_TEST_METHOD(selectdeletesetnames)
+{
+ SQLHANDLE stmt;
+ SQLRETURN rc;
+ SQLCHAR rslt[3][STRLEN];
+ SQLINTEGER *len;
+ char delqry[1024];
+ char *delor;
+ char *word1;
+ char *word2;
+ char *word3;
+ char *qry;
+ char *qrytmp;
+ char *qryquote;
+ char *lower;
+ char *upper;
+ char *delqrytmp;
+ char *checkqry;
+ int cnt;
+ int i;
+
+ stmt= get_statement();
+
+ len= (SQLINTEGER *)malloc(sizeof(SQLINTEGER));
+
+ i= 0;
+ cnt= 0;
+
+ word1= "gr+ word2= "M+ word3= "+
+ /* Build and execute select query for existing users*/
+
+ qrytmp= "select german "
+ "from encodingtest.germantext "
+ "where german like '";
+
+ lower= " or lower(german) like '";
+
+ upper= " or upper(german) like '";
+
+ qryquote= "'";
+
+ delqrytmp= "delete from encodingtest.germantext "
+ " where german like '";
+
+ delor=" or german like '";
+
+ checkqry= "select count(german) from encodingtest.germantext "
+ "where german like 'M+ "or german like '+ "or german like 'gr+
+ qry= (char *)malloc(strlen(qrytmp) +
+ strlen(word1) +
+ strlen(word2) +
+ strlen(word3) +
+ strlen(upper) +
+ strlen(lower) +
+ strlen(qryquote) * 3 + 1);
+ strcpy(qry, qrytmp);
+ strcat(qry, word1);
+ strcat(qry, qryquote);
+ strcat(qry, upper);
+ strcat(qry, word2);
+ strcat(qry, qryquote);
+ strcat(qry, lower);
+ strcat(qry, word3);
+ strcat(qry, qryquote);
+
+ test_printf("the select query is:\n%s\n", qry);
+
+ /* CHECK_SQL_S(SQLExecDirect(stmt, "set names latin1", SQL_NTS), stmt);
+ reset_statement(stmt);*/
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry, SQL_NTS), stmt);
+
+ /* Fetch data from result of select statement */
+
+ for (i= 0; (rc = SQLFetch(stmt)) == SQL_SUCCESS; ++i)
+ {
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_CHAR,
+ rslt[i], STRLEN, &len[i]), stmt);
+ test_printf("text found: %s\n", rslt[i]);
+ }
+ test_printf("%d rows selected\n", i);
+
+ reset_statement(stmt);
+
+ /* if less then 3 rows selected, the test failed */
+
+ if (i < 3)
+ OT_FAIL("The select failed, no or not enough rows were selected");
+
+ /* delete rows */
+
+ strcpy(delqry, delqrytmp);
+ strcat(delqry, rslt[0]);
+ strcat(delqry, qryquote);
+ strcat(delqry, delor);
+ strcat(delqry, rslt[1]);
+ strcat(delqry, qryquote);
+ strcat(delqry, delor);
+ strcat(delqry, rslt[2]);
+ strcat(delqry, qryquote);
+
+ test_printf("the delete query is:\n%s\n", delqry);
+
+ /* CHECK_SQL_S(SQLExecDirect(stmt, "set names utf8", SQL_NTS), stmt);
+ reset_statement(stmt);*/
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)delqry, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)checkqry, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &cnt, 0, &len[0]), stmt);
+
+ if (cnt > 0)
+ {
+ switch (cnt) {
+ case 1:
+ free_statement(stmt);
+ OT_FAIL("The delete failed. There is one row left in the database");
+ break;
+ case 2:
+ free_statement(stmt);
+ OT_FAIL("The delete failed. 2 rows are still in the database");
+ break;
+ case 3:
+ free_statement(stmt);
+ OT_FAIL("The delete failed. All rows are still in the database");
+ break;
+ default:
+ free_statement(stmt);
+ OT_FAIL("Maybe the programmer needs a coffee or it's a bug");
+ break;
+ }
+ }
+ test_printf("3 rows deleted\n");
+ free_statement(stmt);
+}
+
+/* ******************************************
+ * update three words from the database by
+ * using _latin1. After udating, a select
+ * statement checks, if update was ok. This
+ * statement also use _latin1.
+
+ ****************************************** */
+
+OT_TEST_METHOD(update)
+{
+ SQLHANDLE stmt;
+ SQLINTEGER *len;
+ char *qry1;
+ char *qry2;
+ char *qry3;
+ char *checkqry;
+ int cnt;
+
+ stmt= get_statement();
+
+ cnt= 0;
+
+ qry1 = "update encodingtest.germantext "
+ "set german='d+ "where german like _latin1'fen+
+ qry2 = "update encodingtest.germantext "
+ "set german='+ "where lower(german) like _latin1'+
+ qry3 = "update encodingtest.germantext "
+ "set german='Br+ "where upper(german) like _latin1'S+
+ checkqry= "select count(german) from encodingtest.germantext "
+ "where german like _latin1'Br+ "or german like _latin1'+ "or german like _latin1'd+
+ len= (SQLINTEGER *)malloc(sizeof(SQLINTEGER));
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry1, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry2, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry3, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)checkqry, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &cnt, 0, &len[0]), stmt);
+
+ free_statement(stmt);
+
+ if (cnt < 3)
+ OT_FAIL("One or more updates failed or the check select query failed");
+
+ test_printf("%d rows updated\n", cnt);
+}
+
+/* ******************************************
+ * update three words from the database by
+ * using set names or nothing. After update,
+ * a select statement checks, if update works
+ * in the right way. This statement also runs
+ * with set names or nothing.
+ * This test works with v3 by using nothing.
+
+ ****************************************** */
+
+OT_TEST_METHOD(updatesetnames)
+{
+ SQLHANDLE stmt;
+ SQLINTEGER *len;
+ char *qry1;
+ char *qry2;
+ char *qry3;
+ char *checkqry;
+ int cnt;
+
+ stmt= get_statement();
+
+ cnt= 0;
+
+ qry1 = "update encodingtest.germantext "
+ "set german='m+ "where german like _latin1'%+
+ qry2 = "update encodingtest.germantext "
+ "set german='Franz+ "where lower(german) like _latin1'%+
+ qry3 = "update encodingtest.germantext "
+ "set german='+ "where upper(german) like _latin1'+
+ checkqry= "select count(german) from encodingtest.germantext "
+ "where german like 'm+ "or german like 'Franz+ "or german like '+
+ len= (SQLINTEGER *)malloc(sizeof(SQLINTEGER));
+
+ /* CHECK_SQL_S(SQLExecDirect(stmt, "set names latin1", SQL_NTS), stmt);
+ reset_statement(stmt);*/
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry1, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry2, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry3, SQL_NTS), stmt);
+ reset_statement(stmt);
+
+ /* CHECK_SQL_S(SQLExecDirect(stmt, "set names utf8", SQL_NTS), stmt);
+ reset_statement(stmt);*/
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)checkqry, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &cnt, 0, &len[0]), stmt);
+
+ free_statement(stmt);
+
+ if (cnt < 3)
+ OT_FAIL("One or more updates failed or the check select query failed");
+
+ test_printf("%d rows updated\n", cnt);
+}
+
+/* ******************************************
+ * select three words from the database by
+ * using _latin1. After selecting, delete
+ * the three words by using _latin1.
+ * Because update is broken in v5, there is
+ * a method to figure out, which values are
+ * stored.
+
+ ****************************************** */
+
+OT_TEST_METHOD(selectdeletewithwildcards)
+{
+ SQLHANDLE stmt;
+ SQLRETURN rc;
+ SQLCHAR rslt[3][STRLEN];
+ SQLINTEGER *len;
+ char delqry[1024];
+ char *delor;
+ char *origword1;
+ char *origword2;
+ char *origword3;
+ char *word1;
+ char *word2;
+ char *word3;
+ char *cntqry1;
+ char *cntqry2;
+ char *qry;
+ char *qrytmp;
+ char *qryquote;
+ char *lower;
+ char *upper;
+ char *delqrytmp;
+ int i;
+ int cnt;
+
+ stmt= get_statement();
+
+ len= (SQLINTEGER *)malloc(sizeof(SQLINTEGER));
+ i= 0;
+ cnt= 0;
+
+ word1= "%+ word2= "%+ word3= "+
+ origword1= "%n+ origword2= "%+ origword3= "+
+ /* Check if update was correct */
+
+ cntqry1= "select count(german) from encodingtest.germantext "
+ "where german like _latin1'd+ "or german like _latin1'+
+ cntqry2= "select count(german) from encodingtest.germantext "
+ "where german like _latin1'fen+ "or german like _latin1'S+
+ /* Build and execute select query for existing users*/
+
+ qrytmp= "select german "
+ "from encodingtest.germantext "
+ "where german like _latin1'";
+
+ lower= " or lower(german) like _latin1'";
+
+ upper= " or upper(german) like _latin1'";
+
+ qryquote= "'";
+
+ delqrytmp= "delete from encodingtest.germantext "
+ " where german like _latin1'";
+
+ delor= " or german like _latin1'";
+
+ qry="select -1";
+
+ /* check for the right words in the database: */
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)cntqry1, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &i, 0, &len[0]), stmt);
+ reset_statement(stmt);
+
+ if (i!=3)
+ {
+ i=0;
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)cntqry2, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &i, 0, &len[0]), stmt);
+
+ if (i!=3)
+ {
+ free_statement(stmt);
+ OT_FAIL("Maybe the programmer needs a coffee or the update goes wrong");
+ }
+ cnt= 2;
+ }
+ else
+ cnt= 1;
+
+ switch (cnt) {
+ case 1:
+ qry= (char *)malloc(strlen(qrytmp) +
+ strlen(word1) +
+ strlen(word2) +
+ strlen(word3) +
+ strlen(upper) +
+ strlen(lower) +
+ strlen(qryquote) * 3 + 1);
+ strcpy(qry, qrytmp);
+ strcat(qry, word1);
+ strcat(qry, qryquote);
+ strcat(qry, upper);
+ strcat(qry, word2);
+ strcat(qry, qryquote);
+ strcat(qry, lower);
+ strcat(qry, word3);
+ strcat(qry, qryquote);
+ break;
+ case 2:
+ qry= (char *)malloc(strlen(qrytmp) +
+ strlen(origword1) +
+ strlen(origword2) +
+ strlen(origword3) +
+ strlen(upper) +
+ strlen(lower) +
+ strlen(qryquote) * 3 + 1);
+ strcpy(qry, qrytmp);
+ strcat(qry, origword1);
+ strcat(qry, qryquote);
+ strcat(qry, upper);
+ strcat(qry, origword2);
+ strcat(qry, qryquote);
+ strcat(qry, lower);
+ strcat(qry, origword3);
+ strcat(qry, qryquote);
+ break;
+ default:
+ free_statement(stmt);
+ OT_FAIL("Maybe the programmer needs a coffee, couldn't count to 2");
+ break;
+ }
+
+ reset_statement(stmt);
+
+ test_printf("the select query is:\n%s\n", qry);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry, SQL_NTS), stmt);
+
+ /* Fetch data from result of select statement */
+
+ for (i= 0; (rc = SQLFetch(stmt)) == SQL_SUCCESS; ++i)
+ {
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_CHAR,
+ rslt[i], STRLEN, &len[i]), stmt);
+ test_printf("text found: %s\n", rslt[i]);
+ }
+ test_printf("%d rows selected\n", i);
+
+ /* if less then 3 rows selected, the test failed */
+
+ if (i < 3)
+ {
+ free_statement(stmt);
+ OT_FAIL("The select failed, no or not enough rows were selected");
+ }
+ reset_statement(stmt);
+
+ strcpy(delqry, delqrytmp);
+ strcat(delqry, rslt[0]);
+ strcat(delqry, qryquote);
+ strcat(delqry, delor);
+ strcat(delqry, rslt[1]);
+ strcat(delqry, qryquote);
+ strcat(delqry, delor);
+ strcat(delqry, rslt[2]);
+ strcat(delqry, qryquote);
+
+ test_printf("the delete query is:\n%s\n", delqry);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)delqry, SQL_NTS), stmt);
+
+ /* check if delete works */
+
+ if (cnt==2)
+ {
+ reset_statement(stmt);
+ i=0;
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)cntqry2, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &i, 0, &len[0]), stmt);
+ if (i > 0)
+ {
+ free_statement(stmt);
+ OT_FAIL("The delete failed. There is one or more rows left in the database");
+ }
+ }
+ else
+ {
+ reset_statement(stmt);
+ i=0;
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)cntqry1, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &i, 0, &len[0]), stmt);
+
+ if (i > 0)
+ {
+ free_statement(stmt);
+ OT_FAIL("The delete failed. There is one or more rows left in the database");
+ }
+ }
+ test_printf("3 rows deleted\n");
+ free_statement(stmt);
+}
+
+/* ******************************************
+ * select three words from the database by
+ * using set names. After selecting, delete
+ * the three words by using set names.
+ * Because update is broken in v5, there is
+ * a method to figure out, which values are
+ * stored.
+ * This works with v3 without set names.
+
+ ****************************************** */
+
+OT_TEST_METHOD(selectdeletewithwildcardssetnames)
+{
+
+ SQLHANDLE stmt;
+ SQLRETURN rc;
+ SQLCHAR rslt[3][STRLEN];
+ SQLINTEGER *len;
+ char delqry[1024];
+ char *delor;
+ char *origword1;
+ char *origword2;
+ char *origword3;
+ char *word1;
+ char *word2;
+ char *word3;
+ char *cntqry1;
+ char *cntqry2;
+ char *qry;
+ char *qrytmp;
+ char *qryquote;
+ char *lower;
+ char *upper;
+ char *delqrytmp;
+ int i;
+ int cnt;
+
+ stmt= get_statement();
+
+ len= (SQLINTEGER *)malloc(sizeof(SQLINTEGER));
+
+ i= 0;
+ cnt= 0;
+
+ word1= "%+ word2= "FRANZ+ word3= "%+
+ origword1= "%+ origword2= "R+ origword3= "%+
+ /* Check if update was correct */
+
+ cntqry1= "select count(german) from encodingtest.germantext "
+ "where german like 'm+ "or german like '+
+ cntqry2= "select count(german) from encodingtest.germantext "
+ "where german like 'gr+ "or german like '+
+ /* Build and execute select query for existing users*/
+
+ qrytmp= "select german "
+ "from encodingtest.germantext "
+ "where german like '";
+
+ lower= " or lower(german) like '";
+
+ upper= " or upper(german) like '";
+
+ qryquote= "'";
+
+ delqrytmp= "delete from encodingtest.germantext "
+ " where german like '";
+
+ delor= " or german like '";
+
+ qry="select -1";
+
+ /* check for the right words in the database: */
+
+ /* CHECK_SQL_S(SQLExecDirect(stmt, "set names latin1", SQL_NTS), stmt);
+ reset_statement(stmt);*/
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)cntqry1, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &i, 0, &len[0]), stmt);
+ reset_statement(stmt);
+
+ if (i!=3)
+ {
+ i=0;
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)cntqry2, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &i, 0, &len[0]), stmt);
+
+ if (i!=3)
+ {
+ free_statement(stmt);
+ OT_FAIL("Maybe the programmer needs a coffee or the update goes wrong");
+ }
+ cnt= 2;
+ }
+ else
+ cnt= 1;
+
+ switch (cnt) {
+ case 1:
+ qry= (char *)malloc(strlen(qrytmp) +
+ strlen(word1) +
+ strlen(word2) +
+ strlen(word3) +
+ strlen(upper) +
+ strlen(lower) +
+ strlen(qryquote) * 3 + 1);
+ strcpy(qry, qrytmp);
+ strcat(qry, word1);
+ strcat(qry, qryquote);
+ strcat(qry, upper);
+ strcat(qry, word2);
+ strcat(qry, qryquote);
+ strcat(qry, lower);
+ strcat(qry, word3);
+ strcat(qry, qryquote);
+ break;
+ case 2:
+ qry= (char *)malloc(strlen(qrytmp) +
+ strlen(origword1) +
+ strlen(origword2) +
+ strlen(origword3) +
+ strlen(upper) +
+ strlen(lower) +
+ strlen(qryquote) * 3 + 1);
+ strcpy(qry, qrytmp);
+ strcat(qry, origword1);
+ strcat(qry, qryquote);
+ strcat(qry, upper);
+ strcat(qry, origword2);
+ strcat(qry, qryquote);
+ strcat(qry, lower);
+ strcat(qry, origword3);
+ strcat(qry, qryquote);
+ break;
+ default:
+ free_statement(stmt);
+ OT_FAIL("Maybe the programmer needs a coffee, couldn't count to 2");
+ break;
+ }
+
+ reset_statement(stmt);
+
+ test_printf("the select query is:\n%s\n", qry);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry, SQL_NTS), stmt);
+
+ /* Fetch data from result of select statement */
+
+ for (i= 0; (rc = SQLFetch(stmt)) == SQL_SUCCESS; ++i)
+ {
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_CHAR,
+ rslt[i], STRLEN, &len[i]), stmt);
+ test_printf("text found: %s\n", rslt[i]);
+ }
+ test_printf("%d rows selected\n", i);
+
+ /* if less then 3 rows selected, the test failed */
+
+ if (i < 3)
+ {
+ free_statement(stmt);
+ OT_FAIL("The select failed, no or not enough rows were selected");
+ }
+ reset_statement(stmt);
+
+ strcpy(delqry, delqrytmp);
+ strcat(delqry, rslt[0]);
+ strcat(delqry, qryquote);
+ strcat(delqry, delor);
+ strcat(delqry, rslt[1]);
+ strcat(delqry, qryquote);
+ strcat(delqry, delor);
+ strcat(delqry, rslt[2]);
+ strcat(delqry, qryquote);
+
+ test_printf("the delete query is:\n%s\n", delqry);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)delqry, SQL_NTS), stmt);
+
+ /* check if delete works */
+
+ if (cnt==2)
+ {
+ reset_statement(stmt);
+ i=0;
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)cntqry2, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &i, 0, &len[0]), stmt);
+ if (i > 0)
+ {
+ free_statement(stmt);
+ OT_FAIL("The delete failed. There is one or more rows left in the database");
+ }
+ }
+ else
+ {
+ reset_statement(stmt);
+ i=0;
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)cntqry1, SQL_NTS), stmt);
+
+ CHECK_SQL_S(SQLFetch(stmt), stmt);
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_LONG, &i, 0, &len[0]), stmt);
+ if (i > 0)
+ {
+ free_statement(stmt);
+ OT_FAIL("The delete failed. There is one or more rows left in the database");
+ }
+ }
+ test_printf("3 rows deleted\n");
+ free_statement(stmt);
+}
Added: trunk/testsuites/t_charset_bug/t_charset_bug.h
===================================================================
--- trunk/testsuites/t_charset_bug/t_charset_bug.h 2007-04-26 01:14:37 UTC (rev 80)
+++ trunk/testsuites/t_charset_bug/t_charset_bug.h 2007-04-26 08:27:00 UTC (rev 81)
@@ -0,0 +1,17 @@
+#include "odbctest.h"
+
+/* test data definitions */
+extern const char *TD_DBNAME;
+
+extern const int TD_ALLTYPES_COLS;
+
+/* create tests */
+OT_TEST_METHOD(createdatabase);
+OT_TEST_METHOD(createtable);
+OT_TEST_METHOD(insertdata);
+OT_TEST_METHOD(selectdelete);
+OT_TEST_METHOD(selectdeletesetnames);
+OT_TEST_METHOD(update);
+OT_TEST_METHOD(updatesetnames);
+OT_TEST_METHOD(selectdeletewithwildcards);
+OT_TEST_METHOD(selectdeletewithwildcardssetnames);
Added: trunk/testsuites/t_charset_bug/t_charset_bug_suite.c
===================================================================
--- trunk/testsuites/t_charset_bug/t_charset_bug_suite.c 2007-04-26 01:14:37 UTC (rev 80)
+++ trunk/testsuites/t_charset_bug/t_charset_bug_suite.c 2007-04-26 08:27:00 UTC (rev 81)
@@ -0,0 +1,29 @@
+#include "t_charset_bug.h"
+
+OT_SUITE_SETUP(sql_suite_setup)
+{
+ if (!global_connect())
+ return "Cannot create global connection!";
+ else
+ return NULL;
+}
+
+OT_SUITE_TEARDOWN(sql_suite_teardown)
+{
+ global_disconnect();
+ return NULL;
+}
+
+OT_SUITE_REGISTER_START("charset_bug",sql_suite_setup,sql_suite_teardown)
+/* create tests */
+ OT_SUITE_ADD_TEST(createdatabase, NULL, NULL);
+ OT_SUITE_ADD_TEST(createtable, NULL, NULL);
+ OT_SUITE_ADD_TEST(insertdata, NULL, NULL);
+ OT_SUITE_ADD_TEST(selectdelete, NULL, NULL);
+ OT_SUITE_ADD_TEST(selectdeletesetnames, NULL, NULL);
+ OT_SUITE_ADD_TEST(update, NULL, NULL);
+ OT_SUITE_ADD_TEST(updatesetnames, NULL, NULL);
+ OT_SUITE_ADD_TEST(selectdeletewithwildcards, NULL, NULL);
+ OT_SUITE_ADD_TEST(selectdeletewithwildcardssetnames, NULL, NULL);
+OT_SUITE_REGISTER_END
+
| Thread |
|---|
| • ODBC C-tests commit: r81 - in trunk/testsuites: . t_charset_bug | sebrecht | 26 Apr |