/* success write, waits for read */
db->state = SS_READ;
} else {
- fprintf(stderr, "PQflush failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
+ fatal( "PQflush failed: %s\n", PQerrorMessage(db->conn));
}
}
break;
case SS_NONE:
default:
- fprintf(stderr,"Should not be here!\n");
- exit(1);
+ fatal( "Should not be here!\n");
break;
}
if ( pfd.events ) {
int ret = poll( &pfd, 1, INFTIM);
- if ( ret<0 ) {
- fprintf(stderr,"poll failed: %s\n", strerror(errno));
- exit(1);
- }
+ if ( ret<0 )
+ fatal("poll failed: %s\n", strerror(errno));
- if ( pfd.revents & (POLLHUP | POLLNVAL | POLLERR) ) {
- fprintf(stderr,"Poll report about socket error\n");
- exit(1);
+ if ( pfd.revents & (POLLHUP | POLLNVAL | POLLERR) ) {
+ fatal("Poll report about socket error\n");
} else if ( pfd.revents & POLLIN ) {
db->state = SS_READYREAD;
} else if ( pfd.revents & POLLOUT ) {
} while( checkStatus(db) != RS_OK );
while ( (res = PQgetResult(db->conn))!= NULL ) {
- if (PQresultStatus(res) != PGRES_COMMAND_OK) {
- fprintf(stderr, "Execution of prepared statement failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ fatal( "Execution of prepared statement failed: %s\n", PQerrorMessage(db->conn));
PQclear(res);
}
}
res = PQprepare( db->conn, "search_ftsbench", buf, 1, NULL );
- if (PQresultStatus(res) != PGRES_COMMAND_OK) {
- fprintf(stderr, "PREPARE SELECT command failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ fatal( "PREPARE SELECT command failed: %s\n", PQerrorMessage(db->conn));
PQclear(res);
db->prepared = 1;
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
/* skip error ' all words are a stop word' for GIN index -
result is empty, in any case */
- if ( checkEmptyQuery(db, res) == 0 ) {
- fprintf(stderr, "Execution of prepared statement failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if ( checkEmptyQuery(db, res) == 0 )
+ fatal( "Execution of prepared statement failed: %s\n", PQerrorMessage(db->conn));
} else if ( PQntuples(res) == 1 ) {
db->db.nres += atoi( PQgetvalue(res,0,0) );
} else {
- fprintf(stderr,"Bad PQntuples %d\n", PQntuples(res));
- exit(1);
+ fatal("Bad PQntuples %d\n", PQntuples(res));
}
PQclear(res);
db->flags = flags;
res = PQexec(db->conn, "DROP TABLE IF EXISTS ftsbench CASCADE;");
- if (PQresultStatus(res) != PGRES_COMMAND_OK) {
- fprintf(stderr, "DROP TABLE command failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ fatal( "DROP TABLE command failed: %s\n", PQerrorMessage(db->conn));
PQclear(res);
if ( flags & FLG_FUNC )
"FOR EACH ROW EXECUTE PROCEDURE tsearch2(fts, body);" );
res = PQexec(db->conn, buf);
- if (PQresultStatus(res) != PGRES_COMMAND_OK) {
- fprintf(stderr, "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ fatal( "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn));
PQclear(res);
res = PQexec(db->conn, "BEGIN;");
- if (PQresultStatus(res) != PGRES_COMMAND_OK) {
- fprintf(stderr, "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ fatal( "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn));
PQclear(res);
return;
if ( db->db.nquery > 0 ) {
waitResult(db);
- if ( PQsetnonblocking(db->conn, 0) != 0 ) {
- fprintf(stderr, "PQsetnonblocking command failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if ( PQsetnonblocking(db->conn, 0) != 0 )
+ fatal( "PQsetnonblocking command failed: %s\n", PQerrorMessage(db->conn));
}
res = PQexec(db->conn, "COMMIT;");
- if (PQresultStatus(res) != PGRES_COMMAND_OK) {
- fprintf(stderr, "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ fatal( "CREATE TABLE command failed: %s\n", PQerrorMessage(db->conn));
PQclear(res);
if ( (db->flags & (FLG_GIST | FLG_GIN)) != 0 ) {
report("(create index, ");
res = PQexec(db->conn, buf);
- if (PQresultStatus(res) != PGRES_COMMAND_OK) {
- fprintf(stderr, "CREATE INDEX command failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ fatal( "CREATE INDEX command failed: %s\n", PQerrorMessage(db->conn));
PQclear(res);
} else
report("(");
report("vacuum");
res = PQexec(db->conn, "VACUUM ANALYZE ftsbench;");
- if (PQresultStatus(res) != PGRES_COMMAND_OK) {
- fprintf(stderr, "VACUUM ANALYZE command failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ fatal( "VACUUM ANALYZE command failed: %s\n", PQerrorMessage(db->conn));
PQclear(res);
report(") ");
"INSERT INTO ftsbench (id, body) VALUES ( $1 ::int4, $2 ::text);",
2, NULL );
- if (PQresultStatus(res) != PGRES_COMMAND_OK) {
- fprintf(stderr, "PREPARE INSERT command failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ fatal( "PREPARE INSERT command failed: %s\n", PQerrorMessage(db->conn));
PQclear(res);
- if ( PQsetnonblocking(db->conn, 1) != 0 ) {
- fprintf(stderr, "PQsetnonblocking command failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if ( PQsetnonblocking(db->conn, 1) != 0 )
+ fatal( "PQsetnonblocking command failed: %s\n", PQerrorMessage(db->conn));
} else {
waitResult(db);
}
if ( PQsendQueryPrepared( db->conn, "insert_ftsbench",
2, paramValues,
- paramLengths, paramFormats, 0) == 0 ) {
- fprintf(stderr, "PQsendQueryPrepared failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ paramLengths, paramFormats, 0) == 0 )
+ fatal( "PQsendQueryPrepared failed: %s\n", PQerrorMessage(db->conn));
pgflush(db);
sprintf(conninfo, "dbname=%s", connstr);
db->conn = PQconnectdb(conninfo);
- if (PQstatus(db->conn) != CONNECTION_OK) {
- fprintf(stderr, "Connection to database failed: %s\n", PQerrorMessage(db->conn));
- exit(1);
- }
+ if (PQstatus(db->conn) != CONNECTION_OK)
+ fatal( "Connection to database failed: %s\n", PQerrorMessage(db->conn));
db->origreceiver = PQsetNoticeReceiver(db->conn, NoticeReceiver, (void *)db);
db->db.InsertRow = InsertRow;
db->db.Close = Close;
db->socket = PQsocket(db->conn);
- if ( db->socket < 0 ) {
- fprintf(stderr,"Socket error\n");
- exit(1);
- }
+ if ( db->socket < 0 )
+ fatal("Socket error\n");
return (ftsDB*)db;
}