<div dir="ltr">For your information, with the big hint from Matthias in the last email, it's now fixed in 2.18.20. I checked in QGIS 3, it was working fine already.<br></div><div class="gmail_extra"><br><div class="gmail_quote">2017-09-26 9:07 GMT-04:00 Matthias Kuhn <span dir="ltr"><<a href="mailto:matthias@opengis.ch" target="_blank">matthias@opengis.ch</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">For 2.18 it should be ok to make it /InOut/ (there was no return value<br>
before, so it shouldn't break anything).<br>
For 3.0 this can be made /Out/ as proposed.<br>
<span class="HOEnZb"><font color="#888888"><br>
Matthias<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On 09/26/2017 12:06 PM, Luigi Pirelli wrote:<br>
> there is a SIP specification error<br>
> <a href="https://github.com/qgis/QGIS/blob/release-2_18/python/core/qgsvectorlayer.sip#L492" rel="noreferrer" target="_blank">https://github.com/qgis/QGIS/<wbr>blob/release-2_18/python/core/<wbr>qgsvectorlayer.sip#L492</a><br>
> should be  QString &msgError /out/ );<br>
> <br>
> that's the reason that error is not returned in the python side => I<br>
> suppose SIP would change C++ api in:<br>
> msg = saveStyleToDatabase( name, description, useAsDefault, uiFileContent)<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>
> On 25 September 2017 at 16:21, kimaidou <<a href="mailto:kimaidou@gmail.com">kimaidou@gmail.com</a>> wrote:<br>
>> I have tried another method<br>
>><br>
>> * first add default style into DB via UI -> it works<br>
>><br>
>> * the use console to create a new, not default, style<br>
>> msg = ''<br>
>> layer.saveStyleToDatabase( "a new style", "some description", False, None,<br>
>> msg );<br>
>><br>
>> It does not work (not new line created, and msg remains empty. No log in the<br>
>> database, which means NO query has been sent (I have change postgresql<br>
>> config to log all requests).<br>
>><br>
>> But the following method works<br>
>> layer.listStylesInDatabase()<br>
>><br>
>> And a new line appears in the postgresql log<br>
>> 2017-09-25 16:19:18.248 CEST [8984] mdouchin@qgis LOG:  00000: duration:<br>
>> 0.217 ms  statement: SELECT id,styleName,description FROM layer_styles WHERE<br>
>> NOT (f_table_catalog='qgis' AND f_table_schema='sup' AND<br>
>> f_table_name='geo_commune' AND f_geometry_column='geom') ORDER BY<br>
>> update_time DESC<br>
>><br>
>> It seems the method saveStyleToDatabase returns with no error, which can be<br>
>> caused by 2 reasons<br>
>> <a href="https://qgis.org/api/2.18/qgsvectorlayer_8cpp_source.html#l04347" rel="noreferrer" target="_blank">https://qgis.org/api/2.18/<wbr>qgsvectorlayer_8cpp_source.<wbr>html#l04347</a><br>
>><br>
>>  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   }<br>
>><br>
>> /me investigates<br>
>><br>
>> 2017-09-25 15:50 GMT+02:00 Jorge Gustavo Pereira Bastos Rocha<br>
>> <<a href="mailto:jgr@di.uminho.pt">jgr@di.uminho.pt</a>>:<br>
>>><br>
>>> Hi,<br>
>>><br>
>>> It already happened to me. The first user to save a style became the owner<br>
>>> of the table. No other users were able to write on the layer_style table,<br>
>>> because there were DEFAULT PRIVILEGES defined.<br>
>>><br>
>>> Can you check the postgrsql log to see if there is any problem related<br>
>>> 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<br>
>>> 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<br>
>>> PostGIS     layers<br>
>>><br>
>>> Hi,<br>
>>><br>
>>> @ Tom : I really would like to trust QGIS method instead of managing<br>
>>> manually different providers.<br>
>>><br>
>>> @ Luigi<br>
>>> No error message, even worse : i got a message telling everything went<br>
>>> well ;)<br>
>>><br>
>>> layer.saveDefaultStyle()<br>
>>> (u'The style dbname=\'qgis\' host=localhost port=5432 user=\'mdouchin\'<br>
>>> sslmode=disable key=\'ogc_fid\' estimatedmetadata=true srid=2154<br>
>>> type=MultiPolygon table="sup"."geo_commune" (geom) sql= was updated in the<br>
>>> database.', True)<br>
>>><br>
>>> But the line is not created in the layer_styles table.<br>
>>><br>
>>> Michaël<br>
>>><br>
>>><br>
>>> 2017-09-25 14:48 GMT+02:00 Luigi Pirelli<br>
>>> <<a href="mailto:luipir@gmail.com">luipir@gmail.com</a><mailto:<a href="mailto:luipir@gmail.com">luipi<wbr>r@gmail.com</a>>>:<br>
>>> 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>
>>><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>
>>><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>
>>> *<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>
>>><br>
>>> ******************************<wbr>******************************<wbr>******************************<wbr>********<br>
>>><br>
>>><br>
>>> On 25 September 2017 at 13:44, Tom Chadwin<br>
>>> <<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<br>
>>>> 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:<br>
>>>> <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>
>>>> <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>
>>>> 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>
>><br>
> ______________________________<wbr>_________________<br>
> QGIS-Developer mailing list<br>
> <a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br>
> 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>
______________________________<wbr>_________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br>
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></div></div></blockquote></div><br></div>