LCOV - code coverage report
Current view: top level - libreoffice/connectivity/source/commontools - dbtools2.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 22 484 4.5 %
Date: 2012-12-17 Functions: 2 23 8.7 %
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 "connectivity/dbtools.hxx"
      21             : #include "connectivity/dbconversion.hxx"
      22             : #include "connectivity/dbcharset.hxx"
      23             : #include "connectivity/SQLStatementHelper.hxx"
      24             : #include <unotools/confignode.hxx>
      25             : #include "resource/sharedresources.hxx"
      26             : #include "resource/common_res.hrc"
      27             : #include <com/sun/star/sdbc/XConnection.hpp>
      28             : #include <com/sun/star/sdbc/ColumnValue.hpp>
      29             : #include <com/sun/star/sdbc/DataType.hpp>
      30             : #include <com/sun/star/sdbc/DriverManager.hpp>
      31             : #include <com/sun/star/sdbc/XRow.hpp>
      32             : #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
      33             : #include <com/sun/star/sdbcx/XKeysSupplier.hpp>
      34             : #include <com/sun/star/sdbc/XDriverAccess.hpp>
      35             : #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
      36             : #include <com/sun/star/sdbcx/Privilege.hpp>
      37             : #include <com/sun/star/container/XIndexAccess.hpp>
      38             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      39             : #include <com/sun/star/sdbc/KeyRule.hpp>
      40             : #include <com/sun/star/sdbcx/KeyType.hpp>
      41             : #include "TConnection.hxx"
      42             : #include "connectivity/sdbcx/VColumn.hxx"
      43             : #include <com/sun/star/frame/XModel.hpp>
      44             : #include <com/sun/star/container/XChild.hpp>
      45             : 
      46             : #include <tools/diagnose_ex.h>
      47             : #include <unotools/sharedunocomponent.hxx>
      48             : 
      49             : //.........................................................................
      50             : namespace dbtools
      51             : {
      52             : //.........................................................................
      53             :     using namespace ::com::sun::star::uno;
      54             :     using namespace ::com::sun::star::beans;
      55             :     using namespace ::com::sun::star::sdbc;
      56             :     using namespace ::com::sun::star::sdbcx;
      57             :     using namespace ::com::sun::star::lang;
      58             :     using namespace ::com::sun::star::container;
      59             :     using namespace ::com::sun::star::frame;
      60             :     using namespace connectivity;
      61             :     using namespace comphelper;
      62             : 
      63           0 : ::rtl::OUString createStandardColumnPart(const Reference< XPropertySet >& xColProp,const Reference< XConnection>& _xConnection,ISQLStatementHelper* _pHelper,const ::rtl::OUString& _sCreatePattern)
      64             : {
      65             : 
      66           0 :     Reference<XDatabaseMetaData> xMetaData = _xConnection->getMetaData();
      67             : 
      68           0 :     ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
      69             : 
      70           0 :     ::rtl::OUString sTypeName;
      71           0 :     sal_Int32       nDataType   = 0;
      72           0 :     sal_Int32       nPrecision  = 0;
      73           0 :     sal_Int32       nScale      = 0;
      74             : 
      75           0 :     const ::rtl::OUString sQuoteString = xMetaData->getIdentifierQuoteString();
      76           0 :     ::rtl::OUStringBuffer aSql = ::dbtools::quoteName(sQuoteString,::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))));
      77             : 
      78           0 :     aSql.appendAscii(" ");
      79             : 
      80           0 :     nDataType = nPrecision = nScale = 0;
      81           0 :     sal_Bool bIsAutoIncrement = sal_False;
      82           0 :     xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_TYPENAME))           >>= sTypeName;
      83           0 :     xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_TYPE))               >>= nDataType;
      84           0 :     xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_PRECISION))          >>= nPrecision;
      85           0 :     xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCALE))              >>= nScale;
      86           0 :     xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISAUTOINCREMENT))    >>= bIsAutoIncrement;
      87             : 
      88             :     // check if the user enter a specific string to create autoincrement values
      89           0 :     ::rtl::OUString sAutoIncrementValue;
      90           0 :     Reference<XPropertySetInfo> xPropInfo = xColProp->getPropertySetInfo();
      91           0 :     if ( xPropInfo.is() && xPropInfo->hasPropertyByName(rPropMap.getNameByIndex(PROPERTY_ID_AUTOINCREMENTCREATION)) )
      92           0 :         xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_AUTOINCREMENTCREATION)) >>= sAutoIncrementValue;
      93             :     // look if we have to use precisions
      94           0 :     sal_Bool bUseLiteral = sal_False;
      95           0 :     ::rtl::OUString sPreFix,sPostFix,sCreateParams;
      96             :     {
      97           0 :         Reference<XResultSet> xRes = xMetaData->getTypeInfo();
      98           0 :         if(xRes.is())
      99             :         {
     100           0 :             Reference<XRow> xRow(xRes,UNO_QUERY);
     101           0 :             while(xRes->next())
     102             :             {
     103           0 :                 ::rtl::OUString sTypeName2Cmp = xRow->getString(1);
     104           0 :                 sal_Int32 nType = xRow->getShort(2);
     105           0 :                 sPreFix = xRow->getString (4);
     106           0 :                 sPostFix = xRow->getString (5);
     107           0 :                 sCreateParams = xRow->getString(6);
     108             :                 // first identical type will be used if typename is empty
     109           0 :                 if ( sTypeName.isEmpty() && nType == nDataType )
     110           0 :                     sTypeName = sTypeName2Cmp;
     111             : 
     112           0 :                 if( sTypeName.equalsIgnoreAsciiCase(sTypeName2Cmp) && nType == nDataType && !sCreateParams.isEmpty() && !xRow->wasNull())
     113             :                 {
     114           0 :                     bUseLiteral = sal_True;
     115             :                     break;
     116             :                 }
     117           0 :             }
     118           0 :         }
     119             :     }
     120             : 
     121           0 :     sal_Int32 nIndex = 0;
     122           0 :     if ( !sAutoIncrementValue.isEmpty() && (nIndex = sTypeName.indexOf(sAutoIncrementValue)) != -1 )
     123             :     {
     124           0 :         sTypeName = sTypeName.replaceAt(nIndex,sTypeName.getLength() - nIndex,::rtl::OUString());
     125             :     }
     126             : 
     127           0 :     if ( (nPrecision > 0 || nScale > 0) && bUseLiteral )
     128             :     {
     129           0 :         sal_Int32 nParenPos = sTypeName.indexOf('(');
     130           0 :         if ( nParenPos == -1 )
     131             :         {
     132           0 :             aSql.append(sTypeName);
     133           0 :             aSql.appendAscii("(");
     134             :         }
     135             :         else
     136             :         {
     137           0 :             aSql.append(sTypeName.copy(0,++nParenPos));
     138             :         }
     139             : 
     140           0 :         if ( nPrecision > 0 && nDataType != DataType::TIMESTAMP )
     141             :         {
     142           0 :             aSql.append(nPrecision);
     143           0 :             if ( (nScale > 0) || (!_sCreatePattern.isEmpty() && sCreateParams.indexOf(_sCreatePattern) != -1) )
     144           0 :                 aSql.appendAscii(",");
     145             :         }
     146           0 :         if ( (nScale > 0) || ( !_sCreatePattern.isEmpty() && sCreateParams.indexOf(_sCreatePattern) != -1 ) || nDataType == DataType::TIMESTAMP )
     147           0 :             aSql.append(nScale);
     148             : 
     149           0 :         if ( nParenPos == -1 )
     150           0 :             aSql.appendAscii(")");
     151             :         else
     152             :         {
     153           0 :             nParenPos = sTypeName.indexOf(')',nParenPos);
     154           0 :             aSql.append(sTypeName.copy(nParenPos));
     155           0 :         }
     156             :     }
     157             :     else
     158           0 :         aSql.append(sTypeName); // simply add the type name
     159             : 
     160           0 :     ::rtl::OUString aDefault = ::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_DEFAULTVALUE)));
     161           0 :     if ( !aDefault.isEmpty() )
     162             :     {
     163           0 :         aSql.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" DEFAULT ")));
     164           0 :         aSql.append(sPreFix);
     165           0 :         aSql.append(aDefault);
     166           0 :         aSql.append(sPostFix);
     167             :     } // if ( aDefault.getLength() )
     168             : 
     169           0 :     if(::comphelper::getINT32(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_ISNULLABLE))) == ColumnValue::NO_NULLS)
     170           0 :         aSql.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" NOT NULL")));
     171             : 
     172           0 :     if ( bIsAutoIncrement && !sAutoIncrementValue.isEmpty())
     173             :     {
     174           0 :         aSql.appendAscii(" ");
     175           0 :         aSql.append(sAutoIncrementValue);
     176             :     }
     177             : 
     178           0 :     if ( _pHelper )
     179           0 :         _pHelper->addComment(xColProp,aSql);
     180             : 
     181           0 :     return aSql.makeStringAndClear();
     182             : }
     183             : // -----------------------------------------------------------------------------
     184             : 
     185           0 : ::rtl::OUString createStandardCreateStatement(const Reference< XPropertySet >& descriptor,const Reference< XConnection>& _xConnection,ISQLStatementHelper* _pHelper,const ::rtl::OUString& _sCreatePattern)
     186             : {
     187           0 :     ::rtl::OUStringBuffer aSql(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CREATE TABLE ")));
     188           0 :     ::rtl::OUString sCatalog,sSchema,sTable,sComposedName;
     189             : 
     190           0 :     Reference<XDatabaseMetaData> xMetaData = _xConnection->getMetaData();
     191           0 :     ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
     192             : 
     193           0 :     descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME))  >>= sCatalog;
     194           0 :     descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME))   >>= sSchema;
     195           0 :     descriptor->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))         >>= sTable;
     196             : 
     197           0 :     sComposedName = ::dbtools::composeTableName( xMetaData, sCatalog, sSchema, sTable, sal_True, ::dbtools::eInTableDefinitions );
     198           0 :     if ( sComposedName.isEmpty() )
     199           0 :         ::dbtools::throwFunctionSequenceException(_xConnection);
     200             : 
     201           0 :     aSql.append(sComposedName);
     202           0 :     aSql.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" (")));
     203             : 
     204             :     // columns
     205           0 :     Reference<XColumnsSupplier> xColumnSup(descriptor,UNO_QUERY);
     206           0 :     Reference<XIndexAccess> xColumns(xColumnSup->getColumns(),UNO_QUERY);
     207             :     // check if there are columns
     208           0 :     if(!xColumns.is() || !xColumns->getCount())
     209           0 :         ::dbtools::throwFunctionSequenceException(_xConnection);
     210             : 
     211           0 :     Reference< XPropertySet > xColProp;
     212             : 
     213           0 :     sal_Int32 nCount = xColumns->getCount();
     214           0 :     for(sal_Int32 i=0;i<nCount;++i)
     215             :     {
     216           0 :         if ( (xColumns->getByIndex(i) >>= xColProp) && xColProp.is() )
     217             :         {
     218           0 :             aSql.append(createStandardColumnPart(xColProp,_xConnection,_pHelper,_sCreatePattern));
     219           0 :             aSql.appendAscii(",");
     220             :         }
     221             :     }
     222           0 :     return aSql.makeStringAndClear();
     223             : }
     224             : namespace
     225             : {
     226           0 :     ::rtl::OUString generateColumnNames(const Reference<XIndexAccess>& _xColumns,const Reference<XDatabaseMetaData>& _xMetaData)
     227             :     {
     228           0 :         ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
     229           0 :         static const ::rtl::OUString sComma(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(",")));
     230             : 
     231           0 :         const ::rtl::OUString sQuote(_xMetaData->getIdentifierQuoteString());
     232           0 :         ::rtl::OUString sSql( RTL_CONSTASCII_USTRINGPARAM( " (" ));
     233           0 :         Reference< XPropertySet > xColProp;
     234             : 
     235           0 :         sal_Int32 nColCount  = _xColumns->getCount();
     236           0 :         for(sal_Int32 i=0;i<nColCount;++i)
     237             :         {
     238           0 :             if ( (_xColumns->getByIndex(i) >>= xColProp) && xColProp.is() )
     239           0 :                 sSql += ::dbtools::quoteName(sQuote,::comphelper::getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))))
     240           0 :                         + sComma;
     241             :         }
     242             : 
     243           0 :         if ( nColCount )
     244           0 :             sSql = sSql.replaceAt(sSql.getLength()-1,1,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")")));
     245           0 :         return sSql;
     246             :     }
     247             : }
     248             : // -----------------------------------------------------------------------------
     249           0 : ::rtl::OUString createStandardKeyStatement(const Reference< XPropertySet >& descriptor,const Reference< XConnection>& _xConnection)
     250             : {
     251           0 :     Reference<XDatabaseMetaData> xMetaData = _xConnection->getMetaData();
     252           0 :     ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
     253             : 
     254           0 :     ::rtl::OUStringBuffer aSql;
     255             :     // keys
     256           0 :     Reference<XKeysSupplier> xKeySup(descriptor,UNO_QUERY);
     257           0 :     Reference<XIndexAccess> xKeys = xKeySup->getKeys();
     258           0 :     if ( xKeys.is() )
     259             :     {
     260           0 :         Reference< XPropertySet > xColProp;
     261           0 :         Reference<XIndexAccess> xColumns;
     262           0 :         Reference<XColumnsSupplier> xColumnSup;
     263           0 :         ::rtl::OUString sCatalog,sSchema,sTable,sComposedName;
     264           0 :         sal_Bool bPKey = sal_False;
     265           0 :         for(sal_Int32 i=0;i<xKeys->getCount();++i)
     266             :         {
     267           0 :             if ( (xKeys->getByIndex(i) >>= xColProp) && xColProp.is() )
     268             :             {
     269             : 
     270           0 :                 sal_Int32 nKeyType      = ::comphelper::getINT32(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_TYPE)));
     271             : 
     272           0 :                 if ( nKeyType == KeyType::PRIMARY )
     273             :                 {
     274           0 :                     if(bPKey)
     275           0 :                         ::dbtools::throwFunctionSequenceException(_xConnection);
     276             : 
     277           0 :                     bPKey = sal_True;
     278           0 :                     xColumnSup = Reference<XColumnsSupplier>(xColProp,UNO_QUERY);
     279           0 :                     xColumns = Reference<XIndexAccess>(xColumnSup->getColumns(),UNO_QUERY);
     280           0 :                     if(!xColumns.is() || !xColumns->getCount())
     281           0 :                         ::dbtools::throwFunctionSequenceException(_xConnection);
     282             : 
     283           0 :                     const ::rtl::OUString sQuote     = xMetaData->getIdentifierQuoteString();
     284           0 :                     aSql.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" PRIMARY KEY ")));
     285           0 :                     aSql.append(generateColumnNames(xColumns,xMetaData));
     286             :                 }
     287           0 :                 else if(nKeyType == KeyType::UNIQUE)
     288             :                 {
     289           0 :                     xColumnSup = Reference<XColumnsSupplier>(xColProp,UNO_QUERY);
     290           0 :                     xColumns = Reference<XIndexAccess>(xColumnSup->getColumns(),UNO_QUERY);
     291           0 :                     if(!xColumns.is() || !xColumns->getCount())
     292           0 :                         ::dbtools::throwFunctionSequenceException(_xConnection);
     293             : 
     294           0 :                     const ::rtl::OUString sQuote     = xMetaData->getIdentifierQuoteString();
     295           0 :                     aSql.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" UNIQUE ")));
     296           0 :                     aSql.append(generateColumnNames(xColumns,xMetaData));
     297             :                 }
     298           0 :                 else if(nKeyType == KeyType::FOREIGN)
     299             :                 {
     300           0 :                     sal_Int32 nDeleteRule   = getINT32(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_DELETERULE)));
     301             : 
     302           0 :                     xColumnSup = Reference<XColumnsSupplier>(xColProp,UNO_QUERY);
     303           0 :                     xColumns = Reference<XIndexAccess>(xColumnSup->getColumns(),UNO_QUERY);
     304           0 :                     if(!xColumns.is() || !xColumns->getCount())
     305           0 :                         ::dbtools::throwFunctionSequenceException(_xConnection);
     306             : 
     307           0 :                     aSql.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FOREIGN KEY ")));
     308           0 :                     ::rtl::OUString sRefTable = getString(xColProp->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_REFERENCEDTABLE)));
     309             :                     ::dbtools::qualifiedNameComponents(xMetaData,
     310             :                                                         sRefTable,
     311             :                                                         sCatalog,
     312             :                                                         sSchema,
     313             :                                                         sTable,
     314           0 :                                                         ::dbtools::eInDataManipulation);
     315           0 :                     sComposedName = ::dbtools::composeTableName( xMetaData, sCatalog, sSchema, sTable, sal_True, ::dbtools::eInTableDefinitions );
     316             : 
     317             : 
     318           0 :                     if ( sComposedName.isEmpty() )
     319           0 :                         ::dbtools::throwFunctionSequenceException(_xConnection);
     320             : 
     321           0 :                     aSql.append(generateColumnNames(xColumns,xMetaData));
     322             : 
     323           0 :                     switch(nDeleteRule)
     324             :                     {
     325             :                         case KeyRule::CASCADE:
     326           0 :                             aSql.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ON DELETE CASCADE ")));
     327           0 :                             break;
     328             :                         case KeyRule::RESTRICT:
     329           0 :                             aSql.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ON DELETE RESTRICT ")));
     330           0 :                             break;
     331             :                         case KeyRule::SET_NULL:
     332           0 :                             aSql.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ON DELETE SET NULL ")));
     333           0 :                             break;
     334             :                         case KeyRule::SET_DEFAULT:
     335           0 :                             aSql.append(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ON DELETE SET DEFAULT ")));
     336           0 :                             break;
     337             :                         default:
     338             :                             ;
     339           0 :                     }
     340             :                 }
     341             :             }
     342           0 :         }
     343             :     }
     344             : 
     345           0 :     if ( aSql.getLength() )
     346             :     {
     347           0 :         if ( aSql[aSql.getLength() - 1] == ',' )
     348           0 :             aSql[aSql.getLength() - 1] = ')';
     349             :         else
     350           0 :             aSql.appendAscii(")");
     351             :     }
     352             : 
     353           0 :     return aSql.makeStringAndClear();
     354             : 
     355             : }
     356             : // -----------------------------------------------------------------------------
     357           0 : ::rtl::OUString createSqlCreateTableStatement(  const Reference< XPropertySet >& descriptor,
     358             :                                                 const Reference< XConnection>& _xConnection,
     359             :                                                 ISQLStatementHelper* _pHelper,
     360             :                                                 const ::rtl::OUString& _sCreatePattern)
     361             : {
     362           0 :     ::rtl::OUString aSql = ::dbtools::createStandardCreateStatement(descriptor,_xConnection,_pHelper,_sCreatePattern);
     363           0 :     const ::rtl::OUString sKeyStmt = ::dbtools::createStandardKeyStatement(descriptor,_xConnection);
     364           0 :     if ( !sKeyStmt.isEmpty() )
     365           0 :         aSql += sKeyStmt;
     366             :     else
     367             :     {
     368           0 :         if ( aSql.lastIndexOf(',') == (aSql.getLength()-1) )
     369           0 :             aSql = aSql.replaceAt(aSql.getLength()-1,1,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")")));
     370             :         else
     371           0 :             aSql += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")"));
     372             :     }
     373           0 :     return aSql;
     374             : }
     375             : namespace
     376             : {
     377           0 :     Reference<XPropertySet> lcl_createSDBCXColumn(const Reference<XNameAccess>& _xPrimaryKeyColumns,
     378             :                                           const Reference<XConnection>& _xConnection,
     379             :                                           const Any& _aCatalog,
     380             :                                           const ::rtl::OUString& _aSchema,
     381             :                                           const ::rtl::OUString& _aTable,
     382             :                                           const ::rtl::OUString& _rQueryName,
     383             :                                           const ::rtl::OUString& _rName,
     384             :                                           sal_Bool _bCase,
     385             :                                           sal_Bool _bQueryForInfo,
     386             :                                           sal_Bool _bIsAutoIncrement,
     387             :                                           sal_Bool _bIsCurrency,
     388             :                                           sal_Int32 _nDataType)
     389             :     {
     390           0 :         Reference<XPropertySet> xProp;
     391           0 :         Reference<XDatabaseMetaData> xMetaData = _xConnection->getMetaData();
     392           0 :         Reference< XResultSet > xResult = xMetaData->getColumns(_aCatalog, _aSchema, _aTable, _rQueryName);
     393           0 :         ::rtl::OUString sCatalog;
     394           0 :         _aCatalog >>= sCatalog;
     395             : 
     396           0 :         if ( xResult.is() )
     397             :         {
     398           0 :             UStringMixEqual aMixCompare(_bCase);
     399           0 :             Reference< XRow > xRow(xResult,UNO_QUERY);
     400           0 :             while( xResult->next() )
     401             :             {
     402           0 :                 if ( aMixCompare(xRow->getString(4),_rName) )
     403             :                 {
     404           0 :                     sal_Int32       nField5 = xRow->getInt(5);
     405           0 :                     ::rtl::OUString aField6 = xRow->getString(6);
     406           0 :                     sal_Int32       nField7 = xRow->getInt(7)
     407           0 :                                 ,   nField9 = xRow->getInt(9)
     408           0 :                                 ,   nField11= xRow->getInt(11);
     409           0 :                     ::rtl::OUString sField12 = xRow->getString(12),
     410           0 :                                     sField13 = xRow->getString(13);
     411           0 :                     ::comphelper::disposeComponent(xRow);
     412             : 
     413           0 :                     sal_Bool bAutoIncrement = _bIsAutoIncrement
     414           0 :                             ,bIsCurrency    = _bIsCurrency;
     415           0 :                     if ( _bQueryForInfo )
     416             :                     {
     417           0 :                         const ::rtl::OUString sQuote = xMetaData->getIdentifierQuoteString();
     418           0 :                         ::rtl::OUString sQuotedName  = ::dbtools::quoteName(sQuote,_rName);
     419           0 :                         ::rtl::OUString sComposedName;
     420           0 :                         sComposedName = composeTableNameForSelect(_xConnection, getString( _aCatalog ), _aSchema, _aTable );
     421             : 
     422           0 :                         ColumnInformationMap aInfo(_bCase);
     423           0 :                         collectColumnInformation(_xConnection,sComposedName,sQuotedName,aInfo);
     424           0 :                         ColumnInformationMap::iterator aIter = aInfo.begin();
     425           0 :                         if ( aIter != aInfo.end() )
     426             :                         {
     427           0 :                             bAutoIncrement  = aIter->second.first.first;
     428           0 :                             bIsCurrency     = aIter->second.first.second;
     429           0 :                             if ( DataType::OTHER == nField5 )
     430           0 :                                 nField5     = aIter->second.second;
     431           0 :                         }
     432             :                     }
     433           0 :                     else if ( DataType::OTHER == nField5 )
     434           0 :                         nField5 = _nDataType;
     435             : 
     436           0 :                     if ( nField11 != ColumnValue::NO_NULLS )
     437             :                     {
     438             :                         try
     439             :                         {
     440           0 :                             if ( _xPrimaryKeyColumns.is() )
     441             :                             {
     442           0 :                                 if ( _xPrimaryKeyColumns->hasByName(_rName) )
     443           0 :                                     nField11 = ColumnValue::NO_NULLS;
     444             : 
     445             :                             }
     446             :                             else
     447             :                             {
     448           0 :                                 Reference< XResultSet > xPKeys = xMetaData->getPrimaryKeys( _aCatalog, _aSchema, _aTable );
     449           0 :                                 Reference< XRow > xPKeyRow( xPKeys, UNO_QUERY_THROW );
     450           0 :                                 while( xPKeys->next() ) // there can be only one primary key
     451             :                                 {
     452           0 :                                     ::rtl::OUString sKeyColumn = xPKeyRow->getString(4);
     453           0 :                                     if ( aMixCompare(_rName,sKeyColumn) )
     454             :                                     {
     455           0 :                                         nField11 = ColumnValue::NO_NULLS;
     456             :                                         break;
     457             :                                     }
     458           0 :                                 }
     459             :                             }
     460             :                         }
     461           0 :                         catch(SQLException&)
     462             :                         {
     463             :                             OSL_FAIL( "lcl_createSDBCXColumn: caught an exception!" );
     464             :                         }
     465             :                     }
     466             : 
     467             :                     connectivity::sdbcx::OColumn* pRet = new connectivity::sdbcx::OColumn(_rName,
     468             :                                                 aField6,
     469             :                                                 sField13,
     470             :                                                 sField12,
     471             :                                                 nField11,
     472             :                                                 nField7,
     473             :                                                 nField9,
     474             :                                                 nField5,
     475             :                                                 bAutoIncrement,
     476             :                                                 sal_False,
     477             :                                                 bIsCurrency,
     478             :                                                 _bCase,
     479             :                                                 sCatalog,
     480             :                                                 _aSchema,
     481           0 :                                                 _aTable);
     482             : 
     483           0 :                     xProp = pRet;
     484           0 :                     break;
     485             :                 }
     486           0 :             }
     487             :         }
     488             : 
     489           0 :         return xProp;
     490             :     }
     491             :     //------------------------------------------------------------------
     492          22 :     Reference< XModel> lcl_getXModel(const Reference< XInterface>& _xIface)
     493             :     {
     494          22 :         Reference< XInterface > xParent = _xIface;
     495          22 :         Reference< XModel > xModel(xParent,UNO_QUERY);;
     496          74 :         while( xParent.is() && !xModel.is() )
     497             :         {
     498          30 :             Reference<XChild> xChild(xParent,UNO_QUERY);
     499          30 :             xParent.set(xChild.is() ? xChild->getParent() : Reference< XInterface >(),UNO_QUERY);
     500          30 :             xModel.set(xParent,UNO_QUERY);
     501          30 :         }
     502          22 :         return xModel;
     503             :     }
     504             : }
     505             : // -----------------------------------------------------------------------------
     506           0 : Reference<XPropertySet> createSDBCXColumn(const Reference<XPropertySet>& _xTable,
     507             :                                           const Reference<XConnection>& _xConnection,
     508             :                                           const ::rtl::OUString& _rName,
     509             :                                           sal_Bool _bCase,
     510             :                                           sal_Bool _bQueryForInfo,
     511             :                                           sal_Bool _bIsAutoIncrement,
     512             :                                           sal_Bool _bIsCurrency,
     513             :                                           sal_Int32 _nDataType)
     514             : {
     515           0 :     Reference<XPropertySet> xProp;
     516             :     OSL_ENSURE(_xTable.is(),"Table is NULL!");
     517           0 :     if ( !_xTable.is() )
     518             :         return xProp;
     519             : 
     520           0 :     ::dbtools::OPropertyMap& rPropMap = OMetaConnection::getPropMap();
     521           0 :     Reference<XDatabaseMetaData> xMetaData = _xConnection->getMetaData();
     522           0 :     Any aCatalog;
     523           0 :     aCatalog = _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_CATALOGNAME));
     524           0 :     ::rtl::OUString sCatalog;
     525           0 :     aCatalog >>= sCatalog;
     526             : 
     527           0 :     ::rtl::OUString aSchema, aTable;
     528           0 :     _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_SCHEMANAME))  >>= aSchema;
     529           0 :     _xTable->getPropertyValue(rPropMap.getNameByIndex(PROPERTY_ID_NAME))        >>= aTable;
     530             : 
     531           0 :     Reference<XNameAccess> xPrimaryKeyColumns = getPrimaryKeyColumns_throw(_xTable);
     532             : 
     533           0 :     xProp = lcl_createSDBCXColumn(xPrimaryKeyColumns,_xConnection,aCatalog, aSchema, aTable, _rName,_rName,_bCase,_bQueryForInfo,_bIsAutoIncrement,_bIsCurrency,_nDataType);
     534           0 :     if ( !xProp.is() )
     535             :     {
     536           0 :         xProp = lcl_createSDBCXColumn(xPrimaryKeyColumns,_xConnection,aCatalog, aSchema, aTable, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")),_rName,_bCase,_bQueryForInfo,_bIsAutoIncrement,_bIsCurrency,_nDataType);
     537           0 :         if ( !xProp.is() )
     538             :             xProp = new connectivity::sdbcx::OColumn(_rName,
     539             :                                                 ::rtl::OUString(),::rtl::OUString(),::rtl::OUString(),
     540             :                                                 ColumnValue::NULLABLE_UNKNOWN,
     541             :                                                 0,
     542             :                                                 0,
     543             :                                                 DataType::VARCHAR,
     544             :                                                 _bIsAutoIncrement,
     545             :                                                 sal_False,
     546             :                                                 _bIsCurrency,
     547             :                                                 _bCase,
     548             :                                                 sCatalog,
     549             :                                                 aSchema,
     550           0 :                                                 aTable);
     551             : 
     552             :     }
     553             : 
     554           0 :     return xProp;
     555             : }
     556             : 
     557             : // -----------------------------------------------------------------------------
     558           0 : bool getBooleanDataSourceSetting( const Reference< XConnection >& _rxConnection, const sal_Char* _pAsciiSettingName )
     559             : {
     560           0 :     bool bValue( false );
     561             :     try
     562             :     {
     563           0 :         Reference< XPropertySet> xDataSourceProperties( findDataSource( _rxConnection ), UNO_QUERY );
     564             :         OSL_ENSURE( xDataSourceProperties.is(), "::dbtools::getBooleanDataSourceSetting: somebody is using this with a non-SDB-level connection!" );
     565           0 :         if ( xDataSourceProperties.is() )
     566             :         {
     567             :             Reference< XPropertySet > xSettings(
     568           0 :                 xDataSourceProperties->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Settings") ) ),
     569             :                 UNO_QUERY_THROW
     570           0 :             );
     571           0 :             OSL_VERIFY( xSettings->getPropertyValue( ::rtl::OUString::createFromAscii( _pAsciiSettingName ) ) >>= bValue );
     572           0 :         }
     573             :     }
     574           0 :     catch( const Exception& )
     575             :     {
     576             :         DBG_UNHANDLED_EXCEPTION();
     577             :     }
     578           0 :     return bValue;
     579             : }
     580             : // -------------------------------------------------------------------------
     581           0 : bool getDataSourceSetting( const Reference< XInterface >& _xChild, const ::rtl::OUString& _sAsciiSettingsName,
     582             :     Any& /* [out] */ _rSettingsValue )
     583             : {
     584           0 :     bool bIsPresent = false;
     585             :     try
     586             :     {
     587           0 :         const Reference< XPropertySet> xDataSourceProperties( findDataSource( _xChild ), UNO_QUERY );
     588           0 :         if ( !xDataSourceProperties.is() )
     589           0 :             return false;
     590             : 
     591             :         const Reference< XPropertySet > xSettings(
     592           0 :                 xDataSourceProperties->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Settings") ) ),
     593             :                 UNO_QUERY_THROW
     594           0 :             );
     595             : 
     596           0 :         _rSettingsValue = xSettings->getPropertyValue( _sAsciiSettingsName );
     597           0 :         bIsPresent = true;
     598             :     }
     599           0 :     catch( const Exception& )
     600             :     {
     601           0 :         bIsPresent = false;
     602             :     }
     603           0 :     return bIsPresent;
     604             : }
     605             : // -------------------------------------------------------------------------
     606           0 : bool getDataSourceSetting( const Reference< XInterface >& _rxDataSource, const sal_Char* _pAsciiSettingsName,
     607             :     Any& /* [out] */ _rSettingsValue )
     608             : {
     609           0 :     ::rtl::OUString sAsciiSettingsName = ::rtl::OUString::createFromAscii(_pAsciiSettingsName);
     610           0 :     return getDataSourceSetting( _rxDataSource, sAsciiSettingsName,_rSettingsValue );
     611             : }
     612             : // -----------------------------------------------------------------------------
     613           0 : sal_Bool isDataSourcePropertyEnabled(const Reference<XInterface>& _xProp,const ::rtl::OUString& _sProperty,sal_Bool _bDefault)
     614             : {
     615           0 :     sal_Bool bEnabled = _bDefault;
     616             :     try
     617             :     {
     618           0 :         Reference< XPropertySet> xProp(findDataSource(_xProp),UNO_QUERY);
     619           0 :         if ( xProp.is() )
     620             :         {
     621           0 :             Sequence< PropertyValue > aInfo;
     622           0 :             xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Info"))) >>= aInfo;
     623             :             const PropertyValue* pValue =::std::find_if(aInfo.getConstArray(),
     624           0 :                                                 aInfo.getConstArray() + aInfo.getLength(),
     625           0 :                                                 ::std::bind2nd(TPropertyValueEqualFunctor(),_sProperty));
     626           0 :             if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) )
     627           0 :                 pValue->Value >>= bEnabled;
     628           0 :         }
     629             :     }
     630           0 :     catch(SQLException&)
     631             :     {
     632             :         DBG_UNHANDLED_EXCEPTION();
     633             :     }
     634           0 :     return bEnabled;
     635             : }
     636             : // -----------------------------------------------------------------------------
     637           0 : Reference< XTablesSupplier> getDataDefinitionByURLAndConnection(
     638             :             const ::rtl::OUString& _rsUrl,
     639             :             const Reference< XConnection>& _xConnection,
     640             :             const Reference< XComponentContext >& _rxContext)
     641             : {
     642           0 :     Reference< XTablesSupplier> xTablesSup;
     643             :     try
     644             :     {
     645           0 :         Reference< XDriverManager2 > xManager = DriverManager::create( _rxContext );
     646           0 :         Reference< XDataDefinitionSupplier > xSupp( xManager->getDriverByURL( _rsUrl ), UNO_QUERY );
     647             : 
     648           0 :         if ( xSupp.is() )
     649             :         {
     650           0 :             xTablesSup = xSupp->getDataDefinitionByConnection( _xConnection );
     651             :             OSL_ENSURE(xTablesSup.is(),"No table supplier!");
     652           0 :         }
     653             :     }
     654           0 :     catch( const Exception& )
     655             :     {
     656             :         DBG_UNHANDLED_EXCEPTION();
     657             :     }
     658           0 :     return xTablesSup;
     659             : }
     660             : 
     661             : // -----------------------------------------------------------------------------
     662           0 : sal_Int32 getTablePrivileges(const Reference< XDatabaseMetaData>& _xMetaData,
     663             :                              const ::rtl::OUString& _sCatalog,
     664             :                              const ::rtl::OUString& _sSchema,
     665             :                              const ::rtl::OUString& _sTable)
     666             : {
     667             :     OSL_ENSURE(_xMetaData.is(),"Invalid metadata!");
     668           0 :     sal_Int32 nPrivileges = 0;
     669             :     try
     670             :     {
     671           0 :         Any aVal;
     672           0 :         if(!_sCatalog.isEmpty())
     673           0 :             aVal <<= _sCatalog;
     674           0 :         Reference< XResultSet > xPrivileges = _xMetaData->getTablePrivileges(aVal, _sSchema, _sTable);
     675           0 :         Reference< XRow > xCurrentRow(xPrivileges, UNO_QUERY);
     676             : 
     677           0 :         const ::rtl::OUString sUserWorkingFor = _xMetaData->getUserName();
     678           0 :         static const ::rtl::OUString sSELECT( RTL_CONSTASCII_USTRINGPARAM( "SELECT" ));
     679           0 :         static const ::rtl::OUString sINSERT( RTL_CONSTASCII_USTRINGPARAM( "INSERT" ));
     680           0 :         static const ::rtl::OUString sUPDATE( RTL_CONSTASCII_USTRINGPARAM( "UPDATE" ));
     681           0 :         static const ::rtl::OUString sDELETE( RTL_CONSTASCII_USTRINGPARAM( "DELETE" ));
     682           0 :         static const ::rtl::OUString sREAD( RTL_CONSTASCII_USTRINGPARAM( "READ" ));
     683           0 :         static const ::rtl::OUString sCREATE( RTL_CONSTASCII_USTRINGPARAM( "CREATE" ));
     684           0 :         static const ::rtl::OUString sALTER( RTL_CONSTASCII_USTRINGPARAM( "ALTER" ));
     685           0 :         static const ::rtl::OUString sREFERENCE( RTL_CONSTASCII_USTRINGPARAM( "REFERENCE" ));
     686           0 :         static const ::rtl::OUString sDROP( RTL_CONSTASCII_USTRINGPARAM( "DROP" ));
     687             : 
     688           0 :         if ( xCurrentRow.is() )
     689             :         {
     690             :             // after creation the set is positioned before the first record, per definition
     691             : #ifdef DBG_UTIL
     692             :             Reference< XResultSetMetaDataSupplier > xSup(xPrivileges,UNO_QUERY);
     693             :             if ( xSup.is() )
     694             :             {
     695             :                 Reference< XResultSetMetaData > xRsMetaData = xSup->getMetaData();
     696             :                 if ( xRsMetaData.is() )
     697             :                 {
     698             :                     sal_Int32 nCount = xRsMetaData->getColumnCount();
     699             :                     for (sal_Int32 i=1; i<=nCount; ++i)
     700             :                     {
     701             :                         ::rtl::OUString sColumnName = xRsMetaData->getColumnName(i);
     702             :                     }
     703             :                 }
     704             :             }
     705             : #endif
     706             : 
     707           0 :             ::rtl::OUString sPrivilege, sGrantee;
     708           0 :             while ( xPrivileges->next() )
     709             :             {
     710             : #ifdef DBG_UTIL
     711             :                 ::rtl::OUString sCat, sSchema, sName, sGrantor, sGrantable;
     712             :                 sCat        = xCurrentRow->getString(1);
     713             :                 sSchema     = xCurrentRow->getString(2);
     714             :                 sName       = xCurrentRow->getString(3);
     715             :                 sGrantor    = xCurrentRow->getString(4);
     716             : #endif
     717           0 :                 sGrantee    = xCurrentRow->getString(5);
     718           0 :                 sPrivilege  = xCurrentRow->getString(6);
     719             : #ifdef DBG_UTIL
     720             :                 sGrantable  = xCurrentRow->getString(7);
     721             : #endif
     722             : 
     723           0 :                 if (!sUserWorkingFor.equalsIgnoreAsciiCase(sGrantee))
     724           0 :                     continue;
     725             : 
     726           0 :                 if (sPrivilege.equalsIgnoreAsciiCase(sSELECT))
     727           0 :                     nPrivileges |= Privilege::SELECT;
     728           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sINSERT))
     729           0 :                     nPrivileges |= Privilege::INSERT;
     730           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sUPDATE))
     731           0 :                     nPrivileges |= Privilege::UPDATE;
     732           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sDELETE))
     733           0 :                     nPrivileges |= Privilege::DELETE;
     734           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sREAD))
     735           0 :                     nPrivileges |= Privilege::READ;
     736           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sCREATE))
     737           0 :                     nPrivileges |= Privilege::CREATE;
     738           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sALTER))
     739           0 :                     nPrivileges |= Privilege::ALTER;
     740           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sREFERENCE))
     741           0 :                     nPrivileges |= Privilege::REFERENCE;
     742           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sDROP))
     743           0 :                     nPrivileges |= Privilege::DROP;
     744           0 :             }
     745             :         }
     746           0 :         disposeComponent(xPrivileges);
     747             : 
     748             :         // Some drivers put a table privilege as soon as any column has the privilege,
     749             :         // some drivers only if all columns have the privilege.
     750             :         // To unifiy the situation, collect column privileges here, too.
     751           0 :         Reference< XResultSet > xColumnPrivileges = _xMetaData->getColumnPrivileges(aVal, _sSchema, _sTable, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%")));
     752           0 :         Reference< XRow > xColumnCurrentRow(xColumnPrivileges, UNO_QUERY);
     753           0 :         if ( xColumnCurrentRow.is() )
     754             :         {
     755             :             // after creation the set is positioned before the first record, per definition
     756           0 :             ::rtl::OUString sPrivilege, sGrantee;
     757           0 :             while ( xColumnPrivileges->next() )
     758             :             {
     759             : #ifdef DBG_UTIL
     760             :                 ::rtl::OUString sCat, sSchema, sTableName, sColumnName, sGrantor, sGrantable;
     761             :                 sCat        = xColumnCurrentRow->getString(1);
     762             :                 sSchema     = xColumnCurrentRow->getString(2);
     763             :                 sTableName  = xColumnCurrentRow->getString(3);
     764             :                 sColumnName = xColumnCurrentRow->getString(4);
     765             :                 sGrantor    = xColumnCurrentRow->getString(5);
     766             : #endif
     767           0 :                 sGrantee    = xColumnCurrentRow->getString(6);
     768           0 :                 sPrivilege  = xColumnCurrentRow->getString(7);
     769             : #ifdef DBG_UTIL
     770             :                 sGrantable  = xColumnCurrentRow->getString(8);
     771             : #endif
     772             : 
     773           0 :                 if (!sUserWorkingFor.equalsIgnoreAsciiCase(sGrantee))
     774           0 :                     continue;
     775             : 
     776           0 :                 if (sPrivilege.equalsIgnoreAsciiCase(sSELECT))
     777           0 :                     nPrivileges |= Privilege::SELECT;
     778           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sINSERT))
     779           0 :                     nPrivileges |= Privilege::INSERT;
     780           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sUPDATE))
     781           0 :                     nPrivileges |= Privilege::UPDATE;
     782           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sDELETE))
     783           0 :                     nPrivileges |= Privilege::DELETE;
     784           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sREAD))
     785           0 :                     nPrivileges |= Privilege::READ;
     786           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sCREATE))
     787           0 :                     nPrivileges |= Privilege::CREATE;
     788           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sALTER))
     789           0 :                     nPrivileges |= Privilege::ALTER;
     790           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sREFERENCE))
     791           0 :                     nPrivileges |= Privilege::REFERENCE;
     792           0 :                 else if (sPrivilege.equalsIgnoreAsciiCase(sDROP))
     793           0 :                     nPrivileges |= Privilege::DROP;
     794           0 :             }
     795             :         }
     796           0 :         disposeComponent(xColumnPrivileges);
     797             :     }
     798           0 :     catch(const SQLException& e)
     799             :     {
     800           0 :         static ::rtl::OUString sNotSupportedState( RTL_CONSTASCII_USTRINGPARAM( "IM001" ));
     801             :         // some drivers don't support any privileges so we assume that we are allowed to do all we want :-)
     802           0 :         if(e.SQLState == sNotSupportedState)
     803             :             nPrivileges |=  Privilege::DROP         |
     804             :                             Privilege::REFERENCE    |
     805             :                             Privilege::ALTER        |
     806             :                             Privilege::CREATE       |
     807             :                             Privilege::READ         |
     808             :                             Privilege::DELETE       |
     809             :                             Privilege::UPDATE       |
     810             :                             Privilege::INSERT       |
     811           0 :                             Privilege::SELECT;
     812             :         else
     813             :             OSL_FAIL("Could not collect the privileges !");
     814             :     }
     815           0 :     return nPrivileges;
     816             : }
     817             : // -----------------------------------------------------------------------------
     818             : // we need some more information about the column
     819           0 : void collectColumnInformation(const Reference< XConnection>& _xConnection,
     820             :                               const ::rtl::OUString& _sComposedName,
     821             :                               const ::rtl::OUString& _rName,
     822             :                               ColumnInformationMap& _rInfo)
     823             : {
     824           0 :     static ::rtl::OUString STR_WHERE = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" WHERE "));
     825             : 
     826           0 :     ::rtl::OUString sSelect = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SELECT "));
     827           0 :     sSelect += _rName;
     828           0 :     sSelect += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" FROM "));
     829           0 :     sSelect += _sComposedName;
     830           0 :     sSelect += STR_WHERE;
     831           0 :     sSelect += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("0 = 1"));
     832             : 
     833             :     try
     834             :     {
     835           0 :         ::utl::SharedUNOComponent< XStatement > xStmt( _xConnection->createStatement() );
     836           0 :         Reference< XPropertySet > xStatementProps( xStmt, UNO_QUERY_THROW );
     837           0 :         xStatementProps->setPropertyValue( OMetaConnection::getPropMap().getNameByIndex( PROPERTY_ID_ESCAPEPROCESSING ), makeAny( (sal_Bool)sal_False ) );
     838           0 :         Reference< XResultSet > xResult( xStmt->executeQuery( sSelect ), UNO_QUERY_THROW );
     839           0 :         Reference< XResultSetMetaDataSupplier > xSuppMeta( xResult, UNO_QUERY_THROW );
     840           0 :         Reference< XResultSetMetaData > xMeta( xSuppMeta->getMetaData(), UNO_QUERY_THROW );
     841             : 
     842           0 :         sal_Int32 nCount = xMeta->getColumnCount();
     843             :         OSL_ENSURE( nCount != 0, "::dbtools::collectColumnInformation: result set has empty (column-less) meta data!" );
     844           0 :         for (sal_Int32 i=1; i <= nCount ; ++i)
     845             :         {
     846           0 :             _rInfo.insert(ColumnInformationMap::value_type(xMeta->getColumnName(i),
     847           0 :                 ColumnInformation(TBoolPair(xMeta->isAutoIncrement(i),xMeta->isCurrency(i)),xMeta->getColumnType(i))));
     848           0 :         }
     849             :     }
     850           0 :     catch( const Exception& )
     851             :     {
     852             :         DBG_UNHANDLED_EXCEPTION();
     853           0 :     }
     854           0 : }
     855             : 
     856             : // -----------------------------------------------------------------------------
     857          22 : bool isEmbeddedInDatabase( const Reference< XInterface >& _rxComponent, Reference< XConnection >& _rxActualConnection )
     858             : {
     859          22 :     bool bIsEmbedded = false;
     860             :     try
     861             :     {
     862          22 :         Reference< XModel > xModel = lcl_getXModel( _rxComponent );
     863             : 
     864          22 :         if ( xModel.is() )
     865             :         {
     866          18 :             Sequence< PropertyValue > aArgs = xModel->getArgs();
     867          12 :             const PropertyValue* pIter = aArgs.getConstArray();
     868          12 :             const PropertyValue* pEnd  = pIter + aArgs.getLength();
     869         120 :             for(;pIter != pEnd;++pIter)
     870             :             {
     871         108 :                 if ( pIter->Name == "ComponentData" )
     872             :                 {
     873           0 :                     Sequence<PropertyValue> aDocumentContext;
     874           0 :                     pIter->Value >>= aDocumentContext;
     875           0 :                     const PropertyValue* pContextIter = aDocumentContext.getConstArray();
     876           0 :                     const PropertyValue* pContextEnd  = pContextIter + aDocumentContext.getLength();
     877           0 :                     for(;pContextIter != pContextEnd;++pContextIter)
     878             :                     {
     879           0 :                         if (  pContextIter->Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ActiveConnection" ) )
     880           0 :                         && ( pContextIter->Value >>= _rxActualConnection )
     881             :                         )
     882             :                         {
     883           0 :                             bIsEmbedded = true;
     884           0 :                             break;
     885             :                         }
     886             :                     }
     887           0 :                     break;
     888             :                 }
     889          12 :             }
     890          22 :         }
     891             :     }
     892           6 :     catch(Exception&)
     893             :     {
     894             :         // not intereseted in
     895             :     }
     896          22 :     return bIsEmbedded;
     897             : }
     898             : // -----------------------------------------------------------------------------
     899             : namespace
     900             : {
     901           0 :     ::rtl::OUString lcl_getEncodingName( rtl_TextEncoding _eEncoding )
     902             :     {
     903           0 :         ::rtl::OUString sEncodingName;
     904             : 
     905           0 :         OCharsetMap aCharsets;
     906           0 :         OCharsetMap::CharsetIterator aEncodingPos = aCharsets.find( _eEncoding );
     907             :         OSL_ENSURE( aEncodingPos != aCharsets.end(), "lcl_getEncodingName: *which* encoding?" );
     908           0 :         if ( aEncodingPos != aCharsets.end() )
     909           0 :             sEncodingName = (*aEncodingPos).getIanaName();
     910             : 
     911           0 :         return sEncodingName;
     912             :     }
     913             : }
     914             : 
     915             : // -----------------------------------------------------------------------------
     916           0 : sal_Int32 DBTypeConversion::convertUnicodeString( const ::rtl::OUString& _rSource, ::rtl::OString& _rDest, rtl_TextEncoding _eEncoding ) SAL_THROW((com::sun::star::sdbc::SQLException))
     917             : {
     918           0 :     if ( !rtl_convertUStringToString( &_rDest.pData, _rSource.getStr(), _rSource.getLength(),
     919             :             _eEncoding,
     920             :             RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
     921             :             RTL_UNICODETOTEXT_FLAGS_UNDEFINED_REPLACE |
     922             :             RTL_UNICODETOTEXT_FLAGS_PRIVATE_MAPTO0 |
     923           0 :             RTL_UNICODETOTEXT_FLAGS_NOCOMPOSITE )
     924             :         )
     925             :     {
     926           0 :         SharedResources aResources;
     927             :         ::rtl::OUString sMessage = aResources.getResourceStringWithSubstitution( STR_CANNOT_CONVERT_STRING,
     928             :             "$string$", _rSource,
     929             :             "$charset$",  lcl_getEncodingName( _eEncoding )
     930           0 :         );
     931             : 
     932             :         throw SQLException(
     933             :             sMessage,
     934             :             NULL,
     935             :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "22018" ) ),
     936             :             22018,
     937             :             Any()
     938           0 :         );
     939             :     }
     940             : 
     941           0 :     return _rDest.getLength();
     942             : }
     943             : 
     944             : // -----------------------------------------------------------------------------
     945           0 : sal_Int32 DBTypeConversion::convertUnicodeStringToLength( const ::rtl::OUString& _rSource, ::rtl::OString&  _rDest,
     946             :    sal_Int32 _nMaxLen, rtl_TextEncoding _eEncoding ) SAL_THROW((SQLException))
     947             : {
     948           0 :     sal_Int32 nLen = convertUnicodeString( _rSource, _rDest, _eEncoding );
     949           0 :     if ( nLen > _nMaxLen )
     950             :     {
     951           0 :         SharedResources aResources;
     952             :         ::rtl::OUString sMessage = aResources.getResourceStringWithSubstitution( STR_STRING_LENGTH_EXCEEDED,
     953             :             "$string$", _rSource,
     954             :             "$maxlen$", ::rtl::OUString::valueOf( _nMaxLen ),
     955             :             "$charset$", lcl_getEncodingName( _eEncoding )
     956           0 :         );
     957             : 
     958             :         throw SQLException(
     959             :             sMessage,
     960             :             NULL,
     961             :             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "22001" ) ),
     962             :             22001,
     963             :             Any()
     964           0 :         );
     965             :     }
     966             : 
     967           0 :    return nLen;
     968             : }
     969           0 : ::rtl::OUString lcl_getReportEngines()
     970             : {
     971           0 :     static ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.Office.DataAccess/ReportEngines"));
     972           0 :     return s_sNodeName;
     973             : }
     974             : // -----------------------------------------------------------------------------
     975           0 : ::rtl::OUString lcl_getDefaultReportEngine()
     976             : {
     977           0 :     static ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("DefaultReportEngine"));
     978           0 :     return s_sNodeName;
     979             : }
     980             : // -----------------------------------------------------------------------------
     981           0 : ::rtl::OUString lcl_getReportEngineNames()
     982             : {
     983           0 :     static ::rtl::OUString s_sNodeName(RTL_CONSTASCII_USTRINGPARAM("ReportEngineNames"));
     984           0 :     return s_sNodeName;
     985             : }
     986             : // -----------------------------------------------------------------------------
     987           0 : ::rtl::OUString getDefaultReportEngineServiceName(const Reference< XMultiServiceFactory >& _rxORB)
     988             : {
     989             :     ::utl::OConfigurationTreeRoot aReportEngines = ::utl::OConfigurationTreeRoot::createWithServiceFactory(
     990           0 :         _rxORB, lcl_getReportEngines(), -1, ::utl::OConfigurationTreeRoot::CM_READONLY);
     991             : 
     992           0 :     if ( aReportEngines.isValid() )
     993             :     {
     994           0 :         ::rtl::OUString sDefaultReportEngineName;
     995           0 :         aReportEngines.getNodeValue(lcl_getDefaultReportEngine()) >>= sDefaultReportEngineName;
     996           0 :         if ( !sDefaultReportEngineName.isEmpty() )
     997             :         {
     998           0 :             ::utl::OConfigurationNode aReportEngineNames = aReportEngines.openNode(lcl_getReportEngineNames());
     999           0 :             if ( aReportEngineNames.isValid() )
    1000             :             {
    1001           0 :                 ::utl::OConfigurationNode aReportEngine = aReportEngineNames.openNode(sDefaultReportEngineName);
    1002           0 :                 if ( aReportEngine.isValid() )
    1003             :                 {
    1004           0 :                     ::rtl::OUString sRet;
    1005           0 :                     const static ::rtl::OUString s_sService(RTL_CONSTASCII_USTRINGPARAM("ServiceName"));
    1006           0 :                     aReportEngine.getNodeValue(s_sService) >>= sRet;
    1007           0 :                     return sRet;
    1008           0 :                 }
    1009           0 :             }
    1010             :         }
    1011             :         else
    1012           0 :             return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.pentaho.SOReportJobFactory"));
    1013             :     }
    1014             :     else
    1015           0 :         return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.pentaho.SOReportJobFactory"));
    1016           0 :     return ::rtl::OUString();
    1017             : }
    1018             : // -----------------------------------------------------------------------------
    1019             : //.........................................................................
    1020             : }   // namespace dbtools
    1021             : //.........................................................................
    1022             : 
    1023             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10