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