def default(self, line): # XXX What is this idiocy? End-of-input is reported the same # as the line with characters `E', `O', `F'. if line == 'EOF': self.stdout.write('\nMoriturus te querio.\n') return True if self.prompt == self.def_prompt: if line.startswith('.'): cmd = line for i, c in enumerate(line): if c in (' ', '\t'): cmd = line[:i] break self.stdout.write('Unknown command: %s\n' % (cmd, )) return False # Add a line and check whether it finishes a BQL phrase. self.bql.write(line) self.bql.write('\n') string = self.bql.getvalue() if parse.bql_string_complete_p(string): # Reset the BQL input. self.bql = StringIO.StringIO() self.prompt = self.def_prompt try: first = True for phrase in parse.parse_bql_string(string): cursor = bql.execute_phrase(self._bdb, phrase) with txn.bayesdb_caching(self._bdb): # Separate the output tables by a blank line. if first: first = False else: self.stdout.write('\n') if cursor is not None: pretty.pp_cursor(self.stdout, cursor) except (bayeslite.BayesDBException, bayeslite.BQLParseError) as e: self.stdout.write('%s\n' % (e, )) except Exception: self.stdout.write(traceback.format_exc()) else: self.prompt = self.bql_prompt return False
def default(self, line): # XXX What is this idiocy? End-of-input is reported the same # as the line with characters `E', `O', `F'. if line == 'EOF': self.stdout.write('\nMoriturus te querio.\n') return True if self.prompt == self.def_prompt: if line.startswith('.'): cmd = line for i, c in enumerate(line): if c in (' ', '\t'): cmd = line[:i] break self.stdout.write('Unknown command: %s\n' % (cmd,)) return False # Add a line and check whether it finishes a BQL phrase. self.bql.write(line) self.bql.write('\n') string = self.bql.getvalue() if parse.bql_string_complete_p(string): # Reset the BQL input. self.bql = StringIO.StringIO() self.prompt = self.def_prompt try: first = True for phrase in parse.parse_bql_string(string): cursor = bql.execute_phrase(self._bdb, phrase) with txn.bayesdb_caching(self._bdb): # Separate the output tables by a blank line. if first: first = False else: self.stdout.write('\n') if cursor is not None: pretty.pp_cursor(self.stdout, cursor) except (bayeslite.BayesDBException, bayeslite.BQLParseError) as e: self.stdout.write('%s\n' % (e,)) except Exception: self.stdout.write(traceback.format_exc()) else: self.prompt = self.bql_prompt return False
def fetchall(self): with txn.bayesdb_caching(self._bdb): return self._cursor.fetchall()
def fetchmany(self, size=1): with txn.bayesdb_caching(self._bdb): return self._cursor.fetchmany(size=size)