Adding test scripts for data types
[csql.git] / test / dbapi / DataType / byteinttest.c
bloba3ad85a18e29919b0285831fcb4e23e853e92063
1 #include<CSql.h>
3 ByteInt 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 ByteInt 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 %c %s \n", id, name);
17 table->close();
18 return 0;
21 int main()
24 Connection conn;
25 DbRetVal rv = conn.open("praba", "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", typeByteInt, 0, NULL, true, 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 Table *table = dbMgr->openTable("t1");
40 if (table == NULL) { printf("Unable to open table\n"); return 4; }
41 table->bindFld("f1", &id);
42 table->bindFld("f2", name);
43 char *tuple;
44 int ret;
45 ByteInt i;
46 rv =conn.startTransaction();
47 for(i = 0; i< 5; i++)
49 if (rv != OK) exit(5);
50 id= i;
51 strcpy(name, "PRABAKARAN0123456750590");
52 ret = table->insertTuple();
53 if (ret != 0) break;
55 conn.commit();
57 conn.startTransaction();
58 select(table, OpEquals);
59 conn.commit();
61 conn.startTransaction();
62 select(table, OpNotEquals);
63 conn.commit();
65 conn.startTransaction();
66 select(table, OpLessThan);
67 conn.commit();
69 conn.startTransaction();
70 select( table, OpLessThanEquals);
71 conn.commit();
73 conn.startTransaction();
74 select( table, OpGreaterThan);
75 conn.commit();
77 conn.startTransaction();
78 select( table, OpGreaterThanEquals);
79 conn.commit();
81 Condition p1;
82 ByteInt val1 = 0;
83 p1.setTerm("f1", OpEquals, &val1);
84 table->setCondition(&p1);
85 rv = conn.startTransaction();
86 for(i = 0; i< 5; i++)
88 if (rv != OK) exit (1);
89 val1 = i;
90 table->execute();
91 tuple = (char*)table->fetch() ;
92 if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;}
93 strcpy(name, "PRABAKARAN0950576543210");
94 table->updateTuple();
95 table->close();
97 conn.commit();
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->close();break;}
106 printf("deleting tuple %c %s \n", id, name);
107 table->deleteTuple();
108 table->close();
110 conn.commit();
112 table->setCondition(NULL);
113 rv = conn.startTransaction();
114 table->execute();
115 while ((tuple = (char*) table->fetch())) {
116 printf("after delete tuple present. Its value is %c %s \n", id, name);
117 return 10;
119 table->close();
120 conn.commit();
122 dbMgr->closeTable(table);
123 dbMgr->dropTable("t1");
125 conn.close();
126 return 0;