diff options
author | Marc G. Fournier <scrappy@hub.org> | 1998-01-25 06:09:40 +0000 |
---|---|---|
committer | Marc G. Fournier <scrappy@hub.org> | 1998-01-25 06:09:40 +0000 |
commit | 753f720cb8b9c8e66ab486b1b6a7379e472b9a7a (patch) | |
tree | 3cbdec737cb8c43c7969fe62c2fb1119e7d9e10f /src/interfaces/python/pgext.py | |
parent | 98018c4b93073ae7afb705a9ad93d461fbf07aa1 (diff) | |
download | postgresql-753f720cb8b9c8e66ab486b1b6a7379e472b9a7a.tar.gz postgresql-753f720cb8b9c8e66ab486b1b6a7379e472b9a7a.zip |
Merge in D'Arcy Cain's python interface (PyGreSQL 2.0)
Diffstat (limited to 'src/interfaces/python/pgext.py')
-rw-r--r-- | src/interfaces/python/pgext.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/interfaces/python/pgext.py b/src/interfaces/python/pgext.py new file mode 100644 index 00000000000..97c7e342bfc --- /dev/null +++ b/src/interfaces/python/pgext.py @@ -0,0 +1,43 @@ +from pg import * + +# This library file contains some common functions not directly provided by the +# PostGres C library. It offers too a keyword interface for pgmodule connect +# function. + +# encapsulate pg connect function for keywords enabling +def doconnect(dbname = None, host = None, port = None, opt = None, tty = None): + return connect(dbname, host, port, opt, tty) + +# list all databases on the server +def ListDB(pgcnx): + result = pgcnx.query("select datname from pg_database") + list = [] + for node in result: + list.append(result[i][0]) + return list + +# list all tables (classes) in the selected database +def ListTables(pgcnx): + result = pgcnx.query("select relname from pg_class " \ + "where relkind = 'r' " \ + " and relname !~ '^Inv' " \ + " and relname !~ '^pg_'") + list = [] + for node in result: + list.append(node[0]) + return list + +# list table fields (attribute) in given table +def ListAllFields(pgcnx, table): + result = pgcnx.query("select c.relname, a.attname, t.typname " \ + "from pg_class c, pg_attribute a, pg_type t " \ + "where c.relname = '%s' " \ + " and a.attnum > 0" \ + " and a.attrelid = c.oid" \ + " and a.atttypid = t.oid " \ + "order by relname, attname" % table) + # personnal preference ... so I leave the original query + list = [] + for node in result: + list.append(node[1], node[2]) + return list |