Addding test cases for connection and datatype module.
[csql.git] / test / dbapi / DataType / inttest.c
blobd8df10bdd496c12b47eeb27a3fa292193d505f5d
1 #include<CSql.h>
3 int id = 0;
4 char name[196] = "PRABAKARAN";
5 int select(Table *table, ComparisionOp op)
7 printf("Operator test for %d\n", op);
8 Condition p1;
9 int val1 = 3;
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 %d %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", typeInt, 0, 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
48 Table *table = dbMgr->openTable("t1");
49 if (table == NULL) { printf("Unable to open table\n"); return 4; }
50 table->bindFld("f1", &id);
51 table->bindFld("f2", name);
52 char *tuple;
53 int ret;
54 int i;
55 rv =conn.startTransaction();
56 for(i = 0; i< 5; i++)
58 if (rv != OK) exit(5);
59 id= i;
60 strcpy(name, "PRABAKARAN0123456750590");
61 ret = table->insertTuple();
62 if (ret != 0) break;
64 conn.commit();
66 conn.startTransaction();
67 select(table, OpEquals);
68 conn.commit();
70 conn.startTransaction();
71 select(table, OpNotEquals);
72 conn.commit();
74 conn.startTransaction();
75 select(table, OpLessThan);
76 conn.commit();
78 conn.startTransaction();
79 select( table, OpLessThanEquals);
80 conn.commit();
82 conn.startTransaction();
83 select( table, OpGreaterThan);
84 conn.commit();
86 conn.startTransaction();
87 select( table, OpGreaterThanEquals);
88 conn.commit();
90 Condition p1;
91 int val1 = 0;
92 p1.setTerm("f1", OpEquals, &val1);
93 table->setCondition(&p1);
94 rv = conn.startTransaction();
95 for(i = 0; i< 5; i++)
97 if (rv != OK) exit (1);
98 val1 = i;
99 table->execute();
100 tuple = (char*)table->fetch() ;
101 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
102 strcpy(name, "PRABAKARAN0950576543210");
103 table->updateTuple();
104 table->close();
106 conn.commit();
107 rv = conn.startTransaction();
108 for(i = 0; i< 5; i++)
110 if (rv != OK) exit (1);
111 val1 = i;
112 table->execute();
113 tuple = (char*)table->fetch() ;
114 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
115 printf("deleting tuple %d %s \n", id, name);
116 table->deleteTuple();
117 table->close();
119 conn.commit();
121 table->setCondition(NULL);
122 rv = conn.startTransaction();
123 table->execute();
124 while ((tuple = (char*) table->fetch())) {
125 printf("after delete tuple present. Its value is %d %s \n", id, name);
126 return 10;
128 table->close();
129 conn.commit();
131 dbMgr->closeTable(table);
132 dbMgr->dropTable("t1");
134 conn.close();
135 return 0;