1
[csql.git] / test / dbapi / Table / dbfull3.c
blob8aee457bca2899bfea2c3387345302aa23237e20
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 4000 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;
36 Table *table = dbMgr->openTable("t1");
37 if (table == NULL)
39 printf("Unable to open table\n");
40 dbMgr->dropTable("t1");
41 conn.close();
42 return -1;
44 int id1 = 0, id2 = 5;
45 char name[20] = "PRAVEEN";
46 table->bindFld("f1", &id1);
47 table->bindFld("f2", &id2);
48 table->bindFld("f3", name);
49 int i=0;
50 for (i = 0 ; i < 4000 ; i++)
52 conn.startTransaction();
53 id1= i;
54 id2= i;
55 rv = table->insertTuple();
56 if (rv != OK) break;
57 conn.commit();
59 printf("%d records inserted\n", i);
60 //sleep(10);
61 for (int k=0; k <100; k++) {
62 table->setCondition(NULL);
63 rv = table->execute();
64 if (rv != OK) {
65 printf("table execute failed rv:%d\n", rv);
66 dbMgr->closeTable(table);
67 conn.close();
68 return 1;
70 void *tuple = NULL;
71 conn.startTransaction();
72 for (i = 0 ; i < 4000 ; i++)
74 tuple = table->fetchNoBind();
75 if (tuple == NULL) { printf("No more records\n"); break; }
76 rv = table->deleteTuple();
77 if (rv != OK) { printf("Delete tuple failed\n"); break;}
78 if (i%50 == 0) { conn.commit(); conn.startTransaction(); }
80 conn.commit();
81 table->closeScan();
82 printf("Iteration:%d \n %d records deleted\n", k, i);
83 i=0;
84 conn.startTransaction();
85 for (i = 0 ; i < 4000 ; i++)
87 id1= i;
88 id2= i;
89 rv = table->insertTuple();
90 if (rv != OK) break;
91 if (i%50 == 0) { conn.commit(); conn.startTransaction(); }
93 conn.commit();
94 printf("%d records inserted\n", i);
97 dbMgr->closeTable(table);
98 dbMgr->dropTable("t1");
99 conn.close();
100 return 0;