Line data Source code
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 : #ifndef INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MSTATEMENT_HXX
21 : #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MSTATEMENT_HXX
22 :
23 : #include <com/sun/star/sdbc/XStatement.hpp>
24 : #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
25 : #include <com/sun/star/sdbc/XBatchExecution.hpp>
26 : #include <com/sun/star/sdbc/XCloseable.hpp>
27 : #include <com/sun/star/sdbc/SQLWarning.hpp>
28 : #include <comphelper/proparrhlp.hxx>
29 : #include <cppuhelper/compbase3.hxx>
30 : #include <comphelper/uno3.hxx>
31 : #include <connectivity/CommonTools.hxx>
32 : #include <list>
33 : #include <com/sun/star/lang/XServiceInfo.hpp>
34 : #include <comphelper/broadcasthelper.hxx>
35 : #include <connectivity/sqliterator.hxx>
36 : #include <connectivity/sqlparse.hxx>
37 : #include <connectivity/FValue.hxx>
38 : #include "TSortIndex.hxx"
39 : #include "MConnection.hxx"
40 : #include "MTable.hxx"
41 :
42 : #include <boost/shared_ptr.hpp>
43 :
44 : namespace connectivity
45 : {
46 : namespace mork
47 : {
48 : class OResultSet;
49 :
50 : typedef ::cppu::WeakComponentImplHelper3< ::com::sun::star::sdbc::XStatement,
51 : ::com::sun::star::sdbc::XWarningsSupplier,
52 : ::com::sun::star::sdbc::XCloseable> OCommonStatement_IBASE;
53 :
54 :
55 : //************ Class: OCommonStatement
56 : // is a base class for the normal statement and for the prepared statement
57 :
58 : class OCommonStatement;
59 : typedef ::connectivity::OSubComponent< OCommonStatement, OCommonStatement_IBASE > OCommonStatement_SBASE;
60 :
61 : class OCommonStatement :public comphelper::OBaseMutex
62 : ,public OCommonStatement_IBASE
63 : ,public ::cppu::OPropertySetHelper
64 : ,public ::comphelper::OPropertyArrayUsageHelper< OCommonStatement >
65 : ,public OCommonStatement_SBASE
66 : {
67 : friend class ::connectivity::OSubComponent< OCommonStatement, OCommonStatement_IBASE >;
68 :
69 : private:
70 : ::com::sun::star::sdbc::SQLWarning m_aLastWarning;
71 :
72 : protected:
73 : ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet > m_xResultSet;
74 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> m_xDBMetaData;
75 : ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xColNames; // table columns
76 :
77 : // for this Statement
78 :
79 : ::std::list< OUString> m_aBatchList;
80 :
81 : OTable* m_pTable;
82 : OConnection* m_pConnection; // The owning Connection object
83 :
84 : OValueRow m_aRow;
85 :
86 : connectivity::OSQLParser m_aParser;
87 : ::boost::shared_ptr< ::connectivity::OSQLParseTreeIterator >
88 : m_pSQLIterator;
89 :
90 : connectivity::OSQLParseNode* m_pParseTree;
91 :
92 : ::std::vector<sal_Int32> m_aColMapping;
93 : ::std::vector<sal_Int32> m_aOrderbyColumnNumber;
94 : ::std::vector<TAscendingOrder> m_aOrderbyAscending;
95 :
96 : ::cppu::OBroadcastHelper& rBHelper;
97 :
98 : protected:
99 :
100 : // OPropertyArrayUsageHelper
101 : virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const SAL_OVERRIDE;
102 : // OPropertySetHelper
103 : virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper() SAL_OVERRIDE;
104 : virtual sal_Bool SAL_CALL convertFastPropertyValue(
105 : ::com::sun::star::uno::Any & rConvertedValue,
106 : ::com::sun::star::uno::Any & rOldValue,
107 : sal_Int32 nHandle,
108 : const ::com::sun::star::uno::Any& rValue )
109 : throw (::com::sun::star::lang::IllegalArgumentException) SAL_OVERRIDE;
110 : virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
111 : sal_Int32 nHandle,
112 : const ::com::sun::star::uno::Any& rValue) throw (::com::sun::star::uno::Exception, std::exception) SAL_OVERRIDE;
113 : virtual void SAL_CALL getFastPropertyValue(
114 : ::com::sun::star::uno::Any& rValue,
115 : sal_Int32 nHandle) const SAL_OVERRIDE;
116 : virtual ~OCommonStatement();
117 :
118 : protected:
119 :
120 : // Driver Internal Methods
121 :
122 : enum StatementType { eSelect, eCreateTable };
123 : /** called to do the parsing of a to-be-executed SQL statement, and set all members as needed
124 : */
125 : virtual StatementType
126 : parseSql( const OUString& sql , bool bAdjusted = false) throw ( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException );
127 : /** called to initialize a result set, according to a previously parsed SQL statement
128 : */
129 : virtual void initializeResultSet( OResultSet* _pResult );
130 : /** called when a possible cached instance of our last result set should be cleared
131 : */
132 : virtual void clearCachedResultSet();
133 : /** caches a result set which has just been created by an execution of an SQL statement
134 : */
135 : virtual void cacheResultSet( const ::rtl::Reference< OResultSet >& _pResult );
136 :
137 :
138 : /** executes the current query (the one which has been passed to the last parseSql call)
139 : */
140 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >
141 : impl_executeCurrentQuery();
142 :
143 : void createColumnMapping();
144 : void analyseSQL();
145 : void setOrderbyColumn( connectivity::OSQLParseNode* pColumnRef,
146 : connectivity::OSQLParseNode* pAscendingDescending);
147 : virtual void createTable( ) throw (
148 : ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException );
149 :
150 : public:
151 : // other methods
152 4 : OConnection* getOwnConnection() const { return m_pConnection;}
153 :
154 : OCommonStatement(OConnection* _pConnection );
155 : using OCommonStatement_IBASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
156 :
157 : // OComponentHelper
158 : virtual void SAL_CALL disposing(void) SAL_OVERRIDE;
159 :
160 : // XInterface
161 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
162 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
163 : // XInterface
164 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
165 : //XTypeProvider
166 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
167 :
168 : // XPropertySet
169 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
170 : // XStatement
171 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery( const OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
172 : virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
173 : virtual sal_Bool SAL_CALL execute( const OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
174 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
175 : // XWarningsSupplier
176 : virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
177 : virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
178 : // XCloseable
179 : virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
180 :
181 : protected:
182 : using OPropertySetHelper::getFastPropertyValue;
183 : };
184 :
185 : class OStatement : public OCommonStatement,
186 : public ::com::sun::star::lang::XServiceInfo
187 : {
188 : protected:
189 0 : virtual ~OStatement(){}
190 : public:
191 : // a constructor, for when the object needs to be returned:
192 : OStatement( OConnection* _pConnection);
193 : DECLARE_SERVICE_INFO();
194 :
195 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
196 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
197 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
198 : };
199 : }
200 : }
201 :
202 : #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MSTATEMENT_HXX
203 :
204 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|