static int Test(int direct) { SQLTCHAR buf[256]; SQLTCHAR sqlstate[6]; odbc_connect(); if (!close_last_socket()) { fprintf(stderr, "Error closing connection\n"); return 1; } /* force disconnection closing socket */ if (direct) { CHKExecDirect(T("SELECT 1"), SQL_NTS, "E"); } else { SQLSMALLINT cols; /* use prepare, force dialog with server */ if (CHKPrepare(T("SELECT 1"), SQL_NTS, "SE") == SQL_SUCCESS) CHKNumResultCols(&cols, "E"); } CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, 1, sqlstate, NULL, buf, ODBC_VECTOR_SIZE(buf), NULL, "SI"); sqlstate[5] = 0; printf("state=%s err=%s\n", C(sqlstate), C(buf)); odbc_disconnect(); printf("Done.\n"); return 0; }
int main(int argc, char *argv[]) { SQLSMALLINT num_params, cols; SQLLEN count; SQLINTEGER id; odbc_use_version3 = 1; odbc_connect(); odbc_command("create table #tester (id int not null, name varchar(20) not null)"); odbc_command("insert into #tester(id, name) values(1, 'abc')"); odbc_command("insert into #tester(id, name) values(2, 'duck')"); CHKPrepare(T("SELECT * FROM #tester WHERE id = ?"), SQL_NTS, "S"); CHKR(SQLNumParams, (odbc_stmt, &num_params), "S"); assert(num_params == 1); id = 1; CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &id, sizeof(id), NULL, "S"); CHKExecute("S"); CHKR(SQLFreeStmt, (odbc_stmt, SQL_RESET_PARAMS), "S"); CHKRowCount(&count, "S"); CHKNumResultCols(&cols, "S"); assert(cols == 2); odbc_disconnect(); return 0; }
void odbc_check_cols(int n, int line, const char * file) { SQLSMALLINT cols; if (n < 0) { CHKNumResultCols(&cols, "E"); return; } CHKNumResultCols(&cols, "S"); if (cols != n) { fprintf(stderr, "%s:%d: Expected %d columns returned %d\n", file, line, n, (int) cols); odbc_disconnect(); exit(1); } }
static int Test(int direct) { SQLTCHAR buf[256]; SQLTCHAR sqlstate[6]; time_t start_time, end_time; odbc_mark_sockets_opened(); odbc_connect(); if (!shutdown_last_socket()) { fprintf(stderr, "Error shutting down connection\n"); return 1; } CHKSetStmtAttr(SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER) 10, SQL_IS_UINTEGER, "S"); alarm(30); start_time = time(NULL); if (direct) { CHKExecDirect(T("SELECT 1"), SQL_NTS, "E"); } else { SQLSMALLINT cols; /* force dialog with server */ if (CHKPrepare(T("SELECT 1"), SQL_NTS, "SE") == SQL_SUCCESS) CHKNumResultCols(&cols, "E"); } end_time = time(NULL); alarm(0); memset(sqlstate, 'X', sizeof(sqlstate)); CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, 1, sqlstate, NULL, buf, ODBC_VECTOR_SIZE(buf), NULL, "SI"); sqlstate[5] = 0; printf("Message: %s - %s\n", C(sqlstate), C(buf)); if (strcmp(C(sqlstate), "HYT00") || !strstr(C(buf), "Timeout")) { fprintf(stderr, "Invalid timeout message\n"); return 1; } if (end_time - start_time < 10 || end_time - start_time > 26) { fprintf(stderr, "Unexpected connect timeout (%d)\n", (int) (end_time - start_time)); return 1; } odbc_disconnect(); if (end_socket >= 0) close(end_socket); printf("Done.\n"); return 0; }
static void CheckNoRow(const char *query) { SQLRETURN rc; rc = CHKExecDirect(T(query), SQL_NTS, "SINo"); if (rc == SQL_NO_DATA) return; do { SQLSMALLINT cols; CHKNumResultCols(&cols, "S"); if (cols != 0) { fprintf(stderr, "Data not expected here, query:\n\t%s\n", query); exit(1); } } while (CHKMoreResults("SNo") == SQL_SUCCESS); }