Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "UITools.hxx"
22 : : #include <sfx2/docfilt.hxx>
23 : : #include "callbacks.hxx"
24 : : #include "dbustrings.hrc"
25 : : #include "dbu_resource.hrc"
26 : : #include "dlgsave.hxx"
27 : : #include "dbtreelistbox.hxx"
28 : : #include "defaultobjectnamecheck.hxx"
29 : : #include <comphelper/extract.hxx>
30 : : #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
31 : : #include <com/sun/star/sdb/XCompletedConnection.hpp>
32 : : #include <com/sun/star/sdbc/XDataSource.hpp>
33 : : #include <com/sun/star/sdb/SQLContext.hpp>
34 : : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
35 : : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
36 : : #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
37 : : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
38 : : #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
39 : : #include <com/sun/star/sdbcx/XAppend.hpp>
40 : : #include <com/sun/star/sdbc/XRow.hpp>
41 : : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
42 : : #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
43 : : #include <com/sun/star/sdbc/ColumnValue.hpp>
44 : : #include <com/sun/star/task/XInteractionHandler.hpp>
45 : : #include <com/sun/star/ucb/XContent.hpp>
46 : : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
47 : : #include <com/sun/star/beans/PropertyValue.hpp>
48 : : #include <com/sun/star/container/XIndexAccess.hpp>
49 : : #include <com/sun/star/container/XNameContainer.hpp>
50 : : #include <com/sun/star/ucb/InteractiveIOException.hpp>
51 : : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
52 : : #include <com/sun/star/ucb/IOErrorCode.hpp>
53 : : #include <toolkit/helper/vclunohelper.hxx>
54 : : #include <toolkit/awt/vclxwindow.hxx>
55 : : #include <vcl/stdtext.hxx>
56 : : #include <com/sun/star/beans/XPropertySetInfo.hpp>
57 : : #include <com/sun/star/beans/XPropertySet.hpp>
58 : : #include <com/sun/star/container/XNameAccess.hpp>
59 : : #include <com/sun/star/container/XContainer.hpp>
60 : : #include <com/sun/star/container/XHierarchicalNameContainer.hpp>
61 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
62 : : #include <com/sun/star/awt/TextAlign.hpp>
63 : : #include <com/sun/star/awt/FontDescriptor.hpp>
64 : : #include <com/sun/star/awt/FontWeight.hpp>
65 : : #include <com/sun/star/awt/FontRelief.hpp>
66 : : #include <com/sun/star/awt/FontWidth.hpp>
67 : : #include <com/sun/star/frame/XModel.hpp>
68 : : #include "dlgattr.hrc"
69 : : #include "TypeInfo.hxx"
70 : : #include "FieldDescriptions.hxx"
71 : : #include <comphelper/stl_types.hxx>
72 : : #include <comphelper/componentcontext.hxx>
73 : :
74 : : #include <svx/svxids.hrc>
75 : :
76 : : #include <svl/itempool.hxx>
77 : : #include <tools/string.hxx>
78 : : #include "dbaccess_helpid.hrc"
79 : : #include <svl/itemset.hxx>
80 : : #include "sbagrid.hrc"
81 : : #include <svl/rngitem.hxx>
82 : : #include <svl/intitem.hxx>
83 : : #include <svx/algitem.hxx>
84 : : #include <svx/numinf.hxx>
85 : : #include <svl/zforlist.hxx>
86 : : #include "dlgattr.hxx"
87 : : #include <vcl/msgbox.hxx>
88 : : #include <com/sun/star/container/XChild.hpp>
89 : : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
90 : : #include <com/sun/star/util/XNumberFormatter.hpp>
91 : : #include "dbu_misc.hrc"
92 : : #include "sqlmessage.hxx"
93 : : #include <com/sun/star/util/NumberFormat.hpp>
94 : : #include <com/sun/star/util/URL.hpp>
95 : : #include <vcl/toolbox.hxx>
96 : : #include "dlgsize.hxx"
97 : : #include <svtools/editbrowsebox.hxx>
98 : : #include <unotools/configmgr.hxx>
99 : : #include <svtools/helpopt.hxx>
100 : : #include <ucbhelper/content.hxx>
101 : : #include <tools/urlobj.hxx>
102 : : #include <tools/diagnose_ex.h>
103 : : #include <svl/numuno.hxx>
104 : : #include <unotools/pathoptions.hxx>
105 : : #include <svl/filenotation.hxx>
106 : : #include <svtools/fileview.hxx>
107 : : #include <connectivity/FValue.hxx>
108 : :
109 : : #include <editeng/justifyitem.hxx>
110 : :
111 : : // .........................................................................
112 : : namespace dbaui
113 : : {
114 : : // .........................................................................
115 : : using namespace ::dbtools;
116 : : using namespace ::comphelper;
117 : : using namespace ::com::sun::star::uno;
118 : : using namespace ::com::sun::star::task;
119 : : using namespace ::com::sun::star::sdbcx;
120 : : using namespace ::com::sun::star::sdbc;
121 : : using namespace ::com::sun::star::sdb;
122 : : using namespace ::com::sun::star::util;
123 : : using namespace ::com::sun::star::ucb;
124 : : using namespace ::com::sun::star::beans;
125 : : using namespace ::com::sun::star::container;
126 : : using namespace ::com::sun::star::lang;
127 : : using namespace ::com::sun::star::ui::dialogs;
128 : : using namespace ::svt;
129 : : using ::com::sun::star::ucb::InteractiveIOException;
130 : : using ::com::sun::star::ucb::IOErrorCode_NO_FILE;
131 : : using ::com::sun::star::ucb::IOErrorCode_NOT_EXISTING;
132 : : using ::com::sun::star::frame::XModel;
133 : :
134 : : // -----------------------------------------------------------------------------
135 : 0 : SQLExceptionInfo createConnection( const ::rtl::OUString& _rsDataSourceName,
136 : : const Reference< ::com::sun::star::container::XNameAccess >& _xDatabaseContext,
137 : : const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF,
138 : : Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
139 : : Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
140 : : {
141 : 0 : Reference<XPropertySet> xProp;
142 : : try
143 : : {
144 [ # # ][ # # ]: 0 : xProp.set(_xDatabaseContext->getByName(_rsDataSourceName),UNO_QUERY);
[ # # ][ # # ]
145 : : }
146 [ # # ]: 0 : catch(const Exception&)
147 : : {
148 : : }
149 [ # # ]: 0 : SQLExceptionInfo aInfo;
150 : :
151 [ # # ][ # # ]: 0 : return createConnection(xProp,_rMF,_rEvtLst,_rOUTConnection);
152 : : }
153 : : // -----------------------------------------------------------------------------
154 : 0 : SQLExceptionInfo createConnection( const Reference< ::com::sun::star::beans::XPropertySet>& _xDataSource,
155 : : const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF,
156 : : Reference< ::com::sun::star::lang::XEventListener>& _rEvtLst,
157 : : Reference< ::com::sun::star::sdbc::XConnection>& _rOUTConnection )
158 : : {
159 [ # # ]: 0 : SQLExceptionInfo aInfo;
160 [ # # ]: 0 : if ( !_xDataSource.is() )
161 : : {
162 : : OSL_FAIL("createConnection: coult not retrieve the data source!");
163 : : return aInfo;
164 : : }
165 : :
166 : 0 : ::rtl::OUString sPwd, sUser;
167 : 0 : sal_Bool bPwdReq = sal_False;
168 : : try
169 : : {
170 [ # # ][ # # ]: 0 : _xDataSource->getPropertyValue(PROPERTY_PASSWORD) >>= sPwd;
[ # # ]
171 [ # # ][ # # ]: 0 : bPwdReq = ::cppu::any2bool(_xDataSource->getPropertyValue(PROPERTY_ISPASSWORDREQUIRED));
[ # # ][ # # ]
172 [ # # ][ # # ]: 0 : _xDataSource->getPropertyValue(PROPERTY_USER) >>= sUser;
[ # # ][ # # ]
173 : : }
174 [ # # ]: 0 : catch(const Exception&)
175 : : {
176 : : OSL_FAIL("createConnection: error while retrieving data source properties!");
177 : : }
178 : :
179 : :
180 : : try
181 : : {
182 [ # # ][ # # ]: 0 : if(bPwdReq && sPwd.isEmpty())
[ # # ]
183 : : { // password required, but empty -> connect using an interaction handler
184 [ # # ]: 0 : Reference<XCompletedConnection> xConnectionCompletion(_xDataSource, UNO_QUERY);
185 [ # # ]: 0 : if (!xConnectionCompletion.is())
186 : : {
187 : : OSL_FAIL("createConnection: missing an interface ... need an error message here!");
188 : : }
189 : : else
190 : : { // instantiate the default SDB interaction handler
191 [ # # ][ # # ]: 0 : Reference< XInteractionHandler > xHandler(_rMF->createInstance(SERVICE_TASK_INTERACTION_HANDLER), UNO_QUERY);
[ # # ][ # # ]
192 [ # # ]: 0 : if (!xHandler.is())
193 : : {
194 : : OSL_FAIL("createConnection: could not instantiate an interaction handler!");
195 : : // TODO: a real parent!
196 : : }
197 : : else
198 [ # # ][ # # ]: 0 : _rOUTConnection = xConnectionCompletion->connectWithCompletion(xHandler);
[ # # ]
199 : 0 : }
200 : : }
201 : : else
202 : : {
203 [ # # ]: 0 : Reference<XDataSource> xDataSource(_xDataSource,UNO_QUERY);
204 [ # # ][ # # ]: 0 : _rOUTConnection = xDataSource->getConnection(sUser, sPwd);
[ # # ]
205 : : }
206 : : // be notified when connection is in disposing
207 [ # # ]: 0 : Reference< XComponent > xComponent(_rOUTConnection, UNO_QUERY);
208 [ # # ][ # # ]: 0 : if (xComponent.is() && _rEvtLst.is())
[ # # ]
209 [ # # ][ # # ]: 0 : xComponent->addEventListener(_rEvtLst);
210 : : }
211 [ # # # # : 0 : catch(const SQLContext& e) { aInfo = SQLExceptionInfo(e); }
# # # # ]
212 [ # # # # : 0 : catch(const SQLWarning& e) { aInfo = SQLExceptionInfo(e); }
# # # # ]
213 [ # # # # : 0 : catch(const SQLException& e) { aInfo = SQLExceptionInfo(e); }
# # # # #
# # # # ]
214 [ # # ]: 0 : catch(const Exception&) { OSL_FAIL("SbaTableQueryBrowser::OnExpandEntry: could not connect - unknown exception!"); }
215 : :
216 : 0 : return aInfo;
217 : : }
218 : : // -----------------------------------------------------------------------------
219 : 2 : Reference< XDataSource > getDataSourceByName( const ::rtl::OUString& _rDataSourceName,
220 : : Window* _pErrorMessageParent, Reference< XMultiServiceFactory > _rxORB, ::dbtools::SQLExceptionInfo* _pErrorInfo )
221 : : {
222 [ + - ]: 2 : ::comphelper::ComponentContext aContext( _rxORB );
223 [ + - ][ + - ]: 2 : Reference< XNameAccess > xDatabaseContext( aContext.createComponent( "com.sun.star.sdb.DatabaseContext" ), UNO_QUERY_THROW );
224 : :
225 : 2 : Reference< XDataSource > xDatasource;
226 : 2 : Any aError;
227 [ + - ]: 2 : SQLExceptionInfo aSQLError;
228 : : try
229 : : {
230 [ + - ][ + - ]: 2 : xDatabaseContext->getByName( _rDataSourceName ) >>= xDatasource;
[ + - ]
231 : : }
232 [ # # # # : 0 : catch(const WrappedTargetException& e)
# ]
233 : : {
234 [ # # ]: 0 : InteractiveIOException aIOException;
235 [ # # # # : 0 : if ( ( e.TargetException >>= aIOException )
# # # # #
# ]
236 : : && ( ( aIOException.Code == IOErrorCode_NO_FILE )
237 : : || ( aIOException.Code == IOErrorCode_NOT_EXISTING )
238 : : )
239 : : )
240 : : {
241 [ # # # # ]: 0 : String sErrorMessage = String( ModuleRes( STR_FILE_DOES_NOT_EXIST ) );
242 [ # # ]: 0 : OFileNotation aTransformer( e.Message );
243 [ # # # # : 0 : sErrorMessage.SearchAndReplaceAscii( "$file$", aTransformer.get( OFileNotation::N_SYSTEM ) );
# # # # ]
244 [ # # # # : 0 : aSQLError = SQLExceptionInfo( sErrorMessage ).get();
# # # # #
# # # ]
245 : : }
246 : : else
247 : : {
248 [ # # # # : 0 : aSQLError = SQLExceptionInfo( e.TargetException );
# # ]
249 [ # # ]: 0 : if ( !aSQLError.isValid() )
250 : 0 : aError = e.TargetException;
251 [ # # ]: 0 : }
252 : : }
253 [ # # ]: 0 : catch( const Exception& )
254 : : {
255 : : DBG_UNHANDLED_EXCEPTION();
256 : : }
257 : :
258 [ + - ]: 2 : if ( xDatasource.is() )
259 : 2 : return xDatasource;
260 : :
261 [ # # ]: 0 : if ( aSQLError.isValid() )
262 : : {
263 [ # # ]: 0 : if ( _pErrorInfo )
264 : : {
265 [ # # ]: 0 : *_pErrorInfo = aSQLError;
266 : : }
267 : : else
268 : : {
269 [ # # ]: 0 : showError( aSQLError, _pErrorMessageParent, _rxORB );
270 : : }
271 : : }
272 : :
273 [ + - ][ + - ]: 2 : return Reference<XDataSource>();
274 : : }
275 : : // -----------------------------------------------------------------------------
276 : 0 : Reference< XInterface > getDataSourceOrModel(const Reference< XInterface >& _xObject)
277 : : {
278 : 0 : Reference< XInterface > xRet;
279 [ # # ]: 0 : Reference<XDocumentDataSource> xDocumentDataSource(_xObject,UNO_QUERY);
280 [ # # ]: 0 : if ( xDocumentDataSource.is() )
281 [ # # ][ # # ]: 0 : xRet = xDocumentDataSource->getDatabaseDocument();
[ # # ]
282 : :
283 [ # # ]: 0 : if ( !xRet.is() )
284 : : {
285 [ # # ]: 0 : Reference<XOfficeDatabaseDocument> xOfficeDoc(_xObject,UNO_QUERY);
286 [ # # ]: 0 : if ( xOfficeDoc.is() )
287 [ # # ][ # # ]: 0 : xRet = xOfficeDoc->getDataSource();
[ # # ]
288 : : }
289 : :
290 : 0 : return xRet;
291 : : }
292 : : // -----------------------------------------------------------------------------
293 : 0 : void showError(const SQLExceptionInfo& _rInfo,Window* _pParent,const Reference< XMultiServiceFactory >& _xFactory)
294 : : {
295 : : OSL_ENSURE(_pParent,"showError: Parent window must be NOT NULL!");
296 [ # # ]: 0 : ::dbtools::showError(_rInfo,VCLUnoHelper::GetInterface(_pParent),_xFactory);
297 : 0 : }
298 : :
299 : : // -----------------------------------------------------------------------------
300 : :
301 : 0 : TOTypeInfoSP getTypeInfoFromType(const OTypeInfoMap& _rTypeInfo,
302 : : sal_Int32 _nType,
303 : : const ::rtl::OUString& _sTypeName,
304 : : const ::rtl::OUString& _sCreateParams,
305 : : sal_Int32 _nPrecision,
306 : : sal_Int32 _nScale,
307 : : sal_Bool _bAutoIncrement,
308 : : sal_Bool& _brForceToType)
309 : : {
310 [ # # ]: 0 : TOTypeInfoSP pTypeInfo;
311 : 0 : _brForceToType = sal_False;
312 : : // search for type
313 [ # # ]: 0 : ::std::pair<OTypeInfoMap::const_iterator, OTypeInfoMap::const_iterator> aPair = _rTypeInfo.equal_range(_nType);
314 : 0 : OTypeInfoMap::const_iterator aIter = aPair.first;
315 [ # # ]: 0 : if(aIter != _rTypeInfo.end()) // compare with end is correct here
316 : : {
317 [ # # ]: 0 : for(;aIter != aPair.second;++aIter)
318 : : {
319 : : // search the best matching type
320 : : #ifdef DBG_UTIL
321 : : ::rtl::OUString sDBTypeName = aIter->second->aTypeName; (void)sDBTypeName;
322 : : sal_Int32 nDBTypePrecision = aIter->second->nPrecision; (void)nDBTypePrecision;
323 : : sal_Int32 nDBTypeScale = aIter->second->nMaximumScale; (void)nDBTypeScale;
324 : : sal_Bool bDBAutoIncrement = aIter->second->bAutoIncrement; (void)bDBAutoIncrement;
325 : : #endif
326 [ # # # # ]: 0 : if ( (
[ # # ][ # # ]
[ # # # #
# # # # #
# # # ]
327 : 0 : _sTypeName.isEmpty()
328 : 0 : || (aIter->second->aTypeName.equalsIgnoreAsciiCase(_sTypeName))
329 : : )
330 : : && (
331 : : (
332 : 0 : !aIter->second->aCreateParams.getLength()
333 : 0 : && _sCreateParams.isEmpty()
334 : : )
335 : : || (
336 : 0 : (aIter->second->nPrecision >= _nPrecision)
337 : 0 : && (aIter->second->nMaximumScale >= _nScale)
338 : 0 : && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
339 : : )
340 : : )
341 : : )
342 : 0 : break;
343 : : }
344 : :
345 [ # # ]: 0 : if (aIter == aPair.second)
346 : : {
347 [ # # ]: 0 : for(aIter = aPair.first; aIter != aPair.second; ++aIter)
348 : : {
349 : 0 : sal_Int32 nPrec = aIter->second->nPrecision;
350 : 0 : sal_Int32 nScale = aIter->second->nMaximumScale;
351 : : // search the best matching type (now comparing the local names)
352 [ # # ][ # # ]: 0 : if ( (aIter->second->aLocalTypeName.equalsIgnoreAsciiCase(_sTypeName))
[ # # # # ]
[ # # ][ # # ]
[ # # ]
353 : : && (nPrec >= _nPrecision)
354 : : && (nScale >= _nScale)
355 : 0 : && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
356 : : )
357 : : {
358 : : OSL_FAIL(( ::rtl::OString("getTypeInfoFromType: assuming column type ")
359 : : += ::rtl::OString(aIter->second->aTypeName.getStr(), aIter->second->aTypeName.getLength(), osl_getThreadTextEncoding())
360 : : += ::rtl::OString("\" (expected type name ")
361 : : += ::rtl::OString(_sTypeName.getStr(), _sTypeName.getLength(), osl_getThreadTextEncoding())
362 : : += ::rtl::OString(" matches the type's local name).")).getStr());
363 : 0 : break;
364 : : }
365 : : }
366 : : }
367 : :
368 [ # # ]: 0 : if (aIter == aPair.second)
369 : : { // no match for the names, no match for the local names
370 : : // -> drop the precision and the scale restriction, accept any type with the property
371 : : // type id (nType)
372 : :
373 [ # # ]: 0 : for(aIter = aPair.first; aIter != aPair.second; ++aIter)
374 : : {
375 : : // search the best matching type (now comparing the local names)
376 : : #ifdef DBG_UTIL
377 : : ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
378 : : #endif
379 : 0 : sal_Int32 nPrec = aIter->second->nPrecision;
380 : 0 : sal_Int32 nScale = aIter->second->nMaximumScale;
381 [ # # ]: 0 : if ( (nPrec >= _nPrecision)
[ # # # # ]
[ # # ][ # # ]
[ # # ]
382 : : && (nScale >= _nScale)
383 : 0 : && ( (_bAutoIncrement && aIter->second->bAutoIncrement) || !_bAutoIncrement )
384 : : )
385 : 0 : break;
386 : : }
387 : : }
388 [ # # ]: 0 : if (aIter == aPair.second)
389 : : {
390 [ # # ]: 0 : if ( _bAutoIncrement )
391 : : {
392 [ # # ]: 0 : for(aIter = aPair.first; aIter != aPair.second; ++aIter)
393 : : {
394 : : // search the best matching type (now comparing the local names)
395 : : #ifdef DBG_UTIL
396 : : ::rtl::OUString sDBTypeName = aIter->second->aTypeName;
397 : : #endif
398 : 0 : sal_Int32 nScale = aIter->second->nMaximumScale;
399 [ # # ]: 0 : if ( (nScale >= _nScale)
[ # # # # ]
400 : 0 : && (aIter->second->bAutoIncrement == _bAutoIncrement)
401 : : )
402 : 0 : break;
403 : : }
404 [ # # ]: 0 : if ( aIter == aPair.second )
405 : : {
406 : : // try it without the auto increment flag
407 : : pTypeInfo = getTypeInfoFromType(_rTypeInfo,
408 : : _nType,
409 : : _sTypeName,
410 : : _sCreateParams,
411 : : _nPrecision,
412 : : _nScale,
413 : : sal_False,
414 [ # # ][ # # ]: 0 : _brForceToType);
[ # # ]
415 : : }
416 : : else
417 [ # # ]: 0 : pTypeInfo = aIter->second;
418 : : }
419 : : else
420 : : {
421 [ # # ]: 0 : pTypeInfo = aPair.first->second;
422 : 0 : _brForceToType = sal_True;
423 : : }
424 : : }
425 : : else
426 [ # # ]: 0 : pTypeInfo = aIter->second;
427 : : }
428 : : else
429 : : {
430 : 0 : ::comphelper::TStringMixEqualFunctor aCase(sal_False);
431 : : // search for typeinfo where the typename is equal _sTypeName
432 : 0 : OTypeInfoMap::const_iterator typeInfoLoop = _rTypeInfo.begin();
433 : 0 : OTypeInfoMap::const_iterator typeInfoEnd = _rTypeInfo.end();
434 [ # # ]: 0 : for (; typeInfoLoop != typeInfoEnd; ++typeInfoLoop)
435 : : {
436 [ # # ]: 0 : if ( aCase( typeInfoLoop->second->getDBName() , _sTypeName ) )
437 : : {
438 [ # # ]: 0 : pTypeInfo = typeInfoLoop->second;
439 : 0 : break;
440 : : }
441 : : }
442 : : }
443 : :
444 : : OSL_ENSURE(pTypeInfo, "getTypeInfoFromType: no type info found for this type!");
445 : 0 : return pTypeInfo;
446 : : }
447 : : // -----------------------------------------------------------------------------
448 : 0 : void fillTypeInfo( const Reference< ::com::sun::star::sdbc::XConnection>& _rxConnection,
449 : : const String& _rsTypeNames,
450 : : OTypeInfoMap& _rTypeInfoMap,
451 : : ::std::vector<OTypeInfoMap::iterator>& _rTypeInfoIters)
452 : : {
453 [ # # ]: 0 : if(!_rxConnection.is())
454 : 0 : return;
455 [ # # ][ # # ]: 0 : Reference< XResultSet> xRs = _rxConnection->getMetaData ()->getTypeInfo ();
[ # # ][ # # ]
456 [ # # ]: 0 : Reference< XRow> xRow(xRs,UNO_QUERY);
457 : : // Information for a single SQL type
458 [ # # ]: 0 : if(xRs.is())
459 : : {
460 [ # # ][ # # ]: 0 : static const ::rtl::OUString aB1(RTL_CONSTASCII_USTRINGPARAM(" [ "));
[ # # ][ # # ]
461 [ # # ][ # # ]: 0 : static const ::rtl::OUString aB2(RTL_CONSTASCII_USTRINGPARAM(" ]"));
[ # # ][ # # ]
462 [ # # ][ # # ]: 0 : Reference<XResultSetMetaData> xResultSetMetaData = Reference<XResultSetMetaDataSupplier>(xRs,UNO_QUERY)->getMetaData();
[ # # ]
463 : 0 : ::connectivity::ORowSetValue aValue;
464 [ # # ]: 0 : ::std::vector<sal_Int32> aTypes;
465 [ # # ]: 0 : ::std::vector<sal_Bool> aNullable;
466 : : // Loop on the result set until we reach end of file
467 [ # # ][ # # ]: 0 : while (xRs->next())
[ # # ]
468 : : {
469 [ # # ][ # # ]: 0 : TOTypeInfoSP pInfo(new OTypeInfo());
470 : 0 : sal_Int32 nPos = 1;
471 [ # # ]: 0 : if ( aTypes.empty() )
472 : : {
473 [ # # ][ # # ]: 0 : sal_Int32 nCount = xResultSetMetaData->getColumnCount();
474 [ # # ]: 0 : if ( nCount < 1 )
475 : 0 : nCount = 18;
476 [ # # ]: 0 : aTypes.reserve(nCount+1);
477 [ # # ]: 0 : aTypes.push_back(-1);
478 [ # # ]: 0 : aNullable.push_back(sal_False);
479 [ # # ]: 0 : for (sal_Int32 j = 1; j <= nCount ; ++j)
480 : : {
481 [ # # ][ # # ]: 0 : aTypes.push_back(xResultSetMetaData->getColumnType(j));
[ # # ]
482 [ # # ][ # # ]: 0 : aNullable.push_back(xResultSetMetaData->isNullable(j) != ColumnValue::NO_NULLS);
[ # # ]
483 : : }
484 : : }
485 : :
486 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
487 [ # # ]: 0 : pInfo->aTypeName = aValue;
488 : 0 : ++nPos;
489 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
490 [ # # ]: 0 : pInfo->nType = aValue;
491 : 0 : ++nPos;
492 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
493 [ # # ]: 0 : pInfo->nPrecision = aValue;
494 : 0 : ++nPos;
495 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
496 [ # # ]: 0 : pInfo->aLiteralPrefix = aValue;
497 : 0 : ++nPos;
498 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
499 [ # # ]: 0 : pInfo->aLiteralSuffix = aValue;
500 : 0 : ++nPos;
501 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
502 [ # # ]: 0 : pInfo->aCreateParams = aValue;
503 : 0 : ++nPos;
504 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
505 [ # # ]: 0 : pInfo->bNullable = (sal_Int32)aValue == ColumnValue::NULLABLE;
506 : 0 : ++nPos;
507 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
508 [ # # ]: 0 : pInfo->bCaseSensitive = (sal_Bool)aValue;
509 : 0 : ++nPos;
510 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
511 [ # # ]: 0 : pInfo->nSearchType = aValue;
512 : 0 : ++nPos;
513 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
514 [ # # ]: 0 : pInfo->bUnsigned = (sal_Bool)aValue;
515 : 0 : ++nPos;
516 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
517 [ # # ]: 0 : pInfo->bCurrency = (sal_Bool)aValue;
518 : 0 : ++nPos;
519 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
520 [ # # ]: 0 : pInfo->bAutoIncrement = (sal_Bool)aValue;
521 : 0 : ++nPos;
522 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
523 [ # # ]: 0 : pInfo->aLocalTypeName = aValue;
524 : 0 : ++nPos;
525 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
526 [ # # ]: 0 : pInfo->nMinimumScale = aValue;
527 : 0 : ++nPos;
528 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
529 [ # # ]: 0 : pInfo->nMaximumScale = aValue;
530 : 0 : nPos = 18;
531 [ # # ][ # # ]: 0 : aValue.fill(nPos,aTypes[nPos],aNullable[nPos],xRow);
[ # # ]
532 : :
533 : : // check if values are less than zero like it happens in a oracle jdbc driver
534 [ # # ]: 0 : if( pInfo->nPrecision < 0)
535 : 0 : pInfo->nPrecision = 0;
536 [ # # ]: 0 : if( pInfo->nMinimumScale < 0)
537 : 0 : pInfo->nMinimumScale = 0;
538 [ # # ]: 0 : if( pInfo->nMaximumScale < 0)
539 : 0 : pInfo->nMaximumScale = 0;
540 : :
541 [ # # ]: 0 : String aName;
542 [ # # # # : 0 : switch(pInfo->nType)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
543 : : {
544 : : case DataType::CHAR:
545 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_CHAR);
[ # # ]
546 : 0 : break;
547 : : case DataType::VARCHAR:
548 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_TEXT);
[ # # ]
549 : 0 : break;
550 : : case DataType::DECIMAL:
551 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_DECIMAL);
[ # # ]
552 : 0 : break;
553 : : case DataType::NUMERIC:
554 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_NUMERIC);
[ # # ]
555 : 0 : break;
556 : : case DataType::BIGINT:
557 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_BIGINT);
[ # # ]
558 : 0 : break;
559 : : case DataType::FLOAT:
560 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_FLOAT);
[ # # ]
561 : 0 : break;
562 : : case DataType::DOUBLE:
563 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_DOUBLE);
[ # # ]
564 : 0 : break;
565 : : case DataType::LONGVARCHAR:
566 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_MEMO);
[ # # ]
567 : 0 : break;
568 : : case DataType::LONGVARBINARY:
569 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_IMAGE);
[ # # ]
570 : 0 : break;
571 : : case DataType::DATE:
572 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_DATE);
[ # # ]
573 : 0 : break;
574 : : case DataType::TIME:
575 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_TIME);
[ # # ]
576 : 0 : break;
577 : : case DataType::TIMESTAMP:
578 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_DATETIME);
[ # # ]
579 : 0 : break;
580 : : case DataType::BIT:
581 [ # # ]: 0 : if ( !pInfo->aCreateParams.isEmpty() )
582 : : {
583 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_BIT);
[ # # ]
584 : 0 : break;
585 : : }
586 : : // run through
587 : : case DataType::BOOLEAN:
588 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_BOOL);
[ # # ]
589 : 0 : break;
590 : : case DataType::TINYINT:
591 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_TINYINT);
[ # # ]
592 : 0 : break;
593 : : case DataType::SMALLINT:
594 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_SMALLINT);
[ # # ]
595 : 0 : break;
596 : : case DataType::INTEGER:
597 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_INTEGER);
[ # # ]
598 : 0 : break;
599 : : case DataType::REAL:
600 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_REAL);
[ # # ]
601 : 0 : break;
602 : : case DataType::BINARY:
603 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_BINARY);
[ # # ]
604 : 0 : break;
605 : : case DataType::VARBINARY:
606 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_VARBINARY);
[ # # ]
607 : 0 : break;
608 : : case DataType::SQLNULL:
609 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_SQLNULL);
[ # # ]
610 : 0 : break;
611 : : case DataType::OBJECT:
612 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_OBJECT);
[ # # ]
613 : 0 : break;
614 : : case DataType::DISTINCT:
615 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_DISTINCT);
[ # # ]
616 : 0 : break;
617 : : case DataType::STRUCT:
618 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_STRUCT);
[ # # ]
619 : 0 : break;
620 : : case DataType::ARRAY:
621 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_ARRAY);
[ # # ]
622 : 0 : break;
623 : : case DataType::BLOB:
624 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_BLOB);
[ # # ]
625 : 0 : break;
626 : : case DataType::CLOB:
627 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_CLOB);
[ # # ]
628 : 0 : break;
629 : : case DataType::REF:
630 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_REF);
[ # # ]
631 : 0 : break;
632 : : case DataType::OTHER:
633 [ # # ][ # # ]: 0 : aName = _rsTypeNames.GetToken(TYPE_OTHER);
[ # # ]
634 : 0 : break;
635 : : }
636 [ # # ]: 0 : if ( aName.Len() )
637 : : {
638 : 0 : pInfo->aUIName = aName.GetBuffer();
639 : 0 : pInfo->aUIName += aB1;
640 : : }
641 : 0 : pInfo->aUIName += pInfo->aTypeName;
642 [ # # ]: 0 : if ( aName.Len() )
643 : 0 : pInfo->aUIName += aB2;
644 : : // Now that we have the type info, save it in the multimap
645 [ # # ][ # # ]: 0 : _rTypeInfoMap.insert(OTypeInfoMap::value_type(pInfo->nType,pInfo));
[ # # ]
646 [ # # ][ # # ]: 0 : }
647 : : // for a faster index access
648 [ # # ]: 0 : _rTypeInfoIters.reserve(_rTypeInfoMap.size());
649 : :
650 : 0 : OTypeInfoMap::iterator aIter = _rTypeInfoMap.begin();
651 : 0 : OTypeInfoMap::iterator aEnd = _rTypeInfoMap.end();
652 [ # # ]: 0 : for(;aIter != aEnd;++aIter)
653 [ # # ]: 0 : _rTypeInfoIters.push_back(aIter);
654 : :
655 : : // Close the result set/statement.
656 : :
657 [ # # ][ # # ]: 0 : ::comphelper::disposeComponent(xRs);
658 : 0 : }
659 : : }
660 : : // -----------------------------------------------------------------------------
661 : 0 : void setColumnProperties(const Reference<XPropertySet>& _rxColumn,const OFieldDescription* _pFieldDesc)
662 : : {
663 [ # # ][ # # ]: 0 : _rxColumn->setPropertyValue(PROPERTY_NAME,makeAny(_pFieldDesc->GetName()));
[ # # ]
664 [ # # ][ # # ]: 0 : _rxColumn->setPropertyValue(PROPERTY_TYPENAME,makeAny(_pFieldDesc->getTypeInfo()->aTypeName));
[ # # ]
665 [ # # ][ # # ]: 0 : _rxColumn->setPropertyValue(PROPERTY_TYPE,makeAny(_pFieldDesc->GetType()));
[ # # ]
666 [ # # ][ # # ]: 0 : _rxColumn->setPropertyValue(PROPERTY_PRECISION,makeAny(_pFieldDesc->GetPrecision()));
[ # # ]
667 [ # # ][ # # ]: 0 : _rxColumn->setPropertyValue(PROPERTY_SCALE,makeAny(_pFieldDesc->GetScale()));
[ # # ]
668 [ # # ][ # # ]: 0 : _rxColumn->setPropertyValue(PROPERTY_ISNULLABLE, makeAny(_pFieldDesc->GetIsNullable()));
[ # # ]
669 [ # # ][ # # ]: 0 : _rxColumn->setPropertyValue(PROPERTY_ISAUTOINCREMENT,::cppu::bool2any(_pFieldDesc->IsAutoIncrement()));
670 [ # # ][ # # ]: 0 : _rxColumn->setPropertyValue(PROPERTY_DESCRIPTION,makeAny(_pFieldDesc->GetDescription()));
[ # # ]
671 [ # # ][ # # ]: 0 : if ( _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_ISCURRENCY) && _pFieldDesc->IsCurrency() )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
[ # # ]
672 [ # # ][ # # ]: 0 : _rxColumn->setPropertyValue(PROPERTY_ISCURRENCY,::cppu::bool2any(_pFieldDesc->IsCurrency()));
673 : : // set autoincrement value when available
674 : : // and only set when the entry is not empty, that lets the value in the column untouched
675 [ # # ][ # # ]: 0 : if ( _pFieldDesc->IsAutoIncrement() && !_pFieldDesc->GetAutoIncrementValue().isEmpty() && _rxColumn->getPropertySetInfo()->hasPropertyByName(PROPERTY_AUTOINCREMENTCREATION) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # #
# # # # #
# ]
676 [ # # ][ # # ]: 0 : _rxColumn->setPropertyValue(PROPERTY_AUTOINCREMENTCREATION,makeAny(_pFieldDesc->GetAutoIncrementValue()));
[ # # ]
677 : 0 : }
678 : : // -----------------------------------------------------------------------------
679 : 0 : ::rtl::OUString createDefaultName(const Reference< XDatabaseMetaData>& _xMetaData,const Reference<XNameAccess>& _xTables,const ::rtl::OUString& _sName)
680 : : {
681 : : OSL_ENSURE(_xMetaData.is(),"No MetaData!");
682 : 0 : ::rtl::OUString sDefaultName = _sName;
683 : : try
684 : : {
685 : 0 : ::rtl::OUString sCatalog,sSchema,sCompsedName;
686 [ # # ][ # # ]: 0 : if(_xMetaData->supportsCatalogsInTableDefinitions())
[ # # ]
687 : : {
688 : : try
689 : : {
690 [ # # ][ # # ]: 0 : Reference< XConnection> xCon = _xMetaData->getConnection();
691 [ # # ]: 0 : if ( xCon.is() )
692 [ # # ][ # # ]: 0 : sCatalog = xCon->getCatalog();
693 [ # # ]: 0 : if ( sCatalog.isEmpty() )
694 : : {
695 [ # # ][ # # ]: 0 : Reference<XResultSet> xRes = _xMetaData->getCatalogs();
696 [ # # ]: 0 : Reference<XRow> xRow(xRes,UNO_QUERY);
697 [ # # ][ # # ]: 0 : while(xRes.is() && xRes->next())
[ # # ][ # # ]
[ # # ]
698 : : {
699 [ # # ][ # # ]: 0 : sCatalog = xRow->getString(1);
700 [ # # ][ # # ]: 0 : if(!xRow->wasNull())
[ # # ]
701 : 0 : break;
702 : 0 : }
703 [ # # ]: 0 : }
704 : : }
705 [ # # ]: 0 : catch(const SQLException&)
706 : : {
707 : : }
708 : : }
709 [ # # ][ # # ]: 0 : if(_xMetaData->supportsSchemasInTableDefinitions())
[ # # ]
710 : : {
711 [ # # ][ # # ]: 0 : sSchema = _xMetaData->getUserName();
712 : : }
713 [ # # ]: 0 : sCompsedName = ::dbtools::composeTableName( _xMetaData, sCatalog, sSchema, _sName, sal_False, ::dbtools::eInDataManipulation );
714 [ # # ][ # # ]: 0 : sDefaultName = ::dbtools::createUniqueName(_xTables,sCompsedName);
715 : : }
716 [ # # ]: 0 : catch(const SQLException&)
717 : : {
718 : : }
719 : 0 : return sDefaultName;
720 : : }
721 : : // -----------------------------------------------------------------------------
722 : 0 : sal_Bool checkDataSourceAvailable(const ::rtl::OUString& _sDataSourceName,const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xORB)
723 : : {
724 : 0 : sal_Bool bRet = sal_False;
725 [ # # ][ # # ]: 0 : Reference< XNameAccess > xDataBaseContext(_xORB->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
[ # # ][ # # ]
[ # # ]
726 [ # # ]: 0 : if ( xDataBaseContext.is() )
727 : : {
728 [ # # ][ # # ]: 0 : bRet = xDataBaseContext->hasByName(_sDataSourceName);
729 [ # # ]: 0 : if ( !bRet )
730 : : { // try if this one is a URL
731 : : try
732 : : {
733 [ # # ][ # # ]: 0 : bRet = xDataBaseContext->getByName(_sDataSourceName).hasValue();
734 : : }
735 [ # # ]: 0 : catch(const Exception&)
736 : : {
737 : : }
738 : : }
739 : : }
740 : 0 : return bRet;
741 : : }
742 : : // -----------------------------------------------------------------------------
743 : 0 : sal_Int32 mapTextAllign(const SvxCellHorJustify& _eAlignment)
744 : : {
745 : 0 : sal_Int32 nAlignment = com::sun::star::awt::TextAlign::LEFT;
746 [ # # # # ]: 0 : switch (_eAlignment)
747 : : {
748 : : case SVX_HOR_JUSTIFY_STANDARD:
749 : 0 : case SVX_HOR_JUSTIFY_LEFT: nAlignment = ::com::sun::star::awt::TextAlign::LEFT; break;
750 : 0 : case SVX_HOR_JUSTIFY_CENTER: nAlignment = ::com::sun::star::awt::TextAlign::CENTER; break;
751 : 0 : case SVX_HOR_JUSTIFY_RIGHT: nAlignment = ::com::sun::star::awt::TextAlign::RIGHT; break;
752 : : default:
753 : : OSL_FAIL("Invalid TextAlign!");
754 : : }
755 : 0 : return nAlignment;
756 : : }
757 : : // -----------------------------------------------------------------------------
758 : 0 : SvxCellHorJustify mapTextJustify(const sal_Int32& _nAlignment)
759 : : {
760 : 0 : SvxCellHorJustify eJustify = SVX_HOR_JUSTIFY_LEFT;
761 [ # # # # ]: 0 : switch (_nAlignment)
762 : : {
763 : 0 : case ::com::sun::star::awt::TextAlign::LEFT : eJustify = SVX_HOR_JUSTIFY_LEFT; break;
764 : 0 : case ::com::sun::star::awt::TextAlign::CENTER : eJustify = SVX_HOR_JUSTIFY_CENTER; break;
765 : 0 : case ::com::sun::star::awt::TextAlign::RIGHT : eJustify = SVX_HOR_JUSTIFY_RIGHT; break;
766 : : default:
767 : : OSL_FAIL("Invalid TextAlign!");
768 : : }
769 : 0 : return eJustify;
770 : : }
771 : : // -----------------------------------------------------------------------------
772 : 0 : float ConvertFontWeight( ::FontWeight eWeight )
773 : : {
774 [ # # ]: 0 : if( eWeight == WEIGHT_DONTKNOW )
775 : 0 : return ::com::sun::star::awt::FontWeight::DONTKNOW;
776 [ # # ]: 0 : else if( eWeight == WEIGHT_THIN )
777 : 0 : return ::com::sun::star::awt::FontWeight::THIN;
778 [ # # ]: 0 : else if( eWeight == WEIGHT_ULTRALIGHT )
779 : 0 : return ::com::sun::star::awt::FontWeight::ULTRALIGHT;
780 [ # # ]: 0 : else if( eWeight == WEIGHT_LIGHT )
781 : 0 : return ::com::sun::star::awt::FontWeight::LIGHT;
782 [ # # ]: 0 : else if( eWeight == WEIGHT_SEMILIGHT )
783 : 0 : return ::com::sun::star::awt::FontWeight::SEMILIGHT;
784 [ # # ][ # # ]: 0 : else if( ( eWeight == WEIGHT_NORMAL ) || ( eWeight == WEIGHT_MEDIUM ) )
785 : 0 : return ::com::sun::star::awt::FontWeight::NORMAL;
786 [ # # ]: 0 : else if( eWeight == WEIGHT_SEMIBOLD )
787 : 0 : return ::com::sun::star::awt::FontWeight::SEMIBOLD;
788 [ # # ]: 0 : else if( eWeight == WEIGHT_BOLD )
789 : 0 : return ::com::sun::star::awt::FontWeight::BOLD;
790 [ # # ]: 0 : else if( eWeight == WEIGHT_ULTRABOLD )
791 : 0 : return ::com::sun::star::awt::FontWeight::ULTRABOLD;
792 [ # # ]: 0 : else if( eWeight == WEIGHT_BLACK )
793 : 0 : return ::com::sun::star::awt::FontWeight::BLACK;
794 : :
795 : : OSL_FAIL("Unknown FontWeigth" );
796 : 0 : return ::com::sun::star::awt::FontWeight::DONTKNOW;
797 : : }
798 : : // -----------------------------------------------------------------------------
799 : 0 : float ConvertFontWidth( ::FontWidth eWidth )
800 : : {
801 [ # # ]: 0 : if( eWidth == WIDTH_DONTKNOW )
802 : 0 : return ::com::sun::star::awt::FontWidth::DONTKNOW;
803 [ # # ]: 0 : else if( eWidth == WIDTH_ULTRA_CONDENSED )
804 : 0 : return ::com::sun::star::awt::FontWidth::ULTRACONDENSED;
805 [ # # ]: 0 : else if( eWidth == WIDTH_EXTRA_CONDENSED )
806 : 0 : return ::com::sun::star::awt::FontWidth::EXTRACONDENSED;
807 [ # # ]: 0 : else if( eWidth == WIDTH_CONDENSED )
808 : 0 : return ::com::sun::star::awt::FontWidth::CONDENSED;
809 [ # # ]: 0 : else if( eWidth == WIDTH_SEMI_CONDENSED )
810 : 0 : return ::com::sun::star::awt::FontWidth::SEMICONDENSED;
811 [ # # ]: 0 : else if( eWidth == WIDTH_NORMAL )
812 : 0 : return ::com::sun::star::awt::FontWidth::NORMAL;
813 [ # # ]: 0 : else if( eWidth == WIDTH_SEMI_EXPANDED )
814 : 0 : return ::com::sun::star::awt::FontWidth::SEMIEXPANDED;
815 [ # # ]: 0 : else if( eWidth == WIDTH_EXPANDED )
816 : 0 : return ::com::sun::star::awt::FontWidth::EXPANDED;
817 [ # # ]: 0 : else if( eWidth == WIDTH_EXTRA_EXPANDED )
818 : 0 : return ::com::sun::star::awt::FontWidth::EXTRAEXPANDED;
819 [ # # ]: 0 : else if( eWidth == WIDTH_ULTRA_EXPANDED )
820 : 0 : return ::com::sun::star::awt::FontWidth::ULTRAEXPANDED;
821 : :
822 : : OSL_FAIL("Unknown FontWidth" );
823 : 0 : return ::com::sun::star::awt::FontWidth::DONTKNOW;
824 : : }
825 : : // -----------------------------------------------------------------------------
826 : 0 : ::com::sun::star::awt::FontDescriptor CreateFontDescriptor( const Font& rFont )
827 : : {
828 : 0 : ::com::sun::star::awt::FontDescriptor aFD;
829 [ # # ][ # # ]: 0 : aFD.Name = rFont.GetName();
830 [ # # ][ # # ]: 0 : aFD.StyleName = rFont.GetStyleName();
831 [ # # ]: 0 : aFD.Height = (sal_Int16)rFont.GetSize().Height();
832 [ # # ]: 0 : aFD.Width = (sal_Int16)rFont.GetSize().Width();
833 [ # # ]: 0 : aFD.Family = sal::static_int_cast< sal_Int16 >(rFont.GetFamily());
834 [ # # ]: 0 : aFD.CharSet = rFont.GetCharSet();
835 [ # # ]: 0 : aFD.Pitch = sal::static_int_cast< sal_Int16 >(rFont.GetPitch());
836 [ # # ]: 0 : aFD.CharacterWidth = ConvertFontWidth( rFont.GetWidthType() );
837 [ # # ]: 0 : aFD.Weight = ConvertFontWeight( rFont.GetWeight() );
838 [ # # ]: 0 : aFD.Slant = (::com::sun::star::awt::FontSlant)rFont.GetItalic();
839 : : aFD.Underline = sal::static_int_cast< sal_Int16 >(
840 [ # # ]: 0 : rFont.GetUnderline());
841 : : aFD.Strikeout = sal::static_int_cast< sal_Int16 >(
842 [ # # ]: 0 : rFont.GetStrikeout());
843 [ # # ]: 0 : aFD.Orientation = rFont.GetOrientation();
844 [ # # ]: 0 : aFD.Kerning = rFont.IsKerning();
845 [ # # ]: 0 : aFD.WordLineMode = rFont.IsWordLineMode();
846 : 0 : aFD.Type = 0; // ??? => Nur an Metric...
847 : 0 : return aFD;
848 : : }
849 : : // -----------------------------------------------------------------------------
850 : 0 : void callColumnFormatDialog(const Reference<XPropertySet>& xAffectedCol,
851 : : const Reference<XPropertySet>& xField,
852 : : SvNumberFormatter* _pFormatter,
853 : : Window* _pParent)
854 : : {
855 [ # # ][ # # ]: 0 : if (xAffectedCol.is() && xField.is())
[ # # ]
856 : : {
857 : : try
858 : : {
859 [ # # ][ # # ]: 0 : Reference< XPropertySetInfo > xInfo = xAffectedCol->getPropertySetInfo();
860 [ # # ][ # # ]: 0 : sal_Bool bHasFormat = xInfo->hasPropertyByName(PROPERTY_FORMATKEY);
[ # # ]
861 [ # # ][ # # ]: 0 : sal_Int32 nDataType = ::comphelper::getINT32(xField->getPropertyValue(PROPERTY_TYPE));
[ # # ][ # # ]
862 : :
863 : 0 : SvxCellHorJustify eJustify(SVX_HOR_JUSTIFY_STANDARD);
864 [ # # ][ # # ]: 0 : Any aAlignment = xAffectedCol->getPropertyValue(PROPERTY_ALIGN);
[ # # ]
865 [ # # ]: 0 : if (aAlignment.hasValue())
866 [ # # ]: 0 : eJustify = dbaui::mapTextJustify(::comphelper::getINT16(aAlignment));
867 : 0 : sal_Int32 nFormatKey = 0;
868 [ # # ]: 0 : if ( bHasFormat )
869 [ # # ][ # # ]: 0 : nFormatKey = ::comphelper::getINT32(xAffectedCol->getPropertyValue(PROPERTY_FORMATKEY));
[ # # ][ # # ]
870 : :
871 : 0 : sal_uInt16 nFlags = 0;
872 [ # # ][ # # ]: 0 : if(callColumnFormatDialog(_pParent,_pFormatter,nDataType,nFormatKey,eJustify,nFlags,bHasFormat))
873 : : {
874 [ # # ][ # # ]: 0 : xAffectedCol->setPropertyValue(PROPERTY_ALIGN, makeAny((sal_Int16)dbaui::mapTextAllign(eJustify)));
[ # # ][ # # ]
875 [ # # ]: 0 : if (nFlags & TP_ATTR_NUMBER)
876 [ # # ][ # # ]: 0 : xAffectedCol->setPropertyValue(PROPERTY_FORMATKEY, makeAny(nFormatKey));
[ # # ][ # # ]
877 : :
878 [ # # ]: 0 : }
879 : : }
880 : 0 : catch( const Exception& )
881 : : {
882 : : DBG_UNHANDLED_EXCEPTION();
883 : : }
884 : : }
885 : 0 : }
886 : : // -----------------------------------------------------------------------------
887 : 0 : sal_Bool callColumnFormatDialog(Window* _pParent,
888 : : SvNumberFormatter* _pFormatter,
889 : : sal_Int32 _nDataType,
890 : : sal_Int32& _nFormatKey,
891 : : SvxCellHorJustify& _eJustify,
892 : : sal_uInt16& _nFlags,
893 : : sal_Bool _bHasFormat)
894 : : {
895 : 0 : sal_Bool bRet = sal_False;
896 : : // the allowed format changes depending on the type of the field ...
897 : 0 : _nFlags = TP_ATTR_ALIGN;
898 : :
899 [ # # ]: 0 : if (_bHasFormat)
900 : 0 : _nFlags |= TP_ATTR_NUMBER;
901 : :
902 : : // ------------
903 : : // UNO->ItemSet
904 : : static SfxItemInfo aItemInfos[] =
905 : : {
906 : : { 0, 0 },
907 : : { SID_ATTR_NUMBERFORMAT_VALUE, SFX_ITEM_POOLABLE },
908 : : { SID_ATTR_ALIGN_HOR_JUSTIFY, SFX_ITEM_POOLABLE },
909 : : { SID_ATTR_NUMBERFORMAT_ONE_AREA, SFX_ITEM_POOLABLE },
910 : : { SID_ATTR_NUMBERFORMAT_INFO, SFX_ITEM_POOLABLE }
911 : : };
912 : : static sal_uInt16 aAttrMap[] =
913 : : {
914 : : SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY,
915 : : SID_ATTR_NUMBERFORMAT_ONE_AREA, SID_ATTR_NUMBERFORMAT_ONE_AREA,
916 : : SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO,
917 : : 0
918 : : };
919 : :
920 : : SfxPoolItem* pDefaults[] =
921 : : {
922 [ # # ]: 0 : new SfxRangeItem(SBA_DEF_RANGEFORMAT, SBA_DEF_FMTVALUE, SBA_ATTR_ALIGN_HOR_JUSTIFY),
923 [ # # ]: 0 : new SfxUInt32Item(SBA_DEF_FMTVALUE),
924 [ # # ]: 0 : new SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, SBA_ATTR_ALIGN_HOR_JUSTIFY),
925 [ # # ]: 0 : new SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_False),
926 [ # # ]: 0 : new SvxNumberInfoItem(SID_ATTR_NUMBERFORMAT_INFO)
927 [ # # ][ # # ]: 0 : };
[ # # ][ # # ]
[ # # ]
928 : :
929 [ # # ][ # # ]: 0 : SfxItemPool* pPool = new SfxItemPool(rtl::OUString("GridBrowserProperties"), SBA_DEF_RANGEFORMAT, SBA_ATTR_ALIGN_HOR_JUSTIFY, aItemInfos, pDefaults);
930 [ # # ]: 0 : pPool->SetDefaultMetric( SFX_MAPUNIT_TWIP ); // ripped, don't understand why
931 [ # # ]: 0 : pPool->FreezeIdRanges(); // the same
932 : :
933 [ # # ][ # # ]: 0 : SfxItemSet* pFormatDescriptor = new SfxItemSet(*pPool, aAttrMap);
934 : : // fill it
935 [ # # ][ # # ]: 0 : pFormatDescriptor->Put(SvxHorJustifyItem(_eJustify, SBA_ATTR_ALIGN_HOR_JUSTIFY));
[ # # ]
936 : 0 : sal_Bool bText = sal_False;
937 [ # # ]: 0 : if (_bHasFormat)
938 : : {
939 : : // if the col is bound to a text field we have to disallow all non-text formats
940 [ # # ][ # # ]: 0 : if ((DataType::CHAR == _nDataType) || (DataType::VARCHAR == _nDataType) || (DataType::LONGVARCHAR == _nDataType) || (DataType::CLOB == _nDataType))
[ # # ][ # # ]
941 : : {
942 : 0 : bText = sal_True;
943 [ # # ][ # # ]: 0 : pFormatDescriptor->Put(SfxBoolItem(SID_ATTR_NUMBERFORMAT_ONE_AREA, sal_True));
[ # # ]
944 [ # # ][ # # ]: 0 : if (!_pFormatter->IsTextFormat(_nFormatKey))
945 : : // text fields can only have text formats
946 [ # # ][ # # ]: 0 : _nFormatKey = _pFormatter->GetStandardFormat(NUMBERFORMAT_TEXT,_pParent->GetSettings().GetLanguage());
947 : : }
948 : :
949 [ # # ][ # # ]: 0 : pFormatDescriptor->Put(SfxUInt32Item(SBA_DEF_FMTVALUE, _nFormatKey));
[ # # ]
950 : : }
951 : :
952 [ # # ]: 0 : if (!bText)
953 : : {
954 : 0 : double dPreviewVal = 1234.56789;
955 [ # # ]: 0 : SvxNumberInfoItem aFormatter(_pFormatter, dPreviewVal, SID_ATTR_NUMBERFORMAT_INFO);
956 [ # # ][ # # ]: 0 : pFormatDescriptor->Put(aFormatter);
957 : : }
958 : :
959 : : { // want the dialog to be destroyed before our set
960 [ # # ]: 0 : SbaSbAttrDlg aDlg(_pParent, pFormatDescriptor, _pFormatter, _nFlags);
961 [ # # ][ # # ]: 0 : if (RET_OK == aDlg.Execute())
962 : : {
963 : : // ------------
964 : : // ItemSet->UNO
965 : : // UNO-properties
966 : 0 : const SfxItemSet* pSet = aDlg.GetExampleSet();
967 : : // (of course we could put the modified items directly into the column, but then the UNO-model
968 : : // won't reflect these changes, and why do we have a model, then ?)
969 : :
970 : : // horizontal justify
971 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*pSet, pHorJustify, SvxHorJustifyItem, SBA_ATTR_ALIGN_HOR_JUSTIFY, sal_True);
972 : :
973 : 0 : _eJustify = (SvxCellHorJustify)pHorJustify->GetValue();
974 : :
975 : : // format key
976 [ # # ]: 0 : if (_nFlags & TP_ATTR_NUMBER)
977 : : {
978 [ # # ][ # # ]: 0 : SFX_ITEMSET_GET(*pSet, pFormat, SfxUInt32Item, SBA_DEF_FMTVALUE, sal_True);
979 : 0 : _nFormatKey = (sal_Int32)pFormat->GetValue();
980 : : }
981 : 0 : bRet = sal_True;
982 : : }
983 : : // deleted formats
984 : 0 : const SfxItemSet* pResult = aDlg.GetOutputItemSet();
985 [ # # ]: 0 : if (pResult)
986 : : {
987 [ # # ]: 0 : const SfxPoolItem* pItem = pResult->GetItem( SID_ATTR_NUMBERFORMAT_INFO );
988 : 0 : const SvxNumberInfoItem* pInfoItem = static_cast<const SvxNumberInfoItem*>(pItem);
989 [ # # ][ # # ]: 0 : if (pInfoItem && pInfoItem->GetDelCount())
[ # # ]
990 : : {
991 : 0 : const sal_uInt32* pDeletedKeys = pInfoItem->GetDelArray();
992 : :
993 [ # # ]: 0 : for (sal_uInt16 i=0; i< pInfoItem->GetDelCount(); ++i, ++pDeletedKeys)
994 [ # # ]: 0 : _pFormatter->DeleteEntry(*pDeletedKeys);
995 : : }
996 [ # # ]: 0 : }
997 : : }
998 : :
999 [ # # ][ # # ]: 0 : delete pFormatDescriptor;
1000 [ # # ]: 0 : SfxItemPool::Free(pPool);
1001 [ # # ]: 0 : for (sal_uInt16 i=0; i<sizeof(pDefaults)/sizeof(pDefaults[0]); ++i)
1002 [ # # ][ # # ]: 0 : delete pDefaults[i];
1003 : :
1004 : 0 : return bRet;
1005 : : }
1006 : :
1007 : : //------------------------------------------------------------------------------
1008 : 0 : const SfxFilter* getStandardDatabaseFilter()
1009 : : {
1010 [ # # ][ # # ]: 0 : const SfxFilter* pFilter = SfxFilter::GetFilterByName(rtl::OUString("StarOffice XML (Base)"));
[ # # ]
1011 : : OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
1012 : 0 : return pFilter;
1013 : : }
1014 : :
1015 : :
1016 : : // -----------------------------------------------------------------------------
1017 : 0 : sal_Bool appendToFilter(const Reference<XConnection>& _xConnection,
1018 : : const ::rtl::OUString& _sName,
1019 : : const Reference< XMultiServiceFactory >& _xFactory,
1020 : : Window* _pParent)
1021 : : {
1022 : 0 : sal_Bool bRet = sal_False;
1023 [ # # ]: 0 : Reference< XChild> xChild(_xConnection,UNO_QUERY);
1024 [ # # ]: 0 : if(xChild.is())
1025 : : {
1026 [ # # ][ # # ]: 0 : Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
[ # # ]
1027 [ # # ]: 0 : if(xProp.is())
1028 : : {
1029 [ # # ]: 0 : Sequence< ::rtl::OUString > aFilter;
1030 [ # # ][ # # ]: 0 : xProp->getPropertyValue(PROPERTY_TABLEFILTER) >>= aFilter;
[ # # ][ # # ]
1031 : : // first check if we have something like SCHEMA.%
1032 : 0 : sal_Bool bHasToInsert = sal_True;
1033 : 0 : const ::rtl::OUString* pBegin = aFilter.getConstArray();
1034 : 0 : const ::rtl::OUString* pEnd = pBegin + aFilter.getLength();
1035 [ # # ]: 0 : for (;pBegin != pEnd; ++pBegin)
1036 : : {
1037 [ # # ]: 0 : if(pBegin->indexOf('%') != -1)
1038 : : {
1039 : : sal_Int32 nLen;
1040 [ # # ][ # # ]: 0 : if((nLen = pBegin->lastIndexOf('.')) != -1 && !pBegin->compareTo(_sName,nLen))
[ # # ]
1041 : 0 : bHasToInsert = sal_False;
1042 [ # # ]: 0 : else if(pBegin->getLength() == 1)
1043 : 0 : bHasToInsert = sal_False;
1044 : : }
1045 : : }
1046 : :
1047 : 0 : bRet = sal_True;
1048 [ # # ]: 0 : if(bHasToInsert)
1049 : : {
1050 [ # # ][ # # ]: 0 : if(! ::dbaui::checkDataSourceAvailable(::comphelper::getString(xProp->getPropertyValue(PROPERTY_NAME)),_xFactory))
[ # # ][ # # ]
[ # # ][ # # ]
1051 : : {
1052 [ # # ][ # # ]: 0 : String aMessage(ModuleRes(STR_TABLEDESIGN_DATASOURCE_DELETED));
1053 [ # # ][ # # ]: 0 : OSQLWarningBox( _pParent, aMessage ).Execute();
[ # # ]
1054 [ # # ]: 0 : bRet = sal_False;
1055 : : }
1056 : : else
1057 : : {
1058 [ # # ]: 0 : aFilter.realloc(aFilter.getLength()+1);
1059 [ # # ]: 0 : aFilter.getArray()[aFilter.getLength()-1] = _sName;
1060 [ # # ][ # # ]: 0 : xProp->setPropertyValue(PROPERTY_TABLEFILTER,makeAny(aFilter));
[ # # ][ # # ]
1061 : : }
1062 [ # # ]: 0 : }
1063 : 0 : }
1064 : : }
1065 : 0 : return bRet;
1066 : : }
1067 : : // -----------------------------------------------------------------------------
1068 : 0 : void notifySystemWindow(Window* _pWindow,Window* _pToRegister, ::comphelper::mem_fun1_t<TaskPaneList,Window*> _rMemFunc)
1069 : : {
1070 : : OSL_ENSURE(_pWindow,"Window can not be null!");
1071 [ # # ]: 0 : SystemWindow* pSystemWindow = _pWindow ? _pWindow->GetSystemWindow() : NULL;
1072 [ # # ]: 0 : if ( pSystemWindow )
1073 : : {
1074 : 0 : _rMemFunc( pSystemWindow->GetTaskPaneList(), _pToRegister );
1075 : : }
1076 : 0 : }
1077 : : // -----------------------------------------------------------------------------
1078 : 0 : void adjustToolBoxSize(ToolBox* _pToolBox)
1079 : : {
1080 : : // adjust the toolbox size, otherwise large bitmaps don't fit into
1081 [ # # ]: 0 : Size aOldSize = _pToolBox->GetSizePixel();
1082 [ # # ]: 0 : Size aSize = _pToolBox->CalcWindowSizePixel();
1083 [ # # ]: 0 : if ( !aSize.Width() )
1084 : 0 : aSize.Width() = aOldSize.Width();
1085 [ # # ]: 0 : else if ( !aSize.Height() )
1086 : 0 : aSize.Height() = aOldSize.Height();
1087 : :
1088 [ # # ]: 0 : Size aTbSize = _pToolBox->GetSizePixel();
1089 [ # # ][ # # : 0 : if ( (aSize.Width() && aSize.Width() != aTbSize.Width()) ||
# # # # ]
[ # # ]
1090 : 0 : (aSize.Height() && aSize.Height() != aTbSize.Height()) )
1091 : : {
1092 [ # # ][ # # ]: 0 : _pToolBox->SetPosSizePixel( _pToolBox->GetPosPixel(), aSize );
1093 [ # # ]: 0 : _pToolBox->Invalidate();
1094 : : }
1095 : 0 : }
1096 : : // -----------------------------------------------------------------------------
1097 : 0 : void adjustBrowseBoxColumnWidth( ::svt::EditBrowseBox* _pBox, sal_uInt16 _nColId )
1098 : : {
1099 : 0 : sal_Int32 nColSize = -1;
1100 [ # # ][ # # ]: 0 : sal_uInt32 nDefaultWidth = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
[ # # ]
1101 [ # # ][ # # ]: 0 : if ( nDefaultWidth != _pBox->GetColumnWidth( _nColId ) )
1102 : : {
1103 [ # # ][ # # ]: 0 : Size aSizeMM = _pBox->PixelToLogic( Size( _pBox->GetColumnWidth( _nColId ), 0 ), MapMode( MAP_MM ) );
[ # # ][ # # ]
1104 : 0 : nColSize = aSizeMM.Width() * 10;
1105 : : }
1106 : :
1107 [ # # ][ # # ]: 0 : Size aDefaultMM = _pBox->PixelToLogic( Size( nDefaultWidth, 0 ), MapMode( MAP_MM ) );
[ # # ]
1108 : :
1109 [ # # ]: 0 : DlgSize aColumnSizeDlg( _pBox, nColSize, sal_False, aDefaultMM.Width() * 10 );
1110 [ # # ][ # # ]: 0 : if ( aColumnSizeDlg.Execute() )
1111 : : {
1112 [ # # ]: 0 : sal_Int32 nValue = aColumnSizeDlg.GetValue();
1113 [ # # ]: 0 : if ( -1 == nValue )
1114 : : { // default width
1115 [ # # ][ # # ]: 0 : nValue = _pBox->GetDefaultColumnWidth( _pBox->GetColumnTitle( _nColId ) );
[ # # ]
1116 : : }
1117 : : else
1118 : : {
1119 : 0 : Size aSizeMM( nValue / 10, 0 );
1120 [ # # ][ # # ]: 0 : nValue = _pBox->LogicToPixel( aSizeMM, MapMode( MAP_MM ) ).Width();
[ # # ]
1121 : : }
1122 [ # # ]: 0 : _pBox->SetColumnWidth( _nColId, nValue );
1123 [ # # ]: 0 : }
1124 : 0 : }
1125 : : // -----------------------------------------------------------------------------
1126 : : // check if SQL92 name checking is enabled
1127 : 0 : sal_Bool isSQL92CheckEnabled(const Reference<XConnection>& _xConnection)
1128 : : {
1129 : 0 : return ::dbtools::getBooleanDataSourceSetting( _xConnection, PROPERTY_ENABLESQL92CHECK.ascii );
1130 : : }
1131 : : // -----------------------------------------------------------------------------
1132 : 0 : sal_Bool isAppendTableAliasEnabled(const Reference<XConnection>& _xConnection)
1133 : : {
1134 : 0 : return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_APPEND_TABLE_ALIAS.ascii );
1135 : : }
1136 : :
1137 : : // -----------------------------------------------------------------------------
1138 : 0 : sal_Bool generateAsBeforeTableAlias(const Reference<XConnection>& _xConnection)
1139 : : {
1140 : 0 : return ::dbtools::getBooleanDataSourceSetting( _xConnection, INFO_AS_BEFORE_CORRELATION_NAME.ascii );
1141 : : }
1142 : :
1143 : : // -----------------------------------------------------------------------------
1144 : 0 : void fillAutoIncrementValue(const Reference<XPropertySet>& _xDatasource,
1145 : : sal_Bool& _rAutoIncrementValueEnabled,
1146 : : ::rtl::OUString& _rsAutoIncrementValue)
1147 : : {
1148 [ # # ]: 0 : if ( _xDatasource.is() )
1149 : : {
1150 : : OSL_ENSURE(_xDatasource->getPropertySetInfo()->hasPropertyByName(PROPERTY_INFO),"NO datasource supplied!");
1151 [ # # ]: 0 : Sequence<PropertyValue> aInfo;
1152 [ # # ][ # # ]: 0 : _xDatasource->getPropertyValue(PROPERTY_INFO) >>= aInfo;
[ # # ][ # # ]
1153 : :
1154 : : // search the right propertyvalue
1155 : : const PropertyValue* pValue =::std::find_if(aInfo.getConstArray(),
1156 : 0 : aInfo.getConstArray() + aInfo.getLength(),
1157 [ # # # # ]: 0 : ::std::bind2nd(TPropertyValueEqualFunctor(),PROPERTY_AUTOINCREMENTCREATION));
1158 [ # # ][ # # ]: 0 : if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
[ # # ]
1159 : 0 : pValue->Value >>= _rsAutoIncrementValue;
1160 : : pValue =::std::find_if(aInfo.getConstArray(),
1161 : 0 : aInfo.getConstArray() + aInfo.getLength(),
1162 [ # # ]: 0 : ::std::bind2nd(TPropertyValueEqualFunctor(),::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsAutoRetrievingEnabled")) ));
[ # # # # ]
1163 [ # # ][ # # ]: 0 : if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
[ # # ]
1164 [ # # ]: 0 : pValue->Value >>= _rAutoIncrementValueEnabled;
1165 : : }
1166 : 0 : }
1167 : : // -----------------------------------------------------------------------------
1168 : 0 : void fillAutoIncrementValue(const Reference<XConnection>& _xConnection,
1169 : : sal_Bool& _rAutoIncrementValueEnabled,
1170 : : ::rtl::OUString& _rsAutoIncrementValue)
1171 : : {
1172 [ # # ]: 0 : Reference< XChild> xChild(_xConnection,UNO_QUERY);
1173 [ # # ]: 0 : if(xChild.is())
1174 : : {
1175 [ # # ][ # # ]: 0 : Reference< XPropertySet> xProp(xChild->getParent(),UNO_QUERY);
[ # # ]
1176 [ # # ]: 0 : fillAutoIncrementValue(xProp,_rAutoIncrementValueEnabled,_rsAutoIncrementValue);
1177 : 0 : }
1178 : 0 : }
1179 : : // -----------------------------------------------------------------------------
1180 : 0 : ::rtl::OUString getStrippedDatabaseName(const Reference<XPropertySet>& _xDataSource,::rtl::OUString& _rsDatabaseName)
1181 : : {
1182 [ # # ][ # # ]: 0 : if ( _rsDatabaseName.isEmpty() && _xDataSource.is() )
[ # # ]
1183 : : {
1184 : : try
1185 : : {
1186 [ # # ][ # # ]: 0 : _xDataSource->getPropertyValue(PROPERTY_NAME) >>= _rsDatabaseName;
[ # # ][ # # ]
1187 : : }
1188 [ # # ]: 0 : catch(const Exception& )
1189 : : {
1190 : : DBG_UNHANDLED_EXCEPTION();
1191 : : }
1192 : : }
1193 : 0 : ::rtl::OUString sName = _rsDatabaseName;
1194 [ # # ]: 0 : INetURLObject aURL(sName);
1195 [ # # ]: 0 : if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1196 [ # # ]: 0 : sName = aURL.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_UNAMBIGUOUS);
1197 [ # # ]: 0 : return sName;
1198 : : }
1199 : : // -----------------------------------------------------------------------------
1200 : 0 : void AppendConfigToken( ::rtl::OUString& _rURL, sal_Bool _bQuestionMark )
1201 : : {
1202 : : // query part exists?
1203 [ # # ]: 0 : if ( _bQuestionMark )
1204 : : // no, so start with '?'
1205 : 0 : _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("?"));
1206 : : else
1207 : : // yes, so only append with '&'
1208 : 0 : _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&"));
1209 : :
1210 : : // set parameters
1211 : 0 : _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Language="));
1212 : 0 : _rURL += utl::ConfigManager::getLocale();
1213 : 0 : _rURL += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("&System="));
1214 [ # # ][ # # ]: 0 : _rURL += SvtHelpOptions().GetSystem();
[ # # ]
1215 : 0 : }
1216 : :
1217 : : namespace
1218 : : {
1219 : : // -----------------------------------------------------------------------
1220 : :
1221 : 0 : sal_Bool GetHelpAnchor_Impl( const ::rtl::OUString& _rURL, ::rtl::OUString& _rAnchor )
1222 : : {
1223 : 0 : sal_Bool bRet = sal_False;
1224 : 0 : ::rtl::OUString sAnchor;
1225 : :
1226 : : try
1227 : : {
1228 : : ::ucbhelper::Content aCnt( INetURLObject( _rURL ).GetMainURL( INetURLObject::NO_DECODE ),
1229 [ # # ][ # # ]: 0 : Reference< ::com::sun::star::ucb::XCommandEnvironment > () );
[ # # ][ # # ]
1230 [ # # ][ # # ]: 0 : if ( ( aCnt.getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AnchorName")) ) >>= sAnchor ) )
[ # # ]
1231 : : {
1232 : :
1233 [ # # ]: 0 : if ( !sAnchor.isEmpty() )
1234 : : {
1235 : 0 : _rAnchor = sAnchor;
1236 : 0 : bRet = sal_True;
1237 : : }
1238 : : }
1239 : : else
1240 : : {
1241 : : SAL_WARN( "dbaccess.ui", "Property 'AnchorName' is missing" );
1242 [ # # ][ # # ]: 0 : }
1243 : : }
1244 [ # # ]: 0 : catch( Exception& )
1245 : : {
1246 : : }
1247 : :
1248 : 0 : return bRet;
1249 : : }
1250 : : // .........................................................................
1251 : : } // annonymous
1252 : : // .........................................................................
1253 : : // -----------------------------------------------------------------------------
1254 : 0 : ::com::sun::star::util::URL createHelpAgentURL(const ::rtl::OUString& _sModuleName, const rtl::OString& sHelpId)
1255 : : {
1256 : 0 : ::com::sun::star::util::URL aURL;
1257 [ # # ]: 0 : aURL.Complete = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.help://" ) );
1258 : 0 : aURL.Complete += _sModuleName;
1259 [ # # ]: 0 : aURL.Complete += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/" ) );
1260 [ # # ]: 0 : aURL.Complete += ::rtl::OStringToOUString(sHelpId, RTL_TEXTENCODING_UTF8);
1261 : :
1262 : 0 : ::rtl::OUString sAnchor;
1263 : 0 : ::rtl::OUString sTempURL = aURL.Complete;
1264 [ # # ]: 0 : AppendConfigToken( sTempURL, sal_True );
1265 [ # # ]: 0 : sal_Bool bHasAnchor = GetHelpAnchor_Impl( sTempURL, sAnchor );
1266 [ # # ]: 0 : AppendConfigToken(aURL.Complete,sal_True);
1267 [ # # ]: 0 : if ( bHasAnchor )
1268 : : {
1269 [ # # ]: 0 : aURL.Complete += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#"));
1270 : 0 : aURL.Complete += sAnchor;
1271 : : }
1272 : 0 : return aURL;
1273 : : }
1274 : : // -----------------------------------------------------------------------------
1275 : 0 : void setEvalDateFormatForFormatter(Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter)
1276 : : {
1277 : : OSL_ENSURE( _rxFormatter.is(),"setEvalDateFormatForFormatter: Formatter is NULL!");
1278 [ # # ]: 0 : if ( _rxFormatter.is() )
1279 : : {
1280 [ # # ][ # # ]: 0 : Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier = _rxFormatter->getNumberFormatsSupplier();
1281 : :
1282 [ # # ]: 0 : Reference< XUnoTunnel > xTunnel(xSupplier,UNO_QUERY);
1283 [ # # ][ # # ]: 0 : SvNumberFormatsSupplierObj* pSupplierImpl = reinterpret_cast<SvNumberFormatsSupplierObj*>(xTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
[ # # ]
1284 : : OSL_ENSURE(pSupplierImpl,"No Supplier!");
1285 : :
1286 [ # # ]: 0 : if ( pSupplierImpl )
1287 : : {
1288 [ # # ]: 0 : SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
1289 : 0 : pFormatter->SetEvalDateFormat(NF_EVALDATEFORMAT_FORMAT);
1290 : 0 : }
1291 : : }
1292 : 0 : }
1293 : : // -----------------------------------------------------------------------------
1294 : 0 : TOTypeInfoSP queryPrimaryKeyType(const OTypeInfoMap& _rTypeInfo)
1295 : : {
1296 [ # # ]: 0 : TOTypeInfoSP pTypeInfo;
1297 : : // first we search for a type which supports autoIncrement
1298 : 0 : OTypeInfoMap::const_iterator aIter = _rTypeInfo.begin();
1299 : 0 : OTypeInfoMap::const_iterator aEnd = _rTypeInfo.end();
1300 [ # # ]: 0 : for(;aIter != aEnd;++aIter)
1301 : : {
1302 : : // OJ: we don't want to set an autoincrement column to be key
1303 : : // because we don't have the possiblity to know how to create
1304 : : // such auto increment column later on
1305 : : // so until we know how to do it, we create a column without autoincrement
1306 : : // if ( !aIter->second->bAutoIncrement )
1307 : : { // therefor we have searched
1308 [ # # ]: 0 : if ( aIter->second->nType == DataType::INTEGER )
1309 : : {
1310 [ # # ]: 0 : pTypeInfo = aIter->second; // alternative
1311 : 0 : break;
1312 : : }
1313 [ # # ][ # # ]: 0 : else if ( !pTypeInfo.get() && aIter->second->nType == DataType::DOUBLE )
[ # # ]
1314 [ # # ]: 0 : pTypeInfo = aIter->second; // alternative
1315 [ # # ][ # # ]: 0 : else if ( !pTypeInfo.get() && aIter->second->nType == DataType::REAL )
[ # # ]
1316 [ # # ]: 0 : pTypeInfo = aIter->second; // alternative
1317 : : }
1318 : : }
1319 [ # # ]: 0 : if ( !pTypeInfo.get() ) // just a fallback
1320 [ # # ][ # # ]: 0 : pTypeInfo = queryTypeInfoByType(DataType::VARCHAR,_rTypeInfo);
[ # # ]
1321 : :
1322 : : OSL_ENSURE(pTypeInfo.get(),"checkColumns: cann't find a type which is useable as a key!");
1323 : 0 : return pTypeInfo;
1324 : : }
1325 : : // -----------------------------------------------------------------------------
1326 : 0 : TOTypeInfoSP queryTypeInfoByType(sal_Int32 _nDataType,const OTypeInfoMap& _rTypeInfo)
1327 : : {
1328 [ # # ]: 0 : OTypeInfoMap::const_iterator aIter = _rTypeInfo.find(_nDataType);
1329 [ # # ]: 0 : if(aIter != _rTypeInfo.end())
1330 [ # # ]: 0 : return aIter->second;
1331 : : // fall back if the type is unknown
1332 [ # # ]: 0 : TOTypeInfoSP pTypeInfo;
1333 [ # # # # : 0 : switch(_nDataType)
# # # # #
# # # ]
1334 : : {
1335 : : case DataType::TINYINT:
1336 [ # # ][ # # ]: 0 : if( (pTypeInfo = queryTypeInfoByType(DataType::SMALLINT,_rTypeInfo) ) )
[ # # ][ # # ]
1337 : 0 : break;
1338 : : // run through
1339 : : case DataType::SMALLINT:
1340 [ # # ][ # # ]: 0 : if( (pTypeInfo = queryTypeInfoByType(DataType::INTEGER,_rTypeInfo) ) )
[ # # ][ # # ]
1341 : 0 : break;
1342 : : // run through
1343 : : case DataType::INTEGER:
1344 [ # # ][ # # ]: 0 : if( (pTypeInfo = queryTypeInfoByType(DataType::FLOAT,_rTypeInfo) ) )
[ # # ][ # # ]
1345 : 0 : break;
1346 : : // run through
1347 : : case DataType::FLOAT:
1348 [ # # ][ # # ]: 0 : if( (pTypeInfo = queryTypeInfoByType(DataType::REAL,_rTypeInfo) ) )
[ # # ][ # # ]
1349 : 0 : break;
1350 : : // run through
1351 : : case DataType::DATE:
1352 : : case DataType::TIME:
1353 [ # # ][ # # ]: 0 : if( DataType::DATE == _nDataType || DataType::TIME == _nDataType )
1354 : : {
1355 [ # # ][ # # ]: 0 : if( (pTypeInfo = queryTypeInfoByType(DataType::TIMESTAMP,_rTypeInfo) ) )
[ # # ][ # # ]
1356 : 0 : break;
1357 : : }
1358 : : // run through
1359 : : case DataType::TIMESTAMP:
1360 : : case DataType::REAL:
1361 : : case DataType::BIGINT:
1362 [ # # ][ # # ]: 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo) ) )
[ # # ][ # # ]
1363 : 0 : break;
1364 : : // run through
1365 : : case DataType::DOUBLE:
1366 [ # # ][ # # ]: 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo) ) )
[ # # ][ # # ]
1367 : 0 : break;
1368 : : // run through
1369 : : case DataType::NUMERIC:
1370 [ # # ][ # # ]: 0 : pTypeInfo = queryTypeInfoByType(DataType::DECIMAL,_rTypeInfo);
[ # # ]
1371 : 0 : break;
1372 : : case DataType::DECIMAL:
1373 [ # # ][ # # ]: 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::NUMERIC,_rTypeInfo) ) )
[ # # ][ # # ]
1374 : 0 : break;
1375 [ # # ][ # # ]: 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::DOUBLE,_rTypeInfo) ) )
[ # # ][ # # ]
1376 : 0 : break;
1377 : 0 : break;
1378 : : case DataType::VARCHAR:
1379 [ # # ][ # # ]: 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::LONGVARCHAR,_rTypeInfo) ) )
[ # # ][ # # ]
1380 : 0 : break;
1381 : 0 : break;
1382 : : case DataType::LONGVARCHAR:
1383 [ # # ][ # # ]: 0 : if ( (pTypeInfo = queryTypeInfoByType(DataType::CLOB,_rTypeInfo) ) )
[ # # ][ # # ]
1384 : 0 : break;
1385 : 0 : break;
1386 : : default:
1387 : : ;
1388 : : }
1389 [ # # ]: 0 : if ( !pTypeInfo )
1390 : : {
1391 [ # # ]: 0 : ::rtl::OUString sCreate(RTL_CONSTASCII_USTRINGPARAM("x")),sTypeName;
1392 : 0 : sal_Bool bForce = sal_True;
1393 [ # # ][ # # ]: 0 : pTypeInfo = ::dbaui::getTypeInfoFromType(_rTypeInfo,DataType::VARCHAR,sTypeName,sCreate,50,0,sal_False,bForce);
[ # # ]
1394 : : }
1395 : : OSL_ENSURE(pTypeInfo,"Wrong DataType supplied!");
1396 [ # # ][ # # ]: 0 : return pTypeInfo;
1397 : : }
1398 : : // -----------------------------------------------------------------------------
1399 : 0 : sal_Int32 askForUserAction(Window* _pParent,sal_uInt16 _nTitle,sal_uInt16 _nText,sal_Bool _bAll,const ::rtl::OUString& _sName)
1400 : : {
1401 [ # # ]: 0 : SolarMutexGuard aGuard;
1402 [ # # ][ # # ]: 0 : String aMsg = String(ModuleRes(_nText));
1403 [ # # ][ # # ]: 0 : aMsg.SearchAndReplace(rtl::OUString("%1"),String(_sName));
[ # # ][ # # ]
[ # # ]
1404 [ # # ][ # # ]: 0 : OSQLMessageBox aAsk(_pParent,String(ModuleRes(_nTitle )),aMsg,WB_YES_NO | WB_DEF_YES,OSQLMessageBox::Query);
[ # # ][ # # ]
1405 [ # # ]: 0 : if ( _bAll )
1406 : : {
1407 [ # # ][ # # ]: 0 : aAsk.AddButton(String(ModuleRes(STR_BUTTON_TEXT_ALL)), RET_ALL, 0);
[ # # ][ # # ]
1408 [ # # ][ # # ]: 0 : aAsk.GetPushButton(RET_ALL)->SetHelpId(HID_CONFIRM_DROP_BUTTON_ALL);
1409 : : }
1410 [ # # ][ # # ]: 0 : return aAsk.Execute();
[ # # ][ # # ]
1411 : : }
1412 : :
1413 : : // -----------------------------------------------------------------------------
1414 : : namespace
1415 : : {
1416 : 0 : static ::rtl::OUString lcl_createSDBCLevelStatement( const ::rtl::OUString& _rStatement, const Reference< XConnection >& _rxConnection )
1417 : : {
1418 : 0 : ::rtl::OUString sSDBCLevelStatement( _rStatement );
1419 : : try
1420 : : {
1421 [ # # ]: 0 : Reference< XMultiServiceFactory > xAnalyzerFactory( _rxConnection, UNO_QUERY_THROW );
1422 [ # # ][ # # ]: 0 : Reference< XSingleSelectQueryAnalyzer > xAnalyzer( xAnalyzerFactory->createInstance( SERVICE_NAME_SINGLESELECTQUERYCOMPOSER ), UNO_QUERY_THROW );
[ # # ][ # # ]
1423 [ # # ][ # # ]: 0 : xAnalyzer->setQuery( _rStatement );
1424 [ # # ][ # # ]: 0 : sSDBCLevelStatement = xAnalyzer->getQueryWithSubstitution();
[ # # ]
1425 : : }
1426 [ # # ]: 0 : catch( const Exception& )
1427 : : {
1428 : : DBG_UNHANDLED_EXCEPTION();
1429 : : }
1430 : 0 : return sSDBCLevelStatement;
1431 : : }
1432 : : }
1433 : :
1434 : : // -----------------------------------------------------------------------------
1435 : 0 : Reference< XPropertySet > createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection,
1436 : : const ::rtl::OUString& _rCommand )
1437 : : {
1438 [ # # ]: 0 : Reference<XViewsSupplier> xSup(_rxConnection,UNO_QUERY);
1439 : 0 : Reference< XNameAccess > xViews;
1440 [ # # ]: 0 : if(xSup.is())
1441 [ # # ][ # # ]: 0 : xViews = xSup->getViews();
[ # # ]
1442 [ # # ]: 0 : Reference<XDataDescriptorFactory> xFact(xViews,UNO_QUERY);
1443 : : OSL_ENSURE(xFact.is(),"No XDataDescriptorFactory available!");
1444 [ # # ]: 0 : if(!xFact.is())
1445 [ # # ]: 0 : return NULL;
1446 : :
1447 [ # # ][ # # ]: 0 : Reference<XPropertySet> xView = xFact->createDataDescriptor();
1448 [ # # ]: 0 : if ( !xView.is() )
1449 [ # # ]: 0 : return NULL;
1450 : :
1451 : 0 : ::rtl::OUString sCatalog,sSchema,sTable;
1452 [ # # ]: 0 : ::dbtools::qualifiedNameComponents(_rxConnection->getMetaData(),
1453 : : _rName,
1454 : : sCatalog,
1455 : : sSchema,
1456 : : sTable,
1457 [ # # ][ # # ]: 0 : ::dbtools::eInDataManipulation);
1458 : :
1459 [ # # ][ # # ]: 0 : xView->setPropertyValue(PROPERTY_CATALOGNAME,makeAny(sCatalog));
[ # # ][ # # ]
1460 [ # # ][ # # ]: 0 : xView->setPropertyValue(PROPERTY_SCHEMANAME,makeAny(sSchema));
[ # # ][ # # ]
1461 [ # # ][ # # ]: 0 : xView->setPropertyValue(PROPERTY_NAME,makeAny(sTable));
[ # # ][ # # ]
1462 : :
1463 [ # # ][ # # ]: 0 : xView->setPropertyValue( PROPERTY_COMMAND, makeAny( _rCommand ) );
[ # # ][ # # ]
1464 : :
1465 [ # # ]: 0 : Reference<XAppend> xAppend(xViews,UNO_QUERY);
1466 [ # # ]: 0 : if(xAppend.is())
1467 [ # # ][ # # ]: 0 : xAppend->appendByDescriptor(xView);
1468 : :
1469 [ # # ]: 0 : xView = NULL;
1470 : : // we need to reget the view because after appending it it is no longer valid
1471 : : // but this time it isn't a view object it is a table object with type "VIEW"
1472 [ # # ]: 0 : Reference<XTablesSupplier> xTabSup(_rxConnection,UNO_QUERY);
1473 : 0 : Reference< XNameAccess > xTables;
1474 [ # # ]: 0 : if ( xTabSup.is() )
1475 : : {
1476 [ # # ][ # # ]: 0 : xTables = xTabSup->getTables();
[ # # ]
1477 [ # # ][ # # ]: 0 : if ( xTables.is() && xTables->hasByName( _rName ) )
[ # # ][ # # ]
[ # # ]
1478 [ # # ][ # # ]: 0 : xTables->getByName( _rName ) >>= xView;
[ # # ]
1479 : : }
1480 : :
1481 : 0 : return xView;
1482 : : }
1483 : :
1484 : : // -----------------------------------------------------------------------------
1485 : 0 : Reference<XPropertySet> createView( const ::rtl::OUString& _rName, const Reference< XConnection >& _rxConnection
1486 : : ,const Reference<XPropertySet>& _rxSourceObject)
1487 : : {
1488 : 0 : ::rtl::OUString sCommand;
1489 [ # # ][ # # ]: 0 : Reference< XPropertySetInfo > xPSI( _rxSourceObject->getPropertySetInfo(), UNO_SET_THROW );
[ # # ]
1490 [ # # ][ # # ]: 0 : if ( xPSI->hasPropertyByName( PROPERTY_COMMAND ) )
[ # # ][ # # ]
1491 : : {
1492 [ # # ][ # # ]: 0 : _rxSourceObject->getPropertyValue( PROPERTY_COMMAND ) >>= sCommand;
[ # # ]
1493 : :
1494 : 0 : sal_Bool bEscapeProcessing( sal_False );
1495 [ # # ][ # # ]: 0 : OSL_VERIFY( _rxSourceObject->getPropertyValue( PROPERTY_ESCAPE_PROCESSING ) >>= bEscapeProcessing );
[ # # ]
1496 [ # # ]: 0 : if ( bEscapeProcessing )
1497 [ # # ]: 0 : sCommand = lcl_createSDBCLevelStatement( sCommand, _rxConnection );
1498 : : }
1499 : : else
1500 : : {
1501 [ # # ]: 0 : sCommand = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SELECT * FROM " ) );
1502 [ # # ]: 0 : sCommand += composeTableNameForSelect( _rxConnection, _rxSourceObject );
1503 : : }
1504 [ # # ]: 0 : return createView( _rName, _rxConnection, sCommand );
1505 : : }
1506 : :
1507 : : // -----------------------------------------------------------------------------
1508 : 0 : sal_Bool insertHierachyElement( Window* _pParent, const Reference< XMultiServiceFactory >& _rxORB,
1509 : : const Reference<XHierarchicalNameContainer>& _xNames,
1510 : : const String& _sParentFolder,
1511 : : sal_Bool _bForm,
1512 : : sal_Bool _bCollection,
1513 : : const Reference<XContent>& _xContent,
1514 : : sal_Bool _bMove)
1515 : : {
1516 : : OSL_ENSURE( _xNames.is(), "insertHierachyElement: illegal name container!" );
1517 [ # # ]: 0 : if ( !_xNames.is() )
1518 : 0 : return sal_False;
1519 : :
1520 [ # # ]: 0 : Reference<XNameAccess> xNameAccess( _xNames, UNO_QUERY );
1521 [ # # ]: 0 : ::rtl::OUString sName = _sParentFolder;
1522 [ # # ][ # # ]: 0 : if ( _xNames->hasByHierarchicalName(sName) )
[ # # ]
1523 : : {
1524 [ # # ][ # # ]: 0 : Reference<XChild> xChild(_xNames->getByHierarchicalName(sName),UNO_QUERY);
[ # # ]
1525 [ # # ]: 0 : xNameAccess.set(xChild,UNO_QUERY);
1526 [ # # ][ # # ]: 0 : if ( !xNameAccess.is() && xChild.is() )
[ # # ]
1527 [ # # ][ # # ]: 0 : xNameAccess.set(xChild->getParent(),UNO_QUERY);
[ # # ]
1528 : : }
1529 : :
1530 : : OSL_ENSURE( xNameAccess.is(), "insertHierachyElement: could not find the proper name container!" );
1531 [ # # ]: 0 : if ( !xNameAccess.is() )
1532 : 0 : return sal_False;
1533 : :
1534 : 0 : ::rtl::OUString sNewName;
1535 [ # # ]: 0 : Reference<XPropertySet> xProp(_xContent,UNO_QUERY);
1536 [ # # ]: 0 : if ( xProp.is() )
1537 [ # # ][ # # ]: 0 : xProp->getPropertyValue(PROPERTY_NAME) >>= sNewName;
[ # # ]
1538 : :
1539 [ # # ][ # # ]: 0 : if ( !_bMove || sNewName.isEmpty() )
[ # # ]
1540 : : {
1541 [ # # ][ # # ]: 0 : String sTargetName,sLabel;
1542 [ # # ][ # # ]: 0 : if ( sNewName.isEmpty() || xNameAccess->hasByName(sNewName) )
[ # # ][ # # ]
[ # # ]
1543 : : {
1544 [ # # ]: 0 : if ( !sNewName.isEmpty() )
1545 [ # # ]: 0 : sTargetName = sNewName;
1546 : : else
1547 [ # # ][ # # ]: 0 : sTargetName = String(ModuleRes( _bCollection ? STR_NEW_FOLDER : ((_bForm) ? RID_STR_FORM : RID_STR_REPORT)));
[ # # ][ # # ]
[ # # ][ # # ]
1548 [ # # ][ # # ]: 0 : sLabel = String(ModuleRes( _bCollection ? STR_FOLDER_LABEL : ((_bForm) ? STR_FRM_LABEL : STR_RPT_LABEL)));
[ # # ][ # # ]
[ # # ][ # # ]
1549 [ # # ][ # # ]: 0 : sTargetName = ::dbtools::createUniqueName(xNameAccess,sTargetName);
[ # # ]
1550 : :
1551 : :
1552 : : // here we have everything needed to create a new query object ...
1553 [ # # ][ # # ]: 0 : HierarchicalNameCheck aNameChecker( _xNames.get(), sName );
[ # # ]
1554 : : // ... ehm, except a new name
1555 : : OSaveAsDlg aAskForName( _pParent,
1556 : : _rxORB,
1557 : : sTargetName,
1558 : : sLabel,
1559 : : aNameChecker,
1560 [ # # ]: 0 : SAD_ADDITIONAL_DESCRIPTION | SAD_TITLE_PASTE_AS);
1561 [ # # ][ # # ]: 0 : if ( RET_OK != aAskForName.Execute() )
1562 : : // cancelled by the user
1563 : 0 : return sal_False;
1564 : :
1565 [ # # ][ # # ]: 0 : sNewName = aAskForName.getName();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1566 [ # # ][ # # ]: 0 : }
[ # # ][ # # ]
1567 : : }
1568 [ # # ][ # # ]: 0 : else if ( xNameAccess->hasByName(sNewName) )
[ # # ]
1569 : : {
1570 [ # # ][ # # ]: 0 : String sError(ModuleRes(STR_NAME_ALREADY_EXISTS));
1571 [ # # ][ # # ]: 0 : sError.SearchAndReplaceAscii("#",sNewName);
[ # # ]
1572 [ # # ][ # # ]: 0 : throw SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
[ # # ][ # # ]
1573 : : }
1574 : :
1575 : : try
1576 : : {
1577 [ # # ]: 0 : Reference<XMultiServiceFactory> xORB( xNameAccess, UNO_QUERY_THROW );
1578 [ # # ]: 0 : Sequence< Any > aArguments(3);
1579 : 0 : PropertyValue aValue;
1580 : : // set as folder
1581 [ # # ]: 0 : aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"));
1582 [ # # ]: 0 : aValue.Value <<= sNewName;
1583 [ # # ][ # # ]: 0 : aArguments[0] <<= aValue;
1584 : : //parent
1585 [ # # ]: 0 : aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Parent"));
1586 [ # # ]: 0 : aValue.Value <<= xNameAccess;
1587 [ # # ][ # # ]: 0 : aArguments[1] <<= aValue;
1588 : :
1589 [ # # ]: 0 : aValue.Name = PROPERTY_EMBEDDEDOBJECT;
1590 [ # # ]: 0 : aValue.Value <<= _xContent;
1591 [ # # ][ # # ]: 0 : aArguments[2] <<= aValue;
1592 : :
1593 [ # # ][ # # ]: 0 : ::rtl::OUString sServiceName(_bCollection ? ((_bForm) ? SERVICE_NAME_FORM_COLLECTION : SERVICE_NAME_REPORT_COLLECTION) : SERVICE_SDB_DOCUMENTDEFINITION);
[ # # ]
1594 : :
1595 [ # # ][ # # ]: 0 : Reference<XContent > xNew( xORB->createInstanceWithArguments( sServiceName, aArguments ), UNO_QUERY_THROW );
[ # # ]
1596 [ # # ]: 0 : Reference< XNameContainer > xNameContainer( xNameAccess, UNO_QUERY_THROW );
1597 [ # # ][ # # ]: 0 : xNameContainer->insertByName( sNewName, makeAny( xNew ) );
[ # # ][ # # ]
1598 : : }
1599 [ # # # # : 0 : catch( const IllegalArgumentException& e )
# ]
1600 : : {
1601 [ # # ]: 0 : ::dbtools::throwGenericSQLException( e.Message, e.Context );
1602 : : }
1603 [ # # ]: 0 : catch( const Exception& )
1604 : : {
1605 : : DBG_UNHANDLED_EXCEPTION();
1606 : 0 : return sal_False;
1607 : : }
1608 : :
1609 : 0 : return sal_True;
1610 : : }
1611 : : // -----------------------------------------------------------------------------
1612 : 0 : Reference< XNumberFormatter > getNumberFormatter(const Reference< XConnection >& _rxConnection,const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rMF )
1613 : : {
1614 : : // ---------------------------------------------------------------
1615 : : // create a formatter working with the connections format supplier
1616 : 0 : Reference< XNumberFormatter > xFormatter;
1617 : :
1618 : : try
1619 : : {
1620 [ # # ]: 0 : Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(::dbtools::getNumberFormats(_rxConnection, sal_True,_rMF));
1621 : :
1622 [ # # ]: 0 : if ( xSupplier.is() )
1623 : : {
1624 : : // create a new formatter
1625 : : xFormatter = Reference< ::com::sun::star::util::XNumberFormatter > (
1626 [ # # ][ # # ]: 0 : _rMF->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter"))), UNO_QUERY);
[ # # ][ # # ]
[ # # ]
1627 [ # # ]: 0 : if ( xFormatter.is() )
1628 [ # # ][ # # ]: 0 : xFormatter->attachNumberFormatsSupplier(xSupplier);
1629 [ # # ]: 0 : }
1630 : : }
1631 [ # # ]: 0 : catch(const Exception&)
1632 : : {
1633 : : DBG_UNHANDLED_EXCEPTION();
1634 : : }
1635 : 0 : return xFormatter;
1636 : : }
1637 : :
1638 : :
1639 : : // .........................................................................
1640 : : } // dbaui
1641 : : // .........................................................................
1642 : :
1643 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|