LCOV - code coverage report
Current view: top level - dbaccess/source/ui/misc - UITools.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 19 732 2.6 %
Date: 2014-11-03 Functions: 5 39 12.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10