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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.jdbc;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.RowIdLifetime;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Arrays;
import java.util.Properties;
import org.h2.engine.Constants;
import org.h2.engine.Mode.ModeEnum;
import org.h2.engine.SessionInterface;
import org.h2.engine.SessionRemote;
import org.h2.engine.SysProperties;
import org.h2.message.DbException;
import org.h2.message.Trace;
import org.h2.message.TraceObject;
import org.h2.tools.SimpleResultSet;
import org.h2.util.StatementBuilder;
import org.h2.util.StringUtils;
/**
* Represents the meta data for a database.
*/
public class JdbcDatabaseMetaData extends TraceObject implements
DatabaseMetaData, JdbcDatabaseMetaDataBackwardsCompat {
private final JdbcConnection conn;
JdbcDatabaseMetaData(JdbcConnection conn, Trace trace, int id) {
setTrace(trace, TraceObject.DATABASE_META_DATA, id);
this.conn = conn;
}
/**
* Returns the major version of this driver.
*
* @return the major version number
*/
@Override
public int getDriverMajorVersion() {
debugCodeCall("getDriverMajorVersion");
return Constants.VERSION_MAJOR;
}
/**
* Returns the minor version of this driver.
*
* @return the minor version number
*/
@Override
public int getDriverMinorVersion() {
debugCodeCall("getDriverMinorVersion");
return Constants.VERSION_MINOR;
}
/**
* Gets the database product name.
*
* @return the product name ("H2")
*/
@Override
public String getDatabaseProductName() {
debugCodeCall("getDatabaseProductName");
// This value must stay like that, see
// http://opensource.atlassian.com/projects/hibernate/browse/HHH-2682
return "H2";
}
/**
* Gets the product version of the database.
*
* @return the product version
*/
@Override
public String getDatabaseProductVersion() {
debugCodeCall("getDatabaseProductVersion");
return Constants.getFullVersion();
}
/**
* Gets the name of the JDBC driver.
*
* @return the driver name ("H2 JDBC Driver")
*/
@Override
public String getDriverName() {
debugCodeCall("getDriverName");
return "H2 JDBC Driver";
}
/**
* Gets the version number of the driver. The format is
* [MajorVersion].[MinorVersion].
*
* @return the version number
*/
@Override
public String getDriverVersion() {
debugCodeCall("getDriverVersion");
return Constants.getFullVersion();
}
private boolean hasSynonyms() {
SessionInterface si = conn.getSession();
return !(si instanceof SessionRemote)
|| ((SessionRemote) si).getClientVersion() >= Constants.TCP_PROTOCOL_VERSION_17;
}
/**
* Gets the list of tables in the database. The result set is sorted by
* TABLE_TYPE, TABLE_SCHEM, and TABLE_NAME.
*
* <ol>
* <li>TABLE_CAT (String) table catalog</li>
* <li>TABLE_SCHEM (String) table schema</li>
* <li>TABLE_NAME (String) table name</li>
* <li>TABLE_TYPE (String) table type</li>
* <li>REMARKS (String) comment</li>
* <li>TYPE_CAT (String) always null</li>
* <li>TYPE_SCHEM (String) always null</li>
* <li>TYPE_NAME (String) always null</li>
* <li>SELF_REFERENCING_COL_NAME (String) always null</li>
* <li>REF_GENERATION (String) always null</li>
* <li>SQL (String) the create table statement or NULL for systems tables.</li>
* </ol>
*
* @param catalogPattern null (to get all objects) or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @param tableNamePattern null (to get all objects) or a table name
* (uppercase for unquoted names)
* @param types null or a list of table types
* @return the list of columns
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getTables(String catalogPattern, String schemaPattern,
String tableNamePattern, String[] types) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getTables(" + quote(catalogPattern) + ", " +
quote(schemaPattern) + ", " + quote(tableNamePattern) +
", " + quoteArray(types) + ");");
}
checkClosed();
int typesLength = types != null ? types.length : 0;
boolean includeSynonyms = hasSynonyms() && (types == null || Arrays.asList(types).contains("SYNONYM"));
// (1024 - 16) is enough for the most cases
StringBuilder select = new StringBuilder(1008);
if (includeSynonyms) {
select.append("SELECT "
+ "TABLE_CAT, "
+ "TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "TABLE_TYPE, "
+ "REMARKS, "
+ "TYPE_CAT, "
+ "TYPE_SCHEM, "
+ "TYPE_NAME, "
+ "SELF_REFERENCING_COL_NAME, "
+ "REF_GENERATION, "
+ "SQL "
+ "FROM ("
+ "SELECT "
+ "SYNONYM_CATALOG TABLE_CAT, "
+ "SYNONYM_SCHEMA TABLE_SCHEM, "
+ "SYNONYM_NAME as TABLE_NAME, "
+ "TYPE_NAME AS TABLE_TYPE, "
+ "REMARKS, "
+ "TYPE_NAME TYPE_CAT, "
+ "TYPE_NAME TYPE_SCHEM, "
+ "TYPE_NAME AS TYPE_NAME, "
+ "TYPE_NAME SELF_REFERENCING_COL_NAME, "
+ "TYPE_NAME REF_GENERATION, "
+ "NULL AS SQL "
+ "FROM INFORMATION_SCHEMA.SYNONYMS "
+ "WHERE SYNONYM_CATALOG LIKE ?1 ESCAPE ?4 "
+ "AND SYNONYM_SCHEMA LIKE ?2 ESCAPE ?4 "
+ "AND SYNONYM_NAME LIKE ?3 ESCAPE ?4 "
+ "UNION ");
}
select.append("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "TABLE_TYPE, "
+ "REMARKS, "
+ "TYPE_NAME TYPE_CAT, "
+ "TYPE_NAME TYPE_SCHEM, "
+ "TYPE_NAME, "
+ "TYPE_NAME SELF_REFERENCING_COL_NAME, "
+ "TYPE_NAME REF_GENERATION, "
+ "SQL "
+ "FROM INFORMATION_SCHEMA.TABLES "
+ "WHERE TABLE_CATALOG LIKE ?1 ESCAPE ?4 "
+ "AND TABLE_SCHEMA LIKE ?2 ESCAPE ?4 "
+ "AND TABLE_NAME LIKE ?3 ESCAPE ?4");
if (typesLength > 0) {
select.append(" AND TABLE_TYPE IN(");
for (int i = 0; i < typesLength; i++) {
if (i > 0) {
select.append(", ");
}
select.append('?').append(i + 5);
}
select.append(')');
}
if (includeSynonyms) {
select.append(')');
}
PreparedStatement prep = conn.prepareAutoCloseStatement(
select.append(" ORDER BY TABLE_TYPE, TABLE_SCHEM, TABLE_NAME").toString());
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, getSchemaPattern(schemaPattern));
prep.setString(3, getPattern(tableNamePattern));
prep.setString(4, "\\");
for (int i = 0; i < typesLength; i++) {
prep.setString(5 + i, types[i]);
}
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of columns. The result set is sorted by TABLE_SCHEM,
* TABLE_NAME, and ORDINAL_POSITION.
*
* <ol>
* <li>TABLE_CAT (String) table catalog</li>
* <li>TABLE_SCHEM (String) table schema</li>
* <li>TABLE_NAME (String) table name</li>
* <li>COLUMN_NAME (String) column name</li>
* <li>DATA_TYPE (short) data type (see java.sql.Types)</li>
* <li>TYPE_NAME (String) data type name ("INTEGER", "VARCHAR",...)</li>
* <li>COLUMN_SIZE (int) precision
* (values larger than 2 GB are returned as 2 GB)</li>
* <li>BUFFER_LENGTH (int) unused</li>
* <li>DECIMAL_DIGITS (int) scale (0 for INTEGER and VARCHAR)</li>
* <li>NUM_PREC_RADIX (int) radix (always 10)</li>
* <li>NULLABLE (int) columnNoNulls or columnNullable</li>
* <li>REMARKS (String) comment (always empty)</li>
* <li>COLUMN_DEF (String) default value</li>
* <li>SQL_DATA_TYPE (int) unused</li>
* <li>SQL_DATETIME_SUB (int) unused</li>
* <li>CHAR_OCTET_LENGTH (int) unused</li>
* <li>ORDINAL_POSITION (int) the column index (1,2,...)</li>
* <li>IS_NULLABLE (String) "NO" or "YES"</li>
* <li>SCOPE_CATALOG (String) always null</li>
* <li>SCOPE_SCHEMA (String) always null</li>
* <li>SCOPE_TABLE (String) always null</li>
* <li>SOURCE_DATA_TYPE (short) null</li>
* <li>IS_AUTOINCREMENT (String) "NO" or "YES"</li>
* <li>IS_GENERATEDCOLUMN (String) "NO" or "YES"</li>
* </ol>
*
* @param catalogPattern null (to get all objects) or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @param tableNamePattern null (to get all objects) or a table name
* (uppercase for unquoted names)
* @param columnNamePattern null (to get all objects) or a column name
* (uppercase for unquoted names)
* @return the list of columns
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getColumns(String catalogPattern, String schemaPattern,
String tableNamePattern, String columnNamePattern)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getColumns(" + quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableNamePattern)+", "
+quote(columnNamePattern)+");");
}
checkClosed();
boolean includeSynonyms = hasSynonyms();
StringBuilder select = new StringBuilder(2432);
if (includeSynonyms) {
select.append("SELECT "
+ "TABLE_CAT, "
+ "TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "COLUMN_NAME, "
+ "DATA_TYPE, "
+ "TYPE_NAME, "
+ "COLUMN_SIZE, "
+ "BUFFER_LENGTH, "
+ "DECIMAL_DIGITS, "
+ "NUM_PREC_RADIX, "
+ "NULLABLE, "
+ "REMARKS, "
+ "COLUMN_DEF, "
+ "SQL_DATA_TYPE, "
+ "SQL_DATETIME_SUB, "
+ "CHAR_OCTET_LENGTH, "
+ "ORDINAL_POSITION, "
+ "IS_NULLABLE, "
+ "SCOPE_CATALOG, "
+ "SCOPE_SCHEMA, "
+ "SCOPE_TABLE, "
+ "SOURCE_DATA_TYPE, "
+ "IS_AUTOINCREMENT, "
+ "IS_GENERATEDCOLUMN "
+ "FROM ("
+ "SELECT "
+ "s.SYNONYM_CATALOG TABLE_CAT, "
+ "s.SYNONYM_SCHEMA TABLE_SCHEM, "
+ "s.SYNONYM_NAME TABLE_NAME, "
+ "c.COLUMN_NAME, "
+ "c.DATA_TYPE, "
+ "c.TYPE_NAME, "
+ "c.CHARACTER_MAXIMUM_LENGTH COLUMN_SIZE, "
+ "c.CHARACTER_MAXIMUM_LENGTH BUFFER_LENGTH, "
+ "c.NUMERIC_SCALE DECIMAL_DIGITS, "
+ "c.NUMERIC_PRECISION_RADIX NUM_PREC_RADIX, "
+ "c.NULLABLE, "
+ "c.REMARKS, "
+ "c.COLUMN_DEFAULT COLUMN_DEF, "
+ "c.DATA_TYPE SQL_DATA_TYPE, "
+ "ZERO() SQL_DATETIME_SUB, "
+ "c.CHARACTER_OCTET_LENGTH CHAR_OCTET_LENGTH, "
+ "c.ORDINAL_POSITION, "
+ "c.IS_NULLABLE IS_NULLABLE, "
+ "CAST(c.SOURCE_DATA_TYPE AS VARCHAR) SCOPE_CATALOG, "
+ "CAST(c.SOURCE_DATA_TYPE AS VARCHAR) SCOPE_SCHEMA, "
+ "CAST(c.SOURCE_DATA_TYPE AS VARCHAR) SCOPE_TABLE, "
+ "c.SOURCE_DATA_TYPE, "
+ "CASE WHEN c.SEQUENCE_NAME IS NULL THEN "
+ "CAST(?1 AS VARCHAR) ELSE CAST(?2 AS VARCHAR) END IS_AUTOINCREMENT, "
+ "CASE WHEN c.IS_COMPUTED THEN "
+ "CAST(?2 AS VARCHAR) ELSE CAST(?1 AS VARCHAR) END IS_GENERATEDCOLUMN "
+ "FROM INFORMATION_SCHEMA.COLUMNS c JOIN INFORMATION_SCHEMA.SYNONYMS s ON "
+ "s.SYNONYM_FOR = c.TABLE_NAME "
+ "AND s.SYNONYM_FOR_SCHEMA = c.TABLE_SCHEMA "
+ "WHERE s.SYNONYM_CATALOG LIKE ?3 ESCAPE ?7 "
+ "AND s.SYNONYM_SCHEMA LIKE ?4 ESCAPE ?7 "
+ "AND s.SYNONYM_NAME LIKE ?5 ESCAPE ?7 "
+ "AND c.COLUMN_NAME LIKE ?6 ESCAPE ?7 "
+ "UNION ");
}
select.append("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "COLUMN_NAME, "
+ "DATA_TYPE, "
+ "TYPE_NAME, "
+ "CHARACTER_MAXIMUM_LENGTH COLUMN_SIZE, "
+ "CHARACTER_MAXIMUM_LENGTH BUFFER_LENGTH, "
+ "NUMERIC_SCALE DECIMAL_DIGITS, "
+ "NUMERIC_PRECISION_RADIX NUM_PREC_RADIX, "
+ "NULLABLE, "
+ "REMARKS, "
+ "COLUMN_DEFAULT COLUMN_DEF, "
+ "DATA_TYPE SQL_DATA_TYPE, "
+ "ZERO() SQL_DATETIME_SUB, "
+ "CHARACTER_OCTET_LENGTH CHAR_OCTET_LENGTH, "
+ "ORDINAL_POSITION, "
+ "IS_NULLABLE IS_NULLABLE, "
+ "CAST(SOURCE_DATA_TYPE AS VARCHAR) SCOPE_CATALOG, "
+ "CAST(SOURCE_DATA_TYPE AS VARCHAR) SCOPE_SCHEMA, "
+ "CAST(SOURCE_DATA_TYPE AS VARCHAR) SCOPE_TABLE, "
+ "SOURCE_DATA_TYPE, "
+ "CASE WHEN SEQUENCE_NAME IS NULL THEN "
+ "CAST(?1 AS VARCHAR) ELSE CAST(?2 AS VARCHAR) END IS_AUTOINCREMENT, "
+ "CASE WHEN IS_COMPUTED THEN "
+ "CAST(?2 AS VARCHAR) ELSE CAST(?1 AS VARCHAR) END IS_GENERATEDCOLUMN "
+ "FROM INFORMATION_SCHEMA.COLUMNS "
+ "WHERE TABLE_CATALOG LIKE ?3 ESCAPE ?7 "
+ "AND TABLE_SCHEMA LIKE ?4 ESCAPE ?7 "
+ "AND TABLE_NAME LIKE ?5 ESCAPE ?7 "
+ "AND COLUMN_NAME LIKE ?6 ESCAPE ?7");
if (includeSynonyms) {
select.append(')');
}
PreparedStatement prep = conn.prepareAutoCloseStatement(
select.append(" ORDER BY TABLE_SCHEM, TABLE_NAME, ORDINAL_POSITION").toString());
prep.setString(1, "NO");
prep.setString(2, "YES");
prep.setString(3, getCatalogPattern(catalogPattern));
prep.setString(4, getSchemaPattern(schemaPattern));
prep.setString(5, getPattern(tableNamePattern));
prep.setString(6, getPattern(columnNamePattern));
prep.setString(7, "\\");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of indexes for this database. The primary key index (if
* there is one) is also listed, with the name PRIMARY_KEY. The result set
* is sorted by NON_UNIQUE ('false' first), TYPE, TABLE_SCHEM, INDEX_NAME,
* and ORDINAL_POSITION.
*
* <ol>
* <li>TABLE_CAT (String) table catalog</li>
* <li>TABLE_SCHEM (String) table schema</li>
* <li>TABLE_NAME (String) table name</li>
* <li>NON_UNIQUE (boolean) 'true' if non-unique</li>
* <li>INDEX_QUALIFIER (String) index catalog</li>
* <li>INDEX_NAME (String) index name</li>
* <li>TYPE (short) the index type (always tableIndexOther)</li>
* <li>ORDINAL_POSITION (short) column index (1, 2, ...)</li>
* <li>COLUMN_NAME (String) column name</li>
* <li>ASC_OR_DESC (String) ascending or descending (always 'A')</li>
* <li>CARDINALITY (int) numbers of unique values</li>
* <li>PAGES (int) number of pages use (always 0)</li>
* <li>FILTER_CONDITION (String) filter condition (always empty)</li>
* <li>SORT_TYPE (int) the sort type bit map: 1=DESCENDING,
* 2=NULLS_FIRST, 4=NULLS_LAST</li>
* </ol>
*
* @param catalogPattern null or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @param tableName table name (must be specified)
* @param unique only unique indexes
* @param approximate is ignored
* @return the list of indexes and columns
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getIndexInfo(String catalogPattern, String schemaPattern,
String tableName, boolean unique, boolean approximate)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getIndexInfo(" + quote(catalogPattern) + ", " +
quote(schemaPattern) + ", " + quote(tableName) + ", " +
unique + ", " + approximate + ");");
}
String uniqueCondition;
if (unique) {
uniqueCondition = "NON_UNIQUE=FALSE";
} else {
uniqueCondition = "TRUE";
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "NON_UNIQUE, "
+ "TABLE_CATALOG INDEX_QUALIFIER, "
+ "INDEX_NAME, "
+ "INDEX_TYPE TYPE, "
+ "ORDINAL_POSITION, "
+ "COLUMN_NAME, "
+ "ASC_OR_DESC, "
// TODO meta data for number of unique values in an index
+ "CARDINALITY, "
+ "PAGES, "
+ "FILTER_CONDITION, "
+ "SORT_TYPE "
+ "FROM INFORMATION_SCHEMA.INDEXES "
+ "WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND (" + uniqueCondition + ") "
+ "AND TABLE_NAME = ? "
+ "ORDER BY NON_UNIQUE, TYPE, TABLE_SCHEM, INDEX_NAME, ORDINAL_POSITION");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, tableName);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the primary key columns for a table. The result set is sorted by
* TABLE_SCHEM, and COLUMN_NAME (and not by KEY_SEQ).
*
* <ol>
* <li>TABLE_CAT (String) table catalog</li>
* <li>TABLE_SCHEM (String) table schema</li>
* <li>TABLE_NAME (String) table name</li>
* <li>COLUMN_NAME (String) column name</li>
* <li>KEY_SEQ (short) the column index of this column (1,2,...)</li>
* <li>PK_NAME (String) the name of the primary key index</li>
* </ol>
*
* @param catalogPattern null or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @param tableName table name (must be specified)
* @return the list of primary key columns
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getPrimaryKeys(String catalogPattern,
String schemaPattern, String tableName) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getPrimaryKeys("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableName)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "COLUMN_NAME, "
+ "ORDINAL_POSITION KEY_SEQ, "
+ "IFNULL(CONSTRAINT_NAME, INDEX_NAME) PK_NAME "
+ "FROM INFORMATION_SCHEMA.INDEXES "
+ "WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND TABLE_NAME = ? "
+ "AND PRIMARY_KEY = TRUE "
+ "ORDER BY COLUMN_NAME");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, tableName);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Checks if all procedures callable.
*
* @return true
*/
@Override
public boolean allProceduresAreCallable() {
debugCodeCall("allProceduresAreCallable");
return true;
}
/**
* Checks if it possible to query all tables returned by getTables.
*
* @return true
*/
@Override
public boolean allTablesAreSelectable() {
debugCodeCall("allTablesAreSelectable");
return true;
}
/**
* Returns the database URL for this connection.
*
* @return the url
*/
@Override
public String getURL() throws SQLException {
try {
debugCodeCall("getURL");
return conn.getURL();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Returns the user name as passed to DriverManager.getConnection(url, user,
* password).
*
* @return the user name
*/
@Override
public String getUserName() throws SQLException {
try {
debugCodeCall("getUserName");
return conn.getUser();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Returns the same as Connection.isReadOnly().
*
* @return if read only optimization is switched on
*/
@Override
public boolean isReadOnly() throws SQLException {
try {
debugCodeCall("isReadOnly");
return conn.isReadOnly();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Checks if NULL is sorted high (bigger than anything that is not null).
*
* @return false by default; true if the system property h2.sortNullsHigh is
* set to true
*/
@Override
public boolean nullsAreSortedHigh() {
debugCodeCall("nullsAreSortedHigh");
return SysProperties.SORT_NULLS_HIGH;
}
/**
* Checks if NULL is sorted low (smaller than anything that is not null).
*
* @return true by default; false if the system property h2.sortNullsHigh is
* set to true
*/
@Override
public boolean nullsAreSortedLow() {
debugCodeCall("nullsAreSortedLow");
return !SysProperties.SORT_NULLS_HIGH;
}
/**
* Checks if NULL is sorted at the beginning (no matter if ASC or DESC is
* used).
*
* @return false
*/
@Override
public boolean nullsAreSortedAtStart() {
debugCodeCall("nullsAreSortedAtStart");
return false;
}
/**
* Checks if NULL is sorted at the end (no matter if ASC or DESC is used).
*
* @return false
*/
@Override
public boolean nullsAreSortedAtEnd() {
debugCodeCall("nullsAreSortedAtEnd");
return false;
}
/**
* Returns the connection that created this object.
*
* @return the connection
*/
@Override
public Connection getConnection() {
debugCodeCall("getConnection");
return conn;
}
/**
* Gets the list of procedures. The result set is sorted by PROCEDURE_SCHEM,
* PROCEDURE_NAME, and NUM_INPUT_PARAMS. There are potentially multiple
* procedures with the same name, each with a different number of input
* parameters.
*
* <ol>
* <li>PROCEDURE_CAT (String) catalog</li>
* <li>PROCEDURE_SCHEM (String) schema</li>
* <li>PROCEDURE_NAME (String) name</li>
* <li>NUM_INPUT_PARAMS (int) the number of arguments</li>
* <li>NUM_OUTPUT_PARAMS (int) for future use, always 0</li>
* <li>NUM_RESULT_SETS (int) for future use, always 0</li>
* <li>REMARKS (String) description</li>
* <li>PROCEDURE_TYPE (short) if this procedure returns a result
* (procedureNoResult or procedureReturnsResult)</li>
* <li>SPECIFIC_NAME (String) name</li>
* </ol>
*
* @param catalogPattern null or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @param procedureNamePattern the procedure name pattern
* @return the procedures
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getProcedures(String catalogPattern, String schemaPattern,
String procedureNamePattern) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getProcedures("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(procedureNamePattern)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "ALIAS_CATALOG PROCEDURE_CAT, "
+ "ALIAS_SCHEMA PROCEDURE_SCHEM, "
+ "ALIAS_NAME PROCEDURE_NAME, "
+ "COLUMN_COUNT NUM_INPUT_PARAMS, "
+ "ZERO() NUM_OUTPUT_PARAMS, "
+ "ZERO() NUM_RESULT_SETS, "
+ "REMARKS, "
+ "RETURNS_RESULT PROCEDURE_TYPE, "
+ "ALIAS_NAME SPECIFIC_NAME "
+ "FROM INFORMATION_SCHEMA.FUNCTION_ALIASES "
+ "WHERE ALIAS_CATALOG LIKE ? ESCAPE ? "
+ "AND ALIAS_SCHEMA LIKE ? ESCAPE ? "
+ "AND ALIAS_NAME LIKE ? ESCAPE ? "
+ "ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, NUM_INPUT_PARAMS");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, getPattern(procedureNamePattern));
prep.setString(6, "\\");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of procedure columns. The result set is sorted by
* PROCEDURE_SCHEM, PROCEDURE_NAME, NUM_INPUT_PARAMS, and POS.
* There are potentially multiple procedures with the same name, each with a
* different number of input parameters.
*
* <ol>
* <li>PROCEDURE_CAT (String) catalog</li>
* <li>PROCEDURE_SCHEM (String) schema</li>
* <li>PROCEDURE_NAME (String) name</li>
* <li>COLUMN_NAME (String) column name</li>
* <li>COLUMN_TYPE (short) column type
* (always DatabaseMetaData.procedureColumnIn)</li>
* <li>DATA_TYPE (short) sql type</li>
* <li>TYPE_NAME (String) type name</li>
* <li>PRECISION (int) precision</li>
* <li>LENGTH (int) length</li>
* <li>SCALE (short) scale</li>
* <li>RADIX (int) always 10</li>
* <li>NULLABLE (short) nullable
* (DatabaseMetaData.columnNoNulls for primitive data types,
* DatabaseMetaData.columnNullable otherwise)</li>
* <li>REMARKS (String) description</li>
* <li>COLUMN_DEF (String) always null</li>
* <li>SQL_DATA_TYPE (int) for future use, always 0</li>
* <li>SQL_DATETIME_SUB (int) for future use, always 0</li>
* <li>CHAR_OCTET_LENGTH (int) always null</li>
* <li>ORDINAL_POSITION (int) the parameter index
* starting from 1 (0 is the return value)</li>
* <li>IS_NULLABLE (String) always "YES"</li>
* <li>SPECIFIC_NAME (String) name</li>
* </ol>
*
* @param catalogPattern null or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @param procedureNamePattern the procedure name pattern
* @param columnNamePattern the procedure name pattern
* @return the procedure columns
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getProcedureColumns(String catalogPattern,
String schemaPattern, String procedureNamePattern,
String columnNamePattern) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getProcedureColumns("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(procedureNamePattern)+", "
+quote(columnNamePattern)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "ALIAS_CATALOG PROCEDURE_CAT, "
+ "ALIAS_SCHEMA PROCEDURE_SCHEM, "
+ "ALIAS_NAME PROCEDURE_NAME, "
+ "COLUMN_NAME, "
+ "COLUMN_TYPE, "
+ "DATA_TYPE, "
+ "TYPE_NAME, "
+ "PRECISION, "
+ "PRECISION LENGTH, "
+ "SCALE, "
+ "RADIX, "
+ "NULLABLE, "
+ "REMARKS, "
+ "COLUMN_DEFAULT COLUMN_DEF, "
+ "ZERO() SQL_DATA_TYPE, "
+ "ZERO() SQL_DATETIME_SUB, "
+ "ZERO() CHAR_OCTET_LENGTH, "
+ "POS ORDINAL_POSITION, "
+ "? IS_NULLABLE, "
+ "ALIAS_NAME SPECIFIC_NAME "
+ "FROM INFORMATION_SCHEMA.FUNCTION_COLUMNS "
+ "WHERE ALIAS_CATALOG LIKE ? ESCAPE ? "
+ "AND ALIAS_SCHEMA LIKE ? ESCAPE ? "
+ "AND ALIAS_NAME LIKE ? ESCAPE ? "
+ "AND COLUMN_NAME LIKE ? ESCAPE ? "
+ "ORDER BY PROCEDURE_SCHEM, PROCEDURE_NAME, ORDINAL_POSITION");
prep.setString(1, "YES");
prep.setString(2, getCatalogPattern(catalogPattern));
prep.setString(3, "\\");
prep.setString(4, getSchemaPattern(schemaPattern));
prep.setString(5, "\\");
prep.setString(6, getPattern(procedureNamePattern));
prep.setString(7, "\\");
prep.setString(8, getPattern(columnNamePattern));
prep.setString(9, "\\");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of schemas.
* The result set is sorted by TABLE_SCHEM.
*
* <ol>
* <li>TABLE_SCHEM (String) schema name</li>
* <li>TABLE_CATALOG (String) catalog name</li>
* <li>IS_DEFAULT (boolean) if this is the default schema</li>
* </ol>
*
* @return the schema list
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getSchemas() throws SQLException {
try {
debugCodeCall("getSchemas");
checkClosed();
PreparedStatement prep = conn
.prepareAutoCloseStatement("SELECT "
+ "SCHEMA_NAME TABLE_SCHEM, "
+ "CATALOG_NAME TABLE_CATALOG, "
+" IS_DEFAULT "
+ "FROM INFORMATION_SCHEMA.SCHEMATA "
+ "ORDER BY SCHEMA_NAME");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of catalogs.
* The result set is sorted by TABLE_CAT.
*
* <ol>
* <li>TABLE_CAT (String) catalog name</li>
* </ol>
*
* @return the catalog list
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getCatalogs() throws SQLException {
try {
debugCodeCall("getCatalogs");
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement(
"SELECT CATALOG_NAME TABLE_CAT "
+ "FROM INFORMATION_SCHEMA.CATALOGS");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of table types. This call returns a result set with five
* records: "SYSTEM TABLE", "TABLE", "VIEW", "TABLE LINK" and "EXTERNAL".
* <ol>
* <li>TABLE_TYPE (String) table type</li>
* </ol>
*
* @return the table types
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getTableTypes() throws SQLException {
try {
debugCodeCall("getTableTypes");
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TYPE TABLE_TYPE "
+ "FROM INFORMATION_SCHEMA.TABLE_TYPES "
+ "ORDER BY TABLE_TYPE");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of column privileges. The result set is sorted by
* COLUMN_NAME and PRIVILEGE
*
* <ol>
* <li>TABLE_CAT (String) table catalog</li>
* <li>TABLE_SCHEM (String) table schema</li>
* <li>TABLE_NAME (String) table name</li>
* <li>COLUMN_NAME (String) column name</li>
* <li>GRANTOR (String) grantor of access</li>
* <li>GRANTEE (String) grantee of access</li>
* <li>PRIVILEGE (String) SELECT, INSERT, UPDATE, DELETE or REFERENCES
* (only one per row)</li>
* <li>IS_GRANTABLE (String) YES means the grantee can grant access to
* others</li>
* </ol>
*
* @param catalogPattern null (to get all objects) or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @param table a table name (uppercase for unquoted names)
* @param columnNamePattern null (to get all objects) or a column name
* (uppercase for unquoted names)
* @return the list of privileges
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getColumnPrivileges(String catalogPattern,
String schemaPattern, String table, String columnNamePattern)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getColumnPrivileges("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(table)+", "
+quote(columnNamePattern)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "COLUMN_NAME, "
+ "GRANTOR, "
+ "GRANTEE, "
+ "PRIVILEGE_TYPE PRIVILEGE, "
+ "IS_GRANTABLE "
+ "FROM INFORMATION_SCHEMA.COLUMN_PRIVILEGES "
+ "WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND TABLE_NAME = ? "
+ "AND COLUMN_NAME LIKE ? ESCAPE ? "
+ "ORDER BY COLUMN_NAME, PRIVILEGE");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, table);
prep.setString(6, getPattern(columnNamePattern));
prep.setString(7, "\\");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of table privileges. The result set is sorted by
* TABLE_SCHEM, TABLE_NAME, and PRIVILEGE.
*
* <ol>
* <li>TABLE_CAT (String) table catalog</li>
* <li>TABLE_SCHEM (String) table schema</li>
* <li>TABLE_NAME (String) table name</li>
* <li>GRANTOR (String) grantor of access</li>
* <li>GRANTEE (String) grantee of access</li>
* <li>PRIVILEGE (String) SELECT, INSERT, UPDATE, DELETE or REFERENCES
* (only one per row)</li>
* <li>IS_GRANTABLE (String) YES means the grantee can grant access to
* others</li>
* </ol>
*
* @param catalogPattern null (to get all objects) or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @param tableNamePattern null (to get all objects) or a table name
* (uppercase for unquoted names)
* @return the list of privileges
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getTablePrivileges(String catalogPattern,
String schemaPattern, String tableNamePattern) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getTablePrivileges("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableNamePattern)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TABLE_CATALOG TABLE_CAT, "
+ "TABLE_SCHEMA TABLE_SCHEM, "
+ "TABLE_NAME, "
+ "GRANTOR, "
+ "GRANTEE, "
+ "PRIVILEGE_TYPE PRIVILEGE, "
+ "IS_GRANTABLE "
+ "FROM INFORMATION_SCHEMA.TABLE_PRIVILEGES "
+ "WHERE TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND TABLE_NAME LIKE ? ESCAPE ? "
+ "ORDER BY TABLE_SCHEM, TABLE_NAME, PRIVILEGE");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, getPattern(tableNamePattern));
prep.setString(6, "\\");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of columns that best identifier a row in a table.
* The list is ordered by SCOPE.
*
* <ol>
* <li>SCOPE (short) scope of result (always bestRowSession)</li>
* <li>COLUMN_NAME (String) column name</li>
* <li>DATA_TYPE (short) SQL data type, see also java.sql.Types</li>
* <li>TYPE_NAME (String) type name</li>
* <li>COLUMN_SIZE (int) precision
* (values larger than 2 GB are returned as 2 GB)</li>
* <li>BUFFER_LENGTH (int) unused</li>
* <li>DECIMAL_DIGITS (short) scale</li>
* <li>PSEUDO_COLUMN (short) (always bestRowNotPseudo)</li>
* </ol>
*
* @param catalogPattern null (to get all objects) or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @param tableName table name (must be specified)
* @param scope ignored
* @param nullable ignored
* @return the primary key index
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getBestRowIdentifier(String catalogPattern,
String schemaPattern, String tableName, int scope, boolean nullable)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getBestRowIdentifier("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableName)+", "
+scope+", "+nullable+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "CAST(? AS SMALLINT) SCOPE, "
+ "C.COLUMN_NAME, "
+ "C.DATA_TYPE, "
+ "C.TYPE_NAME, "
+ "C.CHARACTER_MAXIMUM_LENGTH COLUMN_SIZE, "
+ "C.CHARACTER_MAXIMUM_LENGTH BUFFER_LENGTH, "
+ "CAST(C.NUMERIC_SCALE AS SMALLINT) DECIMAL_DIGITS, "
+ "CAST(? AS SMALLINT) PSEUDO_COLUMN "
+ "FROM INFORMATION_SCHEMA.INDEXES I, "
+" INFORMATION_SCHEMA.COLUMNS C "
+ "WHERE C.TABLE_NAME = I.TABLE_NAME "
+ "AND C.COLUMN_NAME = I.COLUMN_NAME "
+ "AND C.TABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND C.TABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND C.TABLE_NAME = ? "
+ "AND I.PRIMARY_KEY = TRUE "
+ "ORDER BY SCOPE");
// SCOPE
prep.setInt(1, DatabaseMetaData.bestRowSession);
// PSEUDO_COLUMN
prep.setInt(2, DatabaseMetaData.bestRowNotPseudo);
prep.setString(3, getCatalogPattern(catalogPattern));
prep.setString(4, "\\");
prep.setString(5, getSchemaPattern(schemaPattern));
prep.setString(6, "\\");
prep.setString(7, tableName);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Get the list of columns that are update when any value is updated.
* The result set is always empty.
*
* <ol>
* <li>1 SCOPE (int) not used</li>
* <li>2 COLUMN_NAME (String) column name</li>
* <li>3 DATA_TYPE (int) SQL data type - see also java.sql.Types</li>
* <li>4 TYPE_NAME (String) data type name</li>
* <li>5 COLUMN_SIZE (int) precision
* (values larger than 2 GB are returned as 2 GB)</li>
* <li>6 BUFFER_LENGTH (int) length (bytes)</li>
* <li>7 DECIMAL_DIGITS (int) scale</li>
* <li>8 PSEUDO_COLUMN (int) is this column a pseudo column</li>
* </ol>
*
* @param catalog null (to get all objects) or the catalog name
* @param schema null (to get all objects) or a schema name
* @param tableName table name (must be specified)
* @return an empty result set
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getVersionColumns(String catalog, String schema,
String tableName) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getVersionColumns("
+quote(catalog)+", "
+quote(schema)+", "
+quote(tableName)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "ZERO() SCOPE, "
+ "COLUMN_NAME, "
+ "CAST(DATA_TYPE AS INT) DATA_TYPE, "
+ "TYPE_NAME, "
+ "NUMERIC_PRECISION COLUMN_SIZE, "
+ "NUMERIC_PRECISION BUFFER_LENGTH, "
+ "NUMERIC_PRECISION DECIMAL_DIGITS, "
+ "ZERO() PSEUDO_COLUMN "
+ "FROM INFORMATION_SCHEMA.COLUMNS "
+ "WHERE FALSE");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of primary key columns that are referenced by a table. The
* result set is sorted by PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME,
* FK_NAME, KEY_SEQ.
*
* <ol>
* <li>PKTABLE_CAT (String) primary catalog</li>
* <li>PKTABLE_SCHEM (String) primary schema</li>
* <li>PKTABLE_NAME (String) primary table</li>
* <li>PKCOLUMN_NAME (String) primary column</li>
* <li>FKTABLE_CAT (String) foreign catalog</li>
* <li>FKTABLE_SCHEM (String) foreign schema</li>
* <li>FKTABLE_NAME (String) foreign table</li>
* <li>FKCOLUMN_NAME (String) foreign column</li>
* <li>KEY_SEQ (short) sequence number (1, 2, ...)</li>
* <li>UPDATE_RULE (short) action on update (see
* DatabaseMetaData.importedKey...)</li>
* <li>DELETE_RULE (short) action on delete (see
* DatabaseMetaData.importedKey...)</li>
* <li>FK_NAME (String) foreign key name</li>
* <li>PK_NAME (String) primary key name</li>
* <li>DEFERRABILITY (short) deferrable or not (always
* importedKeyNotDeferrable)</li>
* </ol>
*
* @param catalogPattern null (to get all objects) or the catalog name
* @param schemaPattern the schema name of the foreign table
* @param tableName the name of the foreign table
* @return the result set
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getImportedKeys(String catalogPattern,
String schemaPattern, String tableName) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getImportedKeys("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableName)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "PKTABLE_CATALOG PKTABLE_CAT, "
+ "PKTABLE_SCHEMA PKTABLE_SCHEM, "
+ "PKTABLE_NAME PKTABLE_NAME, "
+ "PKCOLUMN_NAME, "
+ "FKTABLE_CATALOG FKTABLE_CAT, "
+ "FKTABLE_SCHEMA FKTABLE_SCHEM, "
+ "FKTABLE_NAME, "
+ "FKCOLUMN_NAME, "
+ "ORDINAL_POSITION KEY_SEQ, "
+ "UPDATE_RULE, "
+ "DELETE_RULE, "
+ "FK_NAME, "
+ "PK_NAME, "
+ "DEFERRABILITY "
+ "FROM INFORMATION_SCHEMA.CROSS_REFERENCES "
+ "WHERE FKTABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND FKTABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND FKTABLE_NAME = ? "
+ "ORDER BY PKTABLE_CAT, PKTABLE_SCHEM, PKTABLE_NAME, FK_NAME, KEY_SEQ");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, tableName);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of foreign key columns that reference a table. The result
* set is sorted by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, FK_NAME,
* KEY_SEQ.
*
* <ol>
* <li>PKTABLE_CAT (String) primary catalog</li>
* <li>PKTABLE_SCHEM (String) primary schema</li>
* <li>PKTABLE_NAME (String) primary table</li>
* <li>PKCOLUMN_NAME (String) primary column</li>
* <li>FKTABLE_CAT (String) foreign catalog</li>
* <li>FKTABLE_SCHEM (String) foreign schema</li>
* <li>FKTABLE_NAME (String) foreign table</li>
* <li>FKCOLUMN_NAME (String) foreign column</li>
* <li>KEY_SEQ (short) sequence number (1,2,...)</li>
* <li>UPDATE_RULE (short) action on update (see
* DatabaseMetaData.importedKey...)</li>
* <li>DELETE_RULE (short) action on delete (see
* DatabaseMetaData.importedKey...)</li>
* <li>FK_NAME (String) foreign key name</li>
* <li>PK_NAME (String) primary key name</li>
* <li>DEFERRABILITY (short) deferrable or not (always
* importedKeyNotDeferrable)</li>
* </ol>
*
* @param catalogPattern null or the catalog name
* @param schemaPattern the schema name of the primary table
* @param tableName the name of the primary table
* @return the result set
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getExportedKeys(String catalogPattern,
String schemaPattern, String tableName) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getExportedKeys("
+quote(catalogPattern)+", "
+quote(schemaPattern)+", "
+quote(tableName)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "PKTABLE_CATALOG PKTABLE_CAT, "
+ "PKTABLE_SCHEMA PKTABLE_SCHEM, "
+ "PKTABLE_NAME PKTABLE_NAME, "
+ "PKCOLUMN_NAME, "
+ "FKTABLE_CATALOG FKTABLE_CAT, "
+ "FKTABLE_SCHEMA FKTABLE_SCHEM, "
+ "FKTABLE_NAME, "
+ "FKCOLUMN_NAME, "
+ "ORDINAL_POSITION KEY_SEQ, "
+ "UPDATE_RULE, "
+ "DELETE_RULE, "
+ "FK_NAME, "
+ "PK_NAME, "
+ "DEFERRABILITY "
+ "FROM INFORMATION_SCHEMA.CROSS_REFERENCES "
+ "WHERE PKTABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND PKTABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND PKTABLE_NAME = ? "
+ "ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, FK_NAME, KEY_SEQ");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
prep.setString(5, tableName);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of foreign key columns that references a table, as well as
* the list of primary key columns that are references by a table. The
* result set is sorted by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME,
* FK_NAME, KEY_SEQ.
*
* <ol>
* <li>PKTABLE_CAT (String) primary catalog</li>
* <li>PKTABLE_SCHEM (String) primary schema</li>
* <li>PKTABLE_NAME (String) primary table</li>
* <li>PKCOLUMN_NAME (String) primary column</li>
* <li>FKTABLE_CAT (String) foreign catalog</li>
* <li>FKTABLE_SCHEM (String) foreign schema</li>
* <li>FKTABLE_NAME (String) foreign table</li>
* <li>FKCOLUMN_NAME (String) foreign column</li>
* <li>KEY_SEQ (short) sequence number (1,2,...)</li>
* <li>UPDATE_RULE (short) action on update (see
* DatabaseMetaData.importedKey...)</li>
* <li>DELETE_RULE (short) action on delete (see
* DatabaseMetaData.importedKey...)</li>
* <li>FK_NAME (String) foreign key name</li>
* <li>PK_NAME (String) primary key name</li>
* <li>DEFERRABILITY (short) deferrable or not (always
* importedKeyNotDeferrable)</li>
* </ol>
*
* @param primaryCatalogPattern null or the catalog name
* @param primarySchemaPattern the schema name of the primary table
* (optional)
* @param primaryTable the name of the primary table (must be specified)
* @param foreignCatalogPattern null or the catalog name
* @param foreignSchemaPattern the schema name of the foreign table
* (optional)
* @param foreignTable the name of the foreign table (must be specified)
* @return the result set
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getCrossReference(String primaryCatalogPattern,
String primarySchemaPattern, String primaryTable, String foreignCatalogPattern,
String foreignSchemaPattern, String foreignTable) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getCrossReference("
+quote(primaryCatalogPattern)+", "
+quote(primarySchemaPattern)+", "
+quote(primaryTable)+", "
+quote(foreignCatalogPattern)+", "
+quote(foreignSchemaPattern)+", "
+quote(foreignTable)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "PKTABLE_CATALOG PKTABLE_CAT, "
+ "PKTABLE_SCHEMA PKTABLE_SCHEM, "
+ "PKTABLE_NAME PKTABLE_NAME, "
+ "PKCOLUMN_NAME, "
+ "FKTABLE_CATALOG FKTABLE_CAT, "
+ "FKTABLE_SCHEMA FKTABLE_SCHEM, "
+ "FKTABLE_NAME, "
+ "FKCOLUMN_NAME, "
+ "ORDINAL_POSITION KEY_SEQ, "
+ "UPDATE_RULE, "
+ "DELETE_RULE, "
+ "FK_NAME, "
+ "PK_NAME, "
+ "DEFERRABILITY "
+ "FROM INFORMATION_SCHEMA.CROSS_REFERENCES "
+ "WHERE PKTABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND PKTABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND PKTABLE_NAME = ? "
+ "AND FKTABLE_CATALOG LIKE ? ESCAPE ? "
+ "AND FKTABLE_SCHEMA LIKE ? ESCAPE ? "
+ "AND FKTABLE_NAME = ? "
+ "ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, FK_NAME, KEY_SEQ");
prep.setString(1, getCatalogPattern(primaryCatalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(primarySchemaPattern));
prep.setString(4, "\\");
prep.setString(5, primaryTable);
prep.setString(6, getCatalogPattern(foreignCatalogPattern));
prep.setString(7, "\\");
prep.setString(8, getSchemaPattern(foreignSchemaPattern));
prep.setString(9, "\\");
prep.setString(10, foreignTable);
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of user-defined data types.
* This call returns an empty result set.
*
* <ol>
* <li>TYPE_CAT (String) catalog</li>
* <li>TYPE_SCHEM (String) schema</li>
* <li>TYPE_NAME (String) type name</li>
* <li>CLASS_NAME (String) Java class</li>
* <li>DATA_TYPE (short) SQL Type - see also java.sql.Types</li>
* <li>REMARKS (String) description</li>
* <li>BASE_TYPE (short) base type - see also java.sql.Types</li>
* </ol>
*
* @param catalog ignored
* @param schemaPattern ignored
* @param typeNamePattern ignored
* @param types ignored
* @return an empty result set
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getUDTs(String catalog, String schemaPattern,
String typeNamePattern, int[] types) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getUDTs("
+quote(catalog)+", "
+quote(schemaPattern)+", "
+quote(typeNamePattern)+", "
+quoteIntArray(types)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "CAST(NULL AS VARCHAR) TYPE_CAT, "
+ "CAST(NULL AS VARCHAR) TYPE_SCHEM, "
+ "CAST(NULL AS VARCHAR) TYPE_NAME, "
+ "CAST(NULL AS VARCHAR) CLASS_NAME, "
+ "CAST(NULL AS SMALLINT) DATA_TYPE, "
+ "CAST(NULL AS VARCHAR) REMARKS, "
+ "CAST(NULL AS SMALLINT) BASE_TYPE "
+ "FROM DUAL WHERE FALSE");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Gets the list of data types. The result set is sorted by DATA_TYPE and
* afterwards by how closely the data type maps to the corresponding JDBC
* SQL type (best match first).
*
* <ol>
* <li>TYPE_NAME (String) type name</li>
* <li>DATA_TYPE (short) SQL data type - see also java.sql.Types</li>
* <li>PRECISION (int) maximum precision</li>
* <li>LITERAL_PREFIX (String) prefix used to quote a literal</li>
* <li>LITERAL_SUFFIX (String) suffix used to quote a literal</li>
* <li>CREATE_PARAMS (String) parameters used (may be null)</li>
* <li>NULLABLE (short) typeNoNulls (NULL not allowed) or typeNullable</li>
* <li>CASE_SENSITIVE (boolean) case sensitive</li>
* <li>SEARCHABLE (short) typeSearchable</li>
* <li>UNSIGNED_ATTRIBUTE (boolean) unsigned</li>
* <li>FIXED_PREC_SCALE (boolean) fixed precision</li>
* <li>AUTO_INCREMENT (boolean) auto increment</li>
* <li>LOCAL_TYPE_NAME (String) localized version of the data type</li>
* <li>MINIMUM_SCALE (short) minimum scale</li>
* <li>MAXIMUM_SCALE (short) maximum scale</li>
* <li>SQL_DATA_TYPE (int) unused</li>
* <li>SQL_DATETIME_SUB (int) unused</li>
* <li>NUM_PREC_RADIX (int) 2 for binary, 10 for decimal</li>
* </ol>
*
* @return the list of data types
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getTypeInfo() throws SQLException {
try {
debugCodeCall("getTypeInfo");
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "TYPE_NAME, "
+ "DATA_TYPE, "
+ "PRECISION, "
+ "PREFIX LITERAL_PREFIX, "
+ "SUFFIX LITERAL_SUFFIX, "
+ "PARAMS CREATE_PARAMS, "
+ "NULLABLE, "
+ "CASE_SENSITIVE, "
+ "SEARCHABLE, "
+ "FALSE UNSIGNED_ATTRIBUTE, "
+ "FALSE FIXED_PREC_SCALE, "
+ "AUTO_INCREMENT, "
+ "TYPE_NAME LOCAL_TYPE_NAME, "
+ "MINIMUM_SCALE, "
+ "MAXIMUM_SCALE, "
+ "DATA_TYPE SQL_DATA_TYPE, "
+ "ZERO() SQL_DATETIME_SUB, "
+ "RADIX NUM_PREC_RADIX "
+ "FROM INFORMATION_SCHEMA.TYPE_INFO "
+ "ORDER BY DATA_TYPE, POS");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Checks if this database store data in local files.
*
* @return true
*/
@Override
public boolean usesLocalFiles() {
debugCodeCall("usesLocalFiles");
return true;
}
/**
* Checks if this database use one file per table.
*
* @return false
*/
@Override
public boolean usesLocalFilePerTable() {
debugCodeCall("usesLocalFilePerTable");
return false;
}
/**
* Returns the string used to quote identifiers.
*
* @return a double quote
*/
@Override
public String getIdentifierQuoteString() {
debugCodeCall("getIdentifierQuoteString");
return "\"";
}
/**
* Gets the comma-separated list of all SQL keywords that are not supported as
* table/column/index name, in addition to the SQL-2003 keywords. The list
* returned is:
* <pre>
* INTERSECTS,LIMIT,MINUS,OFFSET,ROWNUM,SYSDATE,SYSTIME,SYSTIMESTAMP,TODAY,TOP
* </pre>
* The complete list of keywords (including SQL-2003 keywords) is:
* <pre>
* ALL, CHECK, CONSTRAINT, CROSS, CURRENT_DATE, CURRENT_TIME, CURRENT_TIMESTAMP,
* DISTINCT, EXCEPT, EXISTS, FALSE, FETCH, FOR, FOREIGN, FROM, FULL, GROUP,
* HAVING, INNER, INTERSECT, INTERSECTS, IS, JOIN, LIKE, LIMIT, LOCALTIME,
* LOCALTIMESTAMP, MINUS, NATURAL, NOT, NULL, OFFSET, ON, ORDER, PRIMARY, ROWNUM,
* SELECT, SYSDATE, SYSTIME, SYSTIMESTAMP, TODAY, TOP, TRUE, UNION, UNIQUE, WHERE,
* WITH
* </pre>
*
* @return a list of additional the keywords
*/
@Override
public String getSQLKeywords() {
debugCodeCall("getSQLKeywords");
return "INTERSECTS,LIMIT,MINUS,OFFSET,ROWNUM,SYSDATE,SYSTIME,SYSTIMESTAMP,TODAY,TOP";
}
/**
* Returns the list of numeric functions supported by this database.
*
* @return the list
*/
@Override
public String getNumericFunctions() throws SQLException {
debugCodeCall("getNumericFunctions");
return getFunctions("Functions (Numeric)");
}
/**
* Returns the list of string functions supported by this database.
*
* @return the list
*/
@Override
public String getStringFunctions() throws SQLException {
debugCodeCall("getStringFunctions");
return getFunctions("Functions (String)");
}
/**
* Returns the list of system functions supported by this database.
*
* @return the list
*/
@Override
public String getSystemFunctions() throws SQLException {
debugCodeCall("getSystemFunctions");
return getFunctions("Functions (System)");
}
/**
* Returns the list of date and time functions supported by this database.
*
* @return the list
*/
@Override
public String getTimeDateFunctions() throws SQLException {
debugCodeCall("getTimeDateFunctions");
return getFunctions("Functions (Time and Date)");
}
private String getFunctions(String section) throws SQLException {
try {
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT TOPIC "
+ "FROM INFORMATION_SCHEMA.HELP WHERE SECTION = ?");
prep.setString(1, section);
ResultSet rs = prep.executeQuery();
StatementBuilder buff = new StatementBuilder();
while (rs.next()) {
String s = rs.getString(1).trim();
String[] array = StringUtils.arraySplit(s, ',', true);
for (String a : array) {
buff.appendExceptFirst(",");
String f = a.trim();
int spaceIndex = f.indexOf(' ');
if (spaceIndex >= 0) {
// remove 'Function' from 'INSERT Function'
f = StringUtils.trimSubstring(f, 0, spaceIndex);
}
buff.append(f);
}
}
rs.close();
prep.close();
return buff.toString();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Returns the default escape character for DatabaseMetaData search
* patterns.
*
* @return the default escape character (always '\', independent on the
* mode)
*/
@Override
public String getSearchStringEscape() {
debugCodeCall("getSearchStringEscape");
return "\\";
}
/**
* Returns the characters that are allowed for identifiers in addiction to
* A-Z, a-z, 0-9 and '_'.
*
* @return an empty String ("")
*/
@Override
public String getExtraNameCharacters() {
debugCodeCall("getExtraNameCharacters");
return "";
}
/**
* Returns whether alter table with add column is supported.
* @return true
*/
@Override
public boolean supportsAlterTableWithAddColumn() {
debugCodeCall("supportsAlterTableWithAddColumn");
return true;
}
/**
* Returns whether alter table with drop column is supported.
*
* @return true
*/
@Override
public boolean supportsAlterTableWithDropColumn() {
debugCodeCall("supportsAlterTableWithDropColumn");
return true;
}
/**
* Returns whether column aliasing is supported.
*
* @return true
*/
@Override
public boolean supportsColumnAliasing() {
debugCodeCall("supportsColumnAliasing");
return true;
}
/**
* Returns whether NULL+1 is NULL or not.
*
* @return true
*/
@Override
public boolean nullPlusNonNullIsNull() {
debugCodeCall("nullPlusNonNullIsNull");
return true;
}
/**
* Returns whether CONVERT is supported.
*
* @return true
*/
@Override
public boolean supportsConvert() {
debugCodeCall("supportsConvert");
return true;
}
/**
* Returns whether CONVERT is supported for one datatype to another.
*
* @param fromType the source SQL type
* @param toType the target SQL type
* @return true
*/
@Override
public boolean supportsConvert(int fromType, int toType) {
if (isDebugEnabled()) {
debugCode("supportsConvert("+fromType+", "+fromType+");");
}
return true;
}
/**
* Returns whether table correlation names (table alias) are supported.
*
* @return true
*/
@Override
public boolean supportsTableCorrelationNames() {
debugCodeCall("supportsTableCorrelationNames");
return true;
}
/**
* Returns whether table correlation names (table alias) are restricted to
* be different than table names.
*
* @return false
*/
@Override
public boolean supportsDifferentTableCorrelationNames() {
debugCodeCall("supportsDifferentTableCorrelationNames");
return false;
}
/**
* Returns whether expression in ORDER BY are supported.
*
* @return true
*/
@Override
public boolean supportsExpressionsInOrderBy() {
debugCodeCall("supportsExpressionsInOrderBy");
return true;
}
/**
* Returns whether ORDER BY is supported if the column is not in the SELECT
* list.
*
* @return true
*/
@Override
public boolean supportsOrderByUnrelated() {
debugCodeCall("supportsOrderByUnrelated");
return true;
}
/**
* Returns whether GROUP BY is supported.
*
* @return true
*/
@Override
public boolean supportsGroupBy() {
debugCodeCall("supportsGroupBy");
return true;
}
/**
* Returns whether GROUP BY is supported if the column is not in the SELECT
* list.
*
* @return true
*/
@Override
public boolean supportsGroupByUnrelated() {
debugCodeCall("supportsGroupByUnrelated");
return true;
}
/**
* Checks whether a GROUP BY clause can use columns that are not in the
* SELECT clause, provided that it specifies all the columns in the SELECT
* clause.
*
* @return true
*/
@Override
public boolean supportsGroupByBeyondSelect() {
debugCodeCall("supportsGroupByBeyondSelect");
return true;
}
/**
* Returns whether LIKE... ESCAPE is supported.
*
* @return true
*/
@Override
public boolean supportsLikeEscapeClause() {
debugCodeCall("supportsLikeEscapeClause");
return true;
}
/**
* Returns whether multiple result sets are supported.
*
* @return false
*/
@Override
public boolean supportsMultipleResultSets() {
debugCodeCall("supportsMultipleResultSets");
return false;
}
/**
* Returns whether multiple transactions (on different connections) are
* supported.
*
* @return true
*/
@Override
public boolean supportsMultipleTransactions() {
debugCodeCall("supportsMultipleTransactions");
return true;
}
/**
* Returns whether columns with NOT NULL are supported.
*
* @return true
*/
@Override
public boolean supportsNonNullableColumns() {
debugCodeCall("supportsNonNullableColumns");
return true;
}
/**
* Returns whether ODBC Minimum SQL grammar is supported.
*
* @return true
*/
@Override
public boolean supportsMinimumSQLGrammar() {
debugCodeCall("supportsMinimumSQLGrammar");
return true;
}
/**
* Returns whether ODBC Core SQL grammar is supported.
*
* @return true
*/
@Override
public boolean supportsCoreSQLGrammar() {
debugCodeCall("supportsCoreSQLGrammar");
return true;
}
/**
* Returns whether ODBC Extended SQL grammar is supported.
*
* @return false
*/
@Override
public boolean supportsExtendedSQLGrammar() {
debugCodeCall("supportsExtendedSQLGrammar");
return false;
}
/**
* Returns whether SQL-92 entry level grammar is supported.
*
* @return true
*/
@Override
public boolean supportsANSI92EntryLevelSQL() {
debugCodeCall("supportsANSI92EntryLevelSQL");
return true;
}
/**
* Returns whether SQL-92 intermediate level grammar is supported.
*
* @return false
*/
@Override
public boolean supportsANSI92IntermediateSQL() {
debugCodeCall("supportsANSI92IntermediateSQL");
return false;
}
/**
* Returns whether SQL-92 full level grammar is supported.
*
* @return false
*/
@Override
public boolean supportsANSI92FullSQL() {
debugCodeCall("supportsANSI92FullSQL");
return false;
}
/**
* Returns whether referential integrity is supported.
*
* @return true
*/
@Override
public boolean supportsIntegrityEnhancementFacility() {
debugCodeCall("supportsIntegrityEnhancementFacility");
return true;
}
/**
* Returns whether outer joins are supported.
*
* @return true
*/
@Override
public boolean supportsOuterJoins() {
debugCodeCall("supportsOuterJoins");
return true;
}
/**
* Returns whether full outer joins are supported.
*
* @return false
*/
@Override
public boolean supportsFullOuterJoins() {
debugCodeCall("supportsFullOuterJoins");
return false;
}
/**
* Returns whether limited outer joins are supported.
*
* @return true
*/
@Override
public boolean supportsLimitedOuterJoins() {
debugCodeCall("supportsLimitedOuterJoins");
return true;
}
/**
* Returns the term for "schema".
*
* @return "schema"
*/
@Override
public String getSchemaTerm() {
debugCodeCall("getSchemaTerm");
return "schema";
}
/**
* Returns the term for "procedure".
*
* @return "procedure"
*/
@Override
public String getProcedureTerm() {
debugCodeCall("getProcedureTerm");
return "procedure";
}
/**
* Returns the term for "catalog".
*
* @return "catalog"
*/
@Override
public String getCatalogTerm() {
debugCodeCall("getCatalogTerm");
return "catalog";
}
/**
* Returns whether the catalog is at the beginning.
*
* @return true
*/
@Override
public boolean isCatalogAtStart() {
debugCodeCall("isCatalogAtStart");
return true;
}
/**
* Returns the catalog separator.
*
* @return "."
*/
@Override
public String getCatalogSeparator() {
debugCodeCall("getCatalogSeparator");
return ".";
}
/**
* Returns whether the schema name in INSERT, UPDATE, DELETE is supported.
*
* @return true
*/
@Override
public boolean supportsSchemasInDataManipulation() {
debugCodeCall("supportsSchemasInDataManipulation");
return true;
}
/**
* Returns whether the schema name in procedure calls is supported.
*
* @return true
*/
@Override
public boolean supportsSchemasInProcedureCalls() {
debugCodeCall("supportsSchemasInProcedureCalls");
return true;
}
/**
* Returns whether the schema name in CREATE TABLE is supported.
*
* @return true
*/
@Override
public boolean supportsSchemasInTableDefinitions() {
debugCodeCall("supportsSchemasInTableDefinitions");
return true;
}
/**
* Returns whether the schema name in CREATE INDEX is supported.
*
* @return true
*/
@Override
public boolean supportsSchemasInIndexDefinitions() {
debugCodeCall("supportsSchemasInIndexDefinitions");
return true;
}
/**
* Returns whether the schema name in GRANT is supported.
*
* @return true
*/
@Override
public boolean supportsSchemasInPrivilegeDefinitions() {
debugCodeCall("supportsSchemasInPrivilegeDefinitions");
return true;
}
/**
* Returns whether the catalog name in INSERT, UPDATE, DELETE is supported.
*
* @return true
*/
@Override
public boolean supportsCatalogsInDataManipulation() {
debugCodeCall("supportsCatalogsInDataManipulation");
return true;
}
/**
* Returns whether the catalog name in procedure calls is supported.
*
* @return false
*/
@Override
public boolean supportsCatalogsInProcedureCalls() {
debugCodeCall("supportsCatalogsInProcedureCalls");
return false;
}
/**
* Returns whether the catalog name in CREATE TABLE is supported.
*
* @return true
*/
@Override
public boolean supportsCatalogsInTableDefinitions() {
debugCodeCall("supportsCatalogsInTableDefinitions");
return true;
}
/**
* Returns whether the catalog name in CREATE INDEX is supported.
*
* @return true
*/
@Override
public boolean supportsCatalogsInIndexDefinitions() {
debugCodeCall("supportsCatalogsInIndexDefinitions");
return true;
}
/**
* Returns whether the catalog name in GRANT is supported.
*
* @return true
*/
@Override
public boolean supportsCatalogsInPrivilegeDefinitions() {
debugCodeCall("supportsCatalogsInPrivilegeDefinitions");
return true;
}
/**
* Returns whether positioned deletes are supported.
*
* @return true
*/
@Override
public boolean supportsPositionedDelete() {
debugCodeCall("supportsPositionedDelete");
return true;
}
/**
* Returns whether positioned updates are supported.
*
* @return true
*/
@Override
public boolean supportsPositionedUpdate() {
debugCodeCall("supportsPositionedUpdate");
return true;
}
/**
* Returns whether SELECT ... FOR UPDATE is supported.
*
* @return true
*/
@Override
public boolean supportsSelectForUpdate() {
debugCodeCall("supportsSelectForUpdate");
return true;
}
/**
* Returns whether stored procedures are supported.
*
* @return false
*/
@Override
public boolean supportsStoredProcedures() {
debugCodeCall("supportsStoredProcedures");
return false;
}
/**
* Returns whether subqueries (SELECT) in comparisons are supported.
*
* @return true
*/
@Override
public boolean supportsSubqueriesInComparisons() {
debugCodeCall("supportsSubqueriesInComparisons");
return true;
}
/**
* Returns whether SELECT in EXISTS is supported.
*
* @return true
*/
@Override
public boolean supportsSubqueriesInExists() {
debugCodeCall("supportsSubqueriesInExists");
return true;
}
/**
* Returns whether IN(SELECT...) is supported.
*
* @return true
*/
@Override
public boolean supportsSubqueriesInIns() {
debugCodeCall("supportsSubqueriesInIns");
return true;
}
/**
* Returns whether subqueries in quantified expression are supported.
*
* @return true
*/
@Override
public boolean supportsSubqueriesInQuantifieds() {
debugCodeCall("supportsSubqueriesInQuantifieds");
return true;
}
/**
* Returns whether correlated subqueries are supported.
*
* @return true
*/
@Override
public boolean supportsCorrelatedSubqueries() {
debugCodeCall("supportsCorrelatedSubqueries");
return true;
}
/**
* Returns whether UNION SELECT is supported.
*
* @return true
*/
@Override
public boolean supportsUnion() {
debugCodeCall("supportsUnion");
return true;
}
/**
* Returns whether UNION ALL SELECT is supported.
*
* @return true
*/
@Override
public boolean supportsUnionAll() {
debugCodeCall("supportsUnionAll");
return true;
}
/**
* Returns whether open result sets across commits are supported.
*
* @return false
*/
@Override
public boolean supportsOpenCursorsAcrossCommit() {
debugCodeCall("supportsOpenCursorsAcrossCommit");
return false;
}
/**
* Returns whether open result sets across rollback are supported.
*
* @return false
*/
@Override
public boolean supportsOpenCursorsAcrossRollback() {
debugCodeCall("supportsOpenCursorsAcrossRollback");
return false;
}
/**
* Returns whether open statements across commit are supported.
*
* @return true
*/
@Override
public boolean supportsOpenStatementsAcrossCommit() {
debugCodeCall("supportsOpenStatementsAcrossCommit");
return true;
}
/**
* Returns whether open statements across rollback are supported.
*
* @return true
*/
@Override
public boolean supportsOpenStatementsAcrossRollback() {
debugCodeCall("supportsOpenStatementsAcrossRollback");
return true;
}
/**
* Returns whether transactions are supported.
*
* @return true
*/
@Override
public boolean supportsTransactions() {
debugCodeCall("supportsTransactions");
return true;
}
/**
* Returns whether a specific transaction isolation level is supported.
*
* @param level the transaction isolation level (Connection.TRANSACTION_*)
* @return true
*/
@Override
public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
debugCodeCall("supportsTransactionIsolationLevel");
switch (level) {
case Connection.TRANSACTION_READ_UNCOMMITTED: {
// Currently the combination of MV_STORE=FALSE, LOCK_MODE=0 and
// MULTI_THREADED=TRUE is not supported. Also see code in
// Database#setLockMode(int)
try (PreparedStatement prep = conn.prepareStatement(
"SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=?")) {
// TODO skip MV_STORE check for H2 <= 1.4.197
prep.setString(1, "MV_STORE");
ResultSet rs = prep.executeQuery();
if (rs.next() && Boolean.parseBoolean(rs.getString(1))) {
return true;
}
prep.setString(1, "MULTI_THREADED");
rs = prep.executeQuery();
return !rs.next() || !rs.getString(1).equals("1");
}
}
case Connection.TRANSACTION_READ_COMMITTED:
case Connection.TRANSACTION_REPEATABLE_READ:
case Connection.TRANSACTION_SERIALIZABLE:
return true;
default:
return false;
}
}
/**
* Returns whether data manipulation and CREATE/DROP is supported in
* transactions.
*
* @return false
*/
@Override
public boolean supportsDataDefinitionAndDataManipulationTransactions() {
debugCodeCall("supportsDataDefinitionAndDataManipulationTransactions");
return false;
}
/**
* Returns whether only data manipulations are supported in transactions.
*
* @return true
*/
@Override
public boolean supportsDataManipulationTransactionsOnly() {
debugCodeCall("supportsDataManipulationTransactionsOnly");
return true;
}
/**
* Returns whether CREATE/DROP commit an open transaction.
*
* @return true
*/
@Override
public boolean dataDefinitionCausesTransactionCommit() {
debugCodeCall("dataDefinitionCausesTransactionCommit");
return true;
}
/**
* Returns whether CREATE/DROP do not affect transactions.
*
* @return false
*/
@Override
public boolean dataDefinitionIgnoredInTransactions() {
debugCodeCall("dataDefinitionIgnoredInTransactions");
return false;
}
/**
* Returns whether a specific result set type is supported.
* ResultSet.TYPE_SCROLL_SENSITIVE is not supported.
*
* @param type the result set type
* @return true for all types except ResultSet.TYPE_FORWARD_ONLY
*/
@Override
public boolean supportsResultSetType(int type) {
debugCodeCall("supportsResultSetType", type);
return type != ResultSet.TYPE_SCROLL_SENSITIVE;
}
/**
* Returns whether a specific result set concurrency is supported.
* ResultSet.TYPE_SCROLL_SENSITIVE is not supported.
*
* @param type the result set type
* @param concurrency the result set concurrency
* @return true if the type is not ResultSet.TYPE_SCROLL_SENSITIVE
*/
@Override
public boolean supportsResultSetConcurrency(int type, int concurrency) {
if (isDebugEnabled()) {
debugCode("supportsResultSetConcurrency("+type+", "+concurrency+");");
}
return type != ResultSet.TYPE_SCROLL_SENSITIVE;
}
/**
* Returns whether own updates are visible.
*
* @param type the result set type
* @return true
*/
@Override
public boolean ownUpdatesAreVisible(int type) {
debugCodeCall("ownUpdatesAreVisible", type);
return true;
}
/**
* Returns whether own deletes are visible.
*
* @param type the result set type
* @return false
*/
@Override
public boolean ownDeletesAreVisible(int type) {
debugCodeCall("ownDeletesAreVisible", type);
return false;
}
/**
* Returns whether own inserts are visible.
*
* @param type the result set type
* @return false
*/
@Override
public boolean ownInsertsAreVisible(int type) {
debugCodeCall("ownInsertsAreVisible", type);
return false;
}
/**
* Returns whether other updates are visible.
*
* @param type the result set type
* @return false
*/
@Override
public boolean othersUpdatesAreVisible(int type) {
debugCodeCall("othersUpdatesAreVisible", type);
return false;
}
/**
* Returns whether other deletes are visible.
*
* @param type the result set type
* @return false
*/
@Override
public boolean othersDeletesAreVisible(int type) {
debugCodeCall("othersDeletesAreVisible", type);
return false;
}
/**
* Returns whether other inserts are visible.
*
* @param type the result set type
* @return false
*/
@Override
public boolean othersInsertsAreVisible(int type) {
debugCodeCall("othersInsertsAreVisible", type);
return false;
}
/**
* Returns whether updates are detected.
*
* @param type the result set type
* @return false
*/
@Override
public boolean updatesAreDetected(int type) {
debugCodeCall("updatesAreDetected", type);
return false;
}
/**
* Returns whether deletes are detected.
*
* @param type the result set type
* @return false
*/
@Override
public boolean deletesAreDetected(int type) {
debugCodeCall("deletesAreDetected", type);
return false;
}
/**
* Returns whether inserts are detected.
*
* @param type the result set type
* @return false
*/
@Override
public boolean insertsAreDetected(int type) {
debugCodeCall("insertsAreDetected", type);
return false;
}
/**
* Returns whether batch updates are supported.
*
* @return true
*/
@Override
public boolean supportsBatchUpdates() {
debugCodeCall("supportsBatchUpdates");
return true;
}
/**
* Returns whether the maximum row size includes blobs.
*
* @return false
*/
@Override
public boolean doesMaxRowSizeIncludeBlobs() {
debugCodeCall("doesMaxRowSizeIncludeBlobs");
return false;
}
/**
* Returns the default transaction isolation level.
*
* @return Connection.TRANSACTION_READ_COMMITTED
*/
@Override
public int getDefaultTransactionIsolation() {
debugCodeCall("getDefaultTransactionIsolation");
return Connection.TRANSACTION_READ_COMMITTED;
}
/**
* Checks if for CREATE TABLE Test(ID INT), getTables returns Test as the
* table name.
*
* @return false
*/
@Override
public boolean supportsMixedCaseIdentifiers() {
debugCodeCall("supportsMixedCaseIdentifiers");
return false;
}
/**
* Checks if a table created with CREATE TABLE "Test"(ID INT) is a different
* table than a table created with CREATE TABLE TEST(ID INT).
*
* @return true usually, and false in MySQL mode
*/
@Override
public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
debugCodeCall("supportsMixedCaseQuotedIdentifiers");
return conn.getMode().getEnum() != ModeEnum.MySQL;
}
/**
* Checks if for CREATE TABLE Test(ID INT), getTables returns TEST as the
* table name.
*
* @return true usually, and false in MySQL mode
*/
@Override
public boolean storesUpperCaseIdentifiers() throws SQLException {
debugCodeCall("storesUpperCaseIdentifiers");
return conn.getMode().getEnum() != ModeEnum.MySQL;
}
/**
* Checks if for CREATE TABLE Test(ID INT), getTables returns test as the
* table name.
*
* @return false usually, and true in MySQL mode
*/
@Override
public boolean storesLowerCaseIdentifiers() throws SQLException {
debugCodeCall("storesLowerCaseIdentifiers");
return conn.getMode().getEnum() == ModeEnum.MySQL;
}
/**
* Checks if for CREATE TABLE Test(ID INT), getTables returns Test as the
* table name.
*
* @return false
*/
@Override
public boolean storesMixedCaseIdentifiers() {
debugCodeCall("storesMixedCaseIdentifiers");
return false;
}
/**
* Checks if for CREATE TABLE "Test"(ID INT), getTables returns TEST as the
* table name.
*
* @return false usually, and true in MySQL mode
*/
@Override
public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
debugCodeCall("storesUpperCaseQuotedIdentifiers");
return conn.getMode().getEnum() == ModeEnum.MySQL;
}
/**
* Checks if for CREATE TABLE "Test"(ID INT), getTables returns test as the
* table name.
*
* @return false usually, and true in MySQL mode
*/
@Override
public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
debugCodeCall("storesLowerCaseQuotedIdentifiers");
return conn.getMode().getEnum() == ModeEnum.MySQL;
}
/**
* Checks if for CREATE TABLE "Test"(ID INT), getTables returns Test as the
* table name.
*
* @return true usually, and false in MySQL mode
*/
@Override
public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
debugCodeCall("storesMixedCaseQuotedIdentifiers");
return conn.getMode().getEnum() != ModeEnum.MySQL;
}
/**
* Returns the maximum length for hex values (characters).
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxBinaryLiteralLength() {
debugCodeCall("getMaxBinaryLiteralLength");
return 0;
}
/**
* Returns the maximum length for literals.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxCharLiteralLength() {
debugCodeCall("getMaxCharLiteralLength");
return 0;
}
/**
* Returns the maximum length for column names.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxColumnNameLength() {
debugCodeCall("getMaxColumnNameLength");
return 0;
}
/**
* Returns the maximum number of columns in GROUP BY.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxColumnsInGroupBy() {
debugCodeCall("getMaxColumnsInGroupBy");
return 0;
}
/**
* Returns the maximum number of columns in CREATE INDEX.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxColumnsInIndex() {
debugCodeCall("getMaxColumnsInIndex");
return 0;
}
/**
* Returns the maximum number of columns in ORDER BY.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxColumnsInOrderBy() {
debugCodeCall("getMaxColumnsInOrderBy");
return 0;
}
/**
* Returns the maximum number of columns in SELECT.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxColumnsInSelect() {
debugCodeCall("getMaxColumnsInSelect");
return 0;
}
/**
* Returns the maximum number of columns in CREATE TABLE.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxColumnsInTable() {
debugCodeCall("getMaxColumnsInTable");
return 0;
}
/**
* Returns the maximum number of open connection.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxConnections() {
debugCodeCall("getMaxConnections");
return 0;
}
/**
* Returns the maximum length for a cursor name.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxCursorNameLength() {
debugCodeCall("getMaxCursorNameLength");
return 0;
}
/**
* Returns the maximum length for an index (in bytes).
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxIndexLength() {
debugCodeCall("getMaxIndexLength");
return 0;
}
/**
* Returns the maximum length for a schema name.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxSchemaNameLength() {
debugCodeCall("getMaxSchemaNameLength");
return 0;
}
/**
* Returns the maximum length for a procedure name.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxProcedureNameLength() {
debugCodeCall("getMaxProcedureNameLength");
return 0;
}
/**
* Returns the maximum length for a catalog name.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxCatalogNameLength() {
debugCodeCall("getMaxCatalogNameLength");
return 0;
}
/**
* Returns the maximum size of a row (in bytes).
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxRowSize() {
debugCodeCall("getMaxRowSize");
return 0;
}
/**
* Returns the maximum length of a statement.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxStatementLength() {
debugCodeCall("getMaxStatementLength");
return 0;
}
/**
* Returns the maximum number of open statements.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxStatements() {
debugCodeCall("getMaxStatements");
return 0;
}
/**
* Returns the maximum length for a table name.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxTableNameLength() {
debugCodeCall("getMaxTableNameLength");
return 0;
}
/**
* Returns the maximum number of tables in a SELECT.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxTablesInSelect() {
debugCodeCall("getMaxTablesInSelect");
return 0;
}
/**
* Returns the maximum length for a user name.
*
* @return 0 for limit is unknown
*/
@Override
public int getMaxUserNameLength() {
debugCodeCall("getMaxUserNameLength");
return 0;
}
/**
* Does the database support savepoints.
*
* @return true
*/
@Override
public boolean supportsSavepoints() {
debugCodeCall("supportsSavepoints");
return true;
}
/**
* Does the database support named parameters.
*
* @return false
*/
@Override
public boolean supportsNamedParameters() {
debugCodeCall("supportsNamedParameters");
return false;
}
/**
* Does the database support multiple open result sets.
*
* @return true
*/
@Override
public boolean supportsMultipleOpenResults() {
debugCodeCall("supportsMultipleOpenResults");
return true;
}
/**
* Does the database support getGeneratedKeys.
*
* @return true
*/
@Override
public boolean supportsGetGeneratedKeys() {
debugCodeCall("supportsGetGeneratedKeys");
return true;
}
/**
* [Not supported]
*/
@Override
public ResultSet getSuperTypes(String catalog, String schemaPattern,
String typeNamePattern) throws SQLException {
throw unsupported("superTypes");
}
/**
* Get the list of super tables of a table. This method currently returns an
* empty result set.
* <ol>
* <li>TABLE_CAT (String) table catalog</li>
* <li>TABLE_SCHEM (String) table schema</li>
* <li>TABLE_NAME (String) table name</li>
* <li>SUPERTABLE_NAME (String) the name of the super table</li>
* </ol>
*
* @param catalog null (to get all objects) or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @param tableNamePattern null (to get all objects) or a table name pattern
* (uppercase for unquoted names)
* @return an empty result set
*/
@Override
public ResultSet getSuperTables(String catalog, String schemaPattern,
String tableNamePattern) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getSuperTables("
+quote(catalog)+", "
+quote(schemaPattern)+", "
+quote(tableNamePattern)+");");
}
checkClosed();
PreparedStatement prep = conn.prepareAutoCloseStatement("SELECT "
+ "CATALOG_NAME TABLE_CAT, "
+ "CATALOG_NAME TABLE_SCHEM, "
+ "CATALOG_NAME TABLE_NAME, "
+ "CATALOG_NAME SUPERTABLE_NAME "
+ "FROM INFORMATION_SCHEMA.CATALOGS "
+ "WHERE FALSE");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* [Not supported]
*/
@Override
public ResultSet getAttributes(String catalog, String schemaPattern,
String typeNamePattern, String attributeNamePattern)
throws SQLException {
throw unsupported("attributes");
}
/**
* Does this database supports a result set holdability.
*
* @param holdability ResultSet.HOLD_CURSORS_OVER_COMMIT or
* CLOSE_CURSORS_AT_COMMIT
* @return true if the holdability is ResultSet.CLOSE_CURSORS_AT_COMMIT
*/
@Override
public boolean supportsResultSetHoldability(int holdability) {
debugCodeCall("supportsResultSetHoldability", holdability);
return holdability == ResultSet.CLOSE_CURSORS_AT_COMMIT;
}
/**
* Gets the result set holdability.
*
* @return ResultSet.CLOSE_CURSORS_AT_COMMIT
*/
@Override
public int getResultSetHoldability() {
debugCodeCall("getResultSetHoldability");
return ResultSet.CLOSE_CURSORS_AT_COMMIT;
}
/**
* Gets the major version of the database.
*
* @return the major version
*/
@Override
public int getDatabaseMajorVersion() {
debugCodeCall("getDatabaseMajorVersion");
return Constants.VERSION_MAJOR;
}
/**
* Gets the minor version of the database.
*
* @return the minor version
*/
@Override
public int getDatabaseMinorVersion() {
debugCodeCall("getDatabaseMinorVersion");
return Constants.VERSION_MINOR;
}
/**
* Gets the major version of the supported JDBC API.
*
* @return the major version (4)
*/
@Override
public int getJDBCMajorVersion() {
debugCodeCall("getJDBCMajorVersion");
return 4;
}
/**
* Gets the minor version of the supported JDBC API.
*
* @return the minor version (1)
*/
@Override
public int getJDBCMinorVersion() {
debugCodeCall("getJDBCMinorVersion");
return 1;
}
/**
* Gets the SQL State type.
*
* @return DatabaseMetaData.sqlStateSQL99
*/
@Override
public int getSQLStateType() {
debugCodeCall("getSQLStateType");
return DatabaseMetaData.sqlStateSQL99;
}
/**
* Does the database make a copy before updating.
*
* @return false
*/
@Override
public boolean locatorsUpdateCopy() {
debugCodeCall("locatorsUpdateCopy");
return false;
}
/**
* Does the database support statement pooling.
*
* @return false
*/
@Override
public boolean supportsStatementPooling() {
debugCodeCall("supportsStatementPooling");
return false;
}
// =============================================================
private void checkClosed() {
conn.checkClosed();
}
private static String getPattern(String pattern) {
return pattern == null ? "%" : pattern;
}
private static String getSchemaPattern(String pattern) {
return pattern == null ? "%" : pattern.length() == 0 ?
Constants.SCHEMA_MAIN : pattern;
}
private static String getCatalogPattern(String catalogPattern) {
// Workaround for OpenOffice: getColumns is called with "" as the
// catalog
return catalogPattern == null || catalogPattern.length() == 0 ?
"%" : catalogPattern;
}
/**
* Get the lifetime of a rowid.
*
* @return ROWID_UNSUPPORTED
*/
@Override
public RowIdLifetime getRowIdLifetime() {
debugCodeCall("getRowIdLifetime");
return RowIdLifetime.ROWID_UNSUPPORTED;
}
/**
* Gets the list of schemas in the database.
* The result set is sorted by TABLE_SCHEM.
*
* <ol>
* <li>TABLE_SCHEM (String) schema name</li>
* <li>TABLE_CATALOG (String) catalog name</li>
* <li>IS_DEFAULT (boolean) if this is the default schema</li>
* </ol>
*
* @param catalogPattern null (to get all objects) or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @return the schema list
* @throws SQLException if the connection is closed
*/
@Override
public ResultSet getSchemas(String catalogPattern, String schemaPattern)
throws SQLException {
try {
debugCodeCall("getSchemas(String,String)");
checkClosed();
PreparedStatement prep = conn
.prepareAutoCloseStatement("SELECT "
+ "SCHEMA_NAME TABLE_SCHEM, "
+ "CATALOG_NAME TABLE_CATALOG, "
+" IS_DEFAULT "
+ "FROM INFORMATION_SCHEMA.SCHEMATA "
+ "WHERE CATALOG_NAME LIKE ? ESCAPE ? "
+ "AND SCHEMA_NAME LIKE ? ESCAPE ? "
+ "ORDER BY SCHEMA_NAME");
prep.setString(1, getCatalogPattern(catalogPattern));
prep.setString(2, "\\");
prep.setString(3, getSchemaPattern(schemaPattern));
prep.setString(4, "\\");
return prep.executeQuery();
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Returns whether the database supports calling functions using the call
* syntax.
*
* @return true
*/
@Override
public boolean supportsStoredFunctionsUsingCallSyntax() {
debugCodeCall("supportsStoredFunctionsUsingCallSyntax");
return true;
}
/**
* Returns whether an exception while auto commit is on closes all result
* sets.
*
* @return false
*/
@Override
public boolean autoCommitFailureClosesAllResultSets() {
debugCodeCall("autoCommitFailureClosesAllResultSets");
return false;
}
@Override
public ResultSet getClientInfoProperties() throws SQLException {
Properties clientInfo = conn.getClientInfo();
SimpleResultSet result = new SimpleResultSet();
result.addColumn("Name", Types.VARCHAR, 0, 0);
result.addColumn("Value", Types.VARCHAR, 0, 0);
for (Object key : clientInfo.keySet()) {
result.addRow(key, clientInfo.get(key));
}
return result;
}
/**
* Return an object of this class if possible.
*
* @param iface the class
* @return this
*/
@Override
@SuppressWarnings("unchecked")
public <T> T unwrap(Class<T> iface) throws SQLException {
try {
if (isWrapperFor(iface)) {
return (T) this;
}
throw DbException.getInvalidValueException("iface", iface);
} catch (Exception e) {
throw logAndConvert(e);
}
}
/**
* Checks if unwrap can return an object of this class.
*
* @param iface the class
* @return whether or not the interface is assignable from this class
*/
@Override
public boolean isWrapperFor(Class<?> iface) throws SQLException {
return iface != null && iface.isAssignableFrom(getClass());
}
/**
* [Not supported] Gets the list of function columns.
*/
@Override
public ResultSet getFunctionColumns(String catalog, String schemaPattern,
String functionNamePattern, String columnNamePattern)
throws SQLException {
throw unsupported("getFunctionColumns");
}
/**
* [Not supported] Gets the list of functions.
*/
@Override
public ResultSet getFunctions(String catalog, String schemaPattern,
String functionNamePattern) throws SQLException {
throw unsupported("getFunctions");
}
/**
* [Not supported]
*/
@Override
public boolean generatedKeyAlwaysReturned() {
return true;
}
/**
* [Not supported]
*
* @param catalog null (to get all objects) or the catalog name
* @param schemaPattern null (to get all objects) or a schema name
* (uppercase for unquoted names)
* @param tableNamePattern null (to get all objects) or a table name
* (uppercase for unquoted names)
* @param columnNamePattern null (to get all objects) or a column name
* (uppercase for unquoted names)
*/
@Override
public ResultSet getPseudoColumns(String catalog, String schemaPattern,
String tableNamePattern, String columnNamePattern) {
return null;
}
/**
* INTERNAL
*/
@Override
public String toString() {
return getTraceObjectName() + ": " + conn;
}
}