1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef _CONNECTIVITY_FILE_OSTATEMENT_HXX_
30 #define _CONNECTIVITY_FILE_OSTATEMENT_HXX_
32 #include <com/sun/star/sdbc/XStatement.hpp>
33 #include <com/sun/star/sdbc/XWarningsSupplier.hpp>
34 #include <com/sun/star/sdbc/XMultipleResults.hpp>
35 #include <com/sun/star/sdbc/XBatchExecution.hpp>
36 #include <com/sun/star/sdbc/XCloseable.hpp>
37 #include <com/sun/star/sdbc/SQLWarning.hpp>
38 #include <com/sun/star/util/XCancellable.hpp>
39 #include <comphelper/proparrhlp.hxx>
40 #include <cppuhelper/compbase3.hxx>
41 #include <cppuhelper/implbase2.hxx>
42 #include <comphelper/uno3.hxx>
43 #include "connectivity/CommonTools.hxx"
44 #include "file/FConnection.hxx"
45 #include "file/filedllapi.hxx"
49 #include <com/sun/star/lang/XServiceInfo.hpp>
50 #include <comphelper/propertycontainer.hxx>
51 #include "file/fanalyzer.hxx"
52 #include <comphelper/broadcasthelper.hxx>
53 #include "TSortIndex.hxx"
55 #define SQL_COLUMN_NOTFOUND STRING_NOTFOUND
57 namespace connectivity
63 typedef ::cppu::WeakComponentImplHelper3
< ::com::sun::star::sdbc::XWarningsSupplier
,
64 ::com::sun::star::util::XCancellable
,
65 ::com::sun::star::sdbc::XCloseable
> OStatement_BASE
;
67 //**************************************************************
68 //************ Class: java.sql.Statement
69 //**************************************************************
70 class OOO_DLLPUBLIC_FILE OStatement_Base
:
71 public comphelper::OBaseMutex
,
72 public OStatement_BASE
,
73 public ::comphelper::OPropertyContainer
,
74 public ::comphelper::OPropertyArrayUsageHelper
<OStatement_Base
>
78 ::std::vector
<sal_Int32
> m_aColMapping
; // pos 0 is unused so we don't have to decrement 1 everytime
79 ::std::vector
<sal_Int32
> m_aParameterIndexes
; // maps the parameter index to column index
80 ::std::vector
<sal_Int32
> m_aOrderbyColumnNumber
;
81 ::std::vector
<TAscendingOrder
> m_aOrderbyAscending
;
83 ::com::sun::star::sdbc::SQLWarning m_aLastWarning
;
84 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbc::XResultSet
> m_xResultSet
; // The last ResultSet created
85 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDatabaseMetaData
> m_xDBMetaData
;
86 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> m_xColNames
; // table columns // for this Statement
89 connectivity::OSQLParser m_aParser
;
90 connectivity::OSQLParseTreeIterator m_aSQLIterator
;
92 OConnection
* m_pConnection
;// The owning Connection object
93 connectivity::OSQLParseNode
* m_pParseTree
;
94 OSQLAnalyzer
* m_pSQLAnalyzer
; //the sql analyzer used by the resultset
96 ::std::vector
<sal_Int32
>* m_pEvaluationKeySet
;
98 OFileTable
* m_pTable
; // the current table
99 OValueRefRow m_aSelectRow
;
101 OValueRefRow m_aEvaluateRow
; // contains all values of a row
102 ORefAssignValues m_aAssignValues
; // needed for insert,update and parameters
103 // to compare with the restrictions
105 ::rtl::OUString m_aCursorName
;
106 sal_Int32 m_nMaxFieldSize
;
107 sal_Int32 m_nMaxRows
;
108 sal_Int32 m_nQueryTimeOut
;
109 sal_Int32 m_nFetchSize
;
110 sal_Int32 m_nResultSetType
;
111 sal_Int32 m_nFetchDirection
;
112 sal_Int32 m_nResultSetConcurrency
;
113 sal_Bool m_bEscapeProcessing
;
115 ::cppu::OBroadcastHelper
& rBHelper
;
118 // initialize the column index map (mapping select columns to table columns)
119 void createColumnMapping();
120 // searches the statement for sort criteria
122 void setOrderbyColumn( connectivity::OSQLParseNode
* pColumnRef
,
123 connectivity::OSQLParseNode
* pAscendingDescending
);
125 virtual void initializeResultSet(OResultSet
* _pResult
);
126 // create the analyzer
127 virtual OSQLAnalyzer
* createAnalyzer();
129 void reset () throw( ::com::sun::star::sdbc::SQLException
);
130 void clearMyResultSet () throw( ::com::sun::star::sdbc::SQLException
);
131 void setWarning (const ::com::sun::star::sdbc::SQLWarning
&ex
) throw( ::com::sun::star::sdbc::SQLException
);
132 sal_Int32
getPrecision ( sal_Int32 sqlType
);
134 void disposeResultSet();
135 void GetAssignValues();
136 void SetAssignValue(const String
& aColumnName
,
137 const String
& aValue
,
138 sal_Bool bSetNull
= sal_False
,
139 sal_uInt32 nParameter
=SQL_NO_PARAMETER
);
140 void ParseAssignValues( const ::std::vector
< String
>& aColumnNameList
,
141 connectivity::OSQLParseNode
* pRow_Value_Constructor_Elem
,xub_StrLen nIndex
);
143 virtual void parseParamterElem(const String
& _sColumnName
,OSQLParseNode
* pRow_Value_Constructor_Elem
);
144 // factory method for resultset's
145 virtual OResultSet
* createResultSet() = 0;
146 // OPropertyArrayUsageHelper
147 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const;
148 // OPropertySetHelper
149 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
150 virtual ~OStatement_Base();
152 connectivity::OSQLParseNode
* getParseTree() const { return m_pParseTree
;}
154 OStatement_Base(OConnection
* _pConnection
);
156 OConnection
* getOwnConnection() const { return m_pConnection
;}
158 using OStatement_BASE::operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>;
160 virtual void construct(const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
163 virtual void SAL_CALL
disposing(void);
165 // virtual void SAL_CALL release() throw(::com::sun::star::uno::RuntimeException) = 0;
166 virtual void SAL_CALL
acquire() throw();
168 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
);
170 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw(::com::sun::star::uno::RuntimeException
);
173 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
);
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
);
178 virtual void SAL_CALL
cancel( ) throw(::com::sun::star::uno::RuntimeException
);
180 virtual void SAL_CALL
close( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
183 class OOO_DLLPUBLIC_FILE OStatement_BASE2
:
184 public OStatement_Base
,
185 public connectivity::OSubComponent
<OStatement_BASE2
, OStatement_BASE
>
188 friend class connectivity::OSubComponent
<OStatement_BASE2
, OStatement_BASE
>;
190 OStatement_BASE2(OConnection
* _pConnection
) : OStatement_Base(_pConnection
),
191 connectivity::OSubComponent
<OStatement_BASE2
, OStatement_BASE
>((::cppu::OWeakObject
*)_pConnection
, this){}
193 virtual void SAL_CALL
disposing(void);
195 virtual void SAL_CALL
release() throw();
198 typedef ::cppu::ImplHelper2
< ::com::sun::star::sdbc::XStatement
,::com::sun::star::lang::XServiceInfo
> OStatement_XStatement
;
199 class OOO_DLLPUBLIC_FILE OStatement
:
200 public OStatement_BASE2
,
201 public OStatement_XStatement
204 // factory method for resultset's
205 virtual OResultSet
* createResultSet();
207 // a Constructor, that is needed for when Returning the Object is needed:
208 OStatement( OConnection
* _pConnection
) : OStatement_BASE2( _pConnection
){}
209 DECLARE_SERVICE_INFO();
211 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
);
212 virtual void SAL_CALL
acquire() throw();
213 virtual void SAL_CALL
release() throw();
216 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
) ;
217 virtual sal_Int32 SAL_CALL
executeUpdate( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) ;
218 virtual sal_Bool SAL_CALL
execute( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) ;
219 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
) ;
223 #endif // _CONNECTIVITY_FILE_OSTATEMENT_HXX_
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */