1*9b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9b5730f6SAndrew Rist * distributed with this work for additional information 6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an 15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 17*9b5730f6SAndrew Rist * specific language governing permissions and limitations 18*9b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9b5730f6SAndrew Rist *************************************************************/ 21*9b5730f6SAndrew Rist 22*9b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "MacabStatement.hxx" 28cdf0e10cSrcweir #include "MacabConnection.hxx" 29cdf0e10cSrcweir #include "MacabAddressBook.hxx" 30cdf0e10cSrcweir #include "MacabDriver.hxx" 31cdf0e10cSrcweir #include "MacabResultSet.hxx" 32cdf0e10cSrcweir #include "MacabResultSetMetaData.hxx" 33cdf0e10cSrcweir #include "macabcondition.hxx" 34cdf0e10cSrcweir #include "macaborder.hxx" 35cdf0e10cSrcweir #include "TConnection.hxx" 36cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 37cdf0e10cSrcweir #include "resource/sharedresources.hxx" 38cdf0e10cSrcweir #include "resource/macab_res.hrc" 39cdf0e10cSrcweir 40cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 41cdf0e10cSrcweir # define OUtoCStr( x ) ( ::rtl::OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US).getStr()) 42cdf0e10cSrcweir #else /* OSL_DEBUG_LEVEL */ 43cdf0e10cSrcweir # define OUtoCStr( x ) ("dummy") 44cdf0e10cSrcweir #endif /* OSL_DEBUG_LEVEL */ 45cdf0e10cSrcweir 46cdf0e10cSrcweir using namespace connectivity::macab; 47cdf0e10cSrcweir using namespace com::sun::star::uno; 48cdf0e10cSrcweir using namespace com::sun::star::lang; 49cdf0e10cSrcweir using namespace com::sun::star::beans; 50cdf0e10cSrcweir using namespace com::sun::star::sdbc; 51cdf0e10cSrcweir using namespace com::sun::star::sdbcx; 52cdf0e10cSrcweir using namespace com::sun::star::container; 53cdf0e10cSrcweir using namespace com::sun::star::io; 54cdf0e10cSrcweir using namespace com::sun::star::util; 55cdf0e10cSrcweir 56cdf0e10cSrcweir namespace connectivity 57cdf0e10cSrcweir { 58cdf0e10cSrcweir namespace macab 59cdf0e10cSrcweir { 60cdf0e10cSrcweir void impl_throwError(sal_uInt16 _nErrorId) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir ::connectivity::SharedResources aResources; 63cdf0e10cSrcweir const ::rtl::OUString sError( aResources.getResourceString(_nErrorId) ); 64cdf0e10cSrcweir ::dbtools::throwGenericSQLException(sError,NULL); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir } 67cdf0e10cSrcweir } 68cdf0e10cSrcweir 69cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(MacabStatement, "com.sun.star.sdbc.drivers.MacabStatement", "com.sun.star.sdbc.Statement"); 70cdf0e10cSrcweir //------------------------------------------------------------------------------ 71cdf0e10cSrcweir MacabCommonStatement::MacabCommonStatement(MacabConnection* _pConnection ) 72cdf0e10cSrcweir : MacabCommonStatement_BASE(m_aMutex), 73cdf0e10cSrcweir OPropertySetHelper(MacabCommonStatement_BASE::rBHelper), 74cdf0e10cSrcweir m_aParser(_pConnection->getDriver()->getMSFactory()), 75cdf0e10cSrcweir m_aSQLIterator(_pConnection, _pConnection->createCatalog()->getTables(), m_aParser, NULL ), 76cdf0e10cSrcweir m_pParseTree(NULL), 77cdf0e10cSrcweir m_pConnection(_pConnection), 78cdf0e10cSrcweir rBHelper(MacabCommonStatement_BASE::rBHelper) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir m_pConnection->acquire(); 81cdf0e10cSrcweir } 82cdf0e10cSrcweir // ----------------------------------------------------------------------------- 83cdf0e10cSrcweir MacabCommonStatement::~MacabCommonStatement() 84cdf0e10cSrcweir { 85cdf0e10cSrcweir } 86cdf0e10cSrcweir // ----------------------------------------------------------------------------- 87cdf0e10cSrcweir void MacabCommonStatement::disposing() 88cdf0e10cSrcweir { 89cdf0e10cSrcweir MacabCommonStatement_BASE::disposing(); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir // ----------------------------------------------------------------------------- 92cdf0e10cSrcweir void MacabCommonStatement::resetParameters() const throw(::com::sun::star::sdbc::SQLException) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir impl_throwError(STR_PARA_ONLY_PREPARED); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir // ----------------------------------------------------------------------------- 97cdf0e10cSrcweir void MacabCommonStatement::getNextParameter(::rtl::OUString &) const throw(::com::sun::star::sdbc::SQLException) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir impl_throwError(STR_PARA_ONLY_PREPARED); 100cdf0e10cSrcweir } 101cdf0e10cSrcweir // ----------------------------------------------------------------------------- 102cdf0e10cSrcweir MacabCondition *MacabCommonStatement::analyseWhereClause(const OSQLParseNode *pParseNode) const throw(SQLException) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir if (pParseNode->count() == 3) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir const OSQLParseNode *pLeft = pParseNode->getChild(0), 107cdf0e10cSrcweir *pMiddle = pParseNode->getChild(1), 108cdf0e10cSrcweir *pRight = pParseNode->getChild(2); 109cdf0e10cSrcweir 110cdf0e10cSrcweir // WHERE ( ... ) ? 111cdf0e10cSrcweir if (SQL_ISPUNCTUATION(pLeft, "(") && SQL_ISPUNCTUATION(pRight, ")")) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir return analyseWhereClause(pMiddle); 114cdf0e10cSrcweir } 115cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, comparison_predicate)) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir if (pLeft->isToken() && pRight->isToken()) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir switch (pMiddle->getNodeType()) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir case SQL_NODE_EQUAL: 122cdf0e10cSrcweir // WHERE 0 = 1 123cdf0e10cSrcweir return new MacabConditionConstant(pLeft->getTokenValue() == pRight->getTokenValue()); 124cdf0e10cSrcweir 125cdf0e10cSrcweir case SQL_NODE_NOTEQUAL: 126cdf0e10cSrcweir // WHERE 0 <> 1 127cdf0e10cSrcweir // (might not be correct SQL... don't care, handling anyway) 128cdf0e10cSrcweir return new MacabConditionConstant(pLeft->getTokenValue() != pRight->getTokenValue()); 129cdf0e10cSrcweir 130cdf0e10cSrcweir default: 131cdf0e10cSrcweir break; 132cdf0e10cSrcweir } 133cdf0e10cSrcweir } 134cdf0e10cSrcweir else if (SQL_ISRULE(pLeft, column_ref)) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir ::rtl::OUString sColumnName, 137cdf0e10cSrcweir sTableRange; 138cdf0e10cSrcweir 139cdf0e10cSrcweir m_aSQLIterator.getColumnRange(pLeft, sColumnName, sTableRange); 140cdf0e10cSrcweir 141cdf0e10cSrcweir if (pRight->isToken() || SQL_ISRULE(pRight, parameter)) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir ::rtl::OUString sMatchString; 144cdf0e10cSrcweir 145cdf0e10cSrcweir if (pRight->isToken()) // WHERE Name = 'Doe' 146cdf0e10cSrcweir sMatchString = pRight->getTokenValue(); 147cdf0e10cSrcweir else if (SQL_ISRULE(pRight, parameter)) // WHERE Name = ? 148cdf0e10cSrcweir getNextParameter(sMatchString); 149cdf0e10cSrcweir 150cdf0e10cSrcweir switch (pMiddle->getNodeType()) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir case SQL_NODE_EQUAL: 153cdf0e10cSrcweir // WHERE Name = 'Smith' 154cdf0e10cSrcweir return new MacabConditionEqual(m_pHeader, sColumnName, sMatchString); 155cdf0e10cSrcweir 156cdf0e10cSrcweir case SQL_NODE_NOTEQUAL: 157cdf0e10cSrcweir // WHERE Name <> 'Jones' 158cdf0e10cSrcweir return new MacabConditionDifferent(m_pHeader, sColumnName, sMatchString); 159cdf0e10cSrcweir 160cdf0e10cSrcweir default: 161cdf0e10cSrcweir break; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir } 164cdf0e10cSrcweir } 165cdf0e10cSrcweir } 166cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, search_condition)) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir if (SQL_ISTOKEN(pMiddle, OR)) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir // WHERE Name = 'Smith' OR Name = 'Jones' 171cdf0e10cSrcweir return new MacabConditionOr( 172cdf0e10cSrcweir analyseWhereClause(pLeft), 173cdf0e10cSrcweir analyseWhereClause(pRight)); 174cdf0e10cSrcweir } 175cdf0e10cSrcweir } 176cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, boolean_term)) 177cdf0e10cSrcweir { 178cdf0e10cSrcweir if (SQL_ISTOKEN(pMiddle, AND)) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir // WHERE Name = 'Smith' AND "Given Name" = 'Peter' 181cdf0e10cSrcweir return new MacabConditionAnd( 182cdf0e10cSrcweir analyseWhereClause(pLeft), 183cdf0e10cSrcweir analyseWhereClause(pRight)); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, test_for_null) || SQL_ISRULE(pParseNode, like_predicate)) 188cdf0e10cSrcweir { 189cdf0e10cSrcweir const OSQLParseNode *pLeft = pParseNode->getChild(0); 190cdf0e10cSrcweir const OSQLParseNode* pPart2 = pParseNode->getChild(1); 191cdf0e10cSrcweir const OSQLParseNode *pMiddleLeft = pPart2->getChild(0), 192cdf0e10cSrcweir *pMiddleRight = pPart2->getChild(1), 193cdf0e10cSrcweir *pRight = pPart2->getChild(2); 194cdf0e10cSrcweir 195cdf0e10cSrcweir if (SQL_ISRULE(pParseNode, test_for_null)) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir if (SQL_ISRULE(pLeft, column_ref) && 198cdf0e10cSrcweir SQL_ISTOKEN(pMiddleLeft, IS) && 199cdf0e10cSrcweir SQL_ISTOKEN(pRight, NULL)) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir ::rtl::OUString sColumnName, 202cdf0e10cSrcweir sTableRange; 203cdf0e10cSrcweir 204cdf0e10cSrcweir m_aSQLIterator.getColumnRange(pLeft, sColumnName, sTableRange); 205cdf0e10cSrcweir 206cdf0e10cSrcweir if (SQL_ISTOKEN(pMiddleRight, NOT)) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir // WHERE "Mobile Phone" IS NOT NULL 209cdf0e10cSrcweir return new MacabConditionNotNull(m_pHeader, sColumnName); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir else 212cdf0e10cSrcweir { 213cdf0e10cSrcweir // WHERE "Mobile Phone" IS NULL 214cdf0e10cSrcweir return new MacabConditionNull(m_pHeader, sColumnName); 215cdf0e10cSrcweir } 216cdf0e10cSrcweir } 217cdf0e10cSrcweir } 218cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, like_predicate)) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir if (SQL_ISRULE(pLeft, column_ref)) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir ::rtl::OUString sColumnName, 223cdf0e10cSrcweir sTableRange; 224cdf0e10cSrcweir 225cdf0e10cSrcweir m_aSQLIterator.getColumnRange(pLeft, sColumnName, sTableRange); 226cdf0e10cSrcweir 227cdf0e10cSrcweir if (pMiddleRight->isToken() || SQL_ISRULE(pMiddleRight, parameter)) 228cdf0e10cSrcweir { 229cdf0e10cSrcweir ::rtl::OUString sMatchString; 230cdf0e10cSrcweir 231cdf0e10cSrcweir if (pMiddleRight->isToken()) // WHERE Name LIKE 'Sm%' 232cdf0e10cSrcweir sMatchString = pMiddleRight->getTokenValue(); 233cdf0e10cSrcweir else if (SQL_ISRULE(pMiddleRight, parameter)) // WHERE Name LIKE ? 234cdf0e10cSrcweir getNextParameter(sMatchString); 235cdf0e10cSrcweir 236cdf0e10cSrcweir return new MacabConditionSimilar(m_pHeader, sColumnName, sMatchString); 237cdf0e10cSrcweir } 238cdf0e10cSrcweir } 239cdf0e10cSrcweir } 240cdf0e10cSrcweir } 241cdf0e10cSrcweir impl_throwError(STR_QUERY_TOO_COMPLEX); 242cdf0e10cSrcweir // Unreachable: 243cdf0e10cSrcweir OSL_ASSERT(false); 244cdf0e10cSrcweir return 0; 245cdf0e10cSrcweir } 246cdf0e10cSrcweir // ----------------------------------------------------------------------------- 247cdf0e10cSrcweir MacabOrder *MacabCommonStatement::analyseOrderByClause(const OSQLParseNode *pParseNode) const throw(SQLException) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir if (SQL_ISRULE(pParseNode, ordering_spec_commalist)) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir MacabComplexOrder *list = new MacabComplexOrder(); 252cdf0e10cSrcweir sal_uInt32 n = pParseNode->count(); 253cdf0e10cSrcweir 254cdf0e10cSrcweir // Iterate through the ordering columns 255cdf0e10cSrcweir for (sal_uInt32 i = 0; i < n; i++) 256cdf0e10cSrcweir { 257cdf0e10cSrcweir list->addOrder 258cdf0e10cSrcweir (analyseOrderByClause(pParseNode->getChild(i))); 259cdf0e10cSrcweir } 260cdf0e10cSrcweir 261cdf0e10cSrcweir return list; 262cdf0e10cSrcweir } 263cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, ordering_spec)) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir if (pParseNode->count() == 2) 266cdf0e10cSrcweir { 267cdf0e10cSrcweir OSQLParseNode* pColumnRef = pParseNode->getChild(0); 268cdf0e10cSrcweir OSQLParseNode* pAscendingDescending = pParseNode->getChild(1); 269cdf0e10cSrcweir 270cdf0e10cSrcweir if (SQL_ISRULE(pColumnRef, column_ref)) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir if (pColumnRef->count() == 3) 273cdf0e10cSrcweir pColumnRef = pColumnRef->getChild(2); 274cdf0e10cSrcweir 275cdf0e10cSrcweir if (pColumnRef->count() == 1) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir ::rtl::OUString sColumnName = 278cdf0e10cSrcweir pColumnRef->getChild(0)->getTokenValue(); 279cdf0e10cSrcweir sal_Bool bAscending = 280cdf0e10cSrcweir SQL_ISTOKEN(pAscendingDescending, DESC)? 281cdf0e10cSrcweir sal_False: 282cdf0e10cSrcweir sal_True; 283cdf0e10cSrcweir 284cdf0e10cSrcweir return new MacabSimpleOrder(m_pHeader, sColumnName, bAscending); 285cdf0e10cSrcweir } 286cdf0e10cSrcweir } 287cdf0e10cSrcweir } 288cdf0e10cSrcweir } 289cdf0e10cSrcweir impl_throwError(STR_QUERY_TOO_COMPLEX); 290cdf0e10cSrcweir // Unreachable: 291cdf0e10cSrcweir OSL_ASSERT(false); 292cdf0e10cSrcweir return 0; 293cdf0e10cSrcweir } 294cdf0e10cSrcweir //------------------------------------------------------------------------------ 295cdf0e10cSrcweir ::rtl::OUString MacabCommonStatement::getTableName() const 296cdf0e10cSrcweir { 297cdf0e10cSrcweir const OSQLTables& xTabs = m_aSQLIterator.getTables(); 298cdf0e10cSrcweir 299cdf0e10cSrcweir if( xTabs.empty() ) 300cdf0e10cSrcweir return ::rtl::OUString(); 301cdf0e10cSrcweir 302cdf0e10cSrcweir // can only deal with one table at a time 303cdf0e10cSrcweir if(xTabs.size() > 1 || m_aSQLIterator.hasErrors() ) 304cdf0e10cSrcweir return ::rtl::OUString(); 305cdf0e10cSrcweir 306cdf0e10cSrcweir return xTabs.begin()->first; 307cdf0e10cSrcweir } 308cdf0e10cSrcweir //------------------------------------------------------------------------------ 309cdf0e10cSrcweir void MacabCommonStatement::setMacabFields(MacabResultSet *pResult) const throw(SQLException) 310cdf0e10cSrcweir { 311cdf0e10cSrcweir ::vos::ORef<connectivity::OSQLColumns> xColumns; // selected columns 312cdf0e10cSrcweir MacabResultSetMetaData *pMeta; // meta information - holds the list of AddressBook fields 313cdf0e10cSrcweir 314cdf0e10cSrcweir xColumns = m_aSQLIterator.getSelectColumns(); 315cdf0e10cSrcweir if (!xColumns.isValid()) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir ::connectivity::SharedResources aResources; 318cdf0e10cSrcweir const ::rtl::OUString sError( aResources.getResourceString( 319cdf0e10cSrcweir STR_INVALID_COLUMN_SELECTION 320cdf0e10cSrcweir ) ); 321cdf0e10cSrcweir ::dbtools::throwGenericSQLException(sError,NULL); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir pMeta = static_cast<MacabResultSetMetaData *>(pResult->getMetaData().get()); 324cdf0e10cSrcweir pMeta->setMacabFields(xColumns); 325cdf0e10cSrcweir } 326cdf0e10cSrcweir // ------------------------------------------------------------------------- 327cdf0e10cSrcweir void MacabCommonStatement::selectRecords(MacabResultSet *pResult) const throw(SQLException) 328cdf0e10cSrcweir { 329cdf0e10cSrcweir const OSQLParseNode *pParseNode; 330cdf0e10cSrcweir MacabCondition *pCondition; 331cdf0e10cSrcweir 332cdf0e10cSrcweir pParseNode = m_aSQLIterator.getWhereTree(); 333cdf0e10cSrcweir if (pParseNode != NULL) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir if (SQL_ISRULE(pParseNode, where_clause)) 336cdf0e10cSrcweir { 337cdf0e10cSrcweir // Since we don't support parameters, don't reset them. If we ever 338cdf0e10cSrcweir // support them, uncomment this line and fix resetParameters. 339cdf0e10cSrcweir //resetParameters(); 340cdf0e10cSrcweir pParseNode = pParseNode->getChild(1); 341cdf0e10cSrcweir pCondition = analyseWhereClause(pParseNode); 342cdf0e10cSrcweir if (pCondition->isAlwaysTrue()) 343cdf0e10cSrcweir pResult->allMacabRecords(); 344cdf0e10cSrcweir else if (!pCondition->isAlwaysFalse()) 345cdf0e10cSrcweir pResult->someMacabRecords(pCondition); 346cdf0e10cSrcweir delete pCondition; 347cdf0e10cSrcweir return; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir } 350cdf0e10cSrcweir 351cdf0e10cSrcweir // no WHERE clause: get all rows 352cdf0e10cSrcweir pResult->allMacabRecords(); 353cdf0e10cSrcweir } 354cdf0e10cSrcweir // ------------------------------------------------------------------------- 355cdf0e10cSrcweir void MacabCommonStatement::sortRecords(MacabResultSet *pResult) const throw(SQLException) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir const OSQLParseNode *pParseNode; 358cdf0e10cSrcweir MacabOrder *pOrder; 359cdf0e10cSrcweir 360cdf0e10cSrcweir pParseNode = m_aSQLIterator.getOrderTree(); 361cdf0e10cSrcweir if (pParseNode != NULL) 362cdf0e10cSrcweir { 363cdf0e10cSrcweir if (SQL_ISRULE(pParseNode, opt_order_by_clause)) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir pParseNode = pParseNode->getChild(2); 366cdf0e10cSrcweir pOrder = analyseOrderByClause(pParseNode); 367cdf0e10cSrcweir pResult->sortMacabRecords(pOrder); 368cdf0e10cSrcweir delete pOrder; 369cdf0e10cSrcweir } 370cdf0e10cSrcweir } 371cdf0e10cSrcweir } 372cdf0e10cSrcweir //----------------------------------------------------------------------------- 373cdf0e10cSrcweir Any SAL_CALL MacabCommonStatement::queryInterface( const Type & rType ) throw(RuntimeException) 374cdf0e10cSrcweir { 375cdf0e10cSrcweir Any aRet = MacabCommonStatement_BASE::queryInterface(rType); 376cdf0e10cSrcweir if (!aRet.hasValue()) 377cdf0e10cSrcweir aRet = OPropertySetHelper::queryInterface(rType); 378cdf0e10cSrcweir return aRet; 379cdf0e10cSrcweir } 380cdf0e10cSrcweir // ------------------------------------------------------------------------- 381cdf0e10cSrcweir Sequence< Type > SAL_CALL MacabCommonStatement::getTypes( ) throw(RuntimeException) 382cdf0e10cSrcweir { 383cdf0e10cSrcweir ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< XMultiPropertySet > *)0 ), 384cdf0e10cSrcweir ::getCppuType( (const Reference< XFastPropertySet > *)0 ), 385cdf0e10cSrcweir ::getCppuType( (const Reference< XPropertySet > *)0 )); 386cdf0e10cSrcweir 387cdf0e10cSrcweir return comphelper::concatSequences(aTypes.getTypes(),MacabCommonStatement_BASE::getTypes()); 388cdf0e10cSrcweir } 389cdf0e10cSrcweir // ------------------------------------------------------------------------- 390cdf0e10cSrcweir void SAL_CALL MacabCommonStatement::cancel( ) throw(RuntimeException) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 393cdf0e10cSrcweir 394cdf0e10cSrcweir checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed); 395cdf0e10cSrcweir // cancel the current sql statement 396cdf0e10cSrcweir } 397cdf0e10cSrcweir // ------------------------------------------------------------------------- 398cdf0e10cSrcweir void SAL_CALL MacabCommonStatement::close( ) throw(SQLException, RuntimeException) 399cdf0e10cSrcweir { 400cdf0e10cSrcweir { 401cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 402cdf0e10cSrcweir checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed); 403cdf0e10cSrcweir 404cdf0e10cSrcweir } 405cdf0e10cSrcweir dispose(); 406cdf0e10cSrcweir } 407cdf0e10cSrcweir // ------------------------------------------------------------------------- 408cdf0e10cSrcweir sal_Bool SAL_CALL MacabCommonStatement::execute( 409cdf0e10cSrcweir const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 410cdf0e10cSrcweir { 411cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 412cdf0e10cSrcweir checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed); 413cdf0e10cSrcweir 414cdf0e10cSrcweir Reference< XResultSet > xRS = executeQuery(sql); 415cdf0e10cSrcweir 416cdf0e10cSrcweir return xRS.is(); 417cdf0e10cSrcweir } 418cdf0e10cSrcweir // ------------------------------------------------------------------------- 419cdf0e10cSrcweir Reference< XResultSet > SAL_CALL MacabCommonStatement::executeQuery( 420cdf0e10cSrcweir const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 421cdf0e10cSrcweir { 422cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 423cdf0e10cSrcweir checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed); 424cdf0e10cSrcweir 425cdf0e10cSrcweir OSL_TRACE("Mac OS Address book - SQL Request: %s", OUtoCStr(sql)); 426cdf0e10cSrcweir 427cdf0e10cSrcweir MacabResultSet* pResult = new MacabResultSet(this); 428cdf0e10cSrcweir Reference< XResultSet > xRS = pResult; 429cdf0e10cSrcweir ::rtl::OUString aErr; 430cdf0e10cSrcweir 431cdf0e10cSrcweir m_pParseTree = m_aParser.parseTree(aErr, sql); 432cdf0e10cSrcweir if (m_pParseTree == NULL) 433cdf0e10cSrcweir throw SQLException(aErr, *this, aErr, 0, Any()); 434cdf0e10cSrcweir 435cdf0e10cSrcweir m_aSQLIterator.setParseTree(m_pParseTree); 436cdf0e10cSrcweir m_aSQLIterator.traverseAll(); 437cdf0e10cSrcweir switch (m_aSQLIterator.getStatementType()) 438cdf0e10cSrcweir { 439cdf0e10cSrcweir case SQL_STATEMENT_SELECT: 440cdf0e10cSrcweir { 441cdf0e10cSrcweir ::rtl::OUString sTableName = getTableName(); // FROM which table ? 442cdf0e10cSrcweir if (sTableName.getLength() != 0) // a match 443cdf0e10cSrcweir { 444cdf0e10cSrcweir MacabRecords *aRecords; 445cdf0e10cSrcweir aRecords = m_pConnection->getAddressBook()->getMacabRecords(sTableName); 446cdf0e10cSrcweir 447cdf0e10cSrcweir // In case, somehow, we don't have anything with the name m_sTableName 448cdf0e10cSrcweir if(aRecords == NULL) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir impl_throwError(STR_NO_TABLE); 451cdf0e10cSrcweir } 452cdf0e10cSrcweir else 453cdf0e10cSrcweir { 454cdf0e10cSrcweir m_pHeader = aRecords->getHeader(); 455cdf0e10cSrcweir 456cdf0e10cSrcweir pResult->setTableName(sTableName); 457cdf0e10cSrcweir 458cdf0e10cSrcweir setMacabFields(pResult); // SELECT which columns ? 459cdf0e10cSrcweir selectRecords(pResult); // WHERE which condition ? 460cdf0e10cSrcweir sortRecords(pResult); // ORDER BY which columns ? 461cdf0e10cSrcweir } 462cdf0e10cSrcweir // To be continued: DISTINCT 463cdf0e10cSrcweir // etc... 464cdf0e10cSrcweir } 465cdf0e10cSrcweir } 466cdf0e10cSrcweir break; 467cdf0e10cSrcweir 468cdf0e10cSrcweir default: 469cdf0e10cSrcweir // To be continued: UPDATE 470cdf0e10cSrcweir // DELETE 471cdf0e10cSrcweir // etc... 472cdf0e10cSrcweir impl_throwError(STR_QUERY_TOO_COMPLEX); 473cdf0e10cSrcweir } 474cdf0e10cSrcweir 475cdf0e10cSrcweir m_xResultSet = Reference<XResultSet>(pResult); 476cdf0e10cSrcweir return xRS; 477cdf0e10cSrcweir } 478cdf0e10cSrcweir // ------------------------------------------------------------------------- 479cdf0e10cSrcweir Reference< XConnection > SAL_CALL MacabCommonStatement::getConnection( ) throw(SQLException, RuntimeException) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 482cdf0e10cSrcweir checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed); 483cdf0e10cSrcweir 484cdf0e10cSrcweir // just return our connection here 485cdf0e10cSrcweir return (Reference< XConnection >) m_pConnection; 486cdf0e10cSrcweir } 487cdf0e10cSrcweir // ------------------------------------------------------------------------- 488cdf0e10cSrcweir sal_Int32 SAL_CALL MacabCommonStatement::executeUpdate( const ::rtl::OUString& ) throw(SQLException, RuntimeException) 489cdf0e10cSrcweir { 490cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 491cdf0e10cSrcweir checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed); 492cdf0e10cSrcweir 493cdf0e10cSrcweir // the return values gives information about how many rows are affected by executing the sql statement 494cdf0e10cSrcweir return 0; 495cdf0e10cSrcweir } 496cdf0e10cSrcweir // ------------------------------------------------------------------------- 497cdf0e10cSrcweir Any SAL_CALL MacabCommonStatement::getWarnings( ) throw(SQLException, RuntimeException) 498cdf0e10cSrcweir { 499cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 500cdf0e10cSrcweir checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed); 501cdf0e10cSrcweir 502cdf0e10cSrcweir return makeAny(m_aLastWarning); 503cdf0e10cSrcweir } 504cdf0e10cSrcweir // ------------------------------------------------------------------------- 505cdf0e10cSrcweir void SAL_CALL MacabCommonStatement::clearWarnings( ) throw(SQLException, RuntimeException) 506cdf0e10cSrcweir { 507cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 508cdf0e10cSrcweir checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed); 509cdf0e10cSrcweir 510cdf0e10cSrcweir m_aLastWarning = SQLWarning(); 511cdf0e10cSrcweir } 512cdf0e10cSrcweir // ------------------------------------------------------------------------- 513cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* MacabCommonStatement::createArrayHelper( ) const 514cdf0e10cSrcweir { 515cdf0e10cSrcweir // this properties are defined by the service statement 516cdf0e10cSrcweir // they must be in alphabetic order 517cdf0e10cSrcweir Sequence< Property > aProps(10); 518cdf0e10cSrcweir Property* pProperties = aProps.getArray(); 519cdf0e10cSrcweir sal_Int32 nPos = 0; 520cdf0e10cSrcweir DECL_PROP0(CURSORNAME, ::rtl::OUString); 521cdf0e10cSrcweir DECL_BOOL_PROP0(ESCAPEPROCESSING); 522cdf0e10cSrcweir DECL_PROP0(FETCHDIRECTION,sal_Int32); 523cdf0e10cSrcweir DECL_PROP0(FETCHSIZE, sal_Int32); 524cdf0e10cSrcweir DECL_PROP0(MAXFIELDSIZE,sal_Int32); 525cdf0e10cSrcweir DECL_PROP0(MAXROWS, sal_Int32); 526cdf0e10cSrcweir DECL_PROP0(QUERYTIMEOUT,sal_Int32); 527cdf0e10cSrcweir DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32); 528cdf0e10cSrcweir DECL_PROP0(RESULTSETTYPE,sal_Int32); 529cdf0e10cSrcweir DECL_BOOL_PROP0(USEBOOKMARKS); 530cdf0e10cSrcweir 531cdf0e10cSrcweir return new ::cppu::OPropertyArrayHelper(aProps); 532cdf0e10cSrcweir } 533cdf0e10cSrcweir // ------------------------------------------------------------------------- 534cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & MacabCommonStatement::getInfoHelper() 535cdf0e10cSrcweir { 536cdf0e10cSrcweir return *const_cast<MacabCommonStatement*>(this)->getArrayHelper(); 537cdf0e10cSrcweir } 538cdf0e10cSrcweir // ------------------------------------------------------------------------- 539cdf0e10cSrcweir sal_Bool MacabCommonStatement::convertFastPropertyValue( 540cdf0e10cSrcweir Any &, 541cdf0e10cSrcweir Any &, 542cdf0e10cSrcweir sal_Int32, 543cdf0e10cSrcweir const Any&) throw (::com::sun::star::lang::IllegalArgumentException) 544cdf0e10cSrcweir { 545cdf0e10cSrcweir sal_Bool bConverted = sal_False; 546cdf0e10cSrcweir // here we have to try to convert 547cdf0e10cSrcweir return bConverted; 548cdf0e10cSrcweir } 549cdf0e10cSrcweir // ------------------------------------------------------------------------- 550cdf0e10cSrcweir void MacabCommonStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any&) throw (Exception) 551cdf0e10cSrcweir { 552cdf0e10cSrcweir // set the value to whatever is nescessary 553cdf0e10cSrcweir switch (nHandle) 554cdf0e10cSrcweir { 555cdf0e10cSrcweir case PROPERTY_ID_QUERYTIMEOUT: 556cdf0e10cSrcweir case PROPERTY_ID_MAXFIELDSIZE: 557cdf0e10cSrcweir case PROPERTY_ID_MAXROWS: 558cdf0e10cSrcweir case PROPERTY_ID_CURSORNAME: 559cdf0e10cSrcweir case PROPERTY_ID_RESULTSETCONCURRENCY: 560cdf0e10cSrcweir case PROPERTY_ID_RESULTSETTYPE: 561cdf0e10cSrcweir case PROPERTY_ID_FETCHDIRECTION: 562cdf0e10cSrcweir case PROPERTY_ID_FETCHSIZE: 563cdf0e10cSrcweir case PROPERTY_ID_ESCAPEPROCESSING: 564cdf0e10cSrcweir case PROPERTY_ID_USEBOOKMARKS: 565cdf0e10cSrcweir default: 566cdf0e10cSrcweir ; 567cdf0e10cSrcweir } 568cdf0e10cSrcweir } 569cdf0e10cSrcweir // ------------------------------------------------------------------------- 570cdf0e10cSrcweir void MacabCommonStatement::getFastPropertyValue(Any&,sal_Int32 nHandle) const 571cdf0e10cSrcweir { 572cdf0e10cSrcweir switch (nHandle) 573cdf0e10cSrcweir { 574cdf0e10cSrcweir case PROPERTY_ID_QUERYTIMEOUT: 575cdf0e10cSrcweir case PROPERTY_ID_MAXFIELDSIZE: 576cdf0e10cSrcweir case PROPERTY_ID_MAXROWS: 577cdf0e10cSrcweir case PROPERTY_ID_CURSORNAME: 578cdf0e10cSrcweir case PROPERTY_ID_RESULTSETCONCURRENCY: 579cdf0e10cSrcweir case PROPERTY_ID_RESULTSETTYPE: 580cdf0e10cSrcweir case PROPERTY_ID_FETCHDIRECTION: 581cdf0e10cSrcweir case PROPERTY_ID_FETCHSIZE: 582cdf0e10cSrcweir case PROPERTY_ID_ESCAPEPROCESSING: 583cdf0e10cSrcweir case PROPERTY_ID_USEBOOKMARKS: 584cdf0e10cSrcweir default: 585cdf0e10cSrcweir ; 586cdf0e10cSrcweir } 587cdf0e10cSrcweir } 588cdf0e10cSrcweir // ----------------------------------------------------------------------------- 589cdf0e10cSrcweir void SAL_CALL MacabCommonStatement::acquire() throw() 590cdf0e10cSrcweir { 591cdf0e10cSrcweir MacabCommonStatement_BASE::acquire(); 592cdf0e10cSrcweir } 593cdf0e10cSrcweir // ----------------------------------------------------------------------------- 594cdf0e10cSrcweir void SAL_CALL MacabCommonStatement::release() throw() 595cdf0e10cSrcweir { 596cdf0e10cSrcweir MacabCommonStatement_BASE::release(); 597cdf0e10cSrcweir } 598cdf0e10cSrcweir // ----------------------------------------------------------------------------- 599cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL MacabCommonStatement::getPropertySetInfo( ) throw(RuntimeException) 600cdf0e10cSrcweir { 601cdf0e10cSrcweir return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); 602cdf0e10cSrcweir } 603cdf0e10cSrcweir // ----------------------------------------------------------------------------- 604cdf0e10cSrcweir MacabStatement::MacabStatement(MacabConnection* _pConnection) 605cdf0e10cSrcweir : MacabStatement_BASE(_pConnection) 606cdf0e10cSrcweir { 607cdf0e10cSrcweir } 608