Mercurial > sqlpython
changeset 525:4ec9438c0036
show finally working on mysql
author | Catherine Devlin <catherine.devlin@gmail.com> |
---|---|
date | Sat, 20 Nov 2010 09:16:18 -0500 |
parents | 96803d93b9ae |
children | 0b83bc94a1a1 |
files | sqlpython/connections.py sqlpython/sqlpyPlus.py |
diffstat | 2 files changed, 21 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/sqlpython/connections.py Thu Nov 18 18:47:37 2010 -0500 +++ b/sqlpython/connections.py Sat Nov 20 09:16:18 2010 -0500 @@ -300,7 +300,7 @@ class MySQLInstance(DatabaseInstance): rdbms = 'mysql' default_port = 3306 - paramstyle = 'qmark' + paramstyle = 'format' def set_defaults(self): self.port = self.default_port self.hostname = 'localhost' @@ -332,6 +332,7 @@ AND table_type %(type_op)s UPPER(%(type)S) AND table_name %(name_op)s LOWER(%(name)S) ORDER BY table_schema, table_type, table_name %(sort_direction)s""" + parameter_qry = """SHOW variables LIKE '%%%s%%'%s""" gerald_types = {'TABLE': gerald.mysql_schema.Table, 'VIEW': gerald.mysql_schema.View, 'BASE TABLE': gerald.mysql_schema.Table, @@ -376,7 +377,7 @@ FROM information_schema.routines r WHERE ( (r.routine_schema %(owner_op)s LOWER(%(owner)S)) OR (r.routine_schema = 'public') ) AND LOWER(r.routine_definition) LIKE %(text)S""" - parameter_qry = """SELECT name, unit, setting FROM pg_settings WHERE name LIKE LOWER('%%%s%%');""" + parameter_qry = """SELECT name, unit, setting FROM pg_settings WHERE name LIKE LOWER('%%%s%%')%s""" gerald_types = {'BASE TABLE': gerald.postgres_schema.Table, 'VIEW': gerald.postgres_schema.View} @@ -446,7 +447,7 @@ WHEN 6 THEN 'BIG INTEGER' END type, value FROM v$parameter - WHERE name LIKE LOWER('%%%s%%');""" + WHERE name LIKE LOWER('%%%s%%')%s""" def source(self, target, opts): return self._source(target, opts) def bindSyntax(self, varname):
--- a/sqlpython/sqlpyPlus.py Thu Nov 18 18:47:37 2010 -0500 +++ b/sqlpython/sqlpyPlus.py Sat Nov 20 09:16:18 2010 -0500 @@ -783,7 +783,7 @@ selecttext = self.expandWildSql(arg) else: selecttext = arg - self.querytext = 'select ' + selecttext + self.querytext = '%s %s' % (arg.parsed.command, selecttext) if self.varsUsed: self.curs.execute(self.querytext, self.varsUsed) else: # this is an ugly workaround for the evil paramstyle curse upon DB-API2 @@ -905,6 +905,11 @@ except IndexError: newarg = '' return self.onecmd(self.parsed(shortcut + ' ' + newarg)) + + def _param_select(self, arg, seekme): + seekme = seekme.replace('*','%').replace('?','_') + query = self.parsed(self.current_instance.parameter_qry % (seekme, arg.parsed.terminator or ';')) + return self.do_select(query) def do_show(self, arg): ''' @@ -915,11 +920,8 @@ show all err (type/name) - all compilation errors from the user's PL/SQL objects. show (index/schema/tablespace/trigger/view/constraint/comment) on (table) ''' - arg = arg.strip().replace('*', '%').replace('?', '_') - if not arg: + if not arg.strip(): return Cmd.do_show(self, arg) - if arg.lower().startswith('param'): - arg = ' '.join(arg.split()[1:]) or '%' else: argpieces = arg.lower().split() argpieces = [a for a in argpieces if not a.startswith('-')] @@ -936,10 +938,19 @@ return self.do_ls('table/*') elif (argpieces[0], argpieces[1:2][:3]) == ('all','err'): return self._show_errors(all_users=False, limit=None, targets=argpieces[2:]) + elif argpieces[0].startswith('variable') or argpieces[0].startswith('param'): + argpieces.pop(0) + if argpieces[:1] == ['like']: + argpieces.pop(0) + if argpieces: + target = argpieces[0] + else: + target = '%' + return self._param_select(arg, target.strip("'")) try: return Cmd.do_show(self, arg) except NotImplementedError: - return self.onecmd(self.current_instance.parameter_qry % arg) + return self._param_select(arg, arg) def _vc(self, arg, opts, program): if not os.path.exists('.%s' % program):