code reorg for Transactionw!
[csql.git] / test / dbapi / Table / inserttest3.c
blob12cffc5a1fd0df148de3c23db12800669a33b487
1 //TestCase: We need to start new server to test this.
2 //the default db size set is not enough to test this
3 #include<CSql.h>
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 2;
27 int id1 = 0, id2 = 5;
28 table->bindFld("f1", &id1);
29 table->bindFld("f2", &id2);
30 int icount =0;
31 for (int i = 0 ; i < 10000 ; i++)
33 conn.startTransaction();
34 for (int j = 0 ; j < 100 ; j++) {
35 id1= icount++;
36 rv = table->insertTuple();
37 if (rv != OK) break;
39 if (rv != OK) break;
40 conn.commit();
42 printf("Tuples inserted %d\n", icount);
43 table->setCondition(NULL);
44 rv = table->execute();
45 if (rv != OK)
47 dbMgr->closeTable(table);
48 dbMgr->dropTable("t1");
49 conn.close();
51 void *fld2ptr, *fld3ptr, *tuple;
52 icount = 0;
53 while(true)
55 tuple = (char*)table->fetch() ;
56 if (tuple == NULL) {break;}
57 icount++;
59 table->closeScan();
60 dbMgr->closeTable(table);
61 dbMgr->dropTable("t1");
62 conn.close();
63 if (icount != 1000000) return 3;
64 return 0;