<div dir="ltr"><div><div><div><div><div><div>I have tried another method<br><br></div>* first add default style into DB via UI -> it works<br><br></div>* the use console to create a new, not default, style<br></div><div>msg = ''<br></div><div>layer.saveStyleToDatabase( "a new style", "some description", False, None, msg );<br><br></div>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).<br><br></div>But the following method works<br>layer.listStylesInDatabase()<br><br></div>And a new line appears in the postgresql log<br>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<br><br></div><div>It seems the method saveStyleToDatabase returns with no error, which can be caused by 2 reasons</div><div><a href="https://qgis.org/api/2.18/qgsvectorlayer_8cpp_source.html#l04347">https://qgis.org/api/2.18/qgsvectorlayer_8cpp_source.html#l04347</a></div><div><br></div><div> 4369   this->exportNamedStyle( qmlDocument, msgError );<br> 4370   if ( !msgError.isNull() )<br> 4371   {<br> 4372     return;<br> 4373   }<br> 4374   qmlStyle = qmlDocument.toString();<br> 4375 <br> 4376   this->exportSldStyle( sldDocument, msgError );<br> 4377   if ( !msgError.isNull() )<br> 4378   {<br> 4379     return;<br> 4380   }</div><div><br></div><div>/me investigates<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-09-25 15:50 GMT+02:00 Jorge Gustavo Pereira Bastos Rocha <span dir="ltr"><<a href="mailto:jgr@di.uminho.pt" target="_blank">jgr@di.uminho.pt</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
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.<br>
<br>
Can you check the postgrsql log to see if there is any problem related with permissions?<br>
<br>
Regards,<br>
<br>
Jorge Gustavo<br>
<br>
______________________________<wbr>__________<br>
De: QGIS-Developer [<a href="mailto:qgis-developer-bounces@lists.osgeo.org">qgis-developer-bounces@lists.<wbr>osgeo.org</a>] em nome de kimaidou [<a href="mailto:kimaidou@gmail.com">kimaidou@gmail.com</a>]<br>
Enviado: 25 de Setembro de 2017 14:23<br>
Para: Luigi Pirelli<br>
Cc: <a href="mailto:qgis-developer@lists.osgeo.org">qgis-developer@lists.osgeo.org</a><br>
Assunto: Re: [QGIS-Developer] pyqgis - layer.saveDefaultStyle() for PostGIS     layers<br>
<span class=""><br>
Hi,<br>
<br>
@ Tom : I really would like to trust QGIS method instead of managing manually different providers.<br>
<br>
@ Luigi<br>
No error message, even worse : i got a message telling everything went well ;)<br>
<br>
layer.saveDefaultStyle()<br>
(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)<br>
<br>
But the line is not created in the layer_styles table.<br>
<br>
Michaël<br>
<br>
<br>
</span>2017-09-25 14:48 GMT+02:00 Luigi Pirelli <<a href="mailto:luipir@gmail.com">luipir@gmail.com</a><mailto:<a href="mailto:luipir@gmail.com">luipi<wbr>r@gmail.com</a>>>:<br>
<div><div class="h5">from the code:<br>
<br>
mLayer->saveStyleToDatabase and mLayer->saveDefaultStyle<br>
<br>
and in<br>
QString QgsMapLayer::saveDefaultStyle( bool & theResultFlag )<br>
{<br>
  return saveNamedStyle( styleURI(), theResultFlag );<br>
}<br>
<br>
=> seems you are doing correct.<br>
<br>
any log message?<br>
<br>
******************************<wbr>************<br>
<br>
<br>
void QgsVectorLayerProperties::<wbr>saveDefaultStyle_clicked()<br>
{<br>
  apply();<br>
  QString errorMsg;<br>
  if ( mLayer->dataProvider()-><wbr>isSaveAndLoadStyleToDBSupporte<wbr>d() )<br>
  {<br>
    QMessageBox askToUser;<br>
    askToUser.setText( tr( "Save default style to: " ) );<br>
    askToUser.setIcon( QMessageBox::Question );<br>
    askToUser.addButton( tr( "Cancel" ), QMessageBox::RejectRole );<br>
    askToUser.addButton( tr( "Local database" ), QMessageBox::NoRole );<br>
    askToUser.addButton( tr( "Datasource database" ), QMessageBox::YesRole );<br>
<br>
    switch ( askToUser.exec() )<br>
    {<br>
      case 0:<br>
        return;<br>
      case 2:<br>
        mLayer->saveStyleToDatabase( "", "", true, "", errorMsg );<br>
        if ( errorMsg.isNull() )<br>
        {<br>
          return;<br>
        }<br>
        break;<br>
      default:<br>
        break;<br>
    }<br>
  }<br>
<br>
  bool defaultSavedFlag = false;<br>
  errorMsg = mLayer->saveDefaultStyle( defaultSavedFlag );<br>
  if ( !defaultSavedFlag )<br>
  {<br>
    QMessageBox::warning( this, tr( "Default Style" ), errorMsg );<br>
  }<br>
}<br>
Luigi Pirelli<br>
<br>
******************************<wbr>******************************<wbr>******************************<wbr>********<br>
* Boundless QGIS Support/Development: lpirelli AT boundlessgeo DOT com<br>
* LinkedIn: <a href="https://www.linkedin.com/in/luigipirelli" rel="noreferrer" target="_blank">https://www.linkedin.com/in/<wbr>luigipirelli</a><br>
* Stackexchange: <a href="http://gis.stackexchange.com/users/19667/luigi-pirelli" rel="noreferrer" target="_blank">http://gis.stackexchange.com/<wbr>users/19667/luigi-pirelli</a><br>
* GitHub: <a href="https://github.com/luipir" rel="noreferrer" target="_blank">https://github.com/luipir</a><br>
* Mastering QGIS 2nd Edition:<br>
* <a href="https://www.packtpub.com/big-data-and-business-intelligence/mastering-qgis-second-edition" rel="noreferrer" target="_blank">https://www.packtpub.com/big-<wbr>data-and-business-<wbr>intelligence/mastering-qgis-<wbr>second-edition</a><br>
******************************<wbr>******************************<wbr>******************************<wbr>********<br>
<br>
<br>
</div></div><span class="">On 25 September 2017 at 13:44, Tom Chadwin <<a href="mailto:tom.chadwin@nnpa.org.uk">tom.chadwin@nnpa.org.uk</a><<wbr>mailto:<a href="mailto:tom.chadwin@nnpa.org.uk">tom.chadwin@nnpa.org.uk</a><wbr>>> wrote:<br>
> Perhaps you have to do it manually via a PostGIS query matching<br>
> f_table_catalog, f_table_schema, and f_table_name, and updating styleqml and<br>
> stylesld?<br>
><br>
> Tom<br>
><br>
><br>
><br>
> -----<br>
> Buy Pie Spy: Adventures in British pastry 2010-11 on Amazon<br>
> --<br>
> Sent from: <a href="http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-f4099106.html" rel="noreferrer" target="_blank">http://osgeo-org.1560.x6.<wbr>nabble.com/QGIS-Developer-<wbr>f4099106.html</a><br>
> ______________________________<wbr>_________________<br>
> QGIS-Developer mailing list<br>
</span>> <a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><wbr><mailto:<a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.<wbr>osgeo.org</a>><br>
<div class="HOEnZb"><div class="h5">> List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
> Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
<br>
</div></div></blockquote></div><br></div>