Line data Source code
1 : #include "common.h"
2 : #include <assert.h>
3 :
4 : #define SQL_QUERY_LENGTH 80
5 :
6 : /* test correctly inserted data after insert */
7 :
8 : /* I don't remember where this test came ... - freddy77 */
9 :
10 : static void
11 20 : insert_test(bool manual)
12 : {
13 20 : SQLLEN sql_nts = SQL_NTS;
14 20 : SQLINTEGER id = 0;
15 : char string[64];
16 20 : SQLINTEGER commit_off = SQL_AUTOCOMMIT_OFF;
17 20 : SQLINTEGER commit_on = SQL_AUTOCOMMIT_ON;
18 :
19 20 : if (manual)
20 10 : CHKSetConnectAttr(SQL_ATTR_AUTOCOMMIT, TDS_INT2PTR(commit_off), SQL_IS_INTEGER, "SI");
21 :
22 20 : odbc_reset_statement();
23 :
24 20 : CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, sizeof(id), 0, &id, 0, &sql_nts, "SI");
25 20 : CHKBindParameter(2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, sizeof(string), 0, string, 0, &sql_nts, "SI");
26 :
27 20 : CHKPrepare(T("insert into test values (?, ?)"), SQL_NTS, "SI");
28 420 : for (id = 0; id < 20; id++) {
29 400 : sprintf(string, "This is a test (%d)", (int) id);
30 400 : CHKExecute("SI");
31 : }
32 :
33 20 : if (manual) {
34 10 : SQLEndTran(SQL_HANDLE_DBC, odbc_conn, SQL_COMMIT);
35 10 : SQLSetConnectAttr(odbc_conn, SQL_ATTR_AUTOCOMMIT, TDS_INT2PTR(commit_on), SQL_IS_INTEGER);
36 : }
37 20 : odbc_reset_statement();
38 20 : }
39 :
40 10 : TEST_MAIN()
41 : {
42 10 : odbc_connect();
43 :
44 10 : odbc_command_with_result(odbc_stmt, "DROP TABLE test");
45 10 : odbc_command("CREATE TABLE test(i int, c varchar(40))");
46 :
47 : /* manual commit */
48 10 : insert_test(true);
49 :
50 10 : odbc_command("DELETE FROM test");
51 :
52 : /* auto commit */
53 10 : insert_test(false);
54 :
55 10 : odbc_command("DROP TABLE test");
56 :
57 10 : odbc_disconnect();
58 :
59 10 : return 0;
60 : }
|