Skip to content

Commit

Permalink
- removed useless function getPrimaryKey since a member already exist
Browse files Browse the repository at this point in the history
  for that
- modified the test to have multiple column primary key (it fails for
  the moment
  • Loading branch information
vmora committed Jul 10, 2013
1 parent b912256 commit 184bf41
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 41 deletions.
37 changes: 1 addition & 36 deletions src/providers/spatialite/qgsspatialiteprovider.cpp
Expand Up @@ -3506,10 +3506,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
QString values;
QString separator;
int ia, ret;


const QString primaryKey = getPrimaryKey();

if ( flist.size() == 0 )
return true;
const QgsAttributes & attributevec = flist[0].attributes();
Expand Down Expand Up @@ -3609,7 +3606,7 @@ bool QgsSpatiaLiteProvider::addFeatures( QgsFeatureList & flist )
continue;

// replace primary key with NULL so that sqlite will generate one for us
if ( primaryKey == fieldname )
if ( mPrimaryKey == fieldname )
{
v = QVariant();
assert(v.toString().isEmpty());
Expand Down Expand Up @@ -5208,35 +5205,3 @@ QGISEXTERN bool deleteLayer( const QString& dbPath, const QString& tableName, QS
return true;
}

QString QgsSpatiaLiteProvider::getPrimaryKey()
{
char **results;
int rows;
int columns;
char *errMsg = NULL;
QString sql = QString( "PRAGMA table_info(%1)" ).arg( mQuery );

int ret = sqlite3_get_table( sqliteHandle, sql.toUtf8().constData(), &results, &rows, &columns, &errMsg );
if ( ret != SQLITE_OK )
{
QgsDebugMsg( "sqlite error: " + QString::fromUtf8( errMsg ) );
}

int pkColIdx=0;
for (; (pkColIdx < columns) && (QString("pk") != results[pkColIdx]) ; pkColIdx++){}
assert(pkColIdx<columns); // we must find it

int nameIdx=0;
for (; (nameIdx < columns) && (QString("name") != results[nameIdx]) ; nameIdx++){}
assert(nameIdx<columns); // we must find it

for (int r=0; r<rows; r++)
{
if ( QString("1") == results[r*columns + pkColIdx] )
{
return QString::fromUtf8( results[r*columns + nameIdx] );
}
}

return QString();
}
4 changes: 0 additions & 4 deletions src/providers/spatialite/qgsspatialiteprovider.h
Expand Up @@ -124,10 +124,6 @@ class QgsSpatiaLiteProvider: public QgsVectorDataProvider
*/
virtual void updateExtents();

/** * Get the name of the primary key for the layer
*/
QString getPrimaryKey();

/**
* Get the field information for the layer
* @return vector of QgsField objects
Expand Down
2 changes: 1 addition & 1 deletion tests/src/python/test_qgsspatialiteprovider.py
Expand Up @@ -41,7 +41,7 @@ def setUpClass(cls):
cur = con.cursor()
sql = "SELECT InitSpatialMetadata()"
cur.execute(sql)
sql = "CREATE TABLE test_pg (id INTEGER NOT NULL PRIMARY KEY, name TEXT NOT NULL)"
sql = "CREATE TABLE test_pg (id INTEGER NOT NULL, name TEXT NOT NULL, PRIMARY KEY (id, name))"
cur.execute(sql)
sql = "SELECT AddGeometryColumn('test_pg', 'geometry', 4326, 'POLYGON', 'XY')"
cur.execute(sql)
Expand Down

0 comments on commit 184bf41

Please sign in to comment.