Browse Source

[dbquery] List all the schemas in a Postgres database

We were only listing the databse name and no tables/columns so far.
Fix a serializing problem with date result.
Romain Rigaux 10 years ago
parent
commit
4a74e08

+ 2 - 0
apps/rdbms/src/rdbms/api.py

@@ -44,6 +44,8 @@ class ResultEncoder(json.JSONEncoder):
   def default(self, obj):
     if isinstance(obj, datetime.datetime):
       return obj.strftime('%Y-%m-%d %H:%M:%S %Z')
+    elif isinstance(obj, datetime.date):
+      return obj.strftime('%Y-%m-%d %Z')
     return super(ResultEncoder, self).default(obj)
 
 

+ 5 - 2
desktop/libs/librdbms/src/librdbms/server/postgresql_lib.py

@@ -82,11 +82,14 @@ class PostgreSQLClient(BaseRDMSClient):
 
 
   def get_databases(self):
-    return [self._conn_params['database']]
+    # List all the schemas in the database
+    cursor = self.connection.cursor()
+    cursor.execute('SELECT schema_name FROM information_schema.schemata')
+    self.connection.commit()
+    return [row[0] for row in cursor.fetchall()]
 
 
   def get_tables(self, database, table_names=[]):
-    # Doesn't use database and only retrieves tables for database currently in use.
     cursor = self.connection.cursor()
     cursor.execute("SELECT table_name FROM information_schema.tables WHERE table_schema='%s'" % database)
     self.connection.commit()