NCBI C++ ToolKit
print.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 static SQLCHAR output[256];
6 
7 #ifdef TDS_NO_DM
8 static const int tds_no_dm = 1;
9 #else
10 static const int tds_no_dm = 0;
11 #endif
12 
13 static int
14 test(int odbc3)
15 {
17  const char *query;
18 
19  odbc_use_version3 = odbc3;
20 
21  odbc_connect();
22 
23  /* issue print statement and test message returned */
24  output[0] = 0;
25  query = "print 'START' select count(*) from sysobjects where name='sysobjects' print 'END'";
26  odbc_command2(query, "I");
28  if (!strstr(odbc_err, "START")) {
29  printf("Message invalid\n");
30  return 1;
31  }
32  odbc_err[0] = 0;
33 
34  if (odbc3) {
35  ODBC_CHECK_COLS(0);
36  ODBC_CHECK_ROWS(-1);
37  CHKFetch("E");
38  CHKMoreResults("S");
39  }
40 
41  ODBC_CHECK_COLS(1);
42  ODBC_CHECK_ROWS(-1);
43 
44  CHKFetch("S");
45  ODBC_CHECK_COLS(1);
46  ODBC_CHECK_ROWS(-1);
47  /* check no data */
48  CHKFetch("No");
49  ODBC_CHECK_COLS(1);
50  ODBC_CHECK_ROWS(1);
51 
52  /* SQLMoreResults return NO DATA or SUCCESS WITH INFO ... */
53  if (tds_no_dm && !odbc3)
54  CHKMoreResults("No");
55  else if (odbc3)
56  CHKMoreResults("I");
57  else
58  CHKMoreResults("INo");
59 
60  /*
61  * ... but read error
62  * (unixODBC till 2.2.11 do not read errors on NO DATA, skip test)
63  */
64  if (tds_no_dm || odbc3) {
66  if (!strstr(odbc_err, "END")) {
67  printf("Message invalid\n");
68  return 1;
69  }
70  odbc_err[0] = 0;
71  }
72 
73  if (odbc3) {
74  ODBC_CHECK_COLS(0);
75  ODBC_CHECK_ROWS(-1);
76 
77  CHKMoreResults("No");
78  }
79 
80  /* issue invalid command and test error */
81  odbc_command2("SELECT donotexistsfield FROM donotexiststable", "E");
83 
84  /* test no data returned */
85  CHKFetch("E");
87 
88  CHKGetData(1, SQL_C_CHAR, output, sizeof(output), &cnamesize, "E");
90 
92 
93  return 0;
94 }
95 
96 int
97 main(int argc, char *argv[])
98 {
99  int ret;
100 
101  /* ODBC 2 */
102  ret = test(0);
103  if (ret != 0)
104  return ret;
105 
106  /* ODBC 3 */
107  ret = test(1);
108  if (ret != 0)
109  return ret;
110 
111  printf("Done.\n");
112  return 0;
113 }
114 
#define CHKMoreResults(res)
Definition: common.h:138
#define CHKGetData(a, b, c, d, e, res)
Definition: common.h:136
#define ODBC_CHECK_COLS(n)
Definition: common.h:69
#define odbc_command2(cmd, res)
Definition: common.h:180
#define ODBC_CHECK_ROWS(n)
Definition: common.h:68
#define CHKFetch(res)
Definition: common.h:118
int odbc_disconnect(void)
Definition: common.c:290
char odbc_err[512]
Definition: common.c:634
int odbc_use_version3
Definition: common.c:34
void odbc_read_error(void)
Definition: common.c:638
static SQLRETURN odbc_connect(TDS_DBC *dbc, TDSLOGIN *login)
Definition: odbc.c:356
#define SQLLEN
Definition: odbc.h:52
int main(int argc, char *argv[])
Definition: print.c:97
static SQLCHAR output[256]
Definition: print.c:5
static const int tds_no_dm
Definition: print.c:10
static int test(int odbc3)
Definition: print.c:14
#define SQL_C_CHAR
Definition: sqlext.h:511
unsigned char SQLCHAR
Definition: sqltypes.h:125
static SQLINTEGER cnamesize
Definition: stats.c:8
static string query
Modified on Thu Mar 28 17:12:46 2024 by modify_doxy.py rev. 669887