1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include "MacabConnection.hxx"
23 #include "MacabHeader.hxx"
24 #include <connectivity/sqliterator.hxx>
25 #include <connectivity/sqlparse.hxx>
26 #include <com/sun/star/sdbc/XStatement.hpp>
27 #include <com/sun/star/sdbc/SQLWarning.hpp>
28 #include <com/sun/star/util/XCancellable.hpp>
29 #include <cppuhelper/compbase.hxx>
30 #include <cppuhelper/implbase.hxx>
31 #include <cppuhelper/basemutex.hxx>
32 #include <comphelper/proparrhlp.hxx>
34 namespace connectivity::macab
36 typedef ::cppu::WeakComponentImplHelper
< css::sdbc::XStatement
,
37 css::sdbc::XWarningsSupplier
,
38 css::util::XCancellable
,
39 css::sdbc::XCloseable
> MacabCommonStatement_BASE
;
42 // Class MacabCommonStatement
43 // is a base class for the normal statement and for the prepared statement
45 class MacabCommonStatement
: public cppu::BaseMutex
,
46 public MacabCommonStatement_BASE
,
47 public ::cppu::OPropertySetHelper
,
48 public comphelper::OPropertyArrayUsageHelper
<MacabCommonStatement
>
51 css::sdbc::SQLWarning m_aLastWarning
;
54 connectivity::OSQLParser m_aParser
;
55 connectivity::OSQLParseTreeIterator m_aSQLIterator
;
56 connectivity::OSQLParseNode
* m_pParseTree
;
57 MacabConnection
* m_pConnection
; // The owning Connection object
58 MacabHeader
* m_pHeader
; // The header of the address book on which to run queries (provided by m_pConnection)
59 css::uno::WeakReference
< css::sdbc::XResultSet
> m_xResultSet
; // The last ResultSet created
63 /// @throws css::sdbc::SQLException
64 class MacabCondition
*analyseWhereClause(
65 const OSQLParseNode
*pParseNode
) const;
66 /// @throws css::sdbc::SQLException
67 class MacabOrder
*analyseOrderByClause(
68 const OSQLParseNode
*pParseNode
) const;
69 OUString
getTableName( ) const;
70 /// @throws css::sdbc::SQLException
71 void setMacabFields(class MacabResultSet
*pResult
) const;
72 /// @throws css::sdbc::SQLException
73 void selectRecords(MacabResultSet
*pResult
) const;
74 /// @throws css::sdbc::SQLException
75 void sortRecords(MacabResultSet
*pResult
) const;
77 // OPropertyArrayUsageHelper
78 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper() const override
;
81 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() override
;
82 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
83 css::uno::Any
& rConvertedValue
,
84 css::uno::Any
& rOldValue
,
86 const css::uno::Any
& rValue
) override
;
87 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
89 const css::uno::Any
& rValue
) override
;
90 virtual void SAL_CALL
getFastPropertyValue(
91 css::uno::Any
& rValue
,
92 sal_Int32 nHandle
) const override
;
94 /// @throws css::sdbc::SQLException
95 virtual void resetParameters() const;
96 /// @throws css::sdbc::SQLException
97 virtual void getNextParameter(OUString
&rParameter
) const;
98 virtual ~MacabCommonStatement() override
;
101 using MacabCommonStatement_BASE::rBHelper
;
103 explicit MacabCommonStatement(MacabConnection
*_pConnection
);
104 using MacabCommonStatement_BASE::operator css::uno::Reference
< css::uno::XInterface
>;
107 using MacabCommonStatement_BASE::disposing
;
110 virtual void SAL_CALL
release() noexcept override
;
111 virtual void SAL_CALL
acquire() noexcept override
;
112 virtual css::uno::Any SAL_CALL
queryInterface(
113 const css::uno::Type
& rType
117 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes(
121 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo(
125 virtual css::uno::Reference
< css::sdbc::XResultSet
> SAL_CALL
executeQuery(
126 const OUString
& sql
) override
;
127 virtual sal_Int32 SAL_CALL
executeUpdate(
128 const OUString
& sql
) override
;
129 virtual sal_Bool SAL_CALL
execute(
130 const OUString
& sql
) override
;
131 virtual css::uno::Reference
< css::sdbc::XConnection
> SAL_CALL
getConnection(
135 virtual css::uno::Any SAL_CALL
getWarnings(
137 virtual void SAL_CALL
clearWarnings(
141 virtual void SAL_CALL
cancel(
145 virtual void SAL_CALL
close(
149 MacabConnection
* getOwnConnection() const { return m_pConnection
; }
153 // Class MacabStatement
155 typedef ::cppu::ImplInheritanceHelper
<
156 MacabCommonStatement
, css::lang::XServiceInfo
> MacabStatement_BASE
;
158 class MacabStatement
: public MacabStatement_BASE
161 virtual ~MacabStatement() override
{ }
164 explicit MacabStatement(MacabConnection
* _pConnection
);
165 DECLARE_SERVICE_INFO();
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */