Addding test cases for connection and datatype module.
[csql.git] / test / dbapi / DataType / floattest.c
bloba7a34d9f1907d2cb26976ea132b9ca5385216845
1 #include<CSql.h>
3 float 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 float val1, i = 1.3;
10 val1=i;
11 p1.setTerm("f1", op, &val1);
12 table->setCondition(&p1);
13 table->execute();
14 void *tuple;
15 while ((tuple = (char*) table->fetch())) {
16 printf("tuple value is %f %s \n", id, name);
18 table->close();
19 return 0;
22 int main()
25 Connection conn;
26 DbRetVal rv = conn.open("praba", "manager");
27 if (rv != OK)
29 printf("Error during connection %d\n", rv);
30 return 1;
32 DatabaseManager *dbMgr = conn.getDatabaseManager();
33 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
34 TableDef tabDef;
35 tabDef.addField("f1", typeFloat, 0, NULL, true, true );
36 tabDef.addField("f2", typeString, 196);
37 rv = dbMgr->createTable("t1", tabDef);
38 if (rv != OK) { printf("Table creation failed\n"); return 3; }
39 printf("Table created\n");
40 #ifdef WITHINDEX
41 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
42 strcpy(idxInfo->tableName, "t1");
43 idxInfo->list.append("f1");
44 idxInfo->indType = hashIndex;
45 rv = dbMgr->createIndex("indx1", idxInfo);
46 if (rv != OK) { printf("Index creation failed\n"); return -1; }
47 printf("Index created\n");
48 #endif
50 Table *table = dbMgr->openTable("t1");
51 if (table == NULL) { printf("Unable to open table\n"); return 4; }
52 table->bindFld("f1", &id);
53 table->bindFld("f2", name);
54 char *tuple;
55 int ret;
56 float i;
57 rv =conn.startTransaction();
58 for(i = 1.0; i< 1.5; i = i + 0.1)
60 if (rv != OK) exit(5);
61 id= i;
62 strcpy(name, "PRABAKARAN0123456750590");
63 ret = table->insertTuple();
64 if (ret != 0) break;
65 printf("Tuple inserted %f\n", i);
67 conn.commit();
69 conn.startTransaction();
70 select(table, OpEquals);
71 conn.commit();
73 conn.startTransaction();
74 select(table, OpNotEquals);
75 conn.commit();
77 conn.startTransaction();
78 select(table, OpLessThan);
79 conn.commit();
81 conn.startTransaction();
82 select( table, OpLessThanEquals);
83 conn.commit();
85 conn.startTransaction();
86 select( table, OpGreaterThan);
87 conn.commit();
89 conn.startTransaction();
90 select( table, OpGreaterThanEquals);
91 conn.commit();
93 Condition p1;
94 float val1 = 0;
95 p1.setTerm("f1", OpEquals, &val1);
96 table->setCondition(&p1);
97 rv = conn.startTransaction();
98 for(i = 1.0; i< 1.5; i = i +0.1)
100 if (rv != OK) exit (1);
101 val1 = 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 = 1.0; i< 1.5; i = i + 0.1)
113 if (rv != OK) exit (1);
114 val1 = i;
115 table->execute();
116 tuple = (char*)table->fetch() ;
117 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
118 printf("deleting tuple %f %s \n", id, name);
119 table->deleteTuple();
120 table->close();
122 conn.commit();
124 table->setCondition(NULL);
125 rv = conn.startTransaction();
126 table->execute();
127 while ((tuple = (char*) table->fetch())) {
128 printf("after delete tuple present. Its value is %f %s \n", id, name);
130 table->close();
131 conn.commit();
133 dbMgr->closeTable(table);
134 dbMgr->dropTable("t1");
136 conn.close();
137 return 0;