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