1
[csql.git] / test / dbapi / Connection / conntest14.c
blob61108d1c0ef988966c1eed47e499ddba525049b1
1 //Insert a tuple in a transaction and abort it
2 //scan should not display the inserted tuple.
4 #include<CSql.h>
5 int main()
7 Connection conn;
8 DbRetVal rv = conn.open("root", "manager");
9 if (rv != OK) { printf("Unable to open database\n"); return 1;}
10 DatabaseManager *dbMgr = conn.getDatabaseManager();
11 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
12 TableDef tabDef;
13 tabDef.addField("f1", typeInt);
14 tabDef.addField("f2", typeString, 196);
15 rv = dbMgr->createTable("t1", tabDef);
16 if (rv != OK) { printf("Table creation failed\n"); return 3; }
17 printf("Table created\n");
18 Table *table = dbMgr->openTable("t1");
19 if (table == NULL) { printf("Unable to open table\n"); return 4; }
20 int id = 0;
21 char name[196] = "ARVIND KOTHI";
22 table->bindFld("f1", &id);
23 table->bindFld("f2", name);
24 int i;
25 for (i=0; i<10; i++)
27 id=i;
28 conn.startTransaction();
29 rv = table->insertTuple();
30 if (rv != OK)
32 printf("Insertion failed at %d th tuple", i+1);
33 dbMgr->closeTable(table);
34 dbMgr->dropTable("t1");
35 return 5;
37 conn.commit();
39 printf("%d tuples are inserted into the dababase\n", i);
41 id=100;
42 conn.startTransaction();
43 rv = table->insertTuple();
44 if (rv != OK)
46 printf("Insertion failed at %d th tuple", i+1);
47 dbMgr->closeTable(table);
48 dbMgr->dropTable("t1");
49 return 6;
51 conn.rollback();
52 void *tuple;
53 table->setCondition(NULL);
54 table->execute();
55 while(true)
57 tuple = (char*)table->fetch() ;
58 if (tuple == NULL) {break;}
59 printf("\nBinded Tuple value is %d %s", id, name);
62 table->closeScan();
63 dbMgr->closeTable(table);
64 dbMgr->dropTable("t1");
65 conn.close();
66 return 0;