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

Go to the SVN repository for this file.

Go to the SVN repository for this file.

Go to the SVN repository for this file.

Go to the SVN repository for this file.

Go to the SVN repository for this file.

Go to the SVN repository for this file.

Go to the SVN repository for this file.

Go to the SVN repository for this file.

1 #include "common.h"
2 
3 #include <common/test_assert.h>
4 
5 static char software_version[] = "$Id: stats.c 80680 2017-12-28 18:51:16Z ucko $";
7 
9 static char output[256];
10 
11 static void
12 ReadCol(int i)
13 {
14  memset(output, 'x', sizeof(output));
15  strcpy(output, "NULL");
16  CHKGetData(i, SQL_C_CHAR, output, sizeof(output), &cnamesize, "S");
17 }
18 
19 static const char *catalog = NULL;
20 static const char *schema = NULL;
21 static const char *proc = "stat_proc";
22 static const char *table = "stat_proc";
23 static const char *column = "@t";
24 
25 #define LEN(x) (x) ? (SQLSMALLINT)strlen(x) : 0
26 
27 static void
28 TestProc(const char *type, const char *expected)
29 {
30  char sql[256];
31 
32  odbc_command("IF OBJECT_ID('stat_proc') IS NOT NULL DROP PROC stat_proc");
33 
34  sprintf(sql, "CREATE PROC stat_proc(@t %s) AS RETURN 0", type);
36 
37  column = "@t";
39 
40  CHKFetch("SI");
41 
42  ReadCol(6);
43  if (strcmp(output, expected) != 0) {
44  fprintf(stderr, "Got \"%s\" expected \"%s\"\n", output, expected);
46  exit(1);
47  }
48 
49  CHKCloseCursor("SI");
50  ODBC_FREE();
51 }
52 
53 static void
54 TestTable(const char *type, const char *expected)
55 {
56  char sql[256];
57 
58  odbc_command("IF OBJECT_ID('stat_t') IS NOT NULL DROP TABLE stat_t");
59 
60  sprintf(sql, "CREATE TABLE stat_t(t %s)", type);
62 
63  column = "t";
64  table = "stat_t";
66 
67  CHKFetch("SI");
68 
69  ReadCol(5);
70  if (strcmp(output, expected) != 0) {
71  fprintf(stderr, "Got \"%s\" expected \"%s\"\n", output, expected);
73  exit(1);
74  }
75 
76  CHKCloseCursor("SI");
77  ODBC_FREE();
78 }
79 
80 
81 #define STR(n) str(int_buf, n)
82 
83 static const char *
84 str(char *buf, int n)
85 {
86  sprintf(buf, "%d", n);
87  return buf;
88 }
89 
90 int
91 main(int argc, char *argv[])
92 {
93  char int_buf[32];
94 
96  odbc_connect();
97 
98  TestProc("DATETIME", STR(SQL_TIMESTAMP));
99  TestTable("DATETIME", STR(SQL_TIMESTAMP));
100 
101  odbc_disconnect();
102 
103 
104  odbc_use_version3 = 1;
105  odbc_connect();
106 
107  TestProc("DATETIME", STR(SQL_TYPE_TIMESTAMP));
108  TestTable("DATETIME", STR(SQL_TYPE_TIMESTAMP));
109 
110  odbc_disconnect();
111 
112  printf("Done.\n");
113  return 0;
114 }
#define CHKGetData(a, b, c, d, e, res)
Definition: common.h:136
#define odbc_command(cmd)
Definition: common.h:179
#define CHKProcedureColumns(a, b, c, d, e, f, g, h, res)
Definition: common.h:169
#define T(s)
Definition: common.h:230
#define ODBC_FREE()
Definition: common.h:218
#define CHKCloseCursor(res)
Definition: common.h:100
#define CHKFetch(res)
Definition: common.h:118
#define CHKColumns(a, b, c, d, e, f, g, h, res)
Definition: common.h:171
#define NULL
Definition: ncbistd.hpp:225
exit(2)
char * buf
int i
yy_size_t n
int strcmp(const char *str1, const char *str2)
Definition: odbc_utils.hpp:160
static const char * expected[]
Definition: bcp.c:42
int odbc_disconnect(void)
Definition: common.c:290
int odbc_use_version3
Definition: common.c:34
static SQLRETURN odbc_connect(TDS_DBC *dbc, TDSLOGIN *login)
Definition: odbc.c:356
#define SQLLEN
Definition: odbc.h:52
static char sql[1024]
Definition: putdata.c:19
#define SQL_TYPE_TIMESTAMP
Definition: sql.h:184
#define SQL_C_CHAR
Definition: sqlext.h:511
#define SQL_TIMESTAMP
Definition: sqlext.h:431
static const char * catalog
Definition: stats.c:19
int main(int argc, char *argv[])
Definition: stats.c:91
static char output[256]
Definition: stats.c:9
static SQLINTEGER cnamesize
Definition: stats.c:8
static void ReadCol(int i)
Definition: stats.c:12
static void TestTable(const char *type, const char *expected)
Definition: stats.c:54
static const char * schema
Definition: stats.c:20
#define LEN(x)
Definition: stats.c:25
static const char * table
Definition: stats.c:22
static const char * str(char *buf, int n)
Definition: stats.c:84
static void * no_unused_var_warn[]
Definition: stats.c:6
static const char * proc
Definition: stats.c:21
static char software_version[]
Definition: stats.c:5
#define STR(n)
Definition: stats.c:81
static const char * column
Definition: stats.c:23
static void TestProc(const char *type, const char *expected)
Definition: stats.c:28
Definition: type.c:6
Modified on Tue Apr 09 07:57:56 2024 by modify_doxy.py rev. 669887
Modified on Wed Apr 10 07:33:20 2024 by modify_doxy.py rev. 669887
Modified on Thu Apr 11 15:07:28 2024 by modify_doxy.py rev. 669887
Modified on Fri Apr 12 17:18:46 2024 by modify_doxy.py rev. 669887
Modified on Sat Apr 13 11:46:39 2024 by modify_doxy.py rev. 669887
Modified on Sun Apr 14 05:26:52 2024 by modify_doxy.py rev. 669887
Modified on Tue Apr 16 20:10:50 2024 by modify_doxy.py rev. 669887
Modified on Wed Apr 17 13:09:27 2024 by modify_doxy.py rev. 669887