Add count of found rows
authorteodor <teodor>
Thu, 26 Oct 2006 17:35:35 +0000 (17:35 +0000)
committerteodor <teodor>
Thu, 26 Oct 2006 17:35:35 +0000 (17:35 +0000)
ftsbench.c
ftsbench.h
mysqldriver.c
pgdriver.c

index 86d9b14..917c090 100644 (file)
@@ -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;i<nclients;i++) {
                        pthread_join(tid[i], NULL);
+                       nres += dbs[i]->nres;
                        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);
        }
index 9037333..00c1a62 100644 (file)
@@ -60,6 +60,7 @@ typedef struct ftsDB {
        /* stats */
        pthread_mutex_t nqueryMutex;
        int                     nquery;
+       int                     nres;
 
        /* follow db specific fields */
 } ftsDB;
index 034a37a..68f5b40 100644 (file)
@@ -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 ++;
index 0a373b6..ed15a57 100644 (file)
@@ -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;