# HG changeset patch # User catherine@cordelia # Date 1251900686 14400 # Node ID fe0051d7f93422be4e3e8aa8e1c5796bbc2d28fe # Parent a70adadca4d8bff3b0775faec856d3e084a0bec2 further gerald experiments diff -r a70adadca4d8 -r fe0051d7f934 sqlpython/schemagroup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sqlpython/schemagroup.py Wed Sep 02 10:11:26 2009 -0400 @@ -0,0 +1,50 @@ +import gerald, re + +def schemagroup(rdbms, connstr, connection, user): + gerald_connstring = connstr.split('/?mode=')[0].replace('//','/') + if rdbms == 'oracle': + childtype = OracleSchemaGroup + grp = childtype(gerald_connstring, connection, user) + return grp + +class SchemaGroup(object): + def __init__(self, gerald_connstring, connection, user): + self.connstring = gerald_connstring + self.connection = connection + self.cursor = connection.cursor() + self.user = user + def refresh(self): + now = self.schemas[self.user].time() + for schemaname in self.all_schemanames(): + if ((schemaname not in self.schemas) or + (self.schemas[schemaname].age() < now) + ): + self.schemas[schemaname] = self.childtype(schemaname, + self) + + +class OracleSchema(gerald.OracleSchema): + def __init__(self, schemaname, parent_group): + self.parent_group = parent_group + gerald.OracleSchema.__init__(self, schemaname, + self.parent_group.connstring) + self.refreshed = self.time() + def time(self): + self.parent_group.cursor.execute('SELECT sysdate FROM dual') + return self.parent_group.cursor.fetchone()[0] + def age(self): + self.parent_group.cursor.execute('''SELECT max(last_ddl_time) + FROM all_objects + WHERE owner = :owner''', + {'owner': self.name}) + return self.parent_group.cursor.fetchone()[0] + +class OracleSchemaGroup(SchemaGroup): + childtype = OracleSchema + def __init__(self, connection_string, connection, user): + SchemaGroup.__init__(self, connection_string, connection, user) + self.schemas = {user: OracleSchema(user, self)} + def all_schemanames(self): + self.cursor.execute('SELECT DISTINCT owner FROM all_objects') + return [r[0] for r in self.cursor.fetchall()] + \ No newline at end of file diff -r a70adadca4d8 -r fe0051d7f934 sqlpython/sqlpython.py --- a/sqlpython/sqlpython.py Fri Aug 28 10:47:59 2009 -0400 +++ b/sqlpython/sqlpython.py Wed Sep 02 10:11:26 2009 -0400 @@ -8,7 +8,7 @@ # 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 +import cmd2, getpass, binascii, cx_Oracle, re, os, platform import sqlalchemy, pyparsing, schemagroup __version__ = '1.7.0'