From 04bb53c0bccbe6936503cb32b4c80024a90f19c1 Mon Sep 17 00:00:00 2001 From: teodor Date: Thu, 26 Oct 2006 17:35:35 +0000 Subject: [PATCH] Add count of found rows --- ftsbench.c | 4 +++- ftsbench.h | 1 + mysqldriver.c | 56 +++++++++++++++++++++++++++++++++++++-------------- pgdriver.c | 6 ++++++ 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/ftsbench.c b/ftsbench.c index 86d9b14..917c090 100644 --- a/ftsbench.c +++ b/ftsbench.c @@ -289,7 +289,7 @@ main(int argn, char *argv[]) { pthread_t *tid = (pthread_t*)malloc( sizeof(pthread_t) * nclients); struct timeval begin; double elapsed; - int total=0; + int total=0, nres=0; struct timespec sleepTo = { 0, 0 }; /* @@ -352,11 +352,13 @@ main(int argn, char *argv[]) { for(i=0;inres; dbs[i]->Close(dbs[i]); } printf("%s%d(%.02f%%) queries proceed\n", (quiet) ? "" : "\r", total, (100.0*(float)total)/(nclients * n)); + printf("Total number of result: %d\n", nres); printf("Total time: %.02f sec, Queries per second: %.02f\n", elapsed, total/elapsed); fflush(stdout); } diff --git a/ftsbench.h b/ftsbench.h index 9037333..00c1a62 100644 --- a/ftsbench.h +++ b/ftsbench.h @@ -60,6 +60,7 @@ typedef struct ftsDB { /* stats */ pthread_mutex_t nqueryMutex; int nquery; + int nres; /* follow db specific fields */ } ftsDB; diff --git a/mysqldriver.c b/mysqldriver.c index 034a37a..68f5b40 100644 --- a/mysqldriver.c +++ b/mysqldriver.c @@ -50,7 +50,10 @@ typedef struct ftsMY { static void execQuery(ftsDB *adb, char **words, int flags) { ftsMY *db = (ftsMY*)adb; - static MYSQL_BIND data; + static MYSQL_BIND datain, dataout; + static int intout; + static my_bool isnull, my_error; + static unsigned long length; MYSQL_RES *res; if ( db->prepareStmt == NULL ) { @@ -71,9 +74,16 @@ execQuery(ftsDB *adb, char **words, int flags) { exit(1); } - memset(&data, 0, sizeof(MYSQL_BIND)); - data.buffer_type = MYSQL_TYPE_BLOB; - data.length = (unsigned long*)&(db->b.strlen); + memset(&datain, 0, sizeof(MYSQL_BIND)); + datain.buffer_type = MYSQL_TYPE_BLOB; + datain.length = (unsigned long*)&(db->b.strlen); + + memset(&dataout, 0, sizeof(MYSQL_BIND)); + dataout.buffer_type= MYSQL_TYPE_LONG; + dataout.buffer= (char *)&intout; + dataout.is_null= &isnull; + dataout.length= &length; + dataout.error= &my_error; db->flags = flags; } @@ -90,27 +100,43 @@ execQuery(ftsDB *adb, char **words, int flags) { words++; } - data.buffer = db->b.str; - data.buffer_length = db->b.strlen; + datain.buffer = db->b.str; + datain.buffer_length = db->b.strlen; - if ( mysql_stmt_bind_param(db->prepareStmt, &data) ) { + if ( mysql_stmt_bind_param(db->prepareStmt, &datain) ) { fprintf(stderr,"mysql_stmt_bind_param failed: %s\n", mysql_error(db->conn)); exit(1); } + res = mysql_stmt_result_metadata(db->prepareStmt); + if ( !res ) { + fprintf(stderr,"mysql_stmt_result_metadata failed: %s\n", mysql_error(db->conn)); + exit(1); + } + if ( mysql_stmt_execute( db->prepareStmt ) ) { fprintf(stderr,"mysql_stmt_execute failed: %s\n", mysql_error(db->conn)); exit(1); } - res = mysql_store_result(db->conn); - if ( res == NULL ) { - if ( mysql_errno(db->conn)!=0 ) { - fprintf(stderr,"mysql_store_result failed: %s\n", mysql_error(db->conn)); - exit(1); - } - } else - mysql_free_result(res); + if (mysql_stmt_bind_result( db->prepareStmt, &dataout)) { + fprintf(stderr,"mysql_stmt_bind_result failed: %s\n", mysql_error(db->conn)); + exit(1); + } + + if ( mysql_stmt_store_result( db->prepareStmt ) ) { + fprintf(stderr,"mysql_stmt_store_result failed: %s\n", mysql_error(db->conn)); + exit(1); + } + + if ( !mysql_stmt_fetch( db->prepareStmt) ) { + db->db.nres += intout; + } else { + fprintf(stderr,"mysql_stmt_fetch returns void result\n"); + exit(1); + } + + mysql_free_result(res); pthread_mutex_lock(&(db->db.nqueryMutex)); db->db.nquery ++; diff --git a/pgdriver.c b/pgdriver.c index 0a373b6..ed15a57 100644 --- a/pgdriver.c +++ b/pgdriver.c @@ -260,7 +260,13 @@ execQuery(ftsDB* adb, char ** words, int flags) { fprintf(stderr, "Execution of prepared statement failed: %s\n", PQerrorMessage(db->conn)); exit(1); } + } else if ( PQntuples(res) == 1 ) { + db->db.nres += atoi( PQgetvalue(res,0,0) ); + } else { + fprintf(stderr,"Bad PQntuples %d\n", PQntuples(res)); + exit(1); } + PQclear(res); db->emptyquery = 0; -- 2.37.3