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 :
148 : public:
149 : // other methods
150 2 : OConnection* getOwnConnection() const { return m_pConnection;}
151 :
152 : OCommonStatement(OConnection* _pConnection );
153 : using OCommonStatement_IBASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
154 :
155 : // OComponentHelper
156 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
157 :
158 : // XInterface
159 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
160 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
161 : // XInterface
162 : 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;
163 : //XTypeProvider
164 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
165 :
166 : // XPropertySet
167 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
168 : // XStatement
169 : 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 ;
170 : virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
171 : virtual sal_Bool SAL_CALL execute( const OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
172 : 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 ;
173 : // XWarningsSupplier
174 : virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
175 : virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
176 : // XCloseable
177 : virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
178 :
179 : protected:
180 : using OPropertySetHelper::getFastPropertyValue;
181 : };
182 :
183 : class OStatement : public OCommonStatement,
184 : public ::com::sun::star::lang::XServiceInfo
185 : {
186 : protected:
187 0 : virtual ~OStatement(){}
188 : public:
189 : // a constructor, for when the object needs to be returned:
190 : OStatement( OConnection* _pConnection);
191 : DECLARE_SERVICE_INFO();
192 :
193 : 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;
194 : virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
195 : virtual void SAL_CALL release() throw() SAL_OVERRIDE;
196 : };
197 : }
198 : }
199 :
200 : #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_MORK_MSTATEMENT_HXX
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|