Adding tests for checking unique index creation
[csql.git] / test / dbapi / Index / common.h
blob52a3d49cf68f3b670994c533f8a098640b02cc04
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 return 0;
17 int createTable(DatabaseManager *dbMgr)
19 TableDef tabDef;
20 tabDef.addField("f1", typeInt, 0, NULL, true, true);
21 tabDef.addField("f2", typeInt);
22 tabDef.addField("f3", typeString, 20);
23 DbRetVal rv = dbMgr->createTable("t1", tabDef);
24 if (rv != OK) { printf("Table creation failed\n"); return 1; }
25 printf("Table created\n");
26 return 0;
28 int insertTupleWithSameValue(DatabaseManager *dbMgr, Connection &conn)
30 Table *table = dbMgr->openTable("t1");
31 if (table == NULL)
33 printf("Unable to open table\n");
34 return 0;
36 int id1 = 0, id2 = 5;
37 char name[20] = "PRAVEEN";
38 table->bindFld("f1", &id1);
39 table->bindFld("f2", &id2);
40 table->bindFld("f3", name);
41 int icount =0;
42 DbRetVal rv = OK;
43 for (int i = 0 ; i < 10 ; i++)
45 conn.startTransaction();
46 id1= 10;
47 rv = table->insertTuple();
48 if (rv != OK) break;
49 icount++;
50 conn.commit();
53 printf("Total Tuples inserted is %d\n", icount);
54 dbMgr->closeTable(table);
55 return icount;