changeset 463:317c0bb8afa4

restrict commands by rdbms
author cat@eee
date Sat, 27 Feb 2010 23:15:30 -0500
parents c6394c335e45
children 26f60d5910a0
files sqlpython/mysqlpy.py sqlpython/sqlpyPlus.py sqlpython/sqlpython.py
diffstat 3 files changed, 20 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/mysqlpy.py	Wed Feb 24 13:24:35 2010 -0500
+++ b/sqlpython/mysqlpy.py	Sat Feb 27 23:15:30 2010 -0500
@@ -85,29 +85,26 @@
         where time_remaining>0;
         '''
        
-    def do_new(self, args):
-        'tells you about new objects'
-        self.onecmd('''SELECT owner,
-       object_name,
-       object_type
-FROM   all_objects
-WHERE  created > SYSDATE - 7;''')
     def do_top9i(self,args):
-        '''Runs query_top9i defined above, to display active sessions in Oracle 9i'''
+        '''Runs query_top9i defined above, to display active sessions in Oracle 9i
+           (Availability: Oracle)'''        
         self.onecmd(self.query_top9i)
     
     def do_top(self,args): 
-        '''Runs query_ractop defined above, to display active sessions in Oracle 10g (and RAC)'''
+        '''Runs query_ractop defined above, to display active sessions in Oracle 10g (and RAC)
+           (Availability: Oracle)'''
         self.onecmd(self.query_ractop)
 
     def do_longops(self,args):
-        '''Runs query_longops defined above, to display long running operations (full scans, etc)'''
+        '''Runs query_longops defined above, to display long running operations (full scans, etc)
+           (Availability: Oracle)'''        
         self.onecmd(self.query_longops)
         
     def do_load(self,args):
         '''Runs query_load10g defined above, to display OS load on cluster nodes (10gRAC)
 Do not confuse with `GET myfile.sql` and `@myfile.sql`,
-which get and run SQL scripts from disk.'''
+which get and run SQL scripts from disk.
+           (Availability: Oracle)'''
         self.onecmd(self.query_load10g)
                 
     def do_db(self,args,filepath='pass.txt'): 
@@ -145,7 +142,8 @@
             self.perror(e)
 
     def do_explain(self,args):
-        '''prints the plan of a given statement from the sql cache. 1 parameter: sql_id, see also do_sql '''
+        '''prints the plan of a given statement from the sql cache. 1 parameter: sql_id, see also do_sql
+           (Availability: Oracle)'''        
         words = args.split()
         if len(words) > 2 and words[0].lower() == 'plan' and words[1].lower() == 'for':
             self.curs.execute('explain %s' % args)
--- a/sqlpython/sqlpyPlus.py	Wed Feb 24 13:24:35 2010 -0500
+++ b/sqlpython/sqlpyPlus.py	Sat Feb 27 23:15:30 2010 -0500
@@ -391,7 +391,7 @@
         heading
         wildsql          Accept wildcards, position #s in column names
         version'''
-    
+        
     def __init__(self):
         sqlpython.sqlpython.__init__(self)
         self.binds = CaselessDict()
--- a/sqlpython/sqlpython.py	Wed Feb 24 13:24:35 2010 -0500
+++ b/sqlpython/sqlpython.py	Sat Feb 27 23:15:30 2010 -0500
@@ -165,6 +165,7 @@
     def do_pickle(self, arg):
         self.current_instance.pickle()
         
+    _availability_regex = re.compile(r'\(\s*Availab(.*)\)', re.IGNORECASE )        
     def postparsing_precmd(self, statement):
         stop = 0
         self.saved_instance_number = None
@@ -177,6 +178,14 @@
             except KeyError:
                 self.list_instances()
                 raise KeyError, 'No connection #%s' % statement.parsed.instance_number
+        try:
+            method = getattr(self, 'do_' + statement.parsed.command)
+            availability = self._availability_regex.search(method.__doc__ or '')
+            if availability and (self.current_instance.rdbms not in availability.group(1).lower()):
+                raise NotImplementedError, '``%s`` unavailable for %s' % (
+                    statement.parsed.command, self.current_instance.rdbms)
+        except AttributeError:
+            pass
         return stop, statement           
     def postparsing_postcmd(self, stop):
         if self.saved_instance_number is not None: