1
[csql.git] / test / dbapi / Table / dbfull1.c
blobb7061a8c8fd700082cd53bfd302f2cca6cc35718
1 // Test Case: DB Full test with only table
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);
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 Table *table = dbMgr->openTable("t1");
26 if (table == NULL)
28 printf("Unable to open table\n");
29 dbMgr->dropTable("t1");
30 conn.close();
31 return -1;
33 int id1 = 0, id2 = 5;
34 char name[20] = "PRAVEEN";
35 table->bindFld("f1", &id1);
36 table->bindFld("f2", &id2);
37 table->bindFld("f3", name);
38 int i=0;
39 for (i = 0 ; i < 4000; i++)
41 conn.startTransaction();
42 id1= i;
43 rv = table->insertTuple();
44 if (rv != OK) break;
45 conn.commit();
47 printf("%d records inserted\n", i);
48 for (int k=0; k <100; k++) {
49 table->setCondition(NULL);
50 rv = table->execute();
51 if (rv != OK) {
52 printf("table execute failed rv:%d\n", rv);
53 dbMgr->closeTable(table);
54 conn.close();
55 return 1;
57 void *tuple = NULL;
58 for (i = 0 ; i < 1000 ; i++)
60 conn.startTransaction();
61 tuple = table->fetchNoBind();
62 if (tuple == NULL) { printf("No more records\n"); break; }
63 rv = table->deleteTuple();
64 if (rv != OK) { printf("Delete tuple failed\n"); break;}
65 conn.commit();
67 table->closeScan();
68 printf("Iteration:%d \n %d records deleted\n", k, i);
69 i=0;
70 for (i = 0 ; i < 1000 ; i++)
72 conn.startTransaction();
73 id1= i;
74 rv = table->insertTuple();
75 if (rv != OK) break;
76 conn.commit();
78 printf("%d records inserted\n", i);
81 dbMgr->closeTable(table);
82 dbMgr->dropTable("t1");
83 conn.close();
84 return 0;