<div dir="ltr"><div>Hi,</div><div><br></div><div>Sorry for the long post, but I need some advice on the current API:</div><div><br></div><div>I'm working on a bugfix (<a href="https://github.com/qgis/QGIS/issues/33383">https://github.com/qgis/QGIS/issues/33383</a>) and (as sometimes happens) I just opened another can of worms, I'm currently testing the following providers:</div><div>- postgres</div><div>- spatialite</div><div>- ogr (spatialite opened with ogr provider)</div><div><br></div><div>and the following methods (dp is the QgsDataProvider instance):</div><div><br></div><div>dp.defaultValue(fieldIndex)</div><div>dp.defaultValueClause(fieldIndex)</div><div><br></div><div> 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:</div><div><br></div><div><a href="https://qgis.org/api/classQgsVectorDataProvider.html#ad2a51ae0b1928a179e258e7eba6d94a7">https://qgis.org/api/classQgsVectorDataProvider.html#ad2a51ae0b1928a179e258e7eba6d94a7</a></div><div><a href="https://qgis.org/api/classQgsVectorDataProvider.html#a8b8b1fe945ec289885d77f820c85f8b6">https://qgis.org/api/classQgsVectorDataProvider.html#a8b8b1fe945ec289885d77f820c85f8b6</a></div><div><br></div><div>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).<br></div><div><br></div><div>Questions:<br></div><div>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.</div><div><br></div><div>2. From the docs it seems that defaultValue() should return ONLY literal defaults and NOT functions, ::nextval and friends</div><div><br></div><div>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?</div><div><br></div><div>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.</div><div><br></div><div>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.<br></div><div><br></div><div>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.<br></div><div></div><div><br></div><div>I'd like to hear other developer's opinion before proceeding with a fix for the a.m. providers.</div><div></div><div></div><div></div><div><br></div><div>Thank you in advance!</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Alessandro Pasotti<br>w3:   <a href="http://www.itopen.it" target="_blank">www.itopen.it</a></div></div>