NCBI C++ ToolKit
cursor6.c
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #include "common.h"
2 
3 #include <common/test_assert.h>
4 
5 /* Test SQLFetchScroll with no bound columns */
6 
7 static int bind_all = 0;
8 static int normal_fetch = 0;
9 static int use_cursors = 1;
10 
11 static void Test(void)
12 {
13 #define ROWS 5
14  struct data_t {
15  SQLINTEGER i;
16  SQLLEN ind_i;
17  char c[20];
18  SQLLEN ind_c;
19  } data[ROWS];
20  SQLUSMALLINT statuses[ROWS];
21  SQLLEN num_row;
22 
24 
25  /* this should not fail or return warnings */
26  if (use_cursors) {
29  }
30  CHKPrepare(T("SELECT c, i FROM #cursor6_test"), SQL_NTS, "S");
31  CHKExecute("S");
32  CHKSetStmtAttr(SQL_ATTR_ROW_BIND_TYPE, int2ptr(sizeof(data[0])), 0, "S");
34  CHKSetStmtAttr(SQL_ATTR_ROW_STATUS_PTR, statuses, 0, "S");
35  CHKSetStmtAttr(SQL_ATTR_ROWS_FETCHED_PTR, &num_row, 0, "S");
36  if (bind_all)
37  CHKBindCol(1, SQL_C_CHAR, &data[0].c, sizeof(data[0].c), &data[0].ind_c, "S");
38  CHKBindCol(2, SQL_C_LONG, &data[0].i, sizeof(data[0].i), &data[0].ind_i, "S");
39 
40 #define FILL(s, n) do { \
41  int _n; for (_n = 0; _n < sizeof(s)/sizeof(s[0]); ++_n) s[_n] = n; \
42 } while(0)
43  FILL(statuses, 9876);
44  num_row = -3;
45  data[0].i = (SQLINTEGER) 0xdeadbeef;
46  data[1].i = (SQLINTEGER) 0xdeadbeef;
47  if (normal_fetch)
48  CHKFetch("S");
49  else
51 
52  /* now check row numbers */
53  printf("num_row %ld statuses[0] %d statuses[1] %d odbc3 %d\n", (long int) num_row,
54  (int) statuses[0], (int) statuses[1], odbc_use_version3);
55 
57  if (num_row != ROWS || statuses[0] != SQL_ROW_SUCCESS || statuses[1] != SQL_ROW_SUCCESS) {
58  fprintf(stderr, "result error 1\n");
59  exit(1);
60  }
61  } else {
62  if (data[0].i != 1 || data[1].i != 0xdeadbeef) {
63  fprintf(stderr, "result error 2\n");
64  exit(1);
65  }
66  }
67 
68  FILL(statuses, 8765);
69  num_row = -3;
70  if (normal_fetch)
71  CHKFetch("S");
72  else
74 }
75 
76 static void Init(void)
77 {
78  int i;
79  char sql[128];
80 
81  odbc_command("CREATE TABLE #cursor6_test (i INT, c VARCHAR(20))");
82  for (i = 1; i <= 10; ++i) {
83  sprintf(sql, "INSERT INTO #cursor6_test(i,c) VALUES(%d, 'a%db%dc%d')", i, i, i, i);
85  }
86 
87 }
88 
89 int
90 main(int argc, char *argv[])
91 {
93  odbc_connect();
94 
96 
97  Init();
98 
99 #define ALL(n) for (n = 0; n < 2; ++n)
101  ALL(bind_all)
103  Test();
104 
105  odbc_disconnect();
106 
107  odbc_use_version3 = 0;
108 
109  odbc_connect();
110  Init();
111 
113  ALL(bind_all)
115  Test();
116 
117  odbc_disconnect();
118 
119  return 0;
120 }
#define int2ptr(i)
Definition: common.h:101
#define CHKPrepare(a, b, res)
Definition: common.h:146
#define odbc_reset_statement()
Definition: common.h:71
#define odbc_command(cmd)
Definition: common.h:179
#define CHKBindCol(a, b, c, d, e, res)
Definition: common.h:94
#define CHKExecute(res)
Definition: common.h:114
#define CHKFetchScroll(a, b, res)
Definition: common.h:120
#define T(s)
Definition: common.h:230
#define CHKSetStmtAttr(a, b, c, res)
Definition: common.h:158
#define CHKFetch(res)
Definition: common.h:118
#define SQLLEN
Definition: odbc.h:52
static SQLRETURN odbc_connect(TDS_DBC *dbc, TDSLOGIN *login)
Definition: odbc.c:356
void odbc_check_cursor(void)
Definition: common.c:548
int odbc_disconnect(void)
Definition: common.c:290
int odbc_use_version3
Definition: common.c:34
static int use_cursors
Definition: cursor6.c:9
int main(int argc, char *argv[])
Definition: cursor6.c:90
static int bind_all
Definition: cursor6.c:7
#define ROWS
static void Init(void)
Definition: cursor6.c:76
#define ALL(n)
#define FILL(s, n)
static void Test(void)
Definition: cursor6.c:11
static int normal_fetch
Definition: cursor6.c:8
static char sql[1024]
Definition: putdata.c:19
char data[12]
Definition: iconv.c:80
exit(2)
int i
#define SQL_FETCH_NEXT
Definition: sql.h:261
#define SQL_NTS
Definition: sql.h:49
#define SQL_ATTR_ROWS_FETCHED_PTR
Definition: sqlext.h:278
#define SQL_ATTR_ROW_ARRAY_SIZE
Definition: sqlext.h:279
#define SQL_ATTR_ROW_STATUS_PTR
Definition: sqlext.h:277
#define SQL_CONCUR_READ_ONLY
Definition: sqlext.h:342
#define SQL_C_LONG
Definition: sqlext.h:512
#define SQL_ATTR_CURSOR_TYPE
Definition: sqlext.h:258
#define SQL_ROW_SUCCESS
Definition: sqlext.h:1806
#define SQL_ATTR_ROW_BIND_TYPE
Definition: sqlext.h:274
#define SQL_ATTR_CONCURRENCY
Definition: sqlext.h:257
#define SQL_CURSOR_STATIC
Definition: sqlext.h:352
#define SQL_C_CHAR
Definition: sqlext.h:511
unsigned short SQLUSMALLINT
Definition: sqltypes.h:202
long SQLINTEGER
Definition: sqltypes.h:176
Modified on Mon Jul 15 05:34:16 2024 by modify_doxy.py rev. 669887