Browse Source

vlib: fix Vect__execute_pg() to handle long SQL statements on failure

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@65131 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 10 years ago
parent
commit
0eea15a59a
1 changed files with 7 additions and 2 deletions
  1. 7 2
      lib/vector/Vlib/read_pg.c

+ 7 - 2
lib/vector/Vlib/read_pg.c

@@ -1505,9 +1505,14 @@ int Vect__execute_pg(PGconn * conn, const char *stmt)
     G_debug(3, "Vect__execute_pg(): %s", stmt);
     result = PQexec(conn, stmt);
     if (!result || PQresultStatus(result) != PGRES_COMMAND_OK) {
-        PQclear(result);
+        size_t stmt_len;
+        char stmt_prt[512];
         
-        G_warning(_("Execution failed: %s\nReason: %s"), stmt,
+        PQclear(result);
+        stmt_len = strlen(stmt);
+        strncpy(stmt_prt, stmt, stmt_len > 511 ? 511 : stmt_len);
+        stmt_prt[stmt_len > 511 ? 511 : stmt_len] = '\0';
+        G_warning(_("Execution failed: %s (...)\nReason: %s"), stmt_prt,
                   PQerrorMessage(conn));
         return -1;
     }