Fixing dbapi/table/test002 failing test
[csql.git] / test / dbapi / Table / inserttest2.c
blob6d63f299ae0d49209bbf69d4f1aef7067f3352c7
1 //Test Case:
2 //Insert 1 million tuples. There will not be enough db space.
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 tabDef.addField("f3", typeString, 1016);
16 rv = dbMgr->createTable("t1", tabDef);
17 if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; }
18 printf("Table created\n");
20 Table *table = dbMgr->openTable("t1");
21 if (table == NULL)
23 printf("Unable to open table\n");
24 dbMgr->dropTable("t1");
25 conn.close();
26 return -1;
28 int id1 = 0, id2 = 5;
29 char name[20] = "PRAVEEN";
30 table->bindFld("f1", &id1);
31 table->bindFld("f2", &id2);
32 table->bindFld("f3", name);
33 int icount =0;
34 for (int i = 0 ; i < 1000 ; i++)
36 conn.startTransaction();
37 for (int j = 0 ; j < 100 ; j++) {
38 id1= icount++;
39 rv = table->insertTuple();
40 if (rv != OK) break;
42 conn.commit();
44 printf("Tuples inserted %d\n", icount);
45 dbMgr->closeTable(table);
46 dbMgr->dropTable("t1");
47 conn.close();
48 if (rv == ErrNoMemory)
50 //insert is expected to fail
51 printf("insert failed with return values %d\n", rv);
52 return 0;
54 return 1;