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
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
|
%{
//--------------------------------------------------------------------------
//
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
//
// Copyright 2008 by Sun Microsystems, Inc.
//
// OpenOffice.org - a multi-platform office productivity suite
//
// $RCSfile: sqlbison.y,v $
//
// $Revision: 1.66.6.5 $
//
// This file is part of OpenOffice.org.
//
// OpenOffice.org is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License version 3
// only, as published by the Free Software Foundation.
//
// OpenOffice.org is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License version 3 for more details
// (a copy is included in the LICENSE file that accompanied this code).
//
// You should have received a copy of the GNU Lesser General Public License
// version 3 along with OpenOffice.org. If not, see
// <http://www.openoffice.org/license.html>
// for a copy of the LGPLv3 License.
//
//--------------------------------------------------------------------------
#include <vector>
#include <string.h>
#ifndef _CONNECTIVITY_SQLNODE_HXX
#include <connectivity/sqlnode.hxx>
#endif
#ifndef _CONNECTIVITY_SQLPARSE_HXX
#include <connectivity/sqlparse.hxx>
#endif
#ifndef _CONNECTIVITY_SQLINTERNALNODE_HXX
#include <internalnode.hxx>
#endif
#ifndef _COM_SUN_STAR_LANG_LOCALE_HPP_
#include <com/sun/star/lang/Locale.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
#include <com/sun/star/sdbc/DataType.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_DATE_HPP_
#include <com/sun/star/util/Date.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_
#include <com/sun/star/util/DateTime.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_TIME_HPP_
#include <com/sun/star/util/Time.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTER_HPP_
#include <com/sun/star/util/XNumberFormatter.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATSSUPPLIER_HPP_
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATS_HPP_
#include <com/sun/star/util/XNumberFormats.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_NUMBERFORMAT_HPP_
#include <com/sun/star/util/NumberFormat.hpp>
#endif
#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTYPES_HPP_
#include <com/sun/star/util/XNumberFormatTypes.hpp>
#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COM_SUN_STAR_I18N_KPARSETYPE_HPP_
#include <com/sun/star/i18n/KParseType.hpp>
#endif
#ifndef _COM_SUN_STAR_I18N_KPARSETOKENS_HPP_
#include <com/sun/star/i18n/KParseTokens.hpp>
#endif
#ifndef _CONNECTIVITY_SQLSCAN_HXX
#include "sqlscan.hxx"
#endif
#ifndef _OSL_DIAGNOSE_H_
#include <osl/diagnose.h>
#endif
#ifndef _DBHELPER_DBCONVERSION_HXX_
#include "connectivity/dbconversion.hxx"
#endif
#include <rtl/ustrbuf.hxx>
#if defined __GNUC__
#pragma GCC system_header
#elif defined __SUNPRO_CC
#pragma disable_warn
#elif defined _MSC_VER
#pragma warning(push, 1)
#pragma warning(disable:4273 4701 4706)
#endif
static ::rtl::OUString aEmptyString;
static connectivity::OSQLInternalNode* newNode(const sal_Char* pNewValue,
const connectivity::SQLNodeType eNodeType,
const sal_uInt32 nNodeID = 0)
{
OSL_TRACE("connectivity: Rule Number: %d,%d",eNodeType,nNodeID);
return new connectivity::OSQLInternalNode(pNewValue, eNodeType, nNodeID);
}
static connectivity::OSQLInternalNode* newNode(const ::rtl::OString& _NewValue,
const connectivity::SQLNodeType eNodeType,
const sal_uInt32 nNodeID = 0)
{
OSL_TRACE("connectivity: Rule Number: %d,%d",eNodeType,nNodeID);
return new connectivity::OSQLInternalNode(_NewValue, eNodeType, nNodeID);
}
static connectivity::OSQLInternalNode* newNode(const ::rtl::OUString& _NewValue,
const connectivity::SQLNodeType eNodeType,
const sal_uInt32 nNodeID = 0)
{
OSL_TRACE("connectivity: Rule Number: %d,%d",eNodeType,nNodeID);
return new connectivity::OSQLInternalNode(_NewValue, eNodeType, nNodeID);
}
// yyi ist die interne Nr. der Regel, die gerade reduziert wird.
// Ueber die Mapping-Tabelle yyrmap wird daraus eine externe Regel-Nr.
#define SQL_NEW_RULE newNode(aEmptyString, SQL_NODE_RULE, yyr1[yyn])
#define SQL_NEW_LISTRULE newNode(aEmptyString, SQL_NODE_LISTRULE, yyr1[yyn])
#define SQL_NEW_COMMALISTRULE newNode(aEmptyString, SQL_NODE_COMMALISTRULE, yyr1[yyn])
connectivity::OSQLParser* xxx_pGLOBAL_SQLPARSER;
#define YYERROR_VERBOSE
#define SQLyyerror(s) \
{ \
xxx_pGLOBAL_SQLPARSER->error(s); \
}
using namespace connectivity;
#define SQLyylex xxx_pGLOBAL_SQLPARSER->SQLlex
%}
/* symbolic tokens */
%union {
connectivity::OSQLParseNode * pParseNode;
}
%type <pParseNode> '(' ')' ',' ':' ';' '?' '[' ']' '{' '}' '.'
%token <pParseNode> SQL_TOKEN_STRING SQL_TOKEN_ACCESS_DATE SQL_TOKEN_INT SQL_TOKEN_REAL_NUM
%token <pParseNode> SQL_TOKEN_INTNUM SQL_TOKEN_APPROXNUM SQL_TOKEN_NOT SQL_TOKEN_NAME
%nonassoc <pParseNode> SQL_TOKEN_UMINUS
/* literal keyword tokens */
%token <pParseNode> SQL_TOKEN_ALL SQL_TOKEN_ALTER SQL_TOKEN_AMMSC SQL_TOKEN_ANY SQL_TOKEN_AS SQL_TOKEN_ASC SQL_TOKEN_AT SQL_TOKEN_AUTHORIZATION SQL_TOKEN_AVG
%token <pParseNode> SQL_TOKEN_BETWEEN SQL_TOKEN_BIT SQL_TOKEN_BOTH SQL_TOKEN_BY
%token <pParseNode> SQL_TOKEN_CAST SQL_TOKEN_CHARACTER SQL_TOKEN_CHECK SQL_TOKEN_COLLATE SQL_TOKEN_COMMIT SQL_TOKEN_CONTINUE SQL_TOKEN_CONVERT SQL_TOKEN_COUNT SQL_TOKEN_CREATE SQL_TOKEN_CROSS
%token <pParseNode> SQL_TOKEN_CURRENT SQL_TOKEN_CURSOR
%token <pParseNode> SQL_TOKEN_DATE SQL_TOKEN_DATEVALUE SQL_TOKEN_DAY SQL_TOKEN_DEC SQL_TOKEN_DECIMAL SQL_TOKEN_DECLARE SQL_TOKEN_DEFAULT SQL_TOKEN_DELETE SQL_TOKEN_DESC
%token <pParseNode> SQL_TOKEN_DISTINCT SQL_TOKEN_DOUBLE SQL_TOKEN_DROP
%token <pParseNode> SQL_TOKEN_ESCAPE SQL_TOKEN_EXCEPT SQL_TOKEN_EXISTS SQL_TOKEN_FALSE SQL_TOKEN_FETCH SQL_TOKEN_FLOAT SQL_TOKEN_FOR SQL_TOKEN_FOREIGN SQL_TOKEN_FOUND SQL_TOKEN_FROM SQL_TOKEN_FULL
%token <pParseNode> SQL_TOKEN_GRANT SQL_TOKEN_GROUP SQL_TOKEN_HAVING SQL_TOKEN_IN SQL_TOKEN_INDICATOR SQL_TOKEN_INNER SQL_TOKEN_INTEGER SQL_TOKEN_INTO SQL_TOKEN_IS SQL_TOKEN_INTERSECT
%token <pParseNode> SQL_TOKEN_JOIN SQL_TOKEN_KEY SQL_TOKEN_LEADING SQL_TOKEN_LIKE SQL_TOKEN_LOCAL SQL_TOKEN_LOWER
%token <pParseNode> SQL_TOKEN_MAX SQL_TOKEN_MIN SQL_TOKEN_NATURAL SQL_TOKEN_NCHAR SQL_TOKEN_NULL SQL_TOKEN_NUMERIC
%token <pParseNode> SQL_TOKEN_OCTET_LENGTH SQL_TOKEN_OF SQL_TOKEN_ON SQL_TOKEN_OPTION SQL_TOKEN_ORDER SQL_TOKEN_OUTER
%token <pParseNode> SQL_TOKEN_PRECISION SQL_TOKEN_PRIMARY SQL_TOKEN_PRIVILEGES SQL_TOKEN_PROCEDURE SQL_TOKEN_PUBLIC
%token <pParseNode> SQL_TOKEN_REAL SQL_TOKEN_REFERENCES SQL_TOKEN_ROLLBACK
%token <pParseNode> SQL_TOKEN_SCHEMA SQL_TOKEN_SELECT SQL_TOKEN_SET SQL_TOKEN_SIZE SQL_TOKEN_SMALLINT SQL_TOKEN_SOME SQL_TOKEN_SQLCODE SQL_TOKEN_SQLERROR SQL_TOKEN_SUM
%token <pParseNode> SQL_TOKEN_TABLE SQL_TOKEN_TIME SQL_TOKEN_TIMESTAMP SQL_TOKEN_TIMEZONE_HOUR SQL_TOKEN_TIMEZONE_MINUTE SQL_TOKEN_TO SQL_TOKEN_TRAILING SQL_TOKEN_TRANSLATE SQL_TOKEN_TRIM SQL_TOKEN_TRUE SQL_TOKEN_UNION
%token <pParseNode> SQL_TOKEN_UNIQUE SQL_TOKEN_UNKNOWN SQL_TOKEN_UPDATE SQL_TOKEN_UPPER SQL_TOKEN_USAGE SQL_TOKEN_USER SQL_TOKEN_USING SQL_TOKEN_VALUES SQL_TOKEN_VIEW
%token <pParseNode> SQL_TOKEN_WHERE SQL_TOKEN_WITH SQL_TOKEN_WORK SQL_TOKEN_ZONE
/* ODBC KEYWORDS */
%token <pParseNode> SQL_TOKEN_CALL SQL_TOKEN_D SQL_TOKEN_FN SQL_TOKEN_T SQL_TOKEN_TS SQL_TOKEN_OJ
/* string functions */
%token <pParseNode> SQL_TOKEN_ASCII SQL_TOKEN_BIT_LENGTH SQL_TOKEN_CHAR SQL_TOKEN_CHAR_LENGTH SQL_TOKEN_CHARACTER_LENGTH
%token <pParseNode> SQL_TOKEN_CONCAT
%token <pParseNode> SQL_TOKEN_DIFFERENCE SQL_TOKEN_INSERT SQL_TOKEN_LCASE SQL_TOKEN_LEFT SQL_TOKEN_LENGTH SQL_TOKEN_LOCATE
%token <pParseNode> SQL_TOKEN_LOCATE_2 SQL_TOKEN_LTRIM SQL_TOKEN_POSITION SQL_TOKEN_REPEAT SQL_TOKEN_REPLACE
%token <pParseNode> SQL_TOKEN_RIGHT SQL_TOKEN_RTRIM SQL_TOKEN_SOUNDEX SQL_TOKEN_SPACE SQL_TOKEN_SUBSTRING SQL_TOKEN_UCASE
/* time and date functions */
%token <pParseNode> SQL_TOKEN_CURRENT_DATE SQL_TOKEN_CURRENT_TIME SQL_TOKEN_CURRENT_TIMESTAMP SQL_TOKEN_CURDATE SQL_TOKEN_CURTIME
%token <pParseNode> SQL_TOKEN_DAYNAME SQL_TOKEN_DAYOFMONTH SQL_TOKEN_DAYOFWEEK SQL_TOKEN_DAYOFYEAR SQL_TOKEN_EXTRACT
%token <pParseNode> SQL_TOKEN_HOUR SQL_TOKEN_MINUTE SQL_TOKEN_MONTH SQL_TOKEN_MONTHNAME SQL_TOKEN_NOW SQL_TOKEN_QUARTER SQL_TOKEN_DATEDIFF
%token <pParseNode> SQL_TOKEN_SECOND SQL_TOKEN_TIMESTAMPADD SQL_TOKEN_TIMESTAMPDIFF SQL_TOKEN_TIMEVALUE SQL_TOKEN_WEEK SQL_TOKEN_YEAR
/* numeric functions */
%token <pParseNode> SQL_TOKEN_ABS SQL_TOKEN_ACOS SQL_TOKEN_ASIN SQL_TOKEN_ATAN SQL_TOKEN_ATAN2 SQL_TOKEN_CEILING
%token <pParseNode> SQL_TOKEN_COS SQL_TOKEN_COT SQL_TOKEN_DEGREES SQL_TOKEN_EXP SQL_TOKEN_FLOOR SQL_TOKEN_LOGF SQL_TOKEN_LOG SQL_TOKEN_LN
%token <pParseNode> SQL_TOKEN_LOG10 SQL_TOKEN_MOD SQL_TOKEN_PI SQL_TOKEN_POWER SQL_TOKEN_RADIANS SQL_TOKEN_RAND SQL_TOKEN_ROUNDMAGIC
%token <pParseNode> SQL_TOKEN_ROUND SQL_TOKEN_SIGN SQL_TOKEN_SIN SQL_TOKEN_SQRT SQL_TOKEN_TAN SQL_TOKEN_TRUNCATE
// computational operation
%token <pParseNode> SQL_TOKEN_EVERY SQL_TOKEN_INTERSECTION SQL_TOKEN_FUSION SQL_TOKEN_COLLECT SQL_TOKEN_VAR_POP SQL_TOKEN_VAR_SAMP
%token <pParseNode> SQL_TOKEN_STDDEV_SAMP SQL_TOKEN_STDDEV_POP
/* operators */
%left SQL_TOKEN_NAME
%left <pParseNode> SQL_TOKEN_OR
%left <pParseNode> SQL_TOKEN_AND
%left <pParseNode> SQL_LESSEQ SQL_GREATEQ SQL_NOTEQUAL SQL_LESS SQL_GREAT SQL_EQUAL /* '<' '>' = <> < > <= >= != */
%left <pParseNode> '+' '-' SQL_CONCAT
%left <pParseNode> '*' '/'
%left SQL_TOKEN_NATURAL SQL_TOKEN_CROSS SQL_TOKEN_FULL SQL_TOKEN_LEFT SQL_TOKEN_RIGHT
%left ')'
%right '='
%right '.'
%right '('
%token <pParseNode> SQL_TOKEN_INVALIDSYMBOL
/*%type <pParseNode> sql_single_statement */
%type <pParseNode> sql /*schema */
%type <pParseNode> column_def_opt_list column_def_opt table_constraint_def column_commalist
%type <pParseNode> view_def opt_with_check_option opt_column_commalist privilege_def
%type <pParseNode> opt_with_grant_option privileges operation_commalist operation
%type <pParseNode> grantee_commalist grantee opt_order_by_clause ordering_spec_commalist
%type <pParseNode> ordering_spec opt_asc_desc manipulative_statement commit_statement
%type <pParseNode> /*delete_statement_positioned*/ delete_statement_searched fetch_statement
%type <pParseNode> insert_statement values_or_query_spec
%type <pParseNode> rollback_statement select_statement_into opt_all_distinct
%type <pParseNode> /*update_statement_positioned*/ assignment_commalist assignment
%type <pParseNode> update_statement_searched target_commalist target opt_where_clause
%type <pParseNode> select_statement selection table_exp from_clause table_ref_commalist table_ref
%type <pParseNode> where_clause opt_group_by_clause column_ref_commalist opt_having_clause
%type <pParseNode> search_condition predicate comparison_predicate between_predicate
%type <pParseNode> like_predicate opt_escape test_for_null in_predicate
%type <pParseNode> all_or_any_predicate any_all_some existence_test subquery
%type <pParseNode> scalar_exp_commalist parameter_ref literal
%type <pParseNode> column_ref data_type column cursor parameter range_variable user /*like_check*/
/* neue Regeln bei OJ */
%type <pParseNode> derived_column as_clause table_name num_primary term num_value_exp
%type <pParseNode> value_exp_primary num_value_fct unsigned_value_spec cast_spec set_fct_spec scalar_subquery
%type <pParseNode> position_exp extract_exp length_exp general_value_spec
%type <pParseNode> general_set_fct set_fct_type query_exp non_join_query_exp joined_table
%type <pParseNode> non_join_query_term non_join_query_primary simple_table
%type <pParseNode> table_value_const_list row_value_constructor row_value_const_list row_value_constructor_elem
%type <pParseNode> qualified_join value_exp query_term join_type outer_join_type join_condition boolean_term
%type <pParseNode> boolean_factor truth_value boolean_test boolean_primary named_columns_join join_spec
%type <pParseNode> cast_operand cast_target factor datetime_value_exp /*interval_value_exp*/ datetime_term datetime_factor
%type <pParseNode> datetime_primary datetime_value_fct time_zone time_zone_specifier /*interval_term*/ /*interval_qualifier*/
%type <pParseNode> /*start_field*/ non_second_datetime_field /*end_field*/ /*single_datetime_field*/ extract_field datetime_field time_zone_field
%type <pParseNode> extract_source char_length_exp octet_length_exp bit_length_exp select_sublist string_value_exp
%type <pParseNode> char_value_exp concatenation char_factor char_primary string_value_fct char_substring_fct fold
%type <pParseNode> form_conversion char_translation trim_fct trim_operands trim_spec bit_value_fct bit_substring_fct op_column_commalist
%type <pParseNode> /*bit_concatenation*/ bit_value_exp bit_factor bit_primary collate_clause char_value_fct unique_spec value_exp_commalist in_predicate_value unique_test update_source
%type <pParseNode> function_arg_commalist3 string_function_3Argument function_arg_commalist4 string_function_4Argument function_arg_commalist2 string_function_1Argument string_function_2Argument
%type <pParseNode> date_function_0Argument date_function_1Argument function_name12 function_name23 function_name1 function_name2 function_name3 function_name0 numeric_function_0Argument numeric_function_1Argument numeric_function_2Argument date_function_3Argument
%type <pParseNode> all query_primary sql_not for_length upper_lower comparison column_val cross_union /*opt_schema_element_list*/
%type <pParseNode> /*op_authorization op_schema*/ nil_fkt schema_element base_table_def base_table_element base_table_element_commalist
%type <pParseNode> column_def odbc_fct_spec odbc_call_spec odbc_fct_type op_parameter union_statement
%type <pParseNode> op_odbc_call_parameter odbc_parameter_commalist odbc_parameter function_args_commalist function_arg
%type <pParseNode> catalog_name schema_name table_node numeric_function string_function function_name date_function table_primary_as_range_column opt_as
%%
/* Parse Tree an OSQLParser zurueckliefern
* (der Zugriff ueber yyval nach Aufruf des Parsers scheitert,
*
*/
sql_single_statement:
sql
{ xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
| sql ';'
{ xxx_pGLOBAL_SQLPARSER->setParseTree( $1 ); }
;
/*
sql_list:
sql_ ';'
{$$ = SQL_NEW_LISTRULE;
$$->append($1);
pSqlParseTreeRoot = $1; -- obsolete - Ergebnis in yyval! rdm }
| sql_list sql ';'
{$1->append($2);
$$ = $1;}
;
*/
/* schema definition language */
/* Note: other ``sql:sal_Unicode() rules appear later in the grammar */
/***
sql:
schema
;
op_authorization:
{$$ = SQL_NEW_RULE;}
| SQL_TOKEN_AUTHORIZATION user
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
op_schema:
{$$ = SQL_NEW_RULE;}
| SQL_TOKEN_NAME
| SQL_TOKEN_NAME '.' SQL_TOKEN_NAME
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($3);
}
;
schema:
SQL_TOKEN_CREATE SQL_TOKEN_SCHEMA op_schema op_authorization opt_schema_element_list
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);
}
;
opt_schema_element_list:
/* empty * / {$$ = SQL_NEW_RULE;}
| schema_glement_list
;
schema_element_list:
schema_element
{$$ = SQL_NEW_LISTRULE;
$$->append($1);}
| schema_element_list schema_element
{$1->append($2);
$$ = $1;}
;
*/
sql:
schema_element
{$$ = SQL_NEW_RULE;
$$->append($1);
}
;
schema_element:
base_table_def
| view_def
| privilege_def
;
base_table_def:
SQL_TOKEN_CREATE SQL_TOKEN_TABLE table_node '(' base_table_element_commalist ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($5);
$$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));}
;
base_table_element_commalist:
base_table_element
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| base_table_element_commalist ',' base_table_element
{$1->append($3);
$$ = $1;}
;
base_table_element:
column_def
| table_constraint_def
;
column_def:
column data_type column_def_opt_list
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
}
;
column_def_opt_list:
/* empty */ {$$ = SQL_NEW_LISTRULE;}
| column_def_opt_list column_def_opt
{$1->append($2);
$$ = $1;}
;
nil_fkt:
datetime_value_fct
;
unique_spec:
SQL_TOKEN_UNIQUE
| SQL_TOKEN_PRIMARY SQL_TOKEN_KEY
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
column_def_opt:
SQL_TOKEN_NOT SQL_TOKEN_NULL
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
| unique_spec
| SQL_TOKEN_DEFAULT literal
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
| SQL_TOKEN_DEFAULT SQL_TOKEN_NULL
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
| SQL_TOKEN_DEFAULT SQL_TOKEN_USER
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
| SQL_TOKEN_DEFAULT nil_fkt
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
| SQL_TOKEN_CHECK
| SQL_TOKEN_CHECK '(' search_condition ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
| SQL_TOKEN_REFERENCES table_node
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
| SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($4);
$$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));}
;
table_constraint_def:
unique_spec '(' column_commalist ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
| SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($4);
$$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));
$$->append($6);
$$->append($7);}
| SQL_TOKEN_FOREIGN SQL_TOKEN_KEY '(' column_commalist ')' SQL_TOKEN_REFERENCES table_node '(' column_commalist ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($4);
$$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));
$$->append($6);
$$->append($7);
$$->append($8 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($9);
$$->append($10 = newNode(")", SQL_NODE_PUNCTUATION));}
| SQL_TOKEN_CHECK '(' search_condition ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
;
op_column_commalist:
/* empty */ {$$ = SQL_NEW_RULE;}
| '(' column_commalist ')'
{$$ = SQL_NEW_RULE;
$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
column_commalist:
column_commalist ',' column
{$1->append($3);
$$ = $1;}
| column
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
;
view_def:
SQL_TOKEN_CREATE SQL_TOKEN_VIEW table_node opt_column_commalist SQL_TOKEN_AS select_statement opt_with_check_option
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6);
$$->append($7);}
;
opt_with_check_option:
/* empty */ {$$ = SQL_NEW_RULE;}
| SQL_TOKEN_WITH SQL_TOKEN_CHECK SQL_TOKEN_OPTION
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);}
;
opt_column_commalist:
/* empty */ {$$ = SQL_NEW_RULE;}
| '(' column_commalist ')'
{$$ = SQL_NEW_RULE;
$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));}
;
privilege_def:
SQL_TOKEN_GRANT privileges SQL_TOKEN_ON table_node SQL_TOKEN_TO grantee_commalist
opt_with_grant_option
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6);
$$->append($7);}
;
opt_with_grant_option:
/* empty */ {$$ = SQL_NEW_RULE;}
| SQL_TOKEN_WITH SQL_TOKEN_GRANT SQL_TOKEN_OPTION
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);}
;
privileges:
SQL_TOKEN_ALL SQL_TOKEN_PRIVILEGES
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
| operation_commalist
;
operation_commalist:
operation
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| operation_commalist ',' operation
{$1->append($3);
$$ = $1;}
;
operation:
SQL_TOKEN_SELECT
| SQL_TOKEN_INSERT opt_column_commalist
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
| SQL_TOKEN_DELETE
| SQL_TOKEN_UPDATE opt_column_commalist
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
| SQL_TOKEN_REFERENCES opt_column_commalist
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
| SQL_TOKEN_USAGE
;
grantee_commalist:
grantee
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| grantee_commalist ',' grantee
{$1->append($3);
$$ = $1;}
;
grantee:
SQL_TOKEN_PUBLIC
| user
;
/* module language */
opt_order_by_clause:
/* empty */ {$$ = SQL_NEW_RULE;}
| SQL_TOKEN_ORDER SQL_TOKEN_BY ordering_spec_commalist
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);}
;
ordering_spec_commalist:
ordering_spec
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| ordering_spec_commalist ',' ordering_spec
{$1->append($3);
$$ = $1;}
;
ordering_spec:
/* SQL_TOKEN_INTNUM opt_asc_desc
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
*/
predicate opt_asc_desc
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
| row_value_constructor_elem opt_asc_desc
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
;
opt_asc_desc:
{$$ = SQL_NEW_RULE;}
| SQL_TOKEN_ASC
| SQL_TOKEN_DESC
;
/***
manipulative_statement_list:
manipulative_statement
{$$ = SQL_NEW_LISTRULE;
$$->append($1);}
| manipulative_statement_list manipulative_statement
{$1->append($2);
$$ = $1;}
;
***/
sql_not:
{$$ = SQL_NEW_RULE;}
| SQL_TOKEN_NOT
;
/* manipulative statements */
sql: manipulative_statement
;
manipulative_statement:
commit_statement
/* | delete_statement_positioned*/
| delete_statement_searched
| fetch_statement
| insert_statement
| rollback_statement
| select_statement_into
/* | update_statement_positioned*/
| update_statement_searched
| union_statement
| '{' odbc_call_spec '}'
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("{", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode("}", SQL_NODE_PUNCTUATION));
}
;
union_statement:
select_statement
| union_statement SQL_TOKEN_UNION all select_statement
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
;
commit_statement:
SQL_TOKEN_COMMIT SQL_TOKEN_WORK
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
;
/*
delete_statement_positioned:
SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6);
$$->append($7);}
;
*/
delete_statement_searched:
SQL_TOKEN_DELETE SQL_TOKEN_FROM table_node opt_where_clause
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);}
;
fetch_statement:
SQL_TOKEN_FETCH cursor SQL_TOKEN_INTO target_commalist
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);}
;
insert_statement:
SQL_TOKEN_INSERT SQL_TOKEN_INTO table_node opt_column_commalist values_or_query_spec
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);}
;
values_or_query_spec:
SQL_TOKEN_VALUES '(' table_value_const_list ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
table_value_const_list:
row_value_constructor
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| table_value_const_list ',' row_value_constructor
{$1->append($3);
$$ = $1;}
;
row_value_const_list:
row_value_constructor_elem
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| row_value_const_list ',' row_value_constructor_elem
{$1->append($3);
$$ = $1;}
;
row_value_constructor:
row_value_constructor_elem
/* | '(' row_value_const_list ')'
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
}
*/
;
row_value_constructor_elem:
value_exp /*[^')']*/
| SQL_TOKEN_DEFAULT
;
rollback_statement:
SQL_TOKEN_ROLLBACK SQL_TOKEN_WORK
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
;
/* INTO target_commalist herausgenommen */
select_statement_into:
SQL_TOKEN_SELECT opt_all_distinct selection SQL_TOKEN_INTO target_commalist table_exp
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6); }
;
opt_all_distinct:
{$$ = SQL_NEW_RULE;}
| SQL_TOKEN_ALL
| SQL_TOKEN_DISTINCT
;
/*
update_statement_positioned:
SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist
SQL_TOKEN_WHERE SQL_TOKEN_CURRENT SQL_TOKEN_OF cursor
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6);
$$->append($7);
$$->append($8);}
;
*/
assignment_commalist:
assignment
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| assignment_commalist ',' assignment
{$1->append($3);
$$ = $1;}
;
assignment:
column SQL_EQUAL update_source
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);}
;
update_source:
value_exp
| SQL_TOKEN_DEFAULT
;
update_statement_searched:
SQL_TOKEN_UPDATE table_node SQL_TOKEN_SET assignment_commalist opt_where_clause
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);}
;
target_commalist:
target
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| target_commalist ',' target
{$1->append($3);
$$ = $1;}
;
target:
parameter_ref
;
opt_where_clause:
/* empty */ {$$ = SQL_NEW_RULE;}
| where_clause
;
/* query expressions */
query_term:
non_join_query_term
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
/* SELECT STATEMENT */
select_statement:
SQL_TOKEN_SELECT opt_all_distinct selection table_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
;
selection:
'*'
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("*", SQL_NODE_PUNCTUATION));
}
| scalar_exp_commalist
;
table_exp:
from_clause
opt_where_clause
opt_group_by_clause
opt_having_clause
opt_order_by_clause
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);}
;
from_clause:
SQL_TOKEN_FROM table_ref_commalist
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
;
table_ref_commalist:
table_ref
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| table_ref_commalist ',' table_ref
{$1->append($3);
$$ = $1;}
;
opt_as:
/* empty */ {$$ = SQL_NEW_RULE;}
| SQL_TOKEN_AS
;
table_primary_as_range_column:
{$$ = SQL_NEW_RULE;}
| opt_as SQL_TOKEN_NAME op_column_commalist
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
}
;
table_ref:
table_node table_primary_as_range_column
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
| subquery range_variable op_column_commalist
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
}
| joined_table
| '{' SQL_TOKEN_OJ joined_table '}'
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("{", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3);
$$->append($4 = newNode("}", SQL_NODE_PUNCTUATION));
}
| '(' joined_table ')'
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
where_clause:
SQL_TOKEN_WHERE search_condition
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
;
opt_group_by_clause:
/* empty */ {$$ = SQL_NEW_RULE;}
| SQL_TOKEN_GROUP SQL_TOKEN_BY column_ref_commalist
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);}
;
column_ref_commalist:
column_ref
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| set_fct_spec
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| column_ref_commalist ',' column_ref
{$1->append($3);
$$ = $1;}
| column_ref_commalist ',' set_fct_spec
{$1->append($3);
$$ = $1;}
;
opt_having_clause:
/* empty */ {$$ = SQL_NEW_RULE;}
| SQL_TOKEN_HAVING search_condition
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
;
/* search conditions */
truth_value:
SQL_TOKEN_TRUE
| SQL_TOKEN_FALSE
| SQL_TOKEN_UNKNOWN
| SQL_TOKEN_NULL
;
boolean_primary:
predicate
| '(' search_condition ')'
{ // boolean_primary: rule 2
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
}
| row_value_constructor_elem /*[^')' ',']*/
{
if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// boolean_primary: rule 3
{
$$ = SQL_NEW_RULE;
sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildComparsionRule($$,$1);
if(nErg == 1)
{
OSQLParseNode* pTemp = $$;
$$ = pTemp->removeAt((sal_uInt32)0);
delete pTemp;
}
else
{
delete $$;
if(nErg)
YYERROR;
else
YYABORT;
}
}
else
YYERROR;
}
;
boolean_test:
boolean_primary
| boolean_primary SQL_TOKEN_IS sql_not truth_value
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
;
boolean_factor:
boolean_test
| SQL_TOKEN_NOT boolean_test
{ // boolean_factor: rule 1
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
boolean_term:
boolean_factor
| boolean_term SQL_TOKEN_AND boolean_factor
{
$$ = SQL_NEW_RULE; // boolean_term: rule 1
$$->append($1);
$$->append($2);
$$->append($3);
}
;
search_condition:
boolean_term
| search_condition SQL_TOKEN_OR boolean_term
{
$$ = SQL_NEW_RULE; // search_condition
$$->append($1);
$$->append($2);
$$->append($3);
}
;
predicate:
comparison_predicate
| between_predicate
| all_or_any_predicate
| existence_test
| unique_test
| test_for_null
| in_predicate
| like_predicate
;
comparison_predicate:
row_value_constructor comparison row_value_constructor
{
$$ = SQL_NEW_RULE; // comparison_predicate: rule 1
$$->append($1);
$$->append($2);
$$->append($3);
}
| comparison row_value_constructor
{
if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // comparison_predicate: rule 2
{
$$ = SQL_NEW_RULE;
sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$2,$1);
if(nErg == 1)
{
OSQLParseNode* pTemp = $$;
$$ = pTemp->removeAt((sal_uInt32)0);
delete pTemp;
}
else
{
delete $$;
YYABORT;
}
}
else
{
YYERROR;
}
}
;
comparison:
SQL_LESS
| SQL_NOTEQUAL
| SQL_EQUAL
| SQL_GREAT
| SQL_LESSEQ
| SQL_GREATEQ
;
between_predicate:
row_value_constructor sql_not SQL_TOKEN_BETWEEN row_value_constructor SQL_TOKEN_AND row_value_constructor
{$$ = SQL_NEW_RULE; // between_predicate: rule 1
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6);
}
| sql_not SQL_TOKEN_BETWEEN row_value_constructor SQL_TOKEN_AND row_value_constructor
{
if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // between_predicate: rule 2
{
$$ = SQL_NEW_RULE;
sal_Int16 nErg = xxx_pGLOBAL_SQLPARSER->buildPredicateRule($$,$3,$2,$5);
if(nErg == 1)
{
OSQLParseNode* pTemp = $$;
$$ = pTemp->removeAt((sal_uInt32)0);
$$->insert(1,$1);
delete pTemp;
delete $4;
}
else
{
delete $$;
YYABORT;
}
}
else
YYERROR;
}
;
like_predicate:
row_value_constructor SQL_TOKEN_NOT SQL_TOKEN_LIKE string_value_exp opt_escape
{
$$ = SQL_NEW_RULE; // like_predicate: rule 1
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);
}
| row_value_constructor SQL_TOKEN_LIKE string_value_exp opt_escape
{
$$ = SQL_NEW_RULE; // like_predicate: rule 2
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
| row_value_constructor SQL_TOKEN_NOT SQL_TOKEN_LIKE value_exp_primary opt_escape
{
$$ = SQL_NEW_RULE; // like_predicate: rule 3
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);
}
| row_value_constructor SQL_TOKEN_LIKE value_exp_primary opt_escape
{
$$ = SQL_NEW_RULE; // like_predicate: rule 4
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
| sql_not SQL_TOKEN_LIKE string_value_exp opt_escape
{
if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // like_predicate: rule 5
{
OSQLParseNode* pColumnRef = newNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQL_NODE_NAME));
$$ = SQL_NEW_RULE;
$$->append(pColumnRef);
$$->append($1);
$$->append($2);
if (xxx_pGLOBAL_SQLPARSER->buildLikeRule($$,$3,$4))
$$->append($4);
else
{
delete $$;
YYABORT;
}
}
else
YYERROR;
}
| sql_not SQL_TOKEN_LIKE value_exp_primary opt_escape
{
if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // like_predicate: rule 6
{
OSQLParseNode* pColumnRef = newNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQL_NODE_NAME));
$$ = SQL_NEW_RULE;
$$->append(pColumnRef);
$$->append($1);
$$->append($2);
if (xxx_pGLOBAL_SQLPARSER->buildLikeRule($$,$3,$4))
$$->append($4);
else
{
delete $$;
YYABORT;
}
}
else
YYERROR;
}
;
opt_escape:
/* empty */ {$$ = SQL_NEW_RULE;}
| SQL_TOKEN_ESCAPE string_value_exp
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
| '{' SQL_TOKEN_ESCAPE SQL_TOKEN_STRING '}'
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("{", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3);
$$->append($4 = newNode("}", SQL_NODE_PUNCTUATION));
}
;
test_for_null:
row_value_constructor SQL_TOKEN_IS sql_not truth_value
{
$$ = SQL_NEW_RULE; // test_for_null: rule 1
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
| SQL_TOKEN_IS sql_not truth_value
{
if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())// test_for_null: rule 2
{
OSQLParseNode* pColumnRef = newNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQL_NODE_NAME));
$$ = SQL_NEW_RULE;
$$->append(pColumnRef);
$$->append($1);
$$->append($2);
$$->append($3);
}
else
YYERROR;
}
;
in_predicate_value:
subquery
{$$ = SQL_NEW_RULE;
$$->append($1);
}
| '(' value_exp_commalist ')'
{$$ = SQL_NEW_RULE;
$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
in_predicate:
row_value_constructor sql_not SQL_TOKEN_IN in_predicate_value
{
$$ = SQL_NEW_RULE;// in_predicate: rule 1
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
| sql_not SQL_TOKEN_IN in_predicate_value
{
if ( xxx_pGLOBAL_SQLPARSER->inPredicateCheck() )// in_predicate: rule 2
{
OSQLParseNode* pColumnRef = newNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQL_NODE_NAME));
$$ = SQL_NEW_RULE;
$$->append(pColumnRef);
$$->append($1);
$$->append($2);
$$->append($3);
// hello
}
else
YYERROR;
}
;
all_or_any_predicate:
row_value_constructor comparison any_all_some subquery
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
| comparison any_all_some subquery
{
if(xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
{
OSQLParseNode* pColumnRef = newNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
pColumnRef->append(newNode(xxx_pGLOBAL_SQLPARSER->getFieldName(),SQL_NODE_NAME));
$$ = SQL_NEW_RULE;
$$->append(pColumnRef);
$$->append($1);
$$->append($2);
$$->append($3);
}
else
YYERROR;
}
;
any_all_some:
SQL_TOKEN_ANY
| SQL_TOKEN_ALL
| SQL_TOKEN_SOME
;
existence_test:
SQL_TOKEN_EXISTS subquery
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
;
unique_test:
SQL_TOKEN_UNIQUE subquery
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
;
subquery:
'(' query_exp ')'
{$$ = SQL_NEW_RULE;
$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));}
;
/* scalar expressions */
scalar_exp_commalist:
select_sublist
{
$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);
}
| scalar_exp_commalist ',' select_sublist
{
$1->append($3);
$$ = $1;
}
;
select_sublist:
/* table_node '.' '*'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($3 = newNode("*", SQL_NODE_PUNCTUATION));
}
*/
derived_column
;
parameter_ref:
parameter
;
/*
op_like:
'*'
{
$$ = newNode("*", SQL_NODE_PUNCTUATION);
}
| '?'
{
$$ = newNode("?", SQL_NODE_PUNCTUATION);
}
| op_like '*'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("*", SQL_NODE_PUNCTUATION));
xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
}
| op_like '?'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("?", SQL_NODE_PUNCTUATION));
xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_False);
}
;
*/
literal:
/* SQL_TOKEN_STRING
| */SQL_TOKEN_INT
| SQL_TOKEN_REAL_NUM
| SQL_TOKEN_INTNUM
| SQL_TOKEN_APPROXNUM
| SQL_TOKEN_ACCESS_DATE
/* rules for predicate check */
| literal SQL_TOKEN_STRING
{
if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
}
else
YYERROR;
}
| literal SQL_TOKEN_INT
{
if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
}
else
YYERROR;
}
| literal SQL_TOKEN_REAL_NUM
{
if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
}
else
YYERROR;
}
| literal SQL_TOKEN_APPROXNUM
{
if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
xxx_pGLOBAL_SQLPARSER->reduceLiteral($$, sal_True);
}
else
YYERROR;
}
;
/* miscellaneous */
as_clause:
/* empty */ {$$ = SQL_NEW_RULE;}
| SQL_TOKEN_AS column
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
| column
;
position_exp:
SQL_TOKEN_POSITION '(' value_exp SQL_TOKEN_IN value_exp ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
}
| SQL_TOKEN_POSITION '(' value_exp_commalist ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
num_value_fct:
position_exp
| extract_exp
| length_exp
;
char_length_exp:
SQL_TOKEN_CHAR_LENGTH '(' value_exp ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
| SQL_TOKEN_CHARACTER_LENGTH '(' value_exp ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
octet_length_exp:
SQL_TOKEN_OCTET_LENGTH '(' value_exp ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
bit_length_exp:
SQL_TOKEN_BIT_LENGTH '(' value_exp ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
length_exp:
char_length_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| octet_length_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| bit_length_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
datetime_field:
non_second_datetime_field
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| SQL_TOKEN_SECOND
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
extract_field:
time_zone_field
| datetime_field
| value_exp
;
time_zone_field:
SQL_TOKEN_TIMEZONE_HOUR
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| SQL_TOKEN_TIMEZONE_MINUTE
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
extract_source:
datetime_value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
/* | interval_value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
} */
;
extract_exp:
SQL_TOKEN_EXTRACT '(' extract_field SQL_TOKEN_FROM value_exp ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
unsigned_value_spec:
general_value_spec
| literal
;
general_value_spec:
parameter
| SQL_TOKEN_USER
| SQL_TOKEN_NULL
| SQL_TOKEN_FALSE
| SQL_TOKEN_TRUE
;
set_fct_spec:
general_set_fct
| '{' odbc_fct_spec '}'
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("{", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode("}", SQL_NODE_PUNCTUATION));
}
| function_name '(' ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
}
| function_name0 '(' ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
}
| function_name1 '(' function_arg ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
| function_name2 '(' function_arg_commalist2 ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
| function_name3 '(' function_arg_commalist3 ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
| string_function_4Argument '(' function_arg_commalist4 ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
| function_name '(' function_args_commalist ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
| function_name12 '(' function_args_commalist ')'
{
if ( $3->count() == 1 || $3->count() == 2 )
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
else
YYERROR;
}
| function_name23 '(' function_args_commalist ')'
{
if ( $3->count() == 2 || $3->count() == 3)
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
else
YYERROR;
}
;
function_name0:
date_function_0Argument
| numeric_function_0Argument
;
function_name1:
string_function_1Argument
| date_function_1Argument
| numeric_function_1Argument
;
function_name2:
string_function_2Argument
| numeric_function_2Argument
;
function_name12:
SQL_TOKEN_ROUND
| SQL_TOKEN_WEEK
| SQL_TOKEN_LOGF
| SQL_TOKEN_LOG
;
function_name23:
SQL_TOKEN_LOCATE
;
function_name3:
string_function_3Argument
| date_function_3Argument
;
function_name:
string_function
| date_function
| numeric_function
| SQL_TOKEN_NAME
;
string_function_1Argument:
SQL_TOKEN_LENGTH
| SQL_TOKEN_ASCII
| SQL_TOKEN_LCASE
| SQL_TOKEN_LTRIM
| SQL_TOKEN_RTRIM
| SQL_TOKEN_SPACE
| SQL_TOKEN_UCASE
;
string_function_2Argument:
SQL_TOKEN_REPEAT
| SQL_TOKEN_LEFT
| SQL_TOKEN_RIGHT
;
string_function_3Argument:
SQL_TOKEN_REPLACE
;
string_function_4Argument:
SQL_TOKEN_INSERT
;
string_function:
SQL_TOKEN_CHAR
| SQL_TOKEN_CONCAT
| SQL_TOKEN_DIFFERENCE
| SQL_TOKEN_LOCATE_2
| SQL_TOKEN_SOUNDEX
;
date_function_0Argument:
SQL_TOKEN_CURDATE
| SQL_TOKEN_CURTIME
| SQL_TOKEN_NOW
;
date_function_1Argument:
SQL_TOKEN_DAYOFWEEK
| SQL_TOKEN_DAYOFMONTH
| SQL_TOKEN_DAYOFYEAR
| SQL_TOKEN_MONTH
| SQL_TOKEN_DAYNAME
| SQL_TOKEN_MONTHNAME
| SQL_TOKEN_QUARTER
| SQL_TOKEN_HOUR
| SQL_TOKEN_MINUTE
| SQL_TOKEN_SECOND
| SQL_TOKEN_YEAR
| SQL_TOKEN_DAY
| SQL_TOKEN_TIMEVALUE
| SQL_TOKEN_DATEVALUE
;
date_function_3Argument:
SQL_TOKEN_DATEDIFF
date_function:
SQL_TOKEN_TIMESTAMPADD
| SQL_TOKEN_TIMESTAMPDIFF
;
numeric_function_0Argument:
SQL_TOKEN_PI
;
numeric_function_1Argument:
SQL_TOKEN_ABS
| SQL_TOKEN_ACOS
| SQL_TOKEN_ASIN
| SQL_TOKEN_ATAN
| SQL_TOKEN_CEILING
| SQL_TOKEN_COS
| SQL_TOKEN_COT
| SQL_TOKEN_DEGREES
| SQL_TOKEN_FLOOR
| SQL_TOKEN_SIGN
| SQL_TOKEN_SIN
| SQL_TOKEN_SQRT
| SQL_TOKEN_TAN
| SQL_TOKEN_EXP
| SQL_TOKEN_LOG10
| SQL_TOKEN_LN
| SQL_TOKEN_RADIANS
| SQL_TOKEN_ROUNDMAGIC
;
numeric_function_2Argument:
SQL_TOKEN_ATAN2
| SQL_TOKEN_MOD
| SQL_TOKEN_POWER
;
numeric_function:
SQL_TOKEN_RAND
| SQL_TOKEN_TRUNCATE
;
op_parameter:
{$$ = SQL_NEW_RULE;}
| '?' SQL_EQUAL
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("?", SQL_NODE_PUNCTUATION));
$$->append($2);
}
;
odbc_call_spec:
op_parameter SQL_TOKEN_CALL table_node op_odbc_call_parameter
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
;
op_odbc_call_parameter:
{$$ = SQL_NEW_RULE;}
| '(' odbc_parameter_commalist ')'
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
odbc_parameter_commalist:
odbc_parameter
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| odbc_parameter_commalist ',' odbc_parameter
{
$1->append($3);
$$ = $1;
}
;
odbc_parameter:
/* empty */ {$$ = SQL_NEW_RULE;}
| literal
| parameter
;
odbc_fct_spec:
odbc_fct_type SQL_TOKEN_STRING
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
odbc_fct_type:
SQL_TOKEN_FN
| SQL_TOKEN_D
| SQL_TOKEN_T
| SQL_TOKEN_TS
;
general_set_fct:
set_fct_type '(' opt_all_distinct value_exp ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4);
$$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));
}
| SQL_TOKEN_COUNT '(' '*' ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3 = newNode("*", SQL_NODE_PUNCTUATION));
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
| SQL_TOKEN_COUNT '(' opt_all_distinct value_exp ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4);
$$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
set_fct_type:
SQL_TOKEN_AVG
| SQL_TOKEN_MAX
| SQL_TOKEN_MIN
| SQL_TOKEN_SUM
| SQL_TOKEN_EVERY
| SQL_TOKEN_ANY
| SQL_TOKEN_SOME
| SQL_TOKEN_STDDEV_POP
| SQL_TOKEN_STDDEV_SAMP
| SQL_TOKEN_VAR_SAMP
| SQL_TOKEN_VAR_POP
| SQL_TOKEN_COLLECT
| SQL_TOKEN_FUSION
| SQL_TOKEN_INTERSECTION
;
outer_join_type:
SQL_TOKEN_LEFT %prec SQL_TOKEN_LEFT
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| SQL_TOKEN_RIGHT %prec SQL_TOKEN_RIGHT
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| SQL_TOKEN_FULL %prec SQL_TOKEN_FULL
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
join_condition:
SQL_TOKEN_ON search_condition
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
join_spec:
join_condition
| named_columns_join
;
join_type:
SQL_TOKEN_INNER
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| outer_join_type
| outer_join_type SQL_TOKEN_OUTER
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
cross_union:
table_ref /*[SQL_TOKEN_CROSS]*/ SQL_TOKEN_CROSS SQL_TOKEN_JOIN table_ref
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
;
qualified_join:
/* wenn SQL_TOKEN_NATURAL, dann keine join_spec */
table_ref /*[SQL_TOKEN_NATURAL]*/ SQL_TOKEN_NATURAL join_type SQL_TOKEN_JOIN table_ref
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);
}
| table_ref join_type SQL_TOKEN_JOIN table_ref join_spec
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
$$->append($5);
}
| cross_union
;
joined_table:
qualified_join
;
named_columns_join:
SQL_TOKEN_USING '(' column_commalist ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
simple_table:
select_statement
| values_or_query_spec
;
non_join_query_primary:
simple_table
| '(' non_join_query_exp ')'
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
non_join_query_term:
non_join_query_primary
| query_term SQL_TOKEN_INTERSECT all query_primary
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
;
query_primary:
non_join_query_primary
;
non_join_query_exp:
non_join_query_term
| query_exp SQL_TOKEN_UNION all query_term
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
| query_exp SQL_TOKEN_EXCEPT all query_term
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
;
all:
/* empty*/ {$$ = SQL_NEW_RULE;}
| SQL_TOKEN_ALL
;
query_exp:
non_join_query_exp /*[^')']*/
;
scalar_subquery:
subquery
;
cast_operand:
value_exp
;
cast_target:
table_node
| data_type
;
cast_spec:
SQL_TOKEN_CAST '(' cast_operand SQL_TOKEN_AS cast_target ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
value_exp_primary:
unsigned_value_spec
| column_ref
| set_fct_spec
| scalar_subquery
| '(' value_exp ')'
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode(")", SQL_NODE_PUNCTUATION));
}
| cast_spec
;
num_primary:
value_exp_primary
| num_value_fct
;
factor:
num_primary
| '-' num_primary %prec SQL_TOKEN_UMINUS
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("-", SQL_NODE_PUNCTUATION));
$$->append($2);
}
| '+' num_primary %prec SQL_TOKEN_UMINUS
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("+", SQL_NODE_PUNCTUATION));
$$->append($2);
}
;
term:
factor
| term '*' factor
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("*", SQL_NODE_PUNCTUATION));
$$->append($3);
}
| term '/' factor
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("/", SQL_NODE_PUNCTUATION));
$$->append($3);
}
;
num_value_exp:
term
| num_value_exp '+' term
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
$$->append($3);
}
| num_value_exp '-' term
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("-", SQL_NODE_PUNCTUATION));
$$->append($3);
}
;
datetime_primary:
/* value_exp_primary
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
|*/ datetime_value_fct
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
datetime_value_fct:
SQL_TOKEN_CURRENT_DATE
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| SQL_TOKEN_CURRENT_TIME
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| SQL_TOKEN_CURRENT_TIMESTAMP
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
time_zone:
SQL_TOKEN_AT time_zone_specifier
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
time_zone_specifier:
SQL_TOKEN_LOCAL
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
/* | SQL_TOKEN_TIME SQL_TOKEN_ZONE interval_value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
}*/
;
datetime_factor:
datetime_primary
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| datetime_primary time_zone
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
datetime_term:
datetime_factor
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
/*
interval_term:
literal
| interval_term '*' factor
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("*", SQL_NODE_PUNCTUATION));
$$->append($3);
}
| interval_term '/' factor
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("/", SQL_NODE_PUNCTUATION));
$$->append($3);
}
;
*/
datetime_value_exp:
datetime_term
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
/* | interval_value_exp '+' datetime_term
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
$$->append($3);
}
| datetime_value_exp '+' interval_term
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
$$->append($3);
}
| datetime_value_exp '-' interval_term
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("-", SQL_NODE_PUNCTUATION));
$$->append($3);
}
*/ ;
/*
interval_value_exp:
interval_term
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| interval_value_exp '+' interval_term
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
$$->append($3);
}
| interval_value_exp '-' interval_term
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("-", SQL_NODE_PUNCTUATION));
$$->append($3);
}
| '(' datetime_value_exp '-' datetime_term ')' interval_qualifier
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode("-", SQL_NODE_PUNCTUATION));
$$->append($4);
$$->append($5 = newNode(")", SQL_NODE_PUNCTUATION));
$$->append($6);
}
;
*/
non_second_datetime_field:
SQL_TOKEN_YEAR
| SQL_TOKEN_MONTH
| SQL_TOKEN_DAY
| SQL_TOKEN_HOUR
| SQL_TOKEN_MINUTE
;
/*start_field:
non_second_datetime_field
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| non_second_datetime_field '(' SQL_TOKEN_INTNUM ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
end_field:
non_second_datetime_field
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| SQL_TOKEN_SECOND
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| SQL_TOKEN_SECOND '(' SQL_TOKEN_INTNUM ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
*/
/*
single_datetime_field:
non_second_datetime_field
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| non_second_datetime_field '(' SQL_TOKEN_INTNUM ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
| SQL_TOKEN_SECOND
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| SQL_TOKEN_SECOND '(' SQL_TOKEN_INTNUM ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
| SQL_TOKEN_SECOND '(' SQL_TOKEN_INTNUM ',' SQL_TOKEN_INTNUM ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(",", SQL_NODE_PUNCTUATION));
$$->append($5);
$$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
*/
/*
interval_qualifier:
start_field SQL_TOKEN_TO end_field
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
}
| single_datetime_field
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
*/
function_arg_commalist2:
function_arg ',' function_arg
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);
$$->append($3);}
;
function_arg_commalist3:
function_arg ',' function_arg ',' function_arg
{
$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);
$$->append($3);
$$->append($5);
}
;
function_arg_commalist4:
function_arg ',' function_arg ',' function_arg ',' function_arg
{
$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);
$$->append($3);
$$->append($5);
$$->append($7);
}
;
value_exp_commalist:
value_exp
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| value_exp_commalist ',' value_exp
{$1->append($3);
$$ = $1;}
/* this rule is only valid if we check predicates */
| value_exp_commalist ';' value_exp
{
if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
{
$1->append($3);
$$ = $1;
}
else
YYERROR;
}
;
function_arg:
value_exp
| value_exp comparison value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
}
;
function_args_commalist:
function_arg
{$$ = SQL_NEW_COMMALISTRULE;
$$->append($1);}
| function_args_commalist ',' function_arg
{$1->append($3);
$$ = $1;}
/* this rule is only valid if we check predicates */
| function_args_commalist ';' function_arg
{
if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck())
{
$1->append($3);
$$ = $1;
}
else
YYERROR;
}
;
value_exp:
num_value_exp /*[^')']*/
| string_value_exp
| datetime_value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
string_value_exp:
char_value_exp
/* | bit_value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
*/ ;
char_value_exp:
char_factor
| concatenation
;
concatenation:
char_value_exp '+' char_factor
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
$$->append($3);
}
| value_exp SQL_CONCAT value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
}
;
char_primary:
SQL_TOKEN_STRING
| string_value_fct
;
collate_clause:
SQL_TOKEN_COLLATE table_node
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
char_factor:
char_primary
| char_primary collate_clause
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
string_value_fct:
char_value_fct
| bit_value_fct
;
bit_value_fct:
bit_substring_fct
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
bit_substring_fct:
SQL_TOKEN_SUBSTRING '(' bit_value_exp SQL_TOKEN_FROM string_value_exp for_length ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6);
$$->append($7 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
bit_value_exp:
bit_factor
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
/*
bit_concatenation
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
|
bit_concatenation:
bit_value_exp '+' bit_factor
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("+", SQL_NODE_PUNCTUATION));
$$->append($3);
}
;
*/
bit_factor:
bit_primary
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
bit_primary:
{$$ = SQL_NEW_RULE;}
/* value_exp_primary
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| string_value_fct
{
$$ = SQL_NEW_RULE;
$$->append($1);
}*/
;
char_value_fct:
char_substring_fct
| fold
| form_conversion
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| char_translation
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
| trim_fct
{
$$ = SQL_NEW_RULE;
$$->append($1);
}
;
for_length:
{$$ = SQL_NEW_RULE;}
| SQL_TOKEN_FOR value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
char_substring_fct:
SQL_TOKEN_SUBSTRING '(' value_exp SQL_TOKEN_FROM value_exp for_length ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6);
$$->append($7 = newNode(")", SQL_NODE_PUNCTUATION));
}
| SQL_TOKEN_SUBSTRING '(' value_exp_commalist ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
upper_lower:
SQL_TOKEN_UPPER
| SQL_TOKEN_LOWER
;
fold:
upper_lower '(' value_exp ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
form_conversion:
SQL_TOKEN_CONVERT '(' string_value_exp SQL_TOKEN_USING table_node ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
}
| SQL_TOKEN_CONVERT '(' cast_operand ',' cast_target ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($2 = newNode(",", SQL_NODE_PUNCTUATION));
$$->append($5);
$$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
char_translation:
SQL_TOKEN_TRANSLATE '(' string_value_exp SQL_TOKEN_USING table_node ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4);
$$->append($5);
$$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
trim_fct:
SQL_TOKEN_TRIM '(' trim_operands ')'
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));
}
;
trim_operands:
trim_spec value_exp SQL_TOKEN_FROM value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
$$->append($4);
}
| trim_spec SQL_TOKEN_FROM value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
}
| value_exp SQL_TOKEN_FROM value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
$$->append($3);
}
| SQL_TOKEN_FROM value_exp
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
| value_exp
;
trim_spec:
SQL_TOKEN_BOTH
| SQL_TOKEN_LEADING
| SQL_TOKEN_TRAILING
;
derived_column:
value_exp as_clause
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
/* Tabellenname */
table_node:
table_name
| schema_name
| catalog_name
;
catalog_name:
SQL_TOKEN_NAME '.' schema_name
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($3);
}
| SQL_TOKEN_NAME ':' schema_name
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode(":", SQL_NODE_PUNCTUATION));
$$->append($3);
}
;
schema_name:
SQL_TOKEN_NAME '.' table_name
{
$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($3);
}
;
table_name:
SQL_TOKEN_NAME
{$$ = SQL_NEW_RULE;
$$->append($1);}
;
/* Columns */
column_ref:
column
{$$ = SQL_NEW_RULE;
$$->append($1);}
/* | table_node '.' column_val %prec '.'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($3);}
*/
| SQL_TOKEN_NAME '.' column_val %prec '.'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($3);
}
| SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($5);}
| SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2= newNode(".", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($5);
$$->append($6 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($7);
}
| SQL_TOKEN_NAME ':' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val %prec '.'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2= newNode(":", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($5);
$$->append($6 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($7);
}
/* | SQL_TOKEN_NAME ';' SQL_TOKEN_NAME '.' SQL_TOKEN_NAME '.' column_val
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2= newNode(";", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($5);
$$->append($6 = newNode(".", SQL_NODE_PUNCTUATION));
$$->append($7);
}
*/ ;
/* data types */
column_val:
column
{$$ = SQL_NEW_RULE;
$$->append($1);}
| '*'
{
$$ = SQL_NEW_RULE;
$$->append($1 = newNode("*", SQL_NODE_PUNCTUATION));
}
;
data_type:
SQL_TOKEN_CHARACTER
| SQL_TOKEN_CHARACTER '(' SQL_TOKEN_INTNUM ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
| SQL_TOKEN_NUMERIC
| SQL_TOKEN_NUMERIC '(' SQL_TOKEN_INTNUM ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
| SQL_TOKEN_NUMERIC '(' SQL_TOKEN_INTNUM ',' SQL_TOKEN_INTNUM ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(",", SQL_NODE_PUNCTUATION));
$$->append($5);
$$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));}
| SQL_TOKEN_DECIMAL
| SQL_TOKEN_DECIMAL '(' SQL_TOKEN_INTNUM ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
| SQL_TOKEN_DECIMAL '(' SQL_TOKEN_INTNUM ',' SQL_TOKEN_INTNUM ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(",", SQL_NODE_PUNCTUATION));
$$->append($5);
$$->append($6 = newNode(")", SQL_NODE_PUNCTUATION));}
| SQL_TOKEN_INTEGER
| SQL_TOKEN_SMALLINT
| SQL_TOKEN_FLOAT
| SQL_TOKEN_FLOAT '(' SQL_TOKEN_INTNUM ')'
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2 = newNode("(", SQL_NODE_PUNCTUATION));
$$->append($3);
$$->append($4 = newNode(")", SQL_NODE_PUNCTUATION));}
| SQL_TOKEN_REAL
| SQL_TOKEN_DOUBLE SQL_TOKEN_PRECISION
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);}
;
/* the various things you can name */
column:
SQL_TOKEN_NAME
| SQL_TOKEN_POSITION
{
sal_uInt32 nNod = $$->getRuleID();
delete $$;
$$ = newNode(xxx_pGLOBAL_SQLPARSER->TokenIDToStr(nNod), SQL_NODE_NAME);
}
| SQL_TOKEN_CHAR_LENGTH
{
sal_uInt32 nNod = $$->getRuleID();
delete $$;
$$ = newNode(xxx_pGLOBAL_SQLPARSER->TokenIDToStr(nNod), SQL_NODE_NAME);
}
| SQL_TOKEN_EXTRACT
{
sal_uInt32 nNod = $$->getRuleID();
delete $$;
$$ = newNode(xxx_pGLOBAL_SQLPARSER->TokenIDToStr(nNod), SQL_NODE_NAME);
}
;
cursor: SQL_TOKEN_NAME
{$$ = SQL_NEW_RULE;
$$->append($1);}
;
/***
module: SQL_TOKEN_NAME
{$$ = SQL_NEW_RULE;
$$->append($1);}
;
***/
parameter:
':' SQL_TOKEN_NAME
{$$ = SQL_NEW_RULE;
$$->append($1 = newNode(":", SQL_NODE_PUNCTUATION));
$$->append($2);}
| '?'
{$$ = SQL_NEW_RULE; // test
$$->append($1 = newNode("?", SQL_NODE_PUNCTUATION));}
| '[' SQL_TOKEN_NAME ']'
{$$ = SQL_NEW_RULE;
$$->append($1 = newNode("[", SQL_NODE_PUNCTUATION));
$$->append($2);
$$->append($3 = newNode("]", SQL_NODE_PUNCTUATION));}
;
/***
procedure: SQL_TOKEN_NAME
{$$ = SQL_NEW_RULE;
$$->append($1);}
;
***/
range_variable:
{$$ = SQL_NEW_RULE;}
| opt_as SQL_TOKEN_NAME
{$$ = SQL_NEW_RULE;
$$->append($1);
$$->append($2);
}
;
user: SQL_TOKEN_NAME
;
/* PREDICATECHECK RULES */
sql:
search_condition /* checking predicats */
{
if (xxx_pGLOBAL_SQLPARSER->inPredicateCheck()) // sql: rule 1
{
$$ = $1;
if ( SQL_ISRULE($$,search_condition) )
{
$$->insert(0,newNode("(", SQL_NODE_PUNCTUATION));
$$->append(newNode(")", SQL_NODE_PUNCTUATION));
}
}
else
YYERROR;
}
| '(' sql ')' /* checking predicats */
;
%%
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::util;
using namespace ::osl;
using namespace ::dbtools;
// using namespace connectivity;
//============================================================
//= a helper for static ascii pseudo-unicode strings
//============================================================
// string constants
struct _ConstAsciiString_
{
sal_Int32 length;
sal_Char const* str;
operator rtl::OUString () const { return rtl::OUString(str, length, RTL_TEXTENCODING_ASCII_US); }
// operator ::rtl::OUString () const { return ::rtl::OUString(str, length, RTL_TEXTENCODING_ASCII_US); }
operator const sal_Char * () const { return str; }
operator ::rtl::OString() const { return str; }
};
#define IMPLEMENT_CONSTASCII_STRING( name, string ) \
_ConstAsciiString_ const name = { sizeof(string)-1, string }
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_GENERAL, "Syntax error in SQL expression");
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_VALUE_NO_LIKE, "The value #1 can not be used with LIKE.");
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_FIELD_NO_LIKE, "LIKE can not be used with this field.");
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_COMPARE, "The entered criterion can not be compared with this field.");
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_DATE_COMPARE, "The field can not be compared with a date.");
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_REAL_COMPARE, "The field can not be compared with a floating point number.");
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_INT_COMPARE, "The field can not be compared with a number.");
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_TABLE, "The database does not contain a table named \"#\".");
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_TABLE_OR_QUERY, "The database does contain neither a table nor a query named \"#\".");
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_COLUMN, "The column \"#1\" is unknown in the table \"#2\".");
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_TABLE_EXIST, "The database already contains a table or view with name \"#\".");
IMPLEMENT_CONSTASCII_STRING(ERROR_STR_INVALID_QUERY_EXIST, "The database already contains a query with name \"#\".");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_LIKE, "LIKE");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_NOT, "NOT");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_NULL, "NULL");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_TRUE, "True");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_FALSE, "False");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_IS, "IS");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_BETWEEN, "BETWEEN");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_OR, "OR");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_AND, "AND");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_AVG, "AVG");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_COUNT, "COUNT");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_MAX, "MAX");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_MIN, "MIN");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_SUM, "SUM");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_EVERY, "EVERY");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_ANY, "ANY");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_SOME, "SOME");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_STDDEV_POP, "STDDEV_POP");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_STDDEV_SAMP, "STDDEV_SAMP");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_VAR_SAMP, "VAR_SAMP");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_VAR_POP, "VAR_POP");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_COLLECT, "COLLECT");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_FUSION, "FUSION");
IMPLEMENT_CONSTASCII_STRING(KEY_STR_INTERSECTION, "INTERSECTION");
IMPLEMENT_CONSTASCII_STRING(FIELD_STR_NULLDATE, "NullDate");
IMPLEMENT_CONSTASCII_STRING(STR_SQL_TOKEN, "SQL_TOKEN_");
//==========================================================================
//= OParseContext
//==========================================================================
//-----------------------------------------------------------------------------
OParseContext::OParseContext()
{
}
//-----------------------------------------------------------------------------
OParseContext::~OParseContext()
{
}
//-----------------------------------------------------------------------------
::rtl::OUString OParseContext::getErrorMessage(ErrorCode _eCode) const
{
::rtl::OUString aMsg;
switch (_eCode)
{
case ERROR_GENERAL: aMsg = ERROR_STR_GENERAL; break;
case ERROR_VALUE_NO_LIKE: aMsg = ERROR_STR_VALUE_NO_LIKE; break;
case ERROR_FIELD_NO_LIKE: aMsg = ERROR_STR_FIELD_NO_LIKE; break;
case ERROR_INVALID_COMPARE: aMsg = ERROR_STR_INVALID_COMPARE; break;
case ERROR_INVALID_INT_COMPARE: aMsg = ERROR_STR_INVALID_INT_COMPARE; break;
case ERROR_INVALID_DATE_COMPARE: aMsg = ERROR_STR_INVALID_DATE_COMPARE; break;
case ERROR_INVALID_REAL_COMPARE: aMsg = ERROR_STR_INVALID_REAL_COMPARE; break;
case ERROR_INVALID_TABLE: aMsg = ERROR_STR_INVALID_TABLE; break;
case ERROR_INVALID_TABLE_OR_QUERY: aMsg = ERROR_STR_INVALID_TABLE_OR_QUERY; break;
case ERROR_INVALID_COLUMN: aMsg = ERROR_STR_INVALID_COLUMN; break;
case ERROR_INVALID_TABLE_EXIST: aMsg = ERROR_STR_INVALID_TABLE_EXIST; break;
case ERROR_INVALID_QUERY_EXIST: aMsg = ERROR_STR_INVALID_QUERY_EXIST; break;
default:
OSL_ENSURE( false, "OParseContext::getErrorMessage: unknown error code!" );
break;
}
return aMsg;
}
//-----------------------------------------------------------------------------
::rtl::OString OParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
{
::rtl::OString aKeyword;
switch (_eKey)
{
case KEY_LIKE: aKeyword = KEY_STR_LIKE; break;
case KEY_NOT: aKeyword = KEY_STR_NOT; break;
case KEY_NULL: aKeyword = KEY_STR_NULL; break;
case KEY_TRUE: aKeyword = KEY_STR_TRUE; break;
case KEY_FALSE: aKeyword = KEY_STR_FALSE; break;
case KEY_IS: aKeyword = KEY_STR_IS; break;
case KEY_BETWEEN: aKeyword = KEY_STR_BETWEEN; break;
case KEY_OR: aKeyword = KEY_STR_OR; break;
case KEY_AND: aKeyword = KEY_STR_AND; break;
case KEY_AVG: aKeyword = KEY_STR_AVG; break;
case KEY_COUNT: aKeyword = KEY_STR_COUNT; break;
case KEY_MAX: aKeyword = KEY_STR_MAX; break;
case KEY_MIN: aKeyword = KEY_STR_MIN; break;
case KEY_SUM: aKeyword = KEY_STR_SUM; break;
case KEY_EVERY: aKeyword = KEY_STR_EVERY; break;
case KEY_ANY: aKeyword = KEY_STR_ANY; break;
case KEY_SOME: aKeyword = KEY_STR_SOME; break;
case KEY_STDDEV_POP: aKeyword = KEY_STR_STDDEV_POP; break;
case KEY_STDDEV_SAMP: aKeyword = KEY_STR_STDDEV_SAMP; break;
case KEY_VAR_SAMP: aKeyword = KEY_STR_VAR_SAMP; break;
case KEY_VAR_POP: aKeyword = KEY_STR_VAR_POP; break;
case KEY_COLLECT: aKeyword = KEY_STR_COLLECT; break;
case KEY_FUSION: aKeyword = KEY_STR_FUSION; break;
case KEY_INTERSECTION:aKeyword = KEY_STR_INTERSECTION; break;
case KEY_NONE: break;
default:
OSL_ENSURE( false, "OParseContext::getIntlKeywordAscii: unknown key!" );
break;
}
return aKeyword;
}
//-----------------------------------------------------------------------------
IParseContext::InternationalKeyCode OParseContext::getIntlKeyCode(const ::rtl::OString& rToken) const
{
static IParseContext::InternationalKeyCode Intl_TokenID[] =
{
KEY_LIKE, KEY_NOT, KEY_NULL, KEY_TRUE,
KEY_FALSE, KEY_IS, KEY_BETWEEN, KEY_OR,
KEY_AND, KEY_AVG, KEY_COUNT, KEY_MAX,
KEY_MIN, KEY_SUM, KEY_EVERY,KEY_ANY,KEY_SOME,
KEY_STDDEV_POP,KEY_STDDEV_SAMP,KEY_VAR_SAMP,
KEY_VAR_POP,KEY_COLLECT,KEY_FUSION,KEY_INTERSECTION
};
sal_uInt32 nCount = sizeof Intl_TokenID / sizeof Intl_TokenID[0];
for (sal_uInt32 i = 0; i < nCount; i++)
{
::rtl::OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
if (rToken.equalsIgnoreAsciiCase(aKey))
return Intl_TokenID[i];
}
return KEY_NONE;
}
//------------------------------------------------------------------------------
static Locale& impl_getLocaleInstance( )
{
static Locale s_aLocale(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "en" ) ),
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "US" ) ),
::rtl::OUString( )
);
return s_aLocale;
}
//------------------------------------------------------------------------------
void OParseContext::setDefaultLocale( const ::com::sun::star::lang::Locale& _rLocale )
{
impl_getLocaleInstance() = _rLocale;
}
//------------------------------------------------------------------------------
Locale OParseContext::getPreferredLocale( ) const
{
return getDefaultLocale();
}
//------------------------------------------------------------------------------
const Locale& OParseContext::getDefaultLocale()
{
return impl_getLocaleInstance();
}
//==========================================================================
//= misc
//==========================================================================
// Der (leider globale) yylval fuer die Uebergabe von
// Werten vom Scanner an den Parser. Die globale Variable
// wird nur kurzzeitig verwendet, der Parser liest die Variable
// sofort nach dem Scanner-Aufruf in eine gleichnamige eigene
// Member-Variable.
const double fMilliSecondsPerDay = 86400000.0;
//------------------------------------------------------------------------------
//------------------------------------------------------------------
::rtl::OUString ConvertLikeToken(const OSQLParseNode* pTokenNode, const OSQLParseNode* pEscapeNode, sal_Bool bInternational)
{
::rtl::OUStringBuffer aMatchStr;
if (pTokenNode->isToken())
{
sal_Unicode cEscape = 0;
if (pEscapeNode->count())
cEscape = pEscapeNode->getChild(1)->getTokenValue().toChar();
// Platzhalter austauschen
aMatchStr = pTokenNode->getTokenValue();
const sal_Int32 nLen = aMatchStr.getLength();
::rtl::OUStringBuffer sSearch,sReplace;
if ( bInternational )
{
sSearch.appendAscii("%_",2);
sReplace.appendAscii("*?",2);
}
else
{
sSearch.appendAscii("*?",2);
sReplace.appendAscii("%_",2);
}
for (sal_Int32 i = 0; i < nLen; i++)
{
const sal_Unicode c = aMatchStr.charAt(i);
if (c == sSearch.charAt(0) || c == sSearch.charAt(1))
{
if (i > 0 && aMatchStr.charAt(i-1) == cEscape)
continue;
else
{
const sal_Unicode cCharacter = sReplace.charAt( (c == sSearch.charAt(0)) ? 0 : 1);
aMatchStr.setCharAt(i , cCharacter);
}
}
}
}
return aMatchStr.makeStringAndClear();
}
//==========================================================================
//= OSQLParser
//==========================================================================
sal_uInt32 OSQLParser::s_nRuleIDs[OSQLParseNode::rule_count + 1];
OSQLParser::RuleIDMap OSQLParser::s_aReverseRuleIDLookup;
OParseContext OSQLParser::s_aDefaultContext;
sal_Int32 OSQLParser::s_nRefCount = 0;
// ::osl::Mutex OSQLParser::s_aMutex;
OSQLScanner* OSQLParser::s_pScanner = 0;
OSQLParseNodesGarbageCollector* OSQLParser::s_pGarbageCollector = 0;
::com::sun::star::uno::Reference< ::com::sun::star::i18n::XLocaleData> OSQLParser::s_xLocaleData = NULL;
//-----------------------------------------------------------------------------
void setParser(OSQLParser* _pParser)
{
xxx_pGLOBAL_SQLPARSER = _pParser;
}
// -------------------------------------------------------------------------
void OSQLParser::setParseTree(OSQLParseNode * pNewParseTree)
{
::osl::MutexGuard aGuard(getMutex());
m_pParseTree = pNewParseTree;
}
//-----------------------------------------------------------------------------
OSQLParseNode* OSQLParser::parseTree(::rtl::OUString& rErrorMessage,
const ::rtl::OUString& rStatement,
sal_Bool bInternational)
{
// Guard the parsing
::osl::MutexGuard aGuard(getMutex());
// must be reset
setParser(this);
// defines how to scan
s_pScanner->SetRule(s_pScanner->GetSQLRule()); // initial
s_pScanner->prepareScan(rStatement, m_pContext, bInternational);
SQLyylval.pParseNode = NULL;
// SQLyypvt = NULL;
m_pParseTree = NULL;
m_sErrorMessage = ::rtl::OUString();
// ... und den Parser anwerfen ...
if (SQLyyparse() != 0)
{
// only set the error message, if it's not already set
if (!m_sErrorMessage.getLength())
m_sErrorMessage = s_pScanner->getErrorMessage();
if (!m_sErrorMessage.getLength())
m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_GENERAL);
rErrorMessage = m_sErrorMessage;
// clear the garbage collector
(*s_pGarbageCollector)->clearAndDelete();
return NULL;
}
else
{
(*s_pGarbageCollector)->clear();
// Das Ergebnis liefern (den Root Parse Node):
// OSL_ENSURE(Sdbyyval.pParseNode != NULL,"OSQLParser: Parser hat keinen ParseNode geliefert");
// return Sdbyyval.pParseNode;
// geht nicht wegen Bug in MKS YACC-erzeugtem Code (es wird ein falscher ParseNode
// geliefert).
// Stattdessen setzt die Parse-Routine jetzt den Member pParseTree
// - einfach diesen zurueckliefern:
OSL_ENSURE(m_pParseTree != NULL,"OSQLParser: Parser hat keinen ParseTree geliefert");
return m_pParseTree;
}
}
//-----------------------------------------------------------------------------
::rtl::OString OSQLParser::TokenIDToStr(sal_uInt32 nTokenID, const IParseContext* pContext)
{
::rtl::OString aStr;
if (pContext)
{
IParseContext::InternationalKeyCode eKeyCode = IParseContext::KEY_NONE;
switch( nTokenID )
{
case SQL_TOKEN_LIKE: eKeyCode = IParseContext::KEY_LIKE; break;
case SQL_TOKEN_NOT: eKeyCode = IParseContext::KEY_NOT; break;
case SQL_TOKEN_NULL: eKeyCode = IParseContext::KEY_NULL; break;
case SQL_TOKEN_TRUE: eKeyCode = IParseContext::KEY_TRUE; break;
case SQL_TOKEN_FALSE: eKeyCode = IParseContext::KEY_FALSE; break;
case SQL_TOKEN_IS: eKeyCode = IParseContext::KEY_IS; break;
case SQL_TOKEN_BETWEEN: eKeyCode = IParseContext::KEY_BETWEEN; break;
case SQL_TOKEN_OR: eKeyCode = IParseContext::KEY_OR; break;
case SQL_TOKEN_AND: eKeyCode = IParseContext::KEY_AND; break;
case SQL_TOKEN_AVG: eKeyCode = IParseContext::KEY_AVG; break;
case SQL_TOKEN_COUNT: eKeyCode = IParseContext::KEY_COUNT; break;
case SQL_TOKEN_MAX: eKeyCode = IParseContext::KEY_MAX; break;
case SQL_TOKEN_MIN: eKeyCode = IParseContext::KEY_MIN; break;
case SQL_TOKEN_SUM: eKeyCode = IParseContext::KEY_SUM; break;
}
if ( eKeyCode != IParseContext::KEY_NONE )
aStr = pContext->getIntlKeywordAscii(eKeyCode);
}
if (!aStr.getLength())
{
aStr = yytname[YYTRANSLATE(nTokenID)];
if(!aStr.compareTo("SQL_TOKEN_",10))
aStr = aStr.copy(10);
}
return aStr;
}
//-----------------------------------------------------------------------------
/*sal_uInt32 OSQLParser::StrToTokenID(const ::rtl::OString & rName)
{
::rtl::OString aName;
if (rName.IsAlphaNumericAscii())
aName = rName;
else
{
aName = "'";
aName += rName;
aName += "'";
}
// Gewuenschten Token-Namen suchen:
for (sal_uInt32 i = 0; i < SQLyyntoken; i++)
{
if (aName == TokenTypes[i].name)
return TokenTypes[i].token;
}
// Nicht gefunden
return 0;
}*/
//-----------------------------------------------------------------------------
::rtl::OUString OSQLParser::RuleIDToStr(sal_uInt32 nRuleID)
{
OSL_ENSURE(nRuleID < (sizeof yytname/sizeof yytname[0]), "OSQLParser::RuleIDToStr: Invalid nRuleId!");
return ::rtl::OUString::createFromAscii(yytname[nRuleID]);
}
//-----------------------------------------------------------------------------
sal_uInt32 OSQLParser::StrToRuleID(const ::rtl::OString & rValue)
{
// In yysvar nach dem angegebenen Namen suchen, den Index zurueckliefern
// (oder 0, wenn nicht gefunden)
static sal_uInt32 nLen = sizeof(yytname)/sizeof(yytname[0]);
for (sal_uInt32 i = YYTRANSLATE(SQL_TOKEN_INVALIDSYMBOL); i < (nLen-1); i++)
{
if (yytname && rValue == yytname[i])
return i;
}
// Nicht gefunden
return 0;
}
//-----------------------------------------------------------------------------
OSQLParseNode::Rule OSQLParser::RuleIDToRule( sal_uInt32 _nRule )
{
return s_aReverseRuleIDLookup[ _nRule ];
}
//-----------------------------------------------------------------------------
sal_uInt32 OSQLParser::RuleID(OSQLParseNode::Rule eRule)
{
return s_nRuleIDs[(sal_uInt16)eRule];
}
// -------------------------------------------------------------------------
sal_Int16 OSQLParser::buildNode(OSQLParseNode*& pAppend,OSQLParseNode* pCompare,OSQLParseNode* pLiteral,OSQLParseNode* pLiteral2)
{
OSQLParseNode* pColumnRef = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::column_ref));
pColumnRef->append(new OSQLInternalNode(m_sFieldName,SQL_NODE_NAME));
OSQLParseNode* pComp = NULL;
if ( SQL_ISTOKEN( pCompare, BETWEEN) && pLiteral2 )
pComp = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::between_predicate));
else
pComp = new OSQLInternalNode(aEmptyString, SQL_NODE_RULE,OSQLParser::RuleID(OSQLParseNode::comparison_predicate));
pComp->append(pColumnRef);
pComp->append(pCompare);
pComp->append(pLiteral);
if ( pLiteral2 )
{
pComp->append(new OSQLInternalNode(aEmptyString, SQL_NODE_KEYWORD,SQL_TOKEN_AND));
pComp->append(pLiteral2);
}
pAppend->append(pComp);
return 1;
}
//-----------------------------------------------------------------------------
sal_Int16 OSQLParser::buildStringNodes(OSQLParseNode*& pLiteral)
{
if(!pLiteral)
return 1;
if(SQL_ISRULE(pLiteral,set_fct_spec) || SQL_ISRULE(pLiteral,general_set_fct) || SQL_ISRULE(pLiteral,column_ref)
|| SQL_ISRULE(pLiteral,subquery))
return 1; // here I have a function that I can't transform into a string
if(pLiteral->getNodeType() == SQL_NODE_INTNUM || pLiteral->getNodeType() == SQL_NODE_APPROXNUM || pLiteral->getNodeType() == SQL_NODE_ACCESS_DATE)
{
OSQLParseNode* pParent = pLiteral->getParent();
OSQLParseNode* pNewNode = new OSQLInternalNode(pLiteral->getTokenValue(), SQL_NODE_STRING);
pParent->replace(pLiteral, pNewNode);
delete pLiteral;
pLiteral = NULL;
return 1;
}
for(sal_uInt32 i=0;i<pLiteral->count();++i)
{
OSQLParseNode* pChild = pLiteral->getChild(i);
buildStringNodes(pChild);
}
if(SQL_ISRULE(pLiteral,term) || SQL_ISRULE(pLiteral,value_exp_primary))
{
m_sErrorMessage = m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_COMPARE);
return 0;
}
return 1;
}
//-----------------------------------------------------------------------------
sal_Int16 OSQLParser::buildComparsionRule(OSQLParseNode*& pAppend,OSQLParseNode* pLiteral)
{
OSQLParseNode* pComp = new OSQLInternalNode(::rtl::OUString::createFromAscii("="), SQL_NODE_EQUAL);
return buildPredicateRule(pAppend,pLiteral,pComp);
}
//-----------------------------------------------------------------------------
void OSQLParser::reduceLiteral(OSQLParseNode*& pLiteral, sal_Bool bAppendBlank)
{
OSL_ENSURE(pLiteral->isRule(), "This is no ::com::sun::star::chaos::Rule");
OSL_ENSURE(pLiteral->count() == 2, "OSQLParser::ReduceLiteral() Invalid count");
OSQLParseNode* pTemp = pLiteral;
::rtl::OUString aValue;
if (bAppendBlank)
{
((aValue = pLiteral->getChild(0)->getTokenValue()) += ::rtl::OUString::createFromAscii(" ")) +=
pLiteral->getChild(1)->getTokenValue();
}
else
(aValue = pLiteral->getChild(0)->getTokenValue()) +=
pLiteral->getChild(1)->getTokenValue();
pLiteral = new OSQLInternalNode(aValue,SQL_NODE_STRING);
delete pTemp;
}
// -------------------------------------------------------------------------
void OSQLParser::error(sal_Char *fmt)
{
if(!m_sErrorMessage.getLength())
{
::rtl::OUString sStr(fmt,strlen(fmt),RTL_TEXTENCODING_UTF8);
::rtl::OUString sSQL_TOKEN(::rtl::OUString::createFromAscii("SQL_TOKEN_"));
sal_Int32 nPos1 = sStr.indexOf(sSQL_TOKEN);
if(nPos1 != -1)
{
::rtl::OUString sFirst = sStr.copy(0,nPos1);
sal_Int32 nPos2 = sStr.indexOf(sSQL_TOKEN,nPos1+1);
if(nPos2 != -1)
{
::rtl::OUString sSecond = sStr.copy(nPos1+sSQL_TOKEN.getLength(),nPos2-nPos1-sSQL_TOKEN.getLength());
sFirst += sSecond;
sFirst += sStr.copy(nPos2+sSQL_TOKEN.getLength());
}
else
sFirst += sStr.copy(nPos1+sSQL_TOKEN.getLength());
m_sErrorMessage = sFirst;
}
else
m_sErrorMessage = sStr;
::rtl::OUString aError = s_pScanner->getErrorMessage();
if(aError.getLength())
{
m_sErrorMessage += ::rtl::OUString::createFromAscii(", ");
m_sErrorMessage += aError;
}
}
}
// -------------------------------------------------------------------------
int OSQLParser::SQLlex()
{
return s_pScanner->SQLlex();
}
#if defined __SUNPRO_CC
#pragma enable_warn
#elif defined _MSC_VER
#pragma warning(pop)
#endif
|