当前位置: 首页>>代码示例>>Python>>正文


Python QSqlDatabase.rollback方法代码示例

本文整理汇总了Python中PyQt4.QtSql.QSqlDatabase.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python QSqlDatabase.rollback方法的具体用法?Python QSqlDatabase.rollback怎么用?Python QSqlDatabase.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtSql.QSqlDatabase的用法示例。


在下文中一共展示了QSqlDatabase.rollback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: rollback

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import rollback [as 别名]
 def rollback(self, silent=None):
     """rollback and log it"""
     if QSqlDatabase.rollback(self):
         if not silent and Debug.sql:
             logDebug('%x rollbacked transaction' % id(self))
     else:
         logWarning('%s cannot rollback: %s' % (self.name, self.lastError()))
开发者ID:ospalh,项目名称:kajongg-fork,代码行数:9,代码来源:query.py

示例2: PostgisDb

# 需要导入模块: from PyQt4.QtSql import QSqlDatabase [as 别名]
# 或者: from PyQt4.QtSql.QSqlDatabase import rollback [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
开发者ID:alexdsz,项目名称:DsgTools,代码行数:104,代码来源:postgisDb.py


注:本文中的PyQt4.QtSql.QSqlDatabase.rollback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。