本文整理汇总了Python中plugins.db_manager.db_plugins.plugin.TableField.modifier方法的典型用法代码示例。如果您正苦于以下问题:Python TableField.modifier方法的具体用法?Python TableField.modifier怎么用?Python TableField.modifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plugins.db_manager.db_plugins.plugin.TableField
的用法示例。
在下文中一共展示了TableField.modifier方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCreateRenameDeleteTable
# 需要导入模块: from plugins.db_manager.db_plugins.plugin import TableField [as 别名]
# 或者: from plugins.db_manager.db_plugins.plugin.TableField import modifier [as 别名]
def testCreateRenameDeleteTable(self):
connection_name = 'testCreateRenameDeleteTable'
plugin = createDbPlugin('gpkg')
uri = QgsDataSourceUri()
test_gpkg_new = os.path.join(self.basetestpath, 'testCreateRenameDeleteTable.gpkg')
shutil.copy(self.test_gpkg, test_gpkg_new)
uri.setDatabase(test_gpkg_new)
self.assertTrue(plugin.addConnection(connection_name, uri))
connection = createDbPlugin('gpkg', connection_name)
connection.connect()
db = connection.database()
self.assertIsNotNone(db)
tables = db.tables()
self.assertEqual(len(tables), 1)
table = tables[0]
self.assertTrue(table.rename('newName'))
self.assertEqual(table.name, 'newName')
connection.reconnect()
db = connection.database()
tables = db.tables()
self.assertEqual(len(tables), 1)
table = tables[0]
self.assertEqual(table.name, 'newName')
fields = []
geom = ['geometry', 'POINT', 4326, 3]
field1 = TableField(table)
field1.name = 'fid'
field1.dataType = 'INTEGER'
field1.notNull = True
field1.primaryKey = True
field2 = TableField(table)
field2.name = 'str_field'
field2.dataType = 'TEXT'
field2.modifier = 20
fields = [field1, field2]
self.assertTrue(db.createVectorTable('newName2', fields, geom))
tables = db.tables()
self.assertEqual(len(tables), 2)
new_table = tables[1]
self.assertEqual(new_table.name, 'newName2')
fields = new_table.fields()
self.assertEqual(len(fields), 3)
self.assertFalse(new_table.hasSpatialIndex())
self.assertTrue(new_table.createSpatialIndex())
self.assertTrue(new_table.hasSpatialIndex())
self.assertTrue(new_table.delete())
tables = db.tables()
self.assertEqual(len(tables), 1)
connection.remove()