From c91d7bf262ef298aacd912bf1bafc417d59ea6b3 Mon Sep 17 00:00:00 2001 From: niharlcp1 Date: Fri, 12 Dec 2008 07:55:00 +0000 Subject: [PATCH] Testing NOT NULL in DBAPI --- test/dbapi/Table/Makefile | 15 ++- test/dbapi/Table/exp.test024 | 10 ++ test/dbapi/Table/exp.test026 | 17 +++ test/dbapi/Table/exp.test027 | 28 +++++ test/dbapi/Table/insertnulltest2.c | 6 +- test/dbapi/Table/insertnulltest3.c | 4 +- .../Table/{insertnulltest2.c => insertnulltest5.c} | 10 +- .../Table/{insertnulltest3.c => insertnulltest6.c} | 32 +++-- .../Table/{insertnulltest3.c => insertnulltest7.c} | 16 +-- test/dbapi/Table/insertnulltest8.c | 138 +++++++++++++++++++++ 10 files changed, 237 insertions(+), 39 deletions(-) create mode 100644 test/dbapi/Table/exp.test024 create mode 100644 test/dbapi/Table/exp.test026 create mode 100644 test/dbapi/Table/exp.test027 copy test/dbapi/Table/{insertnulltest2.c => insertnulltest5.c} (86%) copy test/dbapi/Table/{insertnulltest3.c => insertnulltest6.c} (70%) copy test/dbapi/Table/{insertnulltest3.c => insertnulltest7.c} (79%) create mode 100644 test/dbapi/Table/insertnulltest8.c diff --git a/test/dbapi/Table/Makefile b/test/dbapi/Table/Makefile index c134d88b..e808f8e2 100644 --- a/test/dbapi/Table/Makefile +++ b/test/dbapi/Table/Makefile @@ -34,8 +34,11 @@ TARGETS = \ test020 \ test021 \ test022 \ - test023 - + test023 \ + test024 \ + test025 \ + test026 \ + test027 ifeq ($(PlatForm), supported) @@ -67,6 +70,14 @@ test022:bindtest3.c $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) test023 :spaceusedtest.c $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test024 :insertnulltest5.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test025 :insertnulltest6.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test026 :insertnulltest7.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) +test027 :insertnulltest8.c + $(CPlus) $(CPlusFlags) -o $@ $< $(INCL) $(LIBS) $(SYSLIBS) clean: rm -f $(TARGETS) diff --git a/test/dbapi/Table/exp.test024 b/test/dbapi/Table/exp.test024 new file mode 100644 index 00000000..f046c484 --- /dev/null +++ b/test/dbapi/Table/exp.test024 @@ -0,0 +1,10 @@ +Table created +Tuples inserted in 1/txn is 5 +Column 3 is null +Binded Tuple value is 0 5 PRAVEEN +Binded Tuple value is 1 5 PRAVEEN +Column 3 is null +Binded Tuple value is 2 5 PRAVEEN +Binded Tuple value is 3 5 PRAVEEN +Column 3 is null +Binded Tuple value is 4 5 PRAVEEN diff --git a/test/dbapi/Table/exp.test026 b/test/dbapi/Table/exp.test026 new file mode 100644 index 00000000..536cbc8f --- /dev/null +++ b/test/dbapi/Table/exp.test026 @@ -0,0 +1,17 @@ +Table created +Tuples inserted in 1/txn is 10 +Column 2 is null +Binded Tuple value is 0 5 +Binded Tuple value is 1 6 +Column 2 is null +Binded Tuple value is 2 8 +Binded Tuple value is 3 11 +Column 2 is null +Binded Tuple value is 4 15 +Binded Tuple value is 5 20 +Column 2 is null +Binded Tuple value is 6 26 +Binded Tuple value is 7 33 +Column 2 is null +Binded Tuple value is 8 41 +Binded Tuple value is 9 50 diff --git a/test/dbapi/Table/exp.test027 b/test/dbapi/Table/exp.test027 new file mode 100644 index 00000000..b33841dd --- /dev/null +++ b/test/dbapi/Table/exp.test027 @@ -0,0 +1,28 @@ +Table created +Tuples inserted in 1/txn is 6 +Binded Tuple value is 0 5 10 +Column 3 is null +Binded Tuple value is 1 5 10 +Column 2 is null +Binded Tuple value is 2 5 10 +Column 3 is null +Binded Tuple value is 3 5 10 +Column 2 is null +Binded Tuple value is 4 5 10 +Column 3 is null +Binded Tuple value is 5 5 10 +Scan after updation +******************** +f1 | f2 | f3 +-------------------------- +0 | 5 | 10 +Column 3 is null +1 | 5 | 10 +Column 2 is null +2 | 5 | 10 +Column 3 is null +3 | 5 | 10 +Column 2 is null +4 | 5 | 10 +Column 3 is null +5 | 5 | 10 diff --git a/test/dbapi/Table/insertnulltest2.c b/test/dbapi/Table/insertnulltest2.c index 043656b3..45af2b98 100644 --- a/test/dbapi/Table/insertnulltest2.c +++ b/test/dbapi/Table/insertnulltest2.c @@ -8,9 +8,9 @@ int main() if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} TableDef tabDef; - tabDef.addField("f1", typeInt, 0, NULL, true); - tabDef.addField("f2", typeInt, 0, NULL, false); //NOT NULL - tabDef.addField("f3", typeString, 20); + tabDef.addField("f1", typeInt, 0, NULL, true);//NOT NULL + tabDef.addField("f2", typeInt, 0, NULL, false); + tabDef.addField("f3", typeString, 20);//Bydefault 'NOT NULL' is false rv = dbMgr->createTable("t1", tabDef); if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; } printf("Table created\n"); diff --git a/test/dbapi/Table/insertnulltest3.c b/test/dbapi/Table/insertnulltest3.c index c7fb3bd3..39a7f2d0 100644 --- a/test/dbapi/Table/insertnulltest3.c +++ b/test/dbapi/Table/insertnulltest3.c @@ -8,8 +8,8 @@ int main() if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} TableDef tabDef; - tabDef.addField("f1", typeInt, 0, NULL, true); - tabDef.addField("f2", typeInt, 0, NULL, false); //NOT NULL + tabDef.addField("f1", typeInt, 0, NULL, true);//NOT NULL + tabDef.addField("f2", typeInt, 0, NULL, false); tabDef.addField("f3", typeString, 20); rv = dbMgr->createTable("t1", tabDef); if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; } diff --git a/test/dbapi/Table/insertnulltest2.c b/test/dbapi/Table/insertnulltest5.c similarity index 86% copy from test/dbapi/Table/insertnulltest2.c copy to test/dbapi/Table/insertnulltest5.c index 043656b3..84bd9872 100644 --- a/test/dbapi/Table/insertnulltest2.c +++ b/test/dbapi/Table/insertnulltest5.c @@ -8,9 +8,9 @@ int main() if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} TableDef tabDef; - tabDef.addField("f1", typeInt, 0, NULL, true); - tabDef.addField("f2", typeInt, 0, NULL, false); //NOT NULL - tabDef.addField("f3", typeString, 20); + tabDef.addField("f1", typeInt, 0, NULL, true);//NOT NULL + tabDef.addField("f2", typeInt, 0, NULL, false); + tabDef.addField("f3", typeString, 20);//Bydefault 'NOT NULL' is false rv = dbMgr->createTable("t1", tabDef); if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; } printf("Table created\n"); @@ -33,10 +33,10 @@ int main() { conn.startTransaction(); id1= i; - if (i%2 == 0) table->markFldNull(3); + if (i%2 == 0) table->markFldNull("f3"); rv = table->insertTuple(); if (rv != OK) break; - if (i%2 == 0) table->clearFldNull(3); + if (i%2 == 0) table->clearFldNull("f3"); icount++; conn.commit(); diff --git a/test/dbapi/Table/insertnulltest3.c b/test/dbapi/Table/insertnulltest6.c similarity index 70% copy from test/dbapi/Table/insertnulltest3.c copy to test/dbapi/Table/insertnulltest6.c index c7fb3bd3..ea7533f9 100644 --- a/test/dbapi/Table/insertnulltest3.c +++ b/test/dbapi/Table/insertnulltest6.c @@ -8,9 +8,8 @@ int main() if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} TableDef tabDef; - tabDef.addField("f1", typeInt, 0, NULL, true); - tabDef.addField("f2", typeInt, 0, NULL, false); //NOT NULL - tabDef.addField("f3", typeString, 20); + tabDef.addField("f1", typeInt, 0, NULL, true);//NOT NULL + tabDef.addField("f2", typeInt, 0, NULL, false); rv = dbMgr->createTable("t1", tabDef); if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; } printf("Table created\n"); @@ -23,23 +22,22 @@ int main() conn.close(); return -1; } - int id1 = 0, id2 = 5; - char name[20] = "unchangedvalue"; + int id1=0, id2 = 5; table->bindFld("f1", &id1); table->bindFld("f2", &id2); - //table->bindFld("f3", name); - int icount =0; - for (int i = 0 ; i < 5 ; i++) - { conn.startTransaction(); - id1= i; + table->markFldNull(1); rv = table->insertTuple(); - if (rv != OK) break; - icount++; + if(rv==OK) + { + printf("Error\n"); + dbMgr->dropTable("t1"); + conn.close(); + return -1; + } + table->clearFldNull(1); conn.commit(); - - } - printf("Tuples inserted in 1/txn is %d\n", icount); + table->setCondition(NULL); rv = table->execute(); if (rv != OK) @@ -56,8 +54,8 @@ int main() if (tuple == NULL) {break;} if (table->isFldNull(1)) printf("Column 1 is null\n"); if (table->isFldNull(2)) printf("Column 2 is null\n"); - if (table->isFldNull(3)) printf("Column 3 is null\n"); - printf("Binded Tuple value is %d %d %s \n", id1, id2, name); + printf("Binded Tuple value is %d %d \n", id1, id2); + } table->close(); dbMgr->closeTable(table); diff --git a/test/dbapi/Table/insertnulltest3.c b/test/dbapi/Table/insertnulltest7.c similarity index 79% copy from test/dbapi/Table/insertnulltest3.c copy to test/dbapi/Table/insertnulltest7.c index c7fb3bd3..66109c99 100644 --- a/test/dbapi/Table/insertnulltest3.c +++ b/test/dbapi/Table/insertnulltest7.c @@ -9,8 +9,7 @@ int main() TableDef tabDef; tabDef.addField("f1", typeInt, 0, NULL, true); - tabDef.addField("f2", typeInt, 0, NULL, false); //NOT NULL - tabDef.addField("f3", typeString, 20); + tabDef.addField("f2", typeInt); rv = dbMgr->createTable("t1", tabDef); if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; } printf("Table created\n"); @@ -24,20 +23,19 @@ int main() return -1; } int id1 = 0, id2 = 5; - char name[20] = "unchangedvalue"; table->bindFld("f1", &id1); table->bindFld("f2", &id2); - //table->bindFld("f3", name); int icount =0; - for (int i = 0 ; i < 5 ; i++) + for (int i = 0 ; i < 10 ; i++) { conn.startTransaction(); - id1= i; + id1= i;id2=id2+i; + if (i%2 == 0){ table->markFldNull(1);table->markFldNull(2);} rv = table->insertTuple(); if (rv != OK) break; + if (i%2 == 0) {table->clearFldNull(1);table->clearFldNull(2);} icount++; conn.commit(); - } printf("Tuples inserted in 1/txn is %d\n", icount); table->setCondition(NULL); @@ -48,7 +46,6 @@ int main() dbMgr->dropTable("t1"); conn.close(); } - table->bindFld("f2", &id2); void *tuple = NULL; while(true) { @@ -56,8 +53,7 @@ int main() if (tuple == NULL) {break;} if (table->isFldNull(1)) printf("Column 1 is null\n"); if (table->isFldNull(2)) printf("Column 2 is null\n"); - if (table->isFldNull(3)) printf("Column 3 is null\n"); - printf("Binded Tuple value is %d %d %s \n", id1, id2, name); + printf("Binded Tuple value is %d %d \n", id1, id2); } table->close(); dbMgr->closeTable(table); diff --git a/test/dbapi/Table/insertnulltest8.c b/test/dbapi/Table/insertnulltest8.c new file mode 100644 index 00000000..12bfe4f7 --- /dev/null +++ b/test/dbapi/Table/insertnulltest8.c @@ -0,0 +1,138 @@ +#include +int main() +{ + Connection conn; + DbRetVal rv = conn.open("root", "manager"); + if (rv != OK) return 1; + DatabaseManager *dbMgr = conn.getDatabaseManager(); + if (dbMgr == NULL) { printf("Auth failed\n"); return 2;} + + TableDef tabDef; + tabDef.addField("f1", typeInt, 0, NULL, true);//NOT NULL + tabDef.addField("f2", typeInt, 0, NULL, false); + tabDef.addField("f3", typeInt, 0, NULL, false); + rv = dbMgr->createTable("t1", tabDef); + if (rv != OK) { printf("Table creation failed\n"); conn.close(); return 3; } + printf("Table created\n"); + + Table *table = dbMgr->openTable("t1"); + if (table == NULL) + { + printf("Unable to open table\n"); + dbMgr->dropTable("t1"); + conn.close(); + return -1; + } + int id1=0, id2 = 5, id3=10; + table->bindFld("f1", &id1); + table->bindFld("f2", &id2); + table->bindFld("f3", &id3); + int icount=0; + for(int i=0;i<6;i++) + { + conn.startTransaction(); + id1=i; + if(i%2==0) + { + if(i!=0) + table->markFldNull(2); + } + else table->markFldNull(3); + rv = table->insertTuple(); + if(rv!=OK) break; + if(i%2==0) table->clearFldNull(2); + else table->clearFldNull(3); + icount++; + conn.commit(); + } + printf("Tuples inserted in 1/txn is %d\n", icount); + table->setCondition(NULL); + rv = table->execute(); + if (rv != OK) + { + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + conn.close(); + } + void *tuple = NULL; + while(true) + { + tuple = (char*)table->fetch() ; + if (tuple == NULL) {break;} + if (table->isFldNull(1)) + { + printf("Column 1 is null\n"); + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + conn.close(); + return -1; + } + if (table->isFldNull(2)) printf("Column 2 is null\n"); + if (table->isFldNull(3)) printf("Column 3 is null\n"); + printf("Binded Tuple value is %d %d %d\n", id1, id2, id3); + } + rv=table->close(); + + Condition p1; + int val1=4; + p1.setTerm("f1", OpLessThan, &val1); + table->setCondition(&p1); + conn.startTransaction(); + rv=table->execute(); + if (rv != OK) + { + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + conn.close(); + return 5; + } + + while(true) + { + tuple = (char*)table->fetch(); + + if (tuple == NULL) { break; } + table->markFldNull("f1"); + rv=table->updateTuple(); + table->clearFldNull("f1"); + } + conn.commit(); + table->close(); + + conn.startTransaction(); + table->setCondition(NULL); + rv = table->execute(); + if (rv != OK) + { + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + conn.close(); + return 4; + } + printf("Scan after updation\n"); + printf("********************\n"); + printf("f1 | f2\t| f3\n"); + printf("--------------------------\n"); + + while(true) + { + tuple = (char*)table->fetch() ; + if (tuple == NULL) {break;} + if (table->isFldNull(1)) + { + printf("Column 1 is null\n"); + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + conn.close(); + return -1; + } + if (table->isFldNull(2)) printf("Column 2 is null\n"); + if (table->isFldNull(3)) printf("Column 3 is null\n"); + printf("%d | %d\t| %d\n", id1, id2, id3); + } + table->close(); + dbMgr->closeTable(table); + dbMgr->dropTable("t1"); + conn.close(); + return 0; +} -- 2.11.4.GIT