1
[csql.git] / test / dbapi / DataType / timestamptest.c
blob5e484c36e38e7fa41c66c88ff9d96df53879249e
1 #include<CSql.h>
3 TimeStamp id;
4 char name[196] = "PRABAKARAN";
5 int select(Table *table, ComparisionOp op)
7 printf("Operator test for %d\n", op);
8 Condition p1;
9 TimeStamp val1(1981, 12, 24, 12, 30, 30);
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 ");
16 AllDataType::printVal(&id, typeTimeStamp,0);
17 printf(" %s \n", name);
19 table->closeScan();
20 return 0;
23 int main()
26 Connection conn;
27 DbRetVal rv = conn.open("root", "manager");
28 if (rv != OK)
30 printf("Error during connection %d\n", rv);
31 return 1;
33 DatabaseManager *dbMgr = conn.getDatabaseManager();
34 if (dbMgr == NULL) { printf("Auth failed\n"); return 2;}
35 TableDef tabDef;
36 tabDef.addField("f1", typeTimeStamp, 0, NULL, true);
37 tabDef.addField("f2", typeString, 196);
38 rv = dbMgr->createTable("t1", tabDef);
39 if (rv != OK) { printf("Table creation failed\n"); return 3; }
40 printf("Table created\n");
41 #ifdef WITHINDEX
42 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
43 strcpy(idxInfo->tableName, "t1");
44 idxInfo->list.append("f1");
45 idxInfo->indType = hashIndex;
46 idxInfo->isUnique = true;
47 idxInfo->isPrimary = true;
48 rv = dbMgr->createIndex("indx1", idxInfo);
49 if (rv == OK) { printf("Index creation passed\n"); return 1; }
50 delete idxInfo;
51 dbMgr->dropTable("t1");
52 conn.close();
53 return 0;
54 #endif
55 #ifdef WITHTREEINDEX
56 HashIndexInitInfo *idxInfo = new HashIndexInitInfo();
57 strcpy(idxInfo->tableName, "t1");
58 idxInfo->list.append("f1");
59 idxInfo->indType = treeIndex;
60 rv = dbMgr->createIndex("indx1", idxInfo);
61 delete idxInfo;
62 #endif
64 Table *table = dbMgr->openTable("t1");
65 if (table == NULL) { printf("Unable to open table\n"); return 4; }
66 table->bindFld("f1", &id);
67 table->bindFld("f2", name);
68 char *tuple;
69 int ret;
70 int i;
71 rv =conn.startTransaction();
72 if (rv != OK) exit(5);
73 for(i = 1; i< 10; i++) {
74 id.setDate(1981, 12, 21+i );
75 id.setTime(12, 30, 27 +i);
76 strcpy(name, "PRABAKARAN0123456750590");
77 ret = table->insertTuple();
78 if (ret != 0) break;
79 printf("Inserted ");
80 AllDataType::printVal(&id, typeTimeStamp,0);
81 printf(" %s \n", name);
83 conn.commit();
85 conn.startTransaction();
86 select(table, OpEquals);
87 conn.commit();
89 conn.startTransaction();
90 select(table, OpNotEquals);
91 conn.commit();
93 conn.startTransaction();
94 select(table, OpLessThan);
95 conn.commit();
97 conn.startTransaction();
98 select( table, OpLessThanEquals);
99 conn.commit();
101 conn.startTransaction();
102 select( table, OpGreaterThan);
103 conn.commit();
105 conn.startTransaction();
106 select( table, OpGreaterThanEquals);
107 conn.commit();
109 dbMgr->closeTable(table);
110 dbMgr->dropTable("t1");
112 conn.close();
113 return 0;