table->close is changed to call table->closeScan
[csql.git] / test / dbapi / DataType / chartest.c
blob53edc350532f783a65075ed27c39bf4b8be9a75c
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
52 Table *table = dbMgr->openTable("t1");
53 if (table == NULL) { printf("Unable to open table\n"); return 4; }
54 table->bindFld("f1", id);
55 table->bindFld("f2", name);
56 char *tuple;
57 int ret;
58 int i;
59 rv =conn.startTransaction();
60 for(i = 0; i< 5; i++)
62 if (rv != OK) exit(5);
63 // id= i;
64 sprintf(id, "Value%d",i);
65 strcpy(name, "PRABAKARAN0123456750590");
66 ret = table->insertTuple();
67 if (ret != 0) break;
69 conn.commit();
71 conn.startTransaction();
72 select(table, OpEquals);
73 conn.commit();
75 conn.startTransaction();
76 select(table, OpNotEquals);
77 conn.commit();
79 conn.startTransaction();
80 select(table, OpLessThan);
81 conn.commit();
83 conn.startTransaction();
84 select( table, OpLessThanEquals);
85 conn.commit();
87 conn.startTransaction();
88 select( table, OpGreaterThan);
89 conn.commit();
91 conn.startTransaction();
92 select( table, OpGreaterThanEquals);
93 conn.commit();
95 Condition p1;
96 char val1[30];
97 p1.setTerm("f1", OpEquals, &val1);
98 table->setCondition(&p1);
99 rv = conn.startTransaction();
100 for(i = 0; i< 5; i++)
102 if (rv != OK) exit (1);
103 //val1 = i;
104 sprintf(val1, "Value%d", i);
105 table->execute();
106 tuple = (char*)table->fetch() ;
107 if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
108 strcpy(name, "PRABAKARAN0950576543210");
109 table->updateTuple();
110 table->closeScan();
112 conn.commit();
113 rv = conn.startTransaction();
114 for(i = 0; i< 5; i++)
116 if (rv != OK) exit (1);
117 sprintf(val1, "Value%d", i);
118 //val1 = i;
119 table->execute();
120 tuple = (char*)table->fetch() ;
121 if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
122 printf("deleting tuple %s %s \n", id, name);
123 table->deleteTuple();
124 table->closeScan();
126 conn.commit();
128 table->setCondition(NULL);
129 rv = conn.startTransaction();
130 table->execute();
131 while ((tuple = (char*) table->fetch())) {
132 printf("after delete tuple present. Its value is %s %s \n", id, name);
133 return 10;
135 table->closeScan();
136 conn.commit();
138 dbMgr->closeTable(table);
139 dbMgr->dropTable("t1");
141 conn.close();
142 return 0;