Addding test cases for connection and datatype module.
[csql.git] / test / dbapi / DataType / timetest.c
blob85b3ebbff17b9b20350703e50ce1c416d11c8766
1 #include<CSql.h>
3 Time id;
4 char name[196] = "PRABAKARAN";
5 int select(Table *table, ComparisionOp op)
7 printf("Operator test for %d\n", op);
8 Condition p1;
9 Time val1(12, 30, 30);
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 ");
16 AllDataType::printVal(&id, typeTime,0);
17 printf(" %s \n", name);
19 table->close();
20 return 0;
23 int main()
26 Connection conn;
27 DbRetVal rv = conn.open("praba", "manager");
28 if (rv != OK)
30 printf("Error during connection %d\n", rv);
31 return 1;
33 DatabaseManager *dbMgr = conn.getDatabaseManager();
34 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
35 TableDef tabDef;
36 tabDef.addField("f1", typeTime, 0, NULL, true, true );
37 tabDef.addField("f2", typeString, 196);
38 rv = dbMgr->createTable("t1", tabDef);
39 if (rv != OK) { printf("Table creation failed\n"); return 3; }
40 printf("Table created\n");
41 #ifdef WITHINDEX
42 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
43 strcpy(idxInfo->tableName, "t1");
44 idxInfo->list.append("f1");
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 #endif
51 Table *table = dbMgr->openTable("t1");
52 if (table == NULL) { printf("Unable to open table\n"); return 4; }
53 table->bindFld("f1", &id);
54 table->bindFld("f2", name);
55 char *tuple;
56 int ret;
57 long i;
58 rv =conn.startTransaction();
59 for(i = 10; i< 15; i++)
61 if (rv != OK) exit(5);
62 for (int j =29 ; j <34; j++) {
63 id.set(i, j, 30);
64 strcpy(name, "PRABAKARAN0123456750590");
65 ret = table->insertTuple();
66 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 Time val1;
97 p1.setTerm("f1", OpEquals, &val1);
98 table->setCondition(&p1);
99 rv = conn.startTransaction();
100 if (rv != OK) exit (1);
101 val1.set(12, 30, 30);
102 table->execute();
103 tuple = (char*)table->fetch() ;
104 if (tuple != NULL) {
105 strcpy(name, "My value is updated");
106 table->updateTuple();
108 table->close();
110 conn.commit();
111 rv = conn.startTransaction();
112 for(i = 0; i< 5; i++)
114 if (rv != OK) exit (1);
115 val1.set(12, 29+i, 30);
116 //val1 = i;
117 table->execute();
118 tuple = (char*)table->fetch() ;
119 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
120 printf("deleting tuple ");
121 AllDataType::printVal(&id, typeTime,0);
122 printf(" %s \n", name);
123 table->deleteTuple();
124 table->close();
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 value is ");
133 AllDataType::printVal(&id, typeTime,0);
134 printf(" %s \n", name);
136 table->close();
137 conn.commit();
139 dbMgr->closeTable(table);
140 dbMgr->dropTable("t1");
142 conn.close();
143 return 0;