1010
1111import java .sql .Connection ;
1212import java .sql .DatabaseMetaData ;
13+ import java .sql .DriverPropertyInfo ;
1314import java .sql .JDBCType ;
1415import java .sql .PreparedStatement ;
1516import java .sql .ResultSet ;
1617import java .sql .RowIdLifetime ;
1718import java .sql .SQLException ;
18- import java .sql .SQLFeatureNotSupportedException ;
1919import java .util .ArrayList ;
2020import java .util .List ;
2121
22+ import static java .sql .JDBCType .BIGINT ;
23+ import static java .sql .JDBCType .BOOLEAN ;
2224import static java .sql .JDBCType .INTEGER ;
2325import static java .sql .JDBCType .SMALLINT ;
2426import static org .elasticsearch .xpack .sql .client .StringUtils .EMPTY ;
@@ -664,8 +666,7 @@ public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
664666 // https://www.postgresql.org/docs/9.0/static/infoschema-routines.html
665667 @ Override
666668 public ResultSet getProcedures (String catalog , String schemaPattern , String procedureNamePattern ) throws SQLException {
667- return emptySet (con .cfg ,
668- "ROUTINES" ,
669+ return emptySet (con .cfg , "ROUTINES" ,
669670 "PROCEDURE_CAT" ,
670671 "PROCEDURE_SCHEM" ,
671672 "PROCEDURE_NAME" ,
@@ -680,8 +681,7 @@ public ResultSet getProcedures(String catalog, String schemaPattern, String proc
680681 @ Override
681682 public ResultSet getProcedureColumns (String catalog , String schemaPattern , String procedureNamePattern , String columnNamePattern )
682683 throws SQLException {
683- return emptySet (con .cfg ,
684- "PARAMETERS" ,
684+ return emptySet (con .cfg , "ROUTINES_COLUMNS" ,
685685 "PROCEDURE_CAT" ,
686686 "PROCEDURE_SCHEM" ,
687687 "PROCEDURE_NAME" ,
@@ -775,14 +775,14 @@ public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLExce
775775 public ResultSet getCatalogs () throws SQLException {
776776 // TABLE_CAT is the first column
777777 Object [][] data = queryColumn (con , "SYS TABLES CATALOG LIKE '%'" , 1 );
778- return memorySet (con .cfg , columnInfo ("" , "TABLE_CAT" ), data );
778+ return memorySet (con .cfg , columnInfo ("CATALOGS " , "TABLE_CAT" ), data );
779779 }
780780
781781 @ Override
782782 public ResultSet getTableTypes () throws SQLException {
783783 // TABLE_TYPE (4)
784784 Object [][] data = queryColumn (con , "SYS TABLES TYPE '%'" , 4 );
785- return memorySet (con .cfg , columnInfo ("" , "TABLE_TYPE" ), data );
785+ return memorySet (con .cfg , columnInfo ("TABLE_TYPES " , "TABLE_TYPE" ), data );
786786 }
787787
788788 @ Override
@@ -798,43 +798,128 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa
798798
799799 @ Override
800800 public ResultSet getColumnPrivileges (String catalog , String schema , String table , String columnNamePattern ) throws SQLException {
801- throw new SQLFeatureNotSupportedException ("Privileges not supported" );
801+ return emptySet (con .cfg , "" ,
802+ "TABLE_CAT" ,
803+ "TABLE_SCHEM" ,
804+ "TABLE_NAME" ,
805+ "COLUMN_NAME" ,
806+ "GRANTOR" ,
807+ "GRANTEE" ,
808+ "PRIVILEGE" ,
809+ "IS_GRANTABLE" );
802810 }
803811
804812 @ Override
805813 public ResultSet getTablePrivileges (String catalog , String schemaPattern , String tableNamePattern ) throws SQLException {
806- throw new SQLFeatureNotSupportedException ("Privileges not supported" );
814+ return emptySet (con .cfg , "" ,
815+ "TABLE_CAT" ,
816+ "TABLE_SCHEM" ,
817+ "TABLE_NAME" ,
818+ "GRANTOR" ,
819+ "GRANTEE" ,
820+ "PRIVILEGE" ,
821+ "IS_GRANTABLE" );
807822 }
808823
809824 @ Override
810825 public ResultSet getBestRowIdentifier (String catalog , String schema , String table , int scope , boolean nullable ) throws SQLException {
811- throw new SQLFeatureNotSupportedException ("Row identifiers not supported" );
826+ return emptySet (con .cfg , "" ,
827+ "SCOPE" , SMALLINT ,
828+ "COLUMN_NAME" ,
829+ "DATA_TYPE" , INTEGER ,
830+ "TYPE_NAME" ,
831+ "COLUMN_SIZE" , INTEGER ,
832+ "BUFFER_LENGTH" , INTEGER ,
833+ "DECIMAL_DIGITS" , SMALLINT ,
834+ "PSEUDO_COLUMN" , SMALLINT );
812835 }
813836
814837 @ Override
815838 public ResultSet getVersionColumns (String catalog , String schema , String table ) throws SQLException {
816- throw new SQLFeatureNotSupportedException ("Version column not supported yet" );
839+ return emptySet (con .cfg , "" ,
840+ "SCOPE" , SMALLINT ,
841+ "COLUMN_NAME" ,
842+ "DATA_TYPE" , INTEGER ,
843+ "TYPE_NAME" ,
844+ "COLUMN_SIZE" , INTEGER ,
845+ "BUFFER_LENGTH" , INTEGER ,
846+ "DECIMAL_DIGITS" , SMALLINT ,
847+ "PSEUDO_COLUMN" , SMALLINT );
817848 }
818849
819850 @ Override
820851 public ResultSet getPrimaryKeys (String catalog , String schema , String table ) throws SQLException {
821- throw new SQLFeatureNotSupportedException ("Primary keys not supported" );
852+ return emptySet (con .cfg , "" ,
853+ "TABLE_CAT" ,
854+ "TABLE_SCHEM" ,
855+ "TABLE_NAME" ,
856+ "COLUMN_NAME" ,
857+ "KEY_SEQ" , SMALLINT ,
858+ "PK_NAME" );
822859 }
823860
824861 @ Override
825862 public ResultSet getImportedKeys (String catalog , String schema , String table ) throws SQLException {
826- throw new SQLFeatureNotSupportedException ("Imported keys not supported" );
863+ return emptySet (con .cfg , "" ,
864+ "PKTABLE_CAT" ,
865+ "PKTABLE_SCHEM" ,
866+ "PKTABLE_NAME" ,
867+ "PKCOLUMN_NAME" ,
868+ "FKTABLE_CAT" ,
869+ "FKTABLE_SCHEM" ,
870+ "FKTABLE_NAME" ,
871+ "FKCOLUMN_NAME" ,
872+ "KEY_SEQ" , SMALLINT ,
873+ "UPDATE_RULE " , SMALLINT ,
874+ "DELETE_RULE " , SMALLINT ,
875+ "FK_NAME" ,
876+ "PK_NAME " ,
877+ "DEFERRABILITY" , SMALLINT ,
878+ "IS_NULLABLE"
879+ );
827880 }
828881
829882 @ Override
830883 public ResultSet getExportedKeys (String catalog , String schema , String table ) throws SQLException {
831- throw new SQLFeatureNotSupportedException ("Exported keys not supported" );
884+ return emptySet (con .cfg , "" ,
885+ "PKTABLE_CAT" ,
886+ "PKTABLE_SCHEM" ,
887+ "PKTABLE_NAME" ,
888+ "PKCOLUMN_NAME" ,
889+ "FKTABLE_CAT" ,
890+ "FKTABLE_SCHEM" ,
891+ "FKTABLE_NAME" ,
892+ "FKCOLUMN_NAME" ,
893+ "KEY_SEQ" , SMALLINT ,
894+ "UPDATE_RULE " , SMALLINT ,
895+ "DELETE_RULE " , SMALLINT ,
896+ "FK_NAME" ,
897+ "PK_NAME " ,
898+ "DEFERRABILITY" , SMALLINT ,
899+ "IS_NULLABLE"
900+ );
832901 }
833902
834903 @ Override
835904 public ResultSet getCrossReference (String parentCatalog , String parentSchema , String parentTable , String foreignCatalog ,
836905 String foreignSchema , String foreignTable ) throws SQLException {
837- throw new SQLFeatureNotSupportedException ("Cross reference not supported" );
906+ return emptySet (con .cfg , "" ,
907+ "PKTABLE_CAT" ,
908+ "PKTABLE_SCHEM" ,
909+ "PKTABLE_NAME" ,
910+ "PKCOLUMN_NAME" ,
911+ "FKTABLE_CAT" ,
912+ "FKTABLE_SCHEM" ,
913+ "FKTABLE_NAME" ,
914+ "FKCOLUMN_NAME" ,
915+ "KEY_SEQ" , SMALLINT ,
916+ "UPDATE_RULE " , SMALLINT ,
917+ "DELETE_RULE " , SMALLINT ,
918+ "FK_NAME" ,
919+ "PK_NAME " ,
920+ "DEFERRABILITY" , SMALLINT ,
921+ "IS_NULLABLE"
922+ );
838923 }
839924
840925 @ Override
@@ -844,7 +929,22 @@ public ResultSet getTypeInfo() throws SQLException {
844929
845930 @ Override
846931 public ResultSet getIndexInfo (String catalog , String schema , String table , boolean unique , boolean approximate ) throws SQLException {
847- throw new SQLFeatureNotSupportedException ("Indicies not supported" );
932+ return emptySet (con .cfg , "" ,
933+ "TABLE_CAT" ,
934+ "TABLE_SCHEM" ,
935+ "TABLE_NAME" ,
936+ "NON_UNIQUE" , BOOLEAN ,
937+ "INDEX_QUALIFIER" ,
938+ "INDEX_NAME" ,
939+ "TYPE" , SMALLINT ,
940+ "ORDINAL_POSITION" , SMALLINT ,
941+ "COLUMN_NAME" ,
942+ "ASC_OR_DESC" ,
943+ "CARDINALITY" , BIGINT ,
944+ "PAGES" , BIGINT ,
945+ "FILTER_CONDITION" ,
946+ "TYPE_NAME"
947+ );
848948 }
849949
850950 @ Override
@@ -909,7 +1009,7 @@ public boolean supportsBatchUpdates() throws SQLException {
9091009
9101010 @ Override
9111011 public ResultSet getUDTs (String catalog , String schemaPattern , String typeNamePattern , int [] types ) throws SQLException {
912- return emptySet (con .cfg ,
1012+ return emptySet (con .cfg , "" ,
9131013 "USER_DEFINED_TYPES" ,
9141014 "TYPE_CAT" ,
9151015 "TYPE_SCHEM" ,
@@ -947,7 +1047,7 @@ public boolean supportsGetGeneratedKeys() throws SQLException {
9471047
9481048 @ Override
9491049 public ResultSet getSuperTypes (String catalog , String schemaPattern , String typeNamePattern ) throws SQLException {
950- return emptySet (con .cfg ,
1050+ return emptySet (con .cfg , "" ,
9511051 "SUPER_TYPES" ,
9521052 "TYPE_CAT" ,
9531053 "TYPE_SCHEM" ,
@@ -960,7 +1060,7 @@ public ResultSet getSuperTypes(String catalog, String schemaPattern, String type
9601060
9611061 @ Override
9621062 public ResultSet getSuperTables (String catalog , String schemaPattern , String tableNamePattern ) throws SQLException {
963- return emptySet (con .cfg , "SUPER_TABLES " ,
1063+ return emptySet (con .cfg , "" ,
9641064 "TABLE_CAT" ,
9651065 "TABLE_SCHEM" ,
9661066 "TABLE_NAME" ,
@@ -970,7 +1070,7 @@ public ResultSet getSuperTables(String catalog, String schemaPattern, String tab
9701070 @ Override
9711071 public ResultSet getAttributes (String catalog , String schemaPattern , String typeNamePattern , String attributeNamePattern )
9721072 throws SQLException {
973- return emptySet (con .cfg ,
1073+ return emptySet (con .cfg , "" ,
9741074 "ATTRIBUTES" ,
9751075 "TYPE_CAT" ,
9761076 "TYPE_SCHEM" ,
@@ -1057,12 +1157,27 @@ public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
10571157
10581158 @ Override
10591159 public ResultSet getClientInfoProperties () throws SQLException {
1060- throw new SQLException ("Client info not implemented yet" );
1160+ DriverPropertyInfo [] info = con .cfg .driverPropertyInfo ();
1161+ Object [][] data = new Object [info .length ][];
1162+
1163+ for (int i = 0 ; i < data .length ; i ++) {
1164+ data [i ] = new Object [4 ];
1165+ data [i ][0 ] = info [i ].name ;
1166+ data [i ][1 ] = Integer .valueOf (-1 );
1167+ data [i ][2 ] = EMPTY ;
1168+ data [i ][3 ] = EMPTY ;
1169+ }
1170+
1171+ return memorySet (con .cfg , columnInfo ("" ,
1172+ "NAME" ,
1173+ "MAX_LEN" , INTEGER ,
1174+ "DEFAULT_VALUE" ,
1175+ "DESCRIPTION" ), data );
10611176 }
10621177
10631178 @ Override
10641179 public ResultSet getFunctions (String catalog , String schemaPattern , String functionNamePattern ) throws SQLException {
1065- return emptySet (con .cfg ,
1180+ return emptySet (con .cfg , "" ,
10661181 "FUNCTIONS" ,
10671182 "FUNCTION_CAT" ,
10681183 "FUNCTION_SCHEM" ,
@@ -1075,7 +1190,7 @@ public ResultSet getFunctions(String catalog, String schemaPattern, String funct
10751190 @ Override
10761191 public ResultSet getFunctionColumns (String catalog , String schemaPattern , String functionNamePattern , String columnNamePattern )
10771192 throws SQLException {
1078- return emptySet (con .cfg ,
1193+ return emptySet (con .cfg , "" ,
10791194 "FUNCTION_COLUMNS" ,
10801195 "FUNCTION_CAT" ,
10811196 "FUNCTION_SCHEM" ,
@@ -1098,7 +1213,7 @@ public ResultSet getFunctionColumns(String catalog, String schemaPattern, String
10981213 @ Override
10991214 public ResultSet getPseudoColumns (String catalog , String schemaPattern , String tableNamePattern , String columnNamePattern )
11001215 throws SQLException {
1101- return emptySet (con .cfg ,
1216+ return emptySet (con .cfg , "" ,
11021217 "PSEUDO_COLUMNS" ,
11031218 "TABLE_CAT" ,
11041219 "TABLE_SCHEM" ,
@@ -1213,7 +1328,7 @@ public Object column(int column) {
12131328
12141329 @ Override
12151330 public int batchSize () {
1216- return data .length ;
1331+ return ObjectUtils . isEmpty ( data ) ? 0 : data .length ;
12171332 }
12181333
12191334 @ Override
0 commit comments