Line data Source code
1 : #include "common.h"
2 :
3 : /* Test SQLFetchScroll with no bound columns */
4 :
5 : static int bind_all = 0;
6 : static int normal_fetch = 0;
7 : static int use_cursors = 1;
8 :
9 : static void
10 128 : Test(void)
11 : {
12 : #define ROWS 5
13 : struct data_t {
14 : SQLINTEGER i;
15 : SQLLEN ind_i;
16 : char c[20];
17 : SQLLEN ind_c;
18 : } data[ROWS];
19 : SQLUSMALLINT statuses[ROWS];
20 : SQLLEN num_row;
21 :
22 128 : odbc_reset_statement();
23 :
24 : /* this should not fail or return warnings */
25 128 : if (use_cursors) {
26 64 : CHKSetStmtAttr(SQL_ATTR_CONCURRENCY, TDS_INT2PTR(SQL_CONCUR_READ_ONLY), 0, "S");
27 64 : CHKSetStmtAttr(SQL_ATTR_CURSOR_TYPE, TDS_INT2PTR(SQL_CURSOR_STATIC), 0, "S");
28 : }
29 128 : CHKPrepare(T("SELECT c, i FROM #cursor6_test"), SQL_NTS, "S");
30 128 : CHKExecute("S");
31 128 : CHKSetStmtAttr(SQL_ATTR_ROW_BIND_TYPE, TDS_INT2PTR(sizeof(data[0])), 0, "S");
32 128 : CHKSetStmtAttr(SQL_ATTR_ROW_ARRAY_SIZE, TDS_INT2PTR(ROWS), 0, "S");
33 128 : CHKSetStmtAttr(SQL_ATTR_ROW_STATUS_PTR, statuses, 0, "S");
34 128 : CHKSetStmtAttr(SQL_ATTR_ROWS_FETCHED_PTR, &num_row, 0, "S");
35 128 : if (bind_all)
36 64 : CHKBindCol(1, SQL_C_CHAR, &data[0].c, sizeof(data[0].c), &data[0].ind_c, "S");
37 128 : CHKBindCol(2, SQL_C_LONG, &data[0].i, sizeof(data[0].i), &data[0].ind_i, "S");
38 :
39 : #define FILL(s, n) do { \
40 : int _n; for (_n = 0; _n < TDS_VECTOR_SIZE(s); ++_n) s[_n] = n; \
41 : } while(0)
42 128 : FILL(statuses, 9876);
43 128 : num_row = -3;
44 128 : data[0].i = (SQLINTEGER) 0xdeadbeef;
45 128 : data[1].i = (SQLINTEGER) 0xdeadbeef;
46 128 : if (normal_fetch)
47 64 : CHKFetch("S");
48 : else
49 64 : CHKFetchScroll(SQL_FETCH_NEXT, 0, "S");
50 :
51 : /* now check row numbers */
52 384 : printf("num_row %ld statuses[0] %d statuses[1] %d odbc3 %d\n", (long int) num_row,
53 256 : (int) statuses[0], (int) statuses[1], odbc_use_version3);
54 :
55 128 : if (odbc_use_version3 || !normal_fetch) {
56 96 : if (num_row != ROWS || statuses[0] != SQL_ROW_SUCCESS || statuses[1] != SQL_ROW_SUCCESS) {
57 0 : fprintf(stderr, "result error 1\n");
58 0 : exit(1);
59 : }
60 : } else {
61 32 : if (data[0].i != 1 || data[1].i != 0xdeadbeef) {
62 0 : fprintf(stderr, "result error 2\n");
63 0 : exit(1);
64 : }
65 : }
66 :
67 640 : FILL(statuses, 8765);
68 128 : num_row = -3;
69 128 : if (normal_fetch)
70 64 : CHKFetch("S");
71 : else
72 64 : CHKFetchScroll(SQL_FETCH_NEXT, 0, "S");
73 128 : }
74 :
75 : static void
76 16 : Init(void)
77 : {
78 : int i;
79 : char sql[128];
80 :
81 16 : odbc_command("CREATE TABLE #cursor6_test (i INT, c VARCHAR(20))");
82 176 : for (i = 1; i <= 10; ++i) {
83 160 : sprintf(sql, "INSERT INTO #cursor6_test(i,c) VALUES(%d, 'a%db%dc%d')", i, i, i, i);
84 160 : odbc_command(sql);
85 : }
86 :
87 16 : }
88 :
89 : int
90 10 : main(void)
91 : {
92 10 : odbc_use_version3 = 1;
93 10 : odbc_connect();
94 :
95 10 : odbc_check_cursor();
96 :
97 8 : Init();
98 :
99 : #define ALL(n) for (n = 0; n < 2; ++n)
100 24 : ALL(use_cursors)
101 48 : ALL(bind_all)
102 96 : ALL(normal_fetch)
103 64 : Test();
104 :
105 8 : odbc_disconnect();
106 :
107 8 : odbc_use_version3 = 0;
108 :
109 8 : odbc_connect();
110 8 : Init();
111 :
112 24 : ALL(use_cursors)
113 48 : ALL(bind_all)
114 96 : ALL(normal_fetch)
115 64 : Test();
116 :
117 8 : odbc_disconnect();
118 :
119 : return 0;
120 : }
|