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); tabDef.addField("f2",typeInt); rv = dbMgr->createTable("t1",tabDef); if(rv!=OK) { printf("Table created failed\n"); conn.close(); return 0; } Table *table = dbMgr->openTable("t1"); long spaceused; spaceused = table->spaceUsed(); printf("Total space used=%ld\n",spaceused); dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 0; }
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;} if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; } int inscount = insertTuple(dbMgr, conn); //check the inscount and return error Table *table = dbMgr->openTable("t1"); if (table == NULL) { printf("Unable to open table\n"); return 0; } Condition p1,p2,p3,p4,p5; int val1 = 2, val2 = 3, val3 = 4; p1.setTerm("f1", OpEquals, &val3); p2.setTerm("f2", OpGreaterThan, &val2); p3.setTerm("f2", OpEquals, &val3); p4.setTerm("f1", OpLessThan, &val1); p5.setTerm("f1", OpGreaterThan, &val1); Condition cond1, cond1a; cond1.setTerm(p1.getPredicate(), OpAnd, p2.getPredicate()); cond1a.setTerm(cond1.getPredicate(), OpOr, p4.getPredicate()); table->setCondition(&cond1a); printf("Predicate: (f1 ==4 AND f2 >3) OR (f1< 2) \n"); conn.startTransaction(); execAndPrint(table); conn.commit(); Condition cond2, cond2a; cond2.setTerm(p4.getPredicate(), OpAnd, p2.getPredicate()); cond2a.setTerm(cond1.getPredicate(), OpOr, cond2.getPredicate()); table->setCondition(&cond2a); printf("Predicate: (f1 ==4 AND f2 >3) OR (f1< 2 AND f2 > 4) \n"); conn.startTransaction(); execAndPrint(table); conn.commit(); dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 0; }
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); tabDef.addField("f2", typeInt); tabDef.addField("f3", typeString, 1016); 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; char name[20] = "PRAVEEN"; table->bindFld("f1", &id1); table->bindFld("f2", &id2); table->bindFld("f3", name); int icount =0; for (int i = 0 ; i < 1000 ; i++) { conn.startTransaction(); for (int j = 0 ; j < 100 ; j++) { id1= icount++; rv = table->insertTuple(); if (rv != OK) break; } conn.commit(); } printf("Tuples inserted %d\n", icount); dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); if (rv == ErrNoMemory) { //insert is expected to fail printf("insert failed with return values %d\n", rv); return 0; } return 1; }
//bind non exisiting field 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); tabDef.addField("f2", typeInt); tabDef.addField("f3", typeString, 20); 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; int ret =0; char name[20] = "PRAVEEN"; rv = table->bindFld("f1", &id1); if (rv != OK) ret = 1; rv = table->bindFld("f5", &id2); if (rv == OK) ret = 1; dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return ret; }
int main() { Connection conn; DbRetVal rv = conn.open("root", "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 -1;} TableDef tabDef; tabDef.addField("f1", typeInt, 0, NULL, true, true); tabDef.addField("f2", typeString, 12); rv = dbMgr->createTable("t1", tabDef); if (rv != OK) { printf("Table creation failed\n"); return -1; } HashIndexInitInfo *idxInfo = new HashIndexInitInfo(); strcpy(idxInfo->tableName, "t1"); idxInfo->list.append("f1"); idxInfo->isPrimary = true; idxInfo->isUnique = true; #ifdef HASH idxInfo->indType = hashIndex; rv = dbMgr->createIndex("indx1", idxInfo); if (rv != OK) { printf("Index creation failed\n"); return -1; } #endif #ifdef TREE idxInfo->indType = treeIndex; rv = dbMgr->createIndex("indx1", idxInfo); if (rv != OK) { printf("Index creation failed\n"); return -1; } #endif delete idxInfo; pthread_t thr[THREADS]; int message[THREADS]; int status; for (int i=0; i <THREADS; i++) { message[i] = i; pthread_create (&thr[i], NULL, &runInsTest, (void *) &message[i]); } for (int i=0; i <THREADS; i++) { pthread_join(thr[i], (void**)&status); } Table *table = dbMgr->openTable("t1"); if (table == NULL) { printf("Unable to open table\n"); return -1; } table->setCondition(NULL); rv = conn.startTransaction(); if (rv != OK) while (rv !=OK) rv = conn.startTransaction(); table->execute(); int count=0; void *tuple = NULL; while ((tuple = (char*) table->fetch())) { count++; } printf("Tuples found: %d\n", count); table->closeScan(); conn.commit(); #ifdef HASH Condition p1; int valTerm = 0; p1.setTerm("f1", OpEquals, &valTerm); table->setCondition(&p1); int icount=0; for(int i = 0; i< THREADS * ITERATION; i++) { rv = conn.startTransaction(); if (rv != OK) while (rv !=OK) rv = conn.startTransaction(); valTerm = i+1; rv = table->execute(); tuple = (char*)table->fetch() ; if (tuple == NULL) break; icount++; table->closeScan(); conn.commit(); //if (i%ITERATION == 0) printf("%d\n", i); } printf("Index Tuples found: %d\n", icount); #endif dbMgr->closeTable(table); for (int i=0; i <THREADS; i++) { message[i] = i; pthread_create (&thr[i], NULL, &runSelTest, (void *) &message[i]); } for (int i=0; i <THREADS; i++) { pthread_join(thr[i], (void**)&status); } dbMgr->dropTable("t1"); conn.close(); return 0; }
void* runInsTest(void *message) { Connection conn; DbRetVal rv = conn.open("root", "manager"); if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; } DatabaseManager *dbMgr = conn.getDatabaseManager(); if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;} Table *table = dbMgr->openTable("t1"); if (table == NULL) { printf("Unable to open table\n"); return NULL; } int id = 0; char name[20] = "PRABAKARAN"; //table->bindFld("f1", &id); table->bindFld("f2", name); char *tuple; int ret; int i; int icount =0; int val = *(int*)message; int retrycnt=0; for(i = val * ITERATION; i< (val *ITERATION) +ITERATION; i++) { rv = conn.startTransaction(); if (rv != OK) while (rv !=OK) rv = conn.startTransaction(); id= i; strcpy(name, "KARAN123"); ret = table->insertTuple(); retrycnt=0; while (ret == ErrLockTimeOut) { rv = conn.rollback(); if (rv != OK) { while (rv == ErrLockTimeOut) { printf("retrying abort\n"); rv = conn.rollback(); } } if (retrycnt == 3) { ret = 1; break;} rv = conn.startTransaction(); if (rv != OK) { while (rv == ErrLockTimeOut) { printf("retrying startTransaction\n"); rv = conn.startTransaction(); } } ret = table->insertTuple(); retrycnt++; //ret =1; break; //temp to analyse issue } if (ret != 0) { printf("RETURNING EARLY: %d with i:%d\n", ret, i); break;} icount++; rv = conn.commit(); if (rv != OK) { printf("COMMIT returned %d\n", rv); os::usleep(500); while (rv == ErrLockTimeOut) { printf("retrying commit\n"); rv = conn.commit(); } } //if (icount %ITERATION ==0) printf("%d\n", i); } char msgBuf[1024]; sprintf(msgBuf,"Insert: Thread %lu %d: Total rows :%d\n",os::getthrid(), val, icount); os::write(1,msgBuf,strlen(msgBuf)); dbMgr->closeTable(table); rv = conn.close(); return NULL; }
int main() { Connection conn; DbRetVal rv = conn.open("root", "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); tabDef.addField("f2", typeString, 196); rv = dbMgr->createTable("t1", tabDef); if (rv != OK) { printf("Table creation failed\n"); return 3; } printf("Table created\n"); #ifdef WITHINDEX HashIndexInitInfo *idxInfo = new HashIndexInitInfo(); strcpy(idxInfo->tableName, "t1"); idxInfo->list.append("f1"); idxInfo->indType = hashIndex; idxInfo->isUnique = true; idxInfo->isPrimary = true; rv = dbMgr->createIndex("indx1", idxInfo); if (rv != OK) { printf("Index creation failed\n"); return -1; } printf("Index created\n"); delete idxInfo; #endif #ifdef WITHTREEINDEX HashIndexInitInfo *idxInfo = new HashIndexInitInfo(); strcpy(idxInfo->tableName, "t1"); idxInfo->list.append("f1"); idxInfo->indType = treeIndex; rv = dbMgr->createIndex("indx1", idxInfo); if (rv != OK) { printf("Index creation failed\n"); return -1; } printf("Index created\n"); delete idxInfo; #endif #ifdef WITHTRIEINDEX HashIndexInitInfo *idxInfo = new HashIndexInitInfo(); strcpy(idxInfo->tableName, "t1"); idxInfo->list.append("f1"); idxInfo->indType = trieIndex; rv = dbMgr->createIndex("indx1", idxInfo); if (rv != OK) { printf("Index creation failed\n"); return -1; } printf("Index created\n"); delete idxInfo; #endif 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(); dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 0; }
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); tabDef.addField("f2", typeInt); tabDef.addField("f3", typeString, 2000); 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; char name[20] = "PRAVEEN"; table->bindFld("f1", &id1); table->bindFld("f2", &id2); table->bindFld("f3", name); int i=0; for (i = 0 ; i < 4000; i++) { conn.startTransaction(); id1= i; rv = table->insertTuple(); if (rv != OK) break; conn.commit(); } printf("%d records inserted\n", i); for (int k=0; k <100; k++) { table->setCondition(NULL); rv = table->execute(); if (rv != OK) { printf("table execute failed rv:%d\n", rv); dbMgr->closeTable(table); conn.close(); return 1; } void *tuple = NULL; for (i = 0 ; i < 1000 ; i++) { conn.startTransaction(); tuple = table->fetchNoBind(); if (tuple == NULL) { printf("No more records\n"); break; } rv = table->deleteTuple(); if (rv != OK) { printf("Delete tuple failed\n"); break;} conn.commit(); } table->closeScan(); printf("Iteration:%d \n %d records deleted\n", k, i); i=0; for (i = 0 ; i < 1000 ; i++) { conn.startTransaction(); id1= i; rv = table->insertTuple(); if (rv != OK) break; conn.commit(); } printf("%d records inserted\n", i); } dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 0; }
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;} if ( createTable(dbMgr) != 0 ) { conn.close(); return 3; } #ifdef WITHF1INDEX if (createIndex(dbMgr, "f1", "idx1") != 0) {dbMgr->dropTable("t1"); conn.close(); return 4; } #endif #ifdef WITHF1TREEINDEX if (createIndex(dbMgr, "f1", "idx1", true) != 0) {dbMgr->dropTable("t1"); conn.close(); return 4; } #endif #ifdef WITHF2INDEX if (createIndex(dbMgr, "f2", "idx2") != 0) {dbMgr->dropTable("t1"); conn.close(); return 4; } #endif #ifdef WITHF2TREEINDEX if (createIndex(dbMgr, "f2", "idx2", true) != 0) {dbMgr->dropTable("t1"); conn.close(); return 4; } #endif int inscount = insertTuple(dbMgr, conn); //check the inscount and return error Table *table = dbMgr->openTable("t1"); if (table == NULL) { printf("Unable to open table\n"); return 0; } Condition p1,p2,p3,p4,p5; int val1 = 2, val2 = 3, val3 = 4; p1.setTerm("f1", OpEquals, &val3); p2.setTerm("f2", OpGreaterThan, &val2); p3.setTerm("f2", OpEquals, &val3); p4.setTerm("f1", OpLessThan, &val3); p5.setTerm("f1", OpGreaterThan, &val1); Condition cond1, cond1a; cond1.setTerm(p1.getPredicate(), OpAnd, p2.getPredicate()); cond1a.setTerm(cond1.getPredicate(), OpNot); table->setCondition(&cond1a); printf("Predicate: NOT(f1 ==4 AND f2 >3) \n"); conn.startTransaction(); execAndPrint(table); conn.commit(); Condition cond2, cond2a; cond2.setTerm(p1.getPredicate(), OpAnd, p3.getPredicate()); cond2a.setTerm(cond2.getPredicate(), OpNot); table->setCondition(&cond2a); printf("Predicate: NOT( f1 ==4 AND f2 ==4) \n"); conn.startTransaction(); execAndPrint(table); conn.commit(); Condition cond3, cond3a; cond3.setTerm(p4.getPredicate(), OpAnd, p5.getPredicate()); cond3a.setTerm(cond3.getPredicate(), OpNot); table->setCondition(&cond3a); printf("Predicate: NOT( f1 <4 AND f1 >2) \n"); conn.startTransaction(); execAndPrint(table); conn.commit(); Condition cond4, cond4a; cond4.setTerm(p4.getPredicate(), OpAnd, p2.getPredicate()); cond4a.setTerm(cond4.getPredicate(), OpNot); table->setCondition(&cond4a); printf("Predicate: NOT( f1 <4 AND f2 >3) \n"); conn.startTransaction(); execAndPrint(table); conn.commit(); Condition cond5, cond5a; cond5.setTerm(p2.getPredicate(), OpNot); cond5a.setTerm(p4.getPredicate(), OpAnd, cond5.getPredicate()); table->setCondition(&cond5a); printf("Predicate: ( f1 <4 AND (NOT(f2 >3)) \n"); conn.startTransaction(); execAndPrint(table); conn.commit(); dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 0; }
int main() { Connection conn; DbRetVal rv = conn.open("root", "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 -1;} TableDef tabDef; tabDef.addField("f1", typeInt, 0, NULL, true); tabDef.addField("f2", typeString, 50); rv = dbMgr->createTable("t1", tabDef); if (rv != OK) { printf("Table creation failed\n"); return -1; } printf("Table created\n"); HashIndexInitInfo *idxInfo = new HashIndexInitInfo(); strcpy(idxInfo->tableName, "t1"); idxInfo->list.append("f1"); idxInfo->indType = hashIndex; #ifdef F1TREE idxInfo->indType = treeIndex; #endif #ifdef F2TRIE idxInfo->indType = trieIndex; #endif rv = dbMgr->createIndex("indx1", idxInfo); if (rv != OK) { printf("Index creation failed\n"); return -1; } printf("Index created for f1\n"); printf("size of index field list %d\n", idxInfo->list.size()); idxInfo->list.remove("f1"); printf("size of index field list %d\n", idxInfo->list.size()); idxInfo->list.append("f2"); printf("size of index field list %d\n", idxInfo->list.size()); idxInfo->indType = hashIndex; #ifdef F2TREE idxInfo->indType = treeIndex; #endif #ifdef F2TRIE idxInfo->indType = trieIndex; #endif rv = dbMgr->createIndex("indx2", idxInfo); if (rv != OK) { printf("Index creation failed\n"); return -1; } printf("Index created for f2\n"); delete idxInfo; Table *table = dbMgr->openTable("t1"); if (table == NULL) { printf("Unable to open table\n"); return -1; } int id1 = 0; char id2[50] ="Aruna"; table->bindFld("f1", &id1); table->bindFld("f2", id2); char *tuple; int ret; int i; int icount =0; rv = conn.startTransaction(); if (rv != OK) exit(1); for(i = 0; i< 10; i++) { id1= i; sprintf(id2, "Aruna:%d", i); ret = table->insertTuple(); if (ret != 0) break; icount++; } conn.commit(); printf("Total tuples inserted: %d\n", icount); Condition p1, p2; int val1 = 0; char val2[50]; p1.setTerm("f1", OpEquals, &val1); p2.setTerm("f2", OpEquals, &val2); table->setCondition(&p1); rv =conn.startTransaction(); if (rv != OK) exit(1); for(i = 0; i< 10; i++) { val1 = i; table->execute(); tuple = (char*)table->fetch() ; if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;} printf("I:tuple value is %d %s \n", id1, id2); table->closeScan(); } table->setCondition(&p2); for(i = 0; i< 10; i++) { sprintf(val2, "Aruna:%d", i); table->execute(); tuple = (char*)table->fetch() ; if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;} printf("II:tuple value is %d %s \n", id1, id2); table->closeScan(); } conn.commit(); rv =conn.startTransaction(); if (rv != OK) exit(1); table->setCondition(&p1); val1 = 1; table->execute(); tuple = (char*)table->fetch() ; if (tuple != NULL) { table->deleteTuple(); } table->closeScan(); table->setCondition(&p2); sprintf(val2, "Aruna:%d", 2); table->execute(); tuple = (char*)table->fetch() ; if (tuple != NULL) { table->deleteTuple(); } table->closeScan(); conn.commit(); int count =0; rv = conn.startTransaction(); table->setCondition(NULL); if (rv != OK) exit (1); table->execute(); while((tuple = (char*)table->fetch())!= NULL) { printf("tuple value is %d %s \n", id1, id2); count++; } table->closeScan(); conn.commit(); printf("Total rows selected %d\n", count); dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 0; }
int main() { Connection conn; DbRetVal rv = conn.open("root", "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); 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; } int id = 0; char name[196] = "PRABAKARAN"; table->bindFld("f1", &id); table->bindFld("f2", name); int i; int icount =0; conn.startTransaction(); rv = table->insertTuple(); if (rv != OK) { printf("Insertion failed \n"); return 5; } conn.commit(); conn.startTransaction(); table->setCondition(NULL); rv = table->execute(); if (rv != OK) { dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 6; } void *fld2ptr, *tuple; while(true) { tuple = (char*)table->fetch() ; if (tuple == NULL) {break;} printf("Binded Tuple value is %d %s \n", id, name); } conn.commit(); table->closeScan(); dbMgr->closeTable(table); dbMgr->dropTable("t1"); printf("test passed successfully\n"); return 0; }
int main() { Connection conn; DbRetVal rv = conn.open("root", "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); 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 3; } int id; char name[200]="PRABA"; table->bindFld("f1", &id); table->bindFld("f2", name); int icount = 0; int i; conn.startTransaction(); for (i=0;i<10;i++) { id=i; rv=table->insertTuple(); if(rv!=OK) { printf("Insertion failed at %d th tuple",i); dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 4; } } conn.commit(); conn.startTransaction(); table->setCondition(NULL); rv = table->execute(); if (rv != OK) { dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 6; } printf("Scan before Deletion\n"); printf("********************\n"); void *fld2ptr, *tuple; while(true) { tuple = (char*)table->fetch() ; if (tuple == NULL) {break;} printf("Binded Tuple value is %d %s \n", id, name); } conn.commit(); rv=table->closeScan(); if(rv!=OK){ printf("Error in closing the table\n"); return 3;} Condition p1; int val1 = 5; p1.setTerm("f1",OpEquals, &val1); table->setCondition(&p1); conn.startTransaction(); rv=table->execute(); if (rv != OK) { dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 4; } // char *tuple; //printf("Scan After:\n"); while(true) { tuple = (char*)table->fetch() ; if (tuple == NULL) { break; } //strcpy(name,"Kanchana"); table->deleteTuple(); } conn.commit(); table->closeScan(); conn.startTransaction(); table->setCondition(NULL); rv = table->execute(); if (rv != OK) { dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 6; } printf("Scan After Deletion\n"); printf("********************\n"); while(true) { tuple = (char*)table->fetch() ; if (tuple == NULL) {break;} printf("Binded Tuple value is %d %s \n", id, name); } conn.commit(); //unset the condtion set as we need to delete all rows table->setCondition(NULL); table->closeScan(); dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); printf("Test script passed "); return 0; }
int main() { Connection conn; DbRetVal rv = conn.open("root", "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 -1;} TableDef tabDef; tabDef.addField("f1", typeInt, 0, NULL, true ); tabDef.addField("f2", typeString, 196); rv = dbMgr->createTable("t1", tabDef); if (rv != OK) { printf("Table creation failed\n"); return -1; } printf("Table created\n"); HashIndexInitInfo *idxInfo = new HashIndexInitInfo(); strcpy(idxInfo->tableName, "t1"); idxInfo->list.append("f1"); idxInfo->indType = hashIndex; if (LOAD >0 ) idxInfo->bucketSize = 100007; else idxInfo->bucketSize = 10007; rv = dbMgr->createIndex("indx1", idxInfo); if (rv != OK) { printf("Index creation failed\n"); return -1; } printf("Index created\n"); delete idxInfo; Table *table = dbMgr->openTable("t1"); if (table == NULL) { printf("Unable to open table\n"); return -1; } int id = 0; char name[196] = "PRABAKARAN"; table->bindFld("f1", &id); table->bindFld("f2", name); char *tuple; int ret; int i; int icount =0; if (LOAD > 0) { TableImpl *impl = (TableImpl*)table; impl->setUndoLogging(false); strcpy(name, "PRABAKARAN0123456750590"); rv = conn.startTransaction(); if (rv != OK) exit(1); for(i = 0; i< LOAD; i++) { id= i; ret = table->insertTuple(); if (ret != 0) break; icount++; if (i % 100 == 0 ) { rv = conn.commit(); if (rv != OK) exit(1); rv = conn.startTransaction(); if (rv != OK) exit(1); } if (i %50000 == 0) printf("%d rows inserted\n", i); } conn.commit(); impl->setUndoLogging(true); printf("Loaded %d records\n", icount); } //TableImpl *impl = (TableImpl*)table; //impl->setUndoLogging(false); i = 0; NanoTimer timer; icount =0; for(i = LOAD; i< LOAD+ITERATIONS; i++) { timer.start(); rv = conn.startTransaction(); if (rv != OK) exit(1); id= i; strcpy(name, "PRABAKARAN0123456750590"); ret = table->insertTuple(); if (ret != 0) break; // printf("%d\n ", i); icount++; conn.commit(); timer.stop(); } printf("%d rows inserted %lld %lld %lld\n",icount, timer.minc(), timer.maxc(), timer.avg()); int offset1= os::align(sizeof(int)); Condition p1; int val1 = 0; p1.setTerm("f1", OpEquals, &val1); table->setCondition(&p1); icount=0; timer.reset(); for(i = LOAD; i< LOAD+ITERATIONS; i++) { timer.start(); rv =conn.startTransaction(); if (rv != OK) exit(1); val1 = i; table->execute(); tuple = (char*)table->fetch() ; if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;} // printf(" %d tuple value is %d %s \n", i, *((int*)tuple), tuple+offset1); table->closeScan(); icount++; conn.commit(); timer.stop(); } printf("%d rows selected %lld %lld %lld\n", icount, timer.minc(), timer.maxc(), timer.avg()); timer.reset(); for(i = LOAD; i< LOAD+ITERATIONS; i++) { timer.start(); rv = conn.startTransaction(); if (rv != OK) exit (1); val1 = i; table->execute(); tuple = (char*)table->fetch() ; if (tuple == NULL) {printf("loop break in %d\n", i);table->closeScan();break;} strcpy(name, "PRABAKARAN0950576543210"); table->updateTuple(); table->closeScan(); conn.commit(); timer.stop(); } printf("%d rows updated %lld %lld %lld\n", i- LOAD, timer.minc(), timer.maxc(), timer.avg()); icount=0; for(i = LOAD; i< LOAD+ITERATIONS; i++) { timer.start(); rv = conn.startTransaction(); if (rv != OK) exit (1); val1 = i; table->execute(); tuple = (char*)table->fetch() ; if (tuple == NULL) {printf("No record for %d\n", i);table->closeScan();break;} table->deleteTuple(); icount++; table->closeScan(); conn.commit(); timer.stop(); } printf("%d rows deleted %lld %lld %lld\n", icount, timer.minc(), timer.maxc(), timer.avg()); dbMgr->closeTable(table); dbMgr->dropTable("t1"); printf("Table dropped\n"); conn.close(); return 0; }
void* runSelTest(void *message) { Connection conn; DbRetVal rv = conn.open("root", "manager"); if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; } DatabaseManager *dbMgr = conn.getDatabaseManager(); if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;} Table *table = dbMgr->openTable("t1"); if (table == NULL) { printf("Unable to open table\n"); return NULL; } int id = 0; char name[1020] = "PRABAKARAN"; table->bindFld("f1", &id); table->bindFld("f2", name); char *tuple; int i; int icount =0; int val = *(int*)message; Condition p1; int valTerm = 0; p1.setTerm("f1", OpEquals, &valTerm); table->setCondition(&p1); for(i = val * ITERATION; i< (val *ITERATION) +ITERATION; i++) { rv = conn.startTransaction(); if (rv != OK) while (rv !=OK) rv = conn.startTransaction(); valTerm = i; if (valTerm ==0) valTerm=1; rv = table->execute(); if (rv != OK) { printf("Execute returned %d\n", rv); os::usleep(500); int retry=5; while (rv == ErrLockTimeOut) { if (retry == 0) break; printf("retrying execute\n"); rv = table->execute(); retry--; } } tuple = (char*)table->fetch() ; if (tuple == NULL) break; icount++; table->closeScan(); rv = conn.commit(); if (rv != OK) { while (rv == ErrLockTimeOut) { printf("retrying commit\n"); rv = conn.commit(); } } } char msgBuf[1024]; sprintf(msgBuf,"Select: Thread %lu %d: Total rows :%d\n",os::getthrid(), val, icount); os::write(1,msgBuf,strlen(msgBuf)); dbMgr->closeTable(table); rv = conn.close(); return NULL; }
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", 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"); 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; char name[20] = "PRAVEEN"; 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; if (i%2 == 0) table->markFldNull(3); rv = table->insertTuple(); if (rv != OK) break; if (i%2 == 0) 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(); } table->bindFld("f2", &id2); void *tuple = NULL; while(true) { tuple = (char*)table->fetch() ; 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); } table->closeScan(); dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 0; }
void* runDelTest(void *message) { Connection conn; DbRetVal rv = conn.open("root", "manager"); if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; } DatabaseManager *dbMgr = conn.getDatabaseManager(); if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;} Table *table = dbMgr->openTable("t1"); if (table == NULL) { printf("Unable to open table\n"); return NULL; } int id = 0; char name[20] = "PRABAKARAN"; table->bindFld("f1", &id); table->bindFld("f2", name); char *tuple; int i; int ret; int retrycnt=0; int icount =0; int val = *(int*)message; Condition p1; int valTerm = 0; p1.setTerm("f1", OpEquals, &valTerm); table->setCondition(&p1); for(i = val * ITERATION; i< (val *ITERATION) +ITERATION; i++) { rv = conn.startTransaction(); if (rv != OK) while (rv !=OK) rv = conn.startTransaction(); id= i; valTerm = i; rv = table->execute(); if (rv != OK) { printf("Execute returned %d\n", rv); os::usleep(500); int retry=5; while (rv == ErrLockTimeOut) { if (retry == 0) { printf("DELETE:execute failed\n"); break;} printf("retrying execute\n"); rv = table->execute(); retry--; } } tuple = (char*)table->fetch() ; if (tuple == NULL) { printf("DELETE:fetch failed\n");break;} ret = table->deleteTuple(); retrycnt=0; while (ret == ErrLockTimeOut) { table->closeScan(); rv = conn.rollback(); if (rv != OK) { while (rv == ErrLockTimeOut) { printf("retrying abort\n"); rv = conn.rollback(); } } if (retrycnt == 10) { ret = 1; break;} rv = conn.startTransaction(); if (rv != OK) { while (rv == ErrLockTimeOut) { printf("retrying startTransaction\n"); rv = conn.startTransaction(); } } rv = table->execute(); if (rv != OK) { printf("Execute returned %d\n", rv); os::usleep(500); int retry=5; while (rv == ErrLockTimeOut) { if (retry == 0) { printf("DELETE:execute failed\n"); break;} printf("retrying execute\n"); rv = table->execute(); retry--; } } tuple = (char*)table->fetch() ; if (tuple == NULL) { printf("DELETE:fetch failed\n");break;} ret = table->deleteTuple(); retrycnt++; } if (ret != 0) { printf("RETURNING EARLY: %d with i:%d\n", ret, i); break;} table->closeScan(); rv = conn.commit(); if (rv != OK) { printf("COMMIT returned %d for record %d\n", rv, i); if (rv != ErrLockTimeOut) { printf("RETURNING EARLY: with i:%d\n", i); break; } os::usleep(500); while (rv == ErrLockTimeOut) { printf("retrying commit\n"); rv = conn.commit(); } } icount++; } char msgBuf[1024]; sprintf(msgBuf,"Delete: Thread %lu %d: Total rows :%d\n",os::getthrid(), val, icount); os::write(1,msgBuf,strlen(msgBuf)); dbMgr->closeTable(table); rv = conn.close(); return NULL; }
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); tabDef.addField("f2", typeInt); tabDef.addField("f3", typeString, 20); 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; char name[20] = "PRAVEEN"; table->bindFld("f1", &id1); table->bindFld("f2", &id2); table->bindFld("f3", name); int icount =0; for (int i = 0 ; i < 10 ; i++) { conn.startTransaction(); id1= i; rv = table->insertTuple(); if (rv != OK) break; icount++; conn.commit(); } printf("Tuples inserted in 1/txn is %d\n", icount); icount = 0; conn.startTransaction(); for (int i = 20 ; i < 30 ; i++) { id1 = i; rv = table->insertTuple(); if (rv != OK) break; icount++; } conn.commit(); printf("Tuples inserted in 10/txn is %d\n", icount); table->setCondition(NULL); rv = table->execute(); if (rv != OK) { dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); } void *fld2ptr, *fld3ptr, *tuple; while(true) { tuple = (char*)table->fetch() ; if (tuple == NULL) { break; } fld2ptr = (char*)tuple + os::align(sizeof(int)); fld3ptr = (char*)tuple + (2 * os::align(sizeof(int))); printf("Tuple value is %d %d %s \n", *((int*)tuple), *((int*)fld2ptr), (char*)fld3ptr ); printf("Binded Tuple value is %d %d %s \n", id1, id2, name); } table->closeScan(); dbMgr->closeTable(table); dbMgr->dropTable("t1"); conn.close(); return 0; }