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

Go to the SVN repository for this file.

1 /*
2  * test SQLBindParameter with text and Sybase
3  * test from Keith Woodard (bug #885122)
4  */
5 #include "common.h"
6 
7 #include <common/test_assert.h>
8 
9 static char software_version[] = "$Id: convert_error.c 80680 2017-12-28 18:51:16Z ucko $";
11 
12 static int test_num = 0;
13 
14 static void
15 Test(const char *bind1, SQLSMALLINT type1, const char *bind2, SQLSMALLINT type2)
16 {
17  char sql[512];
18  char *val = "test";
19  SQLLEN ind = 4;
20  int id = 1;
22 
24 
25  ++test_num;
26  sprintf(sql, "insert into #test_output values (%s, %s)", bind1, bind2);
27 
28  CHKPrepare(T(sql), (SQLINTEGER) strlen(sql), "S");
29  if (bind1[0] == '?')
30  CHKBindParameter(id++, SQL_PARAM_INPUT, SQL_C_LONG, type1, 3, 0, &test_num, 0, &ind, "S");
31  if (bind2[0] == '?')
32  CHKBindParameter(id++, SQL_PARAM_INPUT, SQL_C_CHAR, type2, strlen(val) + 1, 0, (SQLCHAR *) val,
33  0, &ind, "S");
34  CHKExecute("S");
35  ODBC_FREE();
36 }
37 
38 int
39 main(int argc, char **argv)
40 {
42  odbc_connect();
43 
44  odbc_command("create table #test_output (id int, msg text)");
45 
46  Test("?", SQL_INTEGER, "?", SQL_LONGVARCHAR);
47  Test("123", SQL_INTEGER, "?", SQL_LONGVARCHAR);
48  Test("?", SQL_INTEGER, "'foo'", SQL_LONGVARCHAR);
49  Test("?", SQL_INTEGER, "?", SQL_VARCHAR);
50 
51  /*
52  * Sybase cannot pass this test without complicated query parsing.
53  * Query with blob columns cannot be prepared so prepared query must
54  * be emulated loosing column informations from server and Sybase do
55  * not convert implicitly VARCHAR to INT
56  */
58  Test("?", SQL_VARCHAR, "?", SQL_LONGVARCHAR);
59  else
60  ++test_num;
61 
63 
64  return 0;
65 }
int main(int argc, char **argv)
Definition: convert_error.c:39
static void * no_unused_var_warn[]
Definition: convert_error.c:10
static char software_version[]
Definition: convert_error.c:9
static int test_num
Definition: convert_error.c:12
static void Test(const char *bind1, SQLSMALLINT type1, const char *bind2, SQLSMALLINT type2)
Definition: convert_error.c:15
#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_command(cmd)
Definition: common.h:179
#define CHKExecute(res)
Definition: common.h:114
#define T(s)
Definition: common.h:230
#define ODBC_FREE()
Definition: common.h:218
#define NULL
Definition: ncbistd.hpp:225
HSTMT odbc_stmt
Definition: common.c:33
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
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
SQLRETURN SQLFreeStmt(SQLHSTMT StatementHandle, SQLUSMALLINT Option)
Definition: odbc.c:4237
#define SQL_RESET_PARAMS
Definition: sql.h:256
#define SQL_INTEGER
Definition: sql.h:170
#define SQL_VARCHAR
Definition: sql.h:178
#define SQL_PARAM_INPUT
Definition: sqlext.h:1852
#define SQL_LONGVARCHAR
Definition: sqlext.h:432
#define SQL_C_LONG
Definition: sqlext.h:512
#define SQL_C_CHAR
Definition: sqlext.h:511
long SQLINTEGER
Definition: sqltypes.h:176
unsigned char SQLCHAR
Definition: sqltypes.h:125
signed short int SQLSMALLINT
Definition: sqltypes.h:201
Modified on Fri Jan 05 07:25:28 2024 by modify_doxy.py rev. 669887