コード例 #1
0
    def getDefinition(self, factId):

        db = self.learnXdB.openDataBase()
        c = db.cursor()

        t = (factId,)
        c.execute("Select id, fact_id, definition_hash, definition_key_hash From Definitions Where fact_id = ?", t)

        row = c.fetchone()
        if row:
            definition = Definition(row[1], row[2], row[3], row[0])
            c.close()
        else:
            c.close()

            c = db.cursor()

            t = (factId,)
            c.execute("Insert Into Definitions (fact_id) Values (?)", t)
            db.commit()
            c.close()

            definition = Definition(factId, None, None, -1)

            c = db.cursor()
            c.execute("Select id From Definitions Where fact_id = ?", t)
            row = c.fetchone()
            if row:
                definition.id = row[0]
            c.close()

        return definition
コード例 #2
0
    def getDefinitions(self, facts):

        db = self.learnXdB.openDataBase()
        c = db.cursor()

        result = list()

        definitionToInsert = list()
        for fact in facts:
            t = (fact.id,)
            c.execute("Select id, fact_id, definition_hash, definition_key_hash From Definitions Where fact_id = ?", t)
            row = c.fetchone()
            if row:
                definition = Definition(row[1], row[2], row[3], row[0])
            else:
                definition = Definition(fact.id, None, None, -1)
                definitionToInsert.append(definition)
            definition.fact = fact
            result.append(definition)
        c.close()

        c = db.cursor()
        for definition in definitionToInsert:
            t = (definition.fact.id,)
            c.execute("Insert Into Definitions (fact_id) Values (?)", t)
        db.commit()
        c.close()

        c = db.cursor()
        for definition in definitionToInsert:
            t = (definition.fact.id,)
            c.execute("Select id From Definitions Where fact_id = ?", t)
            row = c.fetchone()
            if row:
                definition.id = row[0]
        c.close()

        return result