From 2aa996d0ab0601f492d6eeea3d70d654b13c03b1 Mon Sep 17 00:00:00 2001 From: prabatuty Date: Tue, 20 Nov 2007 19:39:34 +0000 Subject: [PATCH] Adding test scripts for data types --- test/TestModules | 4 +- test/dbapi/Connection/threadtest1.c | 2 +- test/dbapi/DataType/Makefile | 50 ++++++++++++++ test/dbapi/DataType/byteinttest.c | 127 ++++++++++++++++++++++++++++++++++++ test/dbapi/DataType/exp.test001 | 27 ++++++++ test/dbapi/DataType/exp.test002 | 27 ++++++++ test/dbapi/DataType/exp.test003 | 27 ++++++++ test/dbapi/DataType/exp.test004 | 27 ++++++++ test/dbapi/DataType/exp.test005 | 27 ++++++++ test/dbapi/DataType/inttest.c | 127 ++++++++++++++++++++++++++++++++++++ test/dbapi/DataType/longlongtest.c | 127 ++++++++++++++++++++++++++++++++++++ test/dbapi/DataType/longtest.c | 127 ++++++++++++++++++++++++++++++++++++ test/dbapi/DataType/shorttest.c | 127 ++++++++++++++++++++++++++++++++++++ 13 files changed, 824 insertions(+), 2 deletions(-) create mode 100644 test/dbapi/DataType/Makefile create mode 100644 test/dbapi/DataType/byteinttest.c create mode 100644 test/dbapi/DataType/exp.test001 create mode 100644 test/dbapi/DataType/exp.test002 create mode 100644 test/dbapi/DataType/exp.test003 create mode 100644 test/dbapi/DataType/exp.test004 create mode 100644 test/dbapi/DataType/exp.test005 create mode 100644 test/dbapi/DataType/inttest.c create mode 100644 test/dbapi/DataType/longlongtest.c create mode 100644 test/dbapi/DataType/longtest.c create mode 100644 test/dbapi/DataType/shorttest.c diff --git a/test/TestModules b/test/TestModules index 438cc353..e816bafc 100644 --- a/test/TestModules +++ b/test/TestModules @@ -3,4 +3,6 @@ #Any line which has "#" symbol is considered as comment and negleted dbapi/Connection dbapi/UserManager -dbapi/Table +#dbapi/Table +dbapi/Index +dbapi/DataType diff --git a/test/dbapi/Connection/threadtest1.c b/test/dbapi/Connection/threadtest1.c index b2bb8397..a32b7243 100644 --- a/test/dbapi/Connection/threadtest1.c +++ b/test/dbapi/Connection/threadtest1.c @@ -45,7 +45,7 @@ void* print_message_function(void *ptr) tabDef.addField("f2", typeInt); rv = dbMgr->createTable("t1", tabDef); if (rv != OK) { printf("Table creation failed\n"); return NULL; } - printf("Table created\n"); + printf("Table created %d %lu\n", os::getpid(), os::getthrid()); rv = conn.close(); if (rv != OK) { printf("Thread Return value of close %d %d\n", rv, getpid()); } diff --git a/test/dbapi/DataType/Makefile b/test/dbapi/DataType/Makefile new file mode 100644 index 00000000..64625d6f --- /dev/null +++ b/test/dbapi/DataType/Makefile @@ -0,0 +1,50 @@ + +OSNAME = $(shell uname -s) +PlatForm=supported + +ifeq ($(OSNAME), SunOS) +CPlus = CC +CPlusFlags = -O2 -w -mt -xarch=v8 +SYSLIBS=-ldl -lnsl -lsocket -lposix4 +else +ifeq ($(OSNAME), Linux) +CPlus = g++ +CPlusFlags = -g -w +SYSLIBS= -rdynamic -lrt -lpthread -lcrypt +else +PlatForm=notsupported +all: + echo "CSQL is not supported on $(OSNAME) platform" +endif +endif + +INCL= -I$(CSQL_INSTALL_ROOT)/include +LIBS= -L$(CSQL_INSTALL_ROOT)/lib -lcsql + +TARGETS = \ + test001 \ + test002 \ + test003 \ + test004 \ + test005 + + + +ifeq ($(PlatForm), supported) +all: $(TARGETS) +endif + +test001: inttest.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test002: longtest.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test003: longlongtest.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test004: shorttest.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test005: byteinttest.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) + +clean: + rm -f $(TARGETS) + diff --git a/test/dbapi/DataType/byteinttest.c b/test/dbapi/DataType/byteinttest.c new file mode 100644 index 00000000..a3ad85a1 --- /dev/null +++ b/test/dbapi/DataType/byteinttest.c @@ -0,0 +1,127 @@ +#include + +ByteInt id = 0; +char name[196] = "PRABAKARAN"; +int select(Table *table, ComparisionOp op) +{ + printf("Operator test for %d\n", op); + Condition p1; + ByteInt val1 = 3; + p1.setTerm("f1", op, &val1); + table->setCondition(&p1); + table->execute(); + void *tuple; + while ((tuple = (char*) table->fetch())) { + printf("tuple value is %c %s \n", id, name); + } + table->close(); + return 0; +} + +int main() +{ + + Connection conn; + DbRetVal rv = conn.open("praba", "manager"); + if (rv != OK) + { + printf("Error during connection %d\n", rv); + return 1; + } + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + TableDef tabDef; + tabDef.addField("f1", typeByteInt, 0, NULL, true, true); + tabDef.addField("f2", typeString, 196); + rv = dbMgr->createTable("t1", tabDef); + if (rv != OK) { printf("Table creation failed\n"); return 3; } + printf("Table created\n"); + Table *table = dbMgr->openTable("t1"); + if (table == NULL) { printf("Unable to open table\n"); return 4; } + table->bindFld("f1", &id); + table->bindFld("f2", name); + char *tuple; + int ret; + ByteInt i; + rv =conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit(5); + id= i; + strcpy(name, "PRABAKARAN0123456750590"); + ret = table->insertTuple(); + if (ret != 0) break; + } + conn.commit(); + + conn.startTransaction(); + select(table, OpEquals); + conn.commit(); + + conn.startTransaction(); + select(table, OpNotEquals); + conn.commit(); + + conn.startTransaction(); + select(table, OpLessThan); + conn.commit(); + + conn.startTransaction(); + select( table, OpLessThanEquals); + conn.commit(); + + conn.startTransaction(); + select( table, OpGreaterThan); + conn.commit(); + + conn.startTransaction(); + select( table, OpGreaterThanEquals); + conn.commit(); + + Condition p1; + ByteInt val1 = 0; + p1.setTerm("f1", OpEquals, &val1); + table->setCondition(&p1); + rv = conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit (1); + val1 = i; + table->execute(); + tuple = (char*)table->fetch() ; + if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;} + strcpy(name, "PRABAKARAN0950576543210"); + table->updateTuple(); + table->close(); + } + conn.commit(); + rv = conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit (1); + val1 = i; + table->execute(); + tuple = (char*)table->fetch() ; + if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;} + printf("deleting tuple %c %s \n", id, name); + table->deleteTuple(); + table->close(); + } + conn.commit(); + + table->setCondition(NULL); + rv = conn.startTransaction(); + table->execute(); + while ((tuple = (char*) table->fetch())) { + printf("after delete tuple present. Its value is %c %s \n", id, name); + return 10; + } + table->close(); + conn.commit(); + + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + + conn.close(); + return 0; +} diff --git a/test/dbapi/DataType/exp.test001 b/test/dbapi/DataType/exp.test001 new file mode 100644 index 00000000..c4e31c5c --- /dev/null +++ b/test/dbapi/DataType/exp.test001 @@ -0,0 +1,27 @@ +Table created +Operator test for 0 +tuple value is 3 PRABAKARAN0123456750590 +Operator test for 1 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +tuple value is 4 PRABAKARAN0123456750590 +Operator test for 2 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +Operator test for 3 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +tuple value is 3 PRABAKARAN0123456750590 +Operator test for 4 +tuple value is 4 PRABAKARAN0123456750590 +Operator test for 5 +tuple value is 3 PRABAKARAN0123456750590 +tuple value is 4 PRABAKARAN0123456750590 +deleting tuple 0 PRABAKARAN0950576543210 +deleting tuple 1 PRABAKARAN0950576543210 +deleting tuple 2 PRABAKARAN0950576543210 +deleting tuple 3 PRABAKARAN0950576543210 +deleting tuple 4 PRABAKARAN0950576543210 diff --git a/test/dbapi/DataType/exp.test002 b/test/dbapi/DataType/exp.test002 new file mode 100644 index 00000000..c4e31c5c --- /dev/null +++ b/test/dbapi/DataType/exp.test002 @@ -0,0 +1,27 @@ +Table created +Operator test for 0 +tuple value is 3 PRABAKARAN0123456750590 +Operator test for 1 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +tuple value is 4 PRABAKARAN0123456750590 +Operator test for 2 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +Operator test for 3 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +tuple value is 3 PRABAKARAN0123456750590 +Operator test for 4 +tuple value is 4 PRABAKARAN0123456750590 +Operator test for 5 +tuple value is 3 PRABAKARAN0123456750590 +tuple value is 4 PRABAKARAN0123456750590 +deleting tuple 0 PRABAKARAN0950576543210 +deleting tuple 1 PRABAKARAN0950576543210 +deleting tuple 2 PRABAKARAN0950576543210 +deleting tuple 3 PRABAKARAN0950576543210 +deleting tuple 4 PRABAKARAN0950576543210 diff --git a/test/dbapi/DataType/exp.test003 b/test/dbapi/DataType/exp.test003 new file mode 100644 index 00000000..c4e31c5c --- /dev/null +++ b/test/dbapi/DataType/exp.test003 @@ -0,0 +1,27 @@ +Table created +Operator test for 0 +tuple value is 3 PRABAKARAN0123456750590 +Operator test for 1 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +tuple value is 4 PRABAKARAN0123456750590 +Operator test for 2 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +Operator test for 3 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +tuple value is 3 PRABAKARAN0123456750590 +Operator test for 4 +tuple value is 4 PRABAKARAN0123456750590 +Operator test for 5 +tuple value is 3 PRABAKARAN0123456750590 +tuple value is 4 PRABAKARAN0123456750590 +deleting tuple 0 PRABAKARAN0950576543210 +deleting tuple 1 PRABAKARAN0950576543210 +deleting tuple 2 PRABAKARAN0950576543210 +deleting tuple 3 PRABAKARAN0950576543210 +deleting tuple 4 PRABAKARAN0950576543210 diff --git a/test/dbapi/DataType/exp.test004 b/test/dbapi/DataType/exp.test004 new file mode 100644 index 00000000..c4e31c5c --- /dev/null +++ b/test/dbapi/DataType/exp.test004 @@ -0,0 +1,27 @@ +Table created +Operator test for 0 +tuple value is 3 PRABAKARAN0123456750590 +Operator test for 1 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +tuple value is 4 PRABAKARAN0123456750590 +Operator test for 2 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +Operator test for 3 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +tuple value is 3 PRABAKARAN0123456750590 +Operator test for 4 +tuple value is 4 PRABAKARAN0123456750590 +Operator test for 5 +tuple value is 3 PRABAKARAN0123456750590 +tuple value is 4 PRABAKARAN0123456750590 +deleting tuple 0 PRABAKARAN0950576543210 +deleting tuple 1 PRABAKARAN0950576543210 +deleting tuple 2 PRABAKARAN0950576543210 +deleting tuple 3 PRABAKARAN0950576543210 +deleting tuple 4 PRABAKARAN0950576543210 diff --git a/test/dbapi/DataType/exp.test005 b/test/dbapi/DataType/exp.test005 new file mode 100644 index 00000000..c4e31c5c --- /dev/null +++ b/test/dbapi/DataType/exp.test005 @@ -0,0 +1,27 @@ +Table created +Operator test for 0 +tuple value is 3 PRABAKARAN0123456750590 +Operator test for 1 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +tuple value is 4 PRABAKARAN0123456750590 +Operator test for 2 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +Operator test for 3 +tuple value is 0 PRABAKARAN0123456750590 +tuple value is 1 PRABAKARAN0123456750590 +tuple value is 2 PRABAKARAN0123456750590 +tuple value is 3 PRABAKARAN0123456750590 +Operator test for 4 +tuple value is 4 PRABAKARAN0123456750590 +Operator test for 5 +tuple value is 3 PRABAKARAN0123456750590 +tuple value is 4 PRABAKARAN0123456750590 +deleting tuple 0 PRABAKARAN0950576543210 +deleting tuple 1 PRABAKARAN0950576543210 +deleting tuple 2 PRABAKARAN0950576543210 +deleting tuple 3 PRABAKARAN0950576543210 +deleting tuple 4 PRABAKARAN0950576543210 diff --git a/test/dbapi/DataType/inttest.c b/test/dbapi/DataType/inttest.c new file mode 100644 index 00000000..a1e664af --- /dev/null +++ b/test/dbapi/DataType/inttest.c @@ -0,0 +1,127 @@ +#include + +int id = 0; +char name[196] = "PRABAKARAN"; +int select(Table *table, ComparisionOp op) +{ + printf("Operator test for %d\n", op); + Condition p1; + int val1 = 3; + p1.setTerm("f1", op, &val1); + table->setCondition(&p1); + table->execute(); + void *tuple; + while ((tuple = (char*) table->fetch())) { + printf("tuple value is %d %s \n", id, name); + } + table->close(); + return 0; +} + +int main() +{ + + Connection conn; + DbRetVal rv = conn.open("praba", "manager"); + if (rv != OK) + { + printf("Error during connection %d\n", rv); + return 1; + } + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + TableDef tabDef; + tabDef.addField("f1", typeInt, 0, NULL, true, true ); + tabDef.addField("f2", typeString, 196); + rv = dbMgr->createTable("t1", tabDef); + if (rv != OK) { printf("Table creation failed\n"); return 3; } + printf("Table created\n"); + Table *table = dbMgr->openTable("t1"); + if (table == NULL) { printf("Unable to open table\n"); return 4; } + table->bindFld("f1", &id); + table->bindFld("f2", name); + char *tuple; + int ret; + int i; + rv =conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit(5); + id= i; + strcpy(name, "PRABAKARAN0123456750590"); + ret = table->insertTuple(); + if (ret != 0) break; + } + conn.commit(); + + conn.startTransaction(); + select(table, OpEquals); + conn.commit(); + + conn.startTransaction(); + select(table, OpNotEquals); + conn.commit(); + + conn.startTransaction(); + select(table, OpLessThan); + conn.commit(); + + conn.startTransaction(); + select( table, OpLessThanEquals); + conn.commit(); + + conn.startTransaction(); + select( table, OpGreaterThan); + conn.commit(); + + conn.startTransaction(); + select( table, OpGreaterThanEquals); + conn.commit(); + + Condition p1; + int val1 = 0; + p1.setTerm("f1", OpEquals, &val1); + table->setCondition(&p1); + rv = conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit (1); + val1 = i; + table->execute(); + tuple = (char*)table->fetch() ; + if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;} + strcpy(name, "PRABAKARAN0950576543210"); + table->updateTuple(); + table->close(); + } + conn.commit(); + rv = conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit (1); + val1 = i; + table->execute(); + tuple = (char*)table->fetch() ; + if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;} + printf("deleting tuple %d %s \n", id, name); + table->deleteTuple(); + table->close(); + } + conn.commit(); + + table->setCondition(NULL); + rv = conn.startTransaction(); + table->execute(); + while ((tuple = (char*) table->fetch())) { + printf("after delete tuple present. Its value is %d %s \n", id, name); + return 10; + } + table->close(); + conn.commit(); + + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + + conn.close(); + return 0; +} diff --git a/test/dbapi/DataType/longlongtest.c b/test/dbapi/DataType/longlongtest.c new file mode 100644 index 00000000..ef618e6f --- /dev/null +++ b/test/dbapi/DataType/longlongtest.c @@ -0,0 +1,127 @@ +#include + +long long id = 0; +char name[196] = "PRABAKARAN"; +int select(Table *table, ComparisionOp op) +{ + printf("Operator test for %d\n", op); + Condition p1; + long long val1 = 3; + p1.setTerm("f1", op, &val1); + table->setCondition(&p1); + table->execute(); + void *tuple; + while ((tuple = (char*) table->fetch())) { + printf("tuple value is %lld %s \n", id, name); + } + table->close(); + return 0; +} + +int main() +{ + + Connection conn; + DbRetVal rv = conn.open("praba", "manager"); + if (rv != OK) + { + printf("Error during connection %d\n", rv); + return 1; + } + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + TableDef tabDef; + tabDef.addField("f1", typeLongLong, 0, NULL, true, true ); + tabDef.addField("f2", typeString, 196); + rv = dbMgr->createTable("t1", tabDef); + if (rv != OK) { printf("Table creation failed\n"); return 3; } + printf("Table created\n"); + Table *table = dbMgr->openTable("t1"); + if (table == NULL) { printf("Unable to open table\n"); return 4; } + table->bindFld("f1", &id); + table->bindFld("f2", name); + char *tuple; + int ret; + long long i; + rv =conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit(5); + id= i; + strcpy(name, "PRABAKARAN0123456750590"); + ret = table->insertTuple(); + if (ret != 0) break; + } + conn.commit(); + + conn.startTransaction(); + select(table, OpEquals); + conn.commit(); + + conn.startTransaction(); + select(table, OpNotEquals); + conn.commit(); + + conn.startTransaction(); + select(table, OpLessThan); + conn.commit(); + + conn.startTransaction(); + select( table, OpLessThanEquals); + conn.commit(); + + conn.startTransaction(); + select( table, OpGreaterThan); + conn.commit(); + + conn.startTransaction(); + select( table, OpGreaterThanEquals); + conn.commit(); + + Condition p1; + long long val1 = 0; + p1.setTerm("f1", OpEquals, &val1); + table->setCondition(&p1); + rv = conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit (1); + val1 = i; + table->execute(); + tuple = (char*)table->fetch() ; + if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;} + strcpy(name, "PRABAKARAN0950576543210"); + table->updateTuple(); + table->close(); + } + conn.commit(); + rv = conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit (1); + val1 = i; + table->execute(); + tuple = (char*)table->fetch() ; + if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;} + printf("deleting tuple %lld %s \n", id, name); + table->deleteTuple(); + table->close(); + } + conn.commit(); + + table->setCondition(NULL); + rv = conn.startTransaction(); + table->execute(); + while ((tuple = (char*) table->fetch())) { + printf("after delete tuple present. Its value is %lld %s \n", id, name); + return 10; + } + table->close(); + conn.commit(); + + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + + conn.close(); + return 0; +} diff --git a/test/dbapi/DataType/longtest.c b/test/dbapi/DataType/longtest.c new file mode 100644 index 00000000..97273d20 --- /dev/null +++ b/test/dbapi/DataType/longtest.c @@ -0,0 +1,127 @@ +#include + +long id = 0; +char name[196] = "PRABAKARAN"; +int select(Table *table, ComparisionOp op) +{ + printf("Operator test for %d\n", op); + Condition p1; + long val1 = 3; + p1.setTerm("f1", op, &val1); + table->setCondition(&p1); + table->execute(); + void *tuple; + while ((tuple = (char*) table->fetch())) { + printf("tuple value is %ld %s \n", id, name); + } + table->close(); + return 0; +} + +int main() +{ + + Connection conn; + DbRetVal rv = conn.open("praba", "manager"); + if (rv != OK) + { + printf("Error during connection %d\n", rv); + return 1; + } + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + TableDef tabDef; + tabDef.addField("f1", typeLong, 0, NULL, true, true ); + tabDef.addField("f2", typeString, 196); + rv = dbMgr->createTable("t1", tabDef); + if (rv != OK) { printf("Table creation failed\n"); return 3; } + printf("Table created\n"); + Table *table = dbMgr->openTable("t1"); + if (table == NULL) { printf("Unable to open table\n"); return 4; } + table->bindFld("f1", &id); + table->bindFld("f2", name); + char *tuple; + int ret; + long i; + rv =conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit(5); + id= i; + strcpy(name, "PRABAKARAN0123456750590"); + ret = table->insertTuple(); + if (ret != 0) break; + } + conn.commit(); + + conn.startTransaction(); + select(table, OpEquals); + conn.commit(); + + conn.startTransaction(); + select(table, OpNotEquals); + conn.commit(); + + conn.startTransaction(); + select(table, OpLessThan); + conn.commit(); + + conn.startTransaction(); + select( table, OpLessThanEquals); + conn.commit(); + + conn.startTransaction(); + select( table, OpGreaterThan); + conn.commit(); + + conn.startTransaction(); + select( table, OpGreaterThanEquals); + conn.commit(); + + Condition p1; + long val1 = 0; + p1.setTerm("f1", OpEquals, &val1); + table->setCondition(&p1); + rv = conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit (1); + val1 = i; + table->execute(); + tuple = (char*)table->fetch() ; + if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;} + strcpy(name, "PRABAKARAN0950576543210"); + table->updateTuple(); + table->close(); + } + conn.commit(); + rv = conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit (1); + val1 = i; + table->execute(); + tuple = (char*)table->fetch() ; + if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;} + printf("deleting tuple %ld %s \n", id, name); + table->deleteTuple(); + table->close(); + } + conn.commit(); + + table->setCondition(NULL); + rv = conn.startTransaction(); + table->execute(); + while ((tuple = (char*) table->fetch())) { + printf("after delete tuple present. Its value is %ld %s \n", id, name); + return 10; + } + table->close(); + conn.commit(); + + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + + conn.close(); + return 0; +} diff --git a/test/dbapi/DataType/shorttest.c b/test/dbapi/DataType/shorttest.c new file mode 100644 index 00000000..8f0716d8 --- /dev/null +++ b/test/dbapi/DataType/shorttest.c @@ -0,0 +1,127 @@ +#include + +short id = 0; +char name[196] = "PRABAKARAN"; +int select(Table *table, ComparisionOp op) +{ + printf("Operator test for %d\n", op); + Condition p1; + short val1 = 3; + p1.setTerm("f1", op, &val1); + table->setCondition(&p1); + table->execute(); + void *tuple; + while ((tuple = (char*) table->fetch())) { + printf("tuple value is %h %s \n", id, name); + } + table->close(); + return 0; +} + +int main() +{ + + Connection conn; + DbRetVal rv = conn.open("praba", "manager"); + if (rv != OK) + { + printf("Error during connection %d\n", rv); + return 1; + } + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + TableDef tabDef; + tabDef.addField("f1", typeShort, 0, NULL, true, true ); + tabDef.addField("f2", typeString, 196); + rv = dbMgr->createTable("t1", tabDef); + if (rv != OK) { printf("Table creation failed\n"); return 3; } + printf("Table created\n"); + Table *table = dbMgr->openTable("t1"); + if (table == NULL) { printf("Unable to open table\n"); return 4; } + table->bindFld("f1", &id); + table->bindFld("f2", name); + char *tuple; + int ret; + short i; + rv =conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit(5); + id= i; + strcpy(name, "PRABAKARAN0123456750590"); + ret = table->insertTuple(); + if (ret != 0) break; + } + conn.commit(); + + conn.startTransaction(); + select(table, OpEquals); + conn.commit(); + + conn.startTransaction(); + select(table, OpNotEquals); + conn.commit(); + + conn.startTransaction(); + select(table, OpLessThan); + conn.commit(); + + conn.startTransaction(); + select( table, OpLessThanEquals); + conn.commit(); + + conn.startTransaction(); + select( table, OpGreaterThan); + conn.commit(); + + conn.startTransaction(); + select( table, OpGreaterThanEquals); + conn.commit(); + + Condition p1; + short val1 = 0; + p1.setTerm("f1", OpEquals, &val1); + table->setCondition(&p1); + rv = conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit (1); + val1 = i; + table->execute(); + tuple = (char*)table->fetch() ; + if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;} + strcpy(name, "PRABAKARAN0950576543210"); + table->updateTuple(); + table->close(); + } + conn.commit(); + rv = conn.startTransaction(); + for(i = 0; i< 5; i++) + { + if (rv != OK) exit (1); + val1 = i; + table->execute(); + tuple = (char*)table->fetch() ; + if (tuple == NULL) {printf("loop break in %d\n", i);table->close();break;} + printf("deleting tuple %h %s \n", id, name); + table->deleteTuple(); + table->close(); + } + conn.commit(); + + table->setCondition(NULL); + rv = conn.startTransaction(); + table->execute(); + while ((tuple = (char*) table->fetch())) { + printf("after delete tuple present. Its value is %h %s \n", id, name); + return 10; + } + table->close(); + conn.commit(); + + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + + conn.close(); + return 0; +} -- 2.11.4.GIT