Skip to content

Commit

Permalink
Add special code to ensure a NULL value gets converted to None
Browse files Browse the repository at this point in the history
NOTE: this should really be done in lower levels
  • Loading branch information
strk committed Jan 9, 2020
1 parent 7acbc36 commit bb12bf2
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions python/plugins/db_manager/db_plugins/postgis/connector.py
Expand Up @@ -26,7 +26,12 @@

from functools import cmp_to_key

from qgis.PyQt.QtCore import QRegExp, QFile, QCoreApplication
from qgis.PyQt.QtCore import (
QRegExp,
QFile,
QCoreApplication,
QVariant
)
from qgis.core import (
Qgis,
QgsCredentials,
Expand Down Expand Up @@ -62,6 +67,21 @@ def __init__(self, connection, sql=None):
if (self.sql != None):
self._execute()

def _toStrResultSet(self, res):
#print("XXX type of QVariant(None) is " + str(type(QVariant(None))))
newres = []
for rec in res:
newrec = []
for col in rec:
#print("XXX col of rec of resultset valued " + str(col)+ " is typed " + str(type(col)))
if type(col) == type(QVariant(None)):

This comment has been minimized.

Copy link
@m-kuhn

m-kuhn May 5, 2020

Member

@strk can you remind me why this conversion is done again?

#print("XXX qvariant type of " + str(col)+ " is " + str(col.type))
if (str(col) == 'NULL'):
col = None
newrec.append(col)
newres.append(newrec)
return newres

def _execute(self, sql=None):
if self.sql == sql and self.result != None:
print ("XXX CursorProxy execute called with sql " + sql)
Expand All @@ -70,7 +90,7 @@ def _execute(self, sql=None):
self.sql = sql
if (self.sql == None):
return
self.result = self.connection._executeSql(self.sql)
self.result = self._toStrResultSet(self.connection._executeSql(self.sql))
self.description = []
if len(self.result):
for i in range(len(self.result)):
Expand Down

0 comments on commit bb12bf2

Please sign in to comment.