Example #1
0
        def do_d(self, line):
                """Method to handle special comand \d,
to list tables or columnds in a table if line isn't empty.
"""
                if not self.current:
                        if line.strip():
                                print_table(self.get_columns(line), self.vertical_display)
                        else:
                                print_table(self.get_tables(), self.vertical_display)
Example #2
0
        def default(self, line):
                """Method to handle unhandled comands, will treat
                line as SQL. If the escape character ';' is not present,
                line is appended to self.current and not run until the
                character is present.
                """
                # Handle control char ^D as an exit command
                if self.current == '' and line.rstrip() == '\x04':
                        self.do_exit(None)

                # Handle query buffer reset
                if line.rstrip().endswith(r'\r'):
                        self.current = ''
                        self.prompt = self._prompt
                        print >> sys.stdout, "Query buffer reset (cleared)."
                else:
                        self.current = '%s %s' % (self.current, line,)

                        if ';' in self.current:
                                first = True
                                data = []
                                for row in self.get_query(self.current):
                                        if first:
                                                keys = getattr(row, 'keys', None)
                                                if not keys:
                                                        # If this DBAPI doesn't provide a keys(), then
                                                        # try cursor.description
                                                        keys = []
                                                        if hasattr(row, 'cursor'):
                                                                description = getattr(row, 'cursor').description
                                                        else:
                                                                description = getattr(row, 'cursor_description')
                                                        for r in description:
                                                                keys.append(r[0])
                                                else:
                                                        keys = keys()
                                                data.append(keys)
                                                first = False
                                        data.append([v for v in row])
                                if len(data) > 1:
                                        print_table(data, self.vertical_display)
                                        print >> sys.stdout, "\n%d found." % (len(data)-1,)
                                else:
                                        print >> sys.stdout, "\nNo results found."
                                self.current = ''
                                if self.prompt == self.multi_prompt:
                                        self.prompt = self._prompt
                        else:
                                self._prompt = self.prompt
                                self.prompt = self.multi_prompt
Example #3
0
        def do_l(self, line):
                """\l
List schemas
"""
                if not self.current:
                        print_table(self.get_schemas(), self.vertical_display)
Example #4
0
        def do_p(self, line):
                """\p
List WT profiles.
"""
                if not self.current:
                        print_table(self.get_profiles(), self.vertical_display)