--- a/pgtoolkit/pgbrowser.py Fri Oct 05 14:31:25 2012 +0200
+++ b/pgtoolkit/pgbrowser.py Tue Dec 11 10:49:42 2012 +0100
@@ -39,7 +39,7 @@
self.hasdefault = hasdefault
self.default = default
self.description = description
-
+
class Constraint:
def __init__(self, browser, table, name, type, fname, fschema, definition):
@@ -89,7 +89,7 @@
def refresh_constraints(self):
rows = self.browser.list_constraints(self.name, self.schema.name)
self._constraints = OrderedDict([(x['name'], Constraint(self.browser, self, **x)) for x in rows])
-
+
def refresh_indexes(self):
rows = self.browser.list_indexes(self.name, self.schema.name)
self._indexes = OrderedDict([(x['name'], Index(self.browser, self, **x)) for x in rows])
@@ -99,13 +99,13 @@
self.refresh_columns()
return self._columns
columns = property(getcolumns)
-
+
def getconstraints(self):
if self._constraints is None:
self.refresh_constraints()
return self._constraints
constraints = property(getconstraints)
-
+
def getindexes(self):
if self._indexes is None:
self.refresh_indexes()
@@ -124,7 +124,7 @@
def refresh(self):
rows = self.browser.list_tables(self.name)
- self._tables = OrderedDict([(x['name'], Table(self.browser, self, **x)) for x in rows])
+ self._tables = OrderedDict([(x['name'], Table(self.browser, self, **x)) for x in rows])
def gettables(self):
if self._tables is None:
@@ -137,10 +137,10 @@
def __init__(self, conn=None):
self._schemas = None
self.conn = conn
-
+
def setconn(self, conn=None):
self.conn = conn
-
+
def refresh(self):
rows = self.list_schemas()
self._schemas = OrderedDict([(x['name'], Schema(self, **x)) for x in rows])
@@ -150,7 +150,7 @@
self.refresh()
return self._schemas
schemas = property(getschemas)
-
+
def _query(self, query, args):
try:
curs = self.conn.cursor()
@@ -218,7 +218,7 @@
format_type(a.atttypid, a.atttypmod) AS "type",
a.attnotnull as "notnull",
a.atthasdef as "hasdefault",
- d.adsrc as "default",
+ pg_catalog.pg_get_expr(d.adbin, d.adrelid) as "default",
pg_catalog.col_description(a.attrelid, a.attnum) AS "description"
FROM pg_catalog.pg_attribute a
LEFT JOIN pg_catalog.pg_class c ON a.attrelid = c.oid
@@ -283,20 +283,20 @@
def list_column_usage(self, table, column, schema='public'):
'''List objects using the column.
-
+
Currently shows views and constraints which use the column.
-
+
This is useful to find which views block alteration of column type etc.
-
+
'''
return self._query('''
SELECT
'view' AS type, view_schema AS schema, view_name AS name
FROM information_schema.view_column_usage
WHERE table_schema=%(schema)s AND table_name=%(table)s AND column_name=%(column)s
-
+
UNION
-
+
SELECT
'constraint' AS type, constraint_schema AS schema, constraint_name AS name
FROM information_schema.constraint_column_usage