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