Add support for PG10
authorSteve Singer <steve@ssinger.info>
Mon, 10 Jul 2017 02:00:12 +0000 (22:00 -0400)
committerSteve Singer <steve@ssinger.info>
Mon, 10 Jul 2017 02:00:12 +0000 (22:00 -0400)
PostgreSQL 10 does away with the old convention of $MAJOR.$MINOR.$PATCH

The existing version detection parsing code does not deal with the new
convention. Update the configure check, the slonik check and the slon check
to work with the new convention and continue to work with the old one.

config/acx_libpq.m4
src/slon/dbutils.c
src/slonik/dbutil.c

index 47d4b6791e093aee531f3b7d85f95fb90a11ad42..7653357c0a731e36ec637df5ab378832d9279c19 100644 (file)
@@ -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")
index 726b45869caf76a972ef2b9950bcb7e473b5ab54..8450b44b660d6d273ff26a3e2f2d886bab14f35f 100644 (file)
@@ -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;
index 8de5699a1a4f7c9034d480e1983923257778dd8d..a0f3151bfe6c05ba085981e0b0ffced75763753e 100644 (file)
@@ -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,