windows changes
[csql.git] / test / tools / csqldump / insert.c
blobd4f7bda3227094336553aa5e37e9ee716b7d23be
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 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
20 strcpy(idxInfo->tableName, "t1");
21 idxInfo->list.append("f1");
22 idxInfo->isUnique = true;
23 idxInfo->isPrimary = true;
24 idxInfo->indType = hashIndex;
25 rv = dbMgr->createIndex("indx", idxInfo);
26 if (rv != OK) { printf("Index creation failed\n"); return ErrUnknown; }
27 delete idxInfo;
28 Table *table = dbMgr->openTable("t1");
29 if (table == NULL)
31 printf("Unable to open table\n");
32 dbMgr->dropTable("t1");
33 conn.close();
34 return 2;
36 int id1 = 0, id2 = 5;
37 table->bindFld("f1", &id1);
38 table->bindFld("f2", &id2);
39 int icount =0;
40 for (int i = 0 ; i < 10000 ; i++)
42 conn.startTransaction();
43 for (int j = 0 ; j < 100 ; j++) {
44 id1= icount++;
45 rv = table->insertTuple();
46 if (rv != OK) break;
48 if (rv != OK) break;
49 conn.commit();
51 printf("Tuples inserted %d\n", icount);
52 table->setCondition(NULL);
53 rv = table->execute();
54 if (rv != OK)
56 dbMgr->closeTable(table);
57 dbMgr->dropTable("t1");
58 conn.close();
60 void *fld2ptr, *fld3ptr, *tuple;
61 icount = 0;
62 while(true)
64 tuple = (char*)table->fetch() ;
65 if (tuple == NULL) {break;}
66 icount++;
68 table->closeScan();
69 dbMgr->closeTable(table);
70 conn.close();
71 if (icount != 1000000) return 3;
72 return 0;