int main(int argc, char *argv[]) { odbc_use_version3 = 1; odbc_connect(); if (((char *) &big_endian)[0] == 1) big_endian = 0; for (use_cursors = 0; use_cursors <= 1; ++use_cursors) { if (use_cursors) { if (!tds_no_dm || !odbc_driver_is_freetds()) odbc_reset_statement(); odbc_check_cursor(); } exec_direct = 1; AllTests(); exec_direct = 0; prepare_before = 1; AllTests(); prepare_before = 0; AllTests(); } odbc_disconnect(); printf("Done successfully!\n"); return 0; }
int main(int argc, char *argv[]) { odbc_use_version3 = 1; odbc_connect(); odbc_check_cursor(); Init(); #define ALL(n) for (n = 0; n < 2; ++n) ALL(use_cursors) ALL(bind_all) ALL(normal_fetch) Test(); odbc_disconnect(); odbc_use_version3 = 0; odbc_connect(); Init(); ALL(use_cursors) ALL(bind_all) ALL(normal_fetch) Test(); odbc_disconnect(); return 0; }
int main(int argc, char **argv) { #define ARRAY_SIZE 10 SQLCHAR v_dec[ARRAY_SIZE][21]; SQLLEN v_ind[ARRAY_SIZE]; SQLULEN nrows; odbc_use_version3 = 1; odbc_connect(); odbc_check_cursor(); odbc_command("IF OBJECT_ID('mytab1') IS NOT NULL DROP TABLE mytab1"); odbc_command("CREATE TABLE mytab1 ( k INT, d DECIMAL(10,2))"); odbc_command("INSERT INTO mytab1 VALUES ( 201, 111.11 )"); /*SQLExecDirect(m_hstmt, (SQLCHAR *) "insert into mytab1 values ( 202, 222.22 )", SQL_NTS); */ odbc_command("INSERT INTO mytab1 VALUES ( 202, null )"); odbc_reset_statement(); CHKSetStmtAttr(SQL_ATTR_CURSOR_SCROLLABLE, (SQLPOINTER) SQL_NONSCROLLABLE, SQL_IS_UINTEGER, "S"); CHKSetStmtAttr(SQL_ATTR_CURSOR_SENSITIVITY, (SQLPOINTER) SQL_SENSITIVE, SQL_IS_UINTEGER, "S"); CHKSetStmtAttr(SQL_ATTR_ROW_BIND_TYPE, (SQLPOINTER) SQL_BIND_BY_COLUMN, SQL_IS_UINTEGER, "S"); CHKSetStmtAttr(SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER) ARRAY_SIZE, SQL_IS_UINTEGER, "S"); CHKSetStmtAttr(SQL_ATTR_ROWS_FETCHED_PTR, (SQLPOINTER) & (nrows), SQL_IS_UINTEGER, "S"); CHKPrepare(T("SELECT SUM(d) FROM mytab1"), SQL_NTS, "S"); CHKExecute("I"); #if 0 CHKMoreResults("S"); /* skip warning*/ #endif CHKBindCol(1, SQL_C_CHAR, v_dec, 21, v_ind, "S"); CHKFetch("S"); printf("fetch 1: rows fetched = %d\n", (int) nrows); printf("fetch 1: value = [%s]\n", v_dec[0]); CHKFetch("No"); CHKMoreResults("No"); odbc_command("drop table mytab1"); odbc_disconnect(); return 0; }
int main(int argc, char **argv) { char buff[64]; SQLLEN ind; odbc_use_version3 = 1; odbc_connect(); odbc_check_cursor(); exec_direct("CREATE TABLE #t1 ( k INT, c VARCHAR(20))"); exec_direct("INSERT INTO #t1 VALUES (1, 'aaa')"); odbc_reset_statement(); CHKSetStmtAttr(SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_LOCK, SQL_IS_UINTEGER, "S"); CHKSetCursorName(T("c112"), SQL_NTS, "S"); CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, int2ptr(SQL_AUTOCOMMIT_OFF), 0, "S"); CHKPrepare(T("SELECT * FROM #t1 FOR UPDATE"), SQL_NTS, "S"); CHKExecute("S"); CHKFetch("S"); exec_direct("UPDATE #t1 SET c = 'xxx' WHERE CURRENT OF c112"); CHKCloseCursor("SI"); CHKEndTran(SQL_HANDLE_DBC, odbc_conn, SQL_COMMIT, "S"); CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, int2ptr(SQL_AUTOCOMMIT_ON), 0, "S"); CHKExecDirect(T("SELECT c FROM #t1 WHERE k = 1"), SQL_NTS, "S"); CHKFetch("S"); CHKGetData(1, SQL_C_CHAR, buff, sizeof(buff), &ind, "S"); printf(">> New value after update = [%s] (should be [xxx]) \n", buff); CHKFreeHandle(SQL_HANDLE_STMT, (SQLHANDLE) odbc_stmt, "S"); odbc_stmt = SQL_NULL_HSTMT; odbc_disconnect(); return 0; }
int main(int argc, char *argv[]) { odbc_connect(); odbc_check_cursor(); if (odbc_db_is_microsoft() && odbc_db_version_int() >= 0x09000000u) mssql2005 = 1; Test(1); Test(0); odbc_disconnect(); return 0; }
int main(int argc, char *argv[]) { int i; SQLLEN len; #ifdef HAVE_SQLROWSETSIZE SQLROWSETSIZE row_count; #else SQLULEN row_count; #endif SQLUSMALLINT statuses[10]; char buf[32]; odbc_use_version3 = 1; odbc_connect(); /* initial value should be 1 */ CHKGetStmtAttr(SQL_ROWSET_SIZE, &len, sizeof(len), NULL, "S"); if (len != 1) { fprintf(stderr, "len should be 1\n"); odbc_disconnect(); return 1; } /* check invalid parameter values */ test_err(-123); test_err(-1); test_err(0); odbc_check_cursor(); /* set some correct values */ CHKSetStmtAttr(SQL_ROWSET_SIZE, (SQLPOINTER) int2ptr(2), 0, "S"); CHKSetStmtAttr(SQL_ROWSET_SIZE, (SQLPOINTER) int2ptr(1), 0, "S"); /* now check that SQLExtendedFetch works as expected */ odbc_command("CREATE TABLE #rowset(n INTEGER, c VARCHAR(20))"); for (i = 0; i < 10; ++i) { char s[10]; char sql[128]; memset(s, 'a' + i, 9); s[9] = 0; sprintf(sql, "INSERT INTO #rowset(n,c) VALUES(%d,'%s')", i+1, s); odbc_command(sql); } odbc_reset_statement(); CHKSetStmtOption(SQL_ATTR_CURSOR_TYPE, SQL_CURSOR_DYNAMIC, "S"); CHKExecDirect((SQLCHAR *) "SELECT * FROM #rowset ORDER BY n", SQL_NTS, "SI"); CHKBindCol(2, SQL_C_CHAR, buf, sizeof(buf), &len, "S"); row_count = 0xdeadbeef; memset(statuses, 0x55, sizeof(statuses)); CHKExtendedFetch(SQL_FETCH_NEXT, 1, &row_count, statuses, "S"); if (row_count != 1 || statuses[0] != SQL_ROW_SUCCESS || strcmp(buf, "aaaaaaaaa") != 0) { fprintf(stderr, "Invalid result\n"); odbc_disconnect(); return 1; } odbc_disconnect(); printf("Done.\n"); return 0; }
int main(int argc, char *argv[]) { #define TEST_FILE "attributes.in" const char *in_file = FREETDS_SRCDIR "/" TEST_FILE; FILE *f; char buf[256]; SQLINTEGER i; SQLLEN len; get_attr_t get_attr_p = get_attr_stmt; odbc_connect(); /* TODO find another way */ odbc_check_cursor(); odbc_command("SET TEXTSIZE 4096"); SQLBindCol(odbc_stmt, 1, SQL_C_SLONG, &i, sizeof(i), &len); f = fopen(in_file, "r"); if (!f) f = fopen(TEST_FILE, "r"); if (!f) { fprintf(stderr, "error opening test file\n"); exit(1); } line_num = 0; while (fgets(buf, sizeof(buf), f)) { char *p = buf, *cmd; ++line_num; while (isspace((unsigned char) *p)) ++p; cmd = strtok(p, SEP); /* skip comments */ if (!cmd || cmd[0] == '#' || cmd[0] == 0 || cmd[0] == '\n') continue; if (strcmp(cmd, "odbc") == 0) { int odbc3 = get_int(strtok(NULL, SEP)) == 3 ? 1 : 0; if (odbc_use_version3 != odbc3) { odbc_use_version3 = odbc3; odbc_disconnect(); odbc_connect(); odbc_command("SET TEXTSIZE 4096"); SQLBindCol(odbc_stmt, 1, SQL_C_SLONG, &i, sizeof(i), &len); } continue; } /* set attribute */ if (strcmp(cmd, "set") == 0) { const struct attribute *attr = lookup_attr(strtok(NULL, SEP)); char *value = strtok(NULL, SEP); SQLRETURN ret; if (!value) fatal("Line %u: value not defined\n", line_num); ret = SQL_ERROR; switch (attr->type) { case type_UINTEGER: case type_INTEGER: ret = SQLSetStmtAttr(odbc_stmt, attr->value, int2ptr(lookup(value, attr->lookup)), sizeof(SQLINTEGER)); break; case type_SMALLINT: ret = SQLSetStmtAttr(odbc_stmt, attr->value, int2ptr(lookup(value, attr->lookup)), sizeof(SQLSMALLINT)); break; case type_LEN: ret = SQLSetStmtAttr(odbc_stmt, attr->value, int2ptr(lookup(value, attr->lookup)), sizeof(SQLLEN)); break; case type_CHARP: ret = SQLSetStmtAttr(odbc_stmt, attr->value, (SQLPOINTER) value, SQL_NTS); break; case type_VOIDP: case type_DESC: fatal("Line %u: not implemented\n"); } if (!SQL_SUCCEEDED(ret)) fatal("Line %u: failure not expected setting statement attribute\n", line_num); get_attr_p = get_attr_stmt; continue; } /* test attribute */ if (strcmp(cmd, "attr") == 0) { const struct attribute *attr = lookup_attr(strtok(NULL, SEP)); char *value = strtok(NULL, SEP); int i, expected = lookup(value, attr->lookup); if (!value) fatal("Line %u: value not defined\n", line_num); i = get_attr_p(attr, expected); if (i != expected) { g_result = 1; fprintf(stderr, "Line %u: invalid %s got %d(%s) expected %s\n", line_num, attr->name, i, unlookup(i, attr->lookup), value); } continue; } if (strcmp(cmd, "reset") == 0) { odbc_reset_statement(); continue; } fatal("Line %u: command '%s' not handled\n", line_num, cmd); } fclose(f); odbc_disconnect(); printf("Done.\n"); return g_result; }
int main(int argc, char *argv[]) { #define ROWS 3 #define C_LEN 10 SQLUINTEGER n[ROWS]; char c[ROWS][C_LEN]; SQLLEN c_len[ROWS], n_len[ROWS]; SQLUSMALLINT statuses[ROWS]; SQLUSMALLINT i; SQLULEN num_row; int i_test; typedef struct _test { SQLUSMALLINT type; SQLINTEGER irow; int start; int num; } TEST; static const TEST tests[] = { {SQL_FETCH_NEXT, 0, 1, 3}, {SQL_FETCH_NEXT, 0, 4, 2}, {SQL_FETCH_PRIOR, 0, 1, 3}, {SQL_FETCH_NEXT, 0, 4, 2}, {SQL_FETCH_NEXT, 0, -1, -1}, {SQL_FETCH_FIRST, 0, 1, 3}, {SQL_FETCH_ABSOLUTE, 3, 3, 3}, {SQL_FETCH_RELATIVE, 1, 4, 2}, {SQL_FETCH_LAST, 0, 3, 3} }; const int num_tests = sizeof(tests) / sizeof(TEST); odbc_use_version3 = 1; odbc_connect(); odbc_check_cursor(); /* create test table */ odbc_command("IF OBJECT_ID('tempdb..#test') IS NOT NULL DROP TABLE #test"); odbc_command("CREATE TABLE #test(i int, c varchar(6))"); odbc_command("INSERT INTO #test(i, c) VALUES(1, 'a')"); odbc_command("INSERT INTO #test(i, c) VALUES(2, 'bb')"); odbc_command("INSERT INTO #test(i, c) VALUES(3, 'ccc')"); odbc_command("INSERT INTO #test(i, c) VALUES(4, 'dddd')"); odbc_command("INSERT INTO #test(i, c) VALUES(5, 'eeeee')"); /* set cursor options */ odbc_reset_statement(); CHKSetStmtAttr(SQL_ATTR_CONCURRENCY, (SQLPOINTER) SQL_CONCUR_ROWVER, 0, "S"); CHKSetStmtAttr(SQL_ATTR_CURSOR_SCROLLABLE, (SQLPOINTER) SQL_SCROLLABLE, 0, "S"); CHKSetStmtAttr(SQL_ATTR_CURSOR_TYPE, (SQLPOINTER) SQL_CURSOR_DYNAMIC, 0, "S"); CHKSetStmtAttr(SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER) ROWS, 0, "S"); CHKSetStmtAttr(SQL_ATTR_ROW_STATUS_PTR, (SQLPOINTER) statuses, 0, "S"); CHKSetStmtAttr(SQL_ATTR_ROWS_FETCHED_PTR, &num_row, 0, "S"); /* */ CHKExecDirect(T("SELECT i, c FROM #test"), SQL_NTS, "S"); /* bind some rows at a time */ CHKBindCol(1, SQL_C_ULONG, n, 0, n_len, "S"); CHKBindCol(2, SQL_C_CHAR, c, C_LEN, c_len, "S"); for (i_test = 0; i_test < num_tests; ++i_test) { const TEST *t = &tests[i_test]; printf("Test %d\n", i_test + 1); if (t->start == -1) { CHKFetchScroll(t->type, t->irow, "No"); } else { CHKFetchScroll(t->type, t->irow, "S"); if (t->start < 1) { fprintf(stderr, "Rows not expected\n"); exit(1); } /* print, just for debug */ for (i = 0; i < num_row; ++i) printf("row %d i %d c %s\n", (int) (i + 1), (int) n[i], c[i]); printf("---\n"); if (num_row != t->num) { fprintf(stderr, "Expected %d rows, got %d\n", t->num, (int) num_row); exit(1); } for (i = 0; i < num_row; ++i) { char name[10]; memset(name, 0, sizeof(name)); memset(name, 'a' - 1 + i + t->start, i + t->start); if (n[i] != i + t->start || c_len[i] != strlen(name) || strcmp(c[i], name) != 0) { fprintf(stderr, "Wrong row returned\n"); fprintf(stderr, "\tn %d %d\n", (int) n[i], i + t->start); fprintf(stderr, "\tc len %d %d\n", (int) c_len[i], (int) strlen(name)); fprintf(stderr, "\tc %s %s\n", c[i], name); exit(1); } } } } odbc_reset_statement(); odbc_disconnect(); return 0; }