Skip to content

Commit

Permalink
[db manager] python3 support (#3512)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn authored and m-kuhn committed Sep 20, 2016
1 parent 1da2474 commit cd1d44b
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
6 changes: 3 additions & 3 deletions python/plugins/db_manager/db_plugins/connector.py
Expand Up @@ -175,7 +175,7 @@ def _get_cursor_columns(self, c):

@classmethod
def quoteId(self, identifier):
if hasattr(identifier, '__iter__'):
if hasattr(identifier, '__iter__') and not isinstance(identifier, str):
ids = list()
for i in identifier:
if i is None or i == "":
Expand All @@ -190,7 +190,7 @@ def quoteId(self, identifier):
@classmethod
def quoteString(self, txt):
""" make the string safe - replace ' with '' """
if hasattr(txt, '__iter__'):
if hasattr(txt, '__iter__') and not isinstance(txt, str):
txts = list()
for i in txt:
if i is None:
Expand All @@ -203,7 +203,7 @@ def quoteString(self, txt):

@classmethod
def getSchemaTableName(self, table):
if not hasattr(table, '__iter__'):
if not hasattr(table, '__iter__') and not isinstance(table, str):
return (None, table)
elif len(table) < 2:
return (None, table[0])
Expand Down
6 changes: 5 additions & 1 deletion python/plugins/db_manager/db_plugins/data_model.py
Expand Up @@ -20,6 +20,10 @@
***************************************************************************/
"""

import sys
if sys.version_info < (3,):
memoryview = buffer

from qgis.PyQt.QtCore import Qt, QTime, QRegExp, QAbstractTableModel
from qgis.PyQt.QtGui import QFont, QStandardItemModel, QStandardItem
from qgis.PyQt.QtWidgets import QApplication
Expand Down Expand Up @@ -76,7 +80,7 @@ def data(self, index, role):

if val is None:
return "NULL"
elif isinstance(val, buffer):
elif isinstance(val, memoryview):
# hide binary data
return None
elif isinstance(val, (str, unicode)) and len(val) > 300:
Expand Down
10 changes: 4 additions & 6 deletions python/plugins/db_manager/db_plugins/oracle/connector.py
Expand Up @@ -369,8 +369,8 @@ def getTables(self, schema=None, add_sys_tables=False):

self.populated = True

listTables = sorted(items, cmp=lambda x, y: cmp((x[2], x[1]),
(y[2], y[1])))
listTables = sorted(items, key=cmp_to_key(lambda x, y: (x[1] > y[1]) - (x[1] < y[1])))

if self.hasCache():
self.updateCache(listTables, schema)
return self.getTablesCache(schema)
Expand All @@ -392,9 +392,7 @@ def getTablesCache(self, schema=None):
pass

if not self.allowGeometrylessTables:
return sorted(items,
cmp=lambda x, y: cmp((x[2], x[1]),
(y[2], y[1])))
return sorted(items, key=cmp_to_key(lambda x, y: (x[1] > y[1]) - (x[1] < y[1])))

# get all non geographic tables and views
schema_where = u""
Expand All @@ -421,7 +419,7 @@ def getTablesCache(self, schema=None):
items.append(item)
c.close()

return sorted(items, cmp=lambda x, y: cmp((x[2], x[1]), (y[2], y[1])))
return sorted(items, key=cmp_to_key(lambda x, y: (x[1] > y[1]) - (x[1] < y[1])))

def updateCache(self, tableList, schema=None):
"""Update the SQLite cache of table list for a schema."""
Expand Down
4 changes: 3 additions & 1 deletion python/plugins/db_manager/db_plugins/postgis/connector.py
Expand Up @@ -22,6 +22,8 @@
***************************************************************************/
"""

from functools import cmp_to_key

from qgis.PyQt.QtCore import QRegExp
from qgis.core import QgsCredentials, QgsDataSourceUri

Expand Down Expand Up @@ -331,7 +333,7 @@ def getTables(self, schema=None, add_sys_tables=False):
items.append(item)
self._close_cursor(c)

return sorted(items, cmp=lambda x, y: cmp((x[2], x[1]), (y[2], y[1])))
return sorted(items, key=cmp_to_key(lambda x, y: (x[1] > y[1]) - (x[1] < y[1])))

def getVectorTables(self, schema=None):
""" get list of table with a geometry column
Expand Down
4 changes: 3 additions & 1 deletion python/plugins/db_manager/db_plugins/spatialite/connector.py
Expand Up @@ -20,6 +20,8 @@
***************************************************************************/
"""

from functools import cmp_to_key

from qgis.PyQt.QtCore import QFile
from qgis.PyQt.QtWidgets import QApplication

Expand Down Expand Up @@ -260,7 +262,7 @@ def getTables(self, schema=None, add_sys_tables=False):
for i, tbl in enumerate(items):
tbl.insert(3, tbl[1] in sys_tables)

return sorted(items, cmp=lambda x, y: cmp(x[1], y[1]))
return sorted(items, key=cmp_to_key(lambda x, y: (x[1] > y[1]) - (x[1] < y[1])))

def getVectorTables(self, schema=None):
""" get list of table with a geometry column
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/db_manager/dlg_sql_layer_window.py
Expand Up @@ -84,9 +84,9 @@ def __init__(self, iface, layer, parent=None):
self.defaultLayerName = 'QueryLayer'

if self.allowMultiColumnPk:
self.uniqueColumnCheck.setText(self.trUtf8("Column(s) with unique values"))
self.uniqueColumnCheck.setText(self.tr("Column(s) with unique values"))
else:
self.uniqueColumnCheck.setText(self.trUtf8("Column with unique values"))
self.uniqueColumnCheck.setText(self.tr("Column with unique values"))

self.editSql.setFocus()
self.editSql.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/db_manager/dlg_sql_window.py
Expand Up @@ -64,9 +64,9 @@ def __init__(self, iface, db, parent=None):
self.defaultLayerName = 'QueryLayer'

if self.allowMultiColumnPk:
self.uniqueColumnCheck.setText(self.trUtf8("Column(s) with unique values"))
self.uniqueColumnCheck.setText(self.tr("Column(s) with unique values"))
else:
self.uniqueColumnCheck.setText(self.trUtf8("Column with unique values"))
self.uniqueColumnCheck.setText(self.tr("Column with unique values"))

self.editSql.setFocus()
self.editSql.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
Expand Down

0 comments on commit cd1d44b

Please sign in to comment.