summaryrefslogtreecommitdiff
path: root/sql-bench/server-cfg.sh
blob: 892d301c70d03918ae130ac10b9df013988a4d55 (plain)
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
#!/usr/bin/perl
# -*- perl -*-
# Copyright (c) 2000-2006 MySQL AB, 2009 Sun Microsystems, Inc.
# Use is subject to license terms.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; version 2
# of the License.
#
# This library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA
#
# The configuration file for the DBI/DBD tests on different databases ....
# You will need the DBD module for the database you are running.
# Monty made this bench script and I (Luuk de Boer) rewrote it to DBI/DBD.
# Monty rewrote this again to use packages.
#
# Each database has a different package that has 3 functions:
# new		Creates a object with some standard slot
# version	Version number of the server
# create	Generates commands to create a table
#

#
# First some global functions that help use the packages:
#

sub get_server
{
  my ($name,$host,$database,$odbc,$machine,$socket,$connect_options)=@_;
  my ($server);
  if ($name =~ /mysql/i)
  { $server=new db_MySQL($host, $database, $machine, $socket,$connect_options); }
  elsif ($name =~ /pg/i)
  { $server= new db_Pg($host,$database); }
  elsif ($name =~ /msql/i)
  { $server= new db_mSQL($host,$database); }
  elsif ($name =~ /solid/i)
  { $server= new db_Solid($host,$database); }
  elsif ($name =~ /Empress/i)
  { $server= new db_Empress($host,$database); }
  elsif ($name =~ /FrontBase/i)
  { $server= new db_FrontBase($host,$database); }
  elsif ($name =~ /Oracle/i)
  { $server= new db_Oracle($host,$database); }
  elsif ($name =~ /Access/i)
  { $server= new db_access($host,$database); }
  elsif ($name =~ /Informix/i)
  { $server= new db_Informix($host,$database); }
  elsif ($name =~ /ms-sql/i)
  { $server= new db_ms_sql($host,$database); }
  elsif ($name =~ /sybase/i)
  { $server= new db_sybase($host,$database); }
  elsif ($name =~ /Adabas/i)			# Adabas has two drivers
  {
    $server= new db_Adabas($host,$database);
    if ($name =~ /AdabasD/i)
    {
      $server->{'data_source'} =~ s/:Adabas:/:AdabasD:/;
    }
  }
  elsif ($name =~ /DB2/i)
  { $server= new db_db2($host,$database); }
  elsif ($name =~ /Mimer/i)
  { $server= new db_Mimer($host,$database); }
  elsif ($name =~ /Sapdb/i)
  { $server= new db_sapdb($host,$database); }
  elsif ($name =~ /interBase/i)
  { $server= new db_interbase($host,$database); }
  else
  {
      die "Unknown sql server name used: $name\nUse one of: Access, Adabas, AdabasD, Empress, FrontBase, Oracle, Informix, InterBase, DB2, mSQL, Mimer, MS-SQL, MySQL, Pg, Solid, SAPDB or Sybase.\nIf the connection is done trough ODBC the name must end with _ODBC\n";
  }
  if ($name =~ /_ODBC$/i || defined($odbc) && $odbc)
  {
    if (! ($server->{'data_source'} =~ /^([^:]*):([^:]+):([^:]*)/ ))
    {
      die "Can't find databasename in data_source: '" .
	  $server->{'data_source'}. "'\n";
    }
    if ($3) {
      $server->{'data_source'} = "$1:ODBC:$3";
    } else {
      $server->{'data_source'} = "$1:ODBC:$database";
    }
  }
  return $server;
}

sub all_servers
{
  return ["Access", "Adabas", "DB2", "Empress", "FrontBase", "Oracle",
	  "Informix", "InterBase", "Mimer", "mSQL", "MS-SQL", "MySQL", "Pg","SAPDB",
	  "Solid", "Sybase"];
}

#############################################################################
#	     First the configuration for MySQL off course :-)
#############################################################################

package db_MySQL;

sub new
{
  my ($type,$host,$database,$machine,$socket,$connect_options)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "mysql";
  $self->{'data_source'}	= "DBI:mysql:database=$database;host=$host";
  $self->{'data_source'} .= ";mysql_socket=$socket" if($socket);
  $self->{'data_source'} .= ";$connect_options" if($connect_options);
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "blob";
  $self->{'text'}		= "text";
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'vacuum'}		= 1; # When using with --fast
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 0; # Transactions disabled by default

  $limits{'NEG'}		= 1; # Supports -id
  $limits{'alter_add_multi_col'}= 1; #Have ALTER TABLE t add a int,add b int;
  $limits{'alter_table'}	= 1; # Have ALTER TABLE
  $limits{'alter_table_dropcol'}= 1; # Have ALTER TABLE DROP column
  $limits{'column_alias'}	= 1; # Alias for fields in select statement.
  $limits{'func_extra_%'}	= 1; # Has % as alias for mod()
  $limits{'func_extra_if'}	= 1; # Have function if.
  $limits{'func_extra_in_num'}	= 1; # Has function in
  $limits{'func_odbc_floor'}	= 1; # Has func_odbc_floor function
  $limits{'func_odbc_mod'}	= 1; # Have function mod.
  $limits{'functions'}		= 1; # Has simple functions (+/-)
  $limits{'group_by_position'}  = 1; # Can use 'GROUP BY 1'
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'group_func_extra_std'} = 1; # Have group function std().
  $limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
  $limits{'group_functions'}	= 1; # Have group functions
  $limits{'having_with_alias'}  = 1; # Can use aliases in HAVING
  $limits{'having_with_group'}	= 1; # Can use group functions in HAVING
  $limits{'insert_multi_value'} = 1; # Have INSERT ... values (1,2),(3,4)
  $limits{'insert_select'}	= 1;
  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables
  $limits{'left_outer_join'}	= 1; # Supports left outer joins
  $limits{'like_with_column'}	= 1; # Can use column1 LIKE column2
  $limits{'limit'}		= 1; # supports the limit attribute
  $limits{'truncate_table'}	= 1;
  $limits{'load_data_infile'}	= 1; # Has load data infile
  $limits{'lock_tables'}	= 1; # Has lock tables
  $limits{'max_column_name'}	= 64; # max table and column name
  $limits{'max_columns'}	= 2000;	# Max number of columns in table
  $limits{'max_conditions'}	= 9999; # (Actually not a limit)
  $limits{'max_index'}		= 16; # Max number of keys
  $limits{'max_index_parts'}	= 16; # Max segments/key
  $limits{'max_tables'}		= (($machine || '') =~ "^win") ? 5000 : 65000;
  $limits{'max_temporary_tables'}= 400;
  $limits{'max_text_size'}	= 1000000; # Good enough for tests
  $limits{'multi_drop'}		= 1; # Drop table can take many tables
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1'
  $limits{'order_by_unused'}	= 1;
  $limits{'query_size'}		= 1000000; # Max size with default buffers.
  $limits{'select_without_from'}= 1; # Can do 'select 1';
  $limits{'subqueries'}		= 0; # Doesn't support sub-queries.
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'working_all_fields'} = 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 

  # Some fixes that depends on the environment
  if (defined($main::opt_create_options) &&
      $main::opt_create_options =~ /engine=heap/i)
  {
    $limits{'working_blobs'}	= 0; # HEAP tables can't handle BLOB's
  }
  # HEAP is deprecated in favor of MEMORY
  if (defined($main::opt_create_options) &&
      $main::opt_create_options =~ /engine=memory/i)
  {
    $limits{'working_blobs'}	= 0; # MEMORY tables can't handle BLOB's
  }
  if (defined($main::opt_create_options) &&
      $main::opt_create_options =~ /engine=innodb/i)
  {
    $self->{'transactions'}	= 1;	# Transactions enabled
  }
  if (defined($main::opt_create_options) &&
      $main::opt_create_options =~ /engine=bdb/i)
  {
    $self->{'transactions'}	= 1;	# Transactions enabled
  }
  if (defined($main::opt_create_options) &&
      $main::opt_create_options =~ /engine=gemini/i)
  {
    $limits{'working_blobs'}	= 0; # Blobs not implemented yet
    $limits{'max_tables'}	= 500;
    $limits{'max_temporary_tables'}= $limits{"max_tables"};
    $self->{'transactions'}	= 1;	# Transactions enabled
  }

  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  my ($dbh,$sth,$version,@row);

  $dbh=$self->connect();
  $sth = $dbh->prepare("select VERSION()") or die $DBI::errstr;
  $version="MySQL 3.20.?";
  if ($sth->execute && (@row = $sth->fetchrow_array))
  {
    $row[0] =~ s/-/ /g;			# To get better tables with long names
    $version="MySQL $row[0]";
  }
  $sth->finish;

  $sth = $dbh->prepare("show status like 'ssl_version'") or die $DBI::errstr;
  if ($sth->execute && (@row = $sth->fetchrow_array) && $row[1])
  {
    $version .= "/$row[1]";
  }
  $sth->finish;
  $dbh->disconnect;
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}

#
# Connection with optional disabling of logging
#

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";

  $dbh->do("SET OPTION LOG_OFF=1,UPDATE_LOG=0");
  if ($main::opt_connect_command ne "")
  {
    $dbh->do($main::opt_connect_command) or
      die "Can't execute connect_command: $main::opt_connect_command  error: $DBI::errstr\n";
  }
  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#
# If one uses $main::opt_fast then one is allowed to use
# non standard types to get better speed.
#

sub create
{
  my($self,$table_name,$fields,$index,$options) = @_;
  my($query,@queries);

  if ($main::opt_temporary_tables)
  {
    $query="create temporary table $table_name (";
  }
  else
  {
    $query="create table $table_name (";
  }
  foreach $field (@$fields)
  {
#    $field =~ s/ decimal/ double(10,2)/i;
    $field =~ s/ big_decimal/ double(10,2)/i;
    $query.= $field . ',';
  }
  foreach $index (@$index)
  {
    $query.= $index . ',';
  }
  substr($query,-1)=")";		# Remove last ',';
  $query.=" $options" if (defined($options));
  $query.=" $main::opt_create_options" if (defined($main::opt_create_options));
  push(@queries,$query);
  return @queries;
}

sub insert_file {
  my ($self,$dbname, $file, $dbh) = @_;
  my ($command, $sth);

  $file =~ s|\\|/|g;			# Change Win32 names to Unix syntax
  $command = "load data infile '$file' into table $dbname columns optionally enclosed by '\\'' terminated by ','";
#  print "$command\n";
  $sth = $dbh->do($command) or die $DBI::errstr;
  return $sth;			# Contains number of rows
}

#
# Do any conversions to the ANSI SQL query so that the database can handle it
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub drop_index {
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index ON $table";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 0;
}

#
# This should return 1 if we to do disconnect / connect when doing
# big batches
#

sub small_rollback_segment
{
  return 0;
}

#
# reconnect on errors (needed mainly be crash-me)
#

