Addding test cases for connection and datatype module.
[csql.git] / test / dbapi / DataType / longtest.c
blobd909470420003979d53dbdf413ba9df8d7959c39
1 #include<CSql.h>
3 long 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 long 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 %ld %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", typeLong, 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
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 long i;
56 rv =conn.startTransaction();
57 for(i = 0; i< 5; i++)
59 if (rv != OK) exit(5);
60 id= i;
61 strcpy(name, "PRABAKARAN0123456750590");
62 ret = table->insertTuple();
63 if (ret != 0) break;
65 conn.commit();
67 conn.startTransaction();
68 select(table, OpEquals);
69 conn.commit();
71 conn.startTransaction();
72 select(table, OpNotEquals);
73 conn.commit();
75 conn.startTransaction();
76 select(table, OpLessThan);
77 conn.commit();
79 conn.startTransaction();
80 select( table, OpLessThanEquals);
81 conn.commit();
83 conn.startTransaction();
84 select( table, OpGreaterThan);
85 conn.commit();
87 conn.startTransaction();
88 select( table, OpGreaterThanEquals);
89 conn.commit();
91 Condition p1;
92 long val1 = 0;
93 p1.setTerm("f1", OpEquals, &val1);
94 table->setCondition(&p1);
95 rv = conn.startTransaction();
96 for(i = 0; i< 5; i++)
98 if (rv != OK) exit (1);
99 val1 = i;
100 table->execute();
101 tuple = (char*)table->fetch() ;
102 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
103 strcpy(name, "PRABAKARAN0950576543210");
104 table->updateTuple();
105 table->close();
107 conn.commit();
108 rv = conn.startTransaction();
109 for(i = 0; i< 5; i++)
111 if (rv != OK) exit (1);
112 val1 = i;
113 table->execute();
114 tuple = (char*)table->fetch() ;
115 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
116 printf("deleting tuple %ld %s \n", id, name);
117 table->deleteTuple();
118 table->close();
120 conn.commit();
122 table->setCondition(NULL);
123 rv = conn.startTransaction();
124 table->execute();
125 while ((tuple = (char*) table->fetch())) {
126 printf("after delete tuple present. Its value is %ld %s \n", id, name);
127 return 10;
129 table->close();
130 conn.commit();
132 dbMgr->closeTable(table);
133 dbMgr->dropTable("t1");
135 conn.close();
136 return 0;