86 changes: 29 additions & 57 deletions src/providers/spatialite/qgsspatialiteconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ bool QgsSpatiaLiteConnection::getTableInfoAbstractInterface( sqlite3 * handle, b
int rows;
int columns;
char *errMsg = NULL;
bool ok = false;
QString sql;
gaiaVectorLayersListPtr list;

Expand Down Expand Up @@ -344,7 +343,6 @@ bool QgsSpatiaLiteConnection::getTableInfoAbstractInterface( sqlite3 * handle, b
break;
};
mTables.append( TableEntry( tableName, column, type ) );
ok = true;

lyr = lyr->Next;
}
Expand All @@ -369,12 +367,11 @@ bool QgsSpatiaLiteConnection::getTableInfoAbstractInterface( sqlite3 * handle, b
QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
mTables.append( TableEntry( tableName, QString(), "qgis_table" ) );
}
ok = true;
}
sqlite3_free_table( results );
}

return ok;
return true;

error:
// unexpected IO error
Expand All @@ -396,7 +393,6 @@ bool QgsSpatiaLiteConnection::getTableInfo( sqlite3 * handle, bool loadGeometryl
int rows;
int columns;
char *errMsg = NULL;
bool ok = false;
QString sql;

// the following query return the tables containing a Geometry column
Expand All @@ -405,23 +401,17 @@ bool QgsSpatiaLiteConnection::getTableInfo( sqlite3 * handle, bool loadGeometryl
ret = sqlite3_get_table( handle, sql.toUtf8(), &results, &rows, &columns, &errMsg );
if ( ret != SQLITE_OK )
goto error;
if ( rows < 1 )
;
else
for ( i = 1; i <= rows; i++ )
{
for ( i = 1; i <= rows; i++ )
{
if ( isRasterlite1Datasource( handle, results[( i * columns ) + 0] ) )
continue;
QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
QString column = QString::fromUtf8( results[( i * columns ) + 1] );
QString type = results[( i * columns ) + 2];
if ( isDeclaredHidden( handle, tableName, column ) )
continue;

mTables.append( TableEntry( tableName, column, type ) );
}
ok = true;
if ( isRasterlite1Datasource( handle, results[( i * columns ) + 0] ) )
continue;
QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
QString column = QString::fromUtf8( results[( i * columns ) + 1] );
QString type = results[( i * columns ) + 2];
if ( isDeclaredHidden( handle, tableName, column ) )
continue;

mTables.append( TableEntry( tableName, column, type ) );
}
sqlite3_free_table( results );

Expand All @@ -434,21 +424,15 @@ bool QgsSpatiaLiteConnection::getTableInfo( sqlite3 * handle, bool loadGeometryl
ret = sqlite3_get_table( handle, sql.toUtf8(), &results, &rows, &columns, &errMsg );
if ( ret != SQLITE_OK )
goto error;
if ( rows < 1 )
;
else
for ( i = 1; i <= rows; i++ )
{
for ( i = 1; i <= rows; i++ )
{
QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
QString column = QString::fromUtf8( results[( i * columns ) + 1] );
QString type = results[( i * columns ) + 2];
if ( isDeclaredHidden( handle, tableName, column ) )
continue;
QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
QString column = QString::fromUtf8( results[( i * columns ) + 1] );
QString type = results[( i * columns ) + 2];
if ( isDeclaredHidden( handle, tableName, column ) )
continue;

mTables.append( TableEntry( tableName, column, type ) );
}
ok = true;
mTables.append( TableEntry( tableName, column, type ) );
}
sqlite3_free_table( results );
}
Expand All @@ -461,21 +445,15 @@ bool QgsSpatiaLiteConnection::getTableInfo( sqlite3 * handle, bool loadGeometryl
ret = sqlite3_get_table( handle, sql.toUtf8(), &results, &rows, &columns, &errMsg );
if ( ret != SQLITE_OK )
goto error;
if ( rows < 1 )
;
else
for ( i = 1; i <= rows; i++ )
{
for ( i = 1; i <= rows; i++ )
{
QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
QString column = QString::fromUtf8( results[( i * columns ) + 1] );
QString type = results[( i * columns ) + 2];
if ( isDeclaredHidden( handle, tableName, column ) )
continue;
QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
QString column = QString::fromUtf8( results[( i * columns ) + 1] );
QString type = results[( i * columns ) + 2];
if ( isDeclaredHidden( handle, tableName, column ) )
continue;

mTables.append( TableEntry( tableName, column, type ) );
}
ok = true;
mTables.append( TableEntry( tableName, column, type ) );
}
sqlite3_free_table( results );
}
Expand All @@ -489,21 +467,15 @@ bool QgsSpatiaLiteConnection::getTableInfo( sqlite3 * handle, bool loadGeometryl
ret = sqlite3_get_table( handle, sql.toUtf8(), &results, &rows, &columns, &errMsg );
if ( ret != SQLITE_OK )
goto error;
if ( rows < 1 )
;
else
for ( i = 1; i <= rows; i++ )
{
for ( i = 1; i <= rows; i++ )
{
QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
mTables.append( TableEntry( tableName, QString(), "qgis_table" ) );
}
ok = true;
QString tableName = QString::fromUtf8( results[( i * columns ) + 0] );
mTables.append( TableEntry( tableName, QString(), "qgis_table" ) );
}
sqlite3_free_table( results );
}

return ok;
return true;

error:
// unexpected IO error
Expand Down
3 changes: 2 additions & 1 deletion src/providers/spatialite/qgsspatialiteconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class QgsSpatiaLiteConnection : public QObject
/**Checks if geometry_columns and spatial_ref_sys exist and have expected layout*/
int checkHasMetadataTables( sqlite3* handle );

/**Inserts information about the spatial tables into mTables*/
/**Inserts information about the spatial tables into mTables
@return true if querying of tables was successful, false on error */
bool getTableInfo( sqlite3 * handle, bool loadGeometrylessTables );

#ifdef SPATIALITE_VERSION_GE_4_0_0
Expand Down
5 changes: 2 additions & 3 deletions tests/src/analysis/testopenstreetmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ void TestOpenStreetMap::download()
QgsRectangle rect( 7.148, 51.249, 7.152, 51.251 );

// start download
OSMDownload download;
download.setQuery( OSMDownload::queryFromRect( rect ) );
QgsOSMDownload download;
download.setQuery( QgsOSMDownload::queryFromRect( rect ) );
download.setOutputFileName( "/tmp/dl-test.osm" );
bool res = download.start();
QVERIFY( res );
Expand All @@ -96,7 +96,6 @@ void TestOpenStreetMap::download()
void TestOpenStreetMap::importAndQueries()
{
QString dbFilename = "/tmp/testdata.db";
//QString xmlFilename = "/tmp/130127_023233_downloaded.osm";
QString xmlFilename = TEST_DATA_DIR "/openstreetmap/testdata.xml";

QgsOSMXmlImport import( xmlFilename, dbFilename );
Expand Down