# HG changeset patch # User catherine@bothari # Date 1258743331 18000 # Node ID dd9aab26479872e5a6c4454b1fdf3f487f83fbe9 # Parent eb7cbbb003956b72a976d0c192e6d07567295e4d mysql logons mostly work diff -r eb7cbbb00395 -r dd9aab264798 sqlpython/schemagroup.py --- a/sqlpython/schemagroup.py Thu Nov 19 20:29:08 2009 -0500 +++ b/sqlpython/schemagroup.py Fri Nov 20 13:55:31 2009 -0500 @@ -67,13 +67,14 @@ curs = connection.cursor() curs.execute("""SELECT '%s', current_time""" % username) return curs + # TODO: we just assume that we always need a refresh - that's sloppy class MySQLSchemaAccess(object): child_type = gerald.MySQLSchema - current_database_time_query = 'SELECT sysdate FROM dual' + current_database_time_query = 'SELECT now()' def latest_ddl_timestamp_query(self, username, connection): curs = connection.cursor() - curs.execute("""SELECT '%s', current_time""" % username) + curs.execute("""SELECT '%s', now()""" % username) return curs class SchemaDict(dict): diff -r eb7cbbb00395 -r dd9aab264798 sqlpython/sqlpyPlus.py --- a/sqlpython/sqlpyPlus.py Thu Nov 19 20:29:08 2009 -0500 +++ b/sqlpython/sqlpyPlus.py Fri Nov 20 13:55:31 2009 -0500 @@ -675,8 +675,6 @@ varname = args.lower().split()[0] self.substvars[varname] = self.pseudo_raw_input(prompt) - #TODO: double-ampersand not working - #substvars not remembered b/t queries def ampersand_substitution(self, raw, regexpr, isglobal): subst = regexpr.search(raw) while subst: @@ -1263,6 +1261,7 @@ idx['type'], (idx['unique'] and 'unique') or '') def _str_constraint(self, cons, long=False): + #TODO: this is way too unclear right now if 'condition' in cons: details = '(%s)' % cons['condition'] elif 'reftable' in cons: @@ -1665,53 +1664,9 @@ def do_refs(self, arg): '''Lists referential integrity (foreign key constraints) on an object or referring to it.''' - if not arg.strip(): - self.perror('Usage: refs (table name)') - result = [] - (type, owner, table_name) = self.resolve(arg.upper()) - sql = """SELECT constraint_name, r_owner, r_constraint_name - FROM all_constraints - WHERE constraint_type = 'R' - AND owner = :owner - AND table_name = :table_name""" - self._execute(sql, {"owner": owner, "table_name": table_name}) - for (constraint_name, remote_owner, remote_constraint_name) in self.curs.fetchall(): - result.append('%s on %s.%s:' % (constraint_name, owner, table_name)) - - self._execute("SELECT column_name FROM all_cons_columns WHERE owner = :owner AND constraint_name = :constraint_name ORDER BY position", - {'constraint_name': constraint_name, 'owner': owner}) - result.append(" (%s)" % (",".join(col[0] for col in self.curs.fetchall()))) - self._execute("SELECT table_name FROM all_constraints WHERE owner = :remote_owner AND constraint_name = :remote_constraint_name", - {'remote_owner': remote_owner, 'remote_constraint_name': remote_constraint_name}) - remote_table_name = self.curs.fetchone()[0] - result.append("must be in %s:" % (remote_table_name)) - self._execute("SELECT column_name FROM all_cons_columns WHERE owner = :remote_owner AND constraint_name = :remote_constraint_name ORDER BY position", - {'remote_constraint_name': remote_constraint_name, 'remote_owner': remote_owner}) - result.append(' (%s)\n' % (",".join(col[0] for col in self.curs.fetchall()))) - remote_table_name = table_name - remote_owner = owner - self._execute("""SELECT owner, constraint_name, table_name, r_constraint_name - FROM all_constraints - WHERE (r_owner, r_constraint_name) IN - ( SELECT owner, constraint_name - FROM all_constraints - WHERE table_name = :remote_table_name - AND owner = :remote_owner )""", - {'remote_table_name': remote_table_name, 'remote_owner': remote_owner}) - for (owner, constraint_name, table_name, remote_constraint_name) in self.curs.fetchall(): - result.append('%s on %s.%s:' % (constraint_name, owner, table_name)) - self._execute("SELECT column_name FROM all_cons_columns WHERE owner = :owner AND constraint_name = :constraint_name ORDER BY position", - {'constraint_name': constraint_name, 'owner': owner}) - result.append(" (%s)" % (",".join(col[0] for col in self.curs.fetchall()))) - self._execute("SELECT table_name FROM all_constraints WHERE owner = :remote_owner AND constraint_name = :remote_constraint_name", - {'remote_owner': remote_owner, 'remote_constraint_name': remote_constraint_name}) - remote_table_name = self.curs.fetchone()[0] - result.append("must be in %s:" % (remote_table_name)) - self._execute("SELECT column_name FROM all_cons_columns WHERE owner = :remote_owner AND constraint_name = :remote_constraint_name ORDER BY position", - {'remote_constraint_name': remote_constraint_name, 'remote_owner': remote_owner}) - result.append(' (%s)\n' % (",".join(col[0] for col in self.curs.fetchall()))) - self.poutput('\n'.join(result) + "\n") - + # TODO: needs much polish + return self.do__dir_constraints(arg) + def _test(): import doctest doctest.testmod()