//From Prepare to Commit(Update int UpdateTest(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt) { int rc,i; int iHolder; char sHolder[200]; char sData[200]; timer.reset(); for(i=0;i<ITERATION;i++){ timer.start(); rc = SQLPrepare (hstmt, (unsigned char *) "UPDATE t1 SET f2 = ? WHERE f1 = ?", SQL_NTS); checkrc (rc, __LINE__); SQLINTEGER sLen = SQL_NTS; rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 196, 0, (void *) sHolder, 0, &sLen); checkrc (rc, __LINE__); rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &iHolder, 0, NULL); checkrc (rc, __LINE__); iHolder = 0; strcpy (sData, "9876543210987654321098765432109876543210"); iHolder = i ; strcpy (sHolder, sData); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); } printf ("Update: %lld %lld %lld\n", timer.minc (), timer.maxc (),timer.avg ()); }
int runDeleteTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt) { int rc; int iHolder; rc = SQLPrepare (hstmt, (unsigned char *) "DELETE FROM t1 WHERE f1 = ?", SQL_NTS); checkrc (rc, __LINE__); rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &iHolder, 0, NULL); checkrc (rc, __LINE__); iHolder = 0; int i, j, k; int tCount; timer.reset (); /* Run 1per Test */ for (i = START; i < (START+ITERATION); i++) { timer.start (); iHolder = i ; rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); } printf ("Delete: 1 %lld %lld %lld\n", timer.min (), timer.max (), timer.avg ()); return 0; }
//aggregate long long int aggregate(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt,int val,bool flag) { int summinmax=0,tempTermVar=0; int rc; /* Set read-only transaction type */ readOnlyTrans (hdbc); if(val==1 && flag){ rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MIN(unique1) from big1;", SQL_NTS); } else if(val==1 && !flag) { rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MIN(unique1) from big1 group by onepercent;", SQL_NTS); } else if(val==2 && flag) { rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MAX(unique1) from big1;", SQL_NTS); } else if(val==2 && !flag){ rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MAX(unique1) from big1 group by onepercent;", SQL_NTS); } else if(val==3 && flag) { rc = SQLPrepare (hstmt, (unsigned char *) "SELECT SUM(unique1) from big1;", SQL_NTS); } else if(val==3 && !flag){ rc = SQLPrepare (hstmt, (unsigned char *) "SELECT SUM(unique1) from big1 group by onepercent;", SQL_NTS); } checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &summinmax, 0, NULL); checkrc (rc, __LINE__); int i, j, k; int Count; timer.reset (); for (i = 0; i < 10; i++) { timer.start (); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLFetch (hstmt); checkrc (rc, __LINE__); Count++; // printf("value=%d",summin); rc = SQLCloseCursor (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); } //printf ("Read: 1 %lld\n", timer.avg ()); /* Set read-write transaction type */ readWriteTrans (hdbc); return timer.avg()/1000; }
int runReadTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt) { int iHolder; int second; char sHolder[200]; char sData[200]; int tempTermVar = 0; int tempTermVal = 0; int rc; /* Set read-only transaction type */ readOnlyTrans (hdbc); rc = SQLPrepare (hstmt, (unsigned char *) "SELECT f1, f2 FROM t1 where f1 = ?", SQL_NTS); checkrc (rc, __LINE__); long sz = 0; rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &iHolder, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &second, 0, NULL); checkrc (rc, __LINE__); iHolder = 0; strcpy (sData, "0123456789012345678901234567890123456789"); int i, j, k; int tCount; timer.reset (); /* Run 1per Test */ for (i = START; i < (START+ITERATION); i++) { timer.start (); tempTermVar = i ; rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLFetch (hstmt); checkrc (rc, __LINE__); tempTermVal = iHolder; strcpy (sData, sHolder); rc = SQLCloseCursor (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); } printf ("Read: 1 %lld %lld %lld\n", timer.min (), timer.max (), timer.avg ()); /* Set read-write transaction type */ readWriteTrans (hdbc); return rc; }
int main(int argc, char** argv) { checkCommandLine(argc); vector<int> values; readFile( argv[1], values ); long total; NanoTimer nTimer; nTimer.start(); total = sum( values, atoi(argv[2]) ); nTimer.stop(); display(total, nTimer); }
//From Prepare to commit (Read) int ReadTest(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt) { int iHolder; char sHolder[200]; char sData[200]; int tempTermVar = 0; int tempTermVal = 0; int rc,i; // Set read-only transaction type readOnlyTrans (hdbc); timer.reset(); for(i=0;i<ITERATION;i++){ timer.start(); rc = SQLPrepare (hstmt, (unsigned char *) "SELECT f1, f2 FROM t1 where f1 = ?", SQL_NTS); checkrc (rc, __LINE__); long sz = 0; rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &iHolder, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 2, SQL_C_CHAR, sHolder, sizeof (sHolder), NULL); checkrc (rc, __LINE__); iHolder = 0; strcpy (sData, "0123456789012345678901234567890123456789"); int tCount; tempTermVar = i ; rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLFetch (hstmt); checkrc (rc, __LINE__); tempTermVal = iHolder; strcpy (sData, sHolder); rc = SQLCloseCursor (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop(); } printf("Select: %lld %lld %lld\n", timer.minc(), timer.maxc(),timer.avg()); readWriteTrans (hdbc); return rc; }
long long int dmlstatement(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt,int val) { int tempTermVar=10000,tempTermVar2=10000; int rc; /* Set read-only transaction type */ readOnlyTrans (hdbc); if(val==1){ rc = SQLPrepare (hstmt, (unsigned char *) "insert into big1 values(?,?,0,2,0,10,50,688,1950,4950,9950,1,100,'MXXXXXXXXXXXXXXXXXXXXXXXXXGXXXXXXXXXXXXXXXXXXXXXXXXC','GXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXXA','OXXXXXXXXXXXXXXXXXXXXXXXXXOXXXXXXXXXXXXXXXXXXXXXXXXO');", SQL_NTS); } else if(val==2){ rc = SQLPrepare (hstmt, (unsigned char *) "UPDATE big1 SET two=1 WHERE unique1=?;", SQL_NTS); }else { rc = SQLPrepare (hstmt, (unsigned char *) "DELETE FROM big1 WHERE unique1=?;", SQL_NTS); } checkrc (rc, __LINE__); int i, j, k; int Count; timer.reset (); for (i = 0; i < 100; i++) { tempTermVar+=i; rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL); checkrc (rc, __LINE__); if(val==1) { tempTermVar2+=i; rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL); checkrc (rc, __LINE__); } timer.start (); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); tempTermVar=10000;tempTermVar2=10000; } //printf ("Read: 1 %lld\n", timer.avg ()); /* Set read-write transaction type */ readWriteTrans (hdbc); return timer.avg()/1000; }
int runInsertTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt) { int rc; int iHolder; char sHolder[200]; char sData[200]; iHolder = 0; strcpy (sData, "0123456789012345678901234567890123456789"); rc = SQLPrepare (hstmt, (unsigned char *) "INSERT INTO t1 VALUES (?, ?)", SQL_NTS); checkrc (rc, __LINE__); rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &iHolder, 0, NULL); checkrc (rc, __LINE__); SQLINTEGER sLen = SQL_NTS; rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 196, 0, (void *) sHolder, 0, &sLen); checkrc (rc, __LINE__); int i, j, k; int tCount; timer.reset (); /* Run 1per Test */ for (i = 0; i < ITERATION; i++) { timer.start (); iHolder = i ; strcpy (sHolder, sData); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); } printf ("Insert: 1 %lld %lld %lld\n", timer.minc (), timer.maxc (), timer.avg ()); return 0; }
int runInsertTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt) { int rc; int iHolder; char sHolder[200]; char sData[200]; iHolder = 0; strcpy (sData, "0123456789012345678901234567890123456789"); rc = SQLPrepare (hstmt, (unsigned char *) "insert into t1 values(?,12,13,14,15,16,17,18,19,20,21,100,100,'AXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXX','GXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXXA','OXXXXXXXXXXXXXXXXXXXXXXXXXOXXXXXXXXXXXXXXXXXXXXXXXXO')", SQL_NTS); checkrc (rc, __LINE__); rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &iHolder, 0, NULL); checkrc (rc, __LINE__); SQLINTEGER sLen = SQL_NTS; /* rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 196, 0, (void *) sHolder, 0, &sLen);*/ checkrc (rc, __LINE__); int i, j, k; int tCount; timer.reset (); /* Run 1per Test */ for (i = START; i<(START + ITERATION); i++) { timer.start (); iHolder = i ; strcpy (sHolder, sData); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); } printf ("Insert: 1 %lld %lld %lld\n", timer.min (), timer.max (), timer.avg ()); return 0; }
int runUpdateTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt) { int rc; int iHolder; char sHolder[200]; char sData[200]; rc = SQLPrepare (hstmt, (unsigned char *) "UPDATE t1 SET f2 = 122323 WHERE f1 = ?", SQL_NTS); checkrc (rc, __LINE__); SQLINTEGER sLen = SQL_NTS; rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &iHolder, 0, NULL); checkrc (rc, __LINE__); iHolder = 0; strcpy (sData, "9876543210987654321098765432109876543210"); int i, j, k; int tCount; timer.reset (); /* Run 1per Test */ for (i = START; i < (START+ITERATION); i++) { timer.start (); iHolder = i ; strcpy (sHolder, sData); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); } printf ("Update: 1 %lld %lld %lld\n", timer.min (), timer.max (), timer.avg ()); return 0; }
//DISTINCT long long int distinct(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt) { int var_onepercent; int rc; readOnlyTrans (hdbc); rc = SQLPrepare (hstmt, (unsigned char *) "SELECT DISTINCT onepercent FROM big1;", SQL_NTS); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &var_onepercent, 0, NULL); checkrc (rc, __LINE__); int i,count; timer.reset (); for (i = 0; i < 10; i++) { count=0; timer.start (); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); while(SQL_SUCCEEDED(rc = SQLFetch(hstmt))){ count++; } //checkrc (rc, __LINE__); rc = SQLCloseCursor (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); if (count != 100) { printf("distinct returned %d rows\n"); readWriteTrans(hdbc); return 0; } } readWriteTrans(hdbc); return timer.avg()/1000; }
long long int joinCondition(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt,int value) { int uni1; int uni2,uni3,uni4,uni5; char str1[52]; char str2[52]; int rc; int searchVal[] = {1, 5, 10, 50, 100, 200, 250, 500, 750, 800}; //Set read-only transaction type readOnlyTrans (hdbc); if(value==1 ) { rc = SQLPrepare (hstmt, (unsigned char *) "SELECT big1.unique1, big1.unique2, small.unique1, small.stringu1 FROM big1,small WHERE big1.unique1=small.unique1 AND big1.unique1 > ? and big1.unique1 <= ?;", SQL_NTS); } else { rc = SQLPrepare (hstmt, (unsigned char *) "SELECT small.unique1, big1.unique1, big2.unique1, small.stringu1, big1.unique2, big2.unique2 FROM big1, big2, small WHERE big1.unique1=small.unique1 AND big1.unique1=big2.unique1 AND big1.unique1 > ? and big1.unique1 <= ?;", SQL_NTS); } checkrc (rc, __LINE__); int tempTermVar1 =0, tempTermVar2=0; rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar1, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL); checkrc (rc, __LINE__); long sz = 0; rc = SQLBindCol (hstmt, 1, SQL_C_SLONG, &uni1, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 2, SQL_C_SLONG, &uni2, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 3, SQL_C_SLONG, &uni3, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str1, sizeof (str1), NULL); checkrc (rc, __LINE__); if(value==2){ rc = SQLBindCol (hstmt, 5, SQL_C_SLONG, &uni4, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 6, SQL_C_SLONG, &uni5, 0, NULL); checkrc (rc, __LINE__); } int i, j, k; int count=0; timer.reset (); for(i=0;i<10;i++){ count=0; tempTermVar1 = searchVal[i]; tempTermVar2 = searchVal[i]+100; timer.start (); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); while(SQL_SUCCEEDED(rc = SQLFetch(hstmt))) { count++; //printf("Uni1:%d uni2=%d uni3=%d \n",uni1,uni2,uni3); } rc = SQLCloseCursor (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); if (count != 100) { printf ("range join returned %d rows\n", count); readWriteTrans (hdbc); return 0; } } readWriteTrans (hdbc); return timer.avg()/1000; }
//Joining long long int joining(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt,int value) { int uni1; int uni2,uni3,uni4,uni5; char str1[52]; char str2[52]; int val[10] = {1, 5, 10, 50, 100, 250, 500, 750, 900, 999}; int tempTermVar=0; char tempval[124]="Value"; int rc; /* Set read-only transaction type */ readOnlyTrans (hdbc); if(value==1 ){ rc = SQLPrepare (hstmt, (unsigned char *) "SELECT big1.unique1, big1.unique2, small.unique1, small.stringu1 FROM big1,small WHERE big1.unique1=small.unique1 AND big1.unique1=?;", SQL_NTS); } else { rc = SQLPrepare (hstmt, (unsigned char *) "SELECT small.unique1, big1.unique1, big2.unique1, small.stringu1, big1.unique2, big2.unique2 FROM big1, big2, small WHERE small.unique1=big1.unique2 AND big1.unique2=big2.unique1 AND big1.unique1 = ?;", SQL_NTS); } checkrc (rc, __LINE__); long sz = 0; rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 1, SQL_C_LONG, &uni1, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 2, SQL_C_LONG, &uni2, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 3, SQL_C_LONG, &uni3, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str1, sizeof (str1), NULL); checkrc (rc, __LINE__); if(value==2 ){ rc = SQLBindCol (hstmt, 5, SQL_C_LONG, &uni4, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 6, SQL_C_LONG, &uni5, 0, NULL); checkrc (rc, __LINE__); } int i, j, k; int Count=0; timer.reset (); for (i = 0; i < 10; i++) { tempTermVar = val[i]; timer.start (); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc=SQLFetch(hstmt); Count++; rc = SQLCloseCursor (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); // printf("uni1=%d uni2=%d uni3=%d str1=%s \n",uni1,uni2,uni3,str1); } readWriteTrans (hdbc); return timer.avg()/1000; }
int main() { DbRetVal rv = OK; AbsSqlConnection *con = SqlFactory::createConnection(CSql); rv = con->connect("root", "manager"); if (rv != OK) return 1; AbsSqlStatement *stmt = SqlFactory::createStatement(CSql); stmt->setConnection(con); char statement[1024]; strcpy(statement, "CREATE TABLE t1 (f1 int, f2 char(196));"); int rows =0; rv = stmt->prepare(statement); if (rv != OK) {delete stmt; delete con; return -1; } rv = stmt->execute(rows); if (rv != OK) {delete stmt; delete con; return -1; } stmt->free(); printf("Table t1 created\n"); strcpy(statement, "CREATE INDEX t1idx on t1 (f1);"); rv = stmt->prepare(statement); if (rv != OK) {delete stmt; delete con; return -1; } rv = stmt->execute(rows); if (rv != OK) {delete stmt; delete con; return -1; } stmt->free(); printf("Index created on t1(f1) \n"); strcpy(statement, "INSERT INTO t1 (f1, f2) VALUES (?, ?);"); int id1 =10; char name[196]; strcpy(name, "Rithish"); NanoTimer timer; rv = stmt->prepare(statement); if (rv != OK) {delete stmt; delete con; return -1; } int count =0; for (int i = 0 ; i < ITERATIONS ; i++) { timer.start(); rv = con->beginTrans(); if (rv != OK) break; id1 = i; stmt->setIntParam(1, id1); strcpy(name, "Gopika"); stmt->setStringParam(2, name); rv = stmt->execute(rows); if (rv != OK) break; rv = con->commit(); if (rv != OK) break; timer.stop(); count++; } printf("Total Rows Inserted %d %lld %lld %lld\n", count, timer.minc(), timer.maxc(), timer.avg()); stmt->free(); strcpy(statement, "SELECT * FROM t1 where f1 = ?;"); rv = stmt->prepare(statement); if (rv != OK) {delete stmt; delete con; return -1; } stmt->bindField(1, &id1); stmt->bindField(2, name); timer.reset(); count =0; for (int i = 0 ; i < ITERATIONS ; i++) { timer.start(); rv = con->beginTrans(); if (rv != OK) break; stmt->setIntParam(1, i); stmt->execute(rows); if (stmt->fetch() == NULL) { printf("unable to read record\n"); break; } stmt->close(); rv = con->commit(); if (rv != OK) break; timer.stop(); count++; } stmt->free(); printf("Total Rows Selected %d %lld %lld %lld\n", count, timer.minc(), timer.maxc(), timer.avg()); strcpy(statement, "UPDATE t1 set f2=? where f1=?;"); rv = stmt->prepare(statement); if (rv != OK) {delete stmt; delete con; return -1; } stmt->bindField(1, &id1); stmt->bindField(2, name); timer.reset(); count =0; for (int i = 0 ; i < ITERATIONS ; i++) { timer.start(); rv = con->beginTrans(); if (rv != OK) break; stmt->setIntParam(2, i); stmt->setStringParam(1, "ChangedValue"); rv = stmt->execute(rows); if (rv != OK && rows !=1) break; rv = con->commit(); if (rv != OK) break; timer.stop(); count++; } stmt->free(); printf("Total Rows Updated %d %lld %lld %lld\n", count, timer.minc(), timer.maxc(), timer.avg()); strcpy(statement, "DELETE FROM t1 where f1=?;"); rv = stmt->prepare(statement); if (rv != OK) {delete stmt; delete con; return -1; } stmt->bindField(1, &id1); timer.reset(); count =0; for (int i = 0 ; i < ITERATIONS ; i++) { timer.start(); rv = con->beginTrans(); if (rv != OK) break; stmt->setIntParam(1, i); rv = stmt->execute(rows); if (rv != OK && rows != 1) break; rv = con->commit(); if (rv != OK) break; timer.stop(); count++; } stmt->free(); printf("Total Rows Deleted %d %lld %lld %lld\n", count, timer.minc(), timer.maxc(), timer.avg()); strcpy(statement, "DROP TABLE t1;"); rv = stmt->prepare(statement); if (rv != OK) {delete stmt; delete con; return -1; } rv = stmt->execute(rows); if (rv != OK) {delete stmt; delete con; return -1; } stmt->free(); printf("Table dropped\n"); delete stmt; delete con; return 0; }
int runReadTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt) { int iHolder; char sHolder[200]; char sData[200]; int tempTermVar = 0; int tempTermVal = 0; int rc,i; timer.reset(); for(i=0;i<ITERATION;i++){ timer.start(); rc = SQLConnect (hdbc, (SQLCHAR *) DSN, SQL_NTS, (SQLCHAR *) "root", (SQLSMALLINT) strlen ("root"), (SQLCHAR *) "manager", (SQLSMALLINT) strlen ("")); if (SQL_SUCCEEDED(rc)) { if (rc == SQL_SUCCESS_WITH_INFO) { printf("Driver reported the following diagnostics\n"); extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC); } }else { fprintf(stderr, "Failed to connect\n"); extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC); } //check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__); checkrc (rc, __LINE__); rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF); checkrc (rc, __LINE__); rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt); checkrc (rc, __LINE__); // Set read-only transaction type readOnlyTrans (hdbc); rc = SQLPrepare (hstmt, (unsigned char *) "SELECT f1, f2 FROM t1 where f1 = ?", SQL_NTS); checkrc (rc, __LINE__); long sz = 0; rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &iHolder, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 2, SQL_C_CHAR, sHolder, sizeof (sHolder), NULL); checkrc (rc, __LINE__); iHolder = 0; strcpy (sData, "0123456789012345678901234567890123456789"); int tCount; tempTermVar = i ; rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLFetch (hstmt); checkrc (rc, __LINE__); tempTermVal = iHolder; strcpy (sData, sHolder); rc = SQLCloseCursor (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt); checkrc (rc, __LINE__); rc = SQLDisconnect (hdbc); checkrc (rc, __LINE__); timer.stop(); } printf("Select: %lld %lld %lld\n", timer.minc(), timer.maxc(),timer.avg()); return rc; }
long long int orderBy(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt) { int val[] = {1, 5, 10, 50, 100, 500, 1000, 5000 ,7500, 9500}; int var_two, var_four, var_ten, var_twenty, var_onepercent; char str1[52]; int tempTermVar=0, tempTermVar2=0, tempTermVar3=0; int rc; rc = SQLPrepare (hstmt, (unsigned char *) "SELECT two, four, ten, twenty, onepercent, string4 from big1 where unique1 between ? and ? order by unique1;", SQL_NTS); checkrc (rc, __LINE__); readOnlyTrans (hdbc); rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &var_two, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &var_four, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 3, SQL_INTEGER, &var_ten, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 4, SQL_INTEGER, &var_twenty, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 5, SQL_INTEGER, &var_onepercent, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 6, SQL_C_CHAR, str1, sizeof (str1), NULL); checkrc (rc, __LINE__); int i, j, k; int count; timer.reset (); for (i = 0; i < 10; i++) { count=0; tempTermVar=val[i]; tempTermVar2 = val[i]+100 ; timer.start (); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLFetch (hstmt); while(SQL_SUCCEEDED(rc = SQLFetch(hstmt))) count++; //checkrc (rc, __LINE__); rc = SQLCloseCursor (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); if (count != 100) { printf("orderby returned %d rows \n", count); readWriteTrans(hdbc); return 0; } } readWriteTrans(hdbc); return timer.avg()/1000; }
long long int runReadTest (SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt,bool flag) { int uni1; int uni2; char str1[52]; char str2[52]; //int val[] = {1, 10, 100, 500, 1000, 5000 ,7500, 8000, 9000, 9999}; int val[10] = {1, 5, 10, 50, 100, 250, 500, 750, 900, 999}; int tempTermVar=0; char tempval[52]="Value"; int rc; /* Set read-only transaction type */ readOnlyTrans (hdbc); if(flag){ rc = SQLPrepare (hstmt, (unsigned char *) "SELECT unique1, unique2, stringu1, stringu2 from big1 where unique1=?;", SQL_NTS); } else { rc = SQLPrepare (hstmt, (unsigned char *) "SELECT unique1, unique2, stringu1, stringu2 from big1 where stringu1=?;", SQL_NTS); } checkrc (rc, __LINE__); long sz = 0; if(flag){ rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL); checkrc (rc, __LINE__); } else{ rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_C_CHAR, 196, 0, tempval, 0, NULL); checkrc (rc, __LINE__); } rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &uni1, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &uni2, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 3, SQL_C_CHAR, str1, sizeof (str1), NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str2, sizeof (str2), NULL); checkrc (rc, __LINE__); int i, j, k; int Count; timer.reset (); char buf[10]="Value"; /* Run 1per Test */ for (i = 0; i < 10; i++) { if(flag){ tempTermVar = val[i] ;} else{ sprintf(tempval,"%s%d",buf, val[i]); } timer.start (); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLFetch (hstmt); checkrc (rc, __LINE__); Count++; rc = SQLCloseCursor (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); } //printf ("Read: 1 %lld\n", timer.avg ()); /* Set read-write transaction type */ readWriteTrans (hdbc); return timer.avg()/1000; }
long long int onePerSel(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt) { int uni1; int uni2; char str1[52]; char str2[52]; //int val[] = {1, 5, 10, 50, 100, 500, 1000, 5000 ,7500, 9500}; int val[10] = {1, 5, 10, 50, 100, 250, 500, 750, 900, 999}; int tempTermVar=0; int tempTermVar2=0; char tempval[124]="Value"; int rc; readOnlyTrans (hdbc); rc = SQLPrepare (hstmt, (unsigned char *) "SELECT unique1, unique2, stringu1 from big1 where unique1 between ? and ?;", SQL_NTS); checkrc (rc, __LINE__); rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &uni1, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &uni2, 0, NULL); checkrc (rc, __LINE__); rc = SQLBindCol (hstmt, 3, SQL_C_CHAR, str1, sizeof (str1), NULL); checkrc (rc, __LINE__); int i, j, k; int Count; timer.reset (); for (i = 0; i < 10; i++) { Count=0; strcpy(tempval,"Value"); tempTermVar = val[i] ; tempTermVar2 = val[i]+99 ; timer.start (); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); while(SQL_SUCCEEDED(rc = SQLFetch(hstmt))) { Count++; } // printf("Count=%d\n",Count); rc = SQLCloseCursor (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); timer.stop (); if (Count != 100) { printf("One % Selection returned %d rows", Count); readWriteTrans (hdbc); return 0; } } readWriteTrans (hdbc); //printf ("Read: 1 %lld\n", timer.avg ()); return timer.avg()/1000; }
void MyMonitorRequester::checkUpdate(shared_ptr<PVStructure> const &pvStructure) { # ifdef TIME_IT value_timer.start(); # endif // Time for value lookup when re-using offset: 2us shared_ptr<PVInt> value = dynamic_pointer_cast<PVInt>(pvStructure->getSubField(user_tag_offset)); // Compare: Time for value lookup when using name: 12us // shared_ptr<PVInt> value = pvStructure->getIntField("timeStamp.userTag"); if (! value) { cout << "No 'timeStamp.userTag'" << endl; return; } # ifdef TIME_IT value_timer.stop(); # endif // Check pulse ID for skipped updates uint64 pulse_id = static_cast<uint64>(value->get()); if (last_pulse_id != 0) { int missing = pulse_id - 1 - last_pulse_id; if (missing > 0) missing_pulses += missing; } last_pulse_id = pulse_id; // Compare lengths of tof and pixel arrays shared_ptr<PVUIntArray> tof = dynamic_pointer_cast<PVUIntArray>(pvStructure->getSubField(tof_offset)); if (!tof) { cout << "No 'time_of_flight' array" << endl; return; } shared_ptr<PVUIntArray> pixel = dynamic_pointer_cast<PVUIntArray>(pvStructure->getSubField(pixel_offset)); if (!pixel) { cout << "No 'pixel' array" << endl; return; } if (tof->getLength() != pixel->getLength()) { ++array_size_differences; if (! quiet) { cout << "time_of_flight: " << tof->getLength() << " elements" << endl; shared_vector<const uint32> tof_data; tof->getAs(tof_data); cout << tof_data << endl; cout << "pixel: " << pixel->getLength() << " elements" << endl; shared_vector<const uint32> pixel_data; pixel->getAs(pixel_data); cout << pixel_data << endl; } } }
int runUpdateTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt) { int rc,i; int iHolder; char sHolder[200]; char sData[200]; timer.reset(); for(i=0;i<ITERATION;i++){ timer.start(); rc = SQLConnect (hdbc, (SQLCHAR *) DSN, SQL_NTS, (SQLCHAR *) "root", (SQLSMALLINT) strlen ("root"), (SQLCHAR *) "manager", (SQLSMALLINT) strlen ("")); if (SQL_SUCCEEDED(rc)) { if (rc == SQL_SUCCESS_WITH_INFO) { printf("Driver reported the following diagnostics\n"); extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC); } }else { fprintf(stderr, "Failed to connect\n"); extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC); } checkrc (rc, __LINE__); rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF); checkrc (rc, __LINE__); rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt); rc = SQLPrepare (hstmt, (unsigned char *) "UPDATE t1 SET f2 = ? WHERE f1 = ?", SQL_NTS); checkrc (rc, __LINE__); SQLINTEGER sLen = SQL_NTS; rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 196, 0, (void *) sHolder, 0, &sLen); checkrc (rc, __LINE__); rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &iHolder, 0, NULL); checkrc (rc, __LINE__); iHolder = 0; strcpy (sData, "9876543210987654321098765432109876543210"); int tCount; iHolder = i ; strcpy (sHolder, sData); rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt); checkrc (rc, __LINE__); rc = SQLDisconnect (hdbc); checkrc (rc, __LINE__); timer.stop (); } printf ("Update: %lld %lld %lld\n", timer.minc (), timer.maxc (),timer.avg ()); return 0; }
int runDeleteTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt) { int rc,i; int iHolder; timer.reset(); for(i=0;i<ITERATION;i++){ timer.start(); rc = SQLConnect (hdbc, (SQLCHAR *) DSN, SQL_NTS, (SQLCHAR *) "root", (SQLSMALLINT) strlen ("root"), (SQLCHAR *) "manager", (SQLSMALLINT) strlen ("")); if (SQL_SUCCEEDED(rc)) { if (rc == SQL_SUCCESS_WITH_INFO) { printf("Driver reported the following diagnostics\n"); extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC); } }else { fprintf(stderr, "Failed to connect\n"); extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC); } //check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__); checkrc (rc, __LINE__); rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF); checkrc (rc, __LINE__); rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt); checkrc (rc, __LINE__); rc = SQLPrepare (hstmt, (unsigned char *)"DELETE FROM t1 WHERE f1 = ?", SQL_NTS); checkrc (rc, __LINE__); rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &iHolder, 0, NULL); checkrc (rc, __LINE__); iHolder = 0; int tCount; iHolder = i ; rc = SQLExecute (hstmt); checkrc (rc, __LINE__); rc = SQLTransact (henv, hdbc, SQL_COMMIT); checkrc (rc, __LINE__); rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt); checkrc (rc, __LINE__); rc = SQLDisconnect (hdbc); checkrc (rc, __LINE__); timer.stop (); } printf ("Delete: %lld %lld %lld\n", timer.minc (), timer.maxc (),timer.avg ()); 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; }