sub reconnect_on_errors
{
  return 0;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

#
# Optimize tables for better performance
#

sub vacuum
{
  my ($self,$full_vacuum,$dbh_ref,@tables)=@_;
  my ($loop_time,$end_time,$dbh);
  if ($#tables >= 0)
  {
    $dbh=$$dbh_ref;
    $loop_time=new Benchmark;
    $dbh->do("OPTIMIZE TABLE " . join(',',@tables)) || die "Got error: $DBI::errstr when executing 'OPTIMIZE TABLE'\n";
    $end_time=new Benchmark;
    print "Time for book-keeping (1): " .
      Benchmark::timestr(Benchmark::timediff($end_time, $loop_time),"all") . "\n\n";
  }
}

#############################################################################
#		     Definitions for mSQL
#############################################################################

package db_mSQL;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "msql";
  $self->{'data_source'}	= "DBI:mSQL:$database:$host";
  $self->{'limits'}		= \%limits;
  $self->{'double_quotes'}	= 0;
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 0;  # No transactions
  $self->{'blob'}		= "text(" . $limits{'max_text_size'} .")";
  $self->{'text'}		= "text(" . $limits{'max_text_size'} .")";

  $limits{'max_conditions'}	= 74;
  $limits{'max_columns'}	= 75;
  $limits{'max_tables'}		= 65000;	# Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};
  $limits{'max_text_size'}	= 32000;
  $limits{'query_size'}		= 65535;
  $limits{'max_index'}		= 5;
  $limits{'max_index_parts'}	= 10;
  $limits{'max_column_name'} = 35;

  $limits{'join_optimizer'}	= 0;		# Can't optimize FROM tables
  $limits{'load_data_infile'}	= 0;
  $limits{'lock_tables'}	= 0;
  $limits{'functions'}		= 0;
  $limits{'group_functions'}	= 0;
  $limits{'group_distinct_functions'}= 0;	 # Have count(distinct)
  $limits{'multi_drop'}		= 0;
  $limits{'select_without_from'}= 0;
  $limits{'subqueries'}		= 0;
  $limits{'left_outer_join'}	= 0;
  $limits{'table_wildcard'}	= 0;
  $limits{'having_with_alias'}  = 0;
  $limits{'having_with_group'}	= 0;
  $limits{'like_with_column'}	= 1;
  $limits{'order_by_position'}  = 1;
  $limits{'group_by_position'}  = 1;
  $limits{'alter_table'}	= 0;
  $limits{'alter_add_multi_col'}= 0;
  $limits{'alter_table_dropcol'}= 0;
  $limits{'group_func_extra_std'} = 0;
  $limits{'limit'}		= 1;		# supports the limit attribute
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'insert_select'}	= 0;

  $limits{'func_odbc_mod'}	= 0;
  $limits{'func_extra_%'}	= 0;
  $limits{'func_odbc_floor'}	= 0;
  $limits{'func_extra_if'}	= 0;
  $limits{'column_alias'}	= 0;
  $limits{'NEG'}		= 0;
  $limits{'func_extra_in_num'}	= 0;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 1;
  $limits{'working_all_fields'} = 1;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 
  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($tmp,$dir);
  foreach $dir ("/usr/local/Hughes", "/usr/local/mSQL","/my/local/mSQL",
		"/usr/local")
  {
    if (-x "$dir/bin/msqladmin")
    {
      $tmp=`$dir/bin/msqladmin version | grep server`;
      if ($tmp =~ /^\s*(.*\w)\s*$/)
      {				# Strip pre- and endspace
	$tmp=$1;
	$tmp =~ s/\s+/ /g;	# Remove unnecessary spaces
	$tmp .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);

	return $tmp;
      }
    }
  }
  return "mSQL version ???";
}


sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  return $dbh;
}

#
# Can't handle many field types, so we map everything to int and real.
#

sub create
{
  my($self,$table_name,$fields,$index) = @_;
  my($query,@queries,$name,$nr);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    $field =~ s/varchar/char/i;		# mSQL doesn't have VARCHAR()
    # mSQL can't handle more than the real basic int types
    $field =~ s/tinyint|smallint|mediumint|integer/int/i;
    # mSQL can't handle different visual lengths
    $field =~ s/int\(\d*\)/int/i;
    # mSQL doesn't have float, change it to real
    $field =~ s/float(\(\d*,\d*\)){0,1}/real/i;
    $field =~ s/double(\(\d*,\d*\)){0,1}/real/i;
    # mSQL doesn't have blob, it has text instead
    if ($field =~ / blob/i)
    {
      $name=$self->{'blob'};
      $field =~ s/ blob/ $name/;
    }
    $query.= $field . ',';
  }
  substr($query,-1)=")";		# Remove last ',';
  push(@queries,$query);
  $nr=0;

  # Prepend table_name to index name because the the name may clash with
  # a field name. (Should be diffent name space, but this is mSQL...)

  foreach $index (@$index)
  {
    # Primary key is unique index in mSQL
    $index =~ s/primary key/unique index primary/i;
    if ($index =~ /^unique\s*\(([^\(]*)\)$/i)
    {
      $nr++;
      push(@queries,"create unique index ${table_name}_$nr on $table_name ($1)");
    }
    else
    {
      if (!($index =~ /^(.*index)\s+(\w*)\s+(\(.*\))$/i))
      {
	die "Can't parse index information in '$index'\n";
      }
      push(@queries,"create $1 ${table_name}_$2 on $table_name $3");
    }
  }
  return @queries;
}


sub insert_file {
  my($self,$dbname, $file) = @_;
  print "insert an ascii file isn't supported by mSQL\n";
  return 0;
}


sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub drop_index
{
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index FROM $table";
}

sub abort_if_fatal_error
{
  return 0;
}

sub small_rollback_segment
{
  return 0;
}

sub reconnect_on_errors
{
  return 0;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

#############################################################################
#		     Definitions for PostgreSQL				    #
#############################################################################

package db_Pg;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "pg";
  $self->{'data_source'}	= "DBI:Pg:dbname=$database";
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "text";
  $self->{'text'}		= "text";
  $self->{'double_quotes'}	= 1;
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled
  $self->{"vacuum"}		= 1;
  $limits{'join_optimizer'}	= 1;		# Can optimize FROM tables
  $limits{'load_data_infile'}	= 0;

  $limits{'NEG'}		= 1;
  $limits{'alter_add_multi_col'}= 0;		# alter_add_multi_col ?
  $limits{'alter_table'}	= 1;
  $limits{'alter_table_dropcol'}= 0;
  $limits{'column_alias'}	= 1;
  $limits{'func_extra_%'}	= 1;
  $limits{'func_extra_if'}	= 0;
  $limits{'func_extra_in_num'}	= 1;
  $limits{'func_odbc_floor'}	= 1;
  $limits{'func_odbc_mod'}	= 1;		# Has %
  $limits{'functions'}		= 1;
  $limits{'group_by_position'}  = 1;
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'group_func_extra_std'} = 0;
  $limits{'group_func_sql_min_str'}= 1; # Can execute MIN() and MAX() on strings
  $limits{'group_functions'}	= 1;
  $limits{'having_with_alias'}  = 0;
  $limits{'having_with_group'}	= 1;
  $limits{'insert_select'}	= 1;
  $limits{'left_outer_join'}	= 1;
  $limits{'like_with_column'}	= 1;
  $limits{'lock_tables'}	= 0;		# in ATIS gives this a problem
  $limits{'max_column_name'} 	= 128;
  $limits{'max_columns'}	= 1000;		# 500 crashes pg 6.3
  $limits{'max_conditions'}	= 9999;		# This makes Pg real slow
  $limits{'max_index'}		= 64;		# Big enough
  $limits{'max_index_parts'}	= 16;
  $limits{'max_tables'}		= 65000;
  $limits{'max_temporary_tables'}= $limits{"max_tables"};

  $limits{'max_text_size'}	= 65000;	# Good enough for test
  $limits{'multi_drop'}		= 1;
  $limits{'order_by_position'}  = 1;
  $limits{'order_by_unused'}	= 1;
  $limits{'query_size'}		= 16777216;
  $limits{'select_without_from'}= 1;
  $limits{'subqueries'}		= 1;
  $limits{'table_wildcard'}	= 1;
  $limits{'truncate_table'}	= 1;
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'working_all_fields'} = 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 

  return $self;
}

# couldn't find the option to get the version number

sub version
{
  my ($version,$dir);
  $version = "PostgreSQL version ???";
  foreach $dir ($ENV{'PGDATA'},"/usr/local/pgsql/data", "/usr/local/pg/data")
  {
    if ($dir && -e "$dir/PG_VERSION")
    {
      $version= `cat $dir/PG_VERSION`;
      if ($? == 0)
      {
	chomp($version);
	$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
	return "PostgreSQL $version";
      }
    }
  }
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}


sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  return $dbh;
}


sub create
{
  my($self,$table_name,$fields,$index) = @_;
  my($query,@queries,$name,$in,$indfield,$table,$nr);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    if ($main::opt_fast)
    {
      # Allow use of char2, char4, char8 or char16
      $field =~ s/char(2|4|8|16)/char$1/;
    }
    # Pg can't handle more than the real basic int types
    $field =~ s/tinyint|smallint|mediumint|integer/int/;
    # Pg can't handle different visual lengths
    $field =~ s/int\(\d*\)/int/;
    $field =~ s/float\(\d*,\d*\)/float/;
    $field =~ s/ double/ float/;
#    $field =~ s/ decimal/ float/i;
#    $field =~ s/ big_decimal/ float/i;
#    $field =~ s/ date/ int/i;
    # Pg doesn't have blob, it has text instead
    $field =~ s/ blob/ text/;
    $query.= $field . ',';
  }
  substr($query,-1)=")";		# Remove last ',';
  push(@queries,$query);
  foreach $index (@$index)
  {
    $index =~ s/primary key/unique index primary_key/i;
    if ($index =~ /^unique.*\(([^\(]*)\)$/i)
    {
      # original: $indfield="using btree (" .$1.")";
      # using btree doesn´t seem to work with Postgres anymore; it creates
      # the table and adds the index, but it isn´t unique
      $indfield=" (" .$1.")";	
      $in="unique index";
      $table="index_$nr"; $nr++;
    }
    elsif ($index =~ /^(.*index)\s+(\w*)\s+(\(.*\))$/i)
    {
      # original: $indfield="using btree (" .$1.")";
      $indfield=" " .$3;
      $in="index";
      $table="index_$nr"; $nr++;
    }
    else
    {
      die "Can't parse index information in '$index'\n";
    }
    push(@queries,"create $in ${table_name}_$table on $table_name $indfield");
  }
  $queries[0]=$query;
  return @queries;
}

sub insert_file {
  my ($self,$dbname, $file, $dbh) = @_;
  my ($command, $sth);

# Syntax:
# copy [binary] <class_name> [with oids]
#      {to|from} {<filename>|stdin|stdout} [using delimiters <delim>]
  print "The ascii files aren't correct for postgres ....!!!\n";
  $command = "copy $dbname from '$file' using delimiters ','";
  print "$command\n";
  $sth = $dbh->do($command) or die $DBI::errstr;
  return $sth;
}

#
# As postgreSQL wants A % B instead of standard mod(A,B) we have to map
# This will not handle all cases, but as the benchmarks doesn't use functions
# inside MOD() the following should work
#
# PostgreSQL cant handle count(*) or even count(1), but it can handle
# count(1+1) sometimes. ==> this is solved in PostgreSQL 6.3
#
# PostgreSQL 6.5 is supporting MOD.

sub query {
  my($self,$sql) = @_;
  my(@select,$change);
# if you use PostgreSQL 6.x and x is lower as 5 then uncomment the line below.
#  $sql =~ s/mod\(([^,]*),([^\)]*)\)/\($1 % $2\)/gi;
#
# if you use PostgreSQL 6.1.x uncomment the lines below
#  if ($sql =~ /select\s+count\(\*\)\s+from/i) {
#  }
#  elsif ($sql =~ /count\(\*\)/i)
#  {
#    if ($sql =~ /select\s+(.*)\s+from/i)
#    {
#      @select = split(/,/,$1);
#      if ($select[0] =~ /(.*)\s+as\s+\w+$/i)
#      {
# 	$change = $1;
#      }
#      else
#      {
#	$change = $select[0];
#      }
#    }
#    if (($change =~ /count/i) || ($change eq "")) {
#      $change = "1+1";
#    }
#    $sql =~ s/count\(\*\)/count($change)/gi;
#  }
# till here.
  return $sql;
}

sub drop_index
{
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index";
}

sub abort_if_fatal_error
{
  return 1 if ($DBI::errstr =~ /sent to backend, but backend closed/i);
  return 0;
}

sub small_rollback_segment
{
  return 0;
}

