mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-15 00:06:49 -05:00
[DB Manager / GPKG] Remove GDAL 1.x support
This commit is contained in:
parent
4eed39b63c
commit
3d9ca40f4e
@ -51,9 +51,6 @@ class GPKGDBConnector(DBConnector):
|
||||
|
||||
def _opendb(self):
|
||||
|
||||
self.gdal_ds = None
|
||||
if hasattr(gdal, 'OpenEx'):
|
||||
# GDAL >= 2
|
||||
self.gdal_ds = gdal.OpenEx(self.dbname, gdal.OF_UPDATE)
|
||||
if self.gdal_ds is None:
|
||||
self.gdal_ds = gdal.OpenEx(self.dbname)
|
||||
@ -61,21 +58,6 @@ class GPKGDBConnector(DBConnector):
|
||||
raise ConnectionError(QApplication.translate("DBManagerPlugin", '"{0}" not found').format(self.dbname))
|
||||
self.has_raster = self.gdal_ds.RasterCount != 0 or self.gdal_ds.GetMetadata('SUBDATASETS') is not None
|
||||
self.connection = None
|
||||
self.gdal2 = True
|
||||
else:
|
||||
# GDAL 1.X compat. To be removed at some point
|
||||
self.gdal_ds = ogr.Open(self.dbname, update=1)
|
||||
if self.gdal_ds is None:
|
||||
self.gdal_ds = ogr.Open(self.dbname)
|
||||
if self.gdal_ds is None or self.gdal_ds.GetDriver().GetName() != 'GPKG':
|
||||
raise ConnectionError(QApplication.translate("DBManagerPlugin", '"{0}" not found').format(self.dbname))
|
||||
# For GDAL 1.X, we cannot issue direct SQL SELECT to the OGR datasource
|
||||
# so we need a direct sqlite connection
|
||||
try:
|
||||
self.connection = spatialite_connect(str(self.dbname))
|
||||
except self.connection_error_types() as e:
|
||||
raise ConnectionError(e)
|
||||
self.gdal2 = False
|
||||
|
||||
def unquoteId(self, quotedId):
|
||||
if len(quotedId) <= 2 or quotedId[0] != '"' or quotedId[len(quotedId) - 1] != '"':
|
||||
@ -92,16 +74,6 @@ class GPKGDBConnector(DBConnector):
|
||||
return unquoted
|
||||
|
||||
def _fetchOne(self, sql):
|
||||
if not self.gdal2:
|
||||
# GDAL 1.X compat. To be removed at some point
|
||||
c = self._get_cursor()
|
||||
self._execute(c, sql)
|
||||
res = c.fetchone()
|
||||
if res is not None:
|
||||
return res
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
sql_lyr = self.gdal_ds.ExecuteSQL(sql)
|
||||
if sql_lyr is None:
|
||||
return None
|
||||
@ -114,12 +86,6 @@ class GPKGDBConnector(DBConnector):
|
||||
return ret
|
||||
|
||||
def _fetchAll(self, sql, include_fid_and_geometry=False):
|
||||
if not self.gdal2:
|
||||
# GDAL 1.X compat. To be removed at some point
|
||||
c = self._get_cursor()
|
||||
self._execute(c, sql)
|
||||
return c.fetchall()
|
||||
else:
|
||||
sql_lyr = self.gdal_ds.ExecuteSQL(sql)
|
||||
if sql_lyr is None:
|
||||
return None
|
||||
@ -167,15 +133,12 @@ class GPKGDBConnector(DBConnector):
|
||||
return ret
|
||||
|
||||
def _execute_and_commit(self, sql):
|
||||
if not self.gdal2:
|
||||
DBConnector._execute_and_commit(self, sql)
|
||||
else:
|
||||
sql_lyr = self.gdal_ds.ExecuteSQL(sql)
|
||||
self.gdal_ds.ReleaseResultSet(sql_lyr)
|
||||
|
||||
def _execute(self, cursor, sql):
|
||||
|
||||
if self.gdal2 and self.connection is None:
|
||||
if self.connection is None:
|
||||
# Needed when evaluating a SQL query
|
||||
try:
|
||||
self.connection = spatialite_connect(str(self.dbname))
|
||||
@ -315,8 +278,7 @@ class GPKGDBConnector(DBConnector):
|
||||
geomname = 'MULTIPOLYGON'
|
||||
elif geomtype_flatten == ogr.wkbGeometryCollection:
|
||||
geomname = 'GEOMETRYCOLLECTION'
|
||||
if self.gdal2:
|
||||
if geomtype_flatten == ogr.wkbCircularString:
|
||||
elif geomtype_flatten == ogr.wkbCircularString:
|
||||
geomname = 'CIRCULARSTRING'
|
||||
elif geomtype_flatten == ogr.wkbCompoundCurve:
|
||||
geomname = 'COMPOUNDCURVE'
|
||||
@ -826,14 +788,13 @@ class GPKGDBConnector(DBConnector):
|
||||
if self.isRasterTable(table) or geom_column is None:
|
||||
return False
|
||||
_, tablename = self.getSchemaTableName(table)
|
||||
if self.gdal2:
|
||||
# Only try this for GDAL >= 2 (but only available in >= 2.1.2)
|
||||
|
||||
# (only available in >= 2.1.2)
|
||||
sql = u"SELECT HasSpatialIndex(%s, %s)" % (self.quoteString(tablename), self.quoteString(geom_column))
|
||||
gdal.PushErrorHandler()
|
||||
ret = self._fetchOne(sql)
|
||||
gdal.PopErrorHandler()
|
||||
else:
|
||||
ret = None
|
||||
|
||||
if ret is None:
|
||||
# might be the case for GDAL < 2.1.2
|
||||
sql = u"SELECT COUNT(*) FROM sqlite_master WHERE type = 'table' AND name LIKE %s" % self.quoteString("%%rtree_" + tablename + "_%%")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user