code reorg for Transactionw!
[csql.git] / test / dbapi / Table / dbfull2.c
blob5596d56c7e03318276c34e206b1d8ff2c64d2cbd
1 // Test Case: DB Full test with table and two index(hash and tree)
2 // Create table
3 // Insert 4000 records
4 // Note:Each page can hold 4 records.
5 // For 100 iterations, delete and insert 1000 records
6 // Result:In all 100 iterations operations should succeed
8 #include<CSql.h>
9 int main()
11 Connection conn;
12 DbRetVal rv = conn.open("root", "manager");
13 if (rv != OK) return 1;
14 DatabaseManager *dbMgr = conn.getDatabaseManager();
15 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
17 TableDef tabDef;
18 tabDef.addField("f1", typeInt, 0, NULL, true);
19 tabDef.addField("f2", typeInt, 0, NULL, true);
20 tabDef.addField("f3", typeString, 2000);
21 rv = dbMgr->createTable("t1", tabDef);
22 if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
23 printf("Table created\n");
25 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
26 strcpy(idxInfo->tableName, "t1");
27 idxInfo->list.append("f1");
28 idxInfo->indType = hashIndex;
29 rv = dbMgr->createIndex("indx1", idxInfo);
30 idxInfo->list.remove("f1");
31 idxInfo->list.append("f2");
32 idxInfo->indType = treeIndex;
33 rv = dbMgr->createIndex("indx2", idxInfo);
34 delete idxInfo;
35 Table *table = dbMgr->openTable("t1");
36 if (table == NULL)
38 printf("Unable to open table\n");
39 dbMgr->dropTable("t1");
40 conn.close();
41 return -1;
43 int id1 = 0, id2 = 5;
44 char name[20] = "PRAVEEN";
45 table->bindFld("f1", &id1);
46 table->bindFld("f2", &id2);
47 table->bindFld("f3", name);
48 int i=0;
49 for (i = 0 ; i < 4000 ; i++)
51 conn.startTransaction();
52 id1= i;
53 id2= i;
54 rv = table->insertTuple();
55 if (rv != OK) break;
56 conn.commit();
58 printf("%d records inserted\n", i);
59 for (int k=0; k <100; k++) {
60 table->setCondition(NULL);
61 rv = table->execute();
62 if (rv != OK) {
63 printf("table execute failed rv:%d\n", rv);
64 dbMgr->closeTable(table);
65 conn.close();
66 return 1;
68 void *tuple = NULL;
69 for (i = 0 ; i < 1000 ; i++)
71 conn.startTransaction();
72 tuple = table->fetchNoBind();
73 if (tuple == NULL) { printf("No more records\n"); break; }
74 rv = table->deleteTuple();
75 if (rv != OK) { printf("Delete tuple failed\n"); break;}
76 conn.commit();
78 table->closeScan();
79 printf("Iteration:%d \n %d records deleted\n", k, i);
80 i=0;
81 for (i = 0 ; i < 1000 ; i++)
83 conn.startTransaction();
84 id1= i;
85 id2= i;
86 rv = table->insertTuple();
87 if (rv != OK) break;
88 conn.commit();
90 printf("%d records inserted\n", i);
93 dbMgr->closeTable(table);
94 dbMgr->dropTable("t1");
95 conn.close();
96 return 0;