Some cleanups
authorteodor <teodor>
Wed, 25 Oct 2006 16:25:53 +0000 (16:25 +0000)
committerteodor <teodor>
Wed, 25 Oct 2006 16:25:53 +0000 (16:25 +0000)
ftsbench.c
pgdriver.c
stopfilter.c

index 83adbcf..f577336 100644 (file)
@@ -338,7 +338,7 @@ main(int argn, char *argv[]) {
                        res = pthread_cond_timedwait( &condFinish, &mutexFinish, &sleepTo );
 
                        if ( !(res == ETIMEDOUT || res == 0) ) {
-                               fprintf(stderr,"pthread_cond_timedwait failed: %s", strerror(errno));
+                               fprintf(stderr,"pthread_cond_timedwait failed: %s\n", strerror(errno));
                                exit(1);
                        }
                }
index a64fbab..1ee408a 100644 (file)
@@ -114,7 +114,7 @@ pgflush(ftsPG *db) {
                /* success write, waits for read */
                db->state = SS_READ;
        } else {
-               fprintf(stderr, "PQflush failed: %s", PQerrorMessage(db->conn));
+               fprintf(stderr, "PQflush failed: %s\n", PQerrorMessage(db->conn));
                exit(1);
        }
 }
@@ -161,7 +161,7 @@ waitResult(ftsPG *db) {
                if ( pfd.events ) {
                        int ret = poll( &pfd, 1, INFTIM);
                        if ( ret<0 ) {
-                               fprintf(stderr,"poll failed: %s", strerror(errno));
+                               fprintf(stderr,"poll failed: %s\n", strerror(errno));
                                exit(1);
                        }
 
@@ -178,7 +178,7 @@ waitResult(ftsPG *db) {
 
        while ( (res = PQgetResult(db->conn))!= NULL ) {
                if (PQresultStatus(res) != PGRES_COMMAND_OK) {
-                       fprintf(stderr, "Execution of prepared statement failed: %s", PQerrorMessage(db->conn));
+                       fprintf(stderr, "Execution of prepared statement failed: %s\n", PQerrorMessage(db->conn));
                        exit(1);
                }
                PQclear(res);
@@ -211,15 +211,13 @@ execQuery(ftsDB* adb, char ** words, int flags) {
 
                db->flags = flags;
 
-               if ( flags & FLG_FUNC )
-                       sprintf(buf, "SELECT count(*) FROM ftsbench WHERE to_tsvector(body) @@ to_tsquery( $1 ::text );");
-               else
-                       sprintf(buf, "SELECT count(*) FROM ftsbench WHERE fts @@ to_tsquery( $1 ::text );");
+               sprintf(buf, "SELECT count(*) FROM ftsbench WHERE %s @@ to_tsquery( $1 ::text );",
+                       ( flags & FLG_FUNC ) ? "to_tsvector(body)" : "fts" );
 
                res = PQprepare( db->conn, "search_ftsbench", buf, 1, NULL );
                
                if (PQresultStatus(res) != PGRES_COMMAND_OK) {
-                       fprintf(stderr, "PREPARE SELECT command failed: %s", PQerrorMessage(db->conn));
+                       fprintf(stderr, "PREPARE SELECT command failed: %s\n", PQerrorMessage(db->conn));
                        exit(1);
                }
                PQclear(res);
@@ -281,7 +279,7 @@ startCreateScheme(ftsDB* adb, int flags) {
 
        res = PQexec(db->conn, "DROP TABLE IF EXISTS ftsbench CASCADE;");
        if (PQresultStatus(res) != PGRES_COMMAND_OK) {
-               fprintf(stderr, "DROP TABLE command failed: %s", PQerrorMessage(db->conn));
+               fprintf(stderr, "DROP TABLE command failed: %s\n", PQerrorMessage(db->conn));
                        exit(1);
        }
        PQclear(res);
@@ -295,14 +293,14 @@ startCreateScheme(ftsDB* adb, int flags) {
 
        res = PQexec(db->conn, buf);
        if (PQresultStatus(res) != PGRES_COMMAND_OK) {
-               fprintf(stderr, "CREATE TABLE command failed: %s", PQerrorMessage(db->conn));
+               fprintf(stderr, "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn));
                        exit(1);
        }
        PQclear(res);
 
        res = PQexec(db->conn, "BEGIN;");
        if (PQresultStatus(res) != PGRES_COMMAND_OK) {
-               fprintf(stderr, "CREATE TABLE command failed: %s", PQerrorMessage(db->conn));
+               fprintf(stderr, "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn));
                        exit(1);
        }
        PQclear(res);
@@ -319,14 +317,14 @@ finishCreateScheme(ftsDB* adb) {
                waitResult(db);
                
                if ( PQsetnonblocking(db->conn, 0) != 0 ) {
-                       fprintf(stderr, "PQsetnonblocking command failed: %s", PQerrorMessage(db->conn));
+                       fprintf(stderr, "PQsetnonblocking command failed: %s\n", PQerrorMessage(db->conn));
                        exit(1);
                }
        }
 
        res = PQexec(db->conn, "COMMIT;");
        if (PQresultStatus(res) != PGRES_COMMAND_OK) {
-               fprintf(stderr, "CREATE TABLE command failed: %s", PQerrorMessage(db->conn));
+               fprintf(stderr, "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn));
                        exit(1);
        }
        PQclear(res);
@@ -346,7 +344,7 @@ finishCreateScheme(ftsDB* adb) {
 
                res = PQexec(db->conn, buf);
                if (PQresultStatus(res) != PGRES_COMMAND_OK) {
-                       fprintf(stderr, "CREATE INDEX command failed: %s", PQerrorMessage(db->conn));
+                       fprintf(stderr, "CREATE INDEX command failed: %s\n", PQerrorMessage(db->conn));
                                exit(1);
                }
                PQclear(res);
@@ -360,7 +358,7 @@ finishCreateScheme(ftsDB* adb) {
 
        res = PQexec(db->conn, "VACUUM ANALYZE ftsbench;");
        if (PQresultStatus(res) != PGRES_COMMAND_OK) {
-               fprintf(stderr, "VACUUM ANALYZE command failed: %s", PQerrorMessage(db->conn));
+               fprintf(stderr, "VACUUM ANALYZE command failed: %s\n", PQerrorMessage(db->conn));
                exit(1);
        }
        PQclear(res);
@@ -388,13 +386,13 @@ InsertRow(ftsDB* adb, int id, char *txt) {
                                                 2, NULL );
                
                if (PQresultStatus(res) != PGRES_COMMAND_OK) {
-                       fprintf(stderr, "PREPARE INSERT command failed: %s", PQerrorMessage(db->conn));
+                       fprintf(stderr, "PREPARE INSERT command failed: %s\n", PQerrorMessage(db->conn));
                        exit(1);
                }
                PQclear(res);
 
                if ( PQsetnonblocking(db->conn, 1) != 0 ) {
-                       fprintf(stderr, "PQsetnonblocking command failed: %s", PQerrorMessage(db->conn));
+                       fprintf(stderr, "PQsetnonblocking command failed: %s\n", PQerrorMessage(db->conn));
                        exit(1);
                }
        } else {
@@ -408,7 +406,7 @@ InsertRow(ftsDB* adb, int id, char *txt) {
        if ( PQsendQueryPrepared( db->conn, "insert_ftsbench",
                                                 2, paramValues,
                                                 paramLengths, paramFormats, 0) == 0 ) {
-                fprintf(stderr, "PQsendQueryPrepared failed: %s", PQerrorMessage(db->conn));
+                fprintf(stderr, "PQsendQueryPrepared failed: %s\n", PQerrorMessage(db->conn));
                 exit(1);
        }
 
@@ -428,7 +426,7 @@ PGInit(char * connstr) {
        db->conn = PQconnectdb(conninfo);
 
        if (PQstatus(db->conn) != CONNECTION_OK) {
-               fprintf(stderr, "Connection to database failed: %s", PQerrorMessage(db->conn));
+               fprintf(stderr, "Connection to database failed: %s\n", PQerrorMessage(db->conn));
                exit(1);
        }
 
index 12e452c..ced7c29 100644 (file)
@@ -79,7 +79,7 @@ readstoplist(char *filename, StopList * s)
                        tmp = (char **) realloc((void *) stop, sizeof(char *) * reallen);
                        if (!tmp)
                        {
-                               fprintf(stderr,"Not enough memory");
+                               fprintf(stderr,"Not enough memory\n");
                                exit(1);
                        }
                        stop = tmp;
@@ -88,7 +88,7 @@ readstoplist(char *filename, StopList * s)
                stop[s->len] = strdup(buf);
                if (!stop[s->len])
                {
-                       fprintf(stderr,"Not enough memory");
+                       fprintf(stderr,"Not enough memory\n");
                        exit(1);
                }