/* BUG 10141 test case */ #include #include #include #include #include #include void CheckRC(SQLRETURN rc, char* msg, char* filename, int lineno); #define CHECKRC(FUNCSHN,MSG) CheckRC(FUNCSHN, MSG, __FILE__, __LINE__) SQLHENV hEnv = SQL_NULL_HENV; SQLHDBC hDbc = SQL_NULL_HDBC; SQLHSTMT hStmt = SQL_NULL_HSTMT; SQLCHAR* connString; SQLCHAR connOut[255]; /* buffer for connection output */ SQLSMALLINT szConnOut; /* num bytes returned in connOut */ SQLINTEGER Version = SQL_OV_ODBC3; void doDrop() { printf("Drop....\n"); CHECKRC( SQLAllocStmt(hDbc, &hStmt), "SQLAllocStmt()" ); CHECKRC( SQLExecDirect(hStmt, (SQLCHAR*)"USE TEST", SQL_NTS), "SQLExecDirect()" ); CHECKRC( SQLExecDirect(hStmt, (SQLCHAR*)"DROP TABLE IF EXISTS BUG10141", SQL_NTS), "SQLExecDirect()" ); CHECKRC( SQLFreeStmt(hStmt, SQL_DROP), "SQLFreeStmt()" ); } void doCreate() { printf("Create....\n"); CHECKRC( SQLAllocStmt(hDbc, &hStmt), "SQLAllocStmt()" ); CHECKRC( SQLExecDirect(hStmt, (SQLCHAR*)"CREATE TABLE BUG10141 " "(F1 int," " F2 int," " F3 int," " F4 int," " F5 int," " F6 int," " F7 int," " F8 int," " F9 int," " F10 int," " F11 int," " F12 int," " F13 int," " F14 int," " F15 int," " F16 int," " F17 int," " F18 int) TYPE=MyISAM;", SQL_NTS), "SQLExecDirect(create)" ); CHECKRC( SQLExecDirect(hStmt, (SQLCHAR*)"INSERT INTO BUG10141 VALUES(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18);", SQL_NTS), "SQLExecDirect(insert)" ); CHECKRC( SQLFreeStmt(hStmt, SQL_DROP), "SQLFreeStmt()" ); } void doTest() { SQLCHAR *pszSQL = "SELECT * FROM BUG10141"; SQLINTEGER F1; SQLINTEGER F2; SQLINTEGER F3; SQLINTEGER F4; SQLINTEGER F5; SQLINTEGER F6; SQLINTEGER F7; SQLINTEGER F8; SQLINTEGER F9; SQLINTEGER F10; SQLINTEGER F11; SQLINTEGER F12; SQLINTEGER F13; SQLINTEGER F14; SQLINTEGER F15; SQLINTEGER F16; SQLINTEGER F17; SQLINTEGER F18; SQLINTEGER L1; SQLINTEGER L2; SQLINTEGER L3; SQLINTEGER L4; SQLINTEGER L5; SQLINTEGER L6; SQLINTEGER L7; SQLINTEGER L8; SQLINTEGER L9; SQLINTEGER L10; SQLINTEGER L11; SQLINTEGER L12; SQLINTEGER L13; SQLINTEGER L14; SQLINTEGER L15; SQLINTEGER L16; SQLINTEGER L17; SQLINTEGER L18; printf("Test....\n"); CHECKRC( SQLAllocStmt(hDbc, &hStmt), "SQLAllocStmt()" ); // CHECKRC(SQLExecDirect(hStmt,pszSQL, SQL_NTS),"SQLExecDirect()"); printf("Get columns....\n"); CHECKRC( SQLColumns(hStmt,NULL, 0, NULL, 0, "BUG10141", SQL_NTS, NULL, 0), "SQLColumns()"); printf("Bind columns....\n"); CHECKRC( SQLBindCol(hStmt,1,SQL_C_SLONG,&F1,0,&L1), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,2,SQL_C_SLONG,&F2,0,&L2), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,3,SQL_C_SLONG,&F3,0,&L3), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,4,SQL_C_SLONG,&F4,0,&L4), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,5,SQL_C_SLONG,&F5,0,&L5), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,6,SQL_C_SLONG,&F6,0,&L6), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,7,SQL_C_SLONG,&F7,0,&L7), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,8,SQL_C_SLONG,&F8,0,&L8), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,9,SQL_C_SLONG,&F9,0,&L9), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,10,SQL_C_SLONG,&F10,0,&L10), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,11,SQL_C_SLONG,&F11,0,&L11), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,12,SQL_C_SLONG,&F12,0,&L12), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,13,SQL_C_SLONG,&F13,0,&L13), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,14,SQL_C_SLONG,&F14,0,&L14), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,15,SQL_C_SLONG,&F15,0,&L15), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,16,SQL_C_SLONG,&F16,0,&L16), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,17,SQL_C_SLONG,&F17,0,&L17), "SQLBindCol()" ); CHECKRC( SQLBindCol(hStmt,18,SQL_C_SLONG,&F18,0,&L18), "SQLBindCol()" ); CHECKRC( SQLFetch(hStmt), "SQLFetch()" ); printf("Index = %i, Value = %i,Length = %i\n",1,F1,L1); printf("Index = %i, Value = %i,Length = %i\n",2,F2,L2); printf("Index = %i, Value = %i,Length = %i\n",3,F3,L3); printf("Index = %i, Value = %i,Length = %i\n",4,F4,L4); printf("Index = %i, Value = %i,Length = %i\n",5,F5,L5); printf("Index = %i, Value = %i,Length = %i\n",6,F6,L6); printf("Index = %i, Value = %i,Length = %i\n",7,F7,L7); printf("Index = %i, Value = %i,Length = %i\n",8,F8,L8); printf("Index = %i, Value = %i,Length = %i\n",9,F9,L9); printf("Index = %i, Value = %i,Length = %i\n",10,F10,L10); printf("Index = %i, Value = %i,Length = %i\n",11,F11,L11); printf("Index = %i, Value = %i,Length = %i\n",12,F12,L12); printf("Index = %i, Value = %i,Length = %i\n",13,F13,L13); printf("Index = %i, Value = %i,Length = %i\n",14,F14,L14); printf("Index = %i, Value = %i,Length = %i\n",15,F15,L15); printf("Index = %i, Value = %i,Length = %i\n",16,F16,L16); printf("Index = %i, Value = %i,Length = %i\n",17,F17,L17); printf("Index = %i, Value = %i,Length = %i\n",18,F18,L18); CHECKRC( SQLFreeStmt(hStmt, SQL_DROP), "SQLFreeStmt()" ); } int main(int argc, char** argv) { int nPrompt = SQL_DRIVER_NOPROMPT; if (argc < 2 || strlen(argv[1]) == 0) { connString = (SQLCHAR *)"DRIVER=MySQL ODBC 3.51 Driver;"; } else connString = (SQLCHAR *)argv[1]; if (SQLAllocEnv(&hEnv) != SQL_SUCCESS) { fprintf(stderr, "Unable to allocate SQLHENV\n"); return(1); } printf("Connect....\n"); SQLAllocEnv(&hEnv); CHECKRC( SQLSetEnvAttr(hEnv,SQL_ATTR_ODBC_VERSION,Version,0 ), "SQLSetEnvAttr()" ); CHECKRC( SQLAllocConnect(hEnv, &hDbc), "SQLAllocConnect()" ); CHECKRC( SQLDriverConnect(hDbc, (HWND)0, connString, SQL_NTS, connOut, 255, &szConnOut, nPrompt), "SQLDriverConnect()" ); doDrop(); doCreate(); doTest(); printf("Disconnect....\n"); CHECKRC( SQLDisconnect(hDbc), "SQLDisconnect()" ); CHECKRC( SQLFreeConnect(hDbc), "SQLFreeConnect()" ); CHECKRC( SQLFreeEnv(hEnv), "SQLFreeEnv()" ); return 0; } void CheckRC(SQLRETURN rc, char* msg, char* filename, int lineno) { #define MSG_LNG 512 SQLCHAR szSqlState[MSG_LNG]; SQLINTEGER pfNativeError; SQLCHAR szErrorMsg[MSG_LNG]; SQLSMALLINT pcbErrorMsg; SQLRETURN ret = SQL_SUCCESS; int error = 0; if (rc != SQL_SUCCESS && rc != SQL_NO_DATA_FOUND) { if (rc != SQL_SUCCESS_WITH_INFO) { fprintf(stderr, "\nERROR (%s:%d): %s\n", filename, lineno, msg); error = 1; } while (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO) { ret = SQLError(hEnv, hDbc, hStmt, szSqlState, &pfNativeError, szErrorMsg, MSG_LNG, &pcbErrorMsg); switch (ret) { case SQL_SUCCESS: if (rc == SQL_SUCCESS_WITH_INFO) { fprintf(stderr, "\nINFO: (%s:%d): %s\n", filename, lineno, msg); } fprintf(stderr, "*** %s\n*** ODBC Code: %s, " "Driver Code: %ld\n\n", szErrorMsg, szSqlState, pfNativeError); break; case SQL_NO_DATA_FOUND: break; default: fprintf(stderr, "*** SQLError() failed with code=%d\n\n", ret); break; } } } if (error) exit(1); }