本文整理汇总了Python中db_manager.db_plugins.postgis.plugin.PGDatabase类的典型用法代码示例。如果您正苦于以下问题:Python PGDatabase类的具体用法?Python PGDatabase怎么用?Python PGDatabase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PGDatabase类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rasterTableGdalURI
def test_rasterTableGdalURI(self):
def check_rasterTableGdalURI(expected_dbname):
tables = database.tables()
raster_tables_count = 0
for tab in tables:
if tab.type == Table.RasterType:
raster_tables_count += 1
gdalUri = tab.gdalUri()
m = re.search(' dbname=\'([^ ]*)\' ', gdalUri)
self.assertTrue(m)
actual_dbname = m.group(1)
self.assertEqual(actual_dbname, expected_dbname)
#print(tab.type)
#print(tab.quotedName())
#print(tab)
# We need to make sure a database is created with at
# least one raster table !
self.assertEqual(raster_tables_count, 1)
obj = QObject() # needs to be kept alive
# Test for empty URI
# See https://issues.qgis.org/issues/16625
# and https://issues.qgis.org/issues/10600
expected_dbname = self.testdb
os.environ['PGDATABASE'] = expected_dbname
database = PGDatabase(obj, QgsDataSourceUri())
self.assertIsInstance(database, PGDatabase)
uri = database.uri()
self.assertEqual(uri.host(), '')
self.assertEqual(uri.username(), '')
self.assertEqual(uri.database(), expected_dbname)
self.assertEqual(uri.service(), '')
check_rasterTableGdalURI(expected_dbname)
# Test for service-only URI
# See https://issues.qgis.org/issues/16626
os.environ['PGDATABASE'] = 'fake'
database = PGDatabase(obj, QgsDataSourceUri('service=dbmanager'))
self.assertIsInstance(database, PGDatabase)
uri = database.uri()
self.assertEqual(uri.host(), '')
self.assertEqual(uri.username(), '')
self.assertEqual(uri.database(), '')
self.assertEqual(uri.service(), 'dbmanager')
check_rasterTableGdalURI(expected_dbname)
示例2: test_unicodeInQuery
def test_unicodeInQuery(self):
os.environ['PGDATABASE'] = self.testdb
obj = QObject() # needs to be kept alive
database = PGDatabase(obj, QgsDataSourceUri())
self.assertIsInstance(database, PGDatabase)
# SQL as string literal
res = database.sqlResultModel("SELECT 'é'::text", obj)
self.assertIsInstance(res, PGSqlResultModel)
dat = res.getData(0, 0)
self.assertEqual(dat, u"é")
# SQL as unicode literal
res = database.sqlResultModel(u"SELECT 'é'::text", obj)
self.assertIsInstance(res, PGSqlResultModel)
dat = res.getData(0, 0)
self.assertEqual(dat, u"é")