1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #ifndef INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FSTATEMENT_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FSTATEMENT_HXX
23 #include <com/sun/star/sdbc/XStatement.hpp>
24 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
25 #include <com/sun/star/sdbc/XMultipleResults.hpp>
26 #include <com/sun/star/sdbc/XBatchExecution.hpp>
27 #include <com/sun/star/sdbc/XCloseable.hpp>
28 #include <com/sun/star/sdbc/SQLWarning.hpp>
29 #include <com/sun/star/util/XCancellable.hpp>
30 #include <comphelper/proparrhlp.hxx>
31 #include <cppuhelper/compbase3.hxx>
32 #include <cppuhelper/implbase2.hxx>
33 #include <comphelper/uno3.hxx>
34 #include <connectivity/CommonTools.hxx>
35 #include "file/FConnection.hxx"
36 #include "file/filedllapi.hxx"
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <comphelper/propertycontainer.hxx>
40 #include "file/fanalyzer.hxx"
41 #include <comphelper/broadcasthelper.hxx>
42 #include "TSortIndex.hxx"
44 namespace connectivity
50 typedef ::cppu::WeakComponentImplHelper3
< ::com::sun::star::sdbc::XWarningsSupplier
,
51 ::com::sun::star::util::XCancellable
,
52 ::com::sun::star::sdbc::XCloseable
> OStatement_BASE
;
55 //************ Class: java.sql.Statement
57 class OOO_DLLPUBLIC_FILE OStatement_Base
:
58 public comphelper::OBaseMutex
,
59 public OStatement_BASE
,
60 public ::comphelper::OPropertyContainer
,
61 public ::comphelper::OPropertyArrayUsageHelper
<OStatement_Base
>
65 ::std::vector
<sal_Int32
> m_aColMapping
; // pos 0 is unused so we don't have to decrement 1 every time
66 ::std::vector
<sal_Int32
> m_aParameterIndexes
; // maps the parameter index to column index
67 ::std::vector
<sal_Int32
> m_aOrderbyColumnNumber
;
68 ::std::vector
<TAscendingOrder
> m_aOrderbyAscending
;
70 ::com::sun::star::sdbc::SQLWarning m_aLastWarning
;
71 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbc::XResultSet
> m_xResultSet
; // The last ResultSet created
72 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDatabaseMetaData
> m_xDBMetaData
;
73 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> m_xColNames
; // table columns // for this Statement
76 connectivity::OSQLParser m_aParser
;
77 connectivity::OSQLParseTreeIterator m_aSQLIterator
;
79 OConnection
* m_pConnection
;// The owning Connection object
80 connectivity::OSQLParseNode
* m_pParseTree
;
81 OSQLAnalyzer
* m_pSQLAnalyzer
; //the sql analyzer used by the resultset
83 ::std::vector
<sal_Int32
>* m_pEvaluationKeySet
;
85 OFileTable
* m_pTable
; // the current table
86 OValueRefRow m_aSelectRow
;
88 OValueRefRow m_aEvaluateRow
; // contains all values of a row
89 ORefAssignValues m_aAssignValues
; // needed for insert,update and parameters
90 // to compare with the restrictions
92 OUString m_aCursorName
;
93 sal_Int32 m_nMaxFieldSize
;
95 sal_Int32 m_nQueryTimeOut
;
96 sal_Int32 m_nFetchSize
;
97 sal_Int32 m_nResultSetType
;
98 sal_Int32 m_nFetchDirection
;
99 sal_Int32 m_nResultSetConcurrency
;
100 bool m_bEscapeProcessing
;
102 ::cppu::OBroadcastHelper
& rBHelper
;
105 // initialize the column index map (mapping select columns to table columns)
106 void createColumnMapping();
107 // searches the statement for sort criteria
109 void setOrderbyColumn( connectivity::OSQLParseNode
* pColumnRef
,
110 connectivity::OSQLParseNode
* pAscendingDescending
);
112 virtual void initializeResultSet(OResultSet
* _pResult
);
113 // create the analyzer
114 OSQLAnalyzer
* createAnalyzer();
116 void closeResultSet() throw (css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
);
117 sal_Int32
getPrecision ( sal_Int32 sqlType
);
119 void disposeResultSet();
120 void GetAssignValues();
121 void SetAssignValue(const OUString
& aColumnName
,
122 const OUString
& aValue
,
123 bool bSetNull
= false,
124 sal_uInt32 nParameter
=SQL_NO_PARAMETER
);
125 void ParseAssignValues( const ::std::vector
< OUString
>& aColumnNameList
,
126 connectivity::OSQLParseNode
* pRow_Value_Constructor_Elem
, sal_Int32 nIndex
);
128 virtual void parseParamterElem(const OUString
& _sColumnName
,OSQLParseNode
* pRow_Value_Constructor_Elem
);
129 // factory method for resultset's
130 virtual OResultSet
* createResultSet() = 0;
131 // OPropertyArrayUsageHelper
132 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const SAL_OVERRIDE
;
133 // OPropertySetHelper
134 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper() SAL_OVERRIDE
;
135 virtual ~OStatement_Base();
137 connectivity::OSQLParseNode
* getParseTree() const { return m_pParseTree
;}
139 OStatement_Base(OConnection
* _pConnection
);
141 OConnection
* getOwnConnection() const { return m_pConnection
;}
143 using OStatement_BASE::operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>;
145 virtual void construct(const OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
148 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
150 // virtual void SAL_CALL release() throw(::com::sun::star::uno::RuntimeException) = 0;
151 virtual void SAL_CALL
acquire() throw() SAL_OVERRIDE
;
153 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
;
155 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
158 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
160 virtual ::com::sun::star::uno::Any SAL_CALL
getWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
161 virtual void SAL_CALL
clearWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
163 virtual void SAL_CALL
cancel( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
165 virtual void SAL_CALL
close( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
168 class OOO_DLLPUBLIC_FILE OStatement_BASE2
:
169 public OStatement_Base
,
170 public connectivity::OSubComponent
<OStatement_BASE2
, OStatement_BASE
>
173 friend class connectivity::OSubComponent
<OStatement_BASE2
, OStatement_BASE
>;
175 OStatement_BASE2(OConnection
* _pConnection
) : OStatement_Base(_pConnection
),
176 connectivity::OSubComponent
<OStatement_BASE2
, OStatement_BASE
>((::cppu::OWeakObject
*)_pConnection
, this){}
178 virtual void SAL_CALL
disposing() SAL_OVERRIDE
;
180 virtual void SAL_CALL
release() throw() SAL_OVERRIDE
;
183 typedef ::cppu::ImplHelper2
< ::com::sun::star::sdbc::XStatement
,::com::sun::star::lang::XServiceInfo
> OStatement_XStatement
;
184 class OOO_DLLPUBLIC_FILE OStatement
:
185 public OStatement_BASE2
,
186 public OStatement_XStatement
189 // factory method for resultset's
190 virtual OResultSet
* createResultSet() SAL_OVERRIDE
;
192 // a Constructor, that is needed for when Returning the Object is needed:
193 OStatement( OConnection
* _pConnection
) : OStatement_BASE2( _pConnection
){}
194 DECLARE_SERVICE_INFO();
196 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
;
197 virtual void SAL_CALL
acquire() throw() SAL_OVERRIDE
;
198 virtual void SAL_CALL
release() throw() SAL_OVERRIDE
;
201 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
;
202 virtual sal_Int32 SAL_CALL
executeUpdate( const OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
203 virtual sal_Bool SAL_CALL
execute( const OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
204 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
;
208 #endif // INCLUDED_CONNECTIVITY_SOURCE_INC_FILE_FSTATEMENT_HXX
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */