From c537ac69b85cb44a61479d59e910e880e5fe28f8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Franti=C5=A1ek=20Dvo=C5=99=C3=A1k?= Date: Sat, 31 Oct 2009 18:58:33 +0000 Subject: [PATCH] Binary data fetch support. Fix build in some cases. --- org.glite.lbjp-common.db/Makefile | 2 +- org.glite.lbjp-common.db/src/db-pg.c | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/org.glite.lbjp-common.db/Makefile b/org.glite.lbjp-common.db/Makefile index 6955f57..71ffa8f 100644 --- a/org.glite.lbjp-common.db/Makefile +++ b/org.glite.lbjp-common.db/Makefile @@ -33,7 +33,7 @@ MYSQL_SONAME:=$(shell ../project/get_soname.sh mysqlclient ${mysql-devel_prefix} PSQL_SONAME:=$(shell ../project/get_soname.sh pq ${postgresql_prefix}/${archlib} ${postgresql_prefix}/lib) MYSQL_CPPFLAGS:=-I${mysql-devel_prefix}/include -I${mysql-devel_prefix}/include/mysql -PSQL_CPPFLAGS=-I`pg_config --includedir` +PSQL_CPPFLAGS:=-I${postgresql_prefix}/include CFLAGS:= \ diff --git a/org.glite.lbjp-common.db/src/db-pg.c b/org.glite.lbjp-common.db/src/db-pg.c index 411177e..b17e6b1 100644 --- a/org.glite.lbjp-common.db/src/db-pg.c +++ b/org.glite.lbjp-common.db/src/db-pg.c @@ -1,9 +1,6 @@ /** * Simple postgres module with org.glite.lbjp-common.db interface. * - * Limitations: - * - binary results as escaped strings - * * PostgreSQL limitations: * - prepared commands requires server >= 8.2 */ @@ -27,7 +24,6 @@ #define DB_CONNECT_TIMEOUT "20" -#define LOG 1 #ifdef LOG #define lprintf(FMT...) fprintf(stdout, "[db-pg] %s: ", __FUNCTION__); fprintf(stdout, ##FMT); #else @@ -312,6 +308,8 @@ int glite_lbu_RollbackPsql(glite_lbu_DBContext ctx_gen __attribute((unused))) { int glite_lbu_FetchRowPsql(glite_lbu_Statement stmt_gen, unsigned int maxn, unsigned long *lengths, char **results) { glite_lbu_StatementPsql stmt = (glite_lbu_StatementPsql)stmt_gen; unsigned int i, n; + size_t len; + char *s; if (stmt->row >= stmt->nrows) return 0; @@ -325,10 +323,11 @@ int glite_lbu_FetchRowPsql(glite_lbu_Statement stmt_gen, unsigned int maxn, unsi return -1; } for (i = 0; i < n; i++) { - results[i] = psql_module.PQgetvalue(stmt->res, stmt->row, i); /* sanity check for internal error (NULL when invalid row) */ - results[i] = strdup(results[i] ? : ""); - if (lengths) lengths[i] = psql_module.PQgetlength(stmt->res, stmt->row, i); + s = psql_module.PQgetvalue(stmt->res, stmt->row, i) ? : ""; + s = psql_module.PQunescapeBytea(s, &len); + results[i] = strdup(s); + if (lengths) lengths[i] = len; } stmt->row++; -- 1.8.2.3