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(void) { odbc_use_version3 = 1; odbc_mark_sockets_opened(); odbc_connect(); CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, (void *) SQL_AUTOCOMMIT_OFF, 0, "S"); odbc_command("SELECT 1"); CHKMoreResults("No"); if (!close_last_socket()) { fprintf(stderr, "Error closing connection\n"); return 1; } CHKEndTran(SQL_HANDLE_DBC, odbc_conn, SQL_ROLLBACK, "E"); /* the error should be written in the connection, not in the statement */ ReadErrorConn(); if (strcmp(odbc_sqlstate, "08S01") != 0 || strstr(odbc_err, "Write to the server") == NULL) { odbc_disconnect(); fprintf(stderr, "Unexpected error message %s %s\n", odbc_sqlstate, odbc_err); return 1; } odbc_disconnect(); return 0; }
static int Test(int direct) { char buf[256]; SQLRETURN ret; unsigned char sqlstate[6]; Connect(); if (!close_last_socket()) { fprintf(stderr, "Error closing connection\n"); return 1; } /* force disconnection closing socket */ if (direct) ret = SQLExecDirect(Statement, (SQLCHAR *) "SELECT 1", SQL_NTS); else ret = SQLPrepare(Statement, (SQLCHAR *) "SELECT 1", SQL_NTS); if (ret != SQL_ERROR) { fprintf(stderr, "Error expected\n"); return 1; } ret = SQLGetDiagRec(SQL_HANDLE_STMT, Statement, 1, sqlstate, NULL, (SQLCHAR *) buf, sizeof(buf), NULL); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) { fprintf(stderr, "Error not set\n"); Disconnect(); return 1; } sqlstate[5] = 0; printf("state=%s err=%s\n", (char*) sqlstate, buf); Disconnect(); printf("Done.\n"); return 0; }