Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mozab / MStatement.hxx
bloba89a0588e6e2cc694485d533331b4ccd69870794
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #ifndef CONNECTIVITY_SSTATEMENT_HXX
20 #define CONNECTIVITY_SSTATEMENT_HXX
22 #include <com/sun/star/sdbc/XStatement.hpp>
23 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
24 #include <com/sun/star/sdbc/XBatchExecution.hpp>
25 #include <com/sun/star/sdbc/XCloseable.hpp>
26 #include <com/sun/star/sdbc/SQLWarning.hpp>
27 #include <comphelper/proparrhlp.hxx>
28 #include <cppuhelper/compbase3.hxx>
29 #include <comphelper/uno3.hxx>
30 #include "connectivity/CommonTools.hxx"
31 #include <list>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <comphelper/broadcasthelper.hxx>
34 #include "connectivity/sqliterator.hxx"
35 #include "connectivity/sqlparse.hxx"
36 #include <connectivity/FValue.hxx>
37 #include "TSortIndex.hxx"
38 #include "MConnection.hxx"
39 #include "MTable.hxx"
41 #include <boost/shared_ptr.hpp>
43 namespace connectivity
45 namespace mozab
47 class OResultSet;
49 typedef ::cppu::WeakComponentImplHelper3< ::com::sun::star::sdbc::XStatement,
50 ::com::sun::star::sdbc::XWarningsSupplier,
51 ::com::sun::star::sdbc::XCloseable> OCommonStatement_IBASE;
54 //************ Class: OCommonStatement
55 // is a base class for the normal statement and for the prepared statement
57 class OCommonStatement;
58 typedef ::connectivity::OSubComponent< OCommonStatement, OCommonStatement_IBASE > OCommonStatement_SBASE;
60 class OCommonStatement :public comphelper::OBaseMutex
61 ,public OCommonStatement_IBASE
62 ,public ::cppu::OPropertySetHelper
63 ,public ::comphelper::OPropertyArrayUsageHelper< OCommonStatement >
64 ,public OCommonStatement_SBASE
66 friend class ::connectivity::OSubComponent< OCommonStatement, OCommonStatement_IBASE >;
68 private:
69 ::com::sun::star::sdbc::SQLWarning m_aLastWarning;
71 protected:
72 ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet > m_xResultSet;
73 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> m_xDBMetaData;
74 ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xColNames; // table columns
76 // for this Statement
78 ::std::list< OUString> m_aBatchList;
80 OTable* m_pTable;
81 OConnection* m_pConnection; // The owning Connection object
83 OValueRow m_aRow;
85 connectivity::OSQLParser m_aParser;
86 ::boost::shared_ptr< ::connectivity::OSQLParseTreeIterator >
87 m_pSQLIterator;
89 connectivity::OSQLParseNode* m_pParseTree;
91 ::std::vector<sal_Int32> m_aColMapping;
92 ::std::vector<sal_Int32> m_aOrderbyColumnNumber;
93 ::std::vector<TAscendingOrder> m_aOrderbyAscending;
95 ::cppu::OBroadcastHelper& rBHelper;
97 protected:
99 // OPropertyArrayUsageHelper
100 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
101 // OPropertySetHelper
102 virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
103 virtual sal_Bool SAL_CALL convertFastPropertyValue(
104 ::com::sun::star::uno::Any & rConvertedValue,
105 ::com::sun::star::uno::Any & rOldValue,
106 sal_Int32 nHandle,
107 const ::com::sun::star::uno::Any& rValue )
108 throw (::com::sun::star::lang::IllegalArgumentException);
109 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
110 sal_Int32 nHandle,
111 const ::com::sun::star::uno::Any& rValue) throw (::com::sun::star::uno::Exception);
112 virtual void SAL_CALL getFastPropertyValue(
113 ::com::sun::star::uno::Any& rValue,
114 sal_Int32 nHandle) const;
115 virtual ~OCommonStatement();
117 protected:
119 // Driver Internal Methods
121 enum StatementType { eSelect, eCreateTable };
122 /** called to do the parsing of a to-be-executed SQL statement, and set all members as needed
124 virtual StatementType
125 parseSql( const OUString& sql , sal_Bool bAdjusted = sal_False) throw ( ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException );
126 /** called to initialize a result set, according to a previously parsed SQL statement
128 virtual void initializeResultSet( OResultSet* _pResult );
129 /** called when a possible cached instance of our last result set should be cleared
131 virtual void clearCachedResultSet();
132 /** caches a result set which has just been created by an execution of an SQL statement
134 virtual void cacheResultSet( const ::rtl::Reference< OResultSet >& _pResult );
137 /** executes the current query (the one which has been passed to the last parseSql call)
139 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet >
140 impl_executeCurrentQuery();
142 void createColumnMapping();
143 void analyseSQL();
144 void setOrderbyColumn( connectivity::OSQLParseNode* pColumnRef,
145 connectivity::OSQLParseNode* pAscendingDescending);
146 virtual void createTable( ) throw (
147 ::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException );
149 public:
150 // other methods
151 OConnection* getOwnConnection() const { return m_pConnection;}
153 OCommonStatement(OConnection* _pConnection );
154 using OCommonStatement_IBASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
156 // OComponentHelper
157 virtual void SAL_CALL disposing(void);
159 // XInterface
160 virtual void SAL_CALL release() throw();
161 virtual void SAL_CALL acquire() throw();
162 // XInterface
163 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
164 //XTypeProvider
165 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw(::com::sun::star::uno::RuntimeException);
167 // XPropertySet
168 virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException);
169 // XStatement
170 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) ;
171 virtual sal_Int32 SAL_CALL executeUpdate( const OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
172 virtual sal_Bool SAL_CALL execute( const OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
173 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) ;
174 // XWarningsSupplier
175 virtual ::com::sun::star::uno::Any SAL_CALL getWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
176 virtual void SAL_CALL clearWarnings( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
177 // XCloseable
178 virtual void SAL_CALL close( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
180 protected:
181 using OPropertySetHelper::getFastPropertyValue;
184 class OStatement : public OCommonStatement,
185 public ::com::sun::star::lang::XServiceInfo
187 protected:
188 ~OStatement(){}
189 public:
190 // a constructor, for when the object needs to be returned:
191 OStatement( OConnection* _pConnection) : OCommonStatement( _pConnection){}
192 DECLARE_SERVICE_INFO();
194 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
195 virtual void SAL_CALL acquire() throw();
196 virtual void SAL_CALL release() throw();
200 #endif // CONNECTIVITY_SSTATEMENT_HXX
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */