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 ;
@@ -209,7 +211,7 @@ public String getStringFunctions() throws SQLException {
209
211
@ Override
210
212
public String getSystemFunctions () throws SQLException {
211
213
// https://docs.microsoft.com/en-us/sql/odbc/reference/appendixes/system-functions?view=sql-server-2017
212
- return "DATABASE, IFNULL, USER" ;
214
+ return "DATABASE,IFNULL,USER" ;
213
215
}
214
216
215
217
@ Override
@@ -663,8 +665,7 @@ public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
663
665
// https://www.postgresql.org/docs/9.0/static/infoschema-routines.html
664
666
@ Override
665
667
public ResultSet getProcedures (String catalog , String schemaPattern , String procedureNamePattern ) throws SQLException {
666
- return emptySet (con .cfg ,
667
- "ROUTINES" ,
668
+ return emptySet (con .cfg , "ROUTINES" ,
668
669
"PROCEDURE_CAT" ,
669
670
"PROCEDURE_SCHEM" ,
670
671
"PROCEDURE_NAME" ,
@@ -679,8 +680,7 @@ public ResultSet getProcedures(String catalog, String schemaPattern, String proc
679
680
@ Override
680
681
public ResultSet getProcedureColumns (String catalog , String schemaPattern , String procedureNamePattern , String columnNamePattern )
681
682
throws SQLException {
682
- return emptySet (con .cfg ,
683
- "PARAMETERS" ,
683
+ return emptySet (con .cfg , "ROUTINES_COLUMNS" ,
684
684
"PROCEDURE_CAT" ,
685
685
"PROCEDURE_SCHEM" ,
686
686
"PROCEDURE_NAME" ,
@@ -774,14 +774,14 @@ public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLExce
774
774
public ResultSet getCatalogs () throws SQLException {
775
775
// TABLE_CAT is the first column
776
776
Object [][] data = queryColumn (con , "SYS TABLES CATALOG LIKE '%' LIKE ''" , 1 );
777
- return memorySet (con .cfg , columnInfo ("" , "TABLE_CAT" ), data );
777
+ return memorySet (con .cfg , columnInfo ("CATALOGS " , "TABLE_CAT" ), data );
778
778
}
779
779
780
780
@ Override
781
781
public ResultSet getTableTypes () throws SQLException {
782
782
// TABLE_TYPE (4)
783
783
Object [][] data = queryColumn (con , "SYS TABLES CATALOG LIKE '' LIKE '' TYPE '%'" , 4 );
784
- return memorySet (con .cfg , columnInfo ("" , "TABLE_TYPE" ), data );
784
+ return memorySet (con .cfg , columnInfo ("TABLE_TYPES " , "TABLE_TYPE" ), data );
785
785
}
786
786
787
787
@ Override
@@ -797,43 +797,128 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa
797
797
798
798
@ Override
799
799
public ResultSet getColumnPrivileges (String catalog , String schema , String table , String columnNamePattern ) throws SQLException {
800
- throw new SQLFeatureNotSupportedException ("Privileges not supported" );
800
+ return emptySet (con .cfg , "" ,
801
+ "TABLE_CAT" ,
802
+ "TABLE_SCHEM" ,
803
+ "TABLE_NAME" ,
804
+ "COLUMN_NAME" ,
805
+ "GRANTOR" ,
806
+ "GRANTEE" ,
807
+ "PRIVILEGE" ,
808
+ "IS_GRANTABLE" );
801
809
}
802
810
803
811
@ Override
804
812
public ResultSet getTablePrivileges (String catalog , String schemaPattern , String tableNamePattern ) throws SQLException {
805
- throw new SQLFeatureNotSupportedException ("Privileges not supported" );
813
+ return emptySet (con .cfg , "" ,
814
+ "TABLE_CAT" ,
815
+ "TABLE_SCHEM" ,
816
+ "TABLE_NAME" ,
817
+ "GRANTOR" ,
818
+ "GRANTEE" ,
819
+ "PRIVILEGE" ,
820
+ "IS_GRANTABLE" );
806
821
}
807
822
808
823
@ Override
809
824
public ResultSet getBestRowIdentifier (String catalog , String schema , String table , int scope , boolean nullable ) throws SQLException {
810
- throw new SQLFeatureNotSupportedException ("Row identifiers not supported" );
825
+ return emptySet (con .cfg , "" ,
826
+ "SCOPE" , SMALLINT ,
827
+ "COLUMN_NAME" ,
828
+ "DATA_TYPE" , INTEGER ,
829
+ "TYPE_NAME" ,
830
+ "COLUMN_SIZE" , INTEGER ,
831
+ "BUFFER_LENGTH" , INTEGER ,
832
+ "DECIMAL_DIGITS" , SMALLINT ,
833
+ "PSEUDO_COLUMN" , SMALLINT );
811
834
}
812
835
813
836
@ Override
814
837
public ResultSet getVersionColumns (String catalog , String schema , String table ) throws SQLException {
815
- throw new SQLFeatureNotSupportedException ("Version column not supported yet" );
838
+ return emptySet (con .cfg , "" ,
839
+ "SCOPE" , SMALLINT ,
840
+ "COLUMN_NAME" ,
841
+ "DATA_TYPE" , INTEGER ,
842
+ "TYPE_NAME" ,
843
+ "COLUMN_SIZE" , INTEGER ,
844
+ "BUFFER_LENGTH" , INTEGER ,
845
+ "DECIMAL_DIGITS" , SMALLINT ,
846
+ "PSEUDO_COLUMN" , SMALLINT );
816
847
}
817
848
818
849
@ Override
819
850
public ResultSet getPrimaryKeys (String catalog , String schema , String table ) throws SQLException {
820
- throw new SQLFeatureNotSupportedException ("Primary keys not supported" );
851
+ return emptySet (con .cfg , "" ,
852
+ "TABLE_CAT" ,
853
+ "TABLE_SCHEM" ,
854
+ "TABLE_NAME" ,
855
+ "COLUMN_NAME" ,
856
+ "KEY_SEQ" , SMALLINT ,
857
+ "PK_NAME" );
821
858
}
822
859
823
860
@ Override
824
861
public ResultSet getImportedKeys (String catalog , String schema , String table ) throws SQLException {
825
- throw new SQLFeatureNotSupportedException ("Imported keys not supported" );
862
+ return emptySet (con .cfg , "" ,
863
+ "PKTABLE_CAT" ,
864
+ "PKTABLE_SCHEM" ,
865
+ "PKTABLE_NAME" ,
866
+ "PKCOLUMN_NAME" ,
867
+ "FKTABLE_CAT" ,
868
+ "FKTABLE_SCHEM" ,
869
+ "FKTABLE_NAME" ,
870
+ "FKCOLUMN_NAME" ,
871
+ "KEY_SEQ" , SMALLINT ,
872
+ "UPDATE_RULE " , SMALLINT ,
873
+ "DELETE_RULE " , SMALLINT ,
874
+ "FK_NAME" ,
875
+ "PK_NAME " ,
876
+ "DEFERRABILITY" , SMALLINT ,
877
+ "IS_NULLABLE"
878
+ );
826
879
}
827
880
828
881
@ Override
829
882
public ResultSet getExportedKeys (String catalog , String schema , String table ) throws SQLException {
830
- throw new SQLFeatureNotSupportedException ("Exported keys not supported" );
883
+ return emptySet (con .cfg , "" ,
884
+ "PKTABLE_CAT" ,
885
+ "PKTABLE_SCHEM" ,
886
+ "PKTABLE_NAME" ,
887
+ "PKCOLUMN_NAME" ,
888
+ "FKTABLE_CAT" ,
889
+ "FKTABLE_SCHEM" ,
890
+ "FKTABLE_NAME" ,
891
+ "FKCOLUMN_NAME" ,
892
+ "KEY_SEQ" , SMALLINT ,
893
+ "UPDATE_RULE " , SMALLINT ,
894
+ "DELETE_RULE " , SMALLINT ,
895
+ "FK_NAME" ,
896
+ "PK_NAME " ,
897
+ "DEFERRABILITY" , SMALLINT ,
898
+ "IS_NULLABLE"
899
+ );
831
900
}
832
901
833
902
@ Override
834
903
public ResultSet getCrossReference (String parentCatalog , String parentSchema , String parentTable , String foreignCatalog ,
835
904
String foreignSchema , String foreignTable ) throws SQLException {
836
- throw new SQLFeatureNotSupportedException ("Cross reference not supported" );
905
+ return emptySet (con .cfg , "" ,
906
+ "PKTABLE_CAT" ,
907
+ "PKTABLE_SCHEM" ,
908
+ "PKTABLE_NAME" ,
909
+ "PKCOLUMN_NAME" ,
910
+ "FKTABLE_CAT" ,
911
+ "FKTABLE_SCHEM" ,
912
+ "FKTABLE_NAME" ,
913
+ "FKCOLUMN_NAME" ,
914
+ "KEY_SEQ" , SMALLINT ,
915
+ "UPDATE_RULE " , SMALLINT ,
916
+ "DELETE_RULE " , SMALLINT ,
917
+ "FK_NAME" ,
918
+ "PK_NAME " ,
919
+ "DEFERRABILITY" , SMALLINT ,
920
+ "IS_NULLABLE"
921
+ );
837
922
}
838
923
839
924
@ Override
@@ -843,7 +928,22 @@ public ResultSet getTypeInfo() throws SQLException {
843
928
844
929
@ Override
845
930
public ResultSet getIndexInfo (String catalog , String schema , String table , boolean unique , boolean approximate ) throws SQLException {
846
- throw new SQLFeatureNotSupportedException ("Indicies not supported" );
931
+ return emptySet (con .cfg , "" ,
932
+ "TABLE_CAT" ,
933
+ "TABLE_SCHEM" ,
934
+ "TABLE_NAME" ,
935
+ "NON_UNIQUE" , BOOLEAN ,
936
+ "INDEX_QUALIFIER" ,
937
+ "INDEX_NAME" ,
938
+ "TYPE" , SMALLINT ,
939
+ "ORDINAL_POSITION" , SMALLINT ,
940
+ "COLUMN_NAME" ,
941
+ "ASC_OR_DESC" ,
942
+ "CARDINALITY" , BIGINT ,
943
+ "PAGES" , BIGINT ,
944
+ "FILTER_CONDITION" ,
945
+ "TYPE_NAME"
946
+ );
847
947
}
848
948
849
949
@ Override
@@ -908,7 +1008,7 @@ public boolean supportsBatchUpdates() throws SQLException {
908
1008
909
1009
@ Override
910
1010
public ResultSet getUDTs (String catalog , String schemaPattern , String typeNamePattern , int [] types ) throws SQLException {
911
- return emptySet (con .cfg ,
1011
+ return emptySet (con .cfg , "" ,
912
1012
"USER_DEFINED_TYPES" ,
913
1013
"TYPE_CAT" ,
914
1014
"TYPE_SCHEM" ,
@@ -946,7 +1046,7 @@ public boolean supportsGetGeneratedKeys() throws SQLException {
946
1046
947
1047
@ Override
948
1048
public ResultSet getSuperTypes (String catalog , String schemaPattern , String typeNamePattern ) throws SQLException {
949
- return emptySet (con .cfg ,
1049
+ return emptySet (con .cfg , "" ,
950
1050
"SUPER_TYPES" ,
951
1051
"TYPE_CAT" ,
952
1052
"TYPE_SCHEM" ,
@@ -959,7 +1059,7 @@ public ResultSet getSuperTypes(String catalog, String schemaPattern, String type
959
1059
960
1060
@ Override
961
1061
public ResultSet getSuperTables (String catalog , String schemaPattern , String tableNamePattern ) throws SQLException {
962
- return emptySet (con .cfg , "SUPER_TABLES " ,
1062
+ return emptySet (con .cfg , "" ,
963
1063
"TABLE_CAT" ,
964
1064
"TABLE_SCHEM" ,
965
1065
"TABLE_NAME" ,
@@ -969,7 +1069,7 @@ public ResultSet getSuperTables(String catalog, String schemaPattern, String tab
969
1069
@ Override
970
1070
public ResultSet getAttributes (String catalog , String schemaPattern , String typeNamePattern , String attributeNamePattern )
971
1071
throws SQLException {
972
- return emptySet (con .cfg ,
1072
+ return emptySet (con .cfg , "" ,
973
1073
"ATTRIBUTES" ,
974
1074
"TYPE_CAT" ,
975
1075
"TYPE_SCHEM" ,
@@ -1056,12 +1156,27 @@ public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
1056
1156
1057
1157
@ Override
1058
1158
public ResultSet getClientInfoProperties () throws SQLException {
1059
- throw new SQLException ("Client info not implemented yet" );
1159
+ DriverPropertyInfo [] info = con .cfg .driverPropertyInfo ();
1160
+ Object [][] data = new Object [info .length ][];
1161
+
1162
+ for (int i = 0 ; i < data .length ; i ++) {
1163
+ data [i ] = new Object [4 ];
1164
+ data [i ][0 ] = info [i ].name ;
1165
+ data [i ][1 ] = Integer .valueOf (-1 );
1166
+ data [i ][2 ] = EMPTY ;
1167
+ data [i ][3 ] = EMPTY ;
1168
+ }
1169
+
1170
+ return memorySet (con .cfg , columnInfo ("" ,
1171
+ "NAME" ,
1172
+ "MAX_LEN" , INTEGER ,
1173
+ "DEFAULT_VALUE" ,
1174
+ "DESCRIPTION" ), data );
1060
1175
}
1061
1176
1062
1177
@ Override
1063
1178
public ResultSet getFunctions (String catalog , String schemaPattern , String functionNamePattern ) throws SQLException {
1064
- return emptySet (con .cfg ,
1179
+ return emptySet (con .cfg , "" ,
1065
1180
"FUNCTIONS" ,
1066
1181
"FUNCTION_CAT" ,
1067
1182
"FUNCTION_SCHEM" ,
@@ -1074,7 +1189,7 @@ public ResultSet getFunctions(String catalog, String schemaPattern, String funct
1074
1189
@ Override
1075
1190
public ResultSet getFunctionColumns (String catalog , String schemaPattern , String functionNamePattern , String columnNamePattern )
1076
1191
throws SQLException {
1077
- return emptySet (con .cfg ,
1192
+ return emptySet (con .cfg , "" ,
1078
1193
"FUNCTION_COLUMNS" ,
1079
1194
"FUNCTION_CAT" ,
1080
1195
"FUNCTION_SCHEM" ,
@@ -1097,7 +1212,7 @@ public ResultSet getFunctionColumns(String catalog, String schemaPattern, String
1097
1212
@ Override
1098
1213
public ResultSet getPseudoColumns (String catalog , String schemaPattern , String tableNamePattern , String columnNamePattern )
1099
1214
throws SQLException {
1100
- return emptySet (con .cfg ,
1215
+ return emptySet (con .cfg , "" ,
1101
1216
"PSEUDO_COLUMNS" ,
1102
1217
"TABLE_CAT" ,
1103
1218
"TABLE_SCHEM" ,
@@ -1212,7 +1327,7 @@ public Object column(int column) {
1212
1327
1213
1328
@ Override
1214
1329
public int batchSize () {
1215
- return data .length ;
1330
+ return ObjectUtils . isEmpty ( data ) ? 0 : data .length ;
1216
1331
}
1217
1332
1218
1333
@ Override
0 commit comments