table->close is changed to call table->closeScan
[csql.git] / test / dbapi / DataType / longtest.c
blob928409f3610b3cec70ef89c2b0184e4479de5ff1
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->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", typeLong, 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 failed\n"); return -1; }
48 printf("Index created\n");
49 delete idxInfo;
50 #endif
52 Table *table = dbMgr->openTable("t1");
53 if (table == NULL) { printf("Unable to open table\n"); return 4; }
54 table->bindFld("f1", &id);
55 table->bindFld("f2", name);
56 char *tuple;
57 int ret;
58 long i;
59 rv =conn.startTransaction();
60 for(i = 0; i< 5; i++)
62 if (rv != OK) exit(5);
63 id= i;
64 strcpy(name, "PRABAKARAN0123456750590");
65 ret = table->insertTuple();
66 if (ret != 0) break;
68 conn.commit();
70 conn.startTransaction();
71 select(table, OpEquals);
72 conn.commit();
74 conn.startTransaction();
75 select(table, OpNotEquals);
76 conn.commit();
78 conn.startTransaction();
79 select(table, OpLessThan);
80 conn.commit();
82 conn.startTransaction();
83 select( table, OpLessThanEquals);
84 conn.commit();
86 conn.startTransaction();
87 select( table, OpGreaterThan);
88 conn.commit();
90 conn.startTransaction();
91 select( table, OpGreaterThanEquals);
92 conn.commit();
94 Condition p1;
95 long val1 = 0;
96 p1.setTerm("f1", OpEquals, &val1);
97 table->setCondition(&p1);
98 rv = conn.startTransaction();
99 for(i = 0; i< 5; i++)
101 if (rv != OK) exit (1);
102 val1 = i;
103 table->execute();
104 tuple = (char*)table->fetch() ;
105 if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
106 strcpy(name, "PRABAKARAN0950576543210");
107 table->updateTuple();
108 table->closeScan();
110 conn.commit();
111 rv = conn.startTransaction();
112 for(i = 0; i< 5; i++)
114 if (rv != OK) exit (1);
115 val1 = i;
116 table->execute();
117 tuple = (char*)table->fetch() ;
118 if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;}
119 printf("deleting tuple %ld %s \n", id, name);
120 table->deleteTuple();
121 table->closeScan();
123 conn.commit();
125 table->setCondition(NULL);
126 rv = conn.startTransaction();
127 table->execute();
128 while ((tuple = (char*) table->fetch())) {
129 printf("after delete tuple present. Its value is %ld %s \n", id, name);
130 return 10;
132 table->closeScan();
133 conn.commit();
135 dbMgr->closeTable(table);
136 dbMgr->dropTable("t1");
138 conn.close();
139 return 0;