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

Go to the SVN repository for this file.

1 #include "common.h"
2 #include <time.h>
3 
4 #include <common/test_assert.h>
5 
6 /* Test various type from odbc and to odbc */
7 
8 /*
9  * This test is useful to test odbc_sql2tds function using TestInput
10  * odbc_sql2tds have some particular cases:
11  * (1) char -> char handled differently with encoding problems
12  * (2) date -> * different format TODO
13  * (3) numeric -> * different format
14  * (4) * -> numeric take precision and scale from ipd TODO
15  * (5) * -> char test wide
16  * (6) * -> blob test wchar and ntext
17  * (7) * -> binary test also with wchar
18  * (8) binary -> * test also with wchar
19  * Also we have to check normal char and wide char
20  */
21 
22 #ifdef TDS_NO_DM
23 static const char tds_no_dm = 1;
24 #else
25 static const char tds_no_dm = 0;
26 #endif
27 
28 static char precision = 18;
29 static char exec_direct = 0;
30 static char prepare_before = 0;
31 static char use_cursors = 0;
32 static int only_test = 0;
33 
34 static int
35 TestOutput(const char *type, const char *value_to_convert, SQLSMALLINT out_c_type, SQLSMALLINT out_sql_type, const char *expected)
36 {
37  char sbuf[1024];
38  unsigned char out_buf[256];
39  SQLLEN out_len = 0;
40  const char *sep;
41 
43 
44  /* build store procedure to test */
45  odbc_command("IF OBJECT_ID('spTestProc') IS NOT NULL DROP PROC spTestProc");
46  sep = "'";
47  if (strncmp(value_to_convert, "0x", 2) == 0)
48  sep = "";
49  sprintf(sbuf, "CREATE PROC spTestProc @i %s OUTPUT AS SELECT @i = CONVERT(%s, %s%s%s)", type, type, sep, value_to_convert, sep);
50  odbc_command(sbuf);
51  memset(out_buf, 0, sizeof(out_buf));
52 
53  if (use_cursors) {
57  }
58 
59  /* bind parameter */
60  if (exec_direct) {
61  CHKBindParameter(1, SQL_PARAM_OUTPUT, out_c_type, out_sql_type, precision, 0, out_buf,
62  sizeof(out_buf), &out_len, "S");
63 
64  /* call store procedure */
65  CHKExecDirect(T("{call spTestProc(?)}"), SQL_NTS, "S");
66  } else {
67  if (prepare_before)
68  CHKPrepare(T("{call spTestProc(?)}"), SQL_NTS, "S");
69 
70  CHKBindParameter(1, SQL_PARAM_OUTPUT, out_c_type, out_sql_type, precision, 0, out_buf,
71  sizeof(out_buf), &out_len, "S");
72 
73  if (!prepare_before)
74  CHKPrepare(T("{call spTestProc(?)}"), SQL_NTS, "S");
75 
76  CHKExecute("S");
77  }
78 
79  /*
80  * MS OBDC requires it cause first recordset is a recordset with a
81  * warning caused by the way it execute RPC (via EXEC statement)
82  */
85 
86  /* test results */
87  odbc_c2string(sbuf, out_c_type, out_buf, out_len);
88 
89  if (strcmp(sbuf, expected) != 0) {
90  if (only_test) {
91  odbc_command("drop proc spTestProc");
92  ODBC_FREE();
93  return 1;
94  }
95  fprintf(stderr, "Wrong result\n Got: %s\n Expected: %s\n", sbuf, expected);
96  exit(1);
97  }
98  only_test = 0;
99  odbc_command("drop proc spTestProc");
100  ODBC_FREE();
101  return 0;
102 }
103 
104 static char check_truncation = 0;
105 static char use_nts = 0;
106 
107 static void
108 TestInput(SQLSMALLINT out_c_type, const char *type, SQLSMALLINT out_sql_type, const char *param_type, const char *value_to_convert)
109 {
110  char sbuf[1024];
111  unsigned char out_buf[256];
112  SQLLEN out_len = 0;
113  const char *expected = value_to_convert;
114  size_t value_len = strlen(value_to_convert);
115  const char *p;
116  const char *sep = "'";
117 
119 
120  /* execute a select to get data as wire */
121  if ((p = strstr(value_to_convert, " -> ")) != NULL) {
122  value_len = p - value_to_convert;
123  expected = p + 4;
124  }
125  if (value_len >= 2 && strncmp(value_to_convert, "0x", 2) == 0)
126  sep = "";
127  sprintf(sbuf, "SELECT CONVERT(%s, %s%.*s%s)", type, sep, (int) value_len, value_to_convert, sep);
128  odbc_command(sbuf);
129  SQLBindCol(odbc_stmt, 1, out_c_type, out_buf, sizeof(out_buf), &out_len);
130  CHKFetch("SI");
131  CHKFetch("No");
132  CHKMoreResults("No");
133  if (use_nts) {
134  out_len = SQL_NTS;
135  use_nts = 0;
136  }
137 
138  /* create a table with a column of that type */
140  sprintf(sbuf, "CREATE TABLE #tmp_insert (col %s)", param_type);
141  odbc_command(sbuf);
142 
143  if (use_cursors) {
147  }
148 
149  /* insert data using prepared statements */
150  sprintf(sbuf, "INSERT INTO #tmp_insert VALUES(?)");
151  if (exec_direct) {
152  CHKBindParameter(1, SQL_PARAM_INPUT, out_c_type, out_sql_type, 20, 0, out_buf, sizeof(out_buf), &out_len, "S");
153 
154  if (check_truncation)
155  CHKExecDirect(T(sbuf), SQL_NTS, "E");
156  else
157  CHKExecDirect(T(sbuf), SQL_NTS, "SNo");
158  } else {
159  if (prepare_before)
160  CHKPrepare(T(sbuf), SQL_NTS, "S");
161 
162  CHKBindParameter(1, SQL_PARAM_INPUT, out_c_type, out_sql_type, 20, 0, out_buf, sizeof(out_buf), &out_len, "S");
163 
164  if (!prepare_before)
165  CHKPrepare(T(sbuf), SQL_NTS, "S");
166 
167  if (check_truncation)
168  CHKExecute("E");
169  else
170  CHKExecute("SNo");
171  }
172 
173  /* check if row is present */
174  if (!check_truncation) {
176  sep = "'";
177  if (strncmp(expected, "0x", 2) == 0)
178  sep = "";
179  if (strcmp(param_type, "TEXT") == 0)
180  sprintf(sbuf, "SELECT * FROM #tmp_insert WHERE CONVERT(VARCHAR(255), col) = CONVERT(VARCHAR(255), %s%s%s)", sep, expected, sep);
181  else if (strcmp(param_type, "NTEXT") == 0)
182  sprintf(sbuf, "SELECT * FROM #tmp_insert WHERE CONVERT(NVARCHAR(2000), col) = CONVERT(NVARCHAR(2000), %s%s%s)", sep, expected, sep);
183  else if (strcmp(param_type, "IMAGE") == 0)
184  sprintf(sbuf, "SELECT * FROM #tmp_insert WHERE CONVERT(VARBINARY(255), col) = CONVERT(VARBINARY(255), %s%s%s)", sep, expected, sep);
185  else
186  sprintf(sbuf, "SELECT * FROM #tmp_insert WHERE col = CONVERT(%s, %s%s%s)", param_type, sep, expected, sep);
187  odbc_command(sbuf);
188 
189  CHKFetch("S");
190  CHKFetch("No");
191  CHKMoreResults("No");
192  }
193  check_truncation = 0;
194  odbc_command("DROP TABLE #tmp_insert");
195  ODBC_FREE();
196 }
197 
198 /* stripped down version of TestInput for NULLs */
199 static void
200 NullInput(SQLSMALLINT out_c_type, SQLSMALLINT out_sql_type, const char *param_type)
201 {
202  char sbuf[1024];
203  SQLLEN out_len = SQL_NULL_DATA;
204 
206 
207  /* create a table with a column of that type */
209  sprintf(sbuf, "CREATE TABLE #tmp_insert (col %s NULL)", param_type);
210  odbc_command(sbuf);
211 
212  if (use_cursors) {
216  }
217 
218  /* insert data using prepared statements */
219  sprintf(sbuf, "INSERT INTO #tmp_insert VALUES(?)");
220  if (exec_direct) {
221  CHKBindParameter(1, SQL_PARAM_INPUT, out_c_type, out_sql_type, 20, 0, NULL, 1, &out_len, "S");
222 
223  CHKExecDirect(T(sbuf), SQL_NTS, "SNo");
224  } else {
225  if (prepare_before)
226  CHKPrepare(T(sbuf), SQL_NTS, "S");
227 
228  CHKBindParameter(1, SQL_PARAM_INPUT, out_c_type, out_sql_type, 20, 0, NULL, 1, &out_len, "S");
229 
230  if (!prepare_before)
231  CHKPrepare(T(sbuf), SQL_NTS, "S");
232 
233  CHKExecute("SNo");
234  }
235 
236  /* check if row is present */
238  if (!odbc_db_is_microsoft() && strcmp(param_type, "TEXT") == 0)
239  odbc_command("SELECT * FROM #tmp_insert WHERE DATALENGTH(col) = 0 OR DATALENGTH(col) IS NULL");
240  else
241  odbc_command("SELECT * FROM #tmp_insert WHERE col IS NULL");
242 
243  CHKFetch("S");
244  CHKFetch("No");
245  CHKMoreResults("No");
246  odbc_command("DROP TABLE #tmp_insert");
247  ODBC_FREE();
248 }
249 
250 
251 static int big_endian = 1;
252 
253 static const char*
254 pack(const char *fmt, ...)
255 {
256  static char out[80];
257  char *p = out;
258 
259  va_list v;
260  va_start(v, fmt);
261  for (; *fmt; ++fmt) {
262  unsigned n = va_arg(v, unsigned);
263  int i, l = 2;
264 
265  assert(p - out + 8 < sizeof(out));
266  switch (*fmt) {
267  case 'l':
268  l += 2;
269  case 's':
270  for (i = 0; i < l; ++i) {
271  sprintf(p, "%02X", (n >> (8*(big_endian ? l-1-i : i))) & 0xffu);
272  p += 2;
273  }
274  break;
275  default:
276  assert(0);
277  }
278  }
279  *p = 0;
280  va_end(v);
281  return out;
282 }
283 
284 static void
285 AllTests(void)
286 {
287  struct tm *ltime;
288  char buf[80];
289  time_t curr_time;
290 
291  SQLINTEGER y, m, d;
292  char date[128];
293 
294  printf("use_cursors %d exec_direct %d prepare_before %d\n", use_cursors, exec_direct, prepare_before);
295 
296  /* test some NULLs */
297  NullInput(SQL_C_CHAR, SQL_VARCHAR, "VARCHAR(100)");
299  NullInput(SQL_C_LONG, SQL_INTEGER, "INTEGER");
302  NullInput(SQL_C_FLOAT, SQL_REAL, "FLOAT");
304  if (odbc_db_is_microsoft() && odbc_db_version_int() >= 0x08000000u)
305  NullInput(SQL_C_BIT, SQL_BIT, "BIT");
306  NullInput(SQL_C_DOUBLE, SQL_DOUBLE, "MONEY");
307 
308  /* FIXME why should return 38 0 as precision and scale ?? correct ?? */
309  precision = 18;
310  TestOutput("NUMERIC(18,2)", "123", SQL_C_NUMERIC, SQL_NUMERIC, "18 0 1 7B");
311  TestOutput("DECIMAL(18,2)", "123", SQL_C_NUMERIC, SQL_DECIMAL, "18 0 1 7B");
312  precision = 38;
313  TestOutput("NUMERIC(18,2)", "123", SQL_C_NUMERIC, SQL_NUMERIC, "38 0 1 7B");
314  TestInput(SQL_C_LONG, "INTEGER", SQL_VARCHAR, "VARCHAR(20)", "12345");
315  TestInput(SQL_C_LONG, "INTEGER", SQL_LONGVARCHAR, "TEXT", "12345");
316  /*
317  * MS driver behavior for output parameters is different
318  * former returns "313233" while newer "333133323333"
319  */
321  TestOutput("VARCHAR(20)", "313233", SQL_C_BINARY, SQL_VARCHAR, "333133323333");
322 
323  only_test = 1;
324  precision = 3;
325  if (TestOutput("DATETIME", "2004-02-24 15:16:17", SQL_C_BINARY, SQL_TIMESTAMP, pack("ssssssl", 2004, 2, 24, 15, 16, 17, 0))) {
326  /* FIXME our driver ignore precision for date */
327  precision = 3;
328  /* Some MS driver incorrectly prepare with smalldatetime*/
330  TestOutput("DATETIME", "2004-02-24 15:16:17", SQL_C_BINARY, SQL_TIMESTAMP, pack("ll", 0x9497, 0xFBAA2C));
331  }
332  TestOutput("SMALLDATETIME", "2004-02-24 15:16:17", SQL_C_BINARY, SQL_TIMESTAMP, pack("ll", 0x9497, 0xFB9640));
333  } else {
334  TestOutput("SMALLDATETIME", "2004-02-24 15:16:17", SQL_C_BINARY, SQL_TIMESTAMP, pack("ssssssl", 2004, 2, 24, 15, 16, 0, 0));
335  }
336  TestInput(SQL_C_TYPE_TIMESTAMP, "DATETIME", SQL_TYPE_TIMESTAMP, "DATETIME", "2005-07-22 09:51:34");
337 
338  /* test timestamp millisecond round off */
339  TestInput(SQL_C_TYPE_TIMESTAMP, "DATETIME", SQL_TYPE_TIMESTAMP, "DATETIME", "2005-07-22 09:51:34.001 -> 2005-07-22 09:51:34.000");
340  TestInput(SQL_C_TYPE_TIMESTAMP, "DATETIME", SQL_TYPE_TIMESTAMP, "DATETIME", "2005-07-22 09:51:34.002 -> 2005-07-22 09:51:34.003");
341  TestInput(SQL_C_TYPE_TIMESTAMP, "DATETIME", SQL_TYPE_TIMESTAMP, "DATETIME", "2005-07-22 09:51:34.003 -> 2005-07-22 09:51:34.003");
342  TestInput(SQL_C_TYPE_TIMESTAMP, "DATETIME", SQL_TYPE_TIMESTAMP, "DATETIME", "2005-07-22 09:51:34.004 -> 2005-07-22 09:51:34.003");
343  TestInput(SQL_C_TYPE_TIMESTAMP, "DATETIME", SQL_TYPE_TIMESTAMP, "DATETIME", "2005-07-22 09:51:34.005 -> 2005-07-22 09:51:34.007");
344  TestInput(SQL_C_TYPE_TIMESTAMP, "DATETIME", SQL_TYPE_TIMESTAMP, "DATETIME", "2005-07-22 09:51:34.006 -> 2005-07-22 09:51:34.007");
345 
346  /* FIXME on ms driver first SQLFetch return SUCCESS_WITH_INFO for truncation error */
347  TestInput(SQL_C_TYPE_DATE, "DATETIME", SQL_TYPE_TIMESTAMP, "DATETIME", "2005-07-22 13:02:03 -> 2005-07-22 00:00:00");
348 
349  /* replace date information with current date */
350  time(&curr_time);
351  ltime = localtime(&curr_time);
352  y = ltime->tm_year + 1900;
353  m = ltime->tm_mon + 1;
354  d = ltime->tm_mday;
355  /* server concept of data can be different so try ask to server */
356  odbc_command("SELECT GETDATE()");
357  SQLBindCol(odbc_stmt, 1, SQL_C_CHAR, date, sizeof(date), NULL);
358  if (SQLFetch(odbc_stmt) == SQL_SUCCESS) {
359  int a, b, c;
360  if (sscanf(date, "%d-%d-%d", &a, &b, &c) == 3) {
361  y = a;
362  m = b;
363  d = c;
364  }
365  }
369  sprintf(buf, "2003-07-22 13:02:03 -> %04d-%02d-%02d 13:02:03", (int) y, (int) m, (int) d);
370  TestInput(SQL_C_TYPE_TIME, "DATETIME", SQL_TYPE_TIMESTAMP, "DATETIME", buf);
371 
372  TestInput(SQL_C_FLOAT, "FLOAT", SQL_REAL, "FLOAT", "1234.25");
373  TestInput(SQL_C_DOUBLE, "REAL", SQL_REAL, "FLOAT", "-1234.25");
374  TestInput(SQL_C_FLOAT, "REAL", SQL_REAL, "FLOAT", "1234.25");
375  TestInput(SQL_C_DOUBLE, "FLOAT", SQL_REAL, "FLOAT", "-1234.25");
376  TestInput(SQL_C_FLOAT, "FLOAT", SQL_FLOAT, "FLOAT", "1234.25");
377  TestInput(SQL_C_DOUBLE, "REAL", SQL_FLOAT, "FLOAT", "-1234.25");
378  TestInput(SQL_C_FLOAT, "FLOAT", SQL_DOUBLE, "FLOAT", "1234.25");
379  TestInput(SQL_C_DOUBLE, "REAL", SQL_DOUBLE, "FLOAT", "-1234.25");
380 
381  TestInput(SQL_C_UTINYINT, "TINYINT", SQL_TINYINT, "TINYINT", "231");
382 
383  TestInput(SQL_C_NUMERIC, "NUMERIC(20,3)", SQL_NUMERIC, "NUMERIC(20,3)", "765432.2 -> 765432");
384  TestInput(SQL_C_NUMERIC, "NUMERIC(20,3)", SQL_VARCHAR, "VARCHAR(20)", "578246.234 -> 578246");
385  TestInput(SQL_C_NUMERIC, "NUMERIC(20,3)", SQL_LONGVARCHAR, "TEXT", "578246.234 -> 578246");
386 
387  TestInput(SQL_C_CHAR, "VARCHAR(100)", SQL_VARBINARY, "VARBINARY(20)", "4145544F -> AETO");
388  TestInput(SQL_C_CHAR, "TEXT", SQL_VARBINARY, "VARBINARY(20)", "4145544F -> AETO");
389  TestInput(SQL_C_CHAR, "VARCHAR(100)", SQL_LONGVARBINARY, "IMAGE", "4145544F -> AETO");
390  TestInput(SQL_C_BINARY, "VARBINARY(100)", SQL_VARCHAR, "VARCHAR(20)", "0x4145544F -> AETO");
391  TestInput(SQL_C_BINARY, "IMAGE", SQL_VARCHAR, "VARCHAR(20)", "0x4145544F -> AETO");
392 
393  TestInput(SQL_C_BIT, "BIT", SQL_BIT, "BIT", "0");
394  TestInput(SQL_C_BIT, "BIT", SQL_BIT, "BIT", "1");
395 
396  TestInput(SQL_C_DOUBLE, "MONEY", SQL_DOUBLE, "MONEY", "123.34");
397 
398  TestInput(SQL_C_CHAR, "VARCHAR(20)", SQL_VARCHAR, "VARCHAR(20)", "1EasyTest");
399  TestInput(SQL_C_CHAR, "VARCHAR(20)", SQL_LONGVARCHAR, "TEXT", "1EasyTest");
400  TestInput(SQL_C_WCHAR, "VARCHAR(10)", SQL_VARCHAR, "VARCHAR(10)", "Test 12345");
401  TestInput(SQL_C_WCHAR, "VARCHAR(10)", SQL_LONGVARCHAR, "TEXT", "Test 12345");
402  /* TODO use collate in syntax if available */
403  TestInput(SQL_C_CHAR, "VARCHAR(20)", SQL_VARCHAR, "VARCHAR(20)", "me\xf4");
404  TestInput(SQL_C_CHAR, "VARCHAR(20)", SQL_LONGVARCHAR, "TEXT", "me\xf4");
405 
406  precision = 6;
407  /* output from char with conversions */
408  TestOutput("VARCHAR(20)", "foo test", SQL_C_CHAR, SQL_VARCHAR, "6 foo te");
409  /* TODO use collate in sintax if available */
410  /* while usually on Microsoft database this encoding is valid on Sybase the database
411  * could use UTF-8 encoding where \xf8\xf9 is an invalid encoded string */
412  if (odbc_db_is_microsoft() && odbc_tds_version() > 0x700)
413  TestOutput("VARCHAR(20)", "0xf8f9", SQL_C_CHAR, SQL_VARCHAR, "2 \xf8\xf9");
414 
415  if ((odbc_db_is_microsoft() && odbc_db_version_int() >= 0x08000000u && odbc_tds_version() > 0x700)
416  || (!odbc_db_is_microsoft() && strncmp(odbc_db_version(), "15.00.", 6) >= 0)) {
417  TestOutput("BIGINT", "-987654321065432", SQL_C_BINARY, SQL_BIGINT, big_endian ? "FFFC7DBBCF083228" : "283208CFBB7DFCFF");
418  TestInput(SQL_C_SBIGINT, "BIGINT", SQL_BIGINT, "BIGINT", "-12345678901234");
419  }
420  if (odbc_db_is_microsoft() && odbc_db_version_int() >= 0x08000000u) {
421  TestInput(SQL_C_CHAR, "NVARCHAR(100)", SQL_WCHAR, "NVARCHAR(100)", "test");
422  TestInput(SQL_C_CHAR, "NVARCHAR(100)", SQL_WLONGVARCHAR, "NTEXT", "test");
423  /* test for invalid stream due to truncation*/
424  TestInput(SQL_C_CHAR, "NVARCHAR(100)", SQL_WCHAR, "NVARCHAR(100)", "01234567890");
425  TestInput(SQL_C_CHAR, "NVARCHAR(100)", SQL_WLONGVARCHAR, "NTEXT", "01234567890");
426 #ifdef ENABLE_DEVELOPING
427  check_truncation = 1;
428  TestInput(SQL_C_CHAR, "NVARCHAR(100)", SQL_WCHAR, "NVARCHAR(100)", "012345678901234567890");
429  check_truncation = 1;
430  TestInput(SQL_C_CHAR, "NVARCHAR(100)", SQL_WLONGVARCHAR, "NTEXT", "012345678901234567890");
431 #endif
432  TestInput(SQL_C_CHAR, "NVARCHAR(100)", SQL_WCHAR, "NVARCHAR(100)", "\xa3h\xf9 -> 0xA3006800f900");
433  TestInput(SQL_C_CHAR, "NVARCHAR(100)", SQL_WLONGVARCHAR, "NTEXT", "\xa3h\xf9 -> 0xA3006800f900");
434  TestInput(SQL_C_CHAR, "NVARCHAR(100)", SQL_WCHAR, "NVARCHAR(100)", "0xA3006800f900 -> \xa3h\xf9");
435  TestInput(SQL_C_CHAR, "NVARCHAR(100)", SQL_WLONGVARCHAR, "NTEXT", "0xA3006800f900 -> \xa3h\xf9");
436 
437  TestInput(SQL_C_LONG, "INT", SQL_WVARCHAR, "NVARCHAR(100)", "45236");
438  TestInput(SQL_C_LONG, "INT", SQL_WLONGVARCHAR, "NTEXT", "45236");
439 
440  precision = 6;
441  TestOutput("NVARCHAR(20)", "foo test", SQL_C_CHAR, SQL_WVARCHAR, "6 foo te");
442  precision = 12;
443  TestOutput("NVARCHAR(20)", "foo test", SQL_C_CHAR, SQL_WVARCHAR, "8 foo test");
444  /* TODO use collate in sintax if available */
445  TestOutput("NVARCHAR(20)", "0xf800f900", SQL_C_CHAR, SQL_WVARCHAR, "2 \xf8\xf9");
446 
447  TestInput(SQL_C_WCHAR, "NVARCHAR(10)", SQL_WVARCHAR, "NVARCHAR(10)", "1EasyTest2");
448  TestInput(SQL_C_WCHAR, "NVARCHAR(10)", SQL_WLONGVARCHAR, "NTEXT", "1EasyTest2");
449  use_nts = 1;
450  TestInput(SQL_C_WCHAR, "NVARCHAR(10)", SQL_WVARCHAR, "NVARCHAR(10)", "1EasyTest3");
451  use_nts = 1;
452  TestInput(SQL_C_WCHAR, "NVARCHAR(10)", SQL_WLONGVARCHAR, "NTEXT", "1EasyTest3");
453  TestInput(SQL_C_WCHAR, "NVARCHAR(3)", SQL_WVARCHAR, "NVARCHAR(3)", "0xf800a300bc06");
454  TestInput(SQL_C_WCHAR, "NVARCHAR(3)", SQL_WLONGVARCHAR, "NTEXT", "0xf800a300bc06");
455 
456  TestInput(SQL_C_WCHAR, "NVARCHAR(10)", SQL_INTEGER, "INT", " -423785 -> -423785");
457 
458  TestInput(SQL_C_CHAR, "NVARCHAR(100)", SQL_VARBINARY, "VARBINARY(20)", "4145544F -> AETO");
459  TestInput(SQL_C_CHAR, "NTEXT", SQL_VARBINARY, "VARBINARY(20)", "4145544F -> AETO");
460 
461  TestInput(SQL_C_BINARY, "VARBINARY(100)", SQL_WVARCHAR, "NVARCHAR(20)", "0x4100450054004F00 -> AETO");
462  TestInput(SQL_C_BINARY, "IMAGE", SQL_WVARCHAR, "NVARCHAR(20)", "0x4100450054004F00 -> AETO");
463  }
464  if (odbc_db_is_microsoft() && odbc_db_version_int() >= 0x09000000u) {
465  TestInput(SQL_C_CHAR, "VARCHAR(20)", SQL_LONGVARCHAR, "VARCHAR(MAX)", "1EasyTest");
466  TestInput(SQL_C_BINARY, "VARBINARY(20)", SQL_LONGVARBINARY, "VARBINARY(MAX)", "Anything will suite!");
467  }
468 }
469 
470 int
471 main(int argc, char *argv[])
472 {
473  odbc_use_version3 = 1;
474  odbc_connect();
475 
476  if (((char *) &big_endian)[0] == 1)
477  big_endian = 0;
478 
479  for (use_cursors = 0; use_cursors <= 1; ++use_cursors) {
480  if (use_cursors) {
483  /* if connection does not support cursors returns success */
484  setenv("TDS_SKIP_SUCCESS", "1", 1);
486  }
487 
488  exec_direct = 1;
489  AllTests();
490 
491  exec_direct = 0;
492  prepare_before = 1;
493  AllTests();
494 
495  prepare_before = 0;
496  AllTests();
497  }
498 
499  odbc_disconnect();
500 
501  printf("Done successfully!\n");
502  return 0;
503 }
504 
#define CHKMoreResults(res)
Definition: common.h:138
#define CHKBindParameter(a, b, c, d, e, f, g, h, i, res)
Definition: common.h:96
#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 CHKExecDirect(a, b, res)
Definition: common.h:112
#define CHKExecute(res)
Definition: common.h:114
#define T(s)
Definition: common.h:230
#define ODBC_FREE()
Definition: common.h:218
#define CHKSetStmtAttr(a, b, c, res)
Definition: common.h:158
#define CHKFetch(res)
Definition: common.h:118
std::ofstream out("events_result.xml")
main entry point for tests
#define SQLLEN
Definition: odbc.h:52
static SQLRETURN odbc_connect(TDS_DBC *dbc, TDSLOGIN *login)
Definition: odbc.c:356
static const char * expected[]
Definition: bcp.c:42
void odbc_c2string(char *out, SQLSMALLINT out_c_type, const void *in, size_t in_len)
Converts an ODBC result into a string.
Definition: c2string.c:26
HSTMT odbc_stmt
Definition: common.c:33
const char * odbc_db_version(void)
Definition: common.c:468
unsigned int odbc_db_version_int(void)
Definition: common.c:483
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
int odbc_db_is_microsoft(void)
Definition: common.c:325
int odbc_tds_version(void)
Definition: common.c:444
int odbc_driver_is_freetds(void)
Definition: common.c:345
static int big_endian
Definition: genparams.c:251
int main(int argc, char *argv[])
Definition: genparams.c:471
static const char tds_no_dm
Definition: genparams.c:25
static char precision
Definition: genparams.c:28
static void NullInput(SQLSMALLINT out_c_type, SQLSMALLINT out_sql_type, const char *param_type)
Definition: genparams.c:200
static int only_test
Definition: genparams.c:32
static char use_cursors
Definition: genparams.c:31
static const char * pack(const char *fmt,...)
Definition: genparams.c:254
static void AllTests(void)
Definition: genparams.c:285
static char check_truncation
Definition: genparams.c:104
static char exec_direct
Definition: genparams.c:29
static int TestOutput(const char *type, const char *value_to_convert, SQLSMALLINT out_c_type, SQLSMALLINT out_sql_type, const char *expected)
Definition: genparams.c:35
static char use_nts
Definition: genparams.c:105
static char prepare_before
Definition: genparams.c:30
static void TestInput(SQLSMALLINT out_c_type, const char *type, SQLSMALLINT out_sql_type, const char *param_type, const char *value_to_convert)
Definition: genparams.c:108
#define setenv(n, v, o)
Definition: replacements.h:185
#define NULL
Definition: ncbistd.hpp:225
exit(2)
char * buf
int i
yy_size_t n
int strncmp(const char *str1, const char *str2, size_t count)
Definition: odbc_utils.hpp:133
int strcmp(const char *str1, const char *str2)
Definition: odbc_utils.hpp:160
unsigned int a
Definition: ncbi_localip.c:102
#define SQL_REAL
Definition: sql.h:173
#define SQL_FLOAT
Definition: sql.h:172
#define SQL_UNBIND
Definition: sql.h:255
SQLRETURN SQLFetch(SQLHSTMT StatementHandle)
Definition: odbc.c:3997
#define SQL_SUCCESS
Definition: sql.h:31
#define SQL_ATTR_CURSOR_SCROLLABLE
Definition: sql.h:87
#define SQL_SCROLLABLE
Definition: sql.h:94
SQLRETURN SQLFreeStmt(SQLHSTMT StatementHandle, SQLUSMALLINT Option)
Definition: odbc.c:4237
#define SQL_TYPE_TIMESTAMP
Definition: sql.h:184
#define SQL_NUMERIC
Definition: sql.h:168
#define SQL_DECIMAL
Definition: sql.h:169
#define SQL_INTEGER
Definition: sql.h:170
#define SQL_NTS
Definition: sql.h:49
#define SQL_NULL_DATA
Definition: sql.h:29
#define SQL_DOUBLE
Definition: sql.h:174
SQLRETURN SQLBindCol(SQLHSTMT StatementHandle, SQLUSMALLINT ColumnNumber, SQLSMALLINT TargetType, SQLPOINTER TargetValue, SQLINTEGER BufferLength, SQLINTEGER *StrLen_or_Ind)
#define SQL_VARCHAR
Definition: sql.h:178
#define SQL_PARAM_INPUT
Definition: sqlext.h:1852
#define SQL_C_DOUBLE
Definition: sqlext.h:515
#define SQL_C_TYPE_TIMESTAMP
Definition: sqlext.h:531
#define SQL_LONGVARBINARY
Definition: sqlext.h:435
#define SQL_LONGVARCHAR
Definition: sqlext.h:432
#define SQL_C_TYPE_DATE
Definition: sqlext.h:529
#define SQL_C_TYPE_TIME
Definition: sqlext.h:530
#define SQL_C_BINARY
Definition: sqlext.h:546
#define SQL_C_LONG
Definition: sqlext.h:512
#define SQL_ATTR_CURSOR_TYPE
Definition: sqlext.h:258
#define SQL_C_FLOAT
Definition: sqlext.h:514
#define SQL_TINYINT
Definition: sqlext.h:437
#define SQL_CURSOR_DYNAMIC
Definition: sqlext.h:351
SQLRETURN SQLMoreResults(SQLHSTMT hstmt)
Definition: odbc.c:865
#define SQL_VARBINARY
Definition: sqlext.h:434
#define SQL_C_BIT
Definition: sqlext.h:547
#define SQL_C_UTINYINT
Definition: sqlext.h:558
#define SQL_BIT
Definition: sqlext.h:438
#define SQL_C_SBIGINT
Definition: sqlext.h:549
#define SQL_C_NUMERIC
Definition: sqlext.h:517
#define SQL_PARAM_OUTPUT
Definition: sqlext.h:1855
#define SQL_BIGINT
Definition: sqlext.h:436
#define SQL_C_CHAR
Definition: sqlext.h:511
#define SQL_TIMESTAMP
Definition: sqlext.h:431
void * SQLPOINTER
Definition: sqltypes.h:195
long SQLINTEGER
Definition: sqltypes.h:176
signed short int SQLSMALLINT
Definition: sqltypes.h:201
#define SQL_WCHAR
Definition: sqlucode.h:14
#define SQL_WVARCHAR
Definition: sqlucode.h:15
#define SQL_C_WCHAR
Definition: sqlucode.h:17
#define SQL_WLONGVARCHAR
Definition: sqlucode.h:16
#define assert(x)
Definition: srv_diag.hpp:58
Definition: type.c:6
Modified on Tue May 28 05:51:22 2024 by modify_doxy.py rev. 669887