[GRASS-SVN] r51154 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Mar 23 11:59:00 EDT 2012


Author: martinl
Date: 2012-03-23 08:59:00 -0700 (Fri, 23 Mar 2012)
New Revision: 51154

Modified:
   grass/trunk/lib/vector/Vlib/close_pg.c
   grass/trunk/lib/vector/Vlib/read_pg.c
   grass/trunk/lib/vector/Vlib/rewind_pg.c
Log:
vlib(pg): fix some schema-related issues


Modified: grass/trunk/lib/vector/Vlib/close_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/close_pg.c	2012-03-23 14:52:57 UTC (rev 51153)
+++ grass/trunk/lib/vector/Vlib/close_pg.c	2012-03-23 15:59:00 UTC (rev 51154)
@@ -52,8 +52,8 @@
 	PQclear(pg_info->res);
 	pg_info->res = NULL;
 	
-	sprintf(stmt, "CLOSE %s%p",
-		pg_info->table_name, pg_info->conn);
+	sprintf(stmt, "CLOSE %s_%s%p",
+		pg_info->schema_name, pg_info->table_name, pg_info->conn);
 	if (execute(pg_info->conn, stmt) == -1) {
 	    G_warning(_("Unable to close cursor"));
 	    return -1;

Modified: grass/trunk/lib/vector/Vlib/read_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/read_pg.c	2012-03-23 14:52:57 UTC (rev 51153)
+++ grass/trunk/lib/vector/Vlib/read_pg.c	2012-03-23 15:59:00 UTC (rev 51154)
@@ -420,17 +420,17 @@
 	if (execute(pg_info->conn, "BEGIN") == -1)
 	    return -1;
 	
-	sprintf(stmt, "DECLARE %s%p CURSOR FOR SELECT %s FROM %s "
+	sprintf(stmt, "DECLARE %s_%s%p CURSOR FOR SELECT %s FROM \"%s\".\"%s\" "
 		"WHERE %s = %d",
-		pg_info->table_name, pg_info->conn, 
-		pg_info->geom_column, 
+		pg_info->schema_name, pg_info->table_name, pg_info->conn, 
+		pg_info->geom_column, pg_info->schema_name,
 		pg_info->table_name, pg_info->fid_column, fid);
 
 	if (execute(pg_info->conn, stmt) == -1)
 	    return -1;
     
-	sprintf(stmt, "FETCH ALL in %s%p", 
-		pg_info->table_name, pg_info->conn);
+	sprintf(stmt, "FETCH ALL in %s_%s%p", 
+		pg_info->schema_name, pg_info->table_name, pg_info->conn);
 	pg_info->res = PQexec(pg_info->conn, stmt);
 	pg_info->next_line = 0;
     }
@@ -447,9 +447,13 @@
 	char stmt[DB_SQL_MAX];
 	PQclear(pg_info->res);
 
-	sprintf(stmt, "FETCH %d in %s%p", CURSOR_PAGE,
-		pg_info->table_name, pg_info->conn);
+	sprintf(stmt, "FETCH %d in %s_%s%p", CURSOR_PAGE,
+		pg_info->schema_name, pg_info->table_name, pg_info->conn);
 	pg_info->res = PQexec(pg_info->conn, stmt);
+	if (!pg_info->res) {
+	    execute(pg_info->conn, "ROLLBACK");
+	    return -1;
+	}
 	pg_info->next_line = 0;
     }
 
@@ -459,9 +463,10 @@
 	    PQclear(pg_info->res);
 	    pg_info->res = NULL;
 	    
-	    sprintf(stmt, "CLOSE %s%p",
-		    pg_info->table_name, pg_info->conn);
+	    sprintf(stmt, "CLOSE %s_%s%p",
+		    pg_info->schema_name, pg_info->table_name, pg_info->conn);
 	    if (execute(pg_info->conn, stmt) == -1) {
+		execute(pg_info->conn, "ROLLBACK");
 		G_warning(_("Unable to close cursor"));
 		return -1;
 	    }
@@ -482,8 +487,8 @@
 	PQclear(pg_info->res);
 	pg_info->res = NULL;
 	
-	sprintf(stmt, "CLOSE %s%p",
-		pg_info->table_name, pg_info->conn);
+	sprintf(stmt, "CLOSE %s_%s%p",
+		pg_info->schema_name, pg_info->table_name, pg_info->conn);
 	if (execute(pg_info->conn, stmt) == -1) {
 	    G_warning(_("Unable to close cursor"));
 	    return -1;
@@ -1027,17 +1032,24 @@
     if (execute(pg_info->conn, "BEGIN") == -1)
 	return -1;
     
-    sprintf(stmt, "DECLARE %s%p CURSOR FOR SELECT %s,%s FROM %s",
-	    pg_info->table_name, pg_info->conn, 
+    sprintf(stmt, "DECLARE %s_%s%p CURSOR FOR SELECT %s,%s FROM \"%s\".\"%s\"",
+	    pg_info->schema_name, pg_info->table_name, pg_info->conn, 
 	    pg_info->geom_column, pg_info->fid_column,
-	    pg_info->table_name);
-
-    if (execute(pg_info->conn, stmt) == -1)
+	    pg_info->schema_name, pg_info->table_name);
+    G_debug(2, "SQL: %s", stmt);
+    
+    if (execute(pg_info->conn, stmt) == -1) {
+	execute(pg_info->conn, "ROLLBACK");
 	return -1;
+    }
     
-    sprintf(stmt, "FETCH %d in %s%p", CURSOR_PAGE,
-	    pg_info->table_name, pg_info->conn);
+    sprintf(stmt, "FETCH %d in %s_%s%p", CURSOR_PAGE,
+	    pg_info->schema_name, pg_info->table_name, pg_info->conn);
     pg_info->res = PQexec(pg_info->conn, stmt);
+    if (!pg_info->res) {
+	execute(pg_info->conn, "ROLLBACK");
+	return -1;
+    }
     pg_info->next_line = 0;
     
     return 0;

Modified: grass/trunk/lib/vector/Vlib/rewind_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/rewind_pg.c	2012-03-23 14:52:57 UTC (rev 51153)
+++ grass/trunk/lib/vector/Vlib/rewind_pg.c	2012-03-23 15:59:00 UTC (rev 51154)
@@ -52,8 +52,8 @@
 	PQclear(pg_info->res);
 	pg_info->res = NULL;
 	
-	sprintf(stmt, "CLOSE %s%p",
-		pg_info->table_name, pg_info->conn);
+	sprintf(stmt, "CLOSE %s_%s%p",
+		pg_info->schema_name, pg_info->table_name, pg_info->conn);
 	if (execute(pg_info->conn, stmt) == -1) {
 	    G_warning(_("Unable to close cursor"));
 	    return -1;



More information about the grass-commit mailing list