Skip to content
Permalink
Browse files

db_manager: cleanups

  • Loading branch information
jef-n committed Mar 21, 2016
1 parent d25c253 commit c55f8b73f0a2c9fdc015d7cbc1ac4fabe36bd23e
Showing with 141 additions and 157 deletions.
  1. +3 −2 python/plugins/db_manager/db_manager.py
  2. +2 −2 python/plugins/db_manager/db_manager_plugin.py
  3. +3 −3 python/plugins/db_manager/db_model.py
  4. +2 −2 python/plugins/db_manager/db_plugins/__init__.py
  5. +3 −3 python/plugins/db_manager/db_plugins/connector.py
  6. +5 −5 python/plugins/db_manager/db_plugins/data_model.py
  7. +1 −1 python/plugins/db_manager/db_plugins/oracle/QtSqlDB.py
  8. +8 −18 python/plugins/db_manager/db_plugins/oracle/connector.py
  9. +1 −1 python/plugins/db_manager/db_plugins/oracle/info_model.py
  10. +6 −11 python/plugins/db_manager/db_plugins/oracle/plugin.py
  11. +2 −2 python/plugins/db_manager/db_plugins/oracle/sql_dictionary.py
  12. +38 −37 python/plugins/db_manager/db_plugins/plugin.py
  13. +2 −2 python/plugins/db_manager/db_plugins/postgis/connector.py
  14. +0 −1 python/plugins/db_manager/db_plugins/postgis/data_model.py
  15. +1 −1 python/plugins/db_manager/db_plugins/postgis/info_model.py
  16. +7 −7 python/plugins/db_manager/db_plugins/postgis/plugin.py
  17. +1 −1 python/plugins/db_manager/db_plugins/postgis/plugins/__init__.py
  18. +6 −6 python/plugins/db_manager/db_plugins/postgis/plugins/versioning/dlg_versioning.py
  19. +2 −2 python/plugins/db_manager/db_plugins/postgis/sql_dictionary.py
  20. +13 −13 python/plugins/db_manager/db_plugins/spatialite/connector.py
  21. +3 −3 python/plugins/db_manager/db_plugins/spatialite/plugin.py
  22. +2 −2 python/plugins/db_manager/db_plugins/spatialite/sql_dictionary.py
  23. +1 −1 python/plugins/db_manager/db_plugins/vlayers/connector.py
  24. +1 −1 python/plugins/db_manager/db_plugins/vlayers/info_model.py
  25. +1 −1 python/plugins/db_manager/db_plugins/vlayers/plugin.py
  26. +2 −2 python/plugins/db_manager/db_plugins/vlayers/sql_dictionary.py
  27. +5 −7 python/plugins/db_manager/db_tree.py
  28. +2 −2 python/plugins/db_manager/dlg_export_vector.py
  29. +0 −1 python/plugins/db_manager/dlg_field_properties.py
  30. +4 −4 python/plugins/db_manager/dlg_import_vector.py
  31. +5 −5 python/plugins/db_manager/dlg_query_builder.py
  32. +6 −6 python/plugins/db_manager/dlg_sql_window.py
  33. +2 −1 python/plugins/db_manager/layer_preview.py
  34. +1 −1 python/plugins/db_manager/table_viewer.py
@@ -24,7 +24,7 @@

import functools

from PyQt.QtCore import QObject, Qt, QSettings, QByteArray, QSize
from PyQt.QtCore import Qt, QSettings, QByteArray, QSize
from PyQt.QtWidgets import QMainWindow, QApplication, QMenu, QTabWidget, QGridLayout, QSpacerItem, QSizePolicy, QDockWidget, QStatusBar, QMenuBar, QToolBar, QTabBar
from PyQt.QtGui import QIcon, QKeySequence

@@ -214,7 +214,8 @@ def registerAction(self, action, menuName, callback=None):
self._registeredDbActions = {}

if callback is not None:
invoke_callback = lambda x: self.invokeCallback(callback)
def invoke_callback(x):
return self.invokeCallback(callback)

