26 QString QgsExecuteSpatialiteQueryAlgorithm::name()
const
28 return QStringLiteral(
"spatialiteexecutesql" );
31 QString QgsExecuteSpatialiteQueryAlgorithm::displayName()
const
33 return QObject::tr(
"SpatiaLite execute SQL" );
36 QStringList QgsExecuteSpatialiteQueryAlgorithm::tags()
const
38 return QObject::tr(
"database,sql,spatialite,execute" ).split(
',' );
41 QString QgsExecuteSpatialiteQueryAlgorithm::group()
const
43 return QObject::tr(
"Database" );
46 QString QgsExecuteSpatialiteQueryAlgorithm::groupId()
const
48 return QStringLiteral(
"database" );
51 QString QgsExecuteSpatialiteQueryAlgorithm::shortHelpString()
const
53 return QObject::tr(
"Executes a SQL command on a SpatiaLite database." );
56 QgsExecuteSpatialiteQueryAlgorithm *QgsExecuteSpatialiteQueryAlgorithm::createInstance()
const
58 return new QgsExecuteSpatialiteQueryAlgorithm();
61 void QgsExecuteSpatialiteQueryAlgorithm::initAlgorithm(
const QVariantMap & )
70 QgsVectorLayer *layer = parameterAsVectorLayer( parameters, QStringLiteral(
"DATABASE" ), context );
73 if ( uri.database().isEmpty() )
75 if ( databaseUri.contains( QStringLiteral(
"|layername" ), Qt::CaseInsensitive ) )
76 databaseUri = databaseUri.left( databaseUri.indexOf( QLatin1String(
"|layername" ) ) );
77 else if ( databaseUri.contains( QStringLiteral(
"|layerid" ), Qt::CaseInsensitive ) )
78 databaseUri = databaseUri.left( databaseUri.indexOf( QLatin1String(
"|layerid" ) ) );
80 uri =
QgsDataSourceUri( QStringLiteral(
"dbname='%1'" ).arg( databaseUri ) );
84 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn;
95 const QString sql = parameterAsString( parameters, QStringLiteral(
"SQL" ), context ).replace(
'\n',
' ' );
98 conn->executeSql( sql );
105 return QVariantMap();