*** empty log message ***
[csql.git] / test / dbapi / Connection / conntest10.c
blobd01689977331feb4d599471b8dbab4f437da653c
1 //Insert a tuple in a transaction and commit it
2 //scan should display the tuple
4 #include<CSql.h>
5 #include<NanoTimer.h>
6 int main()
9 Connection conn;
10 DbRetVal rv = conn.open("root", "manager");
11 if (rv != OK)
13 printf("Error during connection %d\n", rv);
14 return 1;
18 DatabaseManager *dbMgr = conn.getDatabaseManager();
19 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
20 TableDef tabDef;
21 tabDef.addField("f1", typeInt);
22 tabDef.addField("f2", typeString, 196);
23 rv = dbMgr->createTable("t1", tabDef);
24 if (rv != OK) { printf("Table creation failed\n"); return 3; }
25 printf("Table created\n");
26 Table *table = dbMgr->openTable("t1");
27 if (table == NULL) { printf("Unable to open table\n"); return 4; }
28 int id = 0;
29 char name[196] = "PRABAKARAN";
30 table->bindFld("f1", &id);
31 table->bindFld("f2", name);
32 int i;
33 int icount =0;
35 conn.startTransaction();
36 rv = table->insertTuple();
37 if (rv != OK)
39 printf("Insertion failed \n");
40 return 5;
42 conn.commit();
44 conn.startTransaction();
45 table->setCondition(NULL);
46 rv = table->execute();
47 if (rv != OK)
49 dbMgr->closeTable(table);
50 dbMgr->dropTable("t1");
51 conn.close();
52 return 6;
54 void *fld2ptr, *tuple;
56 while(true)
58 tuple = (char*)table->fetch() ;
59 if (tuple == NULL) {break;}
60 printf("Binded Tuple value is %d %s \n", id, name);
63 conn.commit();
64 table->closeScan();
65 dbMgr->closeTable(table);
66 dbMgr->dropTable("t1");
67 printf("test passed successfully\n");
68 return 0;