Skip to content

Commit

Permalink
Use member functions over sqlite3 api
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 15, 2017
1 parent 716ed6b commit 124f3df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/app/qgsnewspatialitelayerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void QgsNewSpatialiteLayerDialog::pbnFindSRID_clicked()
// get the first row of the result set
while ( sqlite3_step( statement.get() ) == SQLITE_ROW )
{
myCRSs.insert( QString::fromUtf8( ( const char * )sqlite3_column_text( statement.get(), 0 ) ) );
myCRSs.insert( statement.columnAsText( 0 ) );
}
}
else
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,7 @@ QString QgsMapLayer::saveNamedStyle( const QString &uri, bool &resultFlag )
QByteArray param1 = qml.toUtf8();

QString mySql = QStringLiteral( "create table if not exists tbl_styles(style varchar primary key,qml varchar)" );
database.prepare( mySql, myResult );
statement = database.prepare( mySql, myResult );
if ( myResult == SQLITE_OK )
{
if ( sqlite3_step( statement.get() ) != SQLITE_DONE )
Expand All @@ -1368,7 +1368,7 @@ QString QgsMapLayer::saveNamedStyle( const QString &uri, bool &resultFlag )
}

mySql = QStringLiteral( "insert into tbl_styles(style,qml) values (?,?)" );
database.prepare( mySql, myResult );
statement = database.prepare( mySql, myResult );
if ( myResult == SQLITE_OK )
{
if ( sqlite3_bind_text( statement.get(), 1, param0.data(), param0.length(), SQLITE_STATIC ) == SQLITE_OK &&
Expand All @@ -1383,7 +1383,7 @@ QString QgsMapLayer::saveNamedStyle( const QString &uri, bool &resultFlag )
if ( !resultFlag )
{
QString mySql = QStringLiteral( "update tbl_styles set qml=? where style=?" );
database.prepare( mySql, myResult );
statement = database.prepare( mySql, myResult );

if ( myResult == SQLITE_OK )
{
Expand Down
30 changes: 15 additions & 15 deletions src/core/symbology/qgsstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,8 +373,8 @@ bool QgsStyle::load( const QString &filename )
while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
QDomDocument doc;
QString symbol_name = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), SymbolName ) ) );
QString xmlstring = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), SymbolXML ) ) );
QString symbol_name = statement.columnAsText( SymbolName );
QString xmlstring = statement.columnAsText( SymbolXML );
if ( !doc.setContent( xmlstring ) )
{
QgsDebugMsg( "Cannot open symbol " + symbol_name );
Expand All @@ -392,8 +392,8 @@ bool QgsStyle::load( const QString &filename )
while ( rc == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
QDomDocument doc;
QString ramp_name = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), ColorrampName ) ) );
QString xmlstring = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), ColorrampXML ) ) );
QString ramp_name = statement.columnAsText( ColorrampName );
QString xmlstring = statement.columnAsText( ColorrampXML );
if ( !doc.setContent( xmlstring ) )
{
QgsDebugMsg( "Cannot open symbol " + ramp_name );
Expand Down Expand Up @@ -547,7 +547,7 @@ QStringList QgsStyle::symbolsOfFavorite( StyleEntity type ) const
QStringList symbols;
while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
symbols << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
symbols << statement.columnAsText( 0 );
}

return symbols;
Expand Down Expand Up @@ -636,7 +636,7 @@ QStringList QgsStyle::tags() const
QStringList tagList;
while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
tagList << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
tagList << statement.columnAsText( 0 );
}

return tagList;
Expand Down Expand Up @@ -803,7 +803,7 @@ QStringList QgsStyle::findSymbols( StyleEntity type, const QString &qword )
QSet< QString > symbols;
while ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
symbols << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
symbols << statement.columnAsText( 0 );
}

// next add symbols with matching tags
Expand Down Expand Up @@ -1076,7 +1076,7 @@ QString QgsStyle::tag( int id ) const
QString tag;
if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
tag = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
tag = statement.columnAsText( 0 );
}

return tag;
Expand Down Expand Up @@ -1108,7 +1108,7 @@ QString QgsStyle::getName( const QString &table, int id ) const
QString name;
if ( nErr == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
name = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
name = statement.columnAsText( 0 );
}

return name;
Expand Down Expand Up @@ -1191,12 +1191,12 @@ QgsSymbolGroupMap QgsStyle::smartgroupsListMap()
// Now run the query and retrieve the group names
sqlite3_statement_unique_ptr statement;
int nError;
mCurrentDB.prepare( query, nError );
statement = mCurrentDB.prepare( query, nError );

QgsSymbolGroupMap groupNames;
while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
QString group = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), SmartgroupName ) ) );
QString group = statement.columnAsText( SmartgroupName );
groupNames.insert( sqlite3_column_int( statement.get(), SmartgroupId ), group );
}

Expand All @@ -1221,7 +1221,7 @@ QStringList QgsStyle::smartgroupNames()
QStringList groups;
while ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
groups << QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
groups << statement.columnAsText( 0 );
}

return groups;
Expand All @@ -1242,7 +1242,7 @@ QStringList QgsStyle::symbolsOfSmartgroup( StyleEntity type, int id )
else
{
QDomDocument doc;
QString xmlstr = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
QString xmlstr = statement.columnAsText( 0 );
if ( !doc.setContent( xmlstr ) )
{
QgsDebugMsg( QString( "Cannot open smartgroup id: %1" ).arg( id ) );
Expand Down Expand Up @@ -1341,7 +1341,7 @@ QgsSmartConditionMap QgsStyle::smartgroup( int id )
if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
QDomDocument doc;
QString xmlstr = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
QString xmlstr = statement.columnAsText( 0 );
if ( !doc.setContent( xmlstr ) )
{
QgsDebugMsg( QString( "Cannot open smartgroup id: %1" ).arg( id ) );
Expand Down Expand Up @@ -1381,7 +1381,7 @@ QString QgsStyle::smartgroupOperator( int id )
if ( nError == SQLITE_OK && sqlite3_step( statement.get() ) == SQLITE_ROW )
{
QDomDocument doc;
QString xmlstr = QString::fromUtf8( reinterpret_cast< const char * >( sqlite3_column_text( statement.get(), 0 ) ) );
QString xmlstr = statement.columnAsText( 0 );
if ( !doc.setContent( xmlstr ) )
{
QgsDebugMsg( QString( "Cannot open smartgroup id: %1" ).arg( id ) );
Expand Down

0 comments on commit 124f3df

Please sign in to comment.