sub reconnect_on_errors
{
  return 0;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

sub vacuum
{
  my ($self,$full_vacuum,$dbh_ref,@tables)=@_;
  my ($loop_time,$end_time,$dbh,$table);
  if (defined($full_vacuum))
  {
    $$dbh_ref->disconnect;  $$dbh_ref= $self->connect();
  }
  $dbh=$$dbh_ref;
  $loop_time=new Benchmark;
  if ($#tables >= 0)
  {
    foreach $table (@tables)
    {
      $dbh->do("vacuum analyze $table") || die "Got error: $DBI::errstr when executing 'vacuum analyze $table'\n";
      $dbh->do("vacuum $table") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
    }
  }
  else
  {
#    $dbh->do("vacuum pg_attributes") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
#    $dbh->do("vacuum pg_index") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
    $dbh->do("vacuum analyze") || die "Got error: $DBI::errstr when executing 'vacuum analyze'\n";
    $dbh->do("vacuum") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
  }
  $end_time=new Benchmark;
  print "Time for book-keeping (1): " .
  Benchmark::timestr(Benchmark::timediff($end_time, $loop_time),"all") . "\n\n";
  $dbh->disconnect;  $$dbh_ref= $self->connect();
}


#############################################################################
#		     Definitions for Solid
#############################################################################

package db_Solid;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "solid";
  $self->{'data_source'}	= "DBI:Solid:";
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "long varchar";
  $self->{'text'}		= "long varchar";
  $self->{'double_quotes'}	= 1;
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled

  $limits{'max_conditions'}	= 9999;		# Probably big enough
  $limits{'max_columns'}	= 2000;		# From crash-me
  $limits{'max_tables'}		= 65000;	# Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};

  $limits{'max_text_size'}	= 65492;	# According to tests
  $limits{'query_size'}		= 65535;	# Probably a limit
  $limits{'max_index'}		= 64;		# Probably big enough
  $limits{'max_index_parts'}	= 64;
  $limits{'max_column_name'} = 80;

  $limits{'join_optimizer'}	= 1;
  $limits{'load_data_infile'}	= 0;
  $limits{'lock_tables'}	= 0;
  $limits{'functions'}		= 1;
  $limits{'group_functions'}	= 1;
  $limits{'group_func_sql_min_str'}	= 1; # Can execute MIN() and MAX() on strings
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'select_without_from'}= 0;		# Can do 'select 1' ?;
  $limits{'multi_drop'}		= 0;
  $limits{'subqueries'}		= 1;
  $limits{'left_outer_join'}	= 1;
  $limits{'table_wildcard'}	= 1;
  $limits{'having_with_alias'}  = 0;
  $limits{'having_with_group'}	= 1;
  $limits{'like_with_column'}	= 1;
  $limits{'order_by_position'}  = 0;		# 2.30.0018 can this
  $limits{'group_by_position'}  = 0;
  $limits{'alter_table'}	= 1;
  $limits{'alter_add_multi_col'}= 0;
  $limits{'alter_table_dropcol'}= 0;

  $limits{'group_func_extra_std'}	= 0;	# Have group function std().

  $limits{'func_odbc_mod'}	= 1;
  $limits{'func_extra_%'}	= 0;
  $limits{'func_odbc_floor'}	= 1;
  $limits{'column_alias'}	= 1;
  $limits{'NEG'}		= 1;
  $limits{'func_extra_in_num'}	= 1;
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'insert_select'}	= 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 1;
  $limits{'working_all_fields'} = 1;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 

  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($version,$dir);
  $version="Solid version ??";
  foreach $dir ($ENV{'SOLIDDIR'},"/usr/local/solid", "/my/local/solid")
  {
    if ($dir && -e "$dir/bin/solcon")
    {
      $version=`$dir/bin/solcon -e"ver" $main::opt_user $main::opt_password | grep Server | sed q`;
      if ($? == 0)
      {
	chomp($version);
	$version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
	return $version;
      }
    }
  }
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#

sub create
{
  my($self,$table_name,$fields,$index) = @_;
  my($query,@queries,$nr);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    $field =~ s/mediumint/integer/i;
    $field =~ s/ double/ float/i;
    # Solid doesn't have blob, it has long varchar
    $field =~ s/ blob/ long varchar/;
#    $field =~ s/ decimal/ float/i;
#    $field =~ s/ big_decimal/ float/i;
#    $field =~ s/ date/ int/i;
    $query.= $field . ',';
  }
  substr($query,-1)=")";		# Remove last ',';
  push(@queries,$query);
  $nr=0;
  foreach $index (@$index)
  {
    if ($index =~ /^primary key/i || $index =~ /^unique/i)
    {					# Add to create statement
      substr($queries[0],-1,0)="," . $index;
    }
    else
    {
      $index =~ /^(.*)\s+(\(.*\))$/;
      push(@queries,"create ${1}$nr on $table_name $2");
      $nr++;
    }
  }
  return @queries;
}

# there is no sql statement in solid which can do the load from
# an ascii file in the db ... but there is the speedloader program
# an external program which can load the ascii file in the db ...
# the server must be down before using speedloader !!!!
# (in the standalone version)
# it works also with a control file ... that one must be made ....
sub insert_file {
  my ($self, $dbname, $file) = @_;
  my ($speedcmd);
  $speedcmd = '/usr/local/solid/bin/solload';
  print "At this moment not supported - solid server must go down \n";
  return 0;
}

# solid can't handle an alias in a having statement so
# select test as foo from tmp group by foo having foor > 2
# becomes
# select test as foo from tmp group by foo having test > 2
#
sub query {
  my($self,$sql) = @_;
  my(@select,$tmp,$newhaving,$key,%change);

  if ($sql =~ /having\s+/i)
  {
    if ($sql =~ /select (.*) from/i)
    {
      (@select) = split(/,\s*/, $1);
      foreach $tmp (@select)
      {
	if ($tmp =~ /(.*)\s+as\s+(\w+)/)
	{
	  $change{$2} = $1;
	}
      }
    }
    if ($sql =~ /having\s+(\w+)/i)
    {
      $newhaving = $1;
      foreach $key (sort {$a cmp $b} keys %change)
      {
	if ($newhaving eq $key)
	{
	  $newhaving =~ s/$key/$change{$key}/g;
	}
      }
    }
    $sql =~ s/(having)\s+(\w+)/$1 $newhaving/i;
  }
  return $sql;
}


sub drop_index
{
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index";
}

sub abort_if_fatal_error
{
  return 0;
}

sub small_rollback_segment
{
  return 0;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

sub reconnect_on_errors
{
  return 0;
}

#############################################################################
#		     Definitions for Empress
#
# at this moment DBI:Empress can only handle 200 prepare statements ...
# so Empress can't be tested with the benchmark test :(
#############################################################################

package db_Empress;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "empress";
  $self->{'data_source'}        = "DBI:EmpressNet:SERVER=$host;Database=/usr/local/empress/rdbms/bin/$database";
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "text";
  $self->{'text'}		= "text";
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled

  $limits{'max_conditions'}	= 1258;
  $limits{'max_columns'}	= 226;		# server is disconnecting????
			# above this value .... but can handle 2419 columns
			# maybe something for crash-me ... but how to check ???
  $limits{'max_tables'}		= 65000;	# Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};
  $limits{'max_text_size'}	= 4095;		# max returned ....
  $limits{'query_size'}		= 65535;	# Not a limit, big enough
  $limits{'max_index'}		= 64;		# Big enough
  $limits{'max_index_parts'}	= 64;		# Big enough
  $limits{'max_column_name'} 	= 31;

  $limits{'join_optimizer'}	= 1;
  $limits{'load_data_infile'}	= 0;
  $limits{'lock_tables'}	= 1;
  $limits{'functions'}		= 1;
  $limits{'group_functions'}	= 1;
  $limits{'group_func_sql_min_str'}	= 1; # Can execute MIN() and MAX() on strings
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'select_without_from'}= 0;
  $limits{'multi_drop'}		= 0;
  $limits{'subqueries'}		= 1;
  $limits{'table_wildcard'}	= 0;
  $limits{'having_with_alias'}  = 0; 	# AS isn't supported in a select
  $limits{'having_with_group'}	= 1;
  $limits{'like_with_column'}	= 1;
  $limits{'order_by_position'}  = 1;
  $limits{'group_by_position'}  = 0;
  $limits{'alter_table'}	= 1;
  $limits{'alter_add_multi_col'}= 0;
  $limits{'alter_table_dropcol'}= 0;

  $limits{'group_func_extra_std'}= 0;	# Have group function std().

  $limits{'func_odbc_mod'}	= 0;
  $limits{'func_extra_%'}	= 1;
  $limits{'func_odbc_floor'}	= 1;
  $limits{'func_extra_if'}	= 0;
  $limits{'column_alias'}	= 0;
  $limits{'NEG'}		= 1;
  $limits{'func_extra_in_num'}	= 0;
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'insert_select'}	= 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 1;
  $limits{'working_all_fields'} = 1;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 

  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self,$dbh)=@_;
  my ($version);
  $version="";
  if (-x "/usr/local/empress/rdbms/bin/empvers")
  {
    $version=`/usr/local/empress/rdbms/bin/empvers | grep Version`;
  }
  if ($version)
  {
    chomp($version);
  }
  else
  {
    $version="Empress version ???";
  }

  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  return $dbh;
}

sub insert_file {
  my($self,$dbname, $file) = @_;
  my($command,$sth);
  $command = "insert into $dbname from '$file'";
  print "$command\n" if ($opt_debug);
  $sth = $dbh->do($command) or die $DBI::errstr;

  return $sth;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#

sub create
{
  my($self,$table_name,$fields,$index) = @_;
  my($query,@queries,$nr);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    $field =~ s/mediumint/int/i;
    $field =~ s/tinyint/int/i;
    $field =~ s/smallint/int/i;
    $field =~ s/longint/int/i;
    $field =~ s/integer/int/i;
    $field =~ s/ double/ longfloat/i;
    # Solid doesn't have blob, it has long varchar
#    $field =~ s/ blob/ text(65535,65535,65535,65535)/;
    $field =~ s/ blob/ text/;
    $field =~ s/ varchar\((\d+)\)/ char($1,3)/;
    $field =~ s/ char\((\d+)\)/ char($1,3)/;
#    $field =~ s/ decimal/ float/i;
#    $field =~ s/ big_decimal/ longfloat/i;
#    $field =~ s/ date/ int/i;
    $field =~ s/ float(.*)/ float/i;
    if ($field =~ / int\((\d+)\)/) {
      if ($1 > 4) {
        $field =~ s/ int\(\d+\)/ longinteger/i;
      } else {
        $field =~ s/ int\(\d+\)/ longinteger/i;
      }
    } else {
      $field =~ s/ int/ longinteger/i;
    }
    $query.= $field . ',';
  }
  substr($query,-1)=")";		# Remove last ',';
  push(@queries,$query);
  $nr=1;
  foreach $index (@$index)
  {
    # Primary key is unique index in Empress
    $index =~ s/primary key/unique index/i;
    if ($index =~ /^unique.*\(([^\(]*)\)$/i)
    {
      $nr++;
      push(@queries,"create unique index ${table_name}_$nr on $table_name ($1)");
    }
    else
    {
      if (!($index =~ /^(.*index)\s+(\w*)\s+(\(.*\))$/i))
      {
	die "Can't parse index information in '$index'\n";
      }
      push(@queries,"create $1 ${table_name}_$2 on $table_name $3");
    }
  }
  return @queries;
}

# empress can't handle an alias and but can handle the number of the
# columname - so
# select test as foo from tmp order by foo
# becomes
# select test from tmp order by 1
#
sub query {
  my($self,$sql) = @_;
  my(@select,$i,$tmp,$newselect,$neworder,@order,$key,%change);
  my($tmp1,$otmp,$tmp2);

  if ($sql =~ /\s+as\s+/i)
  {
    if ($sql =~ /select\s+(.*)\s+from/i) {
      $newselect = $1;
      (@select) = split(/,\s*/, $1);
      $i = 1;
      foreach $tmp (@select) {
	if ($tmp =~ /\s+as\s+(\w+)/) {
	  $change{$1} = $i;
	}
	$i++;
      }
    }
    $newselect =~ s/\s+as\s+(\w+)//gi;
    $tmp2 = 0;
    if ($sql =~ /order\s+by\s+(.*)$/i) {
      (@order) = split(/,\s*/, $1);
      foreach $otmp (@order) {
	foreach $key (sort {$a cmp $b} keys %change) {
	  if ($otmp eq $key) {
	    $neworder .= "$tmp1"."$change{$key}";
	    $tmp1 = ", ";
	    $tmp2 = 1;
	  } elsif ($otmp =~ /(\w+)\s+(.+)$/) {
	    if ($key eq $1) {
	      $neworder .= "$tmp1"."$change{$key} $2";
	      $tmp2 = 1;
	    }
	  }
	}
	if ($tmp2 == 0) {
	  $neworder .= "$tmp1"."$otmp";
	}
	$tmp2 = 0;
	$tmp1 = ", ";
      }
    }
    $sql =~ s/(select)\s+(.*)\s+(from)/$1 $newselect $3/i;
    $sql =~ s/(order\s+by)\s+(.*)$/$1 $neworder/i;
  }
  return $sql;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  $cmd =~ s/\'\'/\' \'/g;
  return $cmd;
}


sub drop_index
{
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index";
}

# This is a because of the 200 statement problem with DBI-Empress

sub abort_if_fatal_error
{
  if ($DBI::errstr =~ /Overflow of table of prepared statements/i)
  {
    print "Overflow of prepared statements ... killing the process\n";
    exit 1;
  }
  return 0;
}

sub small_rollback_segment
{
  return 0;
}

sub reconnect_on_errors
{
  return 0;
}

#############################################################################
#	                 Definitions for Oracle
#############################################################################

package db_Oracle;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "Oracle";
  $self->{'data_source'}	= "DBI:Oracle:$database";
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "long";
  $self->{'text'}		= "long";
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled
  $self->{"vacuum"}		= 1;

  $limits{'max_conditions'}	= 9999; # (Actually not a limit)
  $limits{'max_columns'}	= 254;	# Max number of columns in table
  $limits{'max_tables'}		= 65000; # Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};

  $limits{'max_text_size'}	= 2000; # Limit for blob test-connect
  $limits{'query_size'}		= 65525; # Max size with default buffers.
  $limits{'max_index'}		= 16; # Max number of keys
  $limits{'max_index_parts'}	= 16; # Max segments/key
  $limits{'max_column_name'} = 32; # max table and column name

  $limits{'truncate_table'}	= 1;
  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables
  $limits{'load_data_infile'}	= 0; # Has load data infile
  $limits{'lock_tables'}	= 0; # Has lock tables
  $limits{'functions'}		= 1; # Has simple functions (+/-)
  $limits{'group_functions'}	= 1; # Have group functions
  $limits{'group_func_sql_min_str'}	= 1; # Can execute MIN() and MAX() on strings
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'select_without_from'}= 0;
  $limits{'multi_drop'}		= 0;
  $limits{'subqueries'}		= 1;
  $limits{'left_outer_join'}	= 0; # This may be fixed in the query module
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'having_with_alias'}  = 0; # Can use aliases in HAVING
  $limits{'having_with_group'}	= 1; # Can't use group functions in HAVING
  $limits{'like_with_column'}	= 1; # Can use column1 LIKE column2
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1'
  $limits{'group_by_position'}  = 0;
  $limits{'alter_table'}	= 1;
  $limits{'alter_add_multi_col'}= 0;
  $limits{'alter_table_dropcol'}= 0;

  $limits{'group_func_extra_std'}	= 0; # Have group function std().

  $limits{'func_odbc_mod'}	= 0; # Oracle has problem with mod()
  $limits{'func_extra_%'}	= 0; # Has % as alias for mod()
  $limits{'func_odbc_floor'}	= 1; # Has func_odbc_floor function
  $limits{'func_extra_if'}	= 0; # Have function if.
  $limits{'column_alias'}	= 1; # Alias for fields in select statement.
  $limits{'NEG'}		= 1; # Supports -id
  $limits{'func_extra_in_num'}	= 1; # Has function in
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'insert_select'}	= 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 1;
  $limits{'working_all_fields'} = 1;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 


  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  my ($dbh,$sth,$version,@row);

  $dbh=$self->connect();
  $sth = $dbh->prepare("select VERSION from product_component_version WHERE PRODUCT like 'Oracle%'") or die $DBI::errstr;
  $version="Oracle 7.x";
  if ($sth->execute && (@row = $sth->fetchrow_array))
  {
    $version="Oracle $row[0]";
  }
  $sth->finish;
  $dbh->disconnect;
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#
# If one uses $main::opt_fast then one is allowed to use
# non standard types to get better speed.
#

sub create
{
  my($self,$table_name,$fields,$index) = @_;
  my($query,@queries,$ind,@keys);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    $field =~ s/ character\((\d+)\)/ char\($1\)/i;
    $field =~ s/ character varying\((\d+)\)/ varchar\($1\)/i;
    $field =~ s/ char varying\((\d+)\)/ varchar\($1\)/i;
    $field =~ s/ integer/ number\(38\)/i;
    $field =~ s/ int/ number\(38\)/i;
    $field =~ s/ tinyint/ number\(38\)/i;
    $field =~ s/ smallint/ number\(38\)/i;
    $field =~ s/ mediumint/ number\(38\)/i;
    $field =~ s/ tinynumber\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
    $field =~ s/ smallnumber\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
    $field =~ s/ mediumnumber\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
    $field =~ s/ number\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
    $field =~ s/ numeric\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
    $field =~ s/ decimal\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
    $field =~ s/ dec\((\d+)\)\((\d+)\)/ number\($1,$2\)/i;
    $field =~ s/ float/ number/;
    $field =~ s/ real/ number/;
    $field =~ s/ double precision/ number/;
    $field =~ s/ double/ number/;
    $field =~ s/ blob/ long/;
    $query.= $field . ',';
  }

  foreach $ind (@$index)
  {
    my @index;
    if ( $ind =~ /\bKEY\b/i ){
      push(@keys,"ALTER TABLE $table_name ADD $ind");
    }else{
      my @fields = split(' ',$index);
      my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
      push(@index,$query);
    }
  }
  substr($query,-1)=")";		# Remove last ',';
  push(@queries,$query,@keys,@index);
#print "query:$query\n";

  return @queries;
}

sub insert_file {
  my($self,$dbname, $file) = @_;
  print "insert an ascii file isn't supported by Oracle (?)\n";
  return 0;
}

#
# Do any conversions to the ANSI SQL query so that the database can handle it
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  $cmd =~ s/\'\'/\' \'/g;
  return $cmd;
}


sub drop_index
{
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 0;
}

sub small_rollback_segment
{
  return 1;
}

sub reconnect_on_errors
{
  return 0;
}

#
# optimize the tables ....
#
sub vacuum
{
  my ($self,$full_vacuum,$dbh_ref)=@_;
  my ($loop_time,$end_time,$sth,$dbh);

  if (defined($full_vacuum))
  {
    $$dbh_ref->disconnect;  $$dbh_ref= $self->connect();
  }
  $dbh=$$dbh_ref;
  $loop_time=new Benchmark;
  # first analyze all tables
  $sth = $dbh->prepare("select table_name from user_tables") || die "Got error: $DBI::errstr";
  $sth->execute || die "Got error: $DBI::errstr when select user_tables";
  while (my @r = $sth->fetchrow_array)
  {
    $dbh->do("analyze table $r[0] compute statistics") || die "Got error: $DBI::errstr when executing 'analyze table'\n";
  }
  # now analyze all indexes ...
  $sth = $dbh->prepare("select index_name from user_indexes") || die "Got error: $DBI::errstr";
  $sth->execute || die "Got error: $DBI::errstr when select user_indexes";
  while (my @r1 = $sth->fetchrow_array)
  {
    $dbh->do("analyze index $r1[0] compute statistics") || die "Got error: $DBI::errstr when executing 'analyze index $r1[0]'\n";
  }
  $end_time=new Benchmark;
  print "Time for book-keeping (1): " .
  Benchmark::timestr(Benchmark::timediff($end_time, $loop_time),"all") . "\n\n";
  $dbh->disconnect;  $$dbh_ref= $self->connect();
}


#############################################################################
#	                 Definitions for Informix
#############################################################################

package db_Informix;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "Informix";
  $self->{'data_source'}	= "DBI:Informix:$database";
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "byte in table";
  $self->{'text'}		= "byte in table";
  $self->{'double_quotes'}	= 0; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled
  $self->{'host'}		= $host;

  $limits{'NEG'}		= 1; # Supports -id
  $limits{'alter_table'}	= 1;
  $limits{'alter_add_multi_col'}= 0;
  $limits{'alter_table_dropcol'}= 1;
  $limits{'column_alias'}	= 1; # Alias for fields in select statement.
  $limits{'func_extra_%'}	= 0; # Has % as alias for mod()
  $limits{'func_extra_if'}	= 0; # Have function if.
  $limits{'func_extra_in_num'}= 0; # Has function in
  $limits{'func_odbc_floor'}	= 0; # Has func_odbc_floor function
  $limits{'func_odbc_mod'}	= 1; # Have function mod.
  $limits{'functions'}		= 1; # Has simple functions (+/-)
  $limits{'group_by_position'}  = 1; # Can use 'GROUP BY 1'
  $limits{'group_by_alias'}  = 0; # Can use 'select a as ab from x GROUP BY ab'
  $limits{'group_func_extra_std'} = 0; # Have group function std().
  $limits{'group_functions'}	= 1; # Have group functions
  $limits{'group_func_sql_min_str'}	= 1; # Can execute MIN() and MAX() on strings
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'having_with_alias'}  = 0; # Can use aliases in HAVING
  $limits{'having_with_group'}= 1; # Can't use group functions in HAVING
  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables (always 1 only for msql)
  $limits{'left_outer_join'}	= 0; # Supports left outer joins (ANSI)
  $limits{'like_with_column'}	= 1; # Can use column1 LIKE column2
  $limits{'load_data_infile'}	= 0; # Has load data infile
  $limits{'lock_tables'}	= 1; # Has lock tables
  $limits{'max_conditions'}	= 1214; # (Actually not a limit)
  $limits{'max_column_name'}	= 18; # max table and column name
  $limits{'max_columns'}	= 994;	# Max number of columns in table
  $limits{'max_tables'}		= 65000;	# Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};

  $limits{'max_index'}		= 64; # Max number of keys
  $limits{'max_index_parts'}	= 15; # Max segments/key
  $limits{'max_text_size'}	= 65535;  # Max size with default buffers. ??
  $limits{'multi_drop'}		= 0; # Drop table can take many tables
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1'
  $limits{'query_size'}		= 32766; # Max size with default buffers.
  $limits{'select_without_from'}= 0; # Can do 'select 1';
  $limits{'subqueries'}		= 1; # Doesn't support sub-queries.
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'insert_select'}	= 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 1;
  $limits{'working_all_fields'} = 1;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 

  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  my ($dbh,$sth,$version,@row);

  $ENV{'INFORMIXSERVER'} = $self->{'host'};
  $dbh=$self->connect();
  $sth = $dbh->prepare("SELECT owner FROM systables WHERE tabname = ' VERSION'")
						      or die $DBI::errstr;
  $version='Informix unknown';
  if ($sth->execute && (@row = $sth->fetchrow_array))
  {
    $version="Informix $row[0]";
  }
  $sth->finish;
  $dbh->disconnect;
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  return $dbh;
}


#
# Create table
#

sub create
{
  my($self,$table_name,$fields,$index) = @_;
  my($query,@queries,$name,$nr);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
#    $field =~ s/\btransport_description\b/transport_desc/;
				# to overcome limit 18 chars
    $field =~ s/tinyint/smallint/i;
    $field =~ s/tinyint\(\d+\)/smallint/i;
    $field =~ s/mediumint/integer/i;
    $field =~ s/mediumint\(\d+\)/integer/i;
    $field =~ s/smallint\(\d+\)/smallint/i;
    $field =~ s/integer\(\d+\)/integer/i;
    $field =~ s/int\(\d+\)/integer/i;
#    $field =~ s/\b(?:small)?int(?:eger)?\((\d+)\)/decimal($1)/i;
#    $field =~ s/float(\(\d*,\d*\)){0,1}/real/i;
    $field =~ s/(float|double)(\(.*?\))?/float/i;

    if ($field =~ / blob/i)
    {
      $name=$self->{'blob'};
      $field =~ s/ blob/ $name/;
    }
    $query.= $field . ',';
  }
  substr($query,-1)=")";		# Remove last ',';
  push(@queries,$query);
  $nr=0;

  foreach $index (@$index)
  {
    # Primary key is unique index in Informix
    $index =~ s/primary key/unique index primary/i;
    if ($index =~ /^unique\s*\(([^\(]*)\)$/i)
    {
      $nr++;
      push(@queries,"create unique index ${table_name}_$nr on $table_name ($1)");
    }
    else
    {
      if (!($index =~ /^(.*index)\s+(\w*)\s+(\(.*\))$/i))
      {
	die "Can't parse index information in '$index'\n";
      }
      ### push(@queries,"create $1 ${table_name}_$2 on $table_name $3");
      $nr++;
      push(@queries,"create $1 ${table_name}_$nr on $table_name $3");
    }
  }
  return @queries;
}
#
# Some test needed this
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}


sub fix_for_insert
{
  my ($self,$cmd) = @_;
  $cmd =~ s/\\\'//g;
  return $cmd;
}



sub drop_index
{
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 0;
}

sub small_rollback_segment
{
  return 0;
}

sub reconnect_on_errors
{
  return 0;
}


#############################################################################
#	     Configuration for Access
#############################################################################

package db_access;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "access";
  $self->{'data_source'}	= "DBI:ODBC:$database";
  if (defined($host) && $host ne "")
  {
    $self->{'data_source'}	.= ":$host";
  }
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "blob";
  $self->{'text'}		= "blob"; # text ? 
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled

  $limits{'max_conditions'}	= 97; # We get 'Query is too complex'
  $limits{'max_columns'}	= 255;	# Max number of columns in table
  $limits{'max_tables'}		= 65000;	# Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};

  $limits{'max_text_size'}	= 255;  # Max size with default buffers.
  $limits{'query_size'}		= 65535; # Not a limit, big enough
  $limits{'max_index'}		= 32; # Max number of keys
  $limits{'max_index_parts'}	= 10; # Max segments/key
  $limits{'max_column_name'}	= 64; # max table and column name

  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables
  $limits{'load_data_infile'}	= 0; # Has load data infile
  $limits{'lock_tables'}	= 0; # Has lock tables
  $limits{'functions'}		= 1; # Has simple functions (+/-)
  $limits{'group_functions'}	= 1; # Have group functions
  $limits{'group_func_sql_min_str'}	= 1; # Can execute MIN() and MAX() on strings
  $limits{'group_distinct_functions'}= 0; # Have count(distinct)
  $limits{'select_without_from'}= 1; # Can do 'select 1';
  $limits{'multi_drop'}		= 0; # Drop table can take many tables
  $limits{'subqueries'}		= 1; # Supports sub-queries.
  $limits{'left_outer_join'}	= 1; # Supports left outer joins
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'having_with_alias'}  = 0; # Can use aliases in HAVING
  $limits{'having_with_group'}	= 1; # Can use group functions in HAVING
  $limits{'like_with_column'}	= 1; # Can use column1 LIKE column2
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1'
  $limits{'group_by_position'}  = 0; # Can use 'GROUP BY 1'
  $limits{'alter_table'}	= 1;
  $limits{'alter_add_multi_col'}= 2; #Have ALTER TABLE t add a int, b int;
  $limits{'alter_table_dropcol'}= 1;

  $limits{'group_func_extra_std'} = 0; # Have group function std().

  $limits{'func_odbc_mod'}	= 0; # Have function mod.
  $limits{'func_extra_%'}	= 0; # Has % as alias for mod()
  $limits{'func_odbc_floor'}	= 0; # Has func_odbc_floor function
  $limits{'func_extra_if'}	= 0; # Have function if.
  $limits{'column_alias'}	= 1; # Alias for fields in select statement.
  $limits{'NEG'}		= 1; # Supports -id
  $limits{'func_extra_in_num'}	= 1; # Has function in
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'insert_select'}	= 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 1;
  $limits{'working_all_fields'} = 1;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 
  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  my $version="Access 2000";
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;		#DBI/ODBC can't return the server version
}

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#

sub create
{
  my($self,$table_name,$fields,$index) = @_;
  my($query,@queries,$nr);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    $field =~ s/mediumint/integer/i;
    $field =~ s/tinyint/smallint/i;
    $field =~ s/float\(\d+,\d+\)/float/i;
    $field =~ s/integer\(\d+\)/integer/i;
    $field =~ s/smallint\(\d+\)/smallint/i;
    $field =~ s/int\(\d+\)/integer/i;
    $field =~ s/blob/text/i;
    $query.= $field . ',';
  }
  substr($query,-1)=")";		# Remove last ',';
  push(@queries,$query);
  $nr=0;
  foreach $index (@$index)
  {
    $ext="WITH DISALLOW NULL";
    if (($index =~ s/primary key/unique index primary_key/i))
    {
      $ext="WITH PRIMARY;"
    }
    if ($index =~ /^unique.*\(([^\(]*)\)$/i)
    {
      $nr++;
      $index="unique index ${table_name}_$nr ($1)";
    }
    $index =~ /^(.*)\s+(\(.*\))$/;
    push(@queries,"create ${1} on $table_name $2");
  }
  return @queries;
}

#
# Do any conversions to the ANSI SQL query so that the database can handle it
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub drop_index
{
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index ON $table";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 1 if (($DBI::errstr =~ /The database engine couldn\'t lock table/i) ||
               ($DBI::errstr =~ /niet vergrendelen. De tabel is momenteel in gebruik /i) ||
	       ($DBI::errstr =~ /Den anv.* redan av en annan/i) ||
	       ($DBI::errstr =~ /non-exclusive access/));
  return 0;
}

sub small_rollback_segment
{
  return 0;
}

sub reconnect_on_errors
{
  return 1;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

#############################################################################
#	     Configuration for Microsoft SQL server
#############################################################################

package db_ms_sql;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "ms-sql";
  $self->{'data_source'}	= "DBI:ODBC:$database";
  if (defined($host) && $host ne "")
  {
    $self->{'data_source'}	.= ":$host";
  }
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "text";
  $self->{'text'}		= "text";
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled

  $limits{'max_conditions'}	= 1030; # We get 'Query is too complex'
  $limits{'max_columns'}	= 250;	# Max number of columns in table
  $limits{'max_tables'}		= 65000;	# Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};

  $limits{'max_text_size'}	= 9830;  # Max size with default buffers.
  $limits{'query_size'}		= 9830; # Max size with default buffers.
  $limits{'max_index'}		= 64; # Max number of keys
  $limits{'max_index_parts'}	= 15; # Max segments/key
  $limits{'max_column_name'}	= 30; # max table and column name

  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables
  $limits{'load_data_infile'}	= 0; # Has load data infile
  $limits{'lock_tables'}	= 0; # Has lock tables
  $limits{'functions'}		= 1; # Has simple functions (+/-)
  $limits{'group_functions'}	= 1; # Have group functions
  $limits{'group_func_sql_min_str'}	= 1; # Can execute MIN() and MAX() on strings
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'select_without_from'}= 1; # Can do 'select 1';
  $limits{'multi_drop'}		= 1; # Drop table can take many tables
  $limits{'subqueries'}		= 1; # Supports sub-queries.
  $limits{'left_outer_join'}	= 1; # Supports left outer joins
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'having_with_alias'}  = 0; # Can use aliases in HAVING
  $limits{'having_with_group'}	= 1; # Can't use group functions in HAVING
  $limits{'like_with_column'}	= 1; # Can use column1 LIKE column2
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1'
  $limits{'group_by_position'}  = 0; # Can use 'GROUP BY 1'
  $limits{'alter_table'}	= 1;
  $limits{'alter_add_multi_col'}= 0;
  $limits{'alter_table_dropcol'}= 0;

  $limits{'group_func_extra_std'} = 0; # Have group function std().

  $limits{'func_odbc_mod'}	= 0; # Have function mod.
  $limits{'func_extra_%'}	= 1; # Has % as alias for mod()
  $limits{'func_odbc_floor'}	= 1; # Has func_odbc_floor function
  $limits{'func_extra_if'}	= 0; # Have function if.
  $limits{'column_alias'}	= 1; # Alias for fields in select statement.
  $limits{'NEG'}		= 1; # Supports -id
  $limits{'func_extra_in_num'}	= 0; # Has function in
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'insert_select'}	= 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 1;
  $limits{'working_all_fields'} = 1;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 
  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  my($sth,@row, $version);
  $version='MS SQL server ?';
  $dbh=$self->connect();
  $sth = $dbh->prepare("SELECT \@\@VERSION") or die $DBI::errstr;
  $sth->execute or die $DBI::errstr;
  @row = $sth->fetchrow_array;
  if ($row[0]) {
     @server = split(/\n/,$row[0]);
     chomp(@server);
     $version= "$server[0]";
  } 
  $sth->finish;
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#

sub create
{
  my($self,$table_name,$fields,$index) = @_;
  my($query,@queries,$nr);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    $field =~ s/mediumint/integer/i;
    $field =~ s/float\(\d+,\d+\)/float/i;
    $field =~ s/double\(\d+,\d+\)/float/i;
    $field =~ s/double/float/i;
    $field =~ s/integer\(\d+\)/integer/i;
    $field =~ s/int\(\d+\)/integer/i;
    $field =~ s/smallint\(\d+\)/smallint/i;
    $field =~ s/smallinteger/smallint/i;
    $field =~ s/tinyint\(\d+\)/tinyint/i;
    $field =~ s/tinyinteger/tinyint/i;
    $field =~ s/blob/text/i;
    $query.= $field . ',';
  }
  substr($query,-1)=")";		# Remove last ',';
  push(@queries,$query);
  $nr=0;
  foreach $index (@$index)
  {
    $ext="WITH DISALLOW NULL";
    if (($index =~ s/primary key/unique index primary_key/i))
    {
      $ext="WITH PRIMARY;"
    }
    if ($index =~ /^unique.*\(([^\(]*)\)$/i)
    {
      $nr++;
      $index="unique index ${table_name}_$nr ($1)";
    }
    $index =~ /^(.*)\s+(\(.*\))$/;
    push(@queries,"create ${1} on $table_name $2");
  }
  return @queries;
}

#
# Do any conversions to the ANSI SQL query so that the database can handle it
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub drop_index
{
  my ($self,$table,$index) = @_;
  return "DROP INDEX $table.$index";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 0;
}

sub small_rollback_segment
{
  return 0;
}

sub reconnect_on_errors
{
  return 0;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

#############################################################################
#	     Configuration for Sybase
#############################################################################
package db_sybase;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "sybase";
  $self->{'data_source'}	= "DBI:Sybase:database=$database";
  if (defined($host) && $host ne "")
  {
    $self->{'data_source'}	.= ";hostname=$host";
  }
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "text";
  $self->{'text'}		= "text";
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled
  $self->{"vacuum"}		= 1;

  $limits{'max_conditions'}	= 1030; # We get 'Query is too complex'
  $limits{'max_columns'}	= 250;	# Max number of columns in table
  $limits{'max_tables'}		= 65000;	# Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};

  $limits{'max_text_size'}	= 9830;  # Max size with default buffers.
  $limits{'query_size'}		= 9830; # Max size with default buffers.
  $limits{'max_index'}		= 64; # Max number of keys
  $limits{'max_index_parts'}	= 15; # Max segments/key
  $limits{'max_column_name'}	= 30; # max table and column name

  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables
  $limits{'load_data_infile'}	= 0; # Has load data infile
  $limits{'lock_tables'}	= 0; # Has lock tables
  $limits{'functions'}		= 1; # Has simple functions (+/-)
  $limits{'group_functions'}	= 1; # Have group functions
  $limits{'group_func_sql_min_str'}	= 1; # Can execute MIN() and MAX() on strings
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'select_without_from'}= 1; # Can do 'select 1';
  $limits{'multi_drop'}		= 1; # Drop table can take many tables
  $limits{'subqueries'}		= 1; # Supports sub-queries.
  $limits{'left_outer_join'}	= 1; # Supports left outer joins
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'having_with_alias'}  = 0; # Can use aliases in HAVING
  $limits{'having_with_group'}	= 1; # Can't use group functions in HAVING
  $limits{'like_with_column'}	= 1; # Can use column1 LIKE column2
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1'
  $limits{'group_by_position'}  = 0; # Can use 'GROUP BY 1'
  $limits{'alter_table'}	= 1;
  $limits{'alter_add_multi_col'}= 0;
  $limits{'alter_table_dropcol'}= 0;

  $limits{'group_func_extra_std'} = 0; # Have group function std().

  $limits{'func_odbc_mod'}	= 0; # Have function mod.
  $limits{'func_extra_%'}	= 1; # Has % as alias for mod()
  $limits{'func_odbc_floor'}	= 1; # Has func_odbc_floor function
  $limits{'func_extra_if'}	= 0; # Have function if.
  $limits{'column_alias'}	= 1; # Alias for fields in select statement.
  $limits{'NEG'}		= 1; # Supports -id
  $limits{'func_extra_in_num'}	= 0; # Has function in
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'insert_select'}	= 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 1;
  $limits{'working_all_fields'} = 1;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 
  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  my ($dbh,$sth,$version,@row);

  $dbh=$self->connect();
  $sth = $dbh->prepare('SELECT @@version') or die $DBI::errstr;
  $version="Sybase (unknown)";
  if ($sth->execute && (@row = $sth->fetchrow_array))
  {
    $version=$row[0];
  }
  $sth->finish;
  $dbh->disconnect;
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0 , AutoCommit => 1}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#

sub create
{
  my($self,$table_name,$fields,$index) = @_;
  my($query,@queries,$nr);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    $field =~ s/mediumint/integer/i;
    $field =~ s/float\(\d+,\d+\)/float/i;
    $field =~ s/int\(\d+\)/int/i;
    $field =~ s/double/float/i;
    $field =~ s/integer\(\d+\)/integer/i;
    $field =~ s/smallint\(\d+\)/smallint/i;
    $field =~ s/tinyint\(\d+\)/tinyint/i;
    $field =~ s/blob/text/i;
    $query.= $field . ',';
  }
  substr($query,-1)=")";		# Remove last ',';
  push(@queries,$query);
  $nr=0;
  foreach $index (@$index)
  {
#    $ext="WITH DISALLOW NULL";
    if (($index =~ s/primary key/unique index primary_key/i))
    {
#      $ext="WITH PRIMARY;"
    }
    if ($index =~ /^unique.*\(([^\(]*)\)$/i)
    {
      $nr++;
      $index="unique index ${table_name}_$nr ($1)";
    }
    $index =~ /^(.*)\s+(\(.*\))$/;
    push(@queries,"create ${1} on $table_name $2");
  }
  return @queries;
}

#
# Do any conversions to the ANSI SQL query so that the database can handle it
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub drop_index
{
  my ($self,$table,$index) = @_;
  return "DROP INDEX $table.$index";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 0;
}

sub small_rollback_segment
{
  return 0;
}

sub reconnect_on_errors
{
  return 0;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

#
# optimize the tables ....
#  WARNING (from walrus)! This sub will work only from DBD:sybase
# driver. Because if we use ODBC we don't know actual database name
# (but DSN name only)
sub vacuum
{
  my ($self,$full_vacuum,$dbh_ref)=@_;
  my ($loop_time,$end_time,$dbh);

  if (defined($full_vacuum))
  {
    $$dbh_ref->disconnect;  $$dbh_ref= $self->connect();
  }
  $dbh=$$dbh_ref;
  $loop_time=new Benchmark;
  my (@tables,$sth,$current_table,$current_base);
  $dbh->do("dump tran $database with truncate_only");
  $sth=$dbh->prepare("sp_tables" ) or die "prepere";
  $sth->execute() or die "execute";
  while (@row = $sth->fetchrow_array()) {
    $current_table = $row[2];
    $current_base = $row[0];
    next if ($current_table =~ /^sys/); 
    push(@tables,$current_table) if ($database == $current_base);    
   }

  $sth->finish();

  foreach $table (@tables) {
#    print "$table: \n";
    $dbh->do("update statistics $table") or print "Oops!"; 
  }
 
#  $dbh->do("analyze table ?? compute statistics") || die "Got error: $DBI::errstr when executing 'vacuum'\n";
  $end_time=new Benchmark;
  print "Time for book-keeping (1): " .
  Benchmark::timestr(Benchmark::timediff($end_time, $loop_time),"all") . "\n\n";
  $dbh->disconnect;  $$dbh_ref= $self->connect();
}




#############################################################################
#	                 Definitions for Adabas
#############################################################################

package db_Adabas;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "Adabas";
  $self->{'data_source'}	= "DBI:Adabas:$database";
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "long";
  $self->{'text'}		= "long";
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled

  $limits{'max_conditions'}	= 50; # (Actually not a limit)
  $limits{'max_columns'}	= 254;	# Max number of columns in table
  $limits{'max_tables'}		= 65000;	# Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};

  $limits{'max_text_size'}	= 2000; # Limit for blob test-connect
  $limits{'query_size'}		= 65525; # Max size with default buffers.
  $limits{'max_index'}		= 16; # Max number of keys
  $limits{'max_index_parts'}	= 16; # Max segments/key
  $limits{'max_column_name'} = 32; # max table and column name

  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables
  $limits{'load_data_infile'}	= 0; # Has load data infile
  $limits{'lock_tables'}	= 0; # Has lock tables
  $limits{'functions'}		= 1; # Has simple functions (+/-)
  $limits{'group_functions'}	= 1; # Have group functions
  $limits{'group_func_sql_min_str'}	= 1; # Can execute MIN() and MAX() on strings
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'select_without_from'}= 0;
  $limits{'multi_drop'}		= 0;
  $limits{'subqueries'}		= 1;
  $limits{'left_outer_join'}	= 0; # This may be fixed in the query module
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'having_with_alias'}  = 0; # Can use aliases in HAVING
  $limits{'having_with_group'}	= 1; # Can't use group functions in HAVING
  $limits{'like_with_column'}	= 1; # Can use column1 LIKE column2
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1'
  $limits{'group_by_position'}  = 1;
  $limits{'alter_table'}	= 1;
  $limits{'alter_add_multi_col'}= 2; #Have ALTER TABLE t add a int, b int;
  $limits{'alter_table_dropcol'}= 1;

  $limits{'group_func_extra_std'}	= 0; # Have group function std().

  $limits{'func_odbc_mod'}	= 0; # Oracle has problem with mod()
  $limits{'func_extra_%'}	= 0; # Has % as alias for mod()
  $limits{'func_odbc_floor'}	= 1; # Has func_odbc_floor function
  $limits{'func_extra_if'}	= 0; # Have function if.
  $limits{'column_alias'}	= 1; # Alias for fields in select statement.
  $limits{'NEG'}		= 1; # Supports -id
  $limits{'func_extra_in_num'}	= 1; # Has function in
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'insert_select'}	= 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 1;
  $limits{'working_all_fields'} = 1;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 


  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  my ($dbh,$sth,$version,@row);

  $dbh=$self->connect();
  $sth = $dbh->prepare("SELECT KERNEL FROM VERSIONS") or die $DBI::errstr;
  $version="Adabas (unknown)";
  if ($sth->execute && (@row = $sth->fetchrow_array)
      && $row[0] =~ /([\d\.]+)/)
  {
    $version="Adabas $1";
  }
  $sth->finish;
  $dbh->disconnect;
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#
# If one uses $main::opt_fast then one is allowed to use
# non standard types to get better speed.
#

sub create
{
  my($self,$table_name,$fields,$index) = @_;
  my($query,@queries,$ind,@keys);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    $field =~ s/CHARACTER\s+VARYING/VARCHAR/i;
    $field =~ s/TINYINT/SMALLINT/i;
    $field =~ s/MEDIUMINT/INT/i;
    $field =~ s/SMALLINT\s*\(\d+\)/SMALLINT/i;
    $field =~ s/INT\s*\(\d+\)/INT/i;
    $field =~ s/BLOB/LONG/i;
    $field =~ s/INTEGER\s*\(\d+\)/INTEGER/i;
    $field =~ s/FLOAT\s*\((\d+),\d+\)/FLOAT\($1\)/i;
    $field =~ s/DOUBLE/FLOAT\(38\)/i;
    $field =~ s/DOUBLE\s+PRECISION/FLOAT\(38\)/i;
    $query.= $field . ',';
  }

  foreach $ind (@$index)
  {
    my @index;
    if ( $ind =~ /\bKEY\b/i ){
      push(@keys,"ALTER TABLE $table_name ADD $ind");
    }else{
      my @fields = split(' ',$index);
      my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
      push(@index,$query);
    }
  }
  substr($query,-1)=")";		# Remove last ',';
  push(@queries,$query,@keys,@index);
#print "query:$query\n";

  return @queries;
}

sub insert_file {
  my($self,$dbname, $file) = @_;
  print "insert an ascii file isn't supported by Oracle (?)\n";
  return 0;
}

#
# Do any conversions to the ANSI SQL query so that the database can handle it
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub drop_index
{
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 0;
}

sub small_rollback_segment
{
  return 0;
}

sub reconnect_on_errors
{
  return 0;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

#############################################################################
#	     Configuration for IBM DB2
#############################################################################

package db_db2;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "DB2";
  $self->{'data_source'}	= "DBI:ODBC:$database";
  if (defined($host) && $host ne "")
  {
    $self->{'data_source'}	.= ":$host";
  }
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "varchar(255)";
  $self->{'text'}		= "varchar(255)";
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled

  $limits{'max_conditions'}	= 418; # We get 'Query is too complex'
  $limits{'max_columns'}	= 500;	# Max number of columns in table
  $limits{'max_tables'}		= 65000;	# Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};

  $limits{'max_text_size'}	= 254;  # Max size with default buffers.
  $limits{'query_size'}		= 254; # Max size with default buffers.
  $limits{'max_index'}		= 48; # Max number of keys
  $limits{'max_index_parts'}	= 15; # Max segments/key
  $limits{'max_column_name'}	= 18; # max table and column name

  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables
  $limits{'load_data_infile'}	= 0; # Has load data infile
  $limits{'lock_tables'}	= 0; # Has lock tables
  $limits{'functions'}		= 1; # Has simple functions (+/-)
  $limits{'group_functions'}	= 1; # Have group functions
  $limits{'group_func_sql_min_str'}= 1;
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'select_without_from'}= 0; # Can do 'select 1';
  $limits{'multi_drop'}		= 0; # Drop table can take many tables
  $limits{'subqueries'}		= 1; # Supports sub-queries.
  $limits{'left_outer_join'}	= 1; # Supports left outer joins
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'having_with_alias'}  = 0; # Can use aliases in HAVING
  $limits{'having_with_group'}	= 1; # Can't use group functions in HAVING
  $limits{'like_with_column'}	= 0; # Can use column1 LIKE column2
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1'
  $limits{'group_by_position'}  = 0; # Can use 'GROUP BY 1'
  $limits{'alter_table'}	= 1;
  $limits{'alter_add_multi_col'}= 0;
  $limits{'alter_table_dropcol'}= 0;

  $limits{'group_func_extra_std'} = 0; # Have group function std().

  $limits{'func_odbc_mod'}	= 1; # Have function mod.
  $limits{'func_extra_%'}	= 0; # Has % as alias for mod()
  $limits{'func_odbc_floor'}	= 1; # Has func_odbc_floor function
  $limits{'func_extra_if'}	= 0; # Have function if.
  $limits{'column_alias'}	= 1; # Alias for fields in select statement.
  $limits{'NEG'}		= 1; # Supports -id
  $limits{'func_extra_in_num'}	= 0; # Has function in
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'insert_select'}	= 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 1;
  $limits{'working_all_fields'} = 1;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 
  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  return "IBM DB2 5";		#DBI/ODBC can't return the server version
}

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user, $main::opt_password) ||
    die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#

sub create
{
  my($self,$table_name,$fields,$index) = @_;
  my($query,@queries,$nr);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    $field =~ s/mediumint/integer/i;
    $field =~ s/float\(\d+,\d+\)/float/i;
    $field =~ s/integer\(\d+\)/integer/i;
    $field =~ s/int\(\d+\)/integer/i;
    $field =~ s/tinyint\(\d+\)/smallint/i;
    $field =~ s/tinyint/smallint/i;
    $field =~ s/smallint\(\d+\)/smallint/i;
    $field =~ s/smallinteger/smallint/i;
    $field =~ s/blob/varchar(256)/i;
    $query.= $field . ',';
  }
  substr($query,-1)=")";		# Remove last ',';
  push(@queries,$query);
  $nr=0;
  foreach $index (@$index)
  {
    $ext="WITH DISALLOW NULL";
    if (($index =~ s/primary key/unique index primary_key/i))
    {
      $ext="WITH PRIMARY;"
    }
    if ($index =~ /^unique.*\(([^\(]*)\)$/i)
    {
      $nr++;
      $index="unique index ${table_name}_$nr ($1)";
    }
    $index =~ /^(.*)\s+(\(.*\))$/;
    push(@queries,"create ${1} on $table_name $2");
  }
  return @queries;
}

#
# Do any conversions to the ANSI SQL query so that the database can handle it
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub drop_index
{
  my ($self,$table,$index) = @_;
  return "DROP INDEX $table.$index";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 0;
}

sub small_rollback_segment
{
  return 1;
}

sub reconnect_on_errors
{
  return 0;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

#############################################################################
#	     Configuration for MIMER 
#############################################################################

package db_Mimer;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "mimer";
  $self->{'data_source'}	= "DBI:mimer:$database:$host";
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "binary varying(15000)";
  $self->{'text'}		= "character varying(15000)";
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled
  $self->{'char_null'}          = "cast(NULL as char(1))";
  $self->{'numeric_null'}       = "cast(NULL as int)";

  $limits{'max_conditions'}	= 9999; # (Actually not a limit)
  $limits{'max_columns'}	= 252;	# Max number of columns in table
  $limits{'max_tables'}		= 65000;	# Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};
  $limits{'max_text_size'}	= 15000; # Max size with default buffers.
  $limits{'query_size'}		= 1000000; # Max size with default buffers.
  $limits{'max_index'}		= 32; # Max number of keys
  $limits{'max_index_parts'}	= 16; # Max segments/key
  $limits{'max_column_name'}	= 128; # max table and column name

  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables
  $limits{'load_data_infile'}	= 1; # Has load data infile
  $limits{'lock_tables'}	= 0; # Has lock tables
  $limits{'functions'}		= 1; # Has simple functions (+/-)
  $limits{'group_functions'}	= 1; # Have group functions
  $limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'select_without_from'}= 0; # Cannot do 'select 1';
  $limits{'multi_drop'}		= 0; # Drop table cannot take many tables
  $limits{'subqueries'}		= 1; # Supports sub-queries.
  $limits{'left_outer_join'}	= 1; # Supports left outer joins
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'having_with_alias'}  = 0; # Can use aliases in HAVING
  $limits{'having_with_group'}	= 1; # Can use group functions in HAVING
  $limits{'like_with_column'}	= 1; # Can use column1 LIKE column2
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1'
  $limits{'group_by_position'}  = 0; # Cannot use 'GROUP BY 1'
  $limits{'alter_table'}	= 1; # Have ALTER TABLE
  $limits{'alter_add_multi_col'}= 0; # Have ALTER TABLE t add a int,add b int;
  $limits{'alter_table_dropcol'}= 1; # Have ALTER TABLE DROP column
  $limits{'insert_multi_value'} = 0; # Does not have INSERT ... values (1,2),(3,4)
  $limits{'multi_distinct'}     = 0; # Does not allow select count(distinct a),count(distinct b).. 

  $limits{'group_func_extra_std'} = 0; # Does not have group function std().

  $limits{'func_odbc_mod'}	= 1; # Have function mod.
  $limits{'func_extra_%'}	= 0; # Does not have % as alias for mod()
  $limits{'func_odbc_floor'}	= 1; # Has func_odbc_floor function
  $limits{'func_extra_if'}	= 0; # Does not have function if.
  $limits{'column_alias'}	= 1; # Alias for fields in select statement.
  $limits{'NEG'}		= 1; # Supports -id
  $limits{'func_extra_in_num'}	= 1; # Has function in
  $limits{'limit'}		= 0; # Does not support the limit attribute
  $limits{'unique_index'}	= 1; # Unique index works or not
  $limits{'insert_select'}	= 1;
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 0;
  $limits{'working_all_fields'} = 1;

  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  my ($dbh,$sth,$version,@row);

  $dbh=$self->connect();
#
#  Pick up SQLGetInfo option SQL_DBMS_VER (18)
#
  $version = $dbh->func(18, GetInfo);
  $dbh->disconnect;
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);  
  return $version;
}

#
# Connection with optional disabling of logging
#

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";

  $dbh->do("SET OPTION LOG_OFF=1,UPDATE_LOG=0");
  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#
# If one uses $main::opt_fast then one is allowed to use
# non standard types to get better speed.
#

sub create
{
  my($self,$table_name,$fields,$index,$options) = @_;
  my($query,@queries,@indexes);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
#    $field =~ s/ decimal/ double(10,2)/i;
#    $field =~ s/ big_decimal/ double(10,2)/i;
    $field =~ s/ double/ double precision/i;  
    $field =~ s/ tinyint\(.*\)/ smallint/i;
    $field =~ s/ smallint\(.*\)/ smallint/i;
    $field =~ s/ mediumint/ integer/i;
    $field =~ s/ float\(.*\)/ float/i;
#    $field =~ s/ date/ int/i;		# Because of tcp ?
    $query.= $field . ',';
  }
  foreach $index (@$index)
  {
    if ( $index =~ /\bINDEX\b/i )
    {
      my @fields = split(' ',$index);
      my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
      push(@indexes,$query);
    
    } else {
      $query.= $index . ',';
    }
  }
  substr($query,-1)=")";		# Remove last ',';
  $query.=" $options" if (defined($options));
  push(@queries,$query,@indexes);
  return @queries;
}

sub insert_file {
  my($self,$dbname, $file) = @_;
  print "insert of an ascii file isn't supported by Mimer\n";
  return 0;
}

#
# Do any conversions to the ANSI SQL query so that the database can handle it
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub drop_index {
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 1 if ($DBI::errstr =~ /Table locked by another cursor/);
  return 0;
}

sub small_rollback_segment
{
  return 0;
}

sub reconnect_on_errors
{
  return 0;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

#############################################################################
#	     Configuration for InterBase
#############################################################################

package db_interbase;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "interbase";
  $self->{'data_source'}	= "DBI:InterBase:database=$database;ib_dialect=3";
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "blob";
  $self->{'text'}		= "";
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled
  $self->{'char_null'}          = "";
  $self->{'numeric_null'}       = "";

  $limits{'max_conditions'}	= 9999; # (Actually not a limit)
  $limits{'max_columns'}	= 252;	# Max number of columns in table
  $limits{'max_tables'}		= 65000;	# Should be big enough
  $limits{'max_temporary_tables'}= $limits{"max_tables"};
  $limits{'max_text_size'}	= 15000; # Max size with default buffers.
  $limits{'query_size'}		= 1000000; # Max size with default buffers.
  $limits{'max_index'}		= 65000; # Max number of keys
  $limits{'max_index_parts'}	= 8; # Max segments/key
  $limits{'max_column_name'}	= 128; # max table and column name

  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables
  $limits{'load_data_infile'}	= 0; # Has load data infile
  $limits{'lock_tables'}	= 0; # Has lock tables
  $limits{'functions'}		= 1; # Has simple functions (+/-)
  $limits{'group_functions'}	= 1; # Have group functions
  $limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)
  $limits{'select_without_from'}= 0; # Cannot do 'select 1';
  $limits{'multi_drop'}		= 0; # Drop table cannot take many tables
  $limits{'subqueries'}		= 1; # Supports sub-queries.
  $limits{'left_outer_join'}	= 1; # Supports left outer joins
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'having_with_alias'}  = 0; # Can use aliases in HAVING
  $limits{'having_with_group'}	= 1; # Can use group functions in HAVING
  $limits{'like_with_column'}	= 0; # Can use column1 LIKE column2
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1'
  $limits{'group_by_position'}  = 0; # Cannot use 'GROUP BY 1'
  $limits{'alter_table'}	= 1; # Have ALTER TABLE
  $limits{'alter_add_multi_col'}= 1; # Have ALTER TABLE t add a int,add b int;
  $limits{'alter_table_dropcol'}= 1; # Have ALTER TABLE DROP column
  $limits{'insert_multi_value'} = 0; # Does not have INSERT ... values (1,2),(3,4)

  $limits{'group_func_extra_std'} = 0; # Does not have group function std().

  $limits{'func_odbc_mod'}	= 0; # Have function mod.
  $limits{'func_extra_%'}	= 0; # Does not have % as alias for mod()
  $limits{'func_odbc_floor'}	= 0; # Has func_odbc_floor function
  $limits{'func_extra_if'}	= 0; # Does not have function if.
  $limits{'column_alias'}	= 1; # Alias for fields in select statement.
  $limits{'NEG'}		= 0; # Supports -id
  $limits{'func_extra_in_num'}	= 0; # Has function in
  $limits{'limit'}		= 0; # Does not support the limit attribute
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works
  $limits{'order_by_unused'}	= 1;
  $limits{'working_all_fields'} = 1;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 

  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  my ($dbh,$version);
  
  $version='Interbase ?';
  
  $dbh=$self->connect();
  eval { $version =   $dbh->func('version','ib_database_info')->{'version'}; }; 
  $dbh->disconnect;
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}

#
# Connection with optional disabling of logging
#

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0, AutoCommit => 1}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";

  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#
# If one uses $main::opt_fast then one is allowed to use
# non standard types to get better speed.
#

sub create
{
  my($self,$table_name,$fields,$index,$options) = @_;
  my($query,@queries,@keys,@indexes);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
#    $field =~ s/ big_decimal/ decimal/i;
    $field =~ s/ double/ double precision/i;
    $field =~ s/ tinyint/ smallint/i;
    $field =~ s/ mediumint/ integer/i;
    $field =~ s/\bint\b/integer/i;
    $field =~ s/ float\(\d,\d\)/ float/i;
    $field =~ s/ smallint\(\d\)/ smallint/i;
    $field =~ s/ integer\(\d\)/ integer/i;
    $query.= $field . ',';
  }
  foreach $ind (@$index)
  {
    if ( $ind =~ /(\bKEY\b)|(\bUNIQUE\b)/i ){
      push(@keys,"ALTER TABLE $table_name ADD $ind");
    }else{
      my @fields = split(' ',$ind);
      my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
      push(@indexes,$query);
    }
  }
  substr($query,-1)=")";		# Remove last ',';
  $query.=" $options" if (defined($options));
  push(@queries,$query,@keys,@indexes);
  return @queries;
}

sub insert_file {
  my($self,$dbname, $file) = @_;
  print "insert of an ascii file isn't supported by InterBase\n";
  return 0;
}

#
# Do any conversions to the ANSI SQL query so that the database can handle it
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub drop_index {
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 1 if ($DBI::errstr =~ /Table locked by another cursor/);
  return 0;
}

sub small_rollback_segment
{
  return 1;
}

sub reconnect_on_errors
{
  return 1;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

#############################################################################
#	     Configuration for FrontBase 
#############################################################################

package db_FrontBase;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "FrontBase";
  $self->{'data_source'}	= "DBI:FB:dbname=$database;host=$host";
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "varchar(8000000)";
  $self->{'text'}		= "varchar(8000000)";
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= ' restrict';
  $self->{'transactions'}	= 1; # Transactions enabled
  $self->{'error_on_execute_means_zero_rows'}=1;

  $limits{'max_conditions'}	= 5427; # (Actually not a limit)
  # The following should be 8192, but is smaller because Frontbase crashes..
  $limits{'max_columns'}	= 150;	# Max number of columns in table
  $limits{'max_tables'}		= 5000;	# 10000 crashed FrontBase
  $limits{'max_temporary_tables'}= $limits{"max_tables"};
  $limits{'max_text_size'}	= 65000; # Max size with default buffers.
  $limits{'query_size'}		= 8000000; # Max size with default buffers.
  $limits{'max_index'}		= 38; # Max number of keys
  $limits{'max_index_parts'}	= 20; # Max segments/key
  $limits{'max_column_name'}	= 128; # max table and column name

  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables
  $limits{'load_data_infile'}	= 1; # Has load data infile
  $limits{'lock_tables'}	= 0; # Has lock tables
  $limits{'functions'}		= 1; # Has simple functions (+/-)
  $limits{'group_functions'}	= 1; # Have group functions
  $limits{'group_distinct_functions'}= 0; # Have count(distinct)
  $limits{'select_without_from'}= 0;
  $limits{'multi_drop'}		= 0; # Drop table cannot take many tables
  $limits{'subqueries'}		= 1; # Supports sub-queries.
  $limits{'left_outer_join'}	= 1; # Supports left outer joins
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'having_with_alias'}  = 0; # Can use aliases in HAVING
  $limits{'having_with_group'}	= 0; # Can use group functions in HAVING
  $limits{'like_with_column'}	= 1; # Can use column1 LIKE column2
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1'
  $limits{'group_by_position'}  = 0; # Use of 'GROUP BY 1'
  $limits{'alter_table'}	= 1; # Have ALTER TABLE
  $limits{'alter_add_multi_col'}= 0; # Have ALTER TABLE t add a int,add b int;
  $limits{'alter_table_dropcol'}= 0; # Have ALTER TABLE DROP column
  $limits{'insert_multi_value'} = 1;

  $limits{'group_func_extra_std'} = 0; # Does not have group function std().

  $limits{'func_odbc_mod'}	= 0; # Have function mod.
  $limits{'func_extra_%'}	= 0; # Does not have % as alias for mod()
  $limits{'func_odbc_floor'}	= 0; # Has func_odbc_floor function
  $limits{'func_extra_if'}	= 0; # Does not have function if.
  $limits{'column_alias'}	= 1; # Alias for fields in select statement.
  $limits{'NEG'}		= 1; # Supports -id
  $limits{'func_extra_in_num'}	= 0; # Has function in
  $limits{'limit'}		= 0; # Does not support the limit attribute
  $limits{'insert_select'}	= 0;
  $limits{'order_by_unused'}	= 0;

  # We don't get an error for duplicate row in 'test-insert'
  $limits{'unique_index'}	= 0; # Unique index works or not
  # We can't use a blob as a normal string (we got a wierd error)
  $limits{'working_blobs'}	= 0;
  # 'select min(region),max(region) from bench1' kills the server after a while
  $limits{'group_func_sql_min_str'} = 0;
  # If you do select f1,f2,f3...f200 from table, Frontbase dies.
  $limits{'working_all_fields'} = 0;
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 

  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  my ($dbh,$sth,$version,@row);

#  $dbh=$self->connect();
#
#  Pick up SQLGetInfo option SQL_DBMS_VER (18)
#
  #$version = $dbh->func(18, GetInfo);
  $version="FrontBase 3.3";
#  $dbh->disconnect;
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}

#
# Connection with optional disabling of logging
#

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, 
		    $main::opt_user,
		    $main::opt_password,
		    { PrintError => 0 , 
		      'fb_host'=>$main::opt_host
		    }) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";
  $db->{AutoCommit}=1;
  # $dbh->do("SET OPTION LOG_OFF=1,UPDATE_LOG=0");
  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#
# If one uses $main::opt_fast then one is allowed to use
# non standard types to get better speed.
#

sub create
{
  my($self,$table_name,$fields,$index,$options) = @_;
  my($query,@queries,@indexes,@keys);

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    $field =~ s/ blob/ varchar(32000)/i;
    $field =~ s/ big_decimal/ float/i;
    $field =~ s/ double/ float/i;
    $field =~ s/ tinyint/ smallint/i;
    $field =~ s/ mediumint/ int/i;
    $field =~ s/ integer/ int/i;
    $field =~ s/ float\(\d,\d\)/ float/i;
    $field =~ s/ smallint\(\d\)/ smallint/i;
    $field =~ s/ int\(\d\)/ int/i;
    $query.= $field . ',';
  }
  foreach $ind (@$index)
  {
#    my @index;
    if ( $ind =~ /(\bKEY\b)|(\bUNIQUE\b)/i ){
      push(@keys,"ALTER TABLE $table_name ADD $ind");
    }else{
      my @fields = split(' ',$ind);
      my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
      push(@indexes,$query);
    }
  }
  substr($query,-1)=")";		# Remove last ',';
  $query.=" $options" if (defined($options));
  push(@queries,$query,@keys,@indexes);
  return @queries;
}

sub insert_file {
  my($self,$dbname, $file) = @_;
  print "insert of an ascii file isn't supported by InterBase\n";
  return 0;
}

#
# Do any conversions to the ANSI SQL query so that the database can handle it
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub drop_index {
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 0 if ($DBI::errstr =~ /No raw data handle/);
  return 1;
}

sub small_rollback_segment
{
  return 0;
}

sub reconnect_on_errors
{
  return 1;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

#############################################################################
#	     Configuration for SAPDB 
#############################################################################

package db_sapdb;

sub new
{
  my ($type,$host,$database)= @_;
  my $self= {};
  my %limits;
  bless $self;

  $self->{'cmp_name'}		= "sapdb";
  $self->{'data_source'}	= "DBI:SAP_DB:$database";
  $self->{'limits'}		= \%limits;
  $self->{'blob'}		= "LONG"; # *
  $self->{'text'}		= "LONG"; # *
  $self->{'double_quotes'}	= 1; # Can handle:  'Walker''s'
  $self->{'drop_attr'}		= "";
  $self->{'transactions'}	= 1; # Transactions enabled *
  $self->{'char_null'}          = "";
  $self->{'numeric_null'}       = "";

  $limits{'max_conditions'}	= 9999; # (Actually not a limit) *
  $limits{'max_columns'}	= 1023;	# Max number of columns in table *
  $limits{'max_tables'}		= 65000;	# Should be big enough * unlimited actually
  $limits{'max_temporary_tables'}= $limits{"max_tables"};
  $limits{'max_text_size'}	= 15000; # Max size with default buffers. 
  $limits{'query_size'}		= 64*1024; # Max size with default buffers. *64 kb by default. May be set by system variable 
  $limits{'max_index'}		= 510; # Max number of keys *
  $limits{'max_index_parts'}	= 16; # Max segments/key *
  $limits{'max_column_name'}	= 32; # max table and column name * 

  $limits{'join_optimizer'}	= 1; # Can optimize FROM tables *
  $limits{'load_data_infile'}	= 0; # Has load data infile *
  $limits{'lock_tables'}	= 1; # Has lock tables 
  $limits{'functions'}		= 1; # Has simple functions (+/-) *
  $limits{'group_functions'}	= 1; # Have group functions *
  $limits{'group_func_sql_min_str'} = 1; # Can execute MIN() and MAX() on strings *
  $limits{'group_distinct_functions'}= 1; # Have count(distinct)  *
  $limits{'select_without_from'}= 0; # Cannot do 'select 1';  *
  $limits{'multi_drop'}		= 0; # Drop table cannot take many tables *
  $limits{'subqueries'}		= 1; # Supports sub-queries. *
  $limits{'left_outer_join'}	= 1; # Supports left outer joins *
  $limits{'table_wildcard'}	= 1; # Has SELECT table_name.*
  $limits{'having_with_alias'}  = 0; # Can use aliases in HAVING *
  $limits{'having_with_group'}	= 1; # Can use group functions in HAVING *
  $limits{'like_with_column'}	= 1; # Can use column1 LIKE column2 *
  $limits{'order_by_position'}  = 1; # Can use 'ORDER BY 1' *
  $limits{'group_by_position'}  = 0; # Cannot use 'GROUP BY 1' *
  $limits{'alter_table'}	= 1; # Have ALTER TABLE *
  $limits{'alter_add_multi_col'}= 1; # Have ALTER TABLE t add a int,add b int; *
  $limits{'alter_table_dropcol'}= 1; # Have ALTER TABLE DROP column  *
  $limits{'insert_multi_value'} = 0; # INSERT ... values (1,2),(3,4) *

  $limits{'group_func_extra_std'} = 0; # Does not have group function std().

  $limits{'func_odbc_mod'}	= 0; # Have function mod. *
  $limits{'func_extra_%'}	= 0; # Does not have % as alias for mod() *
  $limits{'func_odbc_floor'}	= 1; # Has func_odbc_floor function *
  $limits{'func_extra_if'}	= 0; # Does not have function if. *
  $limits{'column_alias'}	= 1; # Alias for fields in select statement. *
  $limits{'NEG'}		= 1; # Supports -id *
  $limits{'func_extra_in_num'}	= 0; # Has function in *
  $limits{'limit'}		= 0; # Does not support the limit attribute *
  $limits{'working_blobs'}	= 1; # If big varchar/blobs works *
  $limits{'order_by_unused'}	= 1; # 
  $limits{'working_all_fields'} = 1; #
  $limits{'multi_distinct'}     = 1; # allows select count(distinct a),count(distinct b).. 


  return $self;
}

#
# Get the version number of the database
#

sub version
{
  my ($self)=@_;
  my ($dbh,$sth,$version,@row);

  $dbh=$self->connect();
  $sth = $dbh->prepare("SELECT KERNEL FROM VERSIONS") or die $DBI::errstr;
  $version="SAP DB (unknown)";
  if ($sth->execute && (@row = $sth->fetchrow_array)
      && $row[0] =~ /([\d\.]+)/)
  {
    $version=$row[0];
    $version =~ s/KERNEL/SAP DB/i; 
  }
  $sth->finish;
  $dbh->disconnect;
  $version .= "/ODBC" if ($self->{'data_source'} =~ /:ODBC:/);
  return $version;
}

#
# Connection with optional disabling of logging
#

sub connect
{
  my ($self)=@_;
  my ($dbh);
  $dbh=DBI->connect($self->{'data_source'}, $main::opt_user,
		    $main::opt_password,{ PrintError => 0, AutoCommit => 1}) ||
		      die "Got error: '$DBI::errstr' when connecting to " . $self->{'data_source'} ." with user: '$main::opt_user' password: '$main::opt_password'\n";

  return $dbh;
}

#
# Returns a list of statements to create a table
# The field types are in ANSI SQL format.
#

sub create
{
  my($self,$table_name,$fields,$index,$options) = @_;
  my($query,@queries,$nr);
  my @index;
  my @keys;

  $query="create table $table_name (";
  foreach $field (@$fields)
  {
    $field =~ s/\bmediumint\b/int/i;
    $field =~ s/\btinyint\b/int/i;
    $field =~ s/ int\(\d\)/ int/i;
    $field =~ s/BLOB/LONG/i;
    $field =~ s/INTEGER\s*\(\d+\)/INTEGER/i;
    $field =~ s/SMALLINT\s*\(\d+\)/SMALLINT/i;
    $field =~ s/FLOAT\s*\((\d+),\d+\)/FLOAT\($1\)/i;
    $field =~ s/DOUBLE/FLOAT\(38\)/i;
    $field =~ s/DOUBLE\s+PRECISION/FLOAT\(38\)/i;
    $query.= $field . ',';
  }
  $nr=0;
  foreach $ind (@$index)
  {
    if ( $ind =~ /\bKEY\b/i ){
      push(@keys,"ALTER TABLE $table_name ADD $ind");
    } elsif ($ind =~ /^unique.*\(([^\(]*)\)$/i)  {
      $nr++;
      my $query="create unique index ${table_name}_$nr on $table_name ($1)";
      push(@index,$query);
    }else{
      my @fields = split(' ',$ind);
      my $query="CREATE INDEX $fields[1] ON $table_name $fields[2]";
      push(@index,$query);
    }
  }
  substr($query,-1)=")";		# Remove last ',';
  $query.=" $options" if (defined($options));
  push(@queries,$query);
  push(@queries,@keys);
  push(@queries,@index);
  return @queries;
}

sub insert_file {
  my($self,$dbname, $file) = @_;
  print "insert of an ascii file isn't supported by SAPDB\n";
  return 0;
}

#
# Do any conversions to the ANSI SQL query so that the database can handle it
#

sub query {
  my($self,$sql) = @_;
  return $sql;
}

sub drop_index {
  my ($self,$table,$index) = @_;
  return "DROP INDEX $index";
}

#
# Abort if the server has crashed
# return: 0 if ok
#	  1 question should be retried
#

sub abort_if_fatal_error
{
  return 0;
}

sub small_rollback_segment
{
  return 0;
}

sub reconnect_on_errors
{
  return 0;
}

sub fix_for_insert
{
  my ($self,$cmd) = @_;
  return $cmd;
}

1;