/* 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);
}
}
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);
}
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);
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);
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);
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);
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);
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);
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);
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 {
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);
}
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);
}