本文整理汇总了Python中PyQt4.QtSql.QSqlDatabase.commit方法的典型用法代码示例。如果您正苦于以下问题:Python QSqlDatabase.commit方法的具体用法?Python QSqlDatabase.commit怎么用?Python QSqlDatabase.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtSql.QSqlDatabase
的用法示例。
在下文中一共展示了QSqlDatabase.commit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: commit
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import commit [as 别名]
def commit(self, silent=None):
"""commit and log it"""
result = QSqlDatabase.commit(self)
if result:
if not silent and Debug.sql:
logDebug('%x committed transaction' % id(self))
else:
logWarning('%s cannot commit: %s :' % (self.name, self.lastError()))
示例2: PostgisDb
# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import commit [as 别名]
#.........这里部分代码省略.........
query = QSqlQuery(self.gen.getDatabasesFromServer(),self.db)
dbList = []
while query.next():
dbList.append(query.value(0))
edvgDbList = []
for database in dbList:
db = None
db = QSqlDatabase("QPSQL")
db.setDatabaseName(database)
db.setHostName(self.db.hostName())
db.setPort(self.db.port())
db.setUserName(self.db.userName())
db.setPassword(self.db.password())
if not db.open():
QgsMessageLog.logMessage('DB :'+database+'| msg: '+db.lastError().databaseText(), "DSG Tools Plugin", QgsMessageLog.CRITICAL)
query2 = QSqlQuery(db)
if query2.exec_(self.gen.getEDGVVersion()):
while query2.next():
version = query2.value(0)
if version:
edvgDbList.append((database,version))
else:
QgsMessageLog.logMessage(self.tr('Problem accessing database: ') +database+'\n'+query2.lastError().text(), "DSG Tools Plugin", QgsMessageLog.CRITICAL)
return edvgDbList
def getDbsFromServer(self):
#Can only be used in postgres database.
try:
self.checkAndOpenDb()
except:
return []
query = QSqlQuery(self.gen.getDatabasesFromServer(),self.db)
dbList = []
while query.next():
dbList.append(query.value(0))
return dbList
def checkSuperUser(self):
try:
self.checkAndOpenDb()
except:
return False
query = QSqlQuery(self.db)
if query.exec_(self.gen.isSuperUser(self.db.userName())):
query.next()
value = query.value(0)
return value
return False
def dropDatabase(self, candidateName):
try:
self.checkAndOpenDb()
except:
return
if self.checkSuperUser():
sql = self.gen.dropDatabase(candidateName)
query = QSqlQuery(self.db)
if not query.exec_(sql):
raise Exception(self.tr('Problem dropping database: ') + query.lastError().text())
def createResolvedDomainViews(self, createViewClause, fromClause):
try:
self.checkAndOpenDb()
except:
return
if self.checkSuperUser():
filename = self.getSqlViewFile()
if filename <> None:
file = codecs.open(filename, encoding='utf-8', mode="r")
sql = file.read()
sql = sql.replace('[VIEW]', createViewClause).replace('[FROM]', fromClause)
file.close()
commands = sql.split('#')
self.db.transaction()
query = QSqlQuery(self.db)
for command in commands:
if not query.exec_(command):
self.db.rollback()
self.db.close()
raise Exception(self.tr('Problem creating views: ') + str(query.lastError().text()))
self.db.commit()
self.db.close()
def getSqlViewFile(self):
try:
self.checkAndOpenDb()
except:
return
currentPath = os.path.dirname(__file__)
dbVersion = self.getDatabaseVersion()
file = None
if dbVersion == '2.1.3':
file = os.path.join(currentPath,'..','..','DbTools','PostGISTool', 'sqls', '213', 'views_213.sql')
if dbVersion == 'FTer_2a_Ed':
file = os.path.join(currentPath,'..','..','DbTools','PostGISTool', 'sqls', 'FTer_2a_Ed', 'views_edgvFter_2a_Ed.sql')
return file