comparison src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java @ 907:cc6425e98017

Implement DatabaseMetaData.getClientInfoProperties
author Joeri van Ruth <joeri.van.ruth@monetdbsolutions.com>
date Tue, 18 Jun 2024 10:55:15 +0200 (10 months ago)
parents be8476c1acec
children a8ca336e7f1a
comparison
equal deleted inserted replaced
906:8c8c423dc619 907:cc6425e98017
9 * Copyright August 2008 - 2023 MonetDB B.V.; 9 * Copyright August 2008 - 2023 MonetDB B.V.;
10 * Copyright 1997 - July 2008 CWI. 10 * Copyright 1997 - July 2008 CWI.
11 */ 11 */
12 12
13 package org.monetdb.jdbc; 13 package org.monetdb.jdbc;
14
15 import org.monetdb.mcl.net.ClientInfo;
14 16
15 import java.sql.Connection; 17 import java.sql.Connection;
16 import java.sql.DatabaseMetaData; 18 import java.sql.DatabaseMetaData;
17 import java.sql.Statement; 19 import java.sql.Statement;
18 import java.sql.SQLException; 20 import java.sql.SQLException;
3915 * @return A ResultSet object; each row is a supported client info property 3917 * @return A ResultSet object; each row is a supported client info property
3916 * @throws SQLException if a database access error occurs 3918 * @throws SQLException if a database access error occurs
3917 */ 3919 */
3918 @Override 3920 @Override
3919 public ResultSet getClientInfoProperties() throws SQLException { 3921 public ResultSet getClientInfoProperties() throws SQLException {
3920 // MonetDB currently does not support any client properties, so return an empty ResultSet 3922 // This query combines the properties we know about with any additional properties that
3923 // may have been added to sys.clientinfo_properties in the mean time.
3921 final String query = 3924 final String query =
3922 "SELECT cast(null as varchar(64)) AS \"NAME\", " + 3925 "WITH jdbc_info AS (\n" +
3923 "cast(0 as int) AS \"MAX_LEN\", " + 3926 " SELECT 'ApplicationName' AS \"NAME\", NULL AS \"MAX_LEN\", " + stringEscape(ClientInfo.defaultApplicationName) + " AS \"DEFAULT_VALUE\", 'Name of the application' AS \"DESCRIPTION\", 0 AS i\n" +
3924 "cast(null as varchar(128)) AS \"DEFAULT_VALUE\", " + 3927 " UNION ALL\n" +
3925 "cast(null as varchar(128)) AS \"DESCRIPTION\" " + 3928 " SELECT 'ClientHostname' AS \"NAME\", NULL AS \"MAX_LEN\", " + stringEscape(ClientInfo.defaultHostname) + " AS \"DEFAULT_VALUE\", 'Host the application is running on' AS \"DESCRIPTION\", 1 AS i\n" +
3926 "WHERE 1=0"; 3929 " UNION ALL\n" +
3930 " SELECT 'ClientRemark' AS \"NAME\", 256 AS \"MAX_LEN\", R'' AS \"DEFAULT_VALUE\", 'Additional information' AS \"DESCRIPTION\", 2 AS i\n" +
3931 " UNION ALL\n" +
3932 " SELECT 'ClientLibrary' AS \"NAME\", NULL AS \"MAX_LEN\", " + stringEscape(ClientInfo.defaultClientLibrary) + " AS \"DEFAULT_VALUE\", 'Name and version of the driver' AS \"DESCRIPTION\", 3 AS i\n" +
3933 " UNION ALL\n" +
3934 " SELECT 'ClientPid' AS \"NAME\", 10 AS \"MAX_LEN\", " + stringEscape(ClientInfo.defaultPid) + " AS \"DEFAULT_VALUE\", 'Process id of the application' AS \"DESCRIPTION\", 4 AS i\n" +
3935 ")\n" +
3936 "SELECT\n" +
3937 " prop AS \"NAME\",\n" +
3938 " COALESCE(\"MAX_LEN\", 24) AS \"MAX_LEN\",\n" +
3939 " \"DEFAULT_VALUE\",\n" +
3940 " \"DESCRIPTION\"\n" +
3941 "FROM sys.clientinfo_properties AS sys_info LEFT OUTER JOIN jdbc_info ON prop = \"NAME\"\n" +
3942 "ORDER BY COALESCE(i, 1000), \"NAME\"\n"
3943 ;
3927 3944
3928 return executeMetaDataQuery(query); 3945 return executeMetaDataQuery(query);
3946 }
3947
3948 private static String stringEscape(String s) {
3949 return "R'" + s.replaceAll("'", "''") + "'";
3929 } 3950 }
3930 3951
3931 /** 3952 /**
3932 * Retrieves a description of the system and user functions 3953 * Retrieves a description of the system and user functions
3933 * available in the given catalog. 3954 * available in the given catalog.