[QGIS Commit] r14834 - trunk/qgis/src/providers/postgres

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Dec 3 12:20:14 EST 2010


Author: brushtyler
Date: 2010-12-03 09:20:14 -0800 (Fri, 03 Dec 2010)
New Revision: 14834

Modified:
   trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
Log:
fix adding features on geometryless tables


Modified: trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp
===================================================================
--- trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2010-12-03 16:12:29 UTC (rev 14833)
+++ trunk/qgis/src/providers/postgres/qgspostgresprovider.cpp	2010-12-03 17:20:14 UTC (rev 14834)
@@ -2265,16 +2265,19 @@
     connectionRW->PQexecNR( "BEGIN" );
 
     // Prepare the INSERT statement
-    QString insert = QString( "INSERT INTO %1(" ).arg( mQuery );
-    QString values;
+    QString insert = QString( "INSERT INTO %1 (" ).arg( mQuery );
+    QString values = ") VALUES (";
     QString delim = ",";
+    int offset = 1;
 
     if ( !geometryColumn.isNull() )
     {
       insert += quotedIdentifier( geometryColumn );
-      values = QString( ") VALUES (GeomFromWKB($1%1,%2)" )
-               .arg( connectionRW->useWkbHex() ? "" : "::bytea" )
-               .arg( srid );
+      values += QString( "GeomFromWKB($%1%2,%3)" )
+                .arg( offset )
+                .arg( connectionRW->useWkbHex() ? "" : "::bytea" )
+                .arg( srid );
+      offset += 1;
       delim = ",";
     }
     else
@@ -2282,17 +2285,13 @@
       delim = "";
     }
 
-    int offset;
     if ( primaryKeyType != "tid" && primaryKeyType != "oid" )
     {
       insert += delim + quotedIdentifier( primaryKey );
-      values += delim + "$2";
-      offset = 3;
+      values += delim + QString( "$%1" ).arg( offset );
+      offset += 1;
+      delim = ",";
     }
-    else
-    {
-      offset = 2;
-    }
 
     const QgsAttributeMap &attributevec = flist[0].attributeMap();
 
@@ -2393,12 +2392,15 @@
     {
       const QgsAttributeMap &attributevec = features->attributeMap();
 
-      QString geomParam;
-      appendGeomString( features->geometry(), geomParam );
-
       QStringList params;
-      params << geomParam;
+      if ( !geometryColumn.isNull() )
+      {
+        QString geomParam;
+        appendGeomString( features->geometry(), geomParam );
 
+        params << geomParam;
+      }
+
       if ( primaryKeyType != "tid" && primaryKeyType != "oid" )
       {
         int id = paramValue( primaryKeyDefault(), primaryKeyDefault() ).toInt();



More information about the QGIS-commit mailing list