Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgis provider: a styles in layer_style with useasdefault set to false are used as default style #18933

Open
qgib opened this issue Jun 10, 2014 · 5 comments

Comments

@qgib
Copy link
Contributor

qgib commented Jun 10, 2014

Author Name: Gabriele Monfardini (@gabrimonfa)
Original Redmine Issue: 10523

Redmine category:data_provider/postgis


I have a postgis layer with several styles saved in table public.layer_styles.
All styles have useasdefault set to false (these styles only makes sense within some projects, should not be used as default styles).

Obtained results

When I open the layer without any project, one of the styles is applied, in particular the one with update_time more recent.

Expected results

When I open the layer without any project, no style is applied

Discussion

The exact query that finds the default style is in ~qgis/src/providers/postgres/qgspostgresprovider.cpp, line 3464

  QString selectQmlQuery = QString( "SELECT styleQML"
                                    " FROM layer_styles"
                                    " WHERE f_table_catalog=%1"
                                    " AND f_table_schema=%2"
                                    " AND f_table_name=%3"
                                    " AND f_geometry_column=%4"
                                    " ORDER BY CASE WHEN useAsDefault THEN 1 ELSE 2 END"
                                    ",update_time DESC LIMIT 1" )

In my opinion rows with useasdefault set to false should be completely filtered out by the query.

If all styles have useasdefault set to false, current query retrieves the most recent style while I think that no rows should be retrieved in this case and a "random color" style be applied.

Thus I propose to change the query to:

  QString selectQmlQuery = QString( "SELECT styleQML"
                                    " FROM layer_styles"
                                    " WHERE f_table_catalog=%1"
                                    " AND f_table_schema=%2"
                                    " AND f_table_name=%3"
                                    " AND f_geometry_column=%4"
                                    " WHERE useAsDefault"
                                    " ORDER BY update_time DESC LIMIT 1" )


@qgib
Copy link
Contributor Author

qgib commented Jun 10, 2014

Author Name: Gabriele Monfardini (@gabrimonfa)


  • 7400 was configured as 10523.patch

  • 10523.patch (Gabriele Monfardini) - Patch that modify the query that search for a default style to apply

@qgib
Copy link
Contributor Author

qgib commented Jun 10, 2014

Author Name: Giovanni Manghi (@gioman)


better propose a patch as a pul request on qgis github repository, here it will probably not seen/reviewed by devs.

@qgib
Copy link
Contributor Author

qgib commented Jun 21, 2014

Author Name: Jürgen Fischer (@jef-n)


  • category_id was configured as Data Provider/PostGIS

@qgib
Copy link
Contributor Author

qgib commented Jun 21, 2014

Author Name: Jürgen Fischer (@jef-n)


There are two order criteria - first useDefault, second update_time. So the style with default comes first and the reset is ordered by update_time - that means if there is no style with useDefault the most current non-default style is taken. IMHO that's no bug - although the other behavior also makes sense.


  • tracker_id was changed from 1 to 2

@qgib
Copy link
Contributor Author

qgib commented Apr 30, 2017

Author Name: Giovanni Manghi (@gioman)


  • easy_fix was configured as 0

@qgib qgib added Feature Request Data Provider Related to specific vector, raster or mesh data providers labels May 25, 2019
@alexbruy alexbruy added PostGIS data provider Styles and removed Data Provider Related to specific vector, raster or mesh data providers labels Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants