there is a SIP specification error https://github.com/qgis/QGIS/blob/release-2_18/python/core/qgsvectorlayer.sip#L492 should be QString &msgError /out/ );
that's the reason that error is not returned in the python side => I suppose SIP would change C++ api in: msg = saveStyleToDatabase( name, description, useAsDefault, uiFileContent) Luigi Pirelli ************************************************************************************************** * Boundless QGIS Support/Development: lpirelli AT boundlessgeo DOT com * LinkedIn: https://www.linkedin.com/in/luigipirelli * Stackexchange: http://gis.stackexchange.com/users/19667/luigi-pirelli * GitHub: https://github.com/luipir * Mastering QGIS 2nd Edition: * https://www.packtpub.com/big-data-and-business-intelligence/mastering-qgis-second-edition ************************************************************************************************** On 25 September 2017 at 16:21, kimaidou <[email protected]> wrote: > I have tried another method > > * first add default style into DB via UI -> it works > > * the use console to create a new, not default, style > msg = '' > layer.saveStyleToDatabase( "a new style", "some description", False, None, > msg ); > > It does not work (not new line created, and msg remains empty. No log in the > database, which means NO query has been sent (I have change postgresql > config to log all requests). > > But the following method works > layer.listStylesInDatabase() > > And a new line appears in the postgresql log > 2017-09-25 16:19:18.248 CEST [8984] mdouchin@qgis LOG: 00000: duration: > 0.217 ms statement: SELECT id,styleName,description FROM layer_styles WHERE > NOT (f_table_catalog='qgis' AND f_table_schema='sup' AND > f_table_name='geo_commune' AND f_geometry_column='geom') ORDER BY > update_time DESC > > It seems the method saveStyleToDatabase returns with no error, which can be > caused by 2 reasons > https://qgis.org/api/2.18/qgsvectorlayer_8cpp_source.html#l04347 > > 4369 this->exportNamedStyle( qmlDocument, msgError ); > 4370 if ( !msgError.isNull() ) > 4371 { > 4372 return; > 4373 } > 4374 qmlStyle = qmlDocument.toString(); > 4375 > 4376 this->exportSldStyle( sldDocument, msgError ); > 4377 if ( !msgError.isNull() ) > 4378 { > 4379 return; > 4380 } > > /me investigates > > 2017-09-25 15:50 GMT+02:00 Jorge Gustavo Pereira Bastos Rocha > <[email protected]>: >> >> Hi, >> >> It already happened to me. The first user to save a style became the owner >> of the table. No other users were able to write on the layer_style table, >> because there were DEFAULT PRIVILEGES defined. >> >> Can you check the postgrsql log to see if there is any problem related >> with permissions? >> >> Regards, >> >> Jorge Gustavo >> >> ________________________________________ >> De: QGIS-Developer [[email protected]] em nome de >> kimaidou [[email protected]] >> Enviado: 25 de Setembro de 2017 14:23 >> Para: Luigi Pirelli >> Cc: [email protected] >> Assunto: Re: [QGIS-Developer] pyqgis - layer.saveDefaultStyle() for >> PostGIS layers >> >> Hi, >> >> @ Tom : I really would like to trust QGIS method instead of managing >> manually different providers. >> >> @ Luigi >> No error message, even worse : i got a message telling everything went >> well ;) >> >> layer.saveDefaultStyle() >> (u'The style dbname=\'qgis\' host=localhost port=5432 user=\'mdouchin\' >> sslmode=disable key=\'ogc_fid\' estimatedmetadata=true srid=2154 >> type=MultiPolygon table="sup"."geo_commune" (geom) sql= was updated in the >> database.', True) >> >> But the line is not created in the layer_styles table. >> >> Michaƫl >> >> >> 2017-09-25 14:48 GMT+02:00 Luigi Pirelli >> <[email protected]<mailto:[email protected]>>: >> from the code: >> >> mLayer->saveStyleToDatabase and mLayer->saveDefaultStyle >> >> and in >> QString QgsMapLayer::saveDefaultStyle( bool & theResultFlag ) >> { >> return saveNamedStyle( styleURI(), theResultFlag ); >> } >> >> => seems you are doing correct. >> >> any log message? >> >> ****************************************** >> >> >> void QgsVectorLayerProperties::saveDefaultStyle_clicked() >> { >> apply(); >> QString errorMsg; >> if ( mLayer->dataProvider()->isSaveAndLoadStyleToDBSupported() ) >> { >> QMessageBox askToUser; >> askToUser.setText( tr( "Save default style to: " ) ); >> askToUser.setIcon( QMessageBox::Question ); >> askToUser.addButton( tr( "Cancel" ), QMessageBox::RejectRole ); >> askToUser.addButton( tr( "Local database" ), QMessageBox::NoRole ); >> askToUser.addButton( tr( "Datasource database" ), QMessageBox::YesRole >> ); >> >> switch ( askToUser.exec() ) >> { >> case 0: >> return; >> case 2: >> mLayer->saveStyleToDatabase( "", "", true, "", errorMsg ); >> if ( errorMsg.isNull() ) >> { >> return; >> } >> break; >> default: >> break; >> } >> } >> >> bool defaultSavedFlag = false; >> errorMsg = mLayer->saveDefaultStyle( defaultSavedFlag ); >> if ( !defaultSavedFlag ) >> { >> QMessageBox::warning( this, tr( "Default Style" ), errorMsg ); >> } >> } >> Luigi Pirelli >> >> >> ************************************************************************************************** >> * Boundless QGIS Support/Development: lpirelli AT boundlessgeo DOT com >> * LinkedIn: https://www.linkedin.com/in/luigipirelli >> * Stackexchange: http://gis.stackexchange.com/users/19667/luigi-pirelli >> * GitHub: https://github.com/luipir >> * Mastering QGIS 2nd Edition: >> * >> https://www.packtpub.com/big-data-and-business-intelligence/mastering-qgis-second-edition >> >> ************************************************************************************************** >> >> >> On 25 September 2017 at 13:44, Tom Chadwin >> <[email protected]<mailto:[email protected]>> wrote: >> > Perhaps you have to do it manually via a PostGIS query matching >> > f_table_catalog, f_table_schema, and f_table_name, and updating styleqml >> > and >> > stylesld? >> > >> > Tom >> > >> > >> > >> > ----- >> > Buy Pie Spy: Adventures in British pastry 2010-11 on Amazon >> > -- >> > Sent from: >> > http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-f4099106.html >> > _______________________________________________ >> > QGIS-Developer mailing list >> > [email protected]<mailto:[email protected]> >> > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer >> > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer >> > _______________________________________________ QGIS-Developer mailing list [email protected] List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
