-
Notifications
You must be signed in to change notification settings - Fork 624
/
Copy pathJDBC3DatabaseMetaData.java
2250 lines (1942 loc) · 87.7 KB
/
JDBC3DatabaseMetaData.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.sqlite.jdbc3;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Statement;
import java.sql.Struct;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sqlite.SQLiteConnection;
import org.sqlite.core.CoreDatabaseMetaData;
import org.sqlite.core.CoreStatement;
import org.sqlite.jdbc3.JDBC3DatabaseMetaData.ImportedKeyFinder.ForeignKey;
import org.sqlite.util.QueryUtils;
import org.sqlite.util.StringUtils;
public abstract class JDBC3DatabaseMetaData extends CoreDatabaseMetaData {
private static String driverName;
private static String driverVersion;
static {
try (InputStream sqliteJdbcPropStream =
JDBC3DatabaseMetaData.class
.getClassLoader()
.getResourceAsStream("sqlite-jdbc.properties")) {
if (sqliteJdbcPropStream == null) {
throw new IOException("Cannot load sqlite-jdbc.properties from jar");
}
final Properties sqliteJdbcProp = new Properties();
sqliteJdbcProp.load(sqliteJdbcPropStream);
driverName = sqliteJdbcProp.getProperty("name");
driverVersion = sqliteJdbcProp.getProperty("version");
} catch (Exception e) {
// Default values
driverName = "SQLite JDBC";
driverVersion = "3.0.0-UNKNOWN";
}
}
protected JDBC3DatabaseMetaData(SQLiteConnection conn) {
super(conn);
}
/** @see java.sql.DatabaseMetaData#getConnection() */
public Connection getConnection() {
return conn;
}
/** @see java.sql.DatabaseMetaData#getDatabaseMajorVersion() */
public int getDatabaseMajorVersion() throws SQLException {
return Integer.parseInt(conn.libversion().split("\\.")[0]);
}
/** @see java.sql.DatabaseMetaData#getDatabaseMinorVersion() */
public int getDatabaseMinorVersion() throws SQLException {
return Integer.parseInt(conn.libversion().split("\\.")[1]);
}
/** @see java.sql.DatabaseMetaData#getDriverMajorVersion() */
public int getDriverMajorVersion() {
return Integer.parseInt(driverVersion.split("\\.")[0]);
}
/** @see java.sql.DatabaseMetaData#getDriverMinorVersion() */
public int getDriverMinorVersion() {
return Integer.parseInt(driverVersion.split("\\.")[1]);
}
/** @see java.sql.DatabaseMetaData#getJDBCMajorVersion() */
public int getJDBCMajorVersion() {
return 4;
}
/** @see java.sql.DatabaseMetaData#getJDBCMinorVersion() */
public int getJDBCMinorVersion() {
return 2;
}
/** @see java.sql.DatabaseMetaData#getDefaultTransactionIsolation() */
public int getDefaultTransactionIsolation() {
return Connection.TRANSACTION_SERIALIZABLE;
}
/** @see java.sql.DatabaseMetaData#getMaxBinaryLiteralLength() */
public int getMaxBinaryLiteralLength() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxCatalogNameLength() */
public int getMaxCatalogNameLength() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxCharLiteralLength() */
public int getMaxCharLiteralLength() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxColumnNameLength() */
public int getMaxColumnNameLength() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxColumnsInGroupBy() */
public int getMaxColumnsInGroupBy() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxColumnsInIndex() */
public int getMaxColumnsInIndex() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxColumnsInOrderBy() */
public int getMaxColumnsInOrderBy() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxColumnsInSelect() */
public int getMaxColumnsInSelect() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxColumnsInTable() */
public int getMaxColumnsInTable() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxConnections() */
public int getMaxConnections() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxCursorNameLength() */
public int getMaxCursorNameLength() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxIndexLength() */
public int getMaxIndexLength() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxProcedureNameLength() */
public int getMaxProcedureNameLength() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxRowSize() */
public int getMaxRowSize() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxSchemaNameLength() */
public int getMaxSchemaNameLength() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxStatementLength() */
public int getMaxStatementLength() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxStatements() */
public int getMaxStatements() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxTableNameLength() */
public int getMaxTableNameLength() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxTablesInSelect() */
public int getMaxTablesInSelect() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getMaxUserNameLength() */
public int getMaxUserNameLength() {
return 0;
}
/** @see java.sql.DatabaseMetaData#getResultSetHoldability() */
public int getResultSetHoldability() {
return ResultSet.CLOSE_CURSORS_AT_COMMIT;
}
/** @see java.sql.DatabaseMetaData#getSQLStateType() */
public int getSQLStateType() {
return DatabaseMetaData.sqlStateSQL99;
}
/** @see java.sql.DatabaseMetaData#getDatabaseProductName() */
public String getDatabaseProductName() {
return "SQLite";
}
/** @see java.sql.DatabaseMetaData#getDatabaseProductVersion() */
public String getDatabaseProductVersion() throws SQLException {
return conn.libversion();
}
/** @see java.sql.DatabaseMetaData#getDriverName() */
public String getDriverName() {
return driverName;
}
/** @see java.sql.DatabaseMetaData#getDriverVersion() */
public String getDriverVersion() {
return driverVersion;
}
/** @see java.sql.DatabaseMetaData#getExtraNameCharacters() */
public String getExtraNameCharacters() {
return "";
}
/** @see java.sql.DatabaseMetaData#getCatalogSeparator() */
public String getCatalogSeparator() {
return ".";
}
/** @see java.sql.DatabaseMetaData#getCatalogTerm() */
public String getCatalogTerm() {
return "catalog";
}
/** @see java.sql.DatabaseMetaData#getSchemaTerm() */
public String getSchemaTerm() {
return "schema";
}
/** @see java.sql.DatabaseMetaData#getProcedureTerm() */
public String getProcedureTerm() {
return "not_implemented";
}
/** @see java.sql.DatabaseMetaData#getSearchStringEscape() */
public String getSearchStringEscape() {
return "\\";
}
/** @see java.sql.DatabaseMetaData#getIdentifierQuoteString() */
public String getIdentifierQuoteString() {
return "\"";
}
/**
* @see java.sql.DatabaseMetaData#getSQLKeywords()
* @see <a href="https://www.sqlite.org/lang_keywords.html">SQLite Keywords</a>
*/
public String getSQLKeywords() {
return "ABORT,ACTION,AFTER,ANALYZE,ATTACH,AUTOINCREMENT,BEFORE,"
+ "CASCADE,CONFLICT,DATABASE,DEFERRABLE,DEFERRED,DESC,DETACH,"
+ "EXCLUSIVE,EXPLAIN,FAIL,GLOB,IGNORE,INDEX,INDEXED,INITIALLY,INSTEAD,ISNULL,"
+ "KEY,LIMIT,NOTNULL,OFFSET,PLAN,PRAGMA,QUERY,"
+ "RAISE,REGEXP,REINDEX,RENAME,REPLACE,RESTRICT,"
+ "TEMP,TEMPORARY,TRANSACTION,VACUUM,VIEW,VIRTUAL";
}
/** @see java.sql.DatabaseMetaData#getNumericFunctions() */
public String getNumericFunctions() {
return "";
}
/** @see java.sql.DatabaseMetaData#getStringFunctions() */
public String getStringFunctions() {
return "";
}
/** @see java.sql.DatabaseMetaData#getSystemFunctions() */
public String getSystemFunctions() {
return "";
}
/** @see java.sql.DatabaseMetaData#getTimeDateFunctions() */
public String getTimeDateFunctions() {
return "DATE,TIME,DATETIME,JULIANDAY,STRFTIME";
}
/** @see java.sql.DatabaseMetaData#getURL() */
public String getURL() {
return conn.getUrl();
}
/** @see java.sql.DatabaseMetaData#getUserName() */
public String getUserName() {
return null;
}
/** @see java.sql.DatabaseMetaData#allProceduresAreCallable() */
public boolean allProceduresAreCallable() {
return false;
}
/** @see java.sql.DatabaseMetaData#allTablesAreSelectable() */
public boolean allTablesAreSelectable() {
return true;
}
/** @see java.sql.DatabaseMetaData#dataDefinitionCausesTransactionCommit() */
public boolean dataDefinitionCausesTransactionCommit() {
return false;
}
/** @see java.sql.DatabaseMetaData#dataDefinitionIgnoredInTransactions() */
public boolean dataDefinitionIgnoredInTransactions() {
return false;
}
/** @see java.sql.DatabaseMetaData#doesMaxRowSizeIncludeBlobs() */
public boolean doesMaxRowSizeIncludeBlobs() {
return false;
}
/** @see java.sql.DatabaseMetaData#deletesAreDetected(int) */
public boolean deletesAreDetected(int type) {
return false;
}
/** @see java.sql.DatabaseMetaData#insertsAreDetected(int) */
public boolean insertsAreDetected(int type) {
return false;
}
/** @see java.sql.DatabaseMetaData#isCatalogAtStart() */
public boolean isCatalogAtStart() {
return true;
}
/** @see java.sql.DatabaseMetaData#locatorsUpdateCopy() */
public boolean locatorsUpdateCopy() {
return false;
}
/** @see java.sql.DatabaseMetaData#nullPlusNonNullIsNull() */
public boolean nullPlusNonNullIsNull() {
return true;
}
/** @see java.sql.DatabaseMetaData#nullsAreSortedAtEnd() */
public boolean nullsAreSortedAtEnd() {
return !nullsAreSortedAtStart();
}
/** @see java.sql.DatabaseMetaData#nullsAreSortedAtStart() */
public boolean nullsAreSortedAtStart() {
return true;
}
/** @see java.sql.DatabaseMetaData#nullsAreSortedHigh() */
public boolean nullsAreSortedHigh() {
return true;
}
/** @see java.sql.DatabaseMetaData#nullsAreSortedLow() */
public boolean nullsAreSortedLow() {
return !nullsAreSortedHigh();
}
/** @see java.sql.DatabaseMetaData#othersDeletesAreVisible(int) */
public boolean othersDeletesAreVisible(int type) {
return false;
}
/** @see java.sql.DatabaseMetaData#othersInsertsAreVisible(int) */
public boolean othersInsertsAreVisible(int type) {
return false;
}
/** @see java.sql.DatabaseMetaData#othersUpdatesAreVisible(int) */
public boolean othersUpdatesAreVisible(int type) {
return false;
}
/** @see java.sql.DatabaseMetaData#ownDeletesAreVisible(int) */
public boolean ownDeletesAreVisible(int type) {
return false;
}
/** @see java.sql.DatabaseMetaData#ownInsertsAreVisible(int) */
public boolean ownInsertsAreVisible(int type) {
return false;
}
/** @see java.sql.DatabaseMetaData#ownUpdatesAreVisible(int) */
public boolean ownUpdatesAreVisible(int type) {
return false;
}
/** @see java.sql.DatabaseMetaData#storesLowerCaseIdentifiers() */
public boolean storesLowerCaseIdentifiers() {
return false;
}
/** @see java.sql.DatabaseMetaData#storesLowerCaseQuotedIdentifiers() */
public boolean storesLowerCaseQuotedIdentifiers() {
return false;
}
/** @see java.sql.DatabaseMetaData#storesMixedCaseIdentifiers() */
public boolean storesMixedCaseIdentifiers() {
return true;
}
/** @see java.sql.DatabaseMetaData#storesMixedCaseQuotedIdentifiers() */
public boolean storesMixedCaseQuotedIdentifiers() {
return false;
}
/** @see java.sql.DatabaseMetaData#storesUpperCaseIdentifiers() */
public boolean storesUpperCaseIdentifiers() {
return false;
}
/** @see java.sql.DatabaseMetaData#storesUpperCaseQuotedIdentifiers() */
public boolean storesUpperCaseQuotedIdentifiers() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsAlterTableWithAddColumn() */
public boolean supportsAlterTableWithAddColumn() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsAlterTableWithDropColumn() */
public boolean supportsAlterTableWithDropColumn() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsANSI92EntryLevelSQL() */
public boolean supportsANSI92EntryLevelSQL() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsANSI92FullSQL() */
public boolean supportsANSI92FullSQL() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsANSI92IntermediateSQL() */
public boolean supportsANSI92IntermediateSQL() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsBatchUpdates() */
public boolean supportsBatchUpdates() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsCatalogsInDataManipulation() */
public boolean supportsCatalogsInDataManipulation() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsCatalogsInIndexDefinitions() */
public boolean supportsCatalogsInIndexDefinitions() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsCatalogsInPrivilegeDefinitions() */
public boolean supportsCatalogsInPrivilegeDefinitions() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsCatalogsInProcedureCalls() */
public boolean supportsCatalogsInProcedureCalls() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsCatalogsInTableDefinitions() */
public boolean supportsCatalogsInTableDefinitions() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsColumnAliasing() */
public boolean supportsColumnAliasing() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsConvert() */
public boolean supportsConvert() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsConvert(int, int) */
public boolean supportsConvert(int fromType, int toType) {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsCorrelatedSubqueries() */
public boolean supportsCorrelatedSubqueries() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsDataDefinitionAndDataManipulationTransactions() */
public boolean supportsDataDefinitionAndDataManipulationTransactions() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsDataManipulationTransactionsOnly() */
public boolean supportsDataManipulationTransactionsOnly() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsDifferentTableCorrelationNames() */
public boolean supportsDifferentTableCorrelationNames() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsExpressionsInOrderBy() */
public boolean supportsExpressionsInOrderBy() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsMinimumSQLGrammar() */
public boolean supportsMinimumSQLGrammar() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsCoreSQLGrammar() */
public boolean supportsCoreSQLGrammar() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsExtendedSQLGrammar() */
public boolean supportsExtendedSQLGrammar() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsLimitedOuterJoins() */
public boolean supportsLimitedOuterJoins() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsFullOuterJoins() */
public boolean supportsFullOuterJoins() throws SQLException {
String[] version = conn.libversion().split("\\.");
return Integer.parseInt(version[0]) >= 3 && Integer.parseInt(version[1]) >= 39;
}
/** @see java.sql.DatabaseMetaData#supportsGetGeneratedKeys() */
public boolean supportsGetGeneratedKeys() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsGroupBy() */
public boolean supportsGroupBy() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsGroupByBeyondSelect() */
public boolean supportsGroupByBeyondSelect() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsGroupByUnrelated() */
public boolean supportsGroupByUnrelated() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsIntegrityEnhancementFacility() */
public boolean supportsIntegrityEnhancementFacility() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsLikeEscapeClause() */
public boolean supportsLikeEscapeClause() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsMixedCaseIdentifiers() */
public boolean supportsMixedCaseIdentifiers() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsMixedCaseQuotedIdentifiers() */
public boolean supportsMixedCaseQuotedIdentifiers() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsMultipleOpenResults() */
public boolean supportsMultipleOpenResults() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsMultipleResultSets() */
public boolean supportsMultipleResultSets() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsMultipleTransactions() */
public boolean supportsMultipleTransactions() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsNamedParameters() */
public boolean supportsNamedParameters() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsNonNullableColumns() */
public boolean supportsNonNullableColumns() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsOpenCursorsAcrossCommit() */
public boolean supportsOpenCursorsAcrossCommit() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsOpenCursorsAcrossRollback() */
public boolean supportsOpenCursorsAcrossRollback() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsOpenStatementsAcrossCommit() */
public boolean supportsOpenStatementsAcrossCommit() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsOpenStatementsAcrossRollback() */
public boolean supportsOpenStatementsAcrossRollback() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsOrderByUnrelated() */
public boolean supportsOrderByUnrelated() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsOuterJoins() */
public boolean supportsOuterJoins() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsPositionedDelete() */
public boolean supportsPositionedDelete() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsPositionedUpdate() */
public boolean supportsPositionedUpdate() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsResultSetConcurrency(int, int) */
public boolean supportsResultSetConcurrency(int t, int c) {
return t == ResultSet.TYPE_FORWARD_ONLY && c == ResultSet.CONCUR_READ_ONLY;
}
/** @see java.sql.DatabaseMetaData#supportsResultSetHoldability(int) */
public boolean supportsResultSetHoldability(int h) {
return h == ResultSet.CLOSE_CURSORS_AT_COMMIT;
}
/** @see java.sql.DatabaseMetaData#supportsResultSetType(int) */
public boolean supportsResultSetType(int t) {
return t == ResultSet.TYPE_FORWARD_ONLY;
}
/** @see java.sql.DatabaseMetaData#supportsSavepoints() */
public boolean supportsSavepoints() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsSchemasInDataManipulation() */
public boolean supportsSchemasInDataManipulation() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsSchemasInIndexDefinitions() */
public boolean supportsSchemasInIndexDefinitions() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsSchemasInPrivilegeDefinitions() */
public boolean supportsSchemasInPrivilegeDefinitions() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsSchemasInProcedureCalls() */
public boolean supportsSchemasInProcedureCalls() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsSchemasInTableDefinitions() */
public boolean supportsSchemasInTableDefinitions() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsSelectForUpdate() */
public boolean supportsSelectForUpdate() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsStatementPooling() */
public boolean supportsStatementPooling() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsStoredProcedures() */
public boolean supportsStoredProcedures() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsSubqueriesInComparisons() */
public boolean supportsSubqueriesInComparisons() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsSubqueriesInExists() */
public boolean supportsSubqueriesInExists() {
return true;
} // TODO: check
/** @see java.sql.DatabaseMetaData#supportsSubqueriesInIns() */
public boolean supportsSubqueriesInIns() {
return true;
} // TODO: check
/** @see java.sql.DatabaseMetaData#supportsSubqueriesInQuantifieds() */
public boolean supportsSubqueriesInQuantifieds() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsTableCorrelationNames() */
public boolean supportsTableCorrelationNames() {
return false;
}
/** @see java.sql.DatabaseMetaData#supportsTransactionIsolationLevel(int) */
public boolean supportsTransactionIsolationLevel(int level) {
return level == Connection.TRANSACTION_SERIALIZABLE;
}
/** @see java.sql.DatabaseMetaData#supportsTransactions() */
public boolean supportsTransactions() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsUnion() */
public boolean supportsUnion() {
return true;
}
/** @see java.sql.DatabaseMetaData#supportsUnionAll() */
public boolean supportsUnionAll() {
return true;
}
/** @see java.sql.DatabaseMetaData#updatesAreDetected(int) */
public boolean updatesAreDetected(int type) {
return false;
}
/** @see java.sql.DatabaseMetaData#usesLocalFilePerTable() */
public boolean usesLocalFilePerTable() {
return false;
}
/** @see java.sql.DatabaseMetaData#usesLocalFiles() */
public boolean usesLocalFiles() {
return true;
}
/** @see java.sql.DatabaseMetaData#isReadOnly() */
public boolean isReadOnly() throws SQLException {
return conn.isReadOnly();
}
/**
* @see java.sql.DatabaseMetaData#getAttributes(java.lang.String, java.lang.String,
* java.lang.String, java.lang.String)
*/
public ResultSet getAttributes(String c, String s, String t, String a) throws SQLException {
if (getAttributes == null) {
getAttributes =
conn.prepareStatement(
"select null as TYPE_CAT, null as TYPE_SCHEM, "
+ "null as TYPE_NAME, null as ATTR_NAME, null as DATA_TYPE, "
+ "null as ATTR_TYPE_NAME, null as ATTR_SIZE, null as DECIMAL_DIGITS, "
+ "null as NUM_PREC_RADIX, null as NULLABLE, null as REMARKS, null as ATTR_DEF, "
+ "null as SQL_DATA_TYPE, null as SQL_DATETIME_SUB, null as CHAR_OCTET_LENGTH, "
+ "null as ORDINAL_POSITION, null as IS_NULLABLE, null as SCOPE_CATALOG, "
+ "null as SCOPE_SCHEMA, null as SCOPE_TABLE, null as SOURCE_DATA_TYPE limit 0;");
}
return getAttributes.executeQuery();
}
/**
* @see java.sql.DatabaseMetaData#getBestRowIdentifier(java.lang.String, java.lang.String,
* java.lang.String, int, boolean)
*/
public ResultSet getBestRowIdentifier(String c, String s, String t, int scope, boolean n)
throws SQLException {
if (getBestRowIdentifier == null) {
getBestRowIdentifier =
conn.prepareStatement(
"select null as SCOPE, null as COLUMN_NAME, "
+ "null as DATA_TYPE, null as TYPE_NAME, null as COLUMN_SIZE, "
+ "null as BUFFER_LENGTH, null as DECIMAL_DIGITS, null as PSEUDO_COLUMN limit 0;");
}
return getBestRowIdentifier.executeQuery();
}
/**
* @see java.sql.DatabaseMetaData#getColumnPrivileges(java.lang.String, java.lang.String,
* java.lang.String, java.lang.String)
*/
public ResultSet getColumnPrivileges(String c, String s, String t, String colPat)
throws SQLException {
if (getColumnPrivileges == null) {
getColumnPrivileges =
conn.prepareStatement(
"select null as TABLE_CAT, null as TABLE_SCHEM, "
+ "null as TABLE_NAME, null as COLUMN_NAME, null as GRANTOR, null as GRANTEE, "
+ "null as PRIVILEGE, null as IS_GRANTABLE limit 0;");
}
return getColumnPrivileges.executeQuery();
}
// Column type patterns
protected static final Pattern TYPE_INTEGER = Pattern.compile(".*(INT|BOOL).*");
protected static final Pattern TYPE_VARCHAR = Pattern.compile(".*(CHAR|CLOB|TEXT|BLOB).*");
protected static final Pattern TYPE_FLOAT = Pattern.compile(".*(REAL|FLOA|DOUB|DEC|NUM).*");
/**
* @see java.sql.DatabaseMetaData#getColumns(java.lang.String, java.lang.String,
* java.lang.String, java.lang.String)
*/
public ResultSet getColumns(String c, String s, String tblNamePattern, String colNamePattern)
throws SQLException {
// get the list of tables matching the pattern (getTables)
// create a Matrix Cursor for each of the tables
// create a merge cursor from all the Matrix Cursors
// and return the columname and type from:
// "PRAGMA table_xinfo(tablename)"
// which returns data like this:
// sqlite> PRAGMA lastyear.table_info(gross_sales);
// cid|name|type|notnull|dflt_value|pk
// 0|year|INTEGER|0|'2006'|0
// 1|month|TEXT|0||0
// 2|monthlygross|REAL|0||0
// 3|sortcol|INTEGER|0||0
// sqlite>
// and then make the cursor have these columns
// TABLE_CAT String => table catalog (may be null)
// TABLE_SCHEM String => table schema (may be null)
// TABLE_NAME String => table name
// COLUMN_NAME String => column name
// DATA_TYPE int => SQL type from java.sql.Types
// TYPE_NAME String => Data source dependent type name, for a UDT the type name is
// fully qualified
// COLUMN_SIZE int => column size.
// BUFFER_LENGTH is not used.
// DECIMAL_DIGITS int => the number of fractional digits. Null is returned for data
// types where DECIMAL_DIGITS is not applicable.
// NUM_PREC_RADIX int => Radix (typically either 10 or 2)
// NULLABLE int => is NULL allowed.
// columnNoNulls - might not allow NULL values
// columnNullable - definitely allows NULL values
// columnNullableUnknown - nullability unknown
// REMARKS String => comment describing column (may be null)
// COLUMN_DEF String => default value for the column, which should be interpreted as
// a string when the value is enclosed in single quotes (may be null)
// SQL_DATA_TYPE int => unused
// SQL_DATETIME_SUB int => unused
// CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column
// ORDINAL_POSITION int => index of column in table (starting at 1)
// IS_NULLABLE String => ISO rules are used to determine the nullability for a
// column.
// YES --- if the parameter can include NULLs
// NO --- if the parameter cannot include NULLs
// empty string --- if the nullability for the parameter is unknown
// SCOPE_CATALOG String => catalog of table that is the scope of a reference
// attribute
// (null if DATA_TYPE isn't REF)
// SCOPE_SCHEMA String => schema of table that is the scope of a reference attribute
// (null if the DATA_TYPE isn't REF)
// SCOPE_TABLE String => table name that this the scope of a reference attribute
// (null if the DATA_TYPE isn't REF)
// SOURCE_DATA_TYPE short => source type of a distinct type or user-generated Ref
// type, SQL type from java.sql.Types (null if DATA_TYPE isn't DISTINCT or user-generated
// REF)
// IS_AUTOINCREMENT String => Indicates whether this column is auto incremented
// YES --- if the column is auto incremented
// NO --- if the column is not auto incremented
// empty string --- if it cannot be determined whether the column is auto incremented
// parameter is unknown
// IS_GENERATEDCOLUMN String => Indicates whether this column is auto incremented
// YES --- if the column is generated
// NO --- if the column is not generated
// empty string --- if it cannot be determined whether the column is auto incremented
// parameter is unknown
checkOpen();
StringBuilder sql = new StringBuilder(700);
sql.append("select null as TABLE_CAT, null as TABLE_SCHEM, tblname as TABLE_NAME, ")
.append(
"cn as COLUMN_NAME, ct as DATA_TYPE, tn as TYPE_NAME, colSize as COLUMN_SIZE, ")
.append(
"2000000000 as BUFFER_LENGTH, colDecimalDigits as DECIMAL_DIGITS, 10 as NUM_PREC_RADIX, ")
.append("colnullable as NULLABLE, null as REMARKS, colDefault as COLUMN_DEF, ")
.append(
"0 as SQL_DATA_TYPE, 0 as SQL_DATETIME_SUB, 2000000000 as CHAR_OCTET_LENGTH, ")
.append(
"ordpos as ORDINAL_POSITION, (case colnullable when 0 then 'NO' when 1 then 'YES' else '' end)")
.append(" as IS_NULLABLE, null as SCOPE_CATALOG, null as SCOPE_SCHEMA, ")
.append("null as SCOPE_TABLE, null as SOURCE_DATA_TYPE, ")
.append(
"(case colautoincrement when 0 then 'NO' when 1 then 'YES' else '' end) as IS_AUTOINCREMENT, ")
.append(
"(case colgenerated when 0 then 'NO' when 1 then 'YES' else '' end) as IS_GENERATEDCOLUMN from (");
boolean colFound = false;
ResultSet rs = null;
try {
// Get all tables implied by the input
rs = getTables(c, s, tblNamePattern, null);
while (rs.next()) {
String tableName = rs.getString(3);
boolean isAutoIncrement;
Statement statColAutoinc = conn.createStatement();
ResultSet rsColAutoinc = null;
try {
statColAutoinc = conn.createStatement();
rsColAutoinc =
statColAutoinc.executeQuery(
"SELECT LIKE('%autoincrement%', LOWER(sql)) FROM sqlite_schema "
+ "WHERE LOWER(name) = LOWER('"
+ escape(tableName)
+ "') AND TYPE IN ('table', 'view')");
rsColAutoinc.next();
isAutoIncrement = rsColAutoinc.getInt(1) == 1;
} finally {
if (rsColAutoinc != null) {
try {
rsColAutoinc.close();
} catch (Exception e) {
LogHolder.logger.error("Could not close ResultSet", e);
}
}
if (statColAutoinc != null) {
try {
statColAutoinc.close();
} catch (Exception e) {
LogHolder.logger.error("Could not close statement", e);
}
}
}
// For each table, get the column info and build into overall SQL
String pragmaStatement = "PRAGMA table_xinfo('" + escape(tableName) + "')";
try (Statement colstat = conn.createStatement();
ResultSet rscol = colstat.executeQuery(pragmaStatement)) {
for (int i = 0; rscol.next(); i++) {
String colName = rscol.getString(2);
String colType = rscol.getString(3);
String colNotNull = rscol.getString(4);
String colDefault = rscol.getString(5);
boolean isPk = "1".equals(rscol.getString(6));
String colHidden = rscol.getString(7);
int colNullable = 2;
if (colNotNull != null) {
colNullable = colNotNull.equals("0") ? 1 : 0;
}
if (colFound) {
sql.append(" union all ");
}
colFound = true;