/* BUG 18079 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[255]; 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 mytable;", 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 mytable ( " "AutoSequencial bigint(20) unsigned NOT NULL auto_increment," "Status tinyint(3) unsigned zerofill NOT NULL default 0," "CMC7 binary(15) NOT NULL default 0," "Chave binary(15) NOT NULL default 0, " "Valor bigint(20) unsigned NOT NULL default 0," "DataVenc smallint(5) unsigned NOT NULL default 0," "CpfCnpj bigint(20) unsigned NOT NULL default 0," "TipCust tinyint(3) unsigned NOT NULL default 0," "Motivo tinyint(3) unsigned NOT NULL default 0, " "Controle binary(6) NOT NULL default 0, " "AgenDep smallint(5) unsigned NOT NULL default 0, " "ContaDep binary(6) NOT NULL default 0, " "BancoA smallint(5) unsigned NOT NULL default 0," "AgenA smallint(5) unsigned NOT NULL default 0, " "LoteIn int(10) unsigned NOT NULL default 0, " "RemessaIn int(10) unsigned NOT NULL default 0," "RemessaOut int(10) unsigned NOT NULL default 0," "DataIn smallint(5) unsigned NOT NULL default 0," "CodCli int(10) unsigned NOT NULL default 0," "CodIncon smallint(5) unsigned NOT NULL default 0," "SeqCap int(10) unsigned NOT NULL default 0," "LoteSai int(10) unsigned NOT NULL default 0, " "Banco smallint(5) unsigned NOT NULL default 0, " "Agencia smallint(5) unsigned NOT NULL default 0, " "Conta bigint(20) unsigned NOT NULL default 0," "Numero int(10) unsigned NOT NULL default 0," "Alterado tinyint(1) unsigned NOT NULL default 0," "Bloqueado tinyint(1) unsigned NOT NULL default 0," "Cancelado tinyint(1) unsigned NOT NULL default 0," "CancelProg tinyint(1) unsigned NOT NULL default 0, " "Digitado tinyint(1) unsigned NOT NULL default 0, " "DocNAK tinyint(1) unsigned NOT NULL default 0, " "DocNOK tinyint(1) unsigned NOT NULL default 0, " "Duplicado tinyint(1) unsigned NOT NULL default 0," "Escaninho smallint(5) unsigned NOT NULL default 0, " "Logado tinyint(1) unsigned NOT NULL default 0, " "Vistar tinyint(1) unsigned NOT NULL default 0, " "InfoCtrl binary(2) NOT NULL default 0, " "InfoImg binary(16) NOT NULL default 0, " "EstacaoLock smallint(5) unsigned NOT NULL default 0, " "Comp smallint(5) unsigned NOT NULL default 0," "PRIMARY KEY(AutoSequencial), " "KEY Numero (Numero), " "KEY CpfCnpj (CpfCnpj), " "KEY Chave (Chave)," "KEY LinhaSup (Banco,Agencia,Conta,Numero)" ") ENGINE=InnoDB DEFAULT CHARSET=latin1 CHECKSUM=1;", SQL_NTS), "SQLExecDirect(create)" ); CHECKRC( SQLFreeStmt(hStmt, SQL_DROP), "SQLFreeStmt()" ); } void doTest() { } int main(int argc, char** argv) { int nPrompt = SQL_DRIVER_NOPROMPT; if (argc > 2 && strlen(argv[1]) != 0 && strlen(argv[2]) != 0) sprintf(connString, "DRIVER=MySQL ODBC 3.51 Driver;Database=%s;USER=%s;PWD=%s;", argv[1], argv[2], argc>3 ? argv[3]:""); 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); }