adding test scripts
[csql.git] / test / dbapi / DataType / doubletest.c
blob78082f9aab23ff0e6fc3f4f7d994ba52d8b779d4
1 #include<CSql.h>
3 double 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 double val1 = 1.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 %g %s \n", id, name);
17 table->closeScan();
18 return 0;
21 int main()
24 Connection conn;
25 DbRetVal rv = conn.open("root", "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", typeDouble, 0 , NULL, 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 idxInfo->isUnique = true;
45 idxInfo->isPrimary = true;
46 rv = dbMgr->createIndex("indx1", idxInfo);
47 if (rv == OK) { printf("Index creation passed\n"); return 1; }
48 delete idxInfo;
49 dbMgr->dropTable("t1");
50 conn.close();
51 return 0;
52 #endif
53 #ifdef WITHTREEINDEX
54 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
55 strcpy(idxInfo->tableName, "t1");
56 idxInfo->list.append("f1");
57 idxInfo->indType = treeIndex;
58 rv = dbMgr->createIndex("indx1", idxInfo);
59 delete idxInfo;
60 #endif
61 Table *table = dbMgr->openTable("t1");
62 if (table == NULL) { printf("Unable to open table\n"); return 4; }
63 table->bindFld("f1", &id);
64 table->bindFld("f2", name);
65 char *tuple;
66 int ret;
67 double i;
68 rv =conn.startTransaction();
69 for(i = 1.0; i< 1.5; i = i + 0.1)
71 if (rv != OK) exit(5);
72 id= i;
73 strcpy(name, "PRABAKARAN0123456750590");
74 ret = table->insertTuple();
75 if (ret != 0) break;
76 printf("Tuple inserted %g\n", i);
78 conn.commit();
80 conn.startTransaction();
81 select(table, OpEquals);
82 conn.commit();
84 conn.startTransaction();
85 select(table, OpNotEquals);
86 conn.commit();
88 conn.startTransaction();
89 select(table, OpLessThan);
90 conn.commit();
92 conn.startTransaction();
93 select( table, OpLessThanEquals);
94 conn.commit();
96 conn.startTransaction();
97 select( table, OpGreaterThan);
98 conn.commit();
100 conn.startTransaction();
101 select( table, OpGreaterThanEquals);
102 conn.commit();
104 dbMgr->closeTable(table);
105 dbMgr->dropTable("t1");
107 conn.close();
108 return 0;