NCBI C++ ToolKit
insert_speed.c
Go to the documentation of 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: insert_speed.c 80645 2017-12-28 17:20:38Z ucko $";
7 
8 #define SQL_QUERY_LENGTH 80
9 
10 /* test correctly inserted data after insert */
11 
12 /* I don't remember where this test came ... - freddy77 */
13 
14 static void
16 {
17  SQLLEN sql_nts = SQL_NTS;
18  SQLINTEGER id = 0;
19  char string[64];
20 
22 
23  CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, sizeof(id), 0, &id, 0, &sql_nts, "SI");
24  CHKBindParameter(2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, sizeof(string), 0, string, 0, &sql_nts, "SI");
25 
26  CHKPrepare(T("insert into test values (?, ?)"), SQL_NTS, "SI");
27  for (id = 0; id < 20; id++) {
28  sprintf(string, "This is a test (%d)", (int) id);
29  CHKExecute("SI");
30  }
31 
33 }
34 
35 
36 static void
38 {
39  SQLLEN sql_nts = SQL_NTS;
40  SQLINTEGER commit_off = SQL_AUTOCOMMIT_OFF;
41  SQLINTEGER commit_on = SQL_AUTOCOMMIT_ON;
42  SQLINTEGER id = 0;
43 
44  char string[64];
45 
47 
49 
50  CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, sizeof(id), 0, &id, 0, &sql_nts, "SI");
51  CHKBindParameter(2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, sizeof(string), 0, string, 0, &sql_nts, "SI");
52 
53  CHKPrepare(T("insert into test values (?, ?)"), SQL_NTS, "SI");
54  for (id = 0; id < 20; id++) {
55  sprintf(string, "This is a test (%d)", (int) id);
56  CHKExecute("SI");
57  }
58 
62 }
63 
64 int
65 main(int argc, char **argv)
66 {
67  odbc_connect();
68 
69  odbc_command_with_result(odbc_stmt, "DROP TABLE test");
70  odbc_command("CREATE TABLE test(i int, c varchar(40))");
71 
73 
74  odbc_command("DELETE FROM test");
75 
77 
78  odbc_command("DROP TABLE test");
79 
81 
82  return 0;
83 }
#define int2ptr(i)
Definition: common.h:101
#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 CHKSetConnectAttr(a, b, c, res)
Definition: common.h:152
#define CHKExecute(res)
Definition: common.h:114
#define T(s)
Definition: common.h:230
static void insert_test_auto(void)
Definition: insert_speed.c:15
int main(int argc, char **argv)
Definition: insert_speed.c:65
static void * no_unused_var_warn[]
Definition: insert_speed.c:6
static char software_version[]
Definition: insert_speed.c:5
static void insert_test_man(void)
Definition: insert_speed.c:37
HSTMT odbc_stmt
Definition: common.c:33
int odbc_disconnect(void)
Definition: common.c:290
HDBC odbc_conn
Definition: common.c:32
SQLRETURN odbc_command_with_result(HSTMT stmt, const char *command)
Definition: common.c:312
static SQLRETURN odbc_connect(TDS_DBC *dbc, TDSLOGIN *login)
Definition: odbc.c:356
#define SQLSetConnectAttr(h, n, p, t)
Definition: odbc.c:50
#define SQLLEN
Definition: odbc.h:52
#define SQL_COMMIT
Definition: sql.h:271
#define SQL_INTEGER
Definition: sql.h:170
SQLRETURN SQLEndTran(SQLSMALLINT HandleType, SQLHANDLE Handle, SQLSMALLINT CompletionType)
#define SQL_NTS
Definition: sql.h:49
#define SQL_HANDLE_DBC
Definition: sql.h:65
#define SQL_VARCHAR
Definition: sql.h:178
#define SQL_PARAM_INPUT
Definition: sqlext.h:1852
#define SQL_C_SLONG
Definition: sqlext.h:553
#define SQL_ATTR_AUTOCOMMIT
Definition: sqlext.h:124
#define SQL_AUTOCOMMIT_ON
Definition: sqlext.h:183
#define SQL_AUTOCOMMIT_OFF
Definition: sqlext.h:182
#define SQL_IS_INTEGER
Definition: sqlext.h:307
#define SQL_C_CHAR
Definition: sqlext.h:511
long SQLINTEGER
Definition: sqltypes.h:176
Modified on Fri Mar 01 10:04:49 2024 by modify_doxy.py rev. 669887