Skip to content

Commit

Permalink
implement #2676
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13359 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 24, 2010
1 parent 6f92e7b commit f6473c3
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/plugins/spit/qgsshapefile.cpp
Expand Up @@ -291,7 +291,7 @@ bool QgsShapeFile::insertLayer( QString dbname, QString schema, QString primary_
import_canceled = false;
bool result = true;

QString query = QString( "CREATE TABLE %1.%2(%3 int4 PRIMARY KEY" )
QString query = QString( "CREATE TABLE %1.%2(%3 SERIAL PRIMARY KEY" )
.arg( QgsPgUtil::quotedIdentifier( schema ) )
.arg( QgsPgUtil::quotedIdentifier( table_name ) )
.arg( QgsPgUtil::quotedIdentifier( primary_key ) );
Expand Down Expand Up @@ -397,10 +397,10 @@ bool QgsShapeFile::insertLayer( QString dbname, QString schema, QString primary_
OGRGeometryH geom = OGR_F_GetGeometryRef( feat );
if ( geom )
{
query = QString( "INSERT INTO %1.%2 VALUES(%3" )
query = QString( "INSERT INTO %1.%2(" )
.arg( QgsPgUtil::quotedIdentifier( schema ) )
.arg( QgsPgUtil::quotedIdentifier( table_name ) )
.arg( m );
.arg( QgsPgUtil::quotedIdentifier( table_name ) );
QString values = " VALUES (";

char *geo_temp;
// 'GeometryFromText' supports only 2D coordinates
Expand All @@ -426,11 +426,20 @@ bool QgsShapeFile::insertLayer( QString dbname, QString schema, QString primary_
else
val = QgsPgUtil::quotedValue( val );

query += "," + val;
if ( n > 0 )
{
query += ",";
values += ",";
}
query += QgsPgUtil::quotedIdentifier( column_names[n] );
values += val;
}
query += QString( ",GeometryFromText(%1,%2))" )
.arg( QgsPgUtil::quotedValue( geometry ) )
.arg( srid );
query += "," + QgsPgUtil::quotedIdentifier( geom_col );
values += QString( ",GeometryFromText(%1,%2)" )
.arg( QgsPgUtil::quotedValue( geometry ) )
.arg( srid );

query += ")" + values + ")";

if ( result )
res = PQexec( conn, query.toUtf8() );
Expand Down

0 comments on commit f6473c3

Please sign in to comment.