1
[csql.git] / test / dbapi / DataType / floattest.c
blob6cfe1732101555e907ff9bab3785a41914f8f3a0
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->closeScan();
19 return 0;
22 int main()
25 Connection conn;
26 DbRetVal rv = conn.open("root", "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);
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->isUnique = true;
45 idxInfo->isPrimary = true;
46 idxInfo->indType = hashIndex;
47 rv = dbMgr->createIndex("indx1", idxInfo);
48 if (rv == OK) { printf("Index creation passed\n"); return 1; }
49 delete idxInfo;
50 dbMgr->dropTable("t1");
51 conn.close();
52 return 0;
53 #endif
54 #ifdef WITHTREEINDEX
55 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
56 strcpy(idxInfo->tableName, "t1");
57 idxInfo->list.append("f1");
58 idxInfo->indType = treeIndex;
59 rv = dbMgr->createIndex("indx1", idxInfo);
60 delete idxInfo;
61 #endif
63 Table *table = dbMgr->openTable("t1");
64 if (table == NULL) { printf("Unable to open table\n"); return 4; }
65 table->bindFld("f1", &id);
66 table->bindFld("f2", name);
67 char *tuple;
68 int ret;
69 float i;
70 rv =conn.startTransaction();
71 for(i = 1.0; i< 1.5; i = i + 0.1)
73 if (rv != OK) exit(5);
74 id= i;
75 strcpy(name, "PRABAKARAN0123456750590");
76 ret = table->insertTuple();
77 if (ret != 0) break;
78 printf("Tuple inserted %f\n", i);
80 conn.commit();
82 conn.startTransaction();
83 select(table, OpEquals);
84 conn.commit();
86 conn.startTransaction();
87 select(table, OpNotEquals);
88 conn.commit();
90 conn.startTransaction();
91 select(table, OpLessThan);
92 conn.commit();
94 conn.startTransaction();
95 select( table, OpLessThanEquals);
96 conn.commit();
98 conn.startTransaction();
99 select( table, OpGreaterThan);
100 conn.commit();
102 conn.startTransaction();
103 select( table, OpGreaterThanEquals);
104 conn.commit();
107 dbMgr->closeTable(table);
108 dbMgr->dropTable("t1");
110 conn.close();
111 return 0;