本文整理汇总了Python中PyQt4.QtSql.QSqlDatabase.setConnectOptions方法的典型用法代码示例。如果您正苦于以下问题:Python QSqlDatabase.setConnectOptions方法的具体用法?Python QSqlDatabase.setConnectOptions怎么用?Python QSqlDatabase.setConnectOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtSql.QSqlDatabase
的用法示例。
在下文中一共展示了QSqlDatabase.setConnectOptions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initDb
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import setConnectOptions [as 别名]
def initDb():
"""open the db, create or update it if needed.
Returns a dbHandle."""
dbhandle = QSqlDatabase("QSQLITE")
if InternalParameters.isServer:
name = 'kajonggserver.db'
else:
name = 'kajongg.db'
dbpath = InternalParameters.dbPath or appdataDir() + name
dbhandle.setDatabaseName(dbpath)
dbExisted = os.path.exists(dbpath)
if Debug.sql:
logDebug('%s database %s' % \
('using' if dbExisted else 'creating', dbpath))
# timeout in msec:
dbhandle.setConnectOptions("QSQLITE_BUSY_TIMEOUT=2000")
if not dbhandle.open():
logError('%s %s' % (str(dbhandle.lastError().text()), dbpath))
sys.exit(1)
with Transaction(dbhandle=dbhandle):
if not dbExisted:
Query.createTables(dbhandle)
else:
Query.upgradeDb(dbhandle)
generateDbIdent(dbhandle)
return dbhandle
示例2: getDatabase
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import setConnectOptions [as 别名]
def getDatabase(self, database = 'postgres'):
(host, port, user, password) = self.getServerConfiguration(self.serversCombo.currentText())
db = QSqlDatabase("QPSQL")
db.setConnectOptions('connect_timeout=10')
db.setDatabaseName(database)
db.setHostName(host)
db.setPort(int(port))
db.setUserName(user)
if password == '':
conInfo = 'host='+host+' port='+port+' dbname='+database
self.setCredentials(db, conInfo, user)
else:
db.setPassword(password)
if not db.open():
QgsMessageLog.logMessage(db.lastError().text(), "DSG Tools Plugin", QgsMessageLog.CRITICAL)
return db