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


Python QSqlQuery.bindValue方法代码示例

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


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

示例1: __insertLogEntry

# 需要导入模块: from qgis.PyQt.QtSql import QSqlQuery [as 别名]
# 或者: from qgis.PyQt.QtSql.QSqlQuery import bindValue [as 别名]
    def __insertLogEntry(self,requestType,search,result):
        self.__openDB()
        sql = "INSERT INTO postnas_search_logging (datum,username,requestType,search,result) VALUES (:datum,:username,:requestType,:search,:result)"

        query = QSqlQuery(self.db)
        query.prepare(sql)
        query.bindValue(":datum",datetime.datetime.now().isoformat())
        query.bindValue(":username",self.username)
        query.bindValue(":requestType",requestType)
        query.bindValue(":search",search)
        query.bindValue(":result",str(result).replace("u'","'").replace("\'","\"").replace("[","{").replace("]","}"))
        query.exec_()

        if(query.lastError().number() == -1):
            return True
        else:
            return False
开发者ID:Kreis-Unna,项目名称:PostNAS_Search,代码行数:19,代码来源:PostNAS_Logging.py

示例2: QtSqlDBCursor

# 需要导入模块: from qgis.PyQt.QtSql import QSqlQuery [as 别名]
# 或者: from qgis.PyQt.QtSql.QSqlQuery import bindValue [as 别名]
class QtSqlDBCursor(object):

    def __init__(self, conn):
        self.qry = QSqlQuery(conn)
        self.description = None
        self.rowcount = -1
        self.arraysize = 1

    def close(self):
        self.qry.finish()

    def execute(self, operation, parameters=[]):
        if len(parameters) == 0:
            if not self.qry.exec_(operation):
                raise ExecError(self.qry.lastError().databaseText())
        else:
            if not self.qry.prepare(operation):
                raise ExecError(self.qry.lastError().databaseText())

            for i in range(len(parameters)):
                self.qry.bindValue(i, parameters[i])

            if not self.qry.exec_():
                raise ExecError(self.qry.lastError().databaseText())

        self.rowcount = self.qry.size()
        self.description = []
        for c in range(self.qry.record().count()):
            f = self.qry.record().field(c)

            if f.type() == QVariant.Date:
                t = Date
            elif f.type() == QVariant.Time:
                t = Time
            elif f.type() == QVariant.DateTime:
                t = Timestamp
            elif f.type() == QVariant.Double:
                t = float
            elif f.type() == QVariant.Int:
                t = int
            elif f.type() == QVariant.String:
                t = str
            elif f.type() == QVariant.ByteArray:
                t = str
            else:
                continue

            self.description.append([
                f.name(),                                 # name
                t,                                        # type_code
                f.length(),                               # display_size
                f.length(),                               # internal_size
                f.precision(),                            # precision
                None,                                     # scale
                f.requiredStatus() != QSqlField.Required  # null_ok
            ])

    def executemany(self, operation, seq_of_parameters):
        if len(seq_of_parameters) == 0:
            return

        if not self.qry.prepare(operation):
            raise ExecError(self.qry.lastError().databaseText())

        for r in seq_of_parameters:
            for i in range(len(r)):
                self.qry.bindValue(i, r[i])

            if not self.qry.exec_():
                raise ExecError(self.qry.lastError().databaseText())

    def scroll(self, row):
        return self.qry.seek(row)

    def fetchone(self):
        if not next(self.qry):
            return None

        row = []
        for i in range(len(self.description)):
            value = self.qry.value(i)
            if (isinstance(value, QDate) or
                    isinstance(value, QTime) or
                    isinstance(value, QDateTime)):
                value = value.toString()
            elif isinstance(value, QByteArray):
                value = u"GEOMETRY"
                # value = value.toHex()

            row.append(value)

        return row

    def fetchmany(self, size=10):
        rows = []
        while len(rows) < size:
            row = self.fetchone()
            if row is None:
                break
            rows.append(row)
#.........这里部分代码省略.........
开发者ID:CS-SI,项目名称:QGIS,代码行数:103,代码来源:QtSqlDB.py


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