Beispiel #1
0
    def updateControl(self, control, mapping, sql, *args):
        """
            Update control with result from SQL query.
        """
        query = QSqlQuery()
        query.prepare(sql)
        # Loop though all the placeholders and get value from the
        # function assigned to each one.
        for holder, function in mapping.items():
            value = function()
            query.bindValue(":%s" % holder, value)

        query.exec_()

        for key, value in query.boundValues().items():
            log("%s is %s" % (key, value.toString()))

        if isinstance(control, QComboBox):
            control.clear()
            control.addItem("")
            while query.next():
                value = query.value(0).toString()
                if not value.isEmpty():
                    control.addItem(value)