Modified:
trunk/testsuites/t_sql/databasehandling.c
trunk/testsuites/t_sql/t_sql.h
trunk/testsuites/t_sql/t_sql_suite.c
trunk/testsuites/t_sql/userhandling.c
Log:
creating new test for user handling with german latin1 letters
changing indenting
fixing bug in databasehandling
Modified: trunk/testsuites/t_sql/databasehandling.c
===================================================================
--- trunk/testsuites/t_sql/databasehandling.c 2007-04-10 19:41:16 UTC (rev 71)
+++ trunk/testsuites/t_sql/databasehandling.c 2007-04-10 19:43:34 UTC (rev 72)
@@ -30,7 +30,6 @@
char *qry1;
char *qry2;
char *qry3;
- char *qry4;
char *drpqry;
char *tmp;
SQLINTEGER *len;
@@ -39,100 +38,35 @@
len = (SQLINTEGER *)malloc(sizeof(SQLINTEGER));
stmt = get_statement();
- qry1="select db "
- "from mysql.db "
- "where lower(db) like ('m- " or lower(user) like ('m- " or lower(user) like ('m- " or lower (user)";
-
/*CHECK_SQL_S(SQLExecDirect(stmt, "set names latin1", SQL_NTS), stmt);
reset_statement(stmt);*/
- CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry1, SQL_NTS), stmt);
-
- for(i=0;(rc = SQLFetch(stmt)) == SQL_SUCCESS;++i)
- {
- CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_CHAR,
- name[i], STRLEN, &len[i]), rc);
- test_printf("database exist: %s\n",name[i]);
- }
+ CHECK_SQL_S(SQLExecDirect(stmt,
+ "drop database if exists m+ SQL_NTS), stmt);
reset_statement(stmt);
+ CHECK_SQL_S(SQLExecDirect(stmt,
+ "drop database if exists m+ SQL_NTS), stmt);
+ CHECK_SQL_S(SQLExecDirect(stmt,
+ "drop database if exists m+ SQL_NTS), stmt);
- switch(i)
- {
- case 1:
- tmp="drop database ";
- drpqry=(char *)malloc(strlen(tmp)+strlen(name[0])+1);
- if(drpqry == NULL)
- {
- test_printf("Couldn't allocate enough bytes\n");
- exit(2);
- }
- strcpy(drpqry,tmp);
- strcat(drpqry,name[0]);
-
- CHECK_SQL_S(SQLExecDirect(stmt,(SQLCHAR *)drpqry,SQL_NTS),stmt);
- test_printf("database %s droped\n",name[0]);
- reset_statement(stmt);
- break;
- case 2:
- tmp="drop database ";
- drpqry=(char *)malloc(strlen(tmp)+strlen(name[0])+strlen(name[1])+2);
- if(drpqry == NULL)
- {
- test_printf("Couldn't allocate enough bytes\n");
- exit(1);
- }
- strcpy(drpqry,tmp);
- strcat(drpqry,name[0]);
- strcat(drpqry,",");
- strcat(drpqry,name[1]);
-
- CHECK_SQL_S(SQLExecDirect(stmt,(SQLCHAR *)drpqry,SQL_NTS),stmt);
- test_printf("database %s and database %s droped\n",name[0], name[1]);
- reset_statement(stmt);
- break;
- case 3:
- tmp="drop database ";
- drpqry=(char *)
- malloc(strlen(tmp)+strlen(name[0])+strlen(name[1])+strlen(name[2])+3);
- if(drpqry == NULL)
- {
- test_printf("Couldn't allocate enough bytes\n");
- exit(3);
- }
- strcpy(drpqry,tmp);
- strcat(drpqry,name[0]);
- strcat(drpqry,",");
- strcat(drpqry,name[1]);
- strcat(drpqry,",");
- strcat(drpqry,name[2]);
-
- CHECK_SQL_S(SQLExecDirect(stmt,(SQLCHAR *)drpqry,SQL_NTS),stmt);
- test_printf("databases: %s, %s and %s droped\n",
- name[0],name[1],name[2]);
- reset_statement(stmt);
- break;
- defaul:
- break;
- }
-
- qry2 = "create database m+ qry1 = "create database m "character set latin1 collate latin1_german1_ci";
- CHECK_SQL_S(SQLExecDirect(stmt,qry2,SQL_NTS),stmt);
+ CHECK_SQL_S(SQLExecDirect(stmt, qry1, SQL_NTS), stmt);
reset_statement(stmt);
- qry3 = "create database m+ qry2 = "create database m "character set latin1 collate latin1_german2_ci";
- CHECK_SQL_S(SQLExecDirect(stmt,qry3,SQL_NTS),stmt);
+ CHECK_SQL_S(SQLExecDirect(stmt, qry2, SQL_NTS), stmt);
reset_statement(stmt);
- qry4 = "create database m+ qry3 = "create database m "character set utf8 collate utf8_unicode_ci";
- CHECK_SQL_S(SQLExecDirect(stmt,qry4,SQL_NTS),stmt);
+ CHECK_SQL_S(SQLExecDirect(stmt, qry3, SQL_NTS), stmt);
free_statement(stmt);
}
Modified: trunk/testsuites/t_sql/t_sql.h
===================================================================
--- trunk/testsuites/t_sql/t_sql.h 2007-04-10 19:41:16 UTC (rev 71)
+++ trunk/testsuites/t_sql/t_sql.h 2007-04-10 19:43:34 UTC (rev 72)
@@ -10,6 +10,7 @@
/* create tests */
OT_TEST_METHOD(userhandling);
+OT_TEST_METHOD(userwithgermanletters);
OT_TEST_METHOD(databasehandling);
#endif /* _TSQL_H */
Modified: trunk/testsuites/t_sql/t_sql_suite.c
===================================================================
--- trunk/testsuites/t_sql/t_sql_suite.c 2007-04-10 19:41:16 UTC (rev 71)
+++ trunk/testsuites/t_sql/t_sql_suite.c 2007-04-10 19:43:34 UTC (rev 72)
@@ -17,6 +17,7 @@
OT_SUITE_REGISTER_START("susanne",sql_suite_setup,sql_suite_teardown)
/* create tests */
OT_SUITE_ADD_TEST(userhandling, NULL, NULL);
+ OT_SUITE_ADD_TEST(userwithgermanletters, NULL, NULL);
OT_SUITE_ADD_TEST(databasehandling, NULL, NULL);
OT_SUITE_REGISTER_END
Modified: trunk/testsuites/t_sql/userhandling.c
===================================================================
--- trunk/testsuites/t_sql/userhandling.c 2007-04-10 19:41:16 UTC (rev 71)
+++ trunk/testsuites/t_sql/userhandling.c 2007-04-10 19:43:34 UTC (rev 72)
@@ -30,24 +30,24 @@
char *drpqry;
char *crtqry;
SQLHANDLE stmt;
- stmt = get_statement();
- int cnt = 0;
- int i = 0;
+ SQLINTEGER *len;
+ stmt= get_statement();
+ len= (SQLINTEGER *)malloc(sizeof(SQLINTEGER));
+ int cnt= 0;
+ int i= 0;
+
+ char *qry1= "select count(*) "
+ "from mysql.user "
+ "where lower(user) like 'susanne'";
+
+ char *qry2= "select user "
+ "from mysql.user "
+ "where lower(user) like ('chuck') "
+ "or lower(user) like ('tux') "
+ "or lower(user) like ('slony')";
- SQLINTEGER *len = (SQLINTEGER *)malloc(sizeof(SQLINTEGER));
-
- char *qry1 = "select count(*) "
- "from mysql.user "
- "where lower(user) like 'susanne'";
-
- char *qry2 = "select user "
- "from mysql.user "
- "where lower(user) like ('chuck') "
- "or lower(user) like ('tux') "
- "or lower(user) like ('slony')";
-
- char *qry3 = "select password('elephant')";
-
+ char *qry3= "select password('elephant')";
+
CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry1, SQL_NTS), stmt);
CHECK_SQL_S(SQLFetch(stmt), stmt);
@@ -69,7 +69,7 @@
CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry2, SQL_NTS), stmt);
- for (i = 0; (rc = SQLFetch(stmt)) == SQL_SUCCESS; ++i)
+ for (i= 0; (rc= SQLFetch(stmt)) == SQL_SUCCESS; ++i)
{
CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_CHAR,
name[i], STRLEN, &len[i]), rc);
@@ -77,62 +77,62 @@
}
reset_statement(stmt);
- switch(i) {
- case 1:
- tmp = "drop user ";
- drpqry = (char *)malloc(strlen(tmp) + strlen(name[0]) + 1);
- if (drpqry == NULL)
- {
- test_printf("Couldn't allocate enough bytes\n");
- exit(2);
- }
- strcpy(drpqry, tmp);
- strcat(drpqry, name[0]);
+ switch (i) {
+ case 1:
+ tmp= "drop user ";
+ drpqry= (char *)malloc(strlen(tmp) + strlen(name[0]) + 1);
+ if (drpqry == NULL)
+ {
+ test_printf("Couldn't allocate enough bytes\n");
+ exit(2);
+ }
+ strcpy(drpqry, tmp);
+ strcat(drpqry, name[0]);
- CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)drpqry, SQL_NTS), stmt);
- test_printf("user %s droped\n", name[0]);
- reset_statement(stmt);
- break;
- case 2:
- tmp = "drop user ";
- drpqry = (char *)malloc(strlen(tmp) + strlen(name[0]) +
- strlen(name[1]) + 2);
- if(drpqry == NULL)
- {
- test_printf("Couldn't allocate enough bytes\n");
- exit(1);
- }
- strcpy(drpqry, tmp);
- strcat(drpqry, name[0]);
- strcat(drpqry, ",");
- strcat(drpqry, name[1]);
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)drpqry, SQL_NTS), stmt);
+ test_printf("user %s droped\n", name[0]);
+ reset_statement(stmt);
+ break;
+ case 2:
+ tmp= "drop user ";
+ drpqry= (char *)malloc(strlen(tmp) + strlen(name[0]) +
+ strlen(name[1]) + 2);
+ if (drpqry == NULL)
+ {
+ test_printf("Couldn't allocate enough bytes\n");
+ exit(1);
+ }
+ strcpy(drpqry, tmp);
+ strcat(drpqry, name[0]);
+ strcat(drpqry, ",");
+ strcat(drpqry, name[1]);
- CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)drpqry, SQL_NTS), stmt);
- test_printf("user %s and user %s droped\n",name[0], name[1]);
- reset_statement(stmt);
- break;
- case 3:
- tmp = "drop user ";
- drpqry = (char *) malloc(strlen(tmp) + strlen(name[0]) +
- strlen(name[1]) + strlen(name[2]) + 3);
- if(drpqry == NULL)
- {
- test_printf("Couldn't allocate enough bytes\n");
- exit(3);
- }
- strcpy(drpqry, tmp);
- strcat(drpqry, name[0]);
- strcat(drpqry, ",");
- strcat(drpqry, name[1]);
- strcat(drpqry, ",");
- strcat(drpqry, name[2]);
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)drpqry, SQL_NTS), stmt);
+ test_printf("user %s and user %s droped\n", name[0], name[1]);
+ reset_statement(stmt);
+ break;
+ case 3:
+ tmp= "drop user ";
+ drpqry= (char *) malloc(strlen(tmp) + strlen(name[0]) +
+ strlen(name[1]) + strlen(name[2]) + 3);
+ if (drpqry == NULL)
+ {
+ test_printf("Couldn't allocate enough bytes\n");
+ exit(3);
+ }
+ strcpy(drpqry, tmp);
+ strcat(drpqry, name[0]);
+ strcat(drpqry, ",");
+ strcat(drpqry, name[1]);
+ strcat(drpqry, ",");
+ strcat(drpqry, name[2]);
- CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)drpqry, SQL_NTS), stmt);
- test_printf("users: %s, %s and %s droped\n", name[0], name[1], name[2]);
- reset_statement(stmt);
- break;
- defaul:
- break;
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)drpqry, SQL_NTS), stmt);
+ test_printf("users: %s, %s and %s droped\n", name[0], name[1], name[2]);
+ reset_statement(stmt);
+ break;
+ defaul:
+ break;
}
CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)qry3, SQL_NTS), stmt);
@@ -142,11 +142,11 @@
reset_statement(stmt);
- crttmp = "create user chuck,"
- "tux identified by 'penguin',"
- "slony identified by password '";
- crtqry = (char *) malloc(strlen(crttmp) + strlen(pw) + 2);
- if(crtqry == NULL)
+ crttmp= "create user chuck,"
+ "tux identified by 'penguin',"
+ "slony identified by password '";
+ crtqry= (char *) malloc(strlen(crttmp) + strlen(pw) + 2);
+ if (crtqry == NULL)
{
test_printf("Couldn't allocate enough bytes\n");
exit(3);
@@ -159,3 +159,143 @@
test_printf("users: chuck, tux and slony created\n");
free_statement(stmt);
}
+
+/* ******************************************
+ * create new users with latin1 signs
+ * look if user exist
+ * if user exist, drop user before creating
+
+ ****************************************** */
+
+OT_TEST_METHOD(userwithgermanletters)
+{
+ SQLHANDLE stmt;
+ SQLRETURN rc;
+ SQLCHAR rsname[25][STRLEN];
+ SQLINTEGER *len;
+ char *name[25];
+ char *slctqry;
+ char *slctqrytmp;
+ char *slctqryquote;
+ char *crtqry;
+ char *crtqrytmp;
+ int i;
+ stmt = get_statement();
+ len = (SQLINTEGER *)malloc(sizeof(SQLINTEGER));
+ i=0;
+ name[0] = "t+ name[1] = "t+ name[2] = "t+ name[3] = "te+ name[4] = "t+ name[5] = "t+ name[6] = "t+ name[7] = "t+ name[8] = "t$st";
+ name[9] = "t+ name[10] = "t+ name[11] = "t+ name[12] = "t+ name[13] = "t+ name[14] = "t+ name[15] = "t+ name[16] = "test";
+ name[17] = "tEst";
+ name[18] = "t2st";
+ name[19] = "t3st";
+ name[20] = "t+ name[21] = "t+ name[22] = "t_st";
+ name[23] = "t+ name[24] = "t+
+ /* Build and execute select query for existing users*/
+
+ slctqry = "select user "
+ "from mysql.user where user like _latin1'";
+ slctqryquote= "'";
+ slctqrytmp = (char *)malloc(strlen(slctqry) +
+ strlen(name[0]) +
+ strlen(slctqryquote) + 1);
+ strcpy(slctqrytmp, slctqry);
+ strcat(slctqrytmp, name[0]);
+ strcat(slctqrytmp, slctqryquote);
+
+ for (i= 1; i < 25; ++i)
+ {
+ char *tmp;
+ tmp = " or user like _latin1'";
+ slctqry = (char *)malloc(strlen(slctqrytmp) +
+ strlen(name[i]) +
+ strlen(tmp) +
+ strlen(slctqryquote) + 1);
+ strcpy(slctqry, slctqrytmp);
+ strcat(slctqry, tmp);
+ strcat(slctqry, name[i]);
+ strcat(slctqry, slctqryquote);
+ slctqrytmp = (char *)malloc(strlen(slctqry) + 1);
+ strcpy(slctqrytmp, slctqry);
+ }
+ free(slctqrytmp);
+
+ test_printf("the select query is:\n%s\n",slctqry);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)slctqry, SQL_NTS), stmt);
+
+ free(slctqry);
+
+ /* Fetch data from result of select statement */
+
+ i=0;
+ for (i; (rc = SQLFetch(stmt)) == SQL_SUCCESS; ++i)
+ {
+ CHECK_SQL_S(SQLGetData(stmt, 1, SQL_C_CHAR,
+ rsname[i], STRLEN, &len[i]), rc);
+ test_printf("users exist: %s\n",rsname[i]);
+ }
+ reset_statement(stmt);
+
+ /* Drop existing users */
+
+ for (i; i > 0; --i)
+ {
+ char *tmp;
+ char *drpqry;
+ tmp= "drop user ";
+ drpqry= (char *)malloc(strlen(tmp) +
+ strlen(rsname[i-1]) + 1);
+ strcpy(drpqry, tmp);
+ strcat(drpqry, rsname[i-1]);
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)drpqry, SQL_NTS), stmt);
+ test_printf("User %s dropped\n", rsname[i-1]);
+ reset_statement(stmt);
+ }
+
+ /* Build create users statement and execute this */
+
+ crtqry = "create user ";
+ crtqrytmp = (char *)malloc(strlen(crtqry) + strlen(name[0]) + 1);
+ strcpy(crtqrytmp, crtqry);
+ strcat(crtqrytmp, name[0]);
+
+ for (i= 1; i < 25; ++i)
+ {
+ char *tmp;
+ tmp = ", ";
+ crtqry = (char *)malloc(strlen(crtqrytmp) +
+ strlen(name[i]) +
+ strlen(tmp) + 1);
+ strcpy(crtqry, crtqrytmp);
+ strcat(crtqry, tmp);
+ strcat(crtqry, name[i]);
+ crtqrytmp = (char *)malloc(strlen(crtqry) + 1);
+ strcpy(crtqrytmp, crtqry);
+ }
+ free(crtqrytmp);
+
+ test_printf("the create query is:\n%s\n",crtqry);
+
+ CHECK_SQL_S(SQLExecDirect(stmt, (SQLCHAR *)crtqry, SQL_NTS), stmt);
+ free(crtqry);
+ free_statement(stmt);
+}
| Thread |
|---|
| • ODBC C-tests commit: r72 - trunk/testsuites/t_sql | sebrecht | 10 Apr |