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

Go to the SVN repository for this file.

1 #include "common.h"
2 #include <ctype.h>
3 
4 #include <common/test_assert.h>
5 
6 /*
7  * SQLDescribeCol test
8  */
9 static int g_result = 0;
10 
11 static void
12 do_check(int c, const char *test, int line)
13 {
14  if (c)
15  return;
16 
17  fprintf(stderr, "Failed check %s at line %d\n", test, line);
18  g_result = 1;
19 }
20 
21 #define check(s) do_check(s, #s, __LINE__)
22 
23 int
24 main(int argc, char *argv[])
25 {
27  SQLTCHAR name[128];
28 
29  odbc_connect();
30  odbc_command("create table #dc (col_name int, name2 varchar(100))");
31 
32  odbc_command("select * from #dc");
33 
34  len = 0x1234;
35  CHKDescribeCol(1, NULL, 0, &len, &type, NULL, NULL, NULL, "S");
36  check(len == 8);
37 
38  len = 0x1234;
39  CHKDescribeCol(2, name, 0, &len, &type, NULL, NULL, NULL, "I");
40  check(len == 5);
41 
42  len = 0x1234;
43  CHKDescribeCol(1, NULL, 2, &len, &type, NULL, NULL, NULL, "S");
44  check(len == 8);
45 
46  len = 0x1234;
47  strcpy((char *) name, "xxx");
48  CHKDescribeCol(2, name, 3, &len, &type, NULL, NULL, NULL, "I");
49  check(len == 5 && strcmp(C(name), "na") == 0);
50 
51  len = 0x1234;
52  strcpy((char *) name, "xxx");
53  CHKDescribeCol(1, name, 1, &len, &type, NULL, NULL, NULL, "I");
54  check(len == 8 && strcmp(C(name), "") == 0);
55 
56  len = 0x1234;
57  strcpy((char *) name, "xxx");
58  CHKDescribeCol(2, name, 6, &len, &type, NULL, NULL, NULL, "S");
59  check(len == 5 && strcmp(C(name), "name2") == 0);
60 
62 
63  if (g_result == 0)
64  printf("Done.\n");
65  return g_result;
66 }
#define C(s)
Definition: common.h:231
#define odbc_command(cmd)
Definition: common.h:179
#define CHKDescribeCol(a, b, c, d, e, f, g, h, res)
Definition: common.h:104
#define test(a, b, c, d, e)
Definition: numeric.c:170
static SQLRETURN odbc_connect(TDS_DBC *dbc, TDSLOGIN *login)
Definition: odbc.c:356
int odbc_disconnect(void)
Definition: common.c:290
#define check(s)
Definition: describecol2.c:21
int main(int argc, char *argv[])
Definition: describecol2.c:24
static int g_result
Definition: describecol2.c:9
static void do_check(int c, const char *test, int line)
Definition: describecol2.c:12
static int type
Definition: getdata.c:31
#define NULL
Definition: ncbistd.hpp:225
int len
int strcmp(const char *str1, const char *str2)
Definition: odbc_utils.hpp:160
SQLCHAR SQLTCHAR
Definition: sqltypes.h:463
signed short int SQLSMALLINT
Definition: sqltypes.h:201
Definition: type.c:6
Modified on Fri Sep 20 14:57:28 2024 by modify_doxy.py rev. 669887