Changeset: c523fcaf38cf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c523fcaf38cf
Modified Files:
clients/odbc/tests/ODBCtester.c
Branch: default
Log Message:
Add utility function retrieveDiagMsg() to retrieve a warning or error msg and
normalizes the ODBC Driver version numbers in the msg.
This is needed to get a static output also for future versions.
diffs (95 lines):
diff --git a/clients/odbc/tests/ODBCtester.c b/clients/odbc/tests/ODBCtester.c
--- a/clients/odbc/tests/ODBCtester.c
+++ b/clients/odbc/tests/ODBCtester.c
@@ -17,6 +17,7 @@
#include <string.h>
#include <sql.h>
#include <sqlext.h>
+#include <ctype.h>
#include <inttypes.h>
#include <wchar.h>
@@ -75,6 +76,29 @@ check(SQLRETURN ret, SQLSMALLINT tpe, SQ
}
}
+static size_t
+retrieveDiagMsg(SQLHANDLE stmt, char * outp, size_t outp_len)
+{
+ SQLCHAR state[6];
+ SQLINTEGER errnr = 0;
+ char msg[256];
+ SQLSMALLINT msglen = 0;
+ SQLRETURN ret = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, state, &errnr,
(SQLCHAR *) msg, sizeof(msg), &msglen);
+ if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) {
+ /* The message layout is: "[MonetDB][ODBC Driver
11.46.0][MonetDB-Test]error/warning text".
+ The ODBC driver version numbers changes in time. Overwrite
it to get a stable output */
+ if (strncmp(msg, "[MonetDB][ODBC Driver 11.", 25) == 0) {
+ for (int i = 25; msg[i] != ']'; i++) {
+ if (isdigit(msg[i])) {
+ msg[i] = '#';
+ }
+ }
+ }
+ return snprintf(outp, outp_len, "SQLstate %s, Errnr %d, Message
%s\n", (char*)state, (int)errnr, (char*)msg);
+ }
+ return 0;
+}
+
static void
compareResult(char * testname, char * testresult, char * expected)
{
@@ -142,12 +166,7 @@ testGetDataTruncatedString(SQLHANDLE stm
pos += snprintf(outp + pos, outp_len - pos, "SQLGetData(%d, %s,
20) returns %d, vallen " LLFMT ", buf: '%s'\n", col, ctype_str, ret, (int64_t)
vallen, buf);
/* we expect SQL_SUCCESS_WITH_INFO with warning msg set, fetch
them */
if (ret == SQL_SUCCESS_WITH_INFO) {
- SQLCHAR state[6];
- SQLINTEGER errnr;
- SQLCHAR msg[256];
- SQLSMALLINT msglen;
- ret = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1, state,
&errnr, msg, sizeof(msg), &msglen);
- pos += snprintf(outp + pos, outp_len - pos, "SQLstate
%s, Errnr %d, Message %s\n", (char*)state, (int)errnr, (char*)msg);
+ pos += retrieveDiagMsg(stmt, outp + pos, outp_len -
pos);
/* get the next data part of the value (this is how
SQLGetData is intended to be used to get large data in chunks) */
ret = SQLGetData(stmt, (UWORD)col, (SWORD)ctype, ctype
== SQL_C_WCHAR ? (PTR)&wbuf2 : (PTR)&buf2, (SQLLEN)30, &vallen);
@@ -158,8 +177,8 @@ testGetDataTruncatedString(SQLHANDLE stm
}
pos += snprintf(outp + pos, outp_len - pos,
"SQLGetData(%d, %s, 30) returns %d, vallen " LLFMT ", buf: '%s'\n", col,
ctype_str, ret, (int64_t) vallen, buf2);
if (ret == SQL_SUCCESS_WITH_INFO) {
- ret = SQLGetDiagRec(SQL_HANDLE_STMT, stmt, 1,
state, &errnr, msg, sizeof(msg), &msglen);
- pos += snprintf(outp + pos, outp_len - pos,
"SQLstate %s, Errnr %d, Message %s\n", (char*)state, (int)errnr, (char*)msg);
+ pos += retrieveDiagMsg(stmt, outp + pos,
outp_len - pos);
+ ret = SQL_SUCCESS;
}
}
check(ret, SQL_HANDLE_STMT, stmt, "SQLGetData(col)");
@@ -168,23 +187,23 @@ testGetDataTruncatedString(SQLHANDLE stm
if (ctype == SQL_C_CHAR) {
compareResult("testGetDataTruncatedString(SQL_C_CHAR)", outp,
"SQLExecDirect\nSQLRowCount is 1\nSQLNumResultCols is
1\nSQLFetch\n"
- "SQLColAttribute(1, SQL_DESC_CONCISE_TYPE) returns 0,
NumAttr -10\n"
+ "SQLColAttribute(1, SQL_DESC_CONCISE_TYPE) returns 0,
NumAttr -10\n" /* -10 = SQL_WLONGVARCHAR */
"SQLColAttribute(1, SQL_DESC_LENGTH) returns 0, NumAttr
47\n"
"SQLColAttribute(1, SQL_DESC_DISPLAY_SIZE) returns 0,
NumAttr 47\n"
"SQLGetData(1, SQL_C_CHAR, 20) returns 1, vallen 47,
buf: '1234567890123456789'\n"
- "SQLstate 01004, Errnr 0, Message [MonetDB][ODBC Driver
11.46.0][MonetDB-Test]String data, right truncated\n"
+ "SQLstate 01004, Errnr 0, Message [MonetDB][ODBC Driver
11.##.#][MonetDB-Test]String data, right truncated\n"
"SQLGetData(1, SQL_C_CHAR, 30) returns 0, vallen 28,
buf: '0 abcdefghijklmnopqrstuvwxyz'\n");
} else
if (ctype == SQL_C_WCHAR) {
compareResult("testGetDataTruncatedString(SQL_C_WCHAR)", outp,
"SQLExecDirect\nSQLRowCount is 1\nSQLNumResultCols is
1\nSQLFetch\n"
- "SQLColAttribute(1, SQL_DESC_CONCISE_TYPE) returns 0,
NumAttr -10\n"
+ "SQLColAttribute(1, SQL_DESC_CONCISE_TYPE) returns 0,
NumAttr -10\n" /* -10 = SQL_WLONGVARCHAR */
"SQLColAttribute(1, SQL_DESC_LENGTH) returns 0, NumAttr
47\n"
"SQLColAttribute(1, SQL_DESC_DISPLAY_SIZE) returns 0,
NumAttr 47\n"
"SQLGetData(1, SQL_C_WCHAR, 20) returns 1, vallen 94,
buf: ''\n"
- "SQLstate 01004, Errnr 0, Message [MonetDB][ODBC Driver
11.46.0][MonetDB-Test]String data, right truncated\n"
+ "SQLstate 01004, Errnr 0, Message [MonetDB][ODBC Driver
11.##.#][MonetDB-Test]String data, right truncated\n"
"SQLGetData(1, SQL_C_WCHAR, 30) returns 1, vallen 76,
buf: ''\n"
- "SQLstate 01004, Errnr 0, Message [MonetDB][ODBC Driver
11.46.0][MonetDB-Test]String data, right truncated\n");
+ "SQLstate 01004, Errnr 0, Message [MonetDB][ODBC Driver
11.##.#][MonetDB-Test]String data, right truncated\n");
}
/* cleanup */
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]