summaryrefslogtreecommitdiff
path: root/sw/source/ui/dbui/dbmgr.cxx
blob: a41b77267436f2d85cc470aa1ddbb173fe6e755a (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
/*************************************************************************
 *
 *  $RCSfile: dbmgr.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: os $ $Date: 2000-10-20 14:18:01 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  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
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/


#ifdef PRECOMPILED
#include "ui_pch.hxx"
#endif

#pragma hdrstop

#if STLPORT_VERSION>=321
#include <cstdarg>
#endif

#include <stdio.h>

#ifndef _UCBHELPER_CONTENT_HXX
#include <ucbhelper/content.hxx>
#endif
#ifndef _COM_SUN_STAR_UCB_XCOMMANDENVIRONMENT_HPP_
#include <com/sun/star/ucb/XCommandEnvironment.hpp>
#endif
#ifndef _COM_SUN_STAR_UCB_TRANSFERINFO_HPP_
#include <com/sun/star/ucb/TransferInfo.hpp>
#endif
#ifndef _COM_SUN_STAR_UCB_NAMECLASH_HPP_
#include <com/sun/star/ucb/NameClash.hpp>
#endif
#ifndef _LSTBOX_HXX //autogen
#include <vcl/lstbox.hxx>
#endif
#ifndef _TOOLS_TEMPFILE_HXX
#include <tools/tempfile.hxx>
#endif
#ifndef SVTOOLS_URIHELPER_HXX
#include <svtools/urihelper.hxx>
#endif
#ifndef _SVSTDARR_HXX
#define _SVSTDARR_STRINGSDTOR
#include <svtools/svstdarr.hxx>
#endif
#ifndef _ZFORLIST_HXX //autogen
#include <svtools/zforlist.hxx>
#endif
#ifndef _ZFORMAT_HXX //autogen
#include <svtools/zformat.hxx>
#endif
#ifndef _SFXSTRITEM_HXX //autogen
#include <svtools/stritem.hxx>
#endif
#ifndef _SFXENUMITEM_HXX //autogen
#include <svtools/eitem.hxx>
#endif
#ifndef _SFXINIMGR_HXX //autogen
#include <svtools/iniman.hxx>
#endif
#ifndef _SFX_PRINTER_HXX //autogen
#include <sfx2/printer.hxx>
#endif
#ifndef _SFXDOCFILE_HXX //autogen
#include <sfx2/docfile.hxx>
#endif
#ifndef _SFX_PROGRESS_HXX //autogen
#include <sfx2/progress.hxx>
#endif
#ifndef _SFX_DOCFILT_HACK_HXX //autogen
#include <sfx2/docfilt.hxx>
#endif
#ifndef _SFXDISPATCH_HXX //autogen
#include <sfx2/dispatch.hxx>
#endif
#ifndef _SBAOBJ_HXX //autogen
#include <offmgr/sbaobj.hxx>
#endif
#ifndef _SBA_SBADB_HXX //autogen
#include <offmgr/sbadb.hxx>
#endif
#ifndef _SBAITEMS_HRC
#include <offmgr/sbaitems.hrc>
#endif
#ifndef _SBAITEMS_HXX
#include <offmgr/sbaitems.hxx>
#endif
#ifndef _OFF_APP_HXX //autogen
#include <offmgr/app.hxx>
#endif
#ifndef _SDB_SDBCURS_HXX //autogen
#include <sdb/sdbcurs.hxx>
#endif
#ifndef _MAILENUM_HXX //autogen
#include <goodies/mailenum.hxx>
#endif

#ifndef _SWTYPES_HXX
#include <swtypes.hxx>
#endif
#ifndef _SWMODULE_HXX
#include <swmodule.hxx>
#endif
#ifndef _VIEW_HXX
#include <view.hxx>
#endif
#ifndef _DOCSH_HXX
#include <docsh.hxx>
#endif
#ifndef _EDTWIN_HXX
#include <edtwin.hxx>
#endif
#ifndef _WRTSH_HXX
#include <wrtsh.hxx>
#endif
#ifndef _FLDBAS_HXX
#include <fldbas.hxx>
#endif
#ifndef _INITUI_HXX
#include <initui.hxx>
#endif
#ifndef _SWUNDO_HXX
#include <swundo.hxx>
#endif
#ifndef _FLDDAT_HXX
#include <flddat.hxx>
#endif
#ifndef _SWMODULE_HXX
#include <swmodule.hxx>
#endif
#ifndef _MODCFG_HXX
#include <modcfg.hxx>
#endif
#ifndef _SWPRTOPT_HXX
#include <swprtopt.hxx>
#endif
#ifndef _SHELLIO_HXX
#include <shellio.hxx>
#endif
#ifndef _DBUI_HXX
#include <dbui.hxx>
#endif
#ifndef _DBMGR_HXX
#include <dbmgr.hxx>
#endif
#ifndef _DOC_HXX
#include <doc.hxx>
#endif
#ifndef _SWWAIT_HXX
#include <swwait.hxx>
#endif

#ifndef _DBUI_HRC
#include <dbui.hrc>
#endif
#ifndef _GLOBALS_HRC
#include <globals.hrc>
#endif
#ifndef _STATSTR_HRC
#include <statstr.hrc>
#endif

#ifdef REPLACE_OFADBMGR
#ifndef _SFXREQUEST_HXX
#include <sfx2/request.hxx>
#endif
#ifndef _HINTIDS_HXX
#include <hintids.hxx>
#endif
#ifndef _UTL_DB_CONVERSION_HXX_
#include <unotools/dbconversion.hxx>
#endif
#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#endif
#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
#include <com/sun/star/sdbc/XDataSource.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XTABLESSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_XQUERIESSUPPLIER_HPP_
#include <com/sun/star/sdb/XQueriesSupplier.hpp>
#endif
#ifndef _COM_SUN_STAR_SDB_XCOLUMN_HPP_
#include <com/sun/star/sdb/XColumn.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
#include <com/sun/star/sdbc/DataType.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_XSTATEMENT_HPP_
#include <com/sun/star/sdbc/XStatement.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_RESULTSETTYPE_HPP_
#include <com/sun/star/sdbc/ResultSetType.hpp>
#endif
//#ifndef _COM_SUN_STAR_SDB_XDATABASEACCESS_HPP_
//#include <com/sun/star/sdb/XDatabaseAccess.hpp>
//#endif
#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif
#ifndef _COMPHELPER_PROCESSFACTORY_HXX_
#include <comphelper/processfactory.hxx>
#endif
#ifndef _ISOLANG_HXX
#include <tools/isolang.hxx>
#endif
#ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTYPES_HPP_
#include <com/sun/star/util/XNumberFormatTypes.hpp>
#endif
#ifndef _UTL_UNO3_DB_TOOLS_HXX_
#include <unotools/dbtools.hxx>
#endif
#ifndef _SVX_LANGITEM_HXX
#include <svx/langitem.hxx>
#endif
#ifndef _SVX_UNOMID_HXX
#include <svx/unomid.hxx>
#endif
#ifndef _NUMUNO_HXX
#include <svtools/numuno.hxx>
#endif
#else

#endif  //REPLACE_OFADBMGR

#ifdef REPLACE_OFADBMGR
using namespace rtl;
using namespace com::sun::star::container;
using namespace com::sun::star::lang;
using namespace com::sun::star::sdb;
using namespace com::sun::star::sdbc;
using namespace com::sun::star::sdbcx;
using namespace com::sun::star::beans;
using namespace com::sun::star::util;
#define C2S(cChar) String::CreateFromAscii(cChar)
#endif

using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ucb;

#define C2U(char) rtl::OUString::createFromAscii(char)

#define DB_SEP_SPACE    0
#define DB_SEP_TAB      1
#define DB_SEP_RETURN   2
#define DB_SEP_NEWLINE  3

#ifdef REPLACE_OFADBMGR
SV_IMPL_PTRARR(SwDSParamArr, SwDSParamPtr);

/* -----------------------------17.07.00 17:04--------------------------------

 ---------------------------------------------------------------------------*/
BOOL lcl_MoveAbsolute(SwDSParam* pParam, long nAbsPos)
{
    BOOL bRet = FALSE;
    try
    {
        if(pParam->bScrollable)
        {
            bRet = pParam->xResultSet->absolute( nAbsPos );
        }
        else
        {
            pParam->nSelectionIndex = 0;
            pParam->xResultSet = pParam->xStatement->executeQuery( pParam->sStatement );
            bRet = TRUE;
            while(nAbsPos >= 0 && bRet)
            {
                bRet &= !pParam->xResultSet->next();
                pParam->nSelectionIndex++;
                nAbsPos--;
            }
            bRet &= nAbsPos != -1;
        }
    }
    catch(Exception aExcept)
    {
        DBG_ERROR("exception caught")
    }
    return bRet;
}
/* -----------------------------17.07.00 17:23--------------------------------

 ---------------------------------------------------------------------------*/
BOOL lcl_GetColumnCnt(SwDSParam* pParam,
    const String& rColumnName, long nLanguage, String& rResult, double* pNumber)
{
    Reference< XColumnsSupplier > xColsSupp( pParam->xResultSet, UNO_QUERY );
    Reference <XNameAccess> xCols = xColsSupp->getColumns();
    if(!xCols->hasByName(rColumnName))
        return FALSE;
    Any aCol = xCols->getByName(rColumnName);
    Reference< XPropertySet > xColumnProps;
    if(aCol.hasValue())
        xColumnProps = *(Reference< XPropertySet >*)aCol.getValue();

    SwDBFormatData aFormatData;
    aFormatData.aNullDate = pParam->aNullDate;
    aFormatData.xFormatter = pParam->xFormatter;

    String sLanguage, sCountry;
    ::ConvertLanguageToIsoNames( nLanguage, sLanguage, sCountry );
    aFormatData.aLocale.Language = sLanguage;
    aFormatData.aLocale.Country = sCountry;

    DBG_ERROR("pFormat unset!")
    rResult = SwNewDBMgr::GetDBField( xColumnProps, aFormatData, pNumber);
    return TRUE;
};
#endif
/*--------------------------------------------------------------------
    Beschreibung: Daten importieren
 --------------------------------------------------------------------*/

BOOL SwNewDBMgr::Merge( USHORT nOpt, SwWrtShell* pSh,
                        const String& rStatement,
                        const SbaSelectionListRef xSelectionList,
#ifdef REPLACE_OFADBMGR
                        const String& rDataSource,
                        const String& rTableOrQuery,
#else
                        const String& rDBName,
#endif
                        const String *pPrinter)
{
#ifdef REPLACE_OFADBMGR
    ChgDBName(pSh, rDataSource, rTableOrQuery,rStatement);
#else
    ChgDBName(pSh, rDBName, rStatement);
#endif
    // Falls noch nicht offen, spaetestens hier

#ifdef REPLACE_OFADBMGR
    if(!OpenMergeSource(rDataSource, rTableOrQuery, rStatement, xSelectionList))
        return FALSE;
#else
    if(!OpenDB(FALSE, pSh->GetDBDesc()))
        return FALSE;
#endif

    if (IsInitDBFields())
    {
        // Bei Datenbankfeldern ohne DB-Name DB-Name von Dok einsetzen
        SvStringsDtor aDBNames(1, 1);
        aDBNames.Insert( new String(), 0);
        pSh->ChangeDBFields( aDBNames, pSh->GetDBName());
        SetInitDBFields(FALSE);
    }
#ifdef REPLACE_OFADBMGR
    const SbaSelectionList* pSelList = 0;
    if( xSelectionList.Is() && (long)xSelectionList->GetObject(0) != -1L )
    {
        if( xSelectionList->Count() )
            pSelList = &xSelectionList;
    }
#else
    OfaDBParam& rParam = GetDBData(FALSE);
    ChangeStatement(FALSE, rStatement);
    const SbaSelectionList* pSelList = 0;
    rParam.pSelectionList->Clear();
    if( xSelectionList.Is() && (long)xSelectionList->GetObject(0) != -1L )
    {
        *rParam.pSelectionList = *xSelectionList;
        if( xSelectionList->Count() )
            pSelList = &xSelectionList;
    }
#endif

    BOOL bRet = TRUE;
    switch(nOpt)
    {
        case DBMGR_MERGE:
            bRet = Merge(pSh);   // Mischen
            break;

        case DBMGR_MERGE_MAILMERGE: // Serienbrief
            {
            SfxDispatcher *pDis = pSh->GetView().GetViewFrame()->GetDispatcher();
            if (pPrinter)   // Aufruf kommt aus dem Basic
            {
                SfxBoolItem aSilent( SID_SILENT, TRUE );
                if (pPrinter)
                {
                    SfxStringItem aPrinterName(SID_PRINTER_NAME, *pPrinter);
                    pDis->Execute( SID_PRINTDOC, SFX_CALLMODE_SYNCHRON,
                                   &aPrinterName, &aSilent, 0L );
                }
                else
                {
                    pDis->Execute( SID_PRINTDOC, SFX_CALLMODE_SYNCHRON,
                                   &aSilent, 0L );
                }
            }
            else
                pDis->Execute(SID_PRINTDOC, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD);
            }
            break;

        case DBMGR_MERGE_MAILING:
            bRet = MergeMailing(pSh);   // Mailing
            break;

        case DBMGR_MERGE_MAILFILES:
            bRet = MergeMailFiles(pSh); // Serienbriefe als Dateien abspeichern
            break;

        default:        // Einfuegen der selektierten Eintraege
                        // (war: InsertRecord)
#ifdef REPLACE_OFADBMGR
            ImportFromConnection(pSh );
#else
            ImportFromConnection(pSh, pSelList );
#endif
            break;
    }

#ifdef REPLACE_OFADBMGR
    EndMerge();
#else
    CloseAll();
#endif
    return bRet;
}
/*--------------------------------------------------------------------
    Beschreibung: Daten importieren
 --------------------------------------------------------------------*/


BOOL SwNewDBMgr::Merge(SwWrtShell* pSh)
{
    pSh->StartAllAction();
#ifdef REPLACE_OFADBMGR
#else
    bInMerge = TRUE;

    // 1. Satz positionieren, Evaluierung ueber die Felder
    for (USHORT i = 0; i < aDBDataArr.Count(); i++)
    {
        OfaDBParam* pParam = aDBDataArr[i];

        // Alle Im Dok enthaltenen Datenbanken oeffnen und Cursorpos initialisieren
        if (OpenDB(FALSE, pParam->GetDBName()))
        {
            if (pParam->GetCursor())
                Flush(FALSE);   // Cursor initialisieren
            ToFirstSelectedRecord(FALSE);
        }
    }
#endif

/*  for (ULONG i = 0 ; i < GetDBData().pSelectionList->Count(); i++)
    {
        ULONG nIndex = (ULONG)GetDBData().pSelectionList->GetObject(i);
        DBG_TRACE(String(nIndex));
    }*/

    pSh->ViewShell::UpdateFlds(TRUE);
    pSh->SetModified();

#ifdef REPLACE_OFADBMGR
#else
    bInMerge = FALSE;
#endif

    pSh->EndAllAction();

    return TRUE;
}

/*--------------------------------------------------------------------
    Beschreibung: Daten importieren
 --------------------------------------------------------------------*/


/*void SwNewDBMgr::UpdateImport(    const BOOL bBasic, SwWrtShell* pSh,
                                const String& rDBName,
                                const String& rStatement,
                                const SbaSelectionListRef xSelectionList )
{
    ChgDBName(pSh, rDBName, rStatement);

    if( OpenDB( bBasic, pSh->GetDBDesc()) )
    {
        OfaDBParam& rParam = GetDBData(bBasic);

        ChangeStatement(bBasic, rStatement);

        const SbaSelectionList* pSelList = 0;
        rParam.pSelectionList->Clear();
        if( xSelectionList.Is() && -1L != (long)xSelectionList->GetObject(0) )
        {
            *rParam.pSelectionList = *xSelectionList;
            if( xSelectionList->Count() )
                pSelList = &xSelectionList;
        }

        ImportFromConnection( bBasic, pSh, pSelList );
    }
} */

/*--------------------------------------------------------------------
    Beschreibung:
 --------------------------------------------------------------------*/


#ifdef REPLACE_OFADBMGR
void SwNewDBMgr::ImportFromConnection(  SwWrtShell* pSh )
#else
void SwNewDBMgr::ImportFromConnection(  SwWrtShell* pSh,
                                        const SbaSelectionList* pSelList )
#endif
{
#ifdef REPLACE_OFADBMGR
    if(pMergeData && !pMergeData->bEndOfDB)
#else
    OfaDBParam& rParam = GetDBData(FALSE);
    ASSERT(rParam.GetCursor(), "Cursor");

    if( ToFirstSelectedRecord( FALSE ) && IsSuccessful( FALSE ) )
#endif
    {
#ifdef REPLACE_OFADBMGR
#else
        //  Spaltenkoepfe
        SbaDBDataDefRef aDBDef = OpenColumnNames(FALSE);
        if( aDBDef.Is() )
#endif
        {
            pSh->StartAllAction();
            pSh->StartUndo(0);
            BOOL bGroupUndo(pSh->DoesGroupUndo());
            pSh->DoGroupUndo(FALSE);

            if( pSh->HasSelection() )
                pSh->DelRight();

            SwWait *pWait = 0;

#ifdef REPLACE_OFADBMGR
#else
            if( pSelList )
            {
                for( ULONG i = 0; i < pSelList->Count(); ++i )
                {

                    ULONG nIndex = (ULONG)pSelList->GetObject( i );

                    ASSERT(nIndex >= rParam.CurrentPos(),
                        "Zu lesender Datensatz < vorhergehender Datensatz!");

                    // N„chsten zu lesenden Datensatz ansteuern
                    GotoRecord( nIndex );
                    ImportDBEntry(&aDBDef, pSh);

                    if( i == 10 )
                        pWait = new SwWait( *pSh->GetView().GetDocShell(), TRUE );
                }
            }
            else
#endif
            {
                ULONG i = 0;
                do {

#ifdef REPLACE_OFADBMGR
                    ImportDBEntry(pSh);
#else
                    ImportDBEntry(&aDBDef, pSh);
                    rParam.GetCursor()->Next();
                    rParam.CurrentPos()++;
#endif
                    if( 10 == ++i )
                        pWait = new SwWait( *pSh->GetView().GetDocShell(), TRUE);

#ifdef REPLACE_OFADBMGR
                } while(ToNextMergeRecord());
#else
                } while( !rParam.GetCursor()->IsOffRange() );
#endif
            }

            pSh->DoGroupUndo(bGroupUndo);
            pSh->EndUndo(0);
            pSh->EndAllAction();
            delete pWait;
        }
    }
#ifdef REPLACE_OFADBMGR
#else
    CloseAll();
#endif
}


/*-----------------24.02.97 10.30-------------------

--------------------------------------------------*/

String  lcl_FindColumn(const String& sFormatStr,USHORT  &nUsedPos, BYTE &nSeparator)
{
    String sReturn;
    USHORT nLen = sFormatStr.Len();
    nSeparator = 0xff;
    while(nUsedPos < nLen && nSeparator == 0xff)
    {
        sal_Unicode cAkt = sFormatStr.GetChar(nUsedPos);
        switch(cAkt)
        {
            case ',':
                nSeparator = DB_SEP_SPACE;
            break;
            case ';':
                nSeparator = DB_SEP_RETURN;
            break;
            case ':':
                nSeparator = DB_SEP_TAB;
            break;
            case '#':
                nSeparator = DB_SEP_NEWLINE;
            break;
            default:
                sReturn += cAkt;
        }
        nUsedPos++;

    }
    return sReturn;
}

/*--------------------------------------------------------------------
    Beschreibung:
 --------------------------------------------------------------------*/

inline String lcl_GetDBInsertMode( String sDBName )
{
    sDBName.SearchAndReplace( DB_DELIM, '.');
    return  SFX_APP()->GetIniManager()->Get( String::CreateFromAscii(
                RTL_CONSTASCII_STRINGPARAM( "DataBaseFormatInfo" )),
                FALSE, FALSE, sDBName );
}


#ifdef REPLACE_OFADBMGR
void SwNewDBMgr::ImportDBEntry(SwWrtShell* pSh)
#else
void SwNewDBMgr::ImportDBEntry(SbaDBDataDef* pDef, SwWrtShell* pSh)
#endif
{
#ifdef REPLACE_OFADBMGR
    if(pMergeData && !pMergeData->bEndOfDB)
#else
    OfaDBParam& rParam = GetDBData(FALSE);
    if( !rParam.GetCursor()->IsOffRange() )
#endif
    {
#ifdef REPLACE_OFADBMGR
          Reference< XColumnsSupplier > xColsSupp( pMergeData->xResultSet, UNO_QUERY );
          Reference <XNameAccess> xCols = xColsSupp->getColumns();
        String sSymDBName(pMergeData->sDataSource);
        sSymDBName += DB_DELIM;
        sSymDBName += pMergeData->sTableOrQuery;
        String sFormatStr( lcl_GetDBInsertMode( sSymDBName ));
#else
        const ODbRowRef&  xRow = rParam.GetCursor()->GetRow();
        ULONG nCount = (UINT16)xRow->size();
        String sFormatStr( lcl_GetDBInsertMode( rParam.GetSymDBName() ));
#endif
        USHORT nFmtLen = sFormatStr.Len();
        if( nFmtLen )
        {
            const char cSpace = ' ';
            const char cTab = '\t';
            USHORT nUsedPos = 0;
            BYTE    nSeparator;
            String sColumn = lcl_FindColumn(sFormatStr, nUsedPos, nSeparator);
            while( sColumn.Len() )
            {
#ifdef REPLACE_OFADBMGR
                if(!xCols->hasByName(sColumn))
                    return;
                Any aCol = xCols->getByName(sColumn);
                Reference< XPropertySet > xColumnProp = *(Reference< XPropertySet >*)aCol.getValue();;
                if(xColumnProp.is())
                {
                    SwDBFormatData aDBFormat;
                    String sInsert = GetDBField( xColumnProp,   aDBFormat);
#else
                int nColumn = GetColumnPos(DBMGR_STD, sColumn);
                if(nColumn > 0)
                {
                    String sInsert = ImportDBField(nColumn, pDef, xRow);
#endif
                    if( DB_SEP_SPACE == nSeparator )
                            sInsert += cSpace;
                    else if( DB_SEP_TAB == nSeparator)
                            sInsert += cTab;
                    pSh->Insert(sInsert);
                    if( DB_SEP_RETURN == nSeparator)
                        pSh->SplitNode();
                    else if(DB_SEP_NEWLINE == nSeparator)
                            pSh->InsertLineBreak();
                }
                else
                {
                    // Spalte nicht gefunden -> Fehler anzeigen
                    String sInsert = '?';
                    sInsert += sColumn;
                    sInsert += '?';
                    pSh->Insert(sInsert);
                }
                sColumn = lcl_FindColumn(sFormatStr, nUsedPos, nSeparator);
            }
            pSh->SplitNode();
        }
        else
        {
            String sStr;
#ifdef REPLACE_OFADBMGR
            Sequence<OUString> aColNames = xCols->getElementNames();
            const OUString* pColNames = aColNames.getConstArray();
            long nLength = aColNames.getLength();
            for(long i = 0; i < nLength; i++)
            {
                Any aCol = xCols->getByName(pColNames[i]);
                Reference< XPropertySet > xColumnProp = *(Reference< XPropertySet >*)aCol.getValue();;
                SwDBFormatData aDBFormat;
                sStr += GetDBField( xColumnProp, aDBFormat);
                if (i < nLength - 1)
                    sStr += '\t';
            }
#else
            for (ULONG i = 1; i < nCount; i++)  // 0 = Bookmark
            {
                sStr += ImportDBField(i, pDef, xRow);
                if (i < nCount - 1)
                    sStr += '\t';
            }
#endif
            pSh->SwEditShell::Insert(sStr);
            pSh->SwFEShell::SplitNode();    // Zeilenvorschub
        }
    }
}

/*--------------------------------------------------------------------
    Beschreibung:
 --------------------------------------------------------------------*/


void SwNewDBMgr::ChgDBName(SwWrtShell* pSh,
#ifdef REPLACE_OFADBMGR
                        const String& rDataSource,
                        const String& rTableOrQuery,
#else
                        const String& rDBName,
#endif
                        const String& rStatement)
{
    if (pSh)
    {
#ifdef REPLACE_OFADBMGR
        String sNewDBName(rDataSource);
        sNewDBName += DB_DELIM;
        sNewDBName += rTableOrQuery;
#else
        String sNewDBName(ExtractDBName(rDBName));
#endif
        sNewDBName += ';';
        sNewDBName += rStatement;
        pSh->ChgDBName(sNewDBName);
    }
}

/*--------------------------------------------------------------------
    Beschreibung: Listbox mit Tabellenliste fuellen
 --------------------------------------------------------------------*/
#ifdef REPLACE_OFADBMGR
BOOL SwNewDBMgr::GetTableNames(ListBox* pListBox, const String& rDBName)
#else
BOOL SwNewDBMgr::GetTableNames(ListBox* pListBox, String sDBName)
#endif
{
    BOOL bRet = FALSE;
    String sOldTableName(pListBox->GetSelectEntry());
    pListBox->Clear();
#ifdef REPLACE_OFADBMGR
    Reference< XDataSource> xSource;
    Reference< XConnection> xConnection = SwNewDBMgr::GetConnection(rDBName, xSource);
    if(xConnection.is())
    {
        Reference<XTablesSupplier> xTSupplier = Reference<XTablesSupplier>(xConnection, UNO_QUERY);
        if(xTSupplier.is())
        {
            Reference<XNameAccess> xTbls = xTSupplier->getTables();
            Sequence<OUString> aTbls = xTbls->getElementNames();
            const OUString* pTbls = aTbls.getConstArray();
            for(long i = 0; i < aTbls.getLength(); i++)
                pListBox->InsertEntry(pTbls[i]);
        }
        Reference<XQueriesSupplier> xQSupplier = Reference<XQueriesSupplier>(xConnection, UNO_QUERY);
        if(xQSupplier.is())
        {
            Reference<XNameAccess> xQueries = xQSupplier->getQueries();
            Sequence<OUString> aQueries = xQueries->getElementNames();
            const OUString* pQueries = aQueries.getConstArray();
            for(long i = 0; i < aQueries.getLength(); i++)
                pListBox->InsertEntry(pQueries[i]);
        }
        if (sOldTableName.Len())
            pListBox->SelectEntry(sOldTableName);
        bRet = TRUE;
    }
#else

    sDBName = OFF_APP()->LocalizeDBName(NATIONAL2INI, sDBName);
    if (sDBName.Len())
    {
        SbaDatabaseRef pConnection = pSbaObject->GetDatabase(sDBName, TRUE);

        if (pConnection)
        {
            String sTableName;

            USHORT nCount = pConnection->GetObjectCount(dbTable);

            for (USHORT i = 0; i < nCount; i++)
            {
                sTableName = pConnection->GetObjectName(dbTable, i);
                pListBox->InsertEntry(sTableName);
            }

            nCount = pConnection->GetObjectCount(dbQuery);

            for (i = 0; i < nCount; i++)
            {
                sTableName = pConnection->GetObjectName(dbQuery, i);
                pListBox->InsertEntry(sTableName);
            }

            if (sOldTableName.Len())
                pListBox->SelectEntry(sOldTableName);
            if (!pListBox->GetSelectEntryCount())
                pListBox->SelectEntryPos(0);
            bRet = TRUE;
        }
    }
#endif
    return bRet;
}

/*--------------------------------------------------------------------
    Beschreibung: Listbox mit Spaltennamen einer Datenbank fuellen
 --------------------------------------------------------------------*/
#ifdef REPLACE_OFADBMGR
BOOL SwNewDBMgr::GetColumnNames(ListBox* pListBox,
            const String& rDBName, const String& rTableName, BOOL bAppend)
#else
BOOL SwNewDBMgr::GetColumnNames(ListBox* pListBox, String sDBName, BOOL bAppend)
#endif
{
    if (!bAppend)
        pListBox->Clear();
#ifdef REPLACE_OFADBMGR
    Reference< XDataSource> xSource;
    Reference< XConnection> xConnection = SwNewDBMgr::GetConnection(rDBName, xSource);
    Reference< XColumnsSupplier> xColsSupp = SwNewDBMgr::GetColumnSupplier(xConnection, rTableName);
    if(xColsSupp.is())
    {
        Reference <XNameAccess> xCols = xColsSupp->getColumns();
        const Sequence<OUString> aColNames = xCols->getElementNames();
        const OUString* pColNames = aColNames.getConstArray();
        for(int nCol = 0; nCol < aColNames.getLength(); nCol++)
        {
            pListBox->InsertEntry(pColNames[nCol]);
        }
    }
#else
    if (!sDBName.Len() || (!IsDBOpen(DBMGR_STD, sDBName) && !OpenDB(DBMGR_STD, sDBName, TRUE)))
        return(FALSE);

    SbaDBDataDefRef aDBDef = OpenColumnNames(DBMGR_STD);

    if (aDBDef.Is())
    {
        const SbaColumnList& rCols = aDBDef->GetOriginalColumns();

        for (USHORT i = 1; i <= rCols.Count(); i++)
        {
            const SbaNameItem* pNameItem = (const SbaNameItem*)&rCols.GetObject(i-1)->Get(SBA_DEF_FLTNAME);
            pListBox->InsertEntry(pNameItem->GetValue());
        }

        pListBox->SelectEntryPos(0);
    }
#endif
    return(TRUE);
}

/*--------------------------------------------------------------------
    Beschreibung: CTOR
 --------------------------------------------------------------------*/

SwNewDBMgr::SwNewDBMgr() :
#ifdef REPLACE_OFADBMGR
            pMergeData(0),
            bInMerge(FALSE),
#else
            OfaDBMgr(),
#endif
            nMergeType(DBMGR_INSERT),
            bInitDBFields(FALSE)
{
    pMergeList = new SbaSelectionList;
}
/* -----------------------------18.07.00 08:56--------------------------------

 ---------------------------------------------------------------------------*/
#ifdef REPLACE_OFADBMGR
SwNewDBMgr::~SwNewDBMgr()
{
}
#endif
/*--------------------------------------------------------------------
    Beschreibung:   Serienbrief drucken
 --------------------------------------------------------------------*/


BOOL SwNewDBMgr::MergePrint( SwView& rView,
                             SwPrtOptions& rOpt, SfxProgress& rProgress )
{
    SwWrtShell* pSh = &rView.GetWrtShell();
    //check if the doc is synchronized and contains at least one linked section
    BOOL bSynchronizedDoc = pSh->IsLabelDoc() && pSh->GetSectionFmtCount() > 1;
#ifdef REPLACE_OFADBMGR
    //merge source is already open
    rOpt.nMergeCnt = pMergeData && pMergeData->xSelectionList.Is() ?
                                    pMergeData->xSelectionList->Count() : 0;
#else
    OfaDBParam& rParam = GetDBData(FALSE);

    // 1. Satz positionieren, Evaluierung ueber die Felder
    for (USHORT i = 0; i < aDBDataArr.Count(); i++)
    {
        OfaDBParam* pParam = aDBDataArr[i];

        // Alle Im Dok enthaltenen Datenbanken oeffnen und Cursorpos initialisieren
        if (OpenDB(FALSE, pParam->GetDBName()))
        {
            if (pParam->GetCursor())
                Flush(FALSE);   // Cursor initialisieren
            ToFirstSelectedRecord(FALSE);
        }
    }

    OpenDB(FALSE, rParam.GetDBName());
    if (!ToFirstSelectedRecord(FALSE))
        return(FALSE);
    ODbRowRef xRow = GetCurSelectedRecord(FALSE);
    // keine Arme keine Kekse
    if(!xRow.is())
        return FALSE;

    bInMerge = TRUE;

    rOpt.nMergeCnt = GetDBData(FALSE).pSelectionList.Is()
                            ? GetDBData(FALSE).pSelectionList->Count()
                            : 0;
    rOpt.nMergeAct = 0;

    Flush(FALSE);   // Cursor initialisieren
#endif

//  if (IsPrintFromBasicDB())
//      rOpt.bSinglePrtJobs = IsSingleJobs();
//  else
//  {
        SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
        rOpt.bSinglePrtJobs = pModOpt->IsSinglePrintJob();
//  }

    SfxPrinter *pPrt = pSh->GetPrt();
    Link aSfxSaveLnk = pPrt->GetEndPrintHdl();
    if( rOpt.bSinglePrtJobs  )
        pPrt->SetEndPrintHdl( Link() );

    BOOL bNewJob = FALSE,
         bUserBreak = FALSE,
         bRet = FALSE;

    do {
#ifdef REPLACE_OFADBMGR

#else
        xRow = GetCurSelectedRecord(FALSE); // Naechste Selektion holen
        ULONG nOldRec = GetCurRecordId(FALSE);  // Alte Position merken
        if(xRow.Is())
#endif
        {
            pSh->ViewShell::UpdateFlds();
            ++rOpt.nMergeAct;
            rView.SfxViewShell::Print( rProgress ); // ggf Basic-Macro ausfuehren

            if( rOpt.bSinglePrtJobs && bRet )
            {
                //rOpt.bJobStartet = FALSE;
                bRet = FALSE;
            }

            if( pSh->Prt( rOpt, rProgress ) )
                bRet = TRUE;

            if( !pPrt->IsJobActive() )
            {
                bUserBreak = TRUE;
                bRet = FALSE;
                break;
            }
            if( !rOpt.bSinglePrtJobs )
            {
                String& rJNm = (String&)rOpt.GetJobName();
                rJNm.Erase();
            }
        }
#ifdef REPLACE_OFADBMGR
    } while( bSynchronizedDoc ? ExistsNextRecord() : ToNextMergeRecord());
#else
        // Kontext fuer ToNextSelectedRecord auf richtige Datenbank stellen:
        GetDBData(FALSE, &rParam.GetDBName());
        // Endlosschleifen durch "Erster Datensatz" verhindern:
        if (GetCurRecordId(FALSE) < nOldRec)
            ToSelectedRecord(FALSE, nOldRec);   // Alte Position restaurieren
    } while( xRow.is() && GotoNextSelectedRecord( bSynchronizedDoc) );
#endif

    if( rOpt.bSinglePrtJobs )
    {
        pSh->GetPrt()->SetEndPrintHdl( aSfxSaveLnk );
        if ( !bUserBreak && !pSh->GetPrt()->IsJobActive() )     //Schon zu spaet?
            aSfxSaveLnk.Call( pSh->GetPrt() );
    }

    rOpt.nMergeCnt = 0;
    rOpt.nMergeAct = 0;

    bInMerge = FALSE;

    nMergeType = DBMGR_INSERT;

    SwDocShell* pDocSh = rView.GetDocShell();
    SfxViewFrame *pTmpFrm = SfxViewFrame::GetFirst(pDocSh);

    while (pTmpFrm)     // Alle Views Invalidieren
    {
        SwView *pVw = PTR_CAST(SwView, pTmpFrm->GetViewShell());
        if (pVw)
            pVw->GetEditWin().Invalidate();
        pTmpFrm = pTmpFrm->GetNext(*pTmpFrm, pDocSh);
    }

#ifdef REPLACE_OFADBMGR
#else
    CloseAll();
#endif
    return bRet;
}

/*--------------------------------------------------------------------
    Beschreibung:   Serienbrief als Mail versenden
 --------------------------------------------------------------------*/


BOOL SwNewDBMgr::MergeMailing(SwWrtShell* pSh)
{
    //check if the doc is synchronized and contains at least one linked section
    BOOL bSynchronizedDoc = pSh->IsLabelDoc() && pSh->GetSectionFmtCount() > 1;
#ifdef REPLACE_OFADBMGR
#else

    OfaDBParam& rParam = GetDBData(FALSE);

    // 1. Satz positionieren, Evaluierung ueber die Felder
    for (USHORT i = 0; i < aDBDataArr.Count(); i++)
    {
        OfaDBParam* pParam = aDBDataArr[i];

        // Alle Im Dok enthaltenen Datenbanken oeffnen und Cursorpos initialisieren
        if (OpenDB(FALSE, pParam->GetDBName()))
        {
            if (pParam->GetCursor())
                Flush(FALSE);   // Cursor initialisieren
            ToFirstSelectedRecord(FALSE);
        }
    }

    OpenDB(FALSE, rParam.GetDBName());
    if (!ToFirstSelectedRecord(FALSE))
        return(FALSE);

    ODbRowRef xRow = GetCurSelectedRecord(FALSE);
#endif
    BOOL bLoop = TRUE;

#ifdef REPLACE_OFADBMGR
#else
    // keine Arme keine Kekse
    if(!xRow.is())
        return FALSE;
    SbaDBDataDefRef aDBDef = OpenColumnNames(FALSE);
    if (aDBDef.Is())
#endif
    {
#ifdef REPLACE_OFADBMGR
        Reference< XColumnsSupplier > xColsSupp( pMergeData->xResultSet, UNO_QUERY );
        Reference <XNameAccess> xCols = xColsSupp->getColumns();
        if(!xCols->hasByName(sEMailAddrFld))
            return FALSE;
        Any aCol = xCols->getByName(sEMailAddrFld);
        Reference< XPropertySet > xColumnProp = *(Reference< XPropertySet >*)aCol.getValue();;
#else
        const SbaColumnList& rCols = aDBDef->GetOriginalColumns();
        USHORT nColPos = 0;
        for (nColPos = 0; nColPos < rCols.Count(); nColPos++)
        {
            const SbaNameItem* pNameItem = (const SbaNameItem*)&rCols.GetObject(nColPos)->Get(SBA_DEF_FLTNAME);
            if (pNameItem->GetValue() == sEMailAddrFld)
                break;
        }

        if (nColPos >= rCols.Count())
            return FALSE;
        nColPos++;
#endif

        bInMerge = TRUE;
        SfxDispatcher* pSfxDispatcher = pSh->GetView().GetViewFrame()->GetDispatcher();
        if (!sSubject.Len())    // Kein leeres Subject wegen Automail (PB)
            sSubject = ' ';
        SfxStringItem aSubject(SID_MAIL_SUBJECT, sSubject);
        SfxStringItem aText(SID_MAIL_TEXT, ' ');    // Leerer Text ist nicht moeglich
        SfxStringItem aAttached(SID_MAIL_ATTACH_FILE, sAttached);
        SfxBoolItem aAttach(SID_MAIL_ATTACH, TRUE);

        SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
        BYTE nMailFmts = pModOpt->GetMailingFormats() | TXTFORMAT_ASCII;    // Immer Ascii
        SfxByteItem aTextFormats(SID_MAIL_TXTFORMAT, nMailFmts);
#ifdef REPLACE_OFADBMGR
#else
        Flush(FALSE);   // Cursor initialisieren
#endif

        pSfxDispatcher->Execute( SID_SAVEDOC, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD);
        if( !pSh->IsModified() )
        {
            // Beim Speichern wurde kein Abbruch gedrueckt
            // neue DocShell erzeugen, alle gelinkten Bereiche embedden
            // und unter temporaerem Namen wieder speichern.
            BOOL bDelTempFile = TRUE;
            String sTmpName;
            const SfxFilter* pSfxFlt;

            {
                SfxMedium* pOrig = pSh->GetView().GetDocShell()->GetMedium();

                pSfxFlt = SwIoSystem::GetFileFilter( pOrig->GetPhysicalName(), ::aEmptyStr );

                String sFileName = ::GetTmpFileName();
                String sTmpName = URIHelper::SmartRelToAbs(sFileName);

                BOOL bCopyCompleted = TRUE;
                try
                {
                    String sMain(sTmpName);
                    sal_Unicode cSlash = '/';
                    xub_StrLen nSlashPos = sMain.SearchBackward(cSlash);
                    sMain.Erase(nSlashPos);
                    ::ucb::Content aNewContent( sMain, Reference< XCommandEnvironment > ());
                    Any aAny;
                    TransferInfo aInfo;
                    aInfo.NameClash = NameClash::OVERWRITE;
                    aInfo.NewTitle = INetURLObject(sTmpName).GetName();
                    aInfo.SourceURL = pOrig->GetPhysicalName();
                    aInfo.MoveData  = FALSE;
                    aAny <<= aInfo;
                    aNewContent.executeCommand( C2U( "transfer" ), aAny);
                }
                catch( ... )
                {
                    bCopyCompleted = FALSE;
                }

                if( !bCopyCompleted )
                {
                    // Neues Dokument erzeugen.
                    SfxObjectShellRef xDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
                    SfxMedium* pMed = new SfxMedium( sTmpName, STREAM_READ, TRUE );
                    pMed->SetFilter( pSfxFlt );

                    // alle gelinkten Bereiche/Grafiken aufs lokale FileSystem
                    // einbetten
                    if( xDocSh->DoLoad( pOrig ) &&
                        ((SwDocShell*)(&xDocSh))->EmbedAllLinks() )
                    {
                        xDocSh->DoSaveAs(*pMed);
                        xDocSh->DoSaveCompleted(pMed);
                    }
                    else
                        bDelTempFile = FALSE;

                    xDocSh->DoClose();
                }
                else
                    bDelTempFile = FALSE;

                if( !bDelTempFile )
                    sTmpName = pOrig->GetPhysicalName();
            }


            String sAddress;
            ULONG nDocNo = 1;
            bCancel = FALSE;

            PrintMonitor aPrtMonDlg(&pSh->GetView().GetEditWin(), TRUE);
            aPrtMonDlg.aDocName.SetText(pSh->GetView().GetDocShell()->GetTitle(22));
            aPrtMonDlg.aCancel.SetClickHdl(LINK(this, SwNewDBMgr, PrtCancelHdl));
            aPrtMonDlg.Show();

            OfficeApplication* pOffApp = OFF_APP();
            SfxRequest aReq( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, pOffApp->GetPool() );
            aReq.AppendItem( SfxStringItem( SID_FILE_NAME, sTmpName ));
            aReq.AppendItem( SfxStringItem( SID_FILTER_NAME, pSfxFlt->GetName() ));
            aReq.AppendItem( SfxBoolItem( SID_HIDDEN, TRUE ) );
            aReq.AppendItem( SfxStringItem( SID_REFERER, String::CreateFromAscii(URL_PREFIX_PRIV_SOFFICE )));

            pOffApp->ExecuteSlot( aReq, pOffApp->SfxApplication::GetInterface());
            if( aReq.IsDone() )
            {
                // DocShell besorgen
                SfxViewFrameItem* pVItem = (SfxViewFrameItem*)aReq.GetReturnValue();
                SwView* pView = (SwView*) pVItem->GetFrame()->GetViewShell();
                SwWrtShell& rSh = pView->GetWrtShell();
                pView->AttrChangedNotify( &rSh );//Damit SelectShell gerufen wird.

                SwDoc* pDoc = rSh.GetDoc();
                SwNewDBMgr* pOldDBMgr = pDoc->GetNewDBMgr();
                pDoc->SetNewDBMgr( this );
                pDoc->EmbedAllLinks();
                String sTempStat(SW_RES(STR_DB_EMAIL));

                do
                {
#ifdef REPLACE_OFADBMGR
#else
                    // Naechste Selektion holen
                    xRow = GetCurSelectedRecord(FALSE);
                    ULONG nOldRec = GetCurRecordId(FALSE);  // Alte Position merken
                    if( xRow.is() && xRow->size() > 0)
#endif
                    {

                        if(UIUNDO_DELETE_INVISIBLECNTNT == rSh.GetUndoIds())
                            rSh.Undo();
                        rSh.ViewShell::UpdateFlds();

                        // alle versteckten Felder/Bereiche entfernen
                        rSh.RemoveInvisibleContent();

                        SfxFrameItem aFrame( SID_DOCFRAME, pVItem->GetFrame() );
#ifdef REPLACE_OFADBMGR
                        SwDBFormatData aDBFormat;
                        sAddress = GetDBField( xColumnProp, aDBFormat);
#else
                        sAddress = ImportDBField(nColPos, &aDBDef, xRow);
#endif
                        if (!sAddress.Len())
                            sAddress = '_';

                        String sStat(sTempStat);
                        sStat += ' ';
                        sStat += String::CreateFromInt32( nDocNo++ );
                        aPrtMonDlg.aPrintInfo.SetText(sStat);
                        aPrtMonDlg.aPrinter.SetText( sAddress );

                        // Rechenzeit fuer EMail-Monitor:
                        for (USHORT i = 0; i < 25; i++)
                            Application::Reschedule();

                        sAddress.Insert(String::CreateFromAscii("mailto:"), 0);
                        SfxStringItem aRecipient( SID_MAIL_RECIPIENT, sAddress );

                        const SfxPoolItem* pRet = pSfxDispatcher->Execute(
                                    SID_MAIL_SENDDOC,
                                    SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD,
                                    &aRecipient, &aSubject, &aAttach, &aAttached,
                                    &aText, &aTextFormats, &aFrame,
                                    0L );
                        //this must be done here because pRet may be destroyed in Reschedule (DeleteOnIdle)
                        BOOL bBreak = pRet && !( (SfxBoolItem*)pRet )->GetValue();

                        // Rechenzeit fuer EMail-Monitor:
                        for (i = 0; i < 25; i++)
                            Application::Reschedule();

                        if ( bBreak )
                            break; // das Verschicken wurde unterbrochen

                    }
#ifdef REPLACE_OFADBMGR
                } while( !bCancel && bSynchronizedDoc ? ExistsNextRecord() : ToNextMergeRecord());
#else
                    // Kontext fuer ToNextSelectedRecord auf richtige Datenbank stellen:
                    GetDBData(FALSE, &rParam.GetDBName());

                    // Endlosschleifen durch "Erster Datensatz" verhindern:
                    if (GetCurRecordId(FALSE) < nOldRec)
                        ToSelectedRecord(FALSE, nOldRec);   // Alte Position restaurieren
                } while(!bCancel && xRow.is() && GotoNextSelectedRecord( bSynchronizedDoc));
#endif
                pDoc->SetNewDBMgr( pOldDBMgr );
                pView->GetDocShell()->OwnerLock( FALSE );

            }
            // jetzt noch die temp Datei entfernen
            if( bDelTempFile )
            {
                try
                {
                    ::ucb::Content aTempContent(
                        sTmpName,
                        Reference< XCommandEnvironment > ());
                    aTempContent.executeCommand( C2U( "delete" ),
                                        makeAny( sal_Bool( sal_True ) ) );
                }
                catch( ... )
                {
                    DBG_ERRORFILE( "Exception" );
                }

            }
            SW_MOD()->SetView(&pSh->GetView());
        }

        bInMerge = FALSE;
        nMergeType = DBMGR_INSERT;
    }

