Skip to content

Commit

Permalink
[SQLLINE-310] !schemas command
Browse files Browse the repository at this point in the history
  • Loading branch information
snuyanzin committed Jul 10, 2019
1 parent a672fdf commit 8dac1a6
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/docbkx/manual.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1461,6 +1461,7 @@ sqlline> !help
!run Run a script from the specified file
!save Save the current variables and aliases
!scan Scan for installed JDBC drivers
!schemas List all the schemas in the database
!script Start saving a script to a file
!set Set a sqlline variable, or show its value
!sql Execute a SQL command
Expand Down Expand Up @@ -2733,6 +2734,52 @@ sqlline>
</refentry>
</section>

<section id="sect_command_schemas">
<title>schemas</title>
<refentry id="command_schemas">
<refmeta>
<refentrytitle>schemas</refentrytitle>
<manvolnum>1</manvolnum>
</refmeta>


<refnamediv>
<refname>schemas</refname>
<refpurpose>
List all the schemas in the database
</refpurpose>
</refnamediv>

<refsynopsisdiv>
<cmdsynopsis>
<command>!schemas</command>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
<title>Description</title>
<para>
List all the schemas in the database of the
current connection.
</para>
</refsect1>
<refsect1>
<title>Example of "schemas" command</title>
<screen>
0: jdbc:postgresql:thin:@localhost:5432:mydb> !schemas

+--------------------+---------------+
| table_schem | table_catalog |
+--------------------+---------------+
| information_schema | |
| pg_catalog | |
| public | |
+--------------------+---------------+

0: jdbc:postgresql:thin:@localhost:5432:mydb>
</screen>
</refsect1>
</refentry>
</section>
<section id="sect_command_script">
<title>script</title>
<refentry id="command_script">
Expand Down
1 change: 1 addition & 0 deletions src/main/java/sqlline/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ public Collection<CommandHandler> getCommandHandlers(SqlLine sqlLine) {
new ReflectiveCommandHandler(sqlLine, empty, "manual"),
new ReflectiveCommandHandler(sqlLine, tableCompleter, "importedkeys"),
new ReflectiveCommandHandler(sqlLine, empty, "procedures"),
new ReflectiveCommandHandler(sqlLine, empty, "schemas"),
new ReflectiveCommandHandler(sqlLine, empty, "tables"),
new ReflectiveCommandHandler(sqlLine, empty, "typeinfo"),
new ReflectiveCommandHandler(sqlLine, empty, "commandhandler"),
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/sqlline/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ public void tables(String line, DispatchCallback callback)
metadata("getTables", args, callback);
}

public void schemas(String line, DispatchCallback callback) {
metadata("getSchemas", Collections.emptyList(), callback);
}

public void typeinfo(String line, DispatchCallback callback) {
metadata("getTypeInfo", Collections.emptyList(), callback);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/sqlline/SqlLine.properties
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ help-rerun: Execute previous command from the history file
help-reset: Reset a sqlline variable
help-confirm: Require user to answer 'Are you sure?' before executing 'dangerous' commands (as defined by confirmPattern)
help-confirmPattern: Defines 'dangerous' commands that require user to answer 'Are you sure?' before proceeding (by default, DELETE and DROP)
help-schemas: List all the schemas in the database
variables:\
\n\
\nVariables:\
Expand Down
35 changes: 35 additions & 0 deletions src/main/resources/sqlline/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ save
save — Save the current preferences
scan
scan — Scan class path for JDBC drivers
schemas
schemas — List all the schemas in the database
script
script — Save executed commands to a file
set
Expand Down Expand Up @@ -223,6 +225,8 @@ run
run — Execute a command script
save
save — Save the current preferences
schemas
schemas — List all the schemas in the database
scan
scan — Scan class path for JDBC drivers
script
Expand Down Expand Up @@ -450,6 +454,8 @@ run
run — Execute a command script
save
save — Save the current preferences
schemas
schemas — List all the schemas in the database
scan
scan — Scan class path for JDBC drivers
script
Expand Down Expand Up @@ -1102,6 +1108,7 @@ sqlline> !help
!rollback Roll back the current transaction (if autocommit is off)
!run Run a script from the specified file
!save Save the current variables and aliases
!schemas List all the schemas in the database
!scan Scan for installed JDBC drivers
!script Start saving a script to a file
!set Set a sqlline variable
Expand Down Expand Up @@ -1921,6 +1928,34 @@ yes 0.9 org.sourceforge.jxdbcon.JXDBConDriver

sqlline>

schemas

Name

schemas — List all the schemas in the database

Synopsis

!schemas

Description

List all the schemas in the database of the current connection.

Example of "schemas" command

0: jdbc:postgresql:thin:@localhost:5432:mydb> !schemas

+--------------------+---------------+
| table_schem | table_catalog |
+--------------------+---------------+
| information_schema | |
| pg_catalog | |
| public | |
+--------------------+---------------+

0: jdbc:postgresql:thin:@localhost:5432:mydb>

script

Name
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/sqlline/SqlLineArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,25 @@ public void testReconnect() {
containsString(expected));
}

@Test
public void testSchemas() {
// Set width so we don't inherit from the current terminal.
final String script = "!set maxwidth 80\n"
+ "!set maxcolumnwidth 15\n"
+ "!set incremental true\n"
+ "!schemas\n";
final String line0 =
"| TABLE_SCHEM | TABLE_CATALOG | IS_DEFAULT |";
final String line1 = "| INFORMATION_SCHEMA | PUBLIC | FALSE";
final String line2 = "| PUBLIC | PUBLIC | TRUE |";
final String line3 = "| SCOTT | PUBLIC | FALSE |";
final String line4 = "| SYSTEM_LOBS | PUBLIC | FALSE |";
checkScriptFile(script, true, equalTo(SqlLine.Status.OK),
allOf(containsString(line0), containsString(line1),
containsString(line2), containsString(line3),
containsString(line4)));
}

@Test
public void testTables() {
// Set width so we don't inherit from the current terminal.
Expand Down

0 comments on commit 8dac1a6

Please sign in to comment.