NCBI C++ ToolKit
rebindpar.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 /* Test for executing SQLExecute and rebinding parameters */
6 
7 static char software_version[] = "$Id: rebindpar.c 80680 2017-12-28 18:51:16Z ucko $";
9 
10 #define SWAP_STMT(b) do { SQLHSTMT xyz = odbc_stmt; odbc_stmt = b; b = xyz; } while(0)
11 
12 static HSTMT stmt;
13 
14 static void
16 {
17  SQLLEN ind;
18  int l = (int) strlen(buf);
19  char sql[200];
20 
21  /* insert some data and test success */
22  CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, l, 0, buf, l, &ind, "S");
23 
24  ind = l;
25  CHKExecute("S");
26 
27  SWAP_STMT(stmt);
28  sprintf(sql, "SELECT 1 FROM #tmp1 WHERE c = '%s'", buf);
30  CHKFetch("S");
31  CHKFetch("No");
32  CHKMoreResults("No");
33  SWAP_STMT(stmt);
34 }
35 
36 static void
37 Test(int prebind)
38 {
40  SQLLEN ind;
41  int i;
42  char buf[100];
43 
44  /* build a string longer than 80 character (80 it's the default) */
45  buf[0] = 0;
46  for (i = 0; i < 21; ++i)
47  strcat(buf, "miao");
48 
49  odbc_command("DELETE FROM #tmp1");
50 
51  CHKAllocStmt(&stmt, "S");
52 
53  SWAP_STMT(stmt);
54  if (prebind)
55  CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 1, 0, buf, 1, &ind, "S");
56 
57  CHKPrepare(T("INSERT INTO #tmp1(c) VALUES(?)"), SQL_NTS, "S");
58 
59  /* try to insert an empty string, should not fail */
60  /* NOTE this is currently the only test for insert a empty string using rpc */
62  TestInsert("");
63  TestInsert("a");
64  TestInsert("bb");
65  TestInsert(buf);
66 
67  CHKFreeStmt(SQL_DROP, "S");
69  SWAP_STMT(stmt);
70  ODBC_FREE();
71 }
72 
73 int
74 main(int argc, char *argv[])
75 {
76  odbc_connect();
77 
78  odbc_command("CREATE TABLE #tmp1 (c VARCHAR(200))");
79 
80  Test(1);
81  Test(0);
82 
84 
85  printf("Done.\n");
86  return 0;
87 }
#define CHKFreeStmt(a, res)
Definition: common.h:124
#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 CHKAllocStmt(a, res)
Definition: common.h:90
#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 CHKFetch(res)
Definition: common.h:118
#define NULL
Definition: ncbistd.hpp:225
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
char * buf
int i
HSTMT odbc_stmt
Definition: common.c:33
int odbc_disconnect(void)
Definition: common.c:290
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
int main(int argc, char *argv[])
Definition: rebindpar.c:74
#define SWAP_STMT(b)
Definition: rebindpar.c:10
static void TestInsert(char *buf)
Definition: rebindpar.c:15
static void * no_unused_var_warn[]
Definition: rebindpar.c:8
static HSTMT stmt
Definition: rebindpar.c:12
static void Test(int prebind)
Definition: rebindpar.c:37
static char software_version[]
Definition: rebindpar.c:7
#define strcat(s, k)
#define SQL_NULL_HSTMT
Definition: sql.h:277
#define SQL_DROP
Definition: sql.h:254
#define SQL_NTS
Definition: sql.h:49
#define SQL_VARCHAR
Definition: sql.h:178
#define SQL_PARAM_INPUT
Definition: sqlext.h:1852
#define SQL_C_CHAR
Definition: sqlext.h:511
SQLHANDLE HSTMT
Definition: sqltypes.h:238
Modified on Tue Apr 09 08:00:19 2024 by modify_doxy.py rev. 669887
Modified on Wed Apr 10 07:35:38 2024 by modify_doxy.py rev. 669887
Modified on Thu Apr 11 15:21:02 2024 by modify_doxy.py rev. 669887
Modified on Fri Apr 12 17:23:19 2024 by modify_doxy.py rev. 669887
Modified on Sat Apr 13 11:50:30 2024 by modify_doxy.py rev. 669887
Modified on Sun Apr 14 05:29:28 2024 by modify_doxy.py rev. 669887
Modified on Tue Apr 16 20:15:02 2024 by modify_doxy.py rev. 669887
Modified on Wed Apr 17 13:10:54 2024 by modify_doxy.py rev. 669887