#ifdef REPLACE_OFADBMGR
#else
    CloseAll();
#endif
    return bLoop;
}

/* -----------------------------17.04.00 11:18--------------------------------

 ---------------------------------------------------------------------------*/
#ifdef REPLACE_OFADBMGR
#else
BOOL SwNewDBMgr::GotoNextSelectedRecord( BOOL bSyncronized )
{
    BOOL bRet = FALSE;
    if(!bSyncronized)
        bRet = ToNextSelectedRecord( FALSE );
    else
    {
        OfaDBParam& rParam = GetDBData(FALSE);
        if (rParam.GetCursor())
        {
            if (rParam.pSelectionList.Is() && rParam.pSelectionList->Count())
            {
                bRet = (rParam.CurrentSelPos() < rParam.pSelectionList->Count());
            }
            else
            {
                bRet = !rParam.GetCursor()->IsOffRange();
            }
        }
    }
    return(bRet);
}
#endif
/*--------------------------------------------------------------------
    Beschreibung:   Serienbriefe als einzelne Dokumente speichern
 --------------------------------------------------------------------*/

BOOL SwNewDBMgr::MergeMailFiles(SwWrtShell* pSh)
{
    //check if the doc is synchronized and contains at least one linked section
    BOOL bSynchronizedDoc = pSh->IsLabelDoc() && pSh->GetSectionFmtCount() > 1;
#ifdef REPLACE_OFADBMGR
#else
    OfaDBParam& rParam = GetDBData(FALSE);

    // 1. Satz positionieren, Evaluierung ueber die Felder
    for (USHORT i = 0; i < aDBDataArr.Count(); i++)
    {
        OfaDBParam* pParam = aDBDataArr[i];

        // Alle im Dok enthaltenen Datenbanken oeffnen und Cursorpos initialisieren
        if (OpenDB(FALSE, pParam->GetDBName()))
        {
            if (pParam->GetCursor())
                Flush(FALSE);   // Cursor initialisieren
            ToFirstSelectedRecord(FALSE);
        }
    }

    OpenDB(FALSE, rParam.GetDBName());
    if (!ToFirstSelectedRecord(FALSE))
        return(FALSE);

    ODbRowRef xRow = GetCurSelectedRecord(FALSE);

    // keine Arme keine Kekse
    if(!xRow.is())
        return FALSE;
#endif
    BOOL bLoop = TRUE;

#ifdef REPLACE_OFADBMGR
    Reference< XPropertySet > xColumnProp;
#else
    SbaDBDataDefRef aDBDef = OpenColumnNames(FALSE);
    if (aDBDef.Is())
#endif
    {
        USHORT nColPos = 0;
        BOOL bColumnName = sEMailAddrFld.Len() > 0;

        if (bColumnName)
        {
#ifdef REPLACE_OFADBMGR
            Reference< XColumnsSupplier > xColsSupp( pMergeData->xResultSet, UNO_QUERY );
            Reference <XNameAccess> xCols = xColsSupp->getColumns();
            if(!xCols->hasByName(sEMailAddrFld))
                return FALSE;
            Any aCol = xCols->getByName(sEMailAddrFld);
            xColumnProp = *(Reference< XPropertySet >*)aCol.getValue();;
#else
            const SbaColumnList& rCols = aDBDef->GetOriginalColumns();

            for (nColPos = 0; nColPos < rCols.Count(); nColPos++)
            {
                const SbaNameItem* pNameItem = (const SbaNameItem*)&rCols.GetObject(nColPos)->Get(SBA_DEF_FLTNAME);
                if (pNameItem->GetValue() == sEMailAddrFld)
                    break;
            }

            if (nColPos >= rCols.Count())
                return FALSE;

            nColPos++;
#endif
        }

        bInMerge = TRUE;
        SfxDispatcher* pSfxDispatcher = pSh->GetView().GetViewFrame()->GetDispatcher();

#ifdef REPLACE_OFADBMGR
#else
        Flush(FALSE);   // Cursor initialisieren
#endif

        pSfxDispatcher->Execute( SID_SAVEDOC, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD);
        if( !pSh->IsModified() )
        {
            // Beim Speichern wurde kein Abbruch gedrueckt
            SfxMedium* pOrig = pSh->GetView().GetDocShell()->GetMedium();
            String sOldName(pOrig->GetPhysicalName());
            const SfxFilter* pSfxFlt = SwIoSystem::GetFileFilter(
                                                    sOldName, ::aEmptyStr );
            String sAddress;
            bCancel = FALSE;

            PrintMonitor aPrtMonDlg(&pSh->GetView().GetEditWin());
            aPrtMonDlg.aDocName.SetText(pSh->GetView().GetDocShell()->GetTitle(22));

            aPrtMonDlg.aCancel.SetClickHdl(LINK(this, SwNewDBMgr, PrtCancelHdl));
            aPrtMonDlg.Show();

            SwDocShell *pDocSh = pSh->GetView().GetDocShell();
            // Progress, um KeyInputs zu unterbinden
            SfxProgress aProgress(pDocSh, ::aEmptyStr, 1);

            // Alle Dispatcher sperren
            SfxViewFrame* pViewFrm = SfxViewFrame::GetFirst(pDocSh);
            while (pViewFrm)
            {
                pViewFrm->GetDispatcher()->Lock(TRUE);
                pViewFrm = SfxViewFrame::GetNext(*pViewFrm, pDocSh);
            }
            ULONG nDocNo = 1;
            ULONG nCounter = 0;
            String sExt( INetURLObject( sOldName ).GetExtension() );

            do {
#ifdef REPLACE_OFADBMGR
#else
                // Naechste Selektion holen
                xRow = GetCurSelectedRecord(FALSE);
                ULONG nOldRec = GetCurRecordId(FALSE);  // Alte Position merken

                if( xRow.is() && xRow->size() > 0 )
#endif
                {
                    String sPath(sSubject);

                    if( bColumnName )
                    {
#ifdef REPLACE_OFADBMGR
                        SwDBFormatData aDBFormat;
                        sAddress = GetDBField( xColumnProp, aDBFormat);
#else

                        sAddress = ImportDBField(nColPos, &aDBDef, xRow);
#endif
                        if (!sAddress.Len())
                            sAddress = '_';
                        sPath += sAddress;
                        nCounter = 0;
                    }

                    INetURLObject aEntry(sPath);
                    String sLeading(aEntry.GetBase());
                    aEntry.removeSegment();
                    sPath = aEntry.GetMainURL();
                    TempFile aTemp(sLeading,&sExt,&sPath );

                    if( !aTemp.IsValid() )
                    {
                        ErrorHandler::HandleError( ERRCODE_IO_NOTSUPPORTED );
                        bLoop = FALSE;
                        bCancel = TRUE;
                    }
                    else
                    {
                        INetURLObject aTempFile(aTemp.GetName());
                        aPrtMonDlg.aPrinter.SetText( aTempFile.GetBase() );
                        String sStat(SW_RES(STR_STATSTR_LETTER));   // Brief
                        sStat += ' ';
                        sStat += String::CreateFromInt32( nDocNo++ );
                        aPrtMonDlg.aPrintInfo.SetText(sStat);

                        // Rechenzeit fuer Save-Monitor:
                        for (USHORT i = 0; i < 10; i++)
                            Application::Reschedule();

                        // Neues Dokument erzeugen und speichern
                        SfxObjectShellRef xDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
                        SfxMedium* pMed = new SfxMedium( sOldName, STREAM_STD_READ, TRUE );
                        pMed->SetFilter( pSfxFlt );

                        if (xDocSh->DoLoad(pMed))
                        {
                            SwDoc* pDoc = ((SwDocShell*)(&xDocSh))->GetDoc();
                            SwNewDBMgr* pOldDBMgr = pDoc->GetNewDBMgr();
                            pDoc->SetNewDBMgr( this );
                            pDoc->UpdateFlds(0);

                            // alle versteckten Felder/Bereiche entfernen
                            pDoc->RemoveInvisibleContent();

                            SfxMedium* pDstMed = new SfxMedium( aTempFile.GetFull(), STREAM_STD_READWRITE, TRUE );
                            pDstMed->SetFilter( pSfxFlt );

                            xDocSh->DoSaveAs(*pDstMed);
                            xDocSh->DoSaveCompleted(pDstMed);
                            if( xDocSh->GetError() )
                            {
                                // error message ??
                                ErrorHandler::HandleError( xDocSh->GetError() );
                                bCancel = TRUE;
                                bLoop = FALSE;
                            }
                            pDoc->SetNewDBMgr( pOldDBMgr );
                        }
                        xDocSh->DoClose();
                    }
                }
#ifdef REPLACE_OFADBMGR
            } while( !bCancel && bSynchronizedDoc ? ExistsNextRecord() : ToNextMergeRecord());
#else
                // Kontext fuer ToNextSelectedRecord auf
                // richtige Datenbank stellen:
                GetDBData(FALSE, &rParam.GetDBName());

                // Endlosschleifen durch "Erster Datensatz" verhindern:
                if( !bCancel && GetCurRecordId(FALSE) < nOldRec )
                    ToSelectedRecord(FALSE, nOldRec);   // Alte Position restaurieren
            }  while( !bCancel && xRow.is() &&
                        GotoNextSelectedRecord( bSynchronizedDoc) );
#endif
            // Alle Dispatcher freigeben
            pViewFrm = SfxViewFrame::GetFirst(pDocSh);
            while (pViewFrm)
            {
                pViewFrm->GetDispatcher()->Lock(FALSE);
                pViewFrm = SfxViewFrame::GetNext(*pViewFrm, pDocSh);
            }

            SW_MOD()->SetView(&pSh->GetView());
        }

        bInMerge = FALSE;
        nMergeType = DBMGR_INSERT;
    }

#ifdef REPLACE_OFADBMGR
#else
    CloseAll();
#endif
    return bLoop;
}

/*--------------------------------------------------------------------
    Beschreibung:
  --------------------------------------------------------------------*/

IMPL_LINK_INLINE_START( SwNewDBMgr, PrtCancelHdl, Button *, pButton )
{
    pButton->GetParent()->Hide();
    bCancel = TRUE;
    return 0;
}
IMPL_LINK_INLINE_END( SwNewDBMgr, PrtCancelHdl, Button *, pButton )


/*--------------------------------------------------------------------
    Beschreibung: Numberformat der Spalte ermitteln und ggfs. in
                    den uebergebenen Formatter uebertragen
  --------------------------------------------------------------------*/

#ifdef REPLACE_OFADBMGR
ULONG SwNewDBMgr::GetColumnFmt( const String& rDBName,
                                const String& rTableName,
                                const String& rColNm,
                                SvNumberFormatter* pNFmtr,
                                long nLanguage )
#else
ULONG SwNewDBMgr::GetColumnFmt( const String& rDBName, const String& rColNm,
                                SvNumberFormatter* pNFmtr )
#endif
{
    //JP 12.01.99: ggfs. das NumberFormat im Doc setzen
    ULONG nRet = 0;
#ifdef REPLACE_OFADBMGR
    if(pNFmtr)
    {
        SvNumberFormatsSupplierObj* pNumFmt = new SvNumberFormatsSupplierObj( pNFmtr );
        Reference< util::XNumberFormatsSupplier >  xDocNumFmtsSupplier = pNumFmt;
        Reference< XNumberFormats > xDocNumberFormats = xDocNumFmtsSupplier->getNumberFormats();
         Reference< XNumberFormatTypes > xDocNumberFormatTypes(xDocNumberFormats, UNO_QUERY);

        String sLanguage, sCountry;
        ::ConvertLanguageToIsoNames( nLanguage, sLanguage, sCountry );
        Locale aLocale;
        aLocale.Language = sLanguage;
        aLocale.Country = sCountry;

        Reference< XDataSource> xSource;
        Reference< XConnection> xConnection = SwNewDBMgr::GetConnection(rDBName, xSource);

        //get the number formatter of the data source
        Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
        Reference< XNumberFormats > xNumberFormats;
        if(xSourceProps.is())
        {
            Any aFormats = xSourceProps->getPropertyValue(C2U("NumberFormatsSupplier"));
            if(aFormats.hasValue())
            {
                Reference<XNumberFormatsSupplier> xSuppl = *(Reference<util::XNumberFormatsSupplier>*) aFormats.getValue();
                if(xSuppl.is())
                {
                    xNumberFormats = xSuppl->getNumberFormats();
                }
            }
        }
        Reference< XColumnsSupplier> xColsSupp = SwNewDBMgr::GetColumnSupplier(xConnection, rTableName);
        if(xColsSupp.is())
        {
            Reference <XNameAccess> xCols = xColsSupp->getColumns();
            if(!xCols->hasByName(rColNm))
                return nRet;
            Any aCol = xCols->getByName(rColNm);
            Reference< XPropertySet > xColumnProp = *(Reference< XPropertySet >*)aCol.getValue();;

            Any aFormat = xColumnProp->getPropertyValue(C2U("FormatKey"));
            if(aFormat.hasValue())
            {
                sal_Int32 nFmt;
                aFormat >>= nFmt;
                if(xNumberFormats.is())
                {
                    try
                    {
                        Reference<XPropertySet> xNumProps = xNumberFormats->getByKey( nFmt );
                        Any aFormat = xNumProps->getPropertyValue(C2U("FormatString"));
                        Any aLocale = xNumProps->getPropertyValue(C2U("Locale"));
                        OUString sFormat;
                        aFormat >>= sFormat;
                        com::sun::star::lang::Locale aLoc;
                        aLocale >>= aLoc;
                        nFmt = xDocNumberFormats->addNew( sFormat, aLoc );
                        nRet = nFmt;
                    }
                    catch(...)
                    {
                        DBG_ERROR("illegal number format key")
                    }
                }
            }
            else
                nRet = utl::getDefaultNumberFormat(xColumnProp, xDocNumberFormatTypes,  aLocale);
        }
        else
            nRet = pNFmtr->GetFormatIndex( NF_NUMBER_STANDARD, LANGUAGE_SYSTEM );
    }
#else
    if( pNFmtr )
    {
        int nCol;
        if( OpenDB( DBMGR_STD, rDBName, FALSE ) &&
            0 != ( nCol = GetColumnPos( DBMGR_STD, rColNm )))
            nRet = GetRealColumnFmt( rColNm, GetColumnFormat( DBMGR_STD, nCol ),
                                    *pNFmtr );
        else
            nRet = pNFmtr->GetFormatIndex( NF_NUMBER_STANDARD, LANGUAGE_SYSTEM );
    }
#endif
    return nRet;
}
/* -----------------------------17.07.00 09:47--------------------------------

 ---------------------------------------------------------------------------*/
#ifdef REPLACE_OFADBMGR
sal_Int32 SwNewDBMgr::GetColumnType( const String& rDBName,
                          const String& rTableName,
                          const String& rColNm )
{
    sal_Int32 nRet = DataType::SQLNULL;
    Reference< XDataSource> xSource;
    Reference< XConnection> xConnection = SwNewDBMgr::GetConnection(rDBName, xSource);
    Reference< XColumnsSupplier> xColsSupp = SwNewDBMgr::GetColumnSupplier(xConnection, rTableName);
    if(xColsSupp.is())
    {
          Reference <XNameAccess> xCols = xColsSupp->getColumns();
        if(xCols->hasByName(rColNm))
        {
            Any aCol = xCols->getByName(rColNm);
            Reference <XPropertySet> xCol = *(Reference <XPropertySet>*)aCol.getValue();
            Any aType = xCol->getPropertyValue(C2S("Type"));
            aType >>= nRet;
        }
    }
    return nRet;
}
#else
#endif

#ifdef REPLACE_OFADBMGR
#else
ULONG SwNewDBMgr::GetRealColumnFmt( const String& rColNm, ULONG nFmt,
                                    SvNumberFormatter& rNFmtr )
{
    SvNumberFormatter* pDBNumFmtr;
    const SvNumberformat* pNFmt;
    SbaDBDataDefRef aDBDef = OpenColumnNames( DBMGR_STD );
    if( aDBDef.Is() && 0 != ( pDBNumFmtr = aDBDef->GetFormatter() ) &&
        0 != (pNFmt = pDBNumFmtr->GetEntry( nFmt ) ) )
    {
        nFmt = rNFmtr.GetEntryKey( pNFmt->GetFormatstring(), pNFmt->GetLanguage() );
        if( NUMBERFORMAT_ENTRY_NOT_FOUND == nFmt )
        {
            xub_StrLen nCheckPos;
            short nType;
            XubString aTmp( pNFmt->GetFormatstring() );
            rNFmtr.PutEntry( aTmp, nCheckPos, nType, nFmt, pNFmt->GetLanguage() );
        }
    }
    else
        nFmt = rNFmtr.GetFormatIndex( NF_NUMBER_STANDARD, LANGUAGE_SYSTEM );

    return nFmt;
}
BOOL SwNewDBMgr::IsDBCaseSensitive( const String& rName ) const
{
    BOOL bRet = FALSE;
    String sDBName = OFF_APP()->LocalizeDBName( NATIONAL2INI, rName );
    if( sDBName.Len() )
    {
        SbaDatabaseRef xConnection = pSbaObject->GetDatabase(sDBName, TRUE);
        if( xConnection.Is() )
            // JP 18.11.99: looked from
            //      \offmgr\source\sba\core\db\dbtabobj.cxx
            bRet = SDB_IC_OBJECT == xConnection->GetIdentifierCase();
    }
    return bRet;
}
#endif

#ifdef REPLACE_OFADBMGR
/* -----------------------------03.07.00 17:12--------------------------------

 ---------------------------------------------------------------------------*/
Reference< sdbc::XConnection> SwNewDBMgr::GetConnection(const String& rDataSource,
                                                    Reference<XDataSource>& rxSource)
{
    Reference< sdbc::XConnection> xConnection;
    Reference<XNameAccess> xDBContext;
    Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
    if( xMgr.is() )
    {
        Reference<XInterface> xInstance = xMgr->createInstance( C2U( "com.sun.star.sdb.DatabaseContext" ));
        xDBContext = Reference<XNameAccess>(xInstance, UNO_QUERY) ;
    }
    DBG_ASSERT(xDBContext.is(), "com.sun.star.sdb.DataBaseContext: service not available")
    if(xDBContext.is())
    {
        try
        {
            if(xDBContext->hasByName(rDataSource))
            {
                Any aDBSource = xDBContext->getByName(rDataSource);
                Reference<XDataSource>* pxSource = (Reference<XDataSource>*)aDBSource.getValue();
                   OUString sDummy;
                xConnection = (*pxSource)->getConnection(sDummy, sDummy);
                rxSource = (*pxSource);
            }
        }
        catch(...) {}
    }
    return xConnection;
}
/* -----------------------------03.07.00 17:12--------------------------------

 ---------------------------------------------------------------------------*/
Reference< sdbcx::XColumnsSupplier> SwNewDBMgr::GetColumnSupplier(Reference<sdbc::XConnection> xConnection,
                                    const String& rTableOrQuery,
                                    BYTE    eTableOrQuery)
{
    Reference< sdbcx::XColumnsSupplier> xRet;
    if(SW_DB_SELECT_QUERY != eTableOrQuery)
    {
        Reference<XTablesSupplier> xTSupplier = Reference<XTablesSupplier>(xConnection, UNO_QUERY);
        if(xTSupplier.is())
        {
            Reference<XNameAccess> xTbls = xTSupplier->getTables();
            if(xTbls->hasByName(rTableOrQuery))
                try
                {
                    Any aTable = xTbls->getByName(rTableOrQuery);
                    Reference<XPropertySet> xPropSet = *(Reference<XPropertySet>*)aTable.getValue();
                    xRet = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
                }
                catch(...){}
        }
    }
    if(!xRet.is() && SW_DB_SELECT_QUERY != SW_DB_SELECT_TABLE)
    {
        Reference<XQueriesSupplier> xQSupplier = Reference<XQueriesSupplier>(xConnection, UNO_QUERY);
        if(xQSupplier.is())
        {
            Reference<XNameAccess> xQueries = xQSupplier->getQueries();
            if(xQueries->hasByName(rTableOrQuery))
                try
                {
                    Any aQuery = xQueries->getByName(rTableOrQuery);
                    Reference<XPropertySet> xPropSet = *(Reference<XPropertySet>*)aQuery.getValue();
                    xRet = Reference<XColumnsSupplier>(xPropSet, UNO_QUERY);
                }
                catch(...){}
        }
    }
    return xRet;
}
/* -----------------------------05.07.00 13:44--------------------------------

 ---------------------------------------------------------------------------*/
String SwNewDBMgr::GetDBField(Reference<XPropertySet> xColumnProps,
                        const SwDBFormatData& rDBFormatData,
                        double* pNumber)
{
    Reference< XColumn > xColumn(xColumnProps, UNO_QUERY);
    String sRet;
    DBG_ASSERT(xColumn.is(), "SwNewDBMgr::::ImportDBField: illegal arguments")
    if(!xColumn.is())
        return sRet;

    Any aType = xColumnProps->getPropertyValue(C2U("Type"));
    sal_Int32 eDataType;
    aType >>= eDataType;
    switch(eDataType)
    {
        case DataType::CHAR:
        case DataType::VARCHAR:
        case DataType::LONGVARCHAR:
            sRet = xColumn->getString();
        break;
        case DataType::BIT:
        case DataType::TINYINT:
        case DataType::SMALLINT:
        case DataType::INTEGER:
        case DataType::BIGINT:
        case DataType::FLOAT:
        case DataType::REAL:
        case DataType::DOUBLE:
        case DataType::NUMERIC:
        case DataType::DECIMAL:
        case DataType::DATE:
        case DataType::TIME:
        case DataType::TIMESTAMP:
        {
            ::Date aTempDate(rDBFormatData.aNullDate.Day,
                rDBFormatData.aNullDate.Month, rDBFormatData.aNullDate.Year);

            try
            {
                sRet = utl::DBTypeConversion::getValue(
                    xColumnProps,
                    rDBFormatData.xFormatter,
                    rDBFormatData.aLocale,
                    aTempDate);
                double fVal = xColumn->getDouble();
                if (pNumber)
                    *pNumber = fVal;
            }
            catch(Exception aExcept)
            {
                DBG_ERROR("exception caught")
            }

        }
        break;

//      case DataType::BINARY:
//      case DataType::VARBINARY:
//      case DataType::LONGVARBINARY:
//      case DataType::SQLNULL:
//      case DataType::OTHER:
//      case DataType::OBJECT:
//      case DataType::DISTINCT:
//      case DataType::STRUCT:
//      case DataType::ARRAY:
//      case DataType::BLOB:
//      case DataType::CLOB:
//      case DataType::REF:
//      default:
    }
//  if (pFormat)
//  {
//      SFX_ITEMSET_GET(*pCol, pFormatItem, SfxUInt32Item, SBA_DEF_FMTVALUE, sal_True);
//      *pFormat = pFormatItem->GetValue();
//  }

    return sRet;
}
/* -----------------------------06.07.00 14:26--------------------------------
    opens a data source table or query and keeps the reference
     until EndMerge() is called
 ---------------------------------------------------------------------------*/
BOOL SwNewDBMgr::OpenMergeSource(const String& rDataSource,
                            const String& rDataTableOrQuery,
                            const String& rStatement,
                            const SbaSelectionListRef xSelectionList)
{
    DBG_ASSERT(!bInMerge && !pMergeData, "merge already activated!")
    bInMerge = TRUE;
    pMergeData = new SwDSParam(rDataSource, rDataTableOrQuery, SW_DB_SELECT_UNKNOWN, rStatement);
    //remove corresponding data from aDataSourceParams and insert the merge data
    String sDBName(rDataSource);
    sDBName += DB_DELIM;
    sDBName += rDataTableOrQuery;
    SwDSParam*  pTemp = FindDSData(sDBName, FALSE);
    if(pTemp)
        pTemp = pMergeData;
    else
        aDataSourceParams.Insert(pMergeData, aDataSourceParams.Count());

    Reference<XDataSource> xSource;
    pMergeData->xConnection = SwNewDBMgr::GetConnection(rDataSource, xSource);
    pMergeData->xSelectionList = xSelectionList;
    if( xSelectionList.Is() && xSelectionList->Count() && (long)xSelectionList->GetObject(0) != -1L )
    {
        pMergeData->bSelectionList = TRUE;
    }

    if(pMergeData->xConnection.is())
    {
        try
        {
            pMergeData->bScrollable = pMergeData->xConnection->getMetaData()
                        ->supportsResultSetType((sal_Int32)ResultSetType::SCROLL_INSENSITIVE);
            pMergeData->xStatement = pMergeData->xConnection->createStatement();
            pMergeData->xResultSet = pMergeData->xStatement->executeQuery( rStatement );
            //after executeQuery the cursor must be positioned
            if(pMergeData->bSelectionList)
            {
                if(pMergeData->bScrollable)
                {
                    pMergeData->bEndOfDB = !pMergeData->xResultSet->absolute(
                        (ULONG)pMergeData->xSelectionList->GetObject( 0 ) );
                }
                else
                {
                    ULONG nPos = (ULONG)pMergeData->xSelectionList->GetObject( 0 );
                    while(nPos > 0 && !pMergeData->bEndOfDB)
                    {
                        pMergeData->bEndOfDB |= !pMergeData->xResultSet->next();
                        nPos--;
                    }
                }
                if(1 == pMergeData->xSelectionList->Count())
                    pMergeData->bEndOfDB = TRUE;
            }
            else
            {
                pMergeData->bEndOfDB = !pMergeData->xResultSet->next();
                ++pMergeData->nSelectionIndex;
            }
            Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
            if( xMgr.is() )
            {
                Reference<XInterface> xInstance = xMgr->createInstance( C2U( "com.sun.star.util.NumberFormatter" ));
                pMergeData->xFormatter = Reference<util::XNumberFormatter>(xInstance, UNO_QUERY) ;
            }

            Reference<XPropertySet> xSourceProps(xSource, UNO_QUERY);
            if(xSourceProps.is())
            {
                Any aFormats = xSourceProps->getPropertyValue(C2U("NumberFormatsSupplier"));
                if(aFormats.hasValue())
                {
                    Reference<XNumberFormatsSupplier> xSuppl = *(Reference<util::XNumberFormatsSupplier>*) aFormats.getValue();
                    if(xSuppl.is())
                    {
                        Reference< XPropertySet > xSettings = xSuppl->getNumberFormatSettings();
                        Any aNull = xSettings->getPropertyValue(C2U("NullDate"));
                        if(aNull.hasValue())
                            pMergeData->aNullDate = *(util::Date*)aNull.getValue();
                    }
                }
            }
        }
        catch(Exception aExcept)
        {
            DBG_ERROR("exception caught")
        }
    }
    BOOL bRet = pMergeData && pMergeData->xResultSet.is();
    if(!bRet)
        pMergeData = 0;
    return bRet;
}
/* -----------------------------06.07.00 14:28--------------------------------
    releases the merge data source table or query after merge is completed
 ---------------------------------------------------------------------------*/
void    SwNewDBMgr::EndMerge()
{
    DBG_ASSERT(bInMerge, "merge is not active")
    bInMerge = FALSE;
    pMergeData = 0;
}
/* -----------------------------06.07.00 14:28--------------------------------
    checks if a desired data source table or query is open
 ---------------------------------------------------------------------------*/
BOOL    SwNewDBMgr::IsDataSourceOpen(const String& rDataSource, const String& rTableOrQuery) const
{
     if(pMergeData)
    {
        return rDataSource == pMergeData->sDataSource &&
                    rTableOrQuery == pMergeData->sTableOrQuery &&
                    pMergeData->xResultSet.is();
    }
    else
        return FALSE;
}
/* -----------------------------17.07.00 16:44--------------------------------
    read column data a a specified position
 ---------------------------------------------------------------------------*/
BOOL SwNewDBMgr::GetColumnCnt(const String& rSourceName, const String& rTableName,
                            const String& rColumnName, sal_uInt32 nAbsRecordId,
                            long nLanguage,
                            String& rResult, double* pNumber)
{
    BOOL bRet = FALSE;
    //check if it's the merge data source
    if(pMergeData &&
        rSourceName == pMergeData->sDataSource &&
        rTableName == pMergeData->sTableOrQuery)
    {
        if(!pMergeData->xResultSet.is())
            return FALSE;
        //keep the old index
        sal_Int32 nOldRow = pMergeData->xResultSet->getRow();
        //position to the desired index
        BOOL bMove;
        if(nOldRow != nAbsRecordId)
            bMove = lcl_MoveAbsolute(pMergeData, nAbsRecordId);
        if(bMove)
        {
            bRet = lcl_GetColumnCnt(pMergeData, rColumnName, nLanguage, rResult, pNumber);
        }
        if(nOldRow != nAbsRecordId)
            bMove = lcl_MoveAbsolute(pMergeData, nOldRow);
    }
    //
    return bRet;
}
/* -----------------------------06.07.00 16:47--------------------------------
    reads the column data at the current position
 ---------------------------------------------------------------------------*/
BOOL    SwNewDBMgr::GetMergeColumnCnt(const String& rColumnName, USHORT nLanguage,
                                String &rResult, double *pNumber, sal_uInt32 *pFormat)
{
    if(!pMergeData || !pMergeData->xResultSet.is())
        return FALSE;

    BOOL bRet = lcl_GetColumnCnt(pMergeData, rColumnName, nLanguage, rResult, pNumber);
    return bRet;
}
/* -----------------------------07.07.00 14:28--------------------------------

 ---------------------------------------------------------------------------*/
BOOL SwNewDBMgr::ToNextMergeRecord()
{
    DBG_ASSERT(pMergeData && pMergeData->xResultSet.is(), "no data source in merge")
    if(!pMergeData || !pMergeData->xResultSet.is() || pMergeData->bEndOfDB)
        return FALSE;
    try
    {
        if(pMergeData->bSelectionList)
        {
            if(pMergeData->bScrollable)
            {
                pMergeData->bEndOfDB = !pMergeData->xResultSet->absolute(
                    (ULONG)pMergeData->xSelectionList->GetObject( ++pMergeData->nSelectionIndex ) );
            }
            else
            {
                ULONG nOldPos = pMergeData->nSelectionIndex ?
                    (ULONG)pMergeData->xSelectionList->GetObject(pMergeData->nSelectionIndex): 0;
                ULONG nPos = (ULONG)pMergeData->xSelectionList->GetObject( ++pMergeData->nSelectionIndex );
                DBG_ASSERT(nPos >=0, "selection invalid!")
                long nDiff = nPos - nOldPos;
                //if a backward move is necessary then the result set must be created again
                if(nDiff < 0)
                {
                    try
                    {
                        pMergeData->xResultSet = pMergeData->xStatement->executeQuery( pMergeData->sStatement );
                    }
                    catch(...)
                    {
                        pMergeData->bEndOfDB = TRUE;
                    }
                    nDiff = nPos;
                }
                while(nDiff > 0 && !pMergeData->bEndOfDB)
                {
                    pMergeData->bEndOfDB |= !pMergeData->xResultSet->next();
                    nDiff--;
                }
            }
            if(pMergeData->nSelectionIndex >= pMergeData->xSelectionList->Count())
                pMergeData->bEndOfDB = TRUE;
        }
        else
        {
            pMergeData->bEndOfDB = !pMergeData->xResultSet->next();
            ++pMergeData->nSelectionIndex;
        }
    }
    catch(Exception aExcept)
    {
        DBG_ERROR("exception caught")
    }
    return TRUE;
}
/* -----------------------------13.07.00 17:23--------------------------------
    synchronized labels contain a next record field at their end
    to assure that the next page can be created in mail merge
    the cursor position must be validated
 ---------------------------------------------------------------------------*/
BOOL SwNewDBMgr::ExistsNextRecord() const
{
    return pMergeData && !pMergeData->bEndOfDB;
}
/* -----------------------------13.07.00 10:41--------------------------------

 ---------------------------------------------------------------------------*/
sal_uInt32  SwNewDBMgr::GetSelectedRecordId()
{
    sal_uInt32  nRet = 0;
    DBG_ASSERT(pMergeData && pMergeData->xResultSet.is(), "no data source in merge")
    if(!pMergeData || !pMergeData->xResultSet.is())
        return FALSE;
    try
    {
        nRet = pMergeData->xResultSet->getRow();
    }
    catch(Exception aExcept)
    {
        DBG_ERROR("exception caught")
    }
    return nRet;
}
/* -----------------------------13.07.00 10:58--------------------------------

 ---------------------------------------------------------------------------*/
sal_Bool SwNewDBMgr::ToRecordId(sal_Int32 nSet)
{
    DBG_ASSERT(pMergeData && pMergeData->xResultSet.is(), "no data source in merge")
    if(!pMergeData || !pMergeData->xResultSet.is()|| nSet < 0)
        return FALSE;
    sal_Bool bRet = FALSE;
    sal_Int32 nAbsPos = -1;
    if(pMergeData->bSelectionList)
    {
        if(pMergeData->xSelectionList->Count() > nSet)
        {
            nAbsPos = (sal_Int32)pMergeData->xSelectionList->GetObject(nSet);
        }
    }
    else
        nAbsPos = nSet;

    if(nAbsPos >= 0)
    {
        bRet = lcl_MoveAbsolute(pMergeData, nAbsPos);
        pMergeData->bEndOfDB = !bRet;
    }
    return bRet;
}
/* -----------------------------17.07.00 11:14--------------------------------

 ---------------------------------------------------------------------------*/
BOOL    SwNewDBMgr::ShowInBeamer(const String& rDBName, const String& rTableName,
                                            BYTE nType, const String& rStatement)
{
    DBG_ERROR("no beamer interface available!")
    return FALSE;
}
/* -----------------------------17.07.00 14:50--------------------------------

 ---------------------------------------------------------------------------*/
void lcl_ExtractMembers(const String& rDBName, String& sSource, String& sTable, String& sStatement)
{
    sSource = rDBName.GetToken(0, DB_DELIM);
    sTable = rDBName.GetToken(0).GetToken(1, DB_DELIM);
    sal_uInt16 nPos;
    if ((nPos = rDBName.Search(';')) != STRING_NOTFOUND)
        sStatement = rDBName.Copy(nPos + 1);
}
/* -----------------------------17.07.00 14:17--------------------------------

 ---------------------------------------------------------------------------*/
BOOL SwNewDBMgr::OpenDataSource(const String& rDataSource, const String& rTableOrQuery)
{
    String sDBName = rDataSource;
    sDBName += DB_DELIM;
    sDBName += rTableOrQuery;
    SwDSParam* pFound = FindDSData(sDBName, TRUE);
    pFound->bSelectionList = pFound->xSelectionList.Is() && pFound->xSelectionList->Count();
    Reference< XDataSource> xSource;
    if(pFound->xResultSet.is())
        return TRUE;
    pFound->xConnection = SwNewDBMgr::GetConnection(rDataSource, xSource );
    if(pFound->xConnection.is())
    {
        try
        {
            pFound->bScrollable = pFound->xConnection->getMetaData()
                        ->supportsResultSetType((sal_Int32)ResultSetType::SCROLL_INSENSITIVE);
            pFound->xStatement = pFound->xConnection->createStatement();
            pFound->xResultSet = pFound->xStatement->executeQuery( pFound->sStatement );

            //after executeQuery the cursor must be positioned
            if(pFound->bSelectionList)
            {
                if(pFound->bScrollable)
                {
                    pFound->bEndOfDB = !pMergeData->xResultSet->absolute(
                        (ULONG)pFound->xSelectionList->GetObject( 0 ) );
                }
                else
                {
                    ULONG nPos = (ULONG)pFound->xSelectionList->GetObject( 0 );
                    while(nPos > 0 && !pFound->bEndOfDB)
                    {
                        pFound->bEndOfDB |= !pFound->xResultSet->next();
                        nPos--;
                    }
                }
                if(1 == pFound->xSelectionList->Count())
                    pFound->bEndOfDB = TRUE;
            }
            else
            {
                pFound->bEndOfDB = !pMergeData->xResultSet->next();
                ++pMergeData->nSelectionIndex;
            }
        }
        catch(...)
        {
            pFound->xResultSet = 0;
            pFound->xStatement = 0;
            pFound->xConnection = 0;
        }
    }
    return pFound->xResultSet.is();
}
/* -----------------------------17.07.00 15:55--------------------------------

 ---------------------------------------------------------------------------*/
sal_uInt32      SwNewDBMgr::GetSelectedRecordId(const String& rDataSource, const String& rTableOrQuery)
{
    sal_uInt32 nRet = -1;
    //check for merge data source first
     if(pMergeData && rDataSource == pMergeData->sDataSource &&
                    rTableOrQuery == pMergeData->sTableOrQuery &&
                    pMergeData->xResultSet.is())
        nRet = GetSelectedRecordId();
    else
    {
        String sDBName(rDataSource);
        sDBName += DB_DELIM;
        sDBName += rTableOrQuery;
        SwDSParam* pFound = SwNewDBMgr::FindDSData(sDBName, FALSE);
        if(pFound && pFound->xResultSet.is())
        {
            try
            {
                nRet = pFound->xResultSet->getRow();
            }
            catch(...){}
        }
    }
    return nRet;
}

/* -----------------------------17.07.00 14:18--------------------------------
    close all data sources - after fields were updated
 ---------------------------------------------------------------------------*/
void    SwNewDBMgr::CloseAll(BOOL bIncludingMerge)
{
    for(USHORT nPos = 0; nPos < aDataSourceParams.Count(); nPos++)
    {
        SwDSParam* pParam = aDataSourceParams[nPos];
        if(bIncludingMerge || pParam != pMergeData)
          {
            pParam->xResultSet = 0;
            pParam->xStatement = 0;
            pParam->xConnection = 0;
        }
    }
}
/* -----------------------------17.07.00 14:54--------------------------------

 ---------------------------------------------------------------------------*/
SwDSParam* SwNewDBMgr::FindDSData(const String& rDBName, BOOL bCreate)
{
    String sSource;
    String sTable;
    String sStatement;
    lcl_ExtractMembers(rDBName, sSource, sTable, sStatement);
    SwDSParam* pFound = 0;

    for(USHORT nPos = 0; nPos < aDataSourceParams.Count(); nPos++)
    {
        SwDSParam* pParam = aDataSourceParams[nPos];
        if(sSource == pParam->sDataSource &&
            sTable == pParam->sTableOrQuery)
            {
                pFound = pParam;
                break;
            }
    }
    if(bCreate)
    {
        if(!pFound)
        {
            pFound = new SwDSParam(sSource, sTable, SW_DB_SELECT_UNKNOWN, sStatement);
            aDataSourceParams.Insert(pFound, aDataSourceParams.Count());
        }
        else
            pFound->sStatement = sStatement;
    }
    return pFound;
}
/* -----------------------------17.07.00 14:31--------------------------------
    rDBName: <Source> + DB_DELIM + <Table>; + <Statement>
 ---------------------------------------------------------------------------*/
void    SwNewDBMgr::AddDSData(const String& rDBName, long nSelStart, long nSelEnd)
{
    SwDSParam* pFound = FindDSData(rDBName, TRUE);
    if(pFound->xSelectionList.Is())
        pFound->xSelectionList->Clear();
    else
        pFound->xSelectionList = new SbaSelectionList;
    if (nSelStart > 0)
    {
        if (nSelEnd < nSelStart)
        {
            sal_uInt32 nZw = nSelEnd;
            nSelEnd = nSelStart;
            nSelStart = nZw;
        }

        for (long i = nSelStart; i <= nSelEnd; i++)
            pFound->xSelectionList->Insert((void*)i , LIST_APPEND);
    }
}
/* -----------------------------17.07.00 14:31--------------------------------

 ---------------------------------------------------------------------------*/
void    SwNewDBMgr::GetDSSelection(const String& rDBDesc, long& rSelStart, long& rSelEnd)
{
    SwDSParam* pFound = FindDSData(rDBDesc, FALSE);
    if(!pFound || !pFound->xSelectionList.Is() || !pFound->xSelectionList->Count())
        rSelStart = -1L;
    else
    {
        if(pFound->xSelectionList->Count())
        {
            rSelStart = (sal_uInt32)pFound->xSelectionList->GetObject(0);
            for (sal_uInt32 i = 1; i < pFound->xSelectionList->Count(); i++)
            {
                long nPrev = (sal_uInt32)pFound->xSelectionList->GetObject(i - 1);
                long nNow = (sal_uInt32)pFound->xSelectionList->GetObject(i);

                if (nNow - nPrev > 1)
                {
                    rSelEnd = nPrev;
                    return;
                }
            }
            rSelEnd = (sal_uInt32)pFound->xSelectionList->GetObject(i - 1);
        }
    }
}
/* -----------------------------17.07.00 14:34--------------------------------

 ---------------------------------------------------------------------------*/
const String&   SwNewDBMgr::GetAddressDBName()
{
    DBG_ERROR("no address data base selection available")
    return aEmptyStr;
}
/* -----------------------------18.07.00 13:13--------------------------------

 ---------------------------------------------------------------------------*/
Sequence<OUString> SwNewDBMgr::GetExistingDatabaseNames()
{
    Reference<XNameAccess> xDBContext;
    Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
    if( xMgr.is() )
    {
        Reference<XInterface> xInstance = xMgr->createInstance( C2U( "com.sun.star.sdb.DatabaseContext" ));
        xDBContext = Reference<XNameAccess>(xInstance, UNO_QUERY) ;
    }
    if(xDBContext.is())
    {
        return xDBContext->getElementNames();
    }
    return Sequence<OUString>();
}
#endif  //REPLACE_OFADBMGR

/*------------------------------------------------------------------------
    $Log: not supported by cvs2svn $
    Revision 1.2  2000/10/06 13:32:56  jp
    should changes: don't use IniManager

    Revision 1.1.1.1  2000/09/18 17:14:33  hr
    initial import

    Revision 1.372  2000/09/18 16:05:18  willem.vandorp
    OpenOffice header added.

    Revision 1.371  2000/08/08 10:10:39  os
    ucb transfer command used

    Revision 1.370  2000/07/18 12:50:07  os
    replace ofadbmgr

    Revision 1.369  2000/07/07 15:25:43  os
    replace ofadbmgr

    Revision 1.368  2000/07/06 07:59:10  os
    replace ofadbmgr

    Revision 1.367  2000/07/05 08:23:06  os
    Replace ofadbmgr

    Revision 1.366  2000/06/26 13:18:45  os
    INetURLObject::SmartRelToAbs removed

    Revision 1.365  2000/06/13 09:57:36  os
    using UCB

    Revision 1.364  2000/06/08 09:46:48  os
    ContentBroker not in SwModule

    Revision 1.363  2000/06/07 13:26:07  os
    using UCB

    Revision 1.362  2000/05/23 18:11:05  jp
    Bugfixes for Unicode

    Revision 1.361  2000/04/17 10:01:56  os
    #74698# detect synchronized documents with an additional DBNextSet - field

    Revision 1.360  2000/04/11 08:03:52  os
    UNICODE

    Revision 1.359  2000/02/11 14:44:23  hr
    #70473# changes for unicode ( patched by automated patchtool )

    Revision 1.358  2000/01/06 18:20:27  jp
    Bug #71413#: MergeMailFiles: HandleErrors, created filenames starts with 1

    Revision 1.357  2000/01/06 07:31:29  os
    #71436# mail merge dialog: execute via status method disposed

    Revision 1.356  1999/12/22 15:57:02  jp
    Bug #71238#: MergePrint - behind the first call erase the JobName

    Revision 1.355  1999/12/14 14:35:04  jp
    Bug #69595#: print can create single Jobs

    Revision 1.354  1999/11/23 11:20:55  os
    comment

    Revision 1.353  1999/11/18 21:02:54  jp
    for Bug #68744#: new: IsCaseSensitive



------------------------------------------------------------------------*/