xref: /trunk/main/connectivity/source/inc/file/FStatement.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _CONNECTIVITY_FILE_OSTATEMENT_HXX_
29*cdf0e10cSrcweir #define _CONNECTIVITY_FILE_OSTATEMENT_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <com/sun/star/sdbc/XStatement.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/sdbc/XMultipleResults.hpp>
34*cdf0e10cSrcweir #include <com/sun/star/sdbc/XBatchExecution.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/sdbc/XCloseable.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/sdbc/SQLWarning.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/util/XCancellable.hpp>
38*cdf0e10cSrcweir #include <comphelper/proparrhlp.hxx>
39*cdf0e10cSrcweir #include <cppuhelper/compbase3.hxx>
40*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
41*cdf0e10cSrcweir #include <comphelper/uno3.hxx>
42*cdf0e10cSrcweir #include "connectivity/CommonTools.hxx"
43*cdf0e10cSrcweir #include "file/FConnection.hxx"
44*cdf0e10cSrcweir #include "file/filedllapi.hxx"
45*cdf0e10cSrcweir #ifndef _LIST_
46*cdf0e10cSrcweir #include <list>
47*cdf0e10cSrcweir #endif
48*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
49*cdf0e10cSrcweir #include <comphelper/propertycontainer.hxx>
50*cdf0e10cSrcweir #include "file/fanalyzer.hxx"
51*cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx>
52*cdf0e10cSrcweir #include "TSortIndex.hxx"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #define SQL_COLUMN_NOTFOUND STRING_NOTFOUND
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir namespace connectivity
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir     namespace file
59*cdf0e10cSrcweir     {
60*cdf0e10cSrcweir         class OResultSet;
61*cdf0e10cSrcweir         class OFileTable;
62*cdf0e10cSrcweir         typedef ::cppu::WeakComponentImplHelper3<   ::com::sun::star::sdbc::XWarningsSupplier,
63*cdf0e10cSrcweir                                                     ::com::sun::star::util::XCancellable,
64*cdf0e10cSrcweir                                                     ::com::sun::star::sdbc::XCloseable> OStatement_BASE;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir         //**************************************************************
67*cdf0e10cSrcweir         //************ Class: java.sql.Statement
68*cdf0e10cSrcweir         //**************************************************************
69*cdf0e10cSrcweir         class OOO_DLLPUBLIC_FILE OStatement_Base :
70*cdf0e10cSrcweir                                         public  comphelper::OBaseMutex,
71*cdf0e10cSrcweir                                         public  OStatement_BASE,
72*cdf0e10cSrcweir                                         public  ::comphelper::OPropertyContainer,
73*cdf0e10cSrcweir                                         public  ::comphelper::OPropertyArrayUsageHelper<OStatement_Base>
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir         {
76*cdf0e10cSrcweir         protected:
77*cdf0e10cSrcweir             ::std::vector<sal_Int32>                    m_aColMapping; // pos 0 is unused so we don't have to decrement 1 everytime
78*cdf0e10cSrcweir             ::std::vector<sal_Int32>                    m_aParameterIndexes; // maps the parameter index to column index
79*cdf0e10cSrcweir             ::std::vector<sal_Int32>                    m_aOrderbyColumnNumber;
80*cdf0e10cSrcweir             ::std::vector<TAscendingOrder>              m_aOrderbyAscending;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir             ::com::sun::star::sdbc::SQLWarning                                           m_aLastWarning;
83*cdf0e10cSrcweir             ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XResultSet>    m_xResultSet;   // The last ResultSet created
84*cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDatabaseMetaData> m_xDBMetaData;
85*cdf0e10cSrcweir             ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>  m_xColNames; // table columns                                                          //  for this Statement
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir             connectivity::OSQLParser                    m_aParser;
89*cdf0e10cSrcweir             connectivity::OSQLParseTreeIterator         m_aSQLIterator;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir             OConnection*                                m_pConnection;// The owning Connection object
92*cdf0e10cSrcweir             connectivity::OSQLParseNode*                m_pParseTree;
93*cdf0e10cSrcweir             OSQLAnalyzer*                               m_pSQLAnalyzer; //the sql analyzer used by the resultset
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir             ::std::vector<sal_Int32>*                   m_pEvaluationKeySet;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir             OFileTable*                                 m_pTable;       // the current table
98*cdf0e10cSrcweir             OValueRefRow                                m_aSelectRow;
99*cdf0e10cSrcweir             OValueRefRow                                m_aRow;
100*cdf0e10cSrcweir             OValueRefRow                                m_aEvaluateRow; // contains all values of a row
101*cdf0e10cSrcweir             ORefAssignValues                            m_aAssignValues; // needed for insert,update and parameters
102*cdf0e10cSrcweir                                                                     // to compare with the restrictions
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir             ::rtl::OUString                             m_aCursorName;
105*cdf0e10cSrcweir             sal_Int32                                   m_nMaxFieldSize;
106*cdf0e10cSrcweir             sal_Int32                                   m_nMaxRows;
107*cdf0e10cSrcweir             sal_Int32                                   m_nQueryTimeOut;
108*cdf0e10cSrcweir             sal_Int32                                   m_nFetchSize;
109*cdf0e10cSrcweir             sal_Int32                                   m_nResultSetType;
110*cdf0e10cSrcweir             sal_Int32                                   m_nFetchDirection;
111*cdf0e10cSrcweir             sal_Int32                                   m_nResultSetConcurrency;
112*cdf0e10cSrcweir             sal_Bool                                    m_bEscapeProcessing;
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir             ::cppu::OBroadcastHelper&                   rBHelper;
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir         protected:
117*cdf0e10cSrcweir             // initialize the column index map (mapping select columns to table columns)
118*cdf0e10cSrcweir             void createColumnMapping();
119*cdf0e10cSrcweir             // searches the statement for sort criteria
120*cdf0e10cSrcweir             void anylizeSQL();
121*cdf0e10cSrcweir             void setOrderbyColumn( connectivity::OSQLParseNode* pColumnRef,
122*cdf0e10cSrcweir                                      connectivity::OSQLParseNode* pAscendingDescending);
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir             virtual void initializeResultSet(OResultSet* _pResult);
125*cdf0e10cSrcweir             // create the analyzer
126*cdf0e10cSrcweir             virtual OSQLAnalyzer* createAnalyzer();
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir             void reset () throw( ::com::sun::star::sdbc::SQLException);
129*cdf0e10cSrcweir             void clearMyResultSet () throw( ::com::sun::star::sdbc::SQLException);
130*cdf0e10cSrcweir             void setWarning (const  ::com::sun::star::sdbc::SQLWarning &ex) throw( ::com::sun::star::sdbc::SQLException);
131*cdf0e10cSrcweir             sal_Int32 getPrecision ( sal_Int32 sqlType);
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir             void disposeResultSet();
134*cdf0e10cSrcweir             void GetAssignValues();
135*cdf0e10cSrcweir             void SetAssignValue(const String& aColumnName,
136*cdf0e10cSrcweir                                    const String& aValue,
137*cdf0e10cSrcweir                                    sal_Bool bSetNull = sal_False,
138*cdf0e10cSrcweir                                    sal_uInt32 nParameter=SQL_NO_PARAMETER);
139*cdf0e10cSrcweir             void ParseAssignValues( const ::std::vector< String>& aColumnNameList,
140*cdf0e10cSrcweir                                     connectivity::OSQLParseNode* pRow_Value_Constructor_Elem,xub_StrLen nIndex);
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir             virtual void parseParamterElem(const String& _sColumnName,OSQLParseNode* pRow_Value_Constructor_Elem);
143*cdf0e10cSrcweir             // factory method for resultset's
144*cdf0e10cSrcweir             virtual OResultSet* createResultSet() = 0;
145*cdf0e10cSrcweir             // OPropertyArrayUsageHelper
146*cdf0e10cSrcweir             virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
147*cdf0e10cSrcweir             // OPropertySetHelper
148*cdf0e10cSrcweir             virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper();
149*cdf0e10cSrcweir             virtual ~OStatement_Base();
150*cdf0e10cSrcweir         public:
151*cdf0e10cSrcweir             connectivity::OSQLParseNode* getParseTree() const { return m_pParseTree;}
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir             OStatement_Base(OConnection* _pConnection );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir             OConnection* getOwnConnection() const { return m_pConnection;}
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir             using OStatement_BASE::operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >;
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir             virtual void construct(const ::rtl::OUString& sql)  throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir             // OComponentHelper
162*cdf0e10cSrcweir             virtual void SAL_CALL disposing(void);
163*cdf0e10cSrcweir             // XInterface
164*cdf0e10cSrcweir             //      virtual void SAL_CALL release() throw(::com::sun::star::uno::RuntimeException) = 0;
165*cdf0e10cSrcweir             virtual void SAL_CALL acquire() throw();
166*cdf0e10cSrcweir             // XInterface
167*cdf0e10cSrcweir             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
168*cdf0e10cSrcweir             //XTypeProvider
169*cdf0e10cSrcweir             virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes(  ) throw(::com::sun::star::uno::RuntimeException);
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir             // XPropertySet
172*cdf0e10cSrcweir             virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
173*cdf0e10cSrcweir             // XWarningsSupplier
174*cdf0e10cSrcweir             virtual ::com::sun::star::uno::Any SAL_CALL getWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
175*cdf0e10cSrcweir             virtual void SAL_CALL clearWarnings(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
176*cdf0e10cSrcweir             // XCancellable
177*cdf0e10cSrcweir             virtual void SAL_CALL cancel(  ) throw(::com::sun::star::uno::RuntimeException);
178*cdf0e10cSrcweir             // XCloseable
179*cdf0e10cSrcweir             virtual void SAL_CALL close(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
180*cdf0e10cSrcweir         };
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir         class OOO_DLLPUBLIC_FILE OStatement_BASE2 :
183*cdf0e10cSrcweir                                     public OStatement_Base,
184*cdf0e10cSrcweir                                     public connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE>
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir         {
187*cdf0e10cSrcweir             friend class connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE>;
188*cdf0e10cSrcweir         public:
189*cdf0e10cSrcweir             OStatement_BASE2(OConnection* _pConnection ) :  OStatement_Base(_pConnection ),
190*cdf0e10cSrcweir                                     connectivity::OSubComponent<OStatement_BASE2, OStatement_BASE>((::cppu::OWeakObject*)_pConnection, this){}
191*cdf0e10cSrcweir             // OComponentHelper
192*cdf0e10cSrcweir             virtual void SAL_CALL disposing(void);
193*cdf0e10cSrcweir             // XInterface
194*cdf0e10cSrcweir             virtual void SAL_CALL release() throw();
195*cdf0e10cSrcweir         };
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir         typedef ::cppu::ImplHelper2< ::com::sun::star::sdbc::XStatement,::com::sun::star::lang::XServiceInfo > OStatement_XStatement;
198*cdf0e10cSrcweir         class OOO_DLLPUBLIC_FILE OStatement :
199*cdf0e10cSrcweir                             public OStatement_BASE2,
200*cdf0e10cSrcweir                             public OStatement_XStatement
201*cdf0e10cSrcweir         {
202*cdf0e10cSrcweir         protected:
203*cdf0e10cSrcweir             // factory method for resultset's
204*cdf0e10cSrcweir             virtual OResultSet* createResultSet();
205*cdf0e10cSrcweir         public:
206*cdf0e10cSrcweir             // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
207*cdf0e10cSrcweir             OStatement( OConnection* _pConnection) : OStatement_BASE2( _pConnection){}
208*cdf0e10cSrcweir             DECLARE_SERVICE_INFO();
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir             virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException);
211*cdf0e10cSrcweir             virtual void SAL_CALL acquire() throw();
212*cdf0e10cSrcweir             virtual void SAL_CALL release() throw();
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir             // XStatement
215*cdf0e10cSrcweir             virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > SAL_CALL executeQuery( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
216*cdf0e10cSrcweir             virtual sal_Int32 SAL_CALL executeUpdate( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
217*cdf0e10cSrcweir             virtual sal_Bool SAL_CALL execute( const ::rtl::OUString& sql ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) ;
218*cdf0e10cSrcweir             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) ;
219*cdf0e10cSrcweir         };
220*cdf0e10cSrcweir     }
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir #endif // _CONNECTIVITY_FILE_OSTATEMENT_HXX_
223*cdf0e10cSrcweir 
224