table->closeScan is called instead of close.
[csql.git] / test / dbapi / Predicate / common.h
blob2dc6196aea4d2eeff0b7ffacdaccc587973f7379
1 #include<CSql.h>
2 DbRetVal createIndex(DatabaseManager *dbMgr, char *fldname, char *indname)
4 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
5 strcpy(idxInfo->tableName, "t1");
6 idxInfo->list.append(fldname);
7 idxInfo->indType = hashIndex;
8 idxInfo->isUnique = true;
9 idxInfo->isPrimary = true;
10 DbRetVal rv = dbMgr->createIndex(indname, idxInfo);
11 if (rv != OK) { printf("Index creation failed\n"); return rv; }
12 printf("Index created for %s\n", fldname);
13 delete idxInfo;
14 return OK;
16 DbRetVal createTable(DatabaseManager *dbMgr)
18 TableDef tabDef;
19 tabDef.addField("f1", typeInt, 0, NULL, true);
20 tabDef.addField("f2", typeInt, 0, NULL, true);
21 tabDef.addField("f3", typeInt);
22 tabDef.addField("f4", typeInt);
23 tabDef.addField("f5", typeInt);
24 DbRetVal rv = dbMgr->createTable("t1", tabDef);
25 if (rv != OK) { printf("Table creation failed\n"); return rv; }
26 printf("Table created\n");
27 return OK;
29 int insertTuple(DatabaseManager *dbMgr, Connection &conn)
31 Table *table = dbMgr->openTable("t1");
32 if (table == NULL)
34 printf("Unable to open table\n");
35 return 0;
37 int id1 = 0;
38 table->bindFld("f1", &id1);
39 table->bindFld("f2", &id1);
40 table->bindFld("f3", &id1);
41 table->bindFld("f4", &id1);
42 table->bindFld("f5", &id1);
43 int icount =0;
44 DbRetVal rv = OK;
45 rv = conn.startTransaction();
46 if (rv != OK) { dbMgr->closeTable(table); return 1; }
47 for (int i = 0 ; i < 10 ; i++)
49 id1= i;
50 rv = table->insertTuple();
51 if (rv != OK) break;
52 icount++;
55 conn.commit();
56 printf("Total Tuples inserted is %d\n", icount);
57 dbMgr->closeTable(table);
58 return icount;
60 DbRetVal execAndPrint(Table *table)
62 table->execute();
63 void *tuple;
64 while ((tuple = (char*) table->fetch())) {
65 char *t = (char*) tuple;
66 printf("tuple value is %d %d %d %d %d\n", *(int*)t, *(int*)(t+4),
67 *(int*)(t+8),*(int*)(t+12),*(int*)(t+16));
69 table->closeScan();
70 return OK;