mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-09 00:35:20 -05:00
Merge pull request #5483 from m-kuhn/postgisEmptyValue
[postgres] Distinguish empty and NULL values
This commit is contained in:
commit
29e8990ec1
@ -2050,7 +2050,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist, Flags flags )
|
|||||||
|
|
||||||
if ( i == flist.size() )
|
if ( i == flist.size() )
|
||||||
{
|
{
|
||||||
if ( v == defVal )
|
if ( v == defVal && defVal.isNull() == v.isNull() )
|
||||||
{
|
{
|
||||||
if ( defVal.isNull() )
|
if ( defVal.isNull() )
|
||||||
{
|
{
|
||||||
|
@ -303,6 +303,32 @@ class TestPyQgsPostgresProvider(unittest.TestCase, ProviderTestCase):
|
|||||||
self.assertNotEqual(f[0]['obj_id'], NULL, f[0].attributes())
|
self.assertNotEqual(f[0]['obj_id'], NULL, f[0].attributes())
|
||||||
vl.deleteFeatures([f[0].id()])
|
vl.deleteFeatures([f[0].id()])
|
||||||
|
|
||||||
|
def testNull(self):
|
||||||
|
"""
|
||||||
|
Asserts that 0, '' and NULL are treated as different values on insert
|
||||||
|
"""
|
||||||
|
vl = QgsVectorLayer(self.dbconn + ' sslmode=disable key=\'gid\' table="qgis_test"."constraints" sql=', 'test1', 'postgres')
|
||||||
|
self.assertTrue(vl.isValid())
|
||||||
|
QgsProject.instance().addMapLayer(vl)
|
||||||
|
tg = QgsTransactionGroup()
|
||||||
|
tg.addLayer(vl)
|
||||||
|
vl.startEditing()
|
||||||
|
|
||||||
|
def onError(message):
|
||||||
|
"""We should not get here. If we do, fail and say why"""
|
||||||
|
self.assertFalse(True, message)
|
||||||
|
|
||||||
|
vl.raiseError.connect(onError)
|
||||||
|
|
||||||
|
f = QgsFeature(vl.fields())
|
||||||
|
f['gid'] = 100
|
||||||
|
f['val'] = 0
|
||||||
|
f['name'] = ''
|
||||||
|
self.assertTrue(vl.addFeature(f))
|
||||||
|
feature = next(vl.getFeatures('"gid" = 100'))
|
||||||
|
self.assertEqual(f['val'], feature['val'])
|
||||||
|
self.assertEqual(f['name'], feature['name'])
|
||||||
|
|
||||||
def testNestedInsert(self):
|
def testNestedInsert(self):
|
||||||
tg = QgsTransactionGroup()
|
tg = QgsTransactionGroup()
|
||||||
tg.addLayer(self.vl)
|
tg.addLayer(self.vl)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user