- removed useless function getPrimaryKey since a member already exist

for that
- modified the test to have multiple column primary key (it fails for
  the moment
This commit is contained in:
vmora 2013-07-10 11:13:24 +02:00
parent b912256409
commit 184bf418ca
3 changed files with 2 additions and 41 deletions

View File

@ -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();
@ -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());
@ -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();
}

View File

@ -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

View File

@ -41,7 +41,7 @@ class TestQgsSpatialiteProvider(TestCase):
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)