*** empty log message ***
[csql.git] / test / dbapi / DataType / chartest.c
blob1c61094ceafc9219ced4250dbb76c52a067e8707
1 #include<CSql.h>
3 char id[30];
4 char name[196] = "PRABAKARAN";
5 int select(Table *table, ComparisionOp op)
7 printf("Operator test for %d\n", op);
8 Condition p1;
9 char val1[30] = "Value3";
10 p1.setTerm("f1", op, &val1);
11 table->setCondition(&p1);
12 table->execute();
13 void *tuple;
14 while ((tuple = (char*) table->fetch())) {
15 printf("tuple value is %s %s \n", id, name);
17 table->closeScan();
18 return 0;
21 int main()
24 Connection conn;
25 DbRetVal rv = conn.open("root", "manager");
26 if (rv != OK)
28 printf("Error during connection %d\n", rv);
29 return 1;
31 DatabaseManager *dbMgr = conn.getDatabaseManager();
32 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
33 TableDef tabDef;
34 tabDef.addField("f1", typeString, 30, NULL, true);
35 tabDef.addField("f2", typeString, 196);
36 rv = dbMgr->createTable("t1", tabDef);
37 if (rv != OK) { printf("Table creation failed\n"); return 3; }
38 printf("Table created\n");
39 #ifdef WITHINDEX
40 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
41 strcpy(idxInfo->tableName, "t1");
42 idxInfo->list.append("f1");
43 idxInfo->isUnique = true;
44 idxInfo->isPrimary = true;
45 idxInfo->indType = hashIndex;
46 rv = dbMgr->createIndex("indx1", idxInfo);
47 if (rv != OK) { printf("Index creation failed\n"); return -1; }
48 printf("Index created\n");
49 delete idxInfo;
50 #endif
51 #ifdef WITHTREEINDEX
52 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
53 strcpy(idxInfo->tableName, "t1");
54 idxInfo->list.append("f1");
55 idxInfo->indType = treeIndex;
56 rv = dbMgr->createIndex("indx1", idxInfo);
57 if (rv != OK) { printf("Index creation failed\n"); return -1; }
58 printf("Index created\n");
59 delete idxInfo;
60 #endif
61 #ifdef WITHTRIEINDEX
62 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
63 strcpy(idxInfo->tableName, "t1");
64 idxInfo->list.append("f1");
65 idxInfo->indType = trieIndex;
66 rv = dbMgr->createIndex("indx1", idxInfo);
67 if (rv != OK) { printf("Index creation failed\n"); return -1; }
68 printf("Index created\n");
69 delete idxInfo;
70 #endif
73 Table *table = dbMgr->openTable("t1");
74 if (table == NULL) { printf("Unable to open table\n"); return 4; }
75 table->bindFld("f1", id);
76 table->bindFld("f2", name);
77 char *tuple;
78 int ret;
79 int i;
80 rv =conn.startTransaction();
81 for(i = 0; i< 5; i++)
83 if (rv != OK) exit(5);
84 // id= i;
85 sprintf(id, "Value%d",i);
86 strcpy(name, "PRABAKARAN0123456750590");
87 ret = table->insertTuple();
88 if (ret != 0) break;
90 conn.commit();
92 conn.startTransaction();
93 select(table, OpEquals);
94 conn.commit();
96 conn.startTransaction();
97 select(table, OpNotEquals);
98 conn.commit();
100 conn.startTransaction();
101 select(table, OpLessThan);
102 conn.commit();
104 conn.startTransaction();
105 select( table, OpLessThanEquals);
106 conn.commit();
108 conn.startTransaction();
109 select( table, OpGreaterThan);
110 conn.commit();
112 conn.startTransaction();
113 select( table, OpGreaterThanEquals);
114 conn.commit();
116 dbMgr->closeTable(table);
117 dbMgr->dropTable("t1");
119 conn.close();
120 return 0;