25 QString QgsExecuteSpatialiteQueryAlgorithm::name()
const
27 return QStringLiteral(
"spatialiteexecutesql" );
30 QString QgsExecuteSpatialiteQueryAlgorithm::displayName()
const
32 return QObject::tr(
"SpatiaLite execute SQL" );
35 QStringList QgsExecuteSpatialiteQueryAlgorithm::tags()
const
37 return QObject::tr(
"database,sql,spatialite,execute" ).split(
',' );
40 QString QgsExecuteSpatialiteQueryAlgorithm::group()
const
42 return QObject::tr(
"Database" );
45 QString QgsExecuteSpatialiteQueryAlgorithm::groupId()
const
47 return QStringLiteral(
"database" );
50 QString QgsExecuteSpatialiteQueryAlgorithm::shortHelpString()
const
52 return QObject::tr(
"Executes a SQL command on a SpatiaLite database." );
55 QgsExecuteSpatialiteQueryAlgorithm *QgsExecuteSpatialiteQueryAlgorithm::createInstance()
const
57 return new QgsExecuteSpatialiteQueryAlgorithm();
60 void QgsExecuteSpatialiteQueryAlgorithm::initAlgorithm(
const QVariantMap & )
69 QgsVectorLayer *layer = parameterAsVectorLayer( parameters, QStringLiteral(
"DATABASE" ), context );
72 if ( uri.database().isEmpty() )
74 if ( databaseUri.contains( QStringLiteral(
"|layername" ), Qt::CaseInsensitive ) )
75 databaseUri = databaseUri.left( databaseUri.indexOf( QLatin1String(
"|layername" ) ) );
76 else if ( databaseUri.contains( QStringLiteral(
"|layerid" ), Qt::CaseInsensitive ) )
77 databaseUri = databaseUri.left( databaseUri.indexOf( QLatin1String(
"|layerid" ) ) );
79 uri =
QgsDataSourceUri( QStringLiteral(
"dbname='%1'" ).arg( databaseUri ) );
83 std::unique_ptr<QgsAbstractDatabaseProviderConnection> conn;
94 QString sql = parameterAsString( parameters, QStringLiteral(
"SQL" ), context ).replace(
'\n',
' ' );
97 conn->executeSql( sql );
104 return QVariantMap();