本文整理汇总了Python中PyQt4.QtSql.QSqlDatabase.port方法的典型用法代码示例。如果您正苦于以下问题:Python QSqlDatabase.port方法的具体用法?Python QSqlDatabase.port怎么用?Python QSqlDatabase.port使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtSql.QSqlDatabase
的用法示例。
在下文中一共展示了QSqlDatabase.port方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PostgisDb
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import port [as 别名]
class PostgisDb(AbstractDb):
def __init__(self):
super(PostgisDb,self).__init__()
self.db = QSqlDatabase('QPSQL')
self.gen = SqlGeneratorFactory().createSqlGenerator(False)
def getDatabaseName(self):
return self.db.databaseName()
def connectDatabase(self,conn=None):
if conn.split(':')[0] == 'PG':
connSplit = conn.split(' ')
parDict = dict()
for i in connSplit[1::]:
par = i.split('=')
parDict[par[0]]=par[1]
self.connectDatabaseWithParameters(parDict['host'], parDict['port'], parDict['dbname'], parDict['user'], parDict['password'])
else:
self.connectDatabaseWithQSettings(conn)
def connectDatabaseWithGui(self):
return None
def connectDatabaseWithParameters(self, host, port, database, user, password):
self.db.setHostName(host)
if type(port) != 'int':
self.db.setPort(int(port))
else:
self.db.setPort(port)
self.db.setDatabaseName(database)
self.db.setUserName(user)
if not password or password == '':
conInfo = 'host='+host+' port='+port+' dbname='+database
check = False
while not check:
try:
(success, user, password) = QgsCredentials.instance().get(conInfo, user, None)
if not success:
return
self.db.setPassword(password)
check = True
self.checkAndOpenDb()
QgsCredentials.instance().put(conInfo, user, password)
except:
pass
else:
self.db.setPassword(password)
def connectDatabaseWithQSettings(self, name):
(host, port, database, user, password) = self.getConnectionFromQSettings(name)
self.db.setHostName(host)
if type(port) != 'int':
self.db.setPort(int(port))
else:
self.db.setPort(port)
self.db.setDatabaseName(database)
self.db.setUserName(user)
if not password or password == '':
conInfo = 'host='+host+' port='+port+' dbname='+database
check = False
while not check:
try:
(success, user, password) = QgsCredentials.instance().get(conInfo, user, None)
if not success:
return
self.db.setPassword(password)
check = True
self.checkAndOpenDb()
QgsCredentials.instance().put(conInfo, user, password)
except:
pass
else:
self.db.setPassword(password)
def getDatabaseVersion(self):
try:
self.checkAndOpenDb()
except:
return '-1'
sqlVersion = self.gen.getEDGVVersion()
queryVersion = QSqlQuery(sqlVersion, self.db)
while queryVersion.next():
version = queryVersion.value(0)
return version
def listGeomClassesFromDatabase(self):
try:
self.checkAndOpenDb()
except:
return []
classList = []
sql = self.gen.getTablesFromDatabase()
query = QSqlQuery(sql, self.db)
while query.next():
tableSchema = query.value(0)
tableName = query.value(1)
layerName = tableSchema+'.'+tableName
if tableName.split("_")[-1] == "p" or tableName.split("_")[-1] == "l" \
or tableName.split("_")[-1] == "a":
#.........这里部分代码省略.........