I get the following error.
DB2/NT:-180[IBM][CLI Driver][DB2/NT] SQL0180N The syntax of the string representation of a datetime value is incorrect. SQLSTATE=22007
To look at Team Developer's ODBC log and trace, the values written below as "1> [3] 2011-03-01-00.00.00.000000" are set with SQLBindParameter. But according to DB2's ODBC trace file, the value is "2011-03-01 00:00" and the size of the value is 16, which are wrong. The value must be "2011-03-01-00.00.00.000000", and the length must be 26, if timestamp data type is created with precision 6.
I created a sample program and verified that SQLDescribeParam() and SQLBindParam() worked correctly.
DB2's ODBC trace file
-------------------------
( Row=1, iPar=3, fCType=SQL_C_CHAR, rgbValue="2011-03-01 00:00" - x'323031312D30332D30312030303A3030', pcbValue=16, piIndicatorPtr=16 )
( Row=1, iPar=4, fCType=SQL_C_CHAR, rgbValue="2011-03-01 00:00" - x'323031312D30332D30312030303A3030', pcbValue=16, piIndicatorPtr=16 )
Team Developer's ODBC log
-------------------------
Code: Select all
1> [compile] SELECT NAME FROM ( SELECT * FROM
1> XMTEIINNAI UNION SELECT '01','00',TO_DATE('200001','YYYYMM'),TO_
1> DATE('22221231','YYYYMMDD'), '9','xxxxxxxx',0,NULL,NULL,N
1> ULL,NULL FROM DUAL ) WHERE CCOMPKB = :1 AND CQTAIKEIKB
1> = :2 AND DSTART <= :3 AND DEND >= :4 AND CODE =
1> :5
1> [SQLFreeStmt] 82565176, 0
1> [SQLPrepare] 82565176, 94559992, -3
1> [SQLNumResultCols] 82565176
1> [SQLDescribeCol] 82565176, 1, 90611074, 89 [SQLBindCol] 82565176, 1,
1> -8, 90611224, 202, 0. FRW=1.
1> [get database parameter] param = 1004 [get database parameter] param
1> = 1004 [get database parameter] param = 1004 [execute] [1] 0 [2] 0
1> [3] 2011-03-01-00.00.00.000000 [4] 2011-03-01-00.00.00.000000 [5] 1
1> [SQLExecute] 82565176 [error] = DB2/NT:-180[IBM][CLI Driver][DB2/NT]
1> SQL0180N The syntax of the string representation of a datetime value
1> is incorrect. SQLSTATE=2
1> 2007
-------------------------
Code: Select all
UPRT0210 2d80-cac EXIT SQLBindParameter with return code 0
(SQL_SUCCESS)
HSTMT 0x04EBD838
UWORD 3
SWORD 1 <SQL_PARAM_INPUT>
SWORD 1 <SQL_C_CHAR>
SWORD 11 <SQL_TIMESTAMP>
SQLULEN 26
SWORD 0
PTR 0x05669FB0
SQLLEN 33
SQLLEN * 0x05A2DE0C (16)
...
UPRT0210 2d80-cac EXIT SQLBindParameter with return code 0
(SQL_SUCCESS)
HSTMT 0x04EBD838
UWORD 4
SWORD 1 <SQL_PARAM_INPUT>
SWORD 1 <SQL_C_CHAR>
SWORD 11 <SQL_TIMESTAMP>
SQLULEN 26
SWORD 0
PTR 0x05669FD8
SQLLEN 33
SQLLEN * 0x05A2DE6C (16)
...
sql.ini
Code: Select all
-------------------------
[win32client.dll]
comdll=sqlodb32
[win32client.odb32]
log=C:\odbc.log /Tx /Ld
[odbcrtr]
longbuffer=2048000
odbctrace=on
odbctracefile=C:\odbc_trace.log
remotedbname=SAMPLE,DSN=SAMPLE
servername=server1,sqlapipe
dbname=SJK,sqlapipe
-------------------
Code: Select all
#include <stdio.h>
#include <string.h>
/* #include <stdlib.h> */
/* #include <sqlutil.h> */
/* #include <sql.h> */
/* #include <sqlenv.h> */
#include <db2ApiDf.h>
/* #include <sqlcli.h> */
#include <sqlcli1.h>
void displayMessage(SQLSMALLINT handleType, SQLHANDLE handle);
void displayMessage(SQLSMALLINT handleType, SQLHANDLE handle)
{
int i;
char sqlstate[6];
int sqlcode;
char message[256];
SQLSMALLINT msg_len;
SQLRETURN rc;
i = 1;
while (((rc = SQLGetDiagRec(handleType, handle, i++, sqlstate, &sqlcode,
message, sizeof(message), &msg_len)) == SQL_SUCCESS) || (rc == SQL_SUCCESS_WITH_INFO)) {
printf("\tSQLSTATE = \"%s\"\n", sqlstate);
printf("\tSQLCODE = %d\n", sqlcode);
printf("\tmessage = \"%s\"\n", message);
}
}
int main()
{
SQLHANDLE henv; /* environment handle */
SQLHANDLE hdbc; /* connection handle */
SQLHANDLE hstmt;
SQLHANDLE hstmt2;
SQLRETURN rc;
SQLINTEGER c1;
SQLCHAR c2[21];
SQLCHAR c3[33];
SQLSMALLINT dataType;
SQLULEN parameterSize;
SQLSMALLINT decimalDigits;
SQLSMALLINT nullable;
rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
rc = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0);
rc = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
rc = SQLSetConnectAttr(hdbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, SQL_NTS);
rc = SQLConnect(hdbc, "SAMPLE", SQL_NTS, "user1", SQL_NTS, "password1", SQL_NTS);
if (rc != SQL_SUCCESS) {
displayMessage(SQL_HANDLE_DBC, hdbc);
}
rc = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
rc = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt2);
rc = SQLExecDirect(hstmt, "drop table t1", SQL_NTS);
rc = SQLExecDirect(hstmt, "create table t1 (c1 int not null primary key, c2 char(20), c3 timestamp(6))", SQL_NTS);
rc = SQLPrepare(hstmt, "insert into t1 values (?, ?, ?)", SQL_NTS);
rc = SQLDescribeParam(hstmt, 2, &dataType, ¶meterSize, &decimalDigits, &nullable);
printf("type=%d, parameterSize=%d, dicimalDegits=%d, nullable=%d\n",
dataType, parameterSize, decimalDigits, nullable);
c1 = 1;
strcpy(c2, "hello");
strcpy(c3, "2011-01-02-00.00.00.000000");
/* strcpy(c3, "2011-01-02"); */
printf("SQLBindParameter 1\n");
rc = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &c1, 0, NULL);
if (rc != SQL_SUCCESS) {
displayMessage(SQL_HANDLE_STMT, hstmt);
}
printf("SQLBindParameter 2\n");
rc = SQLBindParameter(hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 20, 0, c2, 21, NULL);
if (rc != SQL_SUCCESS) {
displayMessage(SQL_HANDLE_STMT, hstmt);
}
printf("SQLBindParameter 3\n");
rc = SQLBindParameter(hstmt, 3, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_TIMESTAMP, 26, 0, c3, 33, NULL);
if (rc != SQL_SUCCESS) {
displayMessage(SQL_HANDLE_STMT, hstmt);
}
printf("SQLExecute\n");
rc = SQLExecute(hstmt);
if (rc != SQL_SUCCESS) {
displayMessage(SQL_HANDLE_STMT, hstmt);
}
/* rc = SQLExecDirect(hstmt2, "select * from t1 where c3=?", SQL_NTS); */
rc = SQLPrepare(hstmt2, "select * from t1 where c3>?", SQL_NTS);
strcpy(c3, "2011-01-01-00.00.00.000000");
rc = SQLBindParameter(hstmt2, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_TIMESTAMP, 26, 0, c3, 33, NULL);
if (rc != SQL_SUCCESS) {
displayMessage(SQL_HANDLE_STMT, hstmt2);
}
rc = SQLExecute(hstmt2);
if (rc != SQL_SUCCESS) {
displayMessage(SQL_HANDLE_STMT, hstmt2);
}
rc = SQLBindCol(hstmt2, 1, SQL_C_LONG, &c1, 0, NULL);
rc = SQLBindCol(hstmt2, 2, SQL_C_CHAR, c2, sizeof(c2), NULL);
rc = SQLBindCol(hstmt2, 3, SQL_C_CHAR, c3, sizeof(c3), NULL);
while ((rc = SQLFetch(hstmt2)) != SQL_NO_DATA_FOUND) {
printf("%d, \"%s\", \"%s\"\n", c1, c2, c3);
}
rc = SQLFreeStmt(hstmt, SQL_UNBIND);
rc = SQLFreeStmt(hstmt, SQL_RESET_PARAMS);
rc = SQLFreeStmt(hstmt, SQL_CLOSE);
rc = SQLFreeStmt(hstmt2, SQL_UNBIND);
rc = SQLFreeStmt(hstmt2, SQL_RESET_PARAMS);
rc = SQLFreeStmt(hstmt2, SQL_CLOSE);
rc = SQLEndTran(SQL_HANDLE_DBC, hdbc, SQL_COMMIT);
rc = SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
rc = SQLFreeHandle(SQL_HANDLE_STMT, hstmt2);
rc = SQLDisconnect(hdbc);
rc = SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
rc = SQLFreeHandle(SQL_HANDLE_ENV, henv);
return rc;
}