10
10
11
11
import java .sql .Connection ;
12
12
import java .sql .DatabaseMetaData ;
13
+ import java .sql .DriverPropertyInfo ;
13
14
import java .sql .JDBCType ;
14
15
import java .sql .PreparedStatement ;
15
16
import java .sql .ResultSet ;
16
17
import java .sql .RowIdLifetime ;
17
18
import java .sql .SQLException ;
18
- import java .sql .SQLFeatureNotSupportedException ;
19
19
import java .util .ArrayList ;
20
20
import java .util .List ;
21
21
22
+ import static java .sql .JDBCType .BIGINT ;
23
+ import static java .sql .JDBCType .BOOLEAN ;
22
24
import static java .sql .JDBCType .INTEGER ;
23
25
import static java .sql .JDBCType .SMALLINT ;
24
26
import static org .elasticsearch .xpack .sql .client .StringUtils .EMPTY ;
@@ -664,8 +666,7 @@ public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
664
666
// https://www.postgresql.org/docs/9.0/static/infoschema-routines.html
665
667
@ Override
666
668
public ResultSet getProcedures (String catalog , String schemaPattern , String procedureNamePattern ) throws SQLException {
667
- return emptySet (con .cfg ,
668
- "ROUTINES" ,
669
+ return emptySet (con .cfg , "ROUTINES" ,
669
670
"PROCEDURE_CAT" ,
670
671
"PROCEDURE_SCHEM" ,
671
672
"PROCEDURE_NAME" ,
@@ -680,8 +681,7 @@ public ResultSet getProcedures(String catalog, String schemaPattern, String proc
680
681
@ Override
681
682
public ResultSet getProcedureColumns (String catalog , String schemaPattern , String procedureNamePattern , String columnNamePattern )
682
683
throws SQLException {
683
- return emptySet (con .cfg ,
684
- "PARAMETERS" ,
684
+ return emptySet (con .cfg , "ROUTINES_COLUMNS" ,
685
685
"PROCEDURE_CAT" ,
686
686
"PROCEDURE_SCHEM" ,
687
687
"PROCEDURE_NAME" ,
@@ -775,14 +775,14 @@ public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLExce
775
775
public ResultSet getCatalogs () throws SQLException {
776
776
// TABLE_CAT is the first column
777
777
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 );
779
779
}
780
780
781
781
@ Override
782
782
public ResultSet getTableTypes () throws SQLException {
783
783
// TABLE_TYPE (4)
784
784
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 );
786
786
}
787
787
788
788
@ Override
@@ -798,43 +798,128 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa
798
798
799
799
@ Override
800
800
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" );
802
810
}
803
811
804
812
@ Override
805
813
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" );
807
822
}
808
823
809
824
@ Override
810
825
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 );
812
835
}
813
836
814
837
@ Override
815
838
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 );
817
848
}
818
849
819
850
@ Override
820
851
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" );
822
859
}
823
860
824
861
@ Override
825
862
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
+ );
827
880
}
828
881
829
882
@ Override
830
883
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
+ );
832
901
}
833
902
834
903
@ Override
835
904
public ResultSet getCrossReference (String parentCatalog , String parentSchema , String parentTable , String foreignCatalog ,
836
905
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
+ );
838
923
}
839
924
840
925
@ Override
@@ -844,7 +929,22 @@ public ResultSet getTypeInfo() throws SQLException {
844
929
845
930
@ Override
846
931
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
+ );
848
948
}
849
949
850
950
@ Override
@@ -909,7 +1009,7 @@ public boolean supportsBatchUpdates() throws SQLException {
909
1009
910
1010
@ Override
911
1011
public ResultSet getUDTs (String catalog , String schemaPattern , String typeNamePattern , int [] types ) throws SQLException {
912
- return emptySet (con .cfg ,
1012
+ return emptySet (con .cfg , "" ,
913
1013
"USER_DEFINED_TYPES" ,
914
1014
"TYPE_CAT" ,
915
1015
"TYPE_SCHEM" ,
@@ -947,7 +1047,7 @@ public boolean supportsGetGeneratedKeys() throws SQLException {
947
1047
948
1048
@ Override
949
1049
public ResultSet getSuperTypes (String catalog , String schemaPattern , String typeNamePattern ) throws SQLException {
950
- return emptySet (con .cfg ,
1050
+ return emptySet (con .cfg , "" ,
951
1051
"SUPER_TYPES" ,
952
1052
"TYPE_CAT" ,
953
1053
"TYPE_SCHEM" ,
@@ -960,7 +1060,7 @@ public ResultSet getSuperTypes(String catalog, String schemaPattern, String type
960
1060
961
1061
@ Override
962
1062
public ResultSet getSuperTables (String catalog , String schemaPattern , String tableNamePattern ) throws SQLException {
963
- return emptySet (con .cfg , "SUPER_TABLES " ,
1063
+ return emptySet (con .cfg , "" ,
964
1064
"TABLE_CAT" ,
965
1065
"TABLE_SCHEM" ,
966
1066
"TABLE_NAME" ,
@@ -970,7 +1070,7 @@ public ResultSet getSuperTables(String catalog, String schemaPattern, String tab
970
1070
@ Override
971
1071
public ResultSet getAttributes (String catalog , String schemaPattern , String typeNamePattern , String attributeNamePattern )
972
1072
throws SQLException {
973
- return emptySet (con .cfg ,
1073
+ return emptySet (con .cfg , "" ,
974
1074
"ATTRIBUTES" ,
975
1075
"TYPE_CAT" ,
976
1076
"TYPE_SCHEM" ,
@@ -1057,12 +1157,27 @@ public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
1057
1157
1058
1158
@ Override
1059
1159
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 );
1061
1176
}
1062
1177
1063
1178
@ Override
1064
1179
public ResultSet getFunctions (String catalog , String schemaPattern , String functionNamePattern ) throws SQLException {
1065
- return emptySet (con .cfg ,
1180
+ return emptySet (con .cfg , "" ,
1066
1181
"FUNCTIONS" ,
1067
1182
"FUNCTION_CAT" ,
1068
1183
"FUNCTION_SCHEM" ,
@@ -1075,7 +1190,7 @@ public ResultSet getFunctions(String catalog, String schemaPattern, String funct
1075
1190
@ Override
1076
1191
public ResultSet getFunctionColumns (String catalog , String schemaPattern , String functionNamePattern , String columnNamePattern )
1077
1192
throws SQLException {
1078
- return emptySet (con .cfg ,
1193
+ return emptySet (con .cfg , "" ,
1079
1194
"FUNCTION_COLUMNS" ,
1080
1195
"FUNCTION_CAT" ,
1081
1196
"FUNCTION_SCHEM" ,
@@ -1098,7 +1213,7 @@ public ResultSet getFunctionColumns(String catalog, String schemaPattern, String
1098
1213
@ Override
1099
1214
public ResultSet getPseudoColumns (String catalog , String schemaPattern , String tableNamePattern , String columnNamePattern )
1100
1215
throws SQLException {
1101
- return emptySet (con .cfg ,
1216
+ return emptySet (con .cfg , "" ,
1102
1217
"PSEUDO_COLUMNS" ,
1103
1218
"TABLE_CAT" ,
1104
1219
"TABLE_SCHEM" ,
@@ -1213,7 +1328,7 @@ public Object column(int column) {
1213
1328
1214
1329
@ Override
1215
1330
public int batchSize () {
1216
- return data .length ;
1331
+ return ObjectUtils . isEmpty ( data ) ? 0 : data .length ;
1217
1332
}
1218
1333
1219
1334
@ Override
0 commit comments