Mercurial > sqlpython
changeset 379:a70adadca4d8
merging
author | catherine@cordelia |
---|---|
date | Fri, 28 Aug 2009 10:47:59 -0400 |
parents | 05d2de3e7ea8 (diff) 9d0a3ab7f573 (current diff) |
children | fe0051d7f934 |
files | sqlpython/sqlpython.py |
diffstat | 2 files changed, 29 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/sqlpython/sqlpyPlus.py Thu Aug 13 13:20:30 2009 -0400 +++ b/sqlpython/sqlpyPlus.py Fri Aug 28 10:47:59 2009 -0400 @@ -1429,7 +1429,7 @@ 'WINDOW', 'WINDOW GROUP', 'XML SCHEMA') - + @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"), @@ -1439,32 +1439,25 @@ Lists objects as through they were in an {object_type}/{object_name} UNIX directory structure. `*` and `%` may be used as wildcards. ''' - clauses = {'owner': '', 'moreColumns': '', - 'source': metaqueries['ls'][self.rdbms], - 'where': self.ls_where_clause(arg, opts)} - if opts.long: - clauses['moreColumns'] = ', status, last_ddl_time' - if opts.all: - clauses['owner'] = "owner || '.' ||" - - # 'Normal' sort order is DATE DESC (maybe), object type ASC, object name ASC - sortdirection = (hasattr(opts, 'reverse') and opts.reverse and 'DESC') or 'ASC' - orderby = 'object_type %s, object_name %s' % (sortdirection, sortdirection) - if hasattr(opts, 'timesort') and opts.timesort: - if hasattr(opts, 'reverse') and opts.reverse: - direction = 'DESC' + seek = '^%s$' % (arg.replace('*', '.*').replace('?','.'). \ + replace('%', '.*')) + gerald = self.connections[self.connection_number]['gerald'] + result = [] + for (name, obj) in gerald.schema.items(): + if hasattr(obj, 'type'): + dbtype = obj.type else: - direction = 'ASC' - orderby = 'last_ddl_time %s, %s' % (direction, orderby) - clauses['orderby'] = orderby - statement = ''' - SELECT object_type || '/' || %(owner)s object_name AS name %(moreColumns)s - FROM (%(source)s) source - %(where)s - ORDER BY %(orderby)s;''' % clauses - self.do_select(self.parsed(statement, - terminator=arg.parsed.terminator or ';', - suffix=arg.parsed.suffix)) + dbtype = str(type(obj)).rstrip("'>").split('.')[-1] + descriptor = '%s/%s' % (dbtype, name) + descriptor = descriptor.upper() + if (not arg) or \ + re.search(seek, descriptor, re.IGNORECASE) or \ + re.search(seek, name, re.IGNORECASE) or \ + re.search(seek, dbtype, re.IGNORECASE): + result.append(descriptor) + # if opts.long: status, last_ddl_time + result.sort(reverse=bool(opts.reverse)) + self.poutput('\n'.join(result)) @options([make_option('-i', '--ignore-case', dest='ignorecase', action='store_true', help='Case-insensitive search')]) def do_grep(self, arg, opts):
--- a/sqlpython/sqlpython.py Thu Aug 13 13:20:30 2009 -0400 +++ b/sqlpython/sqlpython.py Fri Aug 28 10:47:59 2009 -0400 @@ -8,9 +8,9 @@ # Best used with the companion modules sqlpyPlus and mysqlpy # See also http://twiki.cern.ch/twiki/bin/view/PSSGroup/SqlPython -import cmd2,getpass,binascii,cx_Oracle,re,os,platform -import sqlalchemy, pyparsing -__version__ = '1.6.7' +import cmd2,getpass,binascii,cx_Oracle,re,os +import sqlalchemy, pyparsing, schemagroup +__version__ = '1.7.0' class Parser(object): comment_def = "--" + ~ ('-' + pyparsing.CaselessKeyword('begin')) + pyparsing.ZeroOrMore(pyparsing.CharsNotIn("\n")) @@ -98,9 +98,14 @@ def url_connect(self, arg): eng = sqlalchemy.create_engine(arg) self.conn = eng.connect().connection + user = eng.url.username or '' + rdbms = eng.url.drivername conn = {'conn': self.conn, 'prompt': self.prompt, 'dbname': eng.url.database, - 'rdbms': eng.url.drivername, 'user': eng.url.username or '', - 'eng': eng} + 'rdbms': rdbms, 'user': user, 'eng': eng, + 'schemas': schemagroup.schemagroup(rdbms, arg, + self.conn, user)} + s = conn['schemas'] + s.refresh() return conn def ora_connect(self, arg): modeval = 0