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 
31*cdf0e10cSrcweir #include <stdio.h>
32*cdf0e10cSrcweir #include <osl/diagnose.h>
33*cdf0e10cSrcweir #include <osl/thread.h>
34*cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/sdbc/ResultSetType.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/sdbc/FetchDirection.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
38*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
39*cdf0e10cSrcweir #include "propertyids.hxx"
40*cdf0e10cSrcweir #include "NStatement.hxx"
41*cdf0e10cSrcweir #include "NConnection.hxx"
42*cdf0e10cSrcweir #include "NDatabaseMetaData.hxx"
43*cdf0e10cSrcweir #include "NResultSet.hxx"
44*cdf0e10cSrcweir #include "NDebug.hxx"
45*cdf0e10cSrcweir #include "resource/evoab2_res.hrc"
46*cdf0e10cSrcweir #include <resource/common_res.hrc>
47*cdf0e10cSrcweir #include <connectivity/dbexception.hxx>
48*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir namespace connectivity { namespace evoab {
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir //------------------------------------------------------------------------------
53*cdf0e10cSrcweir using namespace com::sun::star::uno;
54*cdf0e10cSrcweir using namespace com::sun::star::lang;
55*cdf0e10cSrcweir using namespace com::sun::star::beans;
56*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
57*cdf0e10cSrcweir using namespace com::sun::star::sdbcx;
58*cdf0e10cSrcweir using namespace com::sun::star::container;
59*cdf0e10cSrcweir using namespace com::sun::star::io;
60*cdf0e10cSrcweir using namespace com::sun::star::util;
61*cdf0e10cSrcweir //------------------------------------------------------------------------------
62*cdf0e10cSrcweir OCommonStatement::OCommonStatement(OEvoabConnection* _pConnection)
63*cdf0e10cSrcweir 	: OCommonStatement_IBase(m_aMutex)
64*cdf0e10cSrcweir 	, ::comphelper::OPropertyContainer(OCommonStatement_IBase::rBHelper)
65*cdf0e10cSrcweir     , OStatement_CBase( (::cppu::OWeakObject*)_pConnection, this )
66*cdf0e10cSrcweir 	, m_xResultSet(NULL)
67*cdf0e10cSrcweir 	, m_pResultSet(NULL)
68*cdf0e10cSrcweir 	, m_pConnection(_pConnection)
69*cdf0e10cSrcweir 	, m_aParser(_pConnection->getDriver().getMSFactory())
70*cdf0e10cSrcweir 	, m_aSQLIterator( _pConnection, _pConnection->createCatalog()->getTables(), m_aParser, NULL )
71*cdf0e10cSrcweir 	, m_pParseTree(NULL)
72*cdf0e10cSrcweir     , m_nMaxFieldSize(0)
73*cdf0e10cSrcweir     , m_nMaxRows(0)
74*cdf0e10cSrcweir     , m_nQueryTimeOut(0)
75*cdf0e10cSrcweir     , m_nFetchSize(0)
76*cdf0e10cSrcweir     , m_nResultSetType(ResultSetType::FORWARD_ONLY)
77*cdf0e10cSrcweir     , m_nFetchDirection(FetchDirection::FORWARD)
78*cdf0e10cSrcweir     , m_nResultSetConcurrency(ResultSetConcurrency::UPDATABLE)
79*cdf0e10cSrcweir     , m_bEscapeProcessing(sal_True)
80*cdf0e10cSrcweir 	, rBHelper(OCommonStatement_IBase::rBHelper)
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 	m_pConnection->acquire();
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir #define REGISTER_PROP( id, member ) \
85*cdf0e10cSrcweir     registerProperty( \
86*cdf0e10cSrcweir         OMetaConnection::getPropMap().getNameByIndex( id ), \
87*cdf0e10cSrcweir         id, \
88*cdf0e10cSrcweir         0, \
89*cdf0e10cSrcweir         &member, \
90*cdf0e10cSrcweir         ::getCppuType( &member ) \
91*cdf0e10cSrcweir     );
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     REGISTER_PROP( PROPERTY_ID_CURSORNAME, m_aCursorName );
94*cdf0e10cSrcweir     REGISTER_PROP( PROPERTY_ID_MAXFIELDSIZE, m_nMaxFieldSize );
95*cdf0e10cSrcweir     REGISTER_PROP( PROPERTY_ID_MAXROWS, m_nMaxRows );
96*cdf0e10cSrcweir     REGISTER_PROP( PROPERTY_ID_QUERYTIMEOUT, m_nQueryTimeOut );
97*cdf0e10cSrcweir     REGISTER_PROP( PROPERTY_ID_FETCHSIZE, m_nFetchSize );
98*cdf0e10cSrcweir     REGISTER_PROP( PROPERTY_ID_RESULTSETTYPE, m_nResultSetType );
99*cdf0e10cSrcweir     REGISTER_PROP( PROPERTY_ID_FETCHDIRECTION, m_nFetchDirection );
100*cdf0e10cSrcweir     REGISTER_PROP( PROPERTY_ID_ESCAPEPROCESSING, m_bEscapeProcessing );
101*cdf0e10cSrcweir     REGISTER_PROP( PROPERTY_ID_RESULTSETCONCURRENCY, m_nResultSetConcurrency );
102*cdf0e10cSrcweir }
103*cdf0e10cSrcweir // -----------------------------------------------------------------------------
104*cdf0e10cSrcweir OCommonStatement::~OCommonStatement()
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir //------------------------------------------------------------------------------
108*cdf0e10cSrcweir void OCommonStatement::disposeResultSet()
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir 	// free the cursor if alive
111*cdf0e10cSrcweir 	Reference< XComponent > xComp(m_xResultSet.get(), UNO_QUERY);
112*cdf0e10cSrcweir 	if (xComp.is())
113*cdf0e10cSrcweir 		xComp->dispose();
114*cdf0e10cSrcweir 	m_xResultSet = Reference< XResultSet>();
115*cdf0e10cSrcweir }
116*cdf0e10cSrcweir //------------------------------------------------------------------------------
117*cdf0e10cSrcweir void OCommonStatement::disposing()
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir 	::osl::MutexGuard aGuard(m_aMutex);
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 	disposeResultSet();
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 	if (m_pConnection)
124*cdf0e10cSrcweir 		m_pConnection->release();
125*cdf0e10cSrcweir 	m_pConnection = NULL;
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 	dispose_ChildImpl();
128*cdf0e10cSrcweir 	OCommonStatement_IBase::disposing();
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir //-----------------------------------------------------------------------------
131*cdf0e10cSrcweir Any SAL_CALL OCommonStatement::queryInterface( const Type & rType ) throw(RuntimeException)
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir 	Any aRet = OCommonStatement_IBase::queryInterface(rType);
134*cdf0e10cSrcweir 	if(!aRet.hasValue())
135*cdf0e10cSrcweir 		aRet = ::comphelper::OPropertyContainer::queryInterface(rType);
136*cdf0e10cSrcweir 	return aRet;
137*cdf0e10cSrcweir }
138*cdf0e10cSrcweir // -------------------------------------------------------------------------
139*cdf0e10cSrcweir Sequence< Type > SAL_CALL OCommonStatement::getTypes(  ) throw(RuntimeException)
140*cdf0e10cSrcweir {
141*cdf0e10cSrcweir 	::cppu::OTypeCollection aTypes(	::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
142*cdf0e10cSrcweir 									::getCppuType( (const Reference< XFastPropertySet > *)0 ),
143*cdf0e10cSrcweir 									::getCppuType( (const Reference< XPropertySet > *)0 ));
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	return ::comphelper::concatSequences(aTypes.getTypes(),OCommonStatement_IBase::getTypes());
146*cdf0e10cSrcweir }
147*cdf0e10cSrcweir // -------------------------------------------------------------------------
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir //void SAL_CALL OCommonStatement::cancel(  ) throw(RuntimeException)
150*cdf0e10cSrcweir //{
151*cdf0e10cSrcweir //::osl::MutexGuard aGuard( m_aMutex );
152*cdf0e10cSrcweir //checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
153*cdf0e10cSrcweir //// cancel the current sql statement
154*cdf0e10cSrcweir //}
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir // -------------------------------------------------------------------------
157*cdf0e10cSrcweir void SAL_CALL OCommonStatement::close(  ) throw(SQLException, RuntimeException)
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir 	{
160*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aMutex );
161*cdf0e10cSrcweir 		checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 	}
164*cdf0e10cSrcweir 	dispose();
165*cdf0e10cSrcweir }
166*cdf0e10cSrcweir // -------------------------------------------------------------------------
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir void OCommonStatement::reset() throw (SQLException)
169*cdf0e10cSrcweir {
170*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
171*cdf0e10cSrcweir 	checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 	clearWarnings ();
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	if (m_xResultSet.get().is())
177*cdf0e10cSrcweir 		clearMyResultSet();
178*cdf0e10cSrcweir }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir void OCommonStatement::clearMyResultSet () throw (SQLException)
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
183*cdf0e10cSrcweir 	checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     try
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir 	    Reference<XCloseable> xCloseable;
188*cdf0e10cSrcweir 	    if ( ::comphelper::query_interface( m_xResultSet.get(), xCloseable ) )
189*cdf0e10cSrcweir 		    xCloseable->close();
190*cdf0e10cSrcweir     }
191*cdf0e10cSrcweir     catch( const DisposedException& ) { }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir     m_xResultSet = Reference< XResultSet >();
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir EBookQuery *
197*cdf0e10cSrcweir OCommonStatement::createTrue()
198*cdf0e10cSrcweir { // Not the world's most efficient unconditional true but ...
199*cdf0e10cSrcweir 	return e_book_query_from_string("(exists \"full_name\")");
200*cdf0e10cSrcweir }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir EBookQuery *
203*cdf0e10cSrcweir OCommonStatement::createTest( const ::rtl::OUString &aColumnName,
204*cdf0e10cSrcweir 							 EBookQueryTest eTest,
205*cdf0e10cSrcweir 							 const ::rtl::OUString &aMatch )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     ::rtl::OString sMatch = rtl::OUStringToOString( aMatch, RTL_TEXTENCODING_UTF8 );
208*cdf0e10cSrcweir     ::rtl::OString sColumnName = rtl::OUStringToOString( aColumnName, RTL_TEXTENCODING_UTF8 );
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir 	return e_book_query_field_test( e_contact_field_id( sColumnName ),
211*cdf0e10cSrcweir 									eTest, sMatch );
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir // -------------------------------------------------------------------------
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir ::rtl::OUString OCommonStatement::impl_getColumnRefColumnName_throw( const OSQLParseNode& _rColumnRef )
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     ENSURE_OR_THROW( SQL_ISRULE( &_rColumnRef, column_ref ), "internal error: only column_refs supported as LHS" );
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     ::rtl::OUString sColumnName;
221*cdf0e10cSrcweir     switch ( _rColumnRef.count() )
222*cdf0e10cSrcweir     {
223*cdf0e10cSrcweir     case 3: // SQL_TOKEN_NAME '.' column_val
224*cdf0e10cSrcweir     {
225*cdf0e10cSrcweir         const OSQLParseNode* pPunct = _rColumnRef.getChild( 1 );
226*cdf0e10cSrcweir         const OSQLParseNode* pColVal = _rColumnRef.getChild( 2 );
227*cdf0e10cSrcweir         if  (   SQL_ISPUNCTUATION( pPunct, "." )
228*cdf0e10cSrcweir             &&  ( pColVal->count() == 1 )
229*cdf0e10cSrcweir             )
230*cdf0e10cSrcweir         {
231*cdf0e10cSrcweir             sColumnName = pColVal->getChild( 0 )->getTokenValue();
232*cdf0e10cSrcweir         }
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir     break;
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir     case 1: // column
237*cdf0e10cSrcweir     {
238*cdf0e10cSrcweir         sColumnName = _rColumnRef.getChild( 0 )->getTokenValue();
239*cdf0e10cSrcweir     }
240*cdf0e10cSrcweir     break;
241*cdf0e10cSrcweir     }
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir     if ( !sColumnName.getLength() )
244*cdf0e10cSrcweir         m_pConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this );
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir     return sColumnName;
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir // -------------------------------------------------------------------------
250*cdf0e10cSrcweir void OCommonStatement::orderByAnalysis( const OSQLParseNode* _pOrderByClause, SortDescriptor& _out_rSort )
251*cdf0e10cSrcweir {
252*cdf0e10cSrcweir     ENSURE_OR_THROW( _pOrderByClause, "NULL node" );
253*cdf0e10cSrcweir     ENSURE_OR_THROW( SQL_ISRULE( _pOrderByClause, opt_order_by_clause ), "wrong node type" );
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir     _out_rSort.clear();
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir     const OSQLParseNode* pOrderList = _pOrderByClause->getByRule( OSQLParseNode::ordering_spec_commalist );
258*cdf0e10cSrcweir     ENSURE_OR_THROW( pOrderList, "unexpected parse tree structure" );
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     for ( sal_uInt32 i=0; i<pOrderList->count(); ++i )
261*cdf0e10cSrcweir     {
262*cdf0e10cSrcweir         const OSQLParseNode* pOrderBy = pOrderList->getChild(i);
263*cdf0e10cSrcweir         if ( !pOrderBy || !SQL_ISRULE( pOrderBy, ordering_spec ) )
264*cdf0e10cSrcweir             continue;
265*cdf0e10cSrcweir         const OSQLParseNode* pColumnRef = pOrderBy->count() == 2 ? pOrderBy->getChild(0) : NULL;
266*cdf0e10cSrcweir         const OSQLParseNode* pAscDesc = pOrderBy->count() == 2 ? pOrderBy->getChild(1) : NULL;
267*cdf0e10cSrcweir         ENSURE_OR_THROW(
268*cdf0e10cSrcweir                 ( pColumnRef != NULL )
269*cdf0e10cSrcweir             &&  ( pAscDesc != NULL )
270*cdf0e10cSrcweir             &&  SQL_ISRULE( pAscDesc, opt_asc_desc )
271*cdf0e10cSrcweir             &&  ( pAscDesc->count() < 2 ),
272*cdf0e10cSrcweir             "ordering_spec structure error" );
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir         // column name -> column field
275*cdf0e10cSrcweir         if ( !SQL_ISRULE( pColumnRef, column_ref ) )
276*cdf0e10cSrcweir             m_pConnection->throwGenericSQLException( STR_SORT_BY_COL_ONLY, *this );
277*cdf0e10cSrcweir         const ::rtl::OUString sColumnName( impl_getColumnRefColumnName_throw( *pColumnRef ) );
278*cdf0e10cSrcweir         guint nField = evoab::findEvoabField( sColumnName );
279*cdf0e10cSrcweir         // ascending/descending?
280*cdf0e10cSrcweir         bool bAscending = true;
281*cdf0e10cSrcweir         if  (   ( pAscDesc->count() == 1 )
282*cdf0e10cSrcweir             &&  SQL_ISTOKEN( pAscDesc->getChild( 0 ), DESC )
283*cdf0e10cSrcweir             )
284*cdf0e10cSrcweir             bAscending = false;
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir         _out_rSort.push_back( FieldSort( nField, bAscending ) );
287*cdf0e10cSrcweir     }
288*cdf0e10cSrcweir }
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir // -------------------------------------------------------------------------
291*cdf0e10cSrcweir EBookQuery *OCommonStatement::whereAnalysis( const OSQLParseNode* parseTree )
292*cdf0e10cSrcweir {
293*cdf0e10cSrcweir 	EBookQuery *pResult = NULL;
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir     ENSURE_OR_THROW( parseTree, "invalid parse tree" );
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 	// Nested brackets
298*cdf0e10cSrcweir 	if( parseTree->count() == 3 &&
299*cdf0e10cSrcweir 		SQL_ISPUNCTUATION( parseTree->getChild( 0 ), "(" ) &&
300*cdf0e10cSrcweir 		SQL_ISPUNCTUATION( parseTree->getChild( 2 ), ")" ) )
301*cdf0e10cSrcweir 	{
302*cdf0e10cSrcweir 		pResult = whereAnalysis( parseTree->getChild( 1 ) );
303*cdf0e10cSrcweir 	}
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir 	// SQL AND, OR
306*cdf0e10cSrcweir     else if( ( SQL_ISRULE( parseTree, search_condition ) ||
307*cdf0e10cSrcweir 		  SQL_ISRULE( parseTree, boolean_term ) ) &&
308*cdf0e10cSrcweir 		parseTree->count() == 3 )
309*cdf0e10cSrcweir     {
310*cdf0e10cSrcweir         ENSURE_OR_THROW(    SQL_ISTOKEN( parseTree->getChild( 1 ), OR )
311*cdf0e10cSrcweir                         ||  SQL_ISTOKEN( parseTree->getChild( 1 ), AND ),
312*cdf0e10cSrcweir                         "unexpected search_condition structure" );
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir         EBookQuery *pArgs[2];
315*cdf0e10cSrcweir 		pArgs[0] = whereAnalysis( parseTree->getChild( 0 ) );
316*cdf0e10cSrcweir 		pArgs[1] = whereAnalysis( parseTree->getChild( 2 ) );
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir         if( SQL_ISTOKEN( parseTree->getChild( 1 ), OR ) )
319*cdf0e10cSrcweir             pResult = e_book_query_or( 2, pArgs, TRUE );
320*cdf0e10cSrcweir         else
321*cdf0e10cSrcweir 			pResult = e_book_query_and( 2, pArgs, TRUE );
322*cdf0e10cSrcweir     }
323*cdf0e10cSrcweir 	// SQL =, !=
324*cdf0e10cSrcweir 	else if( SQL_ISRULE( parseTree, comparison_predicate ) )
325*cdf0e10cSrcweir 	{
326*cdf0e10cSrcweir         OSQLParseNode *pPrec = parseTree->getChild( 1 );
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir         ENSURE_OR_THROW( parseTree->count() == 3, "unexpected comparison_predicate structure" );
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir         OSQLParseNode* pLHS = parseTree->getChild( 0 );
331*cdf0e10cSrcweir         OSQLParseNode* pRHS = parseTree->getChild( 2 );
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir         if  (   (   !( SQL_ISRULE( pLHS, column_ref ) )         // on the LHS, we accept a column or a constant int value
334*cdf0e10cSrcweir                 &&  ( pLHS->getNodeType() != SQL_NODE_INTNUM )
335*cdf0e10cSrcweir                 )
336*cdf0e10cSrcweir             ||  (   ( pRHS->getNodeType() != SQL_NODE_STRING )  // on the RHS, certain literals are acceptable
337*cdf0e10cSrcweir                 &&  ( pRHS->getNodeType() != SQL_NODE_INTNUM )
338*cdf0e10cSrcweir                 &&  ( pRHS->getNodeType() != SQL_NODE_APPROXNUM )
339*cdf0e10cSrcweir                 &&  !( SQL_ISTOKEN( pRHS, TRUE ) )
340*cdf0e10cSrcweir                 &&  !( SQL_ISTOKEN( pRHS, FALSE ) )
341*cdf0e10cSrcweir                 )
342*cdf0e10cSrcweir             ||  (   ( pLHS->getNodeType() == SQL_NODE_INTNUM )  // an int on LHS requires an int on RHS
343*cdf0e10cSrcweir                 &&  ( pRHS->getNodeType() != SQL_NODE_INTNUM )
344*cdf0e10cSrcweir                 )
345*cdf0e10cSrcweir             )
346*cdf0e10cSrcweir         {
347*cdf0e10cSrcweir             m_pConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this );
348*cdf0e10cSrcweir         }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir         if  (   ( pPrec->getNodeType() != SQL_NODE_EQUAL )
351*cdf0e10cSrcweir             &&  ( pPrec->getNodeType() != SQL_NODE_NOTEQUAL )
352*cdf0e10cSrcweir             )
353*cdf0e10cSrcweir         {
354*cdf0e10cSrcweir             m_pConnection->throwGenericSQLException( STR_OPERATOR_TOO_COMPLEX, *this );
355*cdf0e10cSrcweir         }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir         // recognize the special "0 = 1" condition
358*cdf0e10cSrcweir         if  (   ( pLHS->getNodeType() == SQL_NODE_INTNUM )
359*cdf0e10cSrcweir             &&  ( pRHS->getNodeType() == SQL_NODE_INTNUM )
360*cdf0e10cSrcweir             &&  ( pPrec->getNodeType() == SQL_NODE_EQUAL )
361*cdf0e10cSrcweir             )
362*cdf0e10cSrcweir         {
363*cdf0e10cSrcweir             const sal_Int32 nLHS = pLHS->getTokenValue().toInt64();
364*cdf0e10cSrcweir             const sal_Int32 nRHS = pRHS->getTokenValue().toInt64();
365*cdf0e10cSrcweir             return ( nLHS == nRHS ) ? createTrue() : NULL;
366*cdf0e10cSrcweir         }
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir         ::rtl::OUString aColumnName( impl_getColumnRefColumnName_throw( *pLHS ) );
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir         ::rtl::OUString aMatchString;
371*cdf0e10cSrcweir 		if ( pRHS->isToken() )
372*cdf0e10cSrcweir 			aMatchString = pRHS->getTokenValue();
373*cdf0e10cSrcweir 		else
374*cdf0e10cSrcweir 			aMatchString = pRHS->getChild( 0 )->getTokenValue();
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir 	    pResult = createTest( aColumnName, E_BOOK_QUERY_IS, aMatchString );
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir         if ( pResult && ( pPrec->getNodeType() == SQL_NODE_NOTEQUAL ) )
379*cdf0e10cSrcweir 		    pResult = e_book_query_not( pResult, TRUE );
380*cdf0e10cSrcweir 	}
381*cdf0e10cSrcweir 	// SQL like
382*cdf0e10cSrcweir 	else if( SQL_ISRULE( parseTree, like_predicate ) )
383*cdf0e10cSrcweir     {
384*cdf0e10cSrcweir         ENSURE_OR_THROW( parseTree->count() == 2, "unexpected like_predicate structure" );
385*cdf0e10cSrcweir         const OSQLParseNode* pPart2 = parseTree->getChild(1);
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir         if( ! SQL_ISRULE( parseTree->getChild( 0 ), column_ref) )
388*cdf0e10cSrcweir             m_pConnection->throwGenericSQLException(STR_QUERY_INVALID_LIKE_COLUMN,*this);
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir         ::rtl::OUString aColumnName( impl_getColumnRefColumnName_throw( *parseTree->getChild( 0 ) ) );
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir         OSQLParseNode *pAtom      = pPart2->getChild( pPart2->count() - 2 );     // Match String
393*cdf0e10cSrcweir 		bool bNotLike             = pPart2->getChild(0)->isToken();
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir         if( !( pAtom->getNodeType() == SQL_NODE_STRING ||
396*cdf0e10cSrcweir 			   pAtom->getNodeType() == SQL_NODE_NAME ||
397*cdf0e10cSrcweir 			   SQL_ISRULE( pAtom,parameter ) ||
398*cdf0e10cSrcweir 			   ( pAtom->getChild( 0 ) && pAtom->getChild( 0 )->getNodeType() == SQL_NODE_NAME ) ||
399*cdf0e10cSrcweir 			   ( pAtom->getChild( 0 ) && pAtom->getChild( 0 )->getNodeType() == SQL_NODE_STRING ) ) )
400*cdf0e10cSrcweir         {
401*cdf0e10cSrcweir             OSL_TRACE( "analyseSQL : pAtom->count() = %d\n", pAtom->count() );
402*cdf0e10cSrcweir             m_pConnection->throwGenericSQLException(STR_QUERY_INVALID_LIKE_STRING,*this);
403*cdf0e10cSrcweir         }
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir         const sal_Unicode WILDCARD = '%';
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 		rtl::OUString aMatchString;
408*cdf0e10cSrcweir 		aMatchString = pAtom->getTokenValue();
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 		// Determine where '%' character is...
411*cdf0e10cSrcweir 		if( aMatchString.equals( ::rtl::OUString::valueOf( WILDCARD ) ) )
412*cdf0e10cSrcweir 		{
413*cdf0e10cSrcweir 		    // String containing only a '%' and nothing else matches everything
414*cdf0e10cSrcweir 			pResult = createTest( aColumnName, E_BOOK_QUERY_CONTAINS,
415*cdf0e10cSrcweir 								  rtl::OUString::createFromAscii( "" ) );
416*cdf0e10cSrcweir 		}
417*cdf0e10cSrcweir 		else if( aMatchString.indexOf( WILDCARD ) == -1 )
418*cdf0e10cSrcweir 		{   // Simple string , eg. "to match" "contains in evo"
419*cdf0e10cSrcweir 			EVO_TRACE_STRING( "Plain contains '%s'", aMatchString );
420*cdf0e10cSrcweir 			pResult = createTest( aColumnName, E_BOOK_QUERY_CONTAINS, aMatchString );
421*cdf0e10cSrcweir 			if( pResult && bNotLike )
422*cdf0e10cSrcweir 				pResult = e_book_query_not( pResult, TRUE );
423*cdf0e10cSrcweir 		}
424*cdf0e10cSrcweir 		else if( bNotLike )
425*cdf0e10cSrcweir 		{
426*cdf0e10cSrcweir 			// We currently can't handle a 'NOT LIKE' when there are '%'
427*cdf0e10cSrcweir             m_pConnection->throwGenericSQLException(STR_QUERY_NOT_LIKE_TOO_COMPLEX,*this);
428*cdf0e10cSrcweir 		}
429*cdf0e10cSrcweir 		else if( (aMatchString.indexOf ( WILDCARD ) == aMatchString.lastIndexOf ( WILDCARD ) ) )
430*cdf0e10cSrcweir 		{   // One occurance of '%'  matches...
431*cdf0e10cSrcweir             if ( aMatchString.indexOf ( WILDCARD ) == 0 )
432*cdf0e10cSrcweir 				pResult = createTest( aColumnName, E_BOOK_QUERY_ENDS_WITH, aMatchString.copy( 1 ) );
433*cdf0e10cSrcweir             else if ( aMatchString.indexOf ( WILDCARD ) == aMatchString.getLength() - 1 )
434*cdf0e10cSrcweir 				pResult = createTest( aColumnName, E_BOOK_QUERY_BEGINS_WITH, aMatchString.copy( 0, aMatchString.getLength() - 1 ) );
435*cdf0e10cSrcweir 			else
436*cdf0e10cSrcweir                 m_pConnection->throwGenericSQLException(STR_QUERY_LIKE_WILDCARD,*this);
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir 			if( pResult && bNotLike )
439*cdf0e10cSrcweir 				pResult = e_book_query_not( pResult, TRUE );
440*cdf0e10cSrcweir         }
441*cdf0e10cSrcweir 		else if( aMatchString.getLength() >= 3 &&
442*cdf0e10cSrcweir 				 aMatchString.indexOf ( WILDCARD ) == 0 &&
443*cdf0e10cSrcweir 				 aMatchString.indexOf ( WILDCARD, 1) == aMatchString.getLength() - 1 ) {
444*cdf0e10cSrcweir 			// one '%' at the start and another at the end
445*cdf0e10cSrcweir 			pResult = createTest( aColumnName, E_BOOK_QUERY_CONTAINS, aMatchString.copy (1, aMatchString.getLength() - 2) );
446*cdf0e10cSrcweir 		}
447*cdf0e10cSrcweir 		else
448*cdf0e10cSrcweir             m_pConnection->throwGenericSQLException(STR_QUERY_LIKE_WILDCARD_MANY,*this);
449*cdf0e10cSrcweir 	}
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 	return pResult;
452*cdf0e10cSrcweir }
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir rtl::OUString OCommonStatement::getTableName()
455*cdf0e10cSrcweir {
456*cdf0e10cSrcweir 	::rtl::OUString aTableName;
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir 	if( m_pParseTree && m_aSQLIterator.getStatementType() == SQL_STATEMENT_SELECT )
459*cdf0e10cSrcweir 	{
460*cdf0e10cSrcweir 		Any aCatalog;
461*cdf0e10cSrcweir 		::rtl::OUString aSchema, aComposedName;
462*cdf0e10cSrcweir 		const OSQLParseNode *pSelectStmnt = m_aSQLIterator.getParseTree();
463*cdf0e10cSrcweir 		const OSQLParseNode *pAllTableNames = pSelectStmnt->getChild( 3 )->getChild( 0 )->getChild( 1 );
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir 		if( m_aSQLIterator.isTableNode( pAllTableNames->getChild( 0 ) ) )
466*cdf0e10cSrcweir 			OSQLParseNode::getTableComponents( pAllTableNames->getChild( 0 ),
467*cdf0e10cSrcweir 											   aCatalog,aSchema, aTableName,NULL );
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir 		else if( SQL_ISRULE( pAllTableNames->getChild( 0 ), table_ref ) )
470*cdf0e10cSrcweir 		{
471*cdf0e10cSrcweir 			OSQLParseNode *pNodeForTableName = pAllTableNames->getChild( 0 )->getChild( 0 );
472*cdf0e10cSrcweir 			if( m_aSQLIterator.isTableNode( pNodeForTableName ) )
473*cdf0e10cSrcweir 			{
474*cdf0e10cSrcweir                 aTableName = OSQLParseNode::getTableRange(pAllTableNames->getChild( 0 ));
475*cdf0e10cSrcweir 				if( !aTableName.getLength() )
476*cdf0e10cSrcweir         			OSQLParseNode::getTableComponents( pNodeForTableName, aCatalog, aSchema, aTableName,NULL);
477*cdf0e10cSrcweir 			}
478*cdf0e10cSrcweir 			else
479*cdf0e10cSrcweir 				OSL_ENSURE( false,  "odd table layout" );
480*cdf0e10cSrcweir 		}
481*cdf0e10cSrcweir 		else
482*cdf0e10cSrcweir 				OSL_ENSURE( false,  "unusual table layout" );
483*cdf0e10cSrcweir 	}
484*cdf0e10cSrcweir 	return aTableName;
485*cdf0e10cSrcweir }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir void OCommonStatement::parseSql( const rtl::OUString& sql, QueryData& _out_rQueryData )
488*cdf0e10cSrcweir {
489*cdf0e10cSrcweir     EVO_TRACE_STRING( "parsing %s", sql );
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir     _out_rQueryData.eFilterType = eFilterOther;
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir     ::rtl::OUString aErr;
494*cdf0e10cSrcweir 	m_pParseTree = m_aParser.parseTree( aErr, sql );
495*cdf0e10cSrcweir 	m_aSQLIterator.setParseTree( m_pParseTree );
496*cdf0e10cSrcweir 	m_aSQLIterator.traverseAll();
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir     _out_rQueryData.sTable = getTableName();
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir     // to be sorted?
501*cdf0e10cSrcweir 	const OSQLParseNode* pOrderByClause = m_aSQLIterator.getOrderTree();
502*cdf0e10cSrcweir     if ( pOrderByClause )
503*cdf0e10cSrcweir     {
504*cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 0
505*cdf0e10cSrcweir         ::rtl::OUString sTreeDebug;
506*cdf0e10cSrcweir         pOrderByClause->showParseTree( sTreeDebug );
507*cdf0e10cSrcweir         EVO_TRACE_STRING( "found order-by tree:\n%s", sTreeDebug );
508*cdf0e10cSrcweir     #endif
509*cdf0e10cSrcweir         orderByAnalysis( pOrderByClause, _out_rQueryData.aSortOrder );
510*cdf0e10cSrcweir     }
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir 	const OSQLParseNode* pWhereClause = m_aSQLIterator.getWhereTree();
513*cdf0e10cSrcweir 	if ( pWhereClause && SQL_ISRULE( pWhereClause, where_clause ) )
514*cdf0e10cSrcweir     {
515*cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 0
516*cdf0e10cSrcweir         ::rtl::OUString sTreeDebug;
517*cdf0e10cSrcweir         pWhereClause->showParseTree( sTreeDebug );
518*cdf0e10cSrcweir         EVO_TRACE_STRING( "found where tree:\n%s", sTreeDebug );
519*cdf0e10cSrcweir     #endif
520*cdf0e10cSrcweir         EBookQuery* pQuery = whereAnalysis( pWhereClause->getChild( 1 ) );
521*cdf0e10cSrcweir         if ( !pQuery )
522*cdf0e10cSrcweir         {
523*cdf0e10cSrcweir 		    _out_rQueryData.eFilterType = eFilterAlwaysFalse;
524*cdf0e10cSrcweir             pQuery = createTrue();
525*cdf0e10cSrcweir         }
526*cdf0e10cSrcweir         _out_rQueryData.setQuery( pQuery );
527*cdf0e10cSrcweir     }
528*cdf0e10cSrcweir 	else
529*cdf0e10cSrcweir 	{
530*cdf0e10cSrcweir 		_out_rQueryData.eFilterType = eFilterNone;
531*cdf0e10cSrcweir 		_out_rQueryData.setQuery( createTrue() );
532*cdf0e10cSrcweir 	}
533*cdf0e10cSrcweir }
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir // -------------------------------------------------------------------------
536*cdf0e10cSrcweir 
537*cdf0e10cSrcweir Reference< XConnection > SAL_CALL OStatement::getConnection(  ) throw(SQLException, RuntimeException)
538*cdf0e10cSrcweir {
539*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
540*cdf0e10cSrcweir 	checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 	// just return our connection here
543*cdf0e10cSrcweir 	return impl_getConnection();
544*cdf0e10cSrcweir }
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir // -------------------------------------------------------------------------
547*cdf0e10cSrcweir Any SAL_CALL OCommonStatement::getWarnings(  ) throw(SQLException, RuntimeException)
548*cdf0e10cSrcweir {
549*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
550*cdf0e10cSrcweir 	checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
551*cdf0e10cSrcweir 
552*cdf0e10cSrcweir 
553*cdf0e10cSrcweir 	return makeAny(SQLWarning());
554*cdf0e10cSrcweir }
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir // -------------------------------------------------------------------------
557*cdf0e10cSrcweir void SAL_CALL OCommonStatement::clearWarnings(  ) throw(SQLException, RuntimeException)
558*cdf0e10cSrcweir {
559*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
560*cdf0e10cSrcweir 	checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir }
563*cdf0e10cSrcweir // -------------------------------------------------------------------------
564*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* OCommonStatement::createArrayHelper( ) const
565*cdf0e10cSrcweir {
566*cdf0e10cSrcweir     Sequence< Property > aProps;
567*cdf0e10cSrcweir     describeProperties( aProps );
568*cdf0e10cSrcweir     return new ::cppu::OPropertyArrayHelper( aProps );
569*cdf0e10cSrcweir }
570*cdf0e10cSrcweir // -------------------------------------------------------------------------
571*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & OCommonStatement::getInfoHelper()
572*cdf0e10cSrcweir {
573*cdf0e10cSrcweir 	return *const_cast< OCommonStatement* >( this )->getArrayHelper();
574*cdf0e10cSrcweir }
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir // -----------------------------------------------------------------------------
577*cdf0e10cSrcweir void SAL_CALL OCommonStatement::acquire() throw()
578*cdf0e10cSrcweir {
579*cdf0e10cSrcweir 	OCommonStatement_IBase::acquire();
580*cdf0e10cSrcweir }
581*cdf0e10cSrcweir // -----------------------------------------------------------------------------
582*cdf0e10cSrcweir void SAL_CALL OCommonStatement::release() throw()
583*cdf0e10cSrcweir {
584*cdf0e10cSrcweir     relase_ChildImpl();
585*cdf0e10cSrcweir }
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir // -------------------------------------------------------------------------
588*cdf0e10cSrcweir QueryData OCommonStatement::impl_getEBookQuery_throw( const ::rtl::OUString& _rSql )
589*cdf0e10cSrcweir {
590*cdf0e10cSrcweir     QueryData aData;
591*cdf0e10cSrcweir 	parseSql( _rSql, aData );
592*cdf0e10cSrcweir 
593*cdf0e10cSrcweir #ifdef DEBUG
594*cdf0e10cSrcweir 	char *pSexpr = aData.getQuery() ? e_book_query_to_string( aData.getQuery() ) : g_strdup( "<map failed>" );
595*cdf0e10cSrcweir 	g_message( "Parsed SQL to sexpr '%s'\n", pSexpr );
596*cdf0e10cSrcweir 	g_free( pSexpr );
597*cdf0e10cSrcweir #endif
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir     if ( !aData.getQuery() )
600*cdf0e10cSrcweir         m_pConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this );
601*cdf0e10cSrcweir 
602*cdf0e10cSrcweir     // a postcondition of this method is that we properly determined the SELECT columns
603*cdf0e10cSrcweir     aData.xSelectColumns = m_aSQLIterator.getSelectColumns();
604*cdf0e10cSrcweir 	if ( !aData.xSelectColumns.isValid() )
605*cdf0e10cSrcweir         m_pConnection->throwGenericSQLException( STR_QUERY_TOO_COMPLEX, *this );
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir     return aData;
608*cdf0e10cSrcweir }
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir // -------------------------------------------------------------------------
611*cdf0e10cSrcweir Reference< XResultSet > OCommonStatement::impl_executeQuery_throw( const QueryData& _rQueryData )
612*cdf0e10cSrcweir {
613*cdf0e10cSrcweir     // create result set
614*cdf0e10cSrcweir 	OEvoabResultSet* pResult = new OEvoabResultSet( this, m_pConnection );
615*cdf0e10cSrcweir 	Reference< XResultSet > xRS = pResult;
616*cdf0e10cSrcweir     pResult->construct( _rQueryData );
617*cdf0e10cSrcweir 
618*cdf0e10cSrcweir     // done
619*cdf0e10cSrcweir     m_xResultSet = xRS;
620*cdf0e10cSrcweir 	return xRS;
621*cdf0e10cSrcweir }
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir // -------------------------------------------------------------------------
624*cdf0e10cSrcweir Reference< XResultSet > OCommonStatement::impl_executeQuery_throw( const ::rtl::OUString& _rSql )
625*cdf0e10cSrcweir {
626*cdf0e10cSrcweir 	EVO_TRACE_STRING( "OCommonStatement::impl_executeQuery_throw(%s)\n", _rSql );
627*cdf0e10cSrcweir 
628*cdf0e10cSrcweir #ifdef DEBUG
629*cdf0e10cSrcweir 	g_message( "Parse SQL '%s'\n",
630*cdf0e10cSrcweir 			   (const sal_Char *)OUStringToOString( _rSql, RTL_TEXTENCODING_UTF8 ) );
631*cdf0e10cSrcweir #endif
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir     return impl_executeQuery_throw( impl_getEBookQuery_throw( _rSql ) );
634*cdf0e10cSrcweir }
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir // -----------------------------------------------------------------------------
637*cdf0e10cSrcweir Reference< XPropertySetInfo > SAL_CALL OCommonStatement::getPropertySetInfo(  ) throw(RuntimeException)
638*cdf0e10cSrcweir {
639*cdf0e10cSrcweir 	return ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
640*cdf0e10cSrcweir }
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir // =============================================================================
643*cdf0e10cSrcweir // = OStatement
644*cdf0e10cSrcweir // =============================================================================
645*cdf0e10cSrcweir // -----------------------------------------------------------------------------
646*cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO( OStatement, "com.sun.star.comp.sdbcx.evoab.OStatement", "com.sun.star.sdbc.Statement" );
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir // -----------------------------------------------------------------------------
649*cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( OStatement, OCommonStatement, OStatement_IBase )
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir // -----------------------------------------------------------------------------
652*cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( OStatement, OCommonStatement, OStatement_IBase )
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir // -------------------------------------------------------------------------
655*cdf0e10cSrcweir sal_Bool SAL_CALL OStatement::execute( const ::rtl::OUString& _sql ) throw(SQLException, RuntimeException)
656*cdf0e10cSrcweir {
657*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
658*cdf0e10cSrcweir 	checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir     Reference< XResultSet > xRS = impl_executeQuery_throw( _sql );
661*cdf0e10cSrcweir 	return xRS.is();
662*cdf0e10cSrcweir }
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir // -------------------------------------------------------------------------
665*cdf0e10cSrcweir Reference< XResultSet > SAL_CALL OStatement::executeQuery( const ::rtl::OUString& _sql ) throw(SQLException, RuntimeException)
666*cdf0e10cSrcweir {
667*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
668*cdf0e10cSrcweir 	checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
669*cdf0e10cSrcweir 
670*cdf0e10cSrcweir     return impl_executeQuery_throw( _sql );
671*cdf0e10cSrcweir }
672*cdf0e10cSrcweir 
673*cdf0e10cSrcweir // -----------------------------------------------------------------------------
674*cdf0e10cSrcweir sal_Int32 SAL_CALL OStatement::executeUpdate( const ::rtl::OUString& /*sql*/ ) throw(SQLException, RuntimeException)
675*cdf0e10cSrcweir {
676*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
677*cdf0e10cSrcweir 	checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
678*cdf0e10cSrcweir     ::dbtools::throwFeatureNotImplementedException( "XStatement::executeUpdate", *this );
679*cdf0e10cSrcweir 	return 0;
680*cdf0e10cSrcweir }
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir } } // namespace ::connectivity::evoab
683