table->close is changed to call table->closeScan
[csql.git] / test / dbapi / Index / common.h
blobeca75b9a263a43f3c50a6e0b0ac92868fa6dcd73
1 #include<CSql.h>
2 int createIndex(DatabaseManager *dbMgr, bool unique)
4 //Creating hash index on field f1 of table t1
5 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
6 strcpy(idxInfo->tableName, "t1");
7 idxInfo->list.append("f1");
8 idxInfo->indType = hashIndex;
9 #ifndef DEFAULT
10 idxInfo->isUnique = unique;
11 #endif
12 DbRetVal rv = dbMgr->createIndex("indx1", idxInfo);
13 if (rv != OK) { printf("Index creation failed\n"); return 1; }
14 printf("Index created\n");
15 delete idxInfo;
16 return 0;
18 int createTable(DatabaseManager *dbMgr)
20 TableDef tabDef;
21 tabDef.addField("f1", typeInt, 0, NULL, true);
22 tabDef.addField("f2", typeInt);
23 tabDef.addField("f3", typeString, 20);
24 DbRetVal rv = dbMgr->createTable("t1", tabDef);
25 if (rv != OK) { printf("Table creation failed\n"); return 1; }
26 printf("Table created\n");
27 return 0;
29 int insertTupleWithSameValue(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, id2 = 5;
38 char name[20] = "PRAVEEN";
39 table->bindFld("f1", &id1);
40 table->bindFld("f2", &id2);
41 table->bindFld("f3", name);
42 int icount =0;
43 DbRetVal rv = OK;
44 for (int i = 0 ; i < 10 ; i++)
46 conn.startTransaction();
47 id1= 10;
48 rv = table->insertTuple();
49 if (rv != OK) break;
50 icount++;
51 conn.commit();
54 printf("Total Tuples inserted is %d\n", icount);
55 dbMgr->closeTable(table);
56 return icount;
60 int insertTuplef2NUL(DatabaseManager *dbMgr, Connection &conn)
62 Table *table = dbMgr->openTable("t1");
63 if (table == NULL)
65 printf("Unable to open table\n");
66 return 0;
68 int id1 = 0, id2;
69 int count=0;
70 table->bindFld("f1", &id1);
71 //table->bindFld("f2", &id2);
72 DbRetVal rv = OK;
73 for( int i=10;i<=20;i=i+10)
75 conn.startTransaction();
76 id1= i;
77 rv = table->insertTuple();
78 if (rv != OK) { printf("Insertion failed "); break; }
79 count++;
80 conn.commit();
82 printf("Tuple inserted is %d \n",count);
83 dbMgr->closeTable(table);
84 return 0;
87 int creatTable(DatabaseManager *dbMgr)
89 TableDef tabDef;
90 tabDef.addField("f1", typeInt, 0, NULL, true);
91 tabDef.addField("f2", typeInt);
92 DbRetVal rv = dbMgr->createTable("t1", tabDef);
93 if (rv != OK) { printf("Table creation failed\n"); return 1; }
94 printf("Table created\n");
95 return 0;
97 int createIndex(DatabaseManager *dbMgr)
99 //Creating hash index on field f1 of table t1
100 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
101 strcpy(idxInfo->tableName, "t1");
102 idxInfo->list.append("f1");
103 idxInfo->indType = hashIndex;
105 DbRetVal rv = dbMgr->createIndex("indx1", idxInfo);
106 if (rv != OK) { printf("Index creation failed\n"); return 1; }
107 printf("Index created for t1(f1)\n");
109 //Creating hash index on field f2 of table t1
110 strcpy(idxInfo->tableName, "t1");
111 idxInfo->list.remove("f1");
112 idxInfo->list.append("f2");
113 idxInfo->indType = hashIndex;
115 rv = dbMgr->createIndex("indx2", idxInfo);
116 if (rv != OK) { printf("Index creation failed\n"); return 1; }
117 printf("Index created for t1(f2)\n");
119 delete idxInfo;
120 return 0;