/src/libreoffice/connectivity/source/inc/file/FStatement.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <com/sun/star/sdbc/XStatement.hpp> |
23 | | #include <com/sun/star/sdbc/XWarningsSupplier.hpp> |
24 | | #include <com/sun/star/sdbc/XCloseable.hpp> |
25 | | #include <com/sun/star/sdbc/SQLWarning.hpp> |
26 | | #include <com/sun/star/util/XCancellable.hpp> |
27 | | #include <comphelper/proparrhlp.hxx> |
28 | | #include <cppuhelper/compbase.hxx> |
29 | | #include <cppuhelper/implbase2.hxx> |
30 | | #include <cppuhelper/basemutex.hxx> |
31 | | #include <connectivity/CommonTools.hxx> |
32 | | #include <connectivity/sqlparse.hxx> |
33 | | #include <file/FConnection.hxx> |
34 | | #include <file/filedllapi.hxx> |
35 | | #include <com/sun/star/lang/XServiceInfo.hpp> |
36 | | #include <comphelper/propertycontainer.hxx> |
37 | | #include <file/fanalyzer.hxx> |
38 | | #include <TSortIndex.hxx> |
39 | | #include <unotools/weakref.hxx> |
40 | | |
41 | | namespace connectivity::file |
42 | | { |
43 | | class OResultSet; |
44 | | class OFileTable; |
45 | | typedef ::cppu::WeakComponentImplHelper< css::sdbc::XWarningsSupplier, |
46 | | css::util::XCancellable, |
47 | | css::sdbc::XCloseable> OStatement_BASE; |
48 | | |
49 | | |
50 | | //************ Class: java.sql.Statement |
51 | | |
52 | | class OOO_DLLPUBLIC_FILE OStatement_Base : |
53 | | public cppu::BaseMutex, |
54 | | public OStatement_BASE, |
55 | | public ::comphelper::OPropertyContainer, |
56 | | public ::comphelper::OPropertyArrayUsageHelper<OStatement_Base> |
57 | | |
58 | | { |
59 | | protected: |
60 | | std::vector<sal_Int32> m_aColMapping; // pos 0 is unused so we don't have to decrement 1 every time |
61 | | std::vector<sal_Int32> m_aParameterIndexes; // maps the parameter index to column index |
62 | | std::vector<sal_Int32> m_aOrderbyColumnNumber; |
63 | | std::vector<TAscendingOrder> m_aOrderbyAscending; |
64 | | |
65 | | css::sdbc::SQLWarning m_aLastWarning; |
66 | | unotools::WeakReference< OResultSet> m_xResultSet; // The last ResultSet created |
67 | | css::uno::Reference< css::sdbc::XDatabaseMetaData> m_xDBMetaData; |
68 | | css::uno::Reference< css::container::XNameAccess> m_xColNames; // table columns // for this Statement |
69 | | |
70 | | |
71 | | connectivity::OSQLParser m_aParser; |
72 | | connectivity::OSQLParseTreeIterator m_aSQLIterator; |
73 | | |
74 | | rtl::Reference<OConnection> m_pConnection;// The owning Connection object |
75 | | connectivity::OSQLParseNode* m_pParseTree; |
76 | | std::unique_ptr<OSQLAnalyzer> m_pSQLAnalyzer; //the sql analyzer used by the resultset |
77 | | |
78 | | rtl::Reference<OFileTable> m_pTable; // the current table |
79 | | OValueRefRow m_aSelectRow; |
80 | | OValueRefRow m_aRow; |
81 | | OValueRefRow m_aEvaluateRow; // contains all values of a row |
82 | | ORefAssignValues m_aAssignValues; // needed for insert,update and parameters |
83 | | // to compare with the restrictions |
84 | | |
85 | | OUString m_aCursorName; |
86 | | sal_Int32 m_nMaxFieldSize; |
87 | | sal_Int32 m_nMaxRows; |
88 | | sal_Int32 m_nQueryTimeOut; |
89 | | sal_Int32 m_nFetchSize; |
90 | | sal_Int32 m_nResultSetType; |
91 | | sal_Int32 m_nFetchDirection; |
92 | | sal_Int32 m_nResultSetConcurrency; |
93 | | bool m_bEscapeProcessing; |
94 | | |
95 | | protected: |
96 | | // initialize the column index map (mapping select columns to table columns) |
97 | | void createColumnMapping(); |
98 | | // searches the statement for sort criteria |
99 | | void analyzeSQL(); |
100 | | void setOrderbyColumn( connectivity::OSQLParseNode const * pColumnRef, |
101 | | connectivity::OSQLParseNode const * pAscendingDescending); |
102 | | |
103 | | virtual void initializeResultSet(OResultSet* _pResult); |
104 | | |
105 | | /// @throws css::sdbc::SQLException |
106 | | /// @throws css::uno::RuntimeException |
107 | | void closeResultSet(); |
108 | | |
109 | | void disposeResultSet(); |
110 | | void GetAssignValues(); |
111 | | void SetAssignValue(const OUString& aColumnName, |
112 | | const OUString& aValue, |
113 | | bool bSetNull = false, |
114 | | sal_uInt32 nParameter=SQL_NO_PARAMETER); |
115 | | void ParseAssignValues( const std::vector< OUString>& aColumnNameList, |
116 | | connectivity::OSQLParseNode* pRow_Value_Constructor_Elem, sal_Int32 nIndex); |
117 | | |
118 | | virtual void parseParamterElem(const OUString& _sColumnName,OSQLParseNode* pRow_Value_Constructor_Elem); |
119 | | // factory method for resultset's |
120 | | virtual rtl::Reference<OResultSet> createResultSet() = 0; |
121 | | // OPropertyArrayUsageHelper |
122 | | virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override; |
123 | | // OPropertySetHelper |
124 | | virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() override; |
125 | | virtual ~OStatement_Base() override; |
126 | | public: |
127 | 19.3k | connectivity::OSQLParseNode* getParseTree() const { return m_pParseTree;} |
128 | | |
129 | | OStatement_Base(OConnection* _pConnection ); |
130 | | |
131 | 19.3k | OConnection* getOwnConnection() const { return m_pConnection.get(); } |
132 | | |
133 | | using OStatement_BASE::operator css::uno::Reference< css::uno::XInterface >; |
134 | | |
135 | | /// @throws css::sdbc::SQLException |
136 | | /// @throws css::uno::RuntimeException |
137 | | virtual void construct(const OUString& sql); |
138 | | |
139 | | // OComponentHelper |
140 | | virtual void SAL_CALL disposing() override; |
141 | | // XInterface |
142 | | // virtual void SAL_CALL release() throw(css::uno::RuntimeException) = 0; |
143 | | virtual void SAL_CALL acquire() noexcept override; |
144 | | // XInterface |
145 | | virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; |
146 | | //XTypeProvider |
147 | | virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; |
148 | | |
149 | | // XPropertySet |
150 | | virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) override; |
151 | | // XWarningsSupplier |
152 | | virtual css::uno::Any SAL_CALL getWarnings( ) override; |
153 | | virtual void SAL_CALL clearWarnings( ) override; |
154 | | // XCancellable |
155 | | virtual void SAL_CALL cancel( ) override; |
156 | | // XCloseable |
157 | | virtual void SAL_CALL close( ) override; |
158 | | }; |
159 | | |
160 | | class OOO_DLLPUBLIC_FILE OStatement_BASE2 : public OStatement_Base |
161 | | |
162 | | { |
163 | | public: |
164 | 29.1k | OStatement_BASE2(OConnection* _pConnection ) : OStatement_Base(_pConnection ) {} |
165 | | // OComponentHelper |
166 | | virtual void SAL_CALL disposing() override; |
167 | | // XInterface |
168 | | virtual void SAL_CALL release() noexcept override; |
169 | | }; |
170 | | |
171 | | typedef ::cppu::ImplHelper2< css::sdbc::XStatement,css::lang::XServiceInfo > OStatement_XStatement; |
172 | | class OOO_DLLPUBLIC_FILE OStatement : |
173 | | public OStatement_BASE2, |
174 | | public OStatement_XStatement |
175 | | { |
176 | | protected: |
177 | | // factory method for resultset's |
178 | | virtual rtl::Reference<OResultSet> createResultSet() override; |
179 | | public: |
180 | | // a Constructor, that is needed for when Returning the Object is needed: |
181 | 9.70k | OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){} |
182 | | DECLARE_SERVICE_INFO(); |
183 | | |
184 | | virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type & rType ) override; |
185 | | virtual void SAL_CALL acquire() noexcept override; |
186 | | virtual void SAL_CALL release() noexcept override; |
187 | | |
188 | | // XStatement |
189 | | virtual css::uno::Reference< css::sdbc::XResultSet > SAL_CALL executeQuery( const OUString& sql ) override ; |
190 | | virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) override ; |
191 | | virtual sal_Bool SAL_CALL execute( const OUString& sql ) override ; |
192 | | virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( ) override ; |
193 | | }; |
194 | | |
195 | | } |
196 | | |
197 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |