I went a little further and came up with another extension to the command 
SHOW TABLES.

1) The ability to tell how the column should be named.
2) A way to filter on table names.

Have a look and comment.

/Jacob

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/h2-database/-/mA3GOm_xEeEJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Index: src/main/org/h2/command/Parser.java
===================================================================
--- src/main/org/h2/command/Parser.java	(revision 4218)
+++ src/main/org/h2/command/Parser.java	(working copy)
@@ -849,12 +850,31 @@
             buff.append("'UTF8' AS SERVER_ENCODING FROM DUAL");
         } else if (readIf("TABLES")) {
             // for MySQL compatibility
-            String schema = Constants.SCHEMA_MAIN;
+            String schema = session.getCurrentSchemaName();
+            String tableNameAlias = "TABLE_NAME";
+            String schemaNameAlias = "TABLE_SCHEMA";
+            if (readIf("AS")) {
+            	tableNameAlias = readUniqueIdentifier();
+            	if (readIf(",")) {
+            		schemaNameAlias = readUniqueIdentifier();
+            	}
+            }
             if (readIf("FROM")) {
                 schema = readUniqueIdentifier();
             }
-            buff.append("TABLE_NAME, TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=? ORDER BY TABLE_NAME");
+            Expression like = null;
+            if (readIf("LIKE")) {
+                like = readConcat();
+            }
+            buff.append("TABLE_NAME AS ").append(tableNameAlias).append(", ").append("TABLE_SCHEMA AS ").append(schemaNameAlias).append(" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=?");
+            if (like != null) {
+            	buff.append(" AND TABLE_NAME LIKE ?");
+            }
+            buff.append(" ORDER BY TABLE_NAME");
             paramValues.add(ValueString.get(schema));
+            if (like != null) {
+            	paramValues.add(like.getValue(session));
+            }
         } else if (readIf("COLUMNS")) {
             // for MySQL compatibility
             read("FROM");

Reply via email to