Beispiel #1
0
    def _form_query_from_data(self, row, parsed):
        """Create a query from a row from the query table.

        :param self: The current object
        :type self: queryutils.databases.Database
        :param row: The row fetched from the database
        :type row: dict
        :param parsed: Whether or not the row contains parsetree data 
        :type parsed: bool
        :rtype: queryutils.query.Query
        """
        d = { k:row[k] for k in row.keys() }
        q = Query(row["text"], row["time"])
        q.__dict__.update(d)
        if parsed:
            q.parsetree = ParseTreeNode.loads(row["parsetree"])
        return q
Beispiel #2
0
 def get_parsetrees(self):
     """Return the parsed queries from the parsetree table. 
     
     :param self: The current object
     :type self: queryutils.databases.Database
     :rtype: generator
     """
     self.connect()
     cursor = self.execute("SELECT parsetree, query_id FROM parsetrees")
     for row in cursor.fetchall():
         try:
             p = ParseTreeNode.loads(row["parsetree"])
             p.query_id = row["query_id"]
             yield p
         except ValueError as e:
             print e
             print parsetree
     self.close()