if menuName is None or menuName == "":
self.addAction(action)
@@ -20,11 +20,11 @@
***************************************************************************/
"""

from PyQt.QtCore import Qt, QObject
from PyQt.QtCore import Qt
from PyQt.QtWidgets import QAction, QApplication
from PyQt.QtGui import QIcon

from . import resources_rc
from . import resources_rc # NOQA


class DBManagerPlugin:
@@ -30,10 +30,10 @@

from qgis.core import QgsDataSourceURI, QgsVectorLayer, QgsRasterLayer, QgsMimeDataUtils

from . import resources_rc
from . import resources_rc # NOQA

try:
from qgis.core import QgsVectorLayerImport
from qgis.core import QgsVectorLayerImport # NOQA
isImportVectorAvail = True
except:
isImportVectorAvail = False
@@ -491,7 +491,7 @@ def _refreshIndex(self, index, force=False):
else:
self.notPopulated.emit(index)

except BaseError as e:
except BaseError:
item.populated = False
return

@@ -42,12 +42,12 @@ def initDbPluginList():
continue

try:
exec (u"from .%s import plugin as mod" % name, globals())
exec(u"from .%s import plugin as mod" % name, globals())
except ImportError as e:
DBPLUGIN_ERRORS.append(u"%s: %s" % (name, unicode(e)))
continue

pluginclass = mod.classFactory()
pluginclass = mod.classFactory() # NOQA
SUPPORTED_DBTYPES[pluginclass.typeName()] = pluginclass

return len(SUPPORTED_DBTYPES) > 0
@@ -112,7 +112,7 @@ def _close_cursor(self, c):
if c and not c.closed:
c.close()

except self.error_types() as e:
except self.error_types():
pass

return
@@ -168,9 +168,9 @@ def _rollback(self):
def _get_cursor_columns(self, c):
try:
if c.description:
return map(lambda x: x[0], c.description)
return [x[0] for x in c.description]

except self.connection_error_types() + self.execution_error_types() as e:
except self.connection_error_types() + self.execution_error_types():
return []

@classmethod
@@ -78,9 +78,9 @@ def data(self, index, role):
# too much data to display, elide the string
val = val[:300]
try:
return unicode(val) # convert to unicode
return unicode(val) # convert to unicode
except UnicodeDecodeError:
return unicode(val, 'utf-8', 'replace') # convert from utf8 and replace errors (if any)
return unicode(val, 'utf-8', 'replace') # convert from utf8 and replace errors (if any)

def headerData(self, section, orientation, role):
if role != Qt.DisplayRole:
@@ -100,7 +100,7 @@ def __init__(self, table, parent=None):
self.db = table.database().connector
self.table = table

fieldNames = map(lambda x: x.name, table.fields())
fieldNames = [x.name for x in table.fields()]
BaseTableModel.__init__(self, fieldNames, None, parent)

# get table fields
@@ -267,7 +267,7 @@ def __init__(self, parent, editable=False):
QApplication.translate("DBManagerPlugin", 'Column(s)')], editable, parent)

def append(self, constr):
field_names = map(lambda k_v: unicode(k_v[1].name), iter(constr.fields().items()))
field_names = [unicode(k_v[1].name) for k_v in iter(list(constr.fields().items()))]
data = [constr.name, constr.type2String(), u", ".join(field_names)]
self.appendRow(self.rowFromData(data))
row = self.rowCount() - 1
@@ -303,7 +303,7 @@ def __init__(self, parent, editable=False):
QApplication.translate("DBManagerPlugin", 'Column(s)')], editable, parent)

def append(self, idx):
field_names = map(lambda k_v1: unicode(k_v1[1].name), iter(idx.fields().items()))
field_names = [unicode(k_v1[1].name) for k_v1 in iter(list(idx.fields().items()))]
data = [idx.name, u", ".join(field_names)]
self.appendRow(self.rowFromData(data))
row = self.rowCount() - 1
@@ -21,7 +21,7 @@
"""

from PyQt.QtCore import QVariant, QDate, QTime, QDateTime, QByteArray
from PyQt4.QtSql import QSqlDatabase, QSqlQuery, QSqlField
from PyQt.QtSql import QSqlDatabase, QSqlQuery, QSqlField

paramstyle = "qmark"
threadsafety = 1
@@ -24,7 +24,7 @@
"""

from PyQt.QtCore import QPyNullVariant
from PyQt4.QtSql import QSqlDatabase
from PyQt.QtSql import QSqlDatabase

from ..connector import DBConnector
from ..plugin import ConnectionError, DbError, Table
@@ -101,8 +101,7 @@ def __init__(self, uri, connName):
if (os.path.isfile(sqlite_cache_file)):
try:
self.cache_connection = sqlite3.connect(sqlite_cache_file)
except sqlite3.Error as e:

except sqlite3.Error:
self.cache_connection = False

# Find if there is cache for our connection:
@@ -117,7 +116,7 @@ def __init__(self, uri, connName):
if not has_cached:
self.cache_connection = False

except sqlite3.Error as e:
except sqlite3.Error:
self.cache_connection = False

self._checkSpatial()
@@ -766,7 +765,7 @@ def getTableGeomTypes(self, table, geomCol):

try:
c = self._execute(None, query)
except DbError as e: # handle error views or other problems
except DbError: # handle error views or other problems
return [QGis.WKBUnknown], [-1]

rows = self._fetchall(c)
@@ -1071,7 +1070,7 @@ def getTableExtent(self, table, geom):

try:
c = self._execute(None, sql)
except DbError as e: # no spatial index on table, try aggregation
except DbError: # no spatial index on table, try aggregation
return None

res = self._fetchone(c)
@@ -1106,7 +1105,7 @@ def getTableEstimatedExtent(self, table, geom):
sql = request.format(where, dimension)
try:
c = self._execute(None, sql)
except DbError as e: # no statistics for the current table
except DbError: # no statistics for the current table
return None

res_d = self._fetchone(c)
@@ -1160,7 +1159,7 @@ def getSpatialRefInfo(self, srid):
None,
(u"SELECT CS_NAME FROM MDSYS.CS_SRS WHERE"
u" SRID = {}".format(srid)))
except DbError as e:
except DbError:
return
sr = self._fetchone(c)
c.close()
@@ -1212,8 +1211,6 @@ def deleteTable(self, table):
"""Delete table and its reference in sdo_geom_metadata."""

schema, tablename = self.getSchemaTableName(table)
schema_part = u"AND owner = {} ".format(
self.quoteString(schema)) if schema else ""

if self.isVectorTable(table):
self.deleteMetadata(table)
@@ -1283,8 +1280,6 @@ def createSpatialView(self, view, query):
def deleteView(self, view):
"""Delete a view."""
schema, tablename = self.getSchemaTableName(view)
schema_part = u"AND owner = {} ".format(
self.quoteString(schema)) if schema else ""

if self.isVectorTable(view):
self.deleteMetadata(view)
@@ -1645,7 +1640,7 @@ def _close_cursor(self, c):
if c:
c.close()

except self.error_types() as e:
except self.error_types():
pass

return
@@ -1682,11 +1677,6 @@ def _close_cursor(self, c):
# def _get_cursor_columns(self, c):
# pass

def getQueryBuilderDictionary(self):
from .sql_dictionary import getQueryBuilderDictionary

return getQueryBuilderDictionary()

def getSqlDictionary(self):
"""Returns the dictionary for SQL dialog."""
from .sql_dictionary import getSqlDictionary
@@ -219,7 +219,7 @@ def generalInfo(self):
# primary key defined?
if (not self.table.isView
and self.table.objectType != u"MATERIALIZED VIEW"):
pk = filter(lambda fld: fld.primaryKey, self.table.fields())
pk = [fld for fld in self.table.fields() if fld.primaryKey]
if len(pk) <= 0:
ret.append(
HtmlParagraph(QApplication.translate(
@@ -38,7 +38,7 @@

from qgis.core import QgsCredentials

from . import resources_rc
from . import resources_rc # NOQA


def classFactory():
@@ -91,12 +91,7 @@ def connect(self, parent=None):
uri = QgsDataSourceURI()

settingsList = ["host", "port", "database", "username", "password"]
host, port, database, username, password = map(
lambda x: settings.value(x, "", type=str), settingsList)

# qgis1.5 use 'savePassword' instead of 'save' setting
savedPassword = settings.value("save", False, type=bool) or \
settings.value("savePassword", False, type=bool)
host, port, database, username, password = [settings.value(x, "", type=str) for x in settingsList]

# get all of the connexion options

@@ -348,14 +343,14 @@ def runAction(self, action):
QApplication.setOverrideCursor(Qt.WaitCursor)

if index_action == "rebuild":
self.emitAboutToChange()
self.aboutToChange.emit()
self.database().connector.rebuildTableIndex(
(self.schemaName(), self.name), index_name)
self.refreshIndexes()
return True
elif action.startswith(u"mview/"):
if action == "mview/refresh":
self.emitAboutToChange()
self.aboutToChange.emit()
self.database().connector.refreshMView(
(self.schemaName(), self.name))
return True
@@ -391,7 +386,7 @@ def getValidQGisUniqueFields(self, onlyOne=False):
ret = []

# add the pk
pkcols = filter(lambda x: x.primaryKey, self.fields())
pkcols = [x for x in self.fields() if x.primaryKey]
if len(pkcols) == 1:
ret.append(pkcols[0])

@@ -452,7 +447,7 @@ def info(self):
def runAction(self, action):
if action.startswith("extent/"):
if action == "extent/update":
self.emitAboutToChange()
self.aboutToChange.emit()
self.updateExtent()
return True

@@ -289,10 +289,10 @@ def getSqlDictionary(spatial=True):
def getQueryBuilderDictionary():
# concat functions
def ff(l):
return filter(lambda s: s[0] != '*', l)
return [s for s in l if s[0] != '*']

def add_paren(l):
return map(lambda s: s + "(", l)
return [s + "(" for s in l]

foo = sorted(
add_paren(

0 comments on commit c55f8b7

Please sign in to comment.
You can’t perform that action at this time.