[QGIS-Developer] Data provider default values and default value clause

Alessandro Pasotti apasotti at gmail.com
Fri Jan 24 01:28:39 PST 2020


Hi,

Sorry for the long post, but I need some advice on the current API:

I'm working on a bugfix (https://github.com/qgis/QGIS/issues/33383) and (as
sometimes happens) I just opened another can of worms, I'm currently
testing the following providers:
- postgres
- spatialite
- ogr (spatialite opened with ogr provider)

and the following methods (dp is the QgsDataProvider instance):

dp.defaultValue(fieldIndex)
dp.defaultValueClause(fieldIndex)

the behavior of the tested providers is totally different and before
attempting to homogenize them, I'd like to be sure about my understanding
of the expected behavior, the relevant docs are:

https://qgis.org/api/classQgsVectorDataProvider.html#ad2a51ae0b1928a179e258e7eba6d94a7
https://qgis.org/api/classQgsVectorDataProvider.html#a8b8b1fe945ec289885d77f820c85f8b6

Note that in case of a literal default value (like "123", "My default
text") the result of the two function calls in some (but not all) of the
current provider implementation may be the same (except for the returned
type).

Questions:
1. From the docs it seems that the defaultValueClause() should ONLY return
clauses (like sequences, functions, CURRENT_TIMESTAMP etc.) and should NOT
return literal defaults.

2. From the docs it seems that defaultValue() should return ONLY literal
defaults and NOT functions, ::nextval and friends

3. OGR provider does return the actual client-side calculated value when
calling defaultValue() ONLY in case of literal defaults and
CURRENT_TIMESTAMP, CURRENT_DATE and CURRENT_TIME, it returns the clause
definition in all other cases, is this correct?

4. postgres provider in case the property EvaluateDefaultValues is true
does something more and send the clause to the server for evaluation,
returning the calculated value, otherwise it returns the clause definition.

5. What to return in case of no defaults? Depending on provider and field
types, some implementations return a NULL (QVariant()), some others return
a Python None.

So, I'm confused about the expected behavior, if the documentation of
defaultValue() and defaultValueClause() is correct then the provider
implementations are (at least for some of them) wrong.

I'd like to hear other developer's opinion before proceeding with a fix for
the a.m. providers.

Thank you in advance!

-- 
Alessandro Pasotti
w3:   www.itopen.it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20200124/a55a2f45/attachment.html>


More information about the QGIS-Developer mailing list