processing postgis connector quote indexes names

This commit is contained in:
Alessandro Pasotti 2019-05-22 18:28:35 +02:00
parent a4187a7a6e
commit fd4895b9fb

View File

@ -156,8 +156,8 @@ class TableField(object):
ALTER TABLE command.
"""
data_type = (self.data_type if not self.modifier or self.modifier <
0 else '%s(%d)' % (self.data_type, self.modifier))
data_type = (self.data_type if not self.modifier or self.modifier
< 0 else '%s(%d)' % (self.data_type, self.modifier))
txt = '%s %s %s' % (self._quote(self.name), data_type,
self.is_null_txt())
if self.default and len(self.default) > 0:
@ -721,20 +721,20 @@ class GeoDB(object):
table_name = self._table_name(schema, table)
idx_name = self._quote(name)
sql = 'CREATE INDEX %s ON %s (%s)' % (idx_name, table_name,
self._quote(column))
sql = 'CREATE INDEX "%s" ON %s (%s)' % (idx_name, table_name,
self._quote(column))
self._exec_sql_and_commit(sql)
def create_spatial_index(self, table, schema=None, geom_column='the_geom'):
table_name = self._table_name(schema, table)
idx_name = self._quote(u"sidx_%s_%s" % (table, geom_column))
sql = 'CREATE INDEX %s ON %s USING GIST(%s)' % (idx_name, table_name,
self._quote(geom_column))
sql = 'CREATE INDEX "%s" ON %s USING GIST(%s)' % (idx_name, table_name,
self._quote(geom_column))
self._exec_sql_and_commit(sql)
def delete_index(self, name, schema=None):
index_name = self._table_name(schema, name)
sql = 'DROP INDEX %s' % index_name
sql = 'DROP INDEX "%s"' % index_name
self._exec_sql_and_commit(sql)
def get_database_privileges(self):
@ -831,8 +831,8 @@ class GeoDB(object):
try:
cursor.execute(sql)
except psycopg2.Error as e:
raise QgsProcessingException(str(e) + ' QUERY: ' +
e.cursor.query.decode(e.cursor.connection.encoding))
raise QgsProcessingException(str(e) + ' QUERY: '
+ e.cursor.query.decode(e.cursor.connection.encoding))
def _exec_sql_and_commit(self, sql):
"""Tries to execute and commit some action, on error it rolls