Skip to content

Commit e938d8f

Browse files
committed
Extend JdbcClient welcome message with server product release string, same as done by mclient.
For this MonetConnection is extended with public method getServerProductRelease().
1 parent 4e66424 commit e938d8f

2 files changed

Lines changed: 35 additions & 12 deletions

File tree

src/main/java/org/monetdb/client/JdbcClient.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ public final static void main(String[] args) throws Exception {
410410
// we only want user tables and views to be dumped (DDL and optional data), unless a specific table is requested
411411
final String[] types = {"TABLE","VIEW","MERGE TABLE","REMOTE TABLE","REPLICA TABLE","STREAM TABLE"};
412412
// Future: fetch all type names using dbmd.getTableTypes() and construct String[] with all
413-
// table type names excluding the SYSTEM ... ones and LOCAL TEMPORARY TABLE ones.
413+
// table type names excluding the SYSTEM ... ones and LOCAL TEMPORARY TABLE/VIEW ones.
414414

415415
// request the list of tables/views available in the current schema in the database
416416
ResultSet tbl = dbmd.getTables(null, con.getSchema(), null, (argcount == 0) ? types : null);
@@ -558,14 +558,17 @@ public final static void main(String[] args) throws Exception {
558558
} else {
559559
if (!copts.getOption("quiet").isPresent()) {
560560
// print welcome message
561-
out.println("Welcome to the MonetDB interactive JDBC terminal!");
561+
out.println("Welcome to JdbcClient, the MonetDB interactive SQL client");
562562
if (dbmd != null) {
563-
out.println("JDBC Driver: " + dbmd.getDriverName() +
563+
String monet_release = "";
564+
if (con instanceof MonetConnection)
565+
monet_release = ((MonetConnection) con).getServerProductRelease();
566+
out.println("Using JDBC Driver: " + dbmd.getDriverName() +
564567
" v" + dbmd.getDriverVersion());
565-
out.println("Database Server: " + dbmd.getDatabaseProductName() +
566-
" v" + dbmd.getDatabaseProductVersion());
568+
out.println("Connected Server : " + dbmd.getDatabaseProductName() +
569+
" v" + dbmd.getDatabaseProductVersion() + " " + monet_release);
567570
}
568-
out.println("Current Schema: " + con.getSchema());
571+
out.println("Current Schema : \"" + con.getSchema() + "\"");
569572
out.println("Type \\q to quit (you can also use: quit or exit), \\? or \\h for a list of available commands");
570573
out.flush();
571574
}

src/main/java/org/monetdb/jdbc/MonetConnection.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,15 +1786,16 @@ String getJDBCURL() {
17861786
return target.buildUrl();
17871787
}
17881788

1789-
// Internal caches for 4 static mserver5 environment values
1789+
// Internal caches for 5 static mserver5 environment values
17901790
private String env_current_user;
17911791
private String env_monet_version;
1792+
private String env_monet_release;
17921793
private String env_raw_strings; // Note: this is only supported from Jun2020 (11.37) servers
17931794
private int maxConnections;
17941795

17951796
/**
1796-
* Utility method to fetch 4 mserver5 environment values combined in one query for efficiency.
1797-
* We fetch the env values of: current_user, monet_version, max_clients and raw_strings.
1797+
* Utility method to fetch 5 mserver5 environment values combined in one query for efficiency.
1798+
* We fetch the env() values of: current_user, monet_version, monet_release, max_clients and raw_strings.
17981799
* We cache them such that we do not need to query the server again and again.
17991800
* Note: raw_strings is available in sys.env() result set since release Jun2020 (11.37)
18001801
*
@@ -1808,7 +1809,7 @@ private synchronized void getEnvValues() throws SQLException {
18081809
if (st != null) {
18091810
rs = st.executeQuery(
18101811
"SELECT \"name\", \"value\" FROM \"sys\".\"env\"()" +
1811-
" WHERE \"name\" IN ('monet_version', 'max_clients', 'raw_strings')" +
1812+
" WHERE \"name\" IN ('monet_version', 'monet_release', 'max_clients', 'raw_strings')" +
18121813
" UNION SELECT 'current_user' as \"name\", current_user as \"value\"");
18131814
if (rs != null) {
18141815
while (rs.next()) {
@@ -1820,6 +1821,9 @@ private synchronized void getEnvValues() throws SQLException {
18201821
if ("monet_version".equals(prop)) {
18211822
env_monet_version = value;
18221823
} else
1824+
if ("monet_release".equals(prop)) {
1825+
env_monet_release = value;
1826+
} else
18231827
if ("raw_strings".equals(prop)) {
18241828
env_raw_strings = value;
18251829
} else
@@ -1839,7 +1843,7 @@ private synchronized void getEnvValues() throws SQLException {
18391843
} finally {
18401844
closeResultsetStatement(rs, st);
18411845
}
1842-
// for debug: System.out.println("Read: env_current_user: " + env_current_user + " env_monet_version: " + env_monet_version + " env_max_clients: " + maxConnections + " env_raw_strings: " + env_raw_strings);
1846+
// for debug: System.out.println("Read: env_current_user: " + env_current_user + " env_monet_version: " + env_monet_version + " env_monet_release: " + env_monet_release + " env_max_clients: " + maxConnections + " env_raw_strings: " + env_raw_strings);
18431847
}
18441848

18451849
/**
@@ -1893,6 +1897,22 @@ boolean inRawStringsMode() throws SQLException {
18931897
return "true".equals(env_raw_strings);
18941898
}
18951899

1900+
/**
1901+
* Get the product release of the connected MonetDB server.
1902+
* It is called from JdbcClient, hence it is made public.
1903+
*
1904+
* @return the MonetDB server release string.
1905+
* @throws SQLException if fetching MonetDB server release string failed
1906+
*/
1907+
public String getServerProductRelease() throws SQLException {
1908+
if (env_monet_release == null)
1909+
getEnvValues();
1910+
if (env_monet_version != null)
1911+
return env_monet_release;
1912+
// always return a valid String to prevent NPE
1913+
return "";
1914+
}
1915+
18961916
/**
18971917
* Get the product version of the connected MonetDB Database Server.
18981918
* It is called from: MonetDatabaseMetaData
@@ -1903,9 +1923,9 @@ boolean inRawStringsMode() throws SQLException {
19031923
String getDatabaseProductVersion() throws SQLException {
19041924
if (env_monet_version == null)
19051925
getEnvValues();
1906-
// always return a valid String to prevent NPE in getTables() and getTableTypes()
19071926
if (env_monet_version != null)
19081927
return env_monet_version;
1928+
// always return a valid String to prevent NPE in getTables() and getTableTypes()
19091929
return "";
19101930
}
19111931

0 commit comments

Comments
 (0)