Modify wchar-char test so that it handles parameters which are not properly null...
authorHiroshi Inoue <h-inoue@dream.email.ne.jp>
Sat, 22 Jul 2017 03:06:00 +0000 (12:06 +0900)
committerHiroshi Inoue <h-inoue@dream.email.ne.jp>
Sat, 22 Jul 2017 05:47:47 +0000 (14:47 +0900)
test/expected/wchar-char_2.out
test/src/wchar-char-test-eucjp.c
test/src/wchar-char-test-sjis.c
test/src/wchar-char-test-utf8.c
test/src/wchar-char-test.c

index 591714560ae7ed9fd83aaff3a20fb5ff9d7f68fb..a4b50ca4603c0c9ea0199b473b88cf70735654ba 100755 (executable)
@@ -1 +1,6 @@
-Unfortunately can't handle this locale
+Unfortunately this program can't handle this locale
+Or you are testing an ansi driver
+Anyway bypass this program
+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
index 17c9bbf0dd0f8efc1d3e5d700fa510fb7f15faa1..38c974cce86d02c876abdfad6152186a77d3ba2f 100644 (file)
@@ -4,7 +4,9 @@ static int eucjp_test(HSTMT hstmt)
    int rc;
 
    SQLLEN      ind, cbParam, cbParam2;
+   SQLINTEGER  cbQueryLen;
    unsigned char   lovedt[100] = {0x95, 0x4e, 0x0a, 0x4e, 0x5a, 0x53, 0xf2, 0x53, 0x0, 0x0};
+   unsigned char   lovedt2[100] = {0xf2, 0x53, 0x5a, 0x53, 0x0a, 0x4e, 0x95, 0x4e, 0x0, 0x0};
    SQLWCHAR    wchar[100];
    SQLCHAR     str[100];
    SQLCHAR     chardt[100];
@@ -13,7 +15,9 @@ static int eucjp_test(HSTMT hstmt)
    rc = SQLBindCol(hstmt, 1, SQL_C_CHAR, (SQLPOINTER) chardt, sizeof(chardt), &ind);
    CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_CHAR failed", hstmt);
 
-   cbParam = SQL_NTS;
+   // cbParam = SQL_NTS;
+   cbParam = strlen(lovedt);
+   strcat(lovedt, lovedt2);
    rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
        SQL_C_WCHAR,    /* value type */
        SQL_WCHAR,          /* param type */
@@ -23,11 +27,15 @@ static int eucjp_test(HSTMT hstmt)
        sizeof(lovedt),         /* buffer len */
        &cbParam    /* StrLen_or_IndPtr */);
    CHECK_STMT_RESULT(rc, "SQLBindParameter 1 failed", hstmt);
-   cbParam2 = SQL_NTS;
+   // cbParam2 = SQL_NTS;
+   strncpy((char *) str, "ÀÆÆ£¹À", sizeof(str));
+   cbParam2 = strlen(str);
+   strcat((char *) str, "¿®¸¼");
    rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(str), 0, str, sizeof(str), &cbParam2);
    CHECK_STMT_RESULT(rc, "SQLBindParameter 2 failed", hstmt);
-   strncpy((char *) str, "ÀÆÆ£¹À", sizeof(str));
-   rc = SQLExecDirect(hstmt, query, SQL_NTS);
+   cbQueryLen = (SQLINTEGER) strlen(query);
+   strcat((char *) query, "¿®¸¼");
+   rc = SQLExecDirect(hstmt, query, cbQueryLen);
    CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_CHAR", hstmt);
    while (SQL_SUCCEEDED(SQLFetch(hstmt)))
        printf("ANSI=%s\n", chardt);
@@ -38,7 +46,7 @@ static int eucjp_test(HSTMT hstmt)
    CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_WCHAR failed", hstmt);
 
 
-   rc = SQLExecDirect(hstmt, query, SQL_NTS);
+   rc = SQLExecDirect(hstmt, query, cbQueryLen);
    CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_WCHAR", hstmt);
    while (SQL_SUCCEEDED(rc = SQLFetch(hstmt)))
    {
index 0078aed2faf33a3fca069f89613a401534d4368c..34ea0d7d8121c70315aef9578d809664937db6db 100644 (file)
@@ -4,16 +4,20 @@ static int sjis_test(HSTMT hstmt)
    int rc;
 
    SQLLEN      ind, cbParam, cbParam2;
+   SQLINTEGER  cbQueryLen;
    unsigned char   lovedt[100] = {0x95, 0x4e, 0x0a, 0x4e, 0x5a, 0x53, 0xf2, 0x53, 0x0, 0x0};
+   unsigned char   lovedt2[100] = {0xf2, 0x53, 0x5a, 0x53, 0x0a, 0x4e, 0x95, 0x4e, 0x0, 0x0};
    SQLWCHAR    wchar[100];
    SQLCHAR     str[100];
    SQLCHAR     chardt[100];
-   SQLTCHAR    query[] = _T("select '\8e\84\82Í' || ?::text || '\82Å\82·\81B\8bM\95û\82Í' || ?::text || '\82³\82ñ\82Å\82·\82Ë\81H'");
+   SQLTCHAR    query[200] = _T("select '\8e\84\82Í' || ?::text || '\82Å\82·\81B\8bM\95û\82Í' || ?::text || '\82³\82ñ\82Å\82·\82Ë\81H'");
 
    rc = SQLBindCol(hstmt, 1, SQL_C_CHAR, (SQLPOINTER) chardt, sizeof(chardt), &ind);
    CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_CHAR failed", hstmt);
 
-   cbParam = SQL_NTS;
+   // cbParam = SQL_NTS;
+   cbParam = strlen(lovedt);
+   strcat(lovedt, lovedt2);
    rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
        SQL_C_WCHAR,    /* value type */
        SQL_WCHAR,          /* param type */
@@ -22,12 +26,16 @@ static int sjis_test(HSTMT hstmt)
        lovedt,     // param1,      /* param value ptr */
        sizeof(lovedt),         /* buffer len */
        &cbParam    /* StrLen_or_IndPtr */);
-   CHECK_STMT_RESULT(rc, "SQLBindParameter 1 failed", hstmt);
-   cbParam2 = SQL_NTS;
+       CHECK_STMT_RESULT(rc, "SQLBindParameter 1 failed", hstmt);
+   // cbParam2 = SQL_NTS; 
+   strncpy((char *) str, "\90Ä\93¡\8d_", sizeof(str));
+   cbParam2 = strlen(str);
+   strcat((char *) str, "\90M\92·");
    rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(str), 0, str, sizeof(str), &cbParam2);
    CHECK_STMT_RESULT(rc, "SQLBindParameter 2 failed", hstmt);
-   strncpy((char *) str, "\90Ä\93¡\8d_", sizeof(str));
-   rc = SQLExecDirect(hstmt, query, SQL_NTS);
+   cbQueryLen = (SQLINTEGER) strlen(query);
+   strcat((char *) query, "\82¾\82æ\81[\82ñ");
+   rc = SQLExecDirect(hstmt, query, cbQueryLen);
    CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_CHAR", hstmt);
    while (SQL_SUCCEEDED(SQLFetch(hstmt)))
        printf("ANSI=%s\n", chardt);
@@ -38,7 +46,7 @@ static int sjis_test(HSTMT hstmt)
    CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_WCHAR failed", hstmt);
 
 
-   rc = SQLExecDirect(hstmt, query, SQL_NTS);
+   rc = SQLExecDirect(hstmt, query, cbQueryLen);
    CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_WCHAR", hstmt);
    while (SQL_SUCCEEDED(rc = SQLFetch(hstmt)))
    {
index 88c531face4241fea6d3f8f908f4312b1d01829a..de6af048085cde222726c7d45c2d320bbd2b719e 100644 (file)
@@ -4,7 +4,9 @@ static int utf8_test_one(HSTMT hstmt)
    int rc;
 
    SQLLEN      ind, cbParam, cbParam2;
+   SQLINTEGER  cbQueryLen;
    unsigned char   lovedt[100] = {0x95, 0x4e, 0x0a, 0x4e, 0x5a, 0x53, 0xf2, 0x53, 0x0, 0x0};
+   unsigned char   lovedt2[100] = {0xf2, 0x53, 0x5a, 0x53, 0x0a, 0x4e, 0x95, 0x4e, 0x0, 0x0};
    SQLWCHAR    wchar[100];
    SQLCHAR     str[100];
    SQLCHAR     chardt[100];
@@ -14,7 +16,9 @@ static int utf8_test_one(HSTMT hstmt)
    rc = SQLBindCol(hstmt, 1, SQL_C_CHAR, (SQLPOINTER) chardt, sizeof(chardt), &ind);
    CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_CHAR failed", hstmt);
 
-   cbParam = SQL_NTS;
+   // cbParam = SQL_NTS;
+   cbParam = strlen(lovedt);
+   strcat(lovedt, lovedt2);
    rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT,
        SQL_C_WCHAR,    /* value type */
        SQL_WCHAR,          /* param type */
@@ -24,11 +28,15 @@ static int utf8_test_one(HSTMT hstmt)
        sizeof(lovedt),         /* buffer len */
        &cbParam    /* StrLen_or_IndPtr */);
    CHECK_STMT_RESULT(rc, "SQLBindParameter 1 failed", hstmt);
-   cbParam2 = SQL_NTS;
+   // cbParam2 = SQL_NTS;
+   strncpy((char *) str, "斉藤浩", sizeof(str));
+   cbParam2 = strlen(str);
+   strcat((char *) str, "斉藤浩");
    rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(str), 0, str, sizeof(str), &cbParam2);
    CHECK_STMT_RESULT(rc, "SQLBindParameter 2 failed", hstmt);
-   strncpy((char *) str, "斉藤浩", sizeof(str));
-   rc = SQLExecDirect(hstmt, query, SQL_NTS);
+   cbQueryLen = (SQLINTEGER) strlen(query);
+   strcat((char *) query, "斉藤浩");
+   rc = SQLExecDirect(hstmt, query, cbQueryLen);
    CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_CHAR", hstmt);
    while (SQL_SUCCEEDED(SQLFetch(hstmt)))
        printf("ANSI=%s\n", chardt);
@@ -39,7 +47,7 @@ static int utf8_test_one(HSTMT hstmt)
    CHECK_STMT_RESULT(rc, "SQLBindCol to SQL_C_WCHAR failed", hstmt);
 
 
-   rc = SQLExecDirect(hstmt, query, SQL_NTS);
+   rc = SQLExecDirect(hstmt, query, cbQueryLen);
    CHECK_STMT_RESULT(rc, "SQLExecDirect failed to return SQL_C_WCHAR", hstmt);
    while (SQL_SUCCEEDED(rc = SQLFetch(hstmt)))
    {
index 32f37b5ab54cd1a6a649410b3dae0a23488d6c3b..9553edf8d5ef11480a947bcef1b8d10b1e7eb300 100644 (file)
@@ -81,7 +81,12 @@ int main(int argc, char **argv)
    }
    if (testsw < 0)
    {
-       printf("Unfortunately can't handle this locale\n");
+       printf("Unfortunately this program can't handle this locale\n");
+       printf("Or you are testing an ansi driver\n");
+       printf("Anyway bypass this program\n");
+       printf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n");
+       printf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n");
+       printf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n");
        exit(0);
    }
    test_connect_ext("");