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 "KStatement.hxx" 32*cdf0e10cSrcweir #include "KConnection.hxx" 33*cdf0e10cSrcweir #include "KDriver.hxx" 34*cdf0e10cSrcweir #include "KResultSet.hxx" 35*cdf0e10cSrcweir #include "KResultSetMetaData.hxx" 36*cdf0e10cSrcweir #include "kcondition.hxx" 37*cdf0e10cSrcweir #include "korder.hxx" 38*cdf0e10cSrcweir #include "TConnection.hxx" 39*cdf0e10cSrcweir #include <connectivity/dbexception.hxx> 40*cdf0e10cSrcweir #include "resource/kab_res.hrc" 41*cdf0e10cSrcweir #include "resource/sharedresources.hxx" 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 45*cdf0e10cSrcweir # define OUtoCStr( x ) ( ::rtl::OUStringToOString ( (x), RTL_TEXTENCODING_ASCII_US).getStr()) 46*cdf0e10cSrcweir #else /* OSL_DEBUG_LEVEL */ 47*cdf0e10cSrcweir # define OUtoCStr( x ) ("dummy") 48*cdf0e10cSrcweir #endif /* OSL_DEBUG_LEVEL */ 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using namespace connectivity::kab; 51*cdf0e10cSrcweir using namespace com::sun::star::uno; 52*cdf0e10cSrcweir using namespace com::sun::star::lang; 53*cdf0e10cSrcweir using namespace com::sun::star::beans; 54*cdf0e10cSrcweir using namespace com::sun::star::sdbc; 55*cdf0e10cSrcweir using namespace com::sun::star::sdbcx; 56*cdf0e10cSrcweir using namespace com::sun::star::container; 57*cdf0e10cSrcweir using namespace com::sun::star::io; 58*cdf0e10cSrcweir using namespace com::sun::star::util; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir namespace 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir void lcl_throwError(sal_uInt16 _nErrorId) 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir ::connectivity::SharedResources aResources; 65*cdf0e10cSrcweir const ::rtl::OUString sError( aResources.getResourceString(_nErrorId) ); 66*cdf0e10cSrcweir ::dbtools::throwGenericSQLException(sError,NULL); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir IMPLEMENT_SERVICE_INFO(KabStatement, "com.sun.star.sdbc.drivers.KabStatement", "com.sun.star.sdbc.Statement"); 71*cdf0e10cSrcweir //------------------------------------------------------------------------------ 72*cdf0e10cSrcweir KabCommonStatement::KabCommonStatement(KabConnection* _pConnection ) 73*cdf0e10cSrcweir : KabCommonStatement_BASE(m_aMutex), 74*cdf0e10cSrcweir OPropertySetHelper(KabCommonStatement_BASE::rBHelper), 75*cdf0e10cSrcweir m_aParser(_pConnection->getDriver()->getMSFactory()), 76*cdf0e10cSrcweir m_aSQLIterator(_pConnection, _pConnection->createCatalog()->getTables(), m_aParser, NULL ), 77*cdf0e10cSrcweir m_pParseTree(NULL), 78*cdf0e10cSrcweir m_pConnection(_pConnection), 79*cdf0e10cSrcweir rBHelper(KabCommonStatement_BASE::rBHelper) 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir m_pConnection->acquire(); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 84*cdf0e10cSrcweir KabCommonStatement::~KabCommonStatement() 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 88*cdf0e10cSrcweir void KabCommonStatement::disposing() 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir KabCommonStatement_BASE::disposing(); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 93*cdf0e10cSrcweir void KabCommonStatement::resetParameters() const throw(::com::sun::star::sdbc::SQLException) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir lcl_throwError(STR_PARA_ONLY_PREPARED); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 98*cdf0e10cSrcweir void KabCommonStatement::getNextParameter(::rtl::OUString &) const throw(::com::sun::star::sdbc::SQLException) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir lcl_throwError(STR_PARA_ONLY_PREPARED); 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 103*cdf0e10cSrcweir KabCondition *KabCommonStatement::analyseWhereClause(const OSQLParseNode *pParseNode) const throw(SQLException) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir if (pParseNode->count() == 3) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir const OSQLParseNode *pLeft = pParseNode->getChild(0), 108*cdf0e10cSrcweir *pMiddle = pParseNode->getChild(1), 109*cdf0e10cSrcweir *pRight = pParseNode->getChild(2); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // WHERE ( ... ) ? 112*cdf0e10cSrcweir if (SQL_ISPUNCTUATION(pLeft, "(") && SQL_ISPUNCTUATION(pRight, ")")) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir return analyseWhereClause(pMiddle); 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, comparison_predicate)) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir if (pLeft->isToken() && pRight->isToken()) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir switch (pMiddle->getNodeType()) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir case SQL_NODE_EQUAL: 123*cdf0e10cSrcweir // WHERE 0 = 1 124*cdf0e10cSrcweir return new KabConditionConstant(pLeft->getTokenValue() == pRight->getTokenValue()); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir case SQL_NODE_NOTEQUAL: 127*cdf0e10cSrcweir // WHERE 0 <> 1 128*cdf0e10cSrcweir // (might not be correct SQL... don't care, handling anyway) 129*cdf0e10cSrcweir return new KabConditionConstant(pLeft->getTokenValue() != pRight->getTokenValue()); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir default: 132*cdf0e10cSrcweir break; 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir else if (SQL_ISRULE(pLeft, column_ref)) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir ::rtl::OUString sColumnName, 138*cdf0e10cSrcweir sTableRange; 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir m_aSQLIterator.getColumnRange(pLeft, sColumnName, sTableRange); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir if (pRight->isToken() || SQL_ISRULE(pRight, parameter)) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir ::rtl::OUString sMatchString; 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir if (pRight->isToken()) // WHERE Name = 'Doe' 147*cdf0e10cSrcweir sMatchString = pRight->getTokenValue(); 148*cdf0e10cSrcweir else if (SQL_ISRULE(pRight, parameter)) // WHERE Name = ? 149*cdf0e10cSrcweir getNextParameter(sMatchString); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir switch (pMiddle->getNodeType()) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir case SQL_NODE_EQUAL: 154*cdf0e10cSrcweir // WHERE Name = 'Smith' 155*cdf0e10cSrcweir return new KabConditionEqual(sColumnName, sMatchString); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir case SQL_NODE_NOTEQUAL: 158*cdf0e10cSrcweir // WHERE Name <> 'Jones' 159*cdf0e10cSrcweir return new KabConditionDifferent(sColumnName, sMatchString); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir default: 162*cdf0e10cSrcweir break; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, search_condition)) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir if (SQL_ISTOKEN(pMiddle, OR)) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir // WHERE Name = 'Smith' OR Name = 'Jones' 172*cdf0e10cSrcweir return new KabConditionOr( 173*cdf0e10cSrcweir analyseWhereClause(pLeft), 174*cdf0e10cSrcweir analyseWhereClause(pRight)); 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, boolean_term)) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir if (SQL_ISTOKEN(pMiddle, AND)) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir // WHERE Name = 'Smith' AND "Given Name" = 'Peter' 182*cdf0e10cSrcweir return new KabConditionAnd( 183*cdf0e10cSrcweir analyseWhereClause(pLeft), 184*cdf0e10cSrcweir analyseWhereClause(pRight)); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, test_for_null) || SQL_ISRULE(pParseNode, like_predicate)) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir const OSQLParseNode *pLeft = pParseNode->getChild(0); 191*cdf0e10cSrcweir const OSQLParseNode* pPart2 = pParseNode->getChild(1); 192*cdf0e10cSrcweir const OSQLParseNode *pMiddleLeft = pPart2->getChild(0), 193*cdf0e10cSrcweir *pMiddleRight = pPart2->getChild(1), 194*cdf0e10cSrcweir *pRight = pPart2->getChild(2); 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir if (SQL_ISRULE(pParseNode, test_for_null)) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir if (SQL_ISRULE(pLeft, column_ref) && 199*cdf0e10cSrcweir SQL_ISTOKEN(pMiddleLeft, IS) && 200*cdf0e10cSrcweir SQL_ISTOKEN(pRight, NULL)) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir ::rtl::OUString sColumnName, 203*cdf0e10cSrcweir sTableRange; 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir m_aSQLIterator.getColumnRange(pLeft, sColumnName, sTableRange); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir if (SQL_ISTOKEN(pMiddleRight, NOT)) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir // WHERE "Mobile Phone" IS NOT NULL 210*cdf0e10cSrcweir return new KabConditionNotNull(sColumnName); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir else 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir // WHERE "Mobile Phone" IS NULL 215*cdf0e10cSrcweir return new KabConditionNull(sColumnName); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, like_predicate)) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir if (SQL_ISRULE(pLeft, column_ref)) 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir ::rtl::OUString sColumnName, 224*cdf0e10cSrcweir sTableRange; 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir m_aSQLIterator.getColumnRange(pLeft, sColumnName, sTableRange); 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir if (pMiddleRight->isToken() || SQL_ISRULE(pMiddleRight, parameter)) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir ::rtl::OUString sMatchString; 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir if (pMiddleRight->isToken()) // WHERE Name LIKE 'Sm%' 233*cdf0e10cSrcweir sMatchString = pMiddleRight->getTokenValue(); 234*cdf0e10cSrcweir else if (SQL_ISRULE(pMiddleRight, parameter)) // WHERE Name LIKE ? 235*cdf0e10cSrcweir getNextParameter(sMatchString); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir return new KabConditionSimilar(sColumnName, sMatchString); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir lcl_throwError(STR_QUERY_TOO_COMPLEX); 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir // Unreachable: 246*cdf0e10cSrcweir OSL_ASSERT(false); 247*cdf0e10cSrcweir return 0; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 250*cdf0e10cSrcweir KabOrder *KabCommonStatement::analyseOrderByClause(const OSQLParseNode *pParseNode) const throw(SQLException) 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir if (SQL_ISRULE(pParseNode, ordering_spec_commalist)) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir KabComplexOrder *list = new KabComplexOrder(); 255*cdf0e10cSrcweir sal_uInt32 n = pParseNode->count(); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir // Iterate through the ordering columns 258*cdf0e10cSrcweir for (sal_uInt32 i = 0; i < n; i++) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir list->addOrder 261*cdf0e10cSrcweir (analyseOrderByClause(pParseNode->getChild(i))); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir return list; 265*cdf0e10cSrcweir } 266*cdf0e10cSrcweir else if (SQL_ISRULE(pParseNode, ordering_spec)) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir if (pParseNode->count() == 2) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir OSQLParseNode* pColumnRef = pParseNode->getChild(0); 271*cdf0e10cSrcweir OSQLParseNode* pAscendingDescending = pParseNode->getChild(1); 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir if (SQL_ISRULE(pColumnRef, column_ref)) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir if (pColumnRef->count() == 3) 276*cdf0e10cSrcweir pColumnRef = pColumnRef->getChild(2); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir if (pColumnRef->count() == 1) 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir ::rtl::OUString sColumnName = 281*cdf0e10cSrcweir pColumnRef->getChild(0)->getTokenValue(); 282*cdf0e10cSrcweir sal_Bool bAscending = 283*cdf0e10cSrcweir SQL_ISTOKEN(pAscendingDescending, DESC)? 284*cdf0e10cSrcweir sal_False: 285*cdf0e10cSrcweir sal_True; 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir return new KabSimpleOrder(sColumnName, bAscending); 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir } 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir lcl_throwError(STR_QUERY_TOO_COMPLEX); 293*cdf0e10cSrcweir // Unreachable: 294*cdf0e10cSrcweir OSL_ASSERT(false); 295*cdf0e10cSrcweir return 0; 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir //------------------------------------------------------------------------------ 298*cdf0e10cSrcweir sal_Bool KabCommonStatement::isTableKnown(KabResultSet *pResult) const 299*cdf0e10cSrcweir { 300*cdf0e10cSrcweir // can handle requests like SELECT * FROM addresses addresses 301*cdf0e10cSrcweir // but cannot handle requests like SELECT * FROM addresses persons 302*cdf0e10cSrcweir if (m_aSQLIterator.getTables().size() != 1) 303*cdf0e10cSrcweir return sal_False; 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir if (m_aSQLIterator.getTables().begin()->first != pResult->getMetaData()->getTableName(0)) 306*cdf0e10cSrcweir return sal_False; 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir return sal_True; 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir //------------------------------------------------------------------------------ 311*cdf0e10cSrcweir void KabCommonStatement::setKabFields(KabResultSet *pResult) const throw(SQLException) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir ::vos::ORef<connectivity::OSQLColumns> xColumns; // selected columns 314*cdf0e10cSrcweir KabResultSetMetaData *pMeta; // meta information - holds the list of KAddressBook fields 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir xColumns = m_aSQLIterator.getSelectColumns(); 317*cdf0e10cSrcweir if (!xColumns.isValid()) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir lcl_throwError(STR_INVALID_COLUMN_SELECTION); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir pMeta = static_cast<KabResultSetMetaData *>(pResult->getMetaData().get()); 322*cdf0e10cSrcweir pMeta->setKabFields(xColumns); 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir // ------------------------------------------------------------------------- 325*cdf0e10cSrcweir void KabCommonStatement::selectAddressees(KabResultSet *pResult) const throw(SQLException) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir const OSQLParseNode *pParseNode; 328*cdf0e10cSrcweir KabCondition *pCondition; 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir pParseNode = m_aSQLIterator.getWhereTree(); 331*cdf0e10cSrcweir if (pParseNode != NULL) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir if (SQL_ISRULE(pParseNode, where_clause)) 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir resetParameters(); 336*cdf0e10cSrcweir pParseNode = pParseNode->getChild(1); 337*cdf0e10cSrcweir pCondition = analyseWhereClause(pParseNode); 338*cdf0e10cSrcweir if (pCondition->isAlwaysTrue()) 339*cdf0e10cSrcweir pResult->allKabAddressees(); 340*cdf0e10cSrcweir else if (!pCondition->isAlwaysFalse()) 341*cdf0e10cSrcweir pResult->someKabAddressees(pCondition); 342*cdf0e10cSrcweir delete pCondition; 343*cdf0e10cSrcweir return; 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir // no WHERE clause: get all rows 348*cdf0e10cSrcweir pResult->allKabAddressees(); 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir // ------------------------------------------------------------------------- 351*cdf0e10cSrcweir void KabCommonStatement::sortAddressees(KabResultSet *pResult) const throw(SQLException) 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir const OSQLParseNode *pParseNode; 354*cdf0e10cSrcweir KabOrder *pOrder; 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir pParseNode = m_aSQLIterator.getOrderTree(); 357*cdf0e10cSrcweir if (pParseNode != NULL) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir if (SQL_ISRULE(pParseNode, opt_order_by_clause)) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir pParseNode = pParseNode->getChild(2); 362*cdf0e10cSrcweir pOrder = analyseOrderByClause(pParseNode); 363*cdf0e10cSrcweir pResult->sortKabAddressees(pOrder); 364*cdf0e10cSrcweir delete pOrder; 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir //----------------------------------------------------------------------------- 369*cdf0e10cSrcweir Any SAL_CALL KabCommonStatement::queryInterface( const Type & rType ) throw(RuntimeException) 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir Any aRet = KabCommonStatement_BASE::queryInterface(rType); 372*cdf0e10cSrcweir if (!aRet.hasValue()) 373*cdf0e10cSrcweir aRet = OPropertySetHelper::queryInterface(rType); 374*cdf0e10cSrcweir return aRet; 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir // ------------------------------------------------------------------------- 377*cdf0e10cSrcweir Sequence< Type > SAL_CALL KabCommonStatement::getTypes( ) throw(RuntimeException) 378*cdf0e10cSrcweir { 379*cdf0e10cSrcweir ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< XMultiPropertySet > *)0 ), 380*cdf0e10cSrcweir ::getCppuType( (const Reference< XFastPropertySet > *)0 ), 381*cdf0e10cSrcweir ::getCppuType( (const Reference< XPropertySet > *)0 )); 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir return comphelper::concatSequences(aTypes.getTypes(),KabCommonStatement_BASE::getTypes()); 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir // ------------------------------------------------------------------------- 386*cdf0e10cSrcweir void SAL_CALL KabCommonStatement::cancel( ) throw(RuntimeException) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 391*cdf0e10cSrcweir // cancel the current sql statement 392*cdf0e10cSrcweir } 393*cdf0e10cSrcweir // ------------------------------------------------------------------------- 394*cdf0e10cSrcweir void SAL_CALL KabCommonStatement::close( ) throw(SQLException, RuntimeException) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 398*cdf0e10cSrcweir checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir dispose(); 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir // ------------------------------------------------------------------------- 404*cdf0e10cSrcweir sal_Bool SAL_CALL KabCommonStatement::execute( 405*cdf0e10cSrcweir const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 408*cdf0e10cSrcweir checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir Reference< XResultSet > xRS = executeQuery(sql); 411*cdf0e10cSrcweir 412*cdf0e10cSrcweir return xRS.is(); 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir // ------------------------------------------------------------------------- 415*cdf0e10cSrcweir Reference< XResultSet > SAL_CALL KabCommonStatement::executeQuery( 416*cdf0e10cSrcweir const ::rtl::OUString& sql ) throw(SQLException, RuntimeException) 417*cdf0e10cSrcweir { 418*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 419*cdf0e10cSrcweir checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir OSL_TRACE("KDE Address book - SQL Request: %s", OUtoCStr(sql)); 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir KabResultSet* pResult = new KabResultSet(this); 424*cdf0e10cSrcweir Reference< XResultSet > xRS = pResult; 425*cdf0e10cSrcweir ::rtl::OUString aErr; 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir m_pParseTree = m_aParser.parseTree(aErr, sql); 428*cdf0e10cSrcweir if (m_pParseTree == NULL) 429*cdf0e10cSrcweir throw SQLException(aErr, *this, aErr, 0, Any()); 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir m_aSQLIterator.setParseTree(m_pParseTree); 432*cdf0e10cSrcweir m_aSQLIterator.traverseAll(); 433*cdf0e10cSrcweir switch (m_aSQLIterator.getStatementType()) 434*cdf0e10cSrcweir { 435*cdf0e10cSrcweir case SQL_STATEMENT_SELECT: 436*cdf0e10cSrcweir if (isTableKnown(pResult)) // FROM which table ? 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir setKabFields(pResult); // SELECT which columns ? 439*cdf0e10cSrcweir selectAddressees(pResult); // WHERE which condition ? 440*cdf0e10cSrcweir sortAddressees(pResult); // ORDER BY which columns ? 441*cdf0e10cSrcweir // To be continued: DISTINCT 442*cdf0e10cSrcweir // etc... 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir break; 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir default: 447*cdf0e10cSrcweir // To be continued: UPDATE 448*cdf0e10cSrcweir // DELETE 449*cdf0e10cSrcweir // etc... 450*cdf0e10cSrcweir lcl_throwError(STR_QUERY_TOO_COMPLEX); 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir return xRS; 454*cdf0e10cSrcweir } 455*cdf0e10cSrcweir // ------------------------------------------------------------------------- 456*cdf0e10cSrcweir Reference< XConnection > SAL_CALL KabCommonStatement::getConnection( ) throw(SQLException, RuntimeException) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 459*cdf0e10cSrcweir checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 460*cdf0e10cSrcweir 461*cdf0e10cSrcweir // just return our connection here 462*cdf0e10cSrcweir return (Reference< XConnection >) m_pConnection; 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir // ------------------------------------------------------------------------- 465*cdf0e10cSrcweir sal_Int32 SAL_CALL KabCommonStatement::executeUpdate( const ::rtl::OUString& ) throw(SQLException, RuntimeException) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 468*cdf0e10cSrcweir checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir // the return values gives information about how many rows are affected by executing the sql statement 471*cdf0e10cSrcweir return 0; 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir // ------------------------------------------------------------------------- 474*cdf0e10cSrcweir Any SAL_CALL KabCommonStatement::getWarnings( ) throw(SQLException, RuntimeException) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 477*cdf0e10cSrcweir checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir return makeAny(m_aLastWarning); 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir // ------------------------------------------------------------------------- 482*cdf0e10cSrcweir void SAL_CALL KabCommonStatement::clearWarnings( ) throw(SQLException, RuntimeException) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 485*cdf0e10cSrcweir checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 486*cdf0e10cSrcweir 487*cdf0e10cSrcweir m_aLastWarning = SQLWarning(); 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir // ------------------------------------------------------------------------- 490*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* KabCommonStatement::createArrayHelper( ) const 491*cdf0e10cSrcweir { 492*cdf0e10cSrcweir // this properties are defined by the service statement 493*cdf0e10cSrcweir // they must be in alphabetic order 494*cdf0e10cSrcweir Sequence< Property > aProps(10); 495*cdf0e10cSrcweir Property* pProperties = aProps.getArray(); 496*cdf0e10cSrcweir sal_Int32 nPos = 0; 497*cdf0e10cSrcweir DECL_PROP0(CURSORNAME, ::rtl::OUString); 498*cdf0e10cSrcweir DECL_BOOL_PROP0(ESCAPEPROCESSING); 499*cdf0e10cSrcweir DECL_PROP0(FETCHDIRECTION,sal_Int32); 500*cdf0e10cSrcweir DECL_PROP0(FETCHSIZE, sal_Int32); 501*cdf0e10cSrcweir DECL_PROP0(MAXFIELDSIZE,sal_Int32); 502*cdf0e10cSrcweir DECL_PROP0(MAXROWS, sal_Int32); 503*cdf0e10cSrcweir DECL_PROP0(QUERYTIMEOUT,sal_Int32); 504*cdf0e10cSrcweir DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32); 505*cdf0e10cSrcweir DECL_PROP0(RESULTSETTYPE,sal_Int32); 506*cdf0e10cSrcweir DECL_BOOL_PROP0(USEBOOKMARKS); 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir return new ::cppu::OPropertyArrayHelper(aProps); 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir // ------------------------------------------------------------------------- 511*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & KabCommonStatement::getInfoHelper() 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir return *const_cast<KabCommonStatement*>(this)->getArrayHelper(); 514*cdf0e10cSrcweir } 515*cdf0e10cSrcweir // ------------------------------------------------------------------------- 516*cdf0e10cSrcweir sal_Bool KabCommonStatement::convertFastPropertyValue( 517*cdf0e10cSrcweir Any &, 518*cdf0e10cSrcweir Any &, 519*cdf0e10cSrcweir sal_Int32, 520*cdf0e10cSrcweir const Any&) throw (::com::sun::star::lang::IllegalArgumentException) 521*cdf0e10cSrcweir { 522*cdf0e10cSrcweir sal_Bool bConverted = sal_False; 523*cdf0e10cSrcweir // here we have to try to convert 524*cdf0e10cSrcweir return bConverted; 525*cdf0e10cSrcweir } 526*cdf0e10cSrcweir // ------------------------------------------------------------------------- 527*cdf0e10cSrcweir void KabCommonStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any&) throw (Exception) 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir // set the value to whatever is nescessary 530*cdf0e10cSrcweir switch (nHandle) 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir case PROPERTY_ID_QUERYTIMEOUT: 533*cdf0e10cSrcweir case PROPERTY_ID_MAXFIELDSIZE: 534*cdf0e10cSrcweir case PROPERTY_ID_MAXROWS: 535*cdf0e10cSrcweir case PROPERTY_ID_CURSORNAME: 536*cdf0e10cSrcweir case PROPERTY_ID_RESULTSETCONCURRENCY: 537*cdf0e10cSrcweir case PROPERTY_ID_RESULTSETTYPE: 538*cdf0e10cSrcweir case PROPERTY_ID_FETCHDIRECTION: 539*cdf0e10cSrcweir case PROPERTY_ID_FETCHSIZE: 540*cdf0e10cSrcweir case PROPERTY_ID_ESCAPEPROCESSING: 541*cdf0e10cSrcweir case PROPERTY_ID_USEBOOKMARKS: 542*cdf0e10cSrcweir default: 543*cdf0e10cSrcweir ; 544*cdf0e10cSrcweir } 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir // ------------------------------------------------------------------------- 547*cdf0e10cSrcweir void KabCommonStatement::getFastPropertyValue(Any&,sal_Int32 nHandle) const 548*cdf0e10cSrcweir { 549*cdf0e10cSrcweir switch (nHandle) 550*cdf0e10cSrcweir { 551*cdf0e10cSrcweir case PROPERTY_ID_QUERYTIMEOUT: 552*cdf0e10cSrcweir case PROPERTY_ID_MAXFIELDSIZE: 553*cdf0e10cSrcweir case PROPERTY_ID_MAXROWS: 554*cdf0e10cSrcweir case PROPERTY_ID_CURSORNAME: 555*cdf0e10cSrcweir case PROPERTY_ID_RESULTSETCONCURRENCY: 556*cdf0e10cSrcweir case PROPERTY_ID_RESULTSETTYPE: 557*cdf0e10cSrcweir case PROPERTY_ID_FETCHDIRECTION: 558*cdf0e10cSrcweir case PROPERTY_ID_FETCHSIZE: 559*cdf0e10cSrcweir case PROPERTY_ID_ESCAPEPROCESSING: 560*cdf0e10cSrcweir case PROPERTY_ID_USEBOOKMARKS: 561*cdf0e10cSrcweir default: 562*cdf0e10cSrcweir ; 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir } 565*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 566*cdf0e10cSrcweir void SAL_CALL KabCommonStatement::acquire() throw() 567*cdf0e10cSrcweir { 568*cdf0e10cSrcweir KabCommonStatement_BASE::acquire(); 569*cdf0e10cSrcweir } 570*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 571*cdf0e10cSrcweir void SAL_CALL KabCommonStatement::release() throw() 572*cdf0e10cSrcweir { 573*cdf0e10cSrcweir KabCommonStatement_BASE::release(); 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 576*cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL KabCommonStatement::getPropertySetInfo( ) throw(RuntimeException) 577*cdf0e10cSrcweir { 578*cdf0e10cSrcweir return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper()); 579*cdf0e10cSrcweir } 580*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 581*cdf0e10cSrcweir KabStatement::KabStatement(KabConnection* _pConnection) 582*cdf0e10cSrcweir : KabStatement_BASE(_pConnection) 583*cdf0e10cSrcweir { 584*cdf0e10cSrcweir } 585