# HG changeset patch # User Catherine Devlin # Date 1240524304 14400 # Node ID 747b325eb98dce955fe300ebb291ca3232ee70e4 # Parent af0e16a5e0030edd56e9dc79e896f98e8e2d6275 yay, desc and ls work diff -r af0e16a5e003 -r 747b325eb98d sqlpython/sqlpyPlus.py --- a/sqlpython/sqlpyPlus.py Thu Apr 23 17:13:31 2009 -0400 +++ b/sqlpython/sqlpyPlus.py Thu Apr 23 18:05:04 2009 -0400 @@ -948,22 +948,15 @@ return self._do_describe_oracle () if opts.refresh: self.connections[self.connection_number]['gerald_result'] = self.connections[self.connection_number]['gerald']() - schema = self.connections[self.connection_number]['gerald_result'].schema - target = arg.upper().strip() - for (objname, obj) in schema.items(): - if objname.upper() == target: - self.poutput(objname) - if hasattr(obj, 'columns'): - self.tblname = objname - columns = obj.columns.values() - columns.sort() - self.rows = [(c[0], c[1], self._str_datatype_(c[2], c[3], c[4], c[5]), c[6], c[7]) - for c in columns] - self.colnames = 'position name type nullable default'.split() - self.coltypes = [str, str, str, str, str] - self.varsUsed = {} - self.select_output(selecttext='describe ' + target, - terminator=arg.parsed.terminator, rowlimit=arg.parsed.suffix) + for (descriptor, obj) in self.gerald_resolve(arg): + self.poutput(descriptor) + if hasattr(obj, 'columns'): + self.tblname = obj.name + columns = obj.columns.values() + columns.sort() + self.pseudo_query(arg=arg, colnames = 'position name type nullable default', + rows=[(c[0], c[1], self._str_datatype_(c[2], c[3], c[4], c[5]), c[6], c[7]) + for c in columns]) def do_deps(self, arg): '''Lists all objects that are dependent upon the object.''' @@ -1389,18 +1382,40 @@ self.do_select(self.parsed(statement, terminator=arg.parsed.terminator or ';', suffix=arg.parsed.suffix)) - + + def pseudo_query(self, arg, colnames, rows): + self.rows = rows + self.colnames = colnames.split() + self.coltypes = [str] * len(self.colnames) + self.varsUsed = {} + self.select_output(arg.parsed.raw, terminator=arg.parsed.terminator, rowlimit=arg.parsed.suffix) + + def gerald_resolve(self, target): + target = target.lower().strip() + schema = self.connections[self.connection_number]['gerald_result'].schema + for (objname, obj) in schema.items(): + descriptor = '%s/%s' % (str(type(obj)).split('.')[-1].rstrip("'>"), objname) + if (not target) or (objname == target) or (descriptor == target): + yield (descriptor, obj) + @options([make_option('-l', '--long', action='store_true', help='long descriptions'), - make_option('-a', '--all', action='store_true', help="all schemas' objects"), - make_option('-t', '--timesort', action='store_true', help="Sort by last_ddl_time"), - make_option('-r', '--reverse', action='store_true', help="Reverse order while sorting")]) + make_option('-a', '--all', action='store_true', help="all schemas' objects"), + make_option('-t', '--timesort', action='store_true', help="Sort by last_ddl_time"), + make_option('-r', '--reverse', action='store_true', help="Reverse order while sorting")]) def do_ls(self, arg, opts): if self.rdbms == 'oracle': return self._do_ls_oracle(arg, opts) - ger = self.connections[self.connection_number]['gerald_result'] - - - return + rows = [] + for (descriptor, obj) in self.gerald_resolve(arg): + if opts.long: + rows.append((descriptor,)) + else: + rows.append((descriptor,)) + if opts.long: + colnames = 'name' + else: + colnames = 'name' + self.pseudo_query(arg=arg, colnames=colnames, rows=rows) @options([make_option('-i', '--ignore-case', dest='ignorecase', action='store_true', help='Case-insensitive search')]) def do_grep(self, arg, opts):