mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
parent
22daf464e2
commit
9880a751a9
@ -29,7 +29,6 @@ from functools import cmp_to_key
|
|||||||
from qgis.PyQt.QtCore import (
|
from qgis.PyQt.QtCore import (
|
||||||
QRegExp,
|
QRegExp,
|
||||||
QFile,
|
QFile,
|
||||||
QCoreApplication,
|
|
||||||
QVariant,
|
QVariant,
|
||||||
QDateTime,
|
QDateTime,
|
||||||
QTime,
|
QTime,
|
||||||
@ -39,7 +38,6 @@ from qgis.PyQt.QtCore import (
|
|||||||
from qgis.core import (
|
from qgis.core import (
|
||||||
Qgis,
|
Qgis,
|
||||||
QgsCoordinateReferenceSystem,
|
QgsCoordinateReferenceSystem,
|
||||||
QgsCredentials,
|
|
||||||
QgsVectorLayer,
|
QgsVectorLayer,
|
||||||
QgsDataSourceUri,
|
QgsDataSourceUri,
|
||||||
QgsProviderRegistry,
|
QgsProviderRegistry,
|
||||||
@ -48,9 +46,10 @@ from qgis.core import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from ..connector import DBConnector
|
from ..connector import DBConnector
|
||||||
from ..plugin import ConnectionError, DbError, Table
|
from ..plugin import DbError, Table
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import psycopg2.extensions
|
import psycopg2.extensions
|
||||||
|
|
||||||
@ -118,18 +117,37 @@ class CursorAdapter():
|
|||||||
|
|
||||||
if self._description is None:
|
if self._description is None:
|
||||||
|
|
||||||
|
self._description = []
|
||||||
|
|
||||||
|
if re.match('^SHOW', self.sql.strip().upper()):
|
||||||
|
try:
|
||||||
|
count = len(self.connection.executeSql(self.sql)[0])
|
||||||
|
except QgsProviderConnectionException:
|
||||||
|
count = 1
|
||||||
|
for i in range(count):
|
||||||
|
self._description.append([
|
||||||
|
'', # name
|
||||||
|
'', # type_code
|
||||||
|
-1, # display_size
|
||||||
|
-1, # internal_size
|
||||||
|
-1, # precision
|
||||||
|
None, # scale
|
||||||
|
True # null_ok
|
||||||
|
])
|
||||||
|
else:
|
||||||
uri = QgsDataSourceUri(self.connection.uri())
|
uri = QgsDataSourceUri(self.connection.uri())
|
||||||
|
|
||||||
# TODO: make this part provider-agnostic
|
# TODO: make this part provider-agnostic
|
||||||
sql = self.sql if self.sql.upper().find(' LIMIT ') >= 0 else self.sql + ' LIMIT 1 '
|
sql = self.sql if self.sql.upper().find(' LIMIT ') >= 0 else self.sql + ' LIMIT 1 '
|
||||||
uri.setTable('(SELECT row_number() OVER () AS __rid__, * FROM (' + sql + ') as foo)')
|
uri.setTable('(SELECT row_number() OVER () AS __rid__, * FROM (' + sql + ') as foo)')
|
||||||
uri.setKeyColumn('__rid__')
|
uri.setKeyColumn('__rid__')
|
||||||
|
uri.setParam('checkPrimaryKeyUnicity', '0')
|
||||||
# TODO: fetch provider name from connection (QgsAbstractConnectionProvider)
|
# TODO: fetch provider name from connection (QgsAbstractConnectionProvider)
|
||||||
# TODO: re-use the VectorLayer for fetching rows in batch mode
|
# TODO: re-use the VectorLayer for fetching rows in batch mode
|
||||||
vl = QgsVectorLayer(uri.uri(False), 'dbmanager_cursor', 'postgres')
|
vl = QgsVectorLayer(uri.uri(False), 'dbmanager_cursor', 'postgres')
|
||||||
|
|
||||||
fields = vl.fields()
|
fields = vl.fields()
|
||||||
self._description = []
|
|
||||||
for i in range(1, len(fields)): # skip first field (__rid__)
|
for i in range(1, len(fields)): # skip first field (__rid__)
|
||||||
f = fields[i]
|
f = fields[i]
|
||||||
self._description.append([
|
self._description.append([
|
||||||
@ -141,6 +159,7 @@ class CursorAdapter():
|
|||||||
None, # scale
|
None, # scale
|
||||||
True # null_ok
|
True # null_ok
|
||||||
])
|
])
|
||||||
|
|
||||||
self._debug("get_description returned " + str(len(self._description)) + " cols")
|
self._debug("get_description returned " + str(len(self._description)) + " cols")
|
||||||
|
|
||||||
return self._description
|
return self._description
|
||||||
|
Loading…
x
Reference in New Issue
Block a user