code reorg for Transactionw!
[csql.git] / test / dbapi / Table / bindtest2.c
blob62d3a61b34a1acc85bb59dce3ef15ac7c64dbd19
1 #include<CSql.h>
2 //bind twice the same field.
3 //the later should have the effect
4 int main()
6 Connection conn;
7 DbRetVal rv = conn.open("root", "manager");
8 if (rv != OK) return 1;
9 DatabaseManager *dbMgr = conn.getDatabaseManager();
10 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
12 TableDef tabDef;
13 tabDef.addField("f1", typeInt, 0, NULL, true);
14 tabDef.addField("f2", typeInt);
15 rv = dbMgr->createTable("t1", tabDef);
16 if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
17 printf("Table created\n");
19 Table *table = dbMgr->openTable("t1");
20 if (table == NULL)
22 printf("Unable to open table\n");
23 dbMgr->dropTable("t1");
24 conn.close();
25 return -1;
27 int id1 = 1, id2 = 5, id3 = 8;
28 int ret =0;
29 char name[20] = "PRAVEEN";
30 rv = table->bindFld("f1", &id1);
31 if (rv != OK) ret = 1;
32 rv = table->bindFld("f2", &id2);
33 if (rv != OK) ret = 2;
34 rv = table->bindFld("f2", &id3);
35 if (rv != OK) ret = 3;
36 conn.startTransaction();
37 rv = table->insertTuple();
38 conn.commit();
39 conn.startTransaction();
40 table->execute();
41 char *tuple = (char*)table->fetch();
42 int value = *(int*)((char*)tuple + 4);
43 if (value !=8) ret = 5;
44 table->closeScan();
45 dbMgr->closeTable(table);
46 dbMgr->dropTable("t1");
47 conn.close();
48 return ret;