Addding test cases for connection and datatype module.
[csql.git] / test / dbapi / DataType / chartest.c
blobd4e3d3e8f8e8c65fddead025b447491cbd99287a
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->close();
18 return 0;
21 int main()
24 Connection conn;
25 DbRetVal rv = conn.open("praba", "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, 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->indType = hashIndex;
44 rv = dbMgr->createIndex("indx1", idxInfo);
45 if (rv != OK) { printf("Index creation failed\n"); return -1; }
46 printf("Index created\n");
47 #endif
49 Table *table = dbMgr->openTable("t1");
50 if (table == NULL) { printf("Unable to open table\n"); return 4; }
51 table->bindFld("f1", id);
52 table->bindFld("f2", name);
53 char *tuple;
54 int ret;
55 int i;
56 rv =conn.startTransaction();
57 for(i = 0; i< 5; i++)
59 if (rv != OK) exit(5);
60 // id= i;
61 sprintf(id, "Value%d",i);
62 strcpy(name, "PRABAKARAN0123456750590");
63 ret = table->insertTuple();
64 if (ret != 0) break;
66 conn.commit();
68 conn.startTransaction();
69 select(table, OpEquals);
70 conn.commit();
72 conn.startTransaction();
73 select(table, OpNotEquals);
74 conn.commit();
76 conn.startTransaction();
77 select(table, OpLessThan);
78 conn.commit();
80 conn.startTransaction();
81 select( table, OpLessThanEquals);
82 conn.commit();
84 conn.startTransaction();
85 select( table, OpGreaterThan);
86 conn.commit();
88 conn.startTransaction();
89 select( table, OpGreaterThanEquals);
90 conn.commit();
92 Condition p1;
93 char val1[30];
94 p1.setTerm("f1", OpEquals, &val1);
95 table->setCondition(&p1);
96 rv = conn.startTransaction();
97 for(i = 0; i< 5; i++)
99 if (rv != OK) exit (1);
100 //val1 = i;
101 sprintf(val1, "Value%d", i);
102 table->execute();
103 tuple = (char*)table->fetch() ;
104 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
105 strcpy(name, "PRABAKARAN0950576543210");
106 table->updateTuple();
107 table->close();
109 conn.commit();
110 rv = conn.startTransaction();
111 for(i = 0; i< 5; i++)
113 if (rv != OK) exit (1);
114 sprintf(val1, "Value%d", i);
115 //val1 = i;
116 table->execute();
117 tuple = (char*)table->fetch() ;
118 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
119 printf("deleting tuple %s %s \n", id, name);
120 table->deleteTuple();
121 table->close();
123 conn.commit();
125 table->setCondition(NULL);
126 rv = conn.startTransaction();
127 table->execute();
128 while ((tuple = (char*) table->fetch())) {
129 printf("after delete tuple present. Its value is %s %s \n", id, name);
130 return 10;
132 table->close();
133 conn.commit();
135 dbMgr->closeTable(table);
136 dbMgr->dropTable("t1");
138 conn.close();
139 return 0;