diff options
| -rw-r--r-- | config/acx_libpq.m4 | 5 | ||||
| -rw-r--r-- | src/slon/dbutils.c | 9 | ||||
| -rw-r--r-- | src/slonik/dbutil.c | 12 |
3 files changed, 17 insertions, 9 deletions
diff --git a/config/acx_libpq.m4 b/config/acx_libpq.m4 index 47d4b679..7653357c 100644 --- a/config/acx_libpq.m4 +++ b/config/acx_libpq.m4 @@ -140,10 +140,9 @@ if test -n "$PG_CONFIG_LOCATION"; then PG_CONFIGURE=`$PG_CONFIG_LOCATION --configure` pg_config_version=`$PG_CONFIG_LOCATION --version` - PG_VERSION=`expr "$pg_config_version" : '[[^0-9]]*\([[0-9]]*\.[[0-9]]*\)'` - + PG_VERSION=`expr "$pg_config_version" : '[[^0-9]]*\([[0-9\.]]*\)'` AC_MSG_CHECKING(for correct version of PostgreSQL) - PG_VERSION_MAJOR=`echo $PG_VERSION | cut -d. -f1` + PG_VERSION_MAJOR=`echo $PG_VERSION | sed -e 's|\([[0-9]]*\)\(\.*.*\)|\1|'` PG_VERSION_MINOR=`echo $PG_VERSION | cut -d. -f2` if test "$PG_VERSION_MAJOR" = "7"; then AC_MSG_RESULT("error") diff --git a/src/slon/dbutils.c b/src/slon/dbutils.c index 726b4586..8450b44b 100644 --- a/src/slon/dbutils.c +++ b/src/slon/dbutils.c @@ -614,6 +614,7 @@ db_get_version(PGconn *conn) int major = 0; int minor = 0; int patch = 0; + int scanres=0; dstring_init(&query); slon_mkquery(&query, "SELECT version();"); @@ -624,8 +625,12 @@ db_get_version(PGconn *conn) PQclear(res); return -1; } - if (sscanf(PQgetvalue(res, 0, 0), "PostgreSQL %d.%d.%d", &major, &minor, &patch) < 2 && - sscanf(PQgetvalue(res, 0, 0), "EnterpriseDB %d.%d.%d", &major, &minor, &patch) < 2) + scanres=sscanf(PQgetvalue(res, 0, 0), "PostgreSQL %d.%d.%d", &major, &minor, &patch); + if(scanres < 1) + { + scanres=sscanf(PQgetvalue(res, 0, 0), "EnterpriseDB %d.%d.%d", &major, &minor, &patch); + } + if ( scanres < 1) { PQclear(res); return -1; diff --git a/src/slonik/dbutil.c b/src/slonik/dbutil.c index 8de5699a..a0f3151b 100644 --- a/src/slonik/dbutil.c +++ b/src/slonik/dbutil.c @@ -441,7 +441,8 @@ db_get_version(SlonikStmt * stmt, SlonikAdmInfo * adminfo) int minor = 0; int patch = 0; int version = 0; - + int scanres=0; + if (db_begin_xact(stmt, adminfo, false) < 0) return -1; @@ -452,9 +453,12 @@ db_get_version(SlonikStmt * stmt, SlonikAdmInfo * adminfo) if (res == NULL) return -1; - - if (sscanf(PQgetvalue(res, 0, 0), "PostgreSQL %d.%d.%d", &major, &minor, &patch) < 2 && - sscanf(PQgetvalue(res, 0, 0), "EnterpriseDB %d.%d.%d", &major, &minor, &patch) < 2) + scanres=sscanf(PQgetvalue(res, 0, 0), "PostgreSQL %d.%d.%d", &major, &minor, &patch); + if(scanres < 1) + { + scanres=sscanf(PQgetvalue(res, 0, 0), "EnterpriseDB %d.%d.%d", &major, &minor, &patch); + } + if ( scanres < 1) { fprintf(stderr, "%s:%d: failed to parse %s for DB version\n", stmt->stmt_filename, stmt->stmt_lno, |
