1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MStatement.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef CONNECTIVITY_SSTATEMENT_HXX
31 #define CONNECTIVITY_SSTATEMENT_HXX
33 #include <com/sun/star/sdbc/XStatement.hpp>
34 #include <com/sun/star/sdbc/XWarningsSupplier.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 <comphelper/proparrhlp.hxx>
39 #include <cppuhelper/compbase3.hxx>
40 #include <comphelper/uno3.hxx>
41 #include "connectivity/CommonTools.hxx"
46 #include <com/sun/star/lang/XServiceInfo.hpp>
47 #include <comphelper/broadcasthelper.hxx>
48 #include "connectivity/sqliterator.hxx"
49 #ifndef _CONNECTIVITY_PARSE_SQLPARSE_HXX_
50 #include "connectivity/sqlparse.hxx"
52 #include <connectivity/FValue.hxx>
53 #include "TSortIndex.hxx"
54 #include "MConnection.hxx"
57 #include <boost/shared_ptr.hpp>
59 namespace connectivity
65 typedef ::cppu::WeakComponentImplHelper3
< ::com::sun::star::sdbc::XStatement
,
66 ::com::sun::star::sdbc::XWarningsSupplier
,
67 ::com::sun::star::sdbc::XCloseable
> OCommonStatement_IBASE
;
69 //**************************************************************
70 //************ Class: OCommonStatement
71 // is a base class for the normal statement and for the prepared statement
72 //**************************************************************
73 class OCommonStatement
;
74 typedef ::connectivity::OSubComponent
< OCommonStatement
, OCommonStatement_IBASE
> OCommonStatement_SBASE
;
76 class OCommonStatement
:public comphelper::OBaseMutex
77 ,public OCommonStatement_IBASE
78 ,public ::cppu::OPropertySetHelper
79 ,public ::comphelper::OPropertyArrayUsageHelper
< OCommonStatement
>
80 ,public OCommonStatement_SBASE
82 friend class ::connectivity::OSubComponent
< OCommonStatement
, OCommonStatement_IBASE
>;
85 ::com::sun::star::sdbc::SQLWarning m_aLastWarning
;
88 ::com::sun::star::uno::WeakReference
< ::com::sun::star::sdbc::XResultSet
> m_xResultSet
;
89 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XDatabaseMetaData
> m_xDBMetaData
;
90 ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
> m_xColNames
; // table columns
94 ::std::list
< ::rtl::OUString
> m_aBatchList
;
97 OConnection
* m_pConnection
; // The owning Connection object
101 connectivity::OSQLParser m_aParser
;
102 ::boost::shared_ptr
< ::connectivity::OSQLParseTreeIterator
>
105 connectivity::OSQLParseNode
* m_pParseTree
;
107 ::std::vector
<sal_Int32
> m_aColMapping
;
108 ::std::vector
<sal_Int32
> m_aOrderbyColumnNumber
;
109 ::std::vector
<TAscendingOrder
> m_aOrderbyAscending
;
111 ::cppu::OBroadcastHelper
& rBHelper
;
115 // OPropertyArrayUsageHelper
116 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const;
117 // OPropertySetHelper
118 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
119 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
120 ::com::sun::star::uno::Any
& rConvertedValue
,
121 ::com::sun::star::uno::Any
& rOldValue
,
123 const ::com::sun::star::uno::Any
& rValue
)
124 throw (::com::sun::star::lang::IllegalArgumentException
);
125 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
127 const ::com::sun::star::uno::Any
& rValue
) throw (::com::sun::star::uno::Exception
);
128 virtual void SAL_CALL
getFastPropertyValue(
129 ::com::sun::star::uno::Any
& rValue
,
130 sal_Int32 nHandle
) const;
131 virtual ~OCommonStatement();
135 // Driver Internal Methods
137 enum StatementType
{ eSelect
, eCreateTable
};
138 /** called to do the parsing of a to-be-executed SQL statement, and set all members as needed
140 virtual StatementType
141 parseSql( const ::rtl::OUString
& sql
, sal_Bool bAdjusted
= sal_False
) throw ( ::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
142 /** called to initialize a result set, according to a previously parsed SQL statement
144 virtual void initializeResultSet( OResultSet
* _pResult
);
145 /** called when a possible cached instance of our last result set should be cleared
147 virtual void clearCachedResultSet();
148 /** caches a result set which has just been created by an execution of an SQL statement
150 virtual void cacheResultSet( const ::rtl::Reference
< OResultSet
>& _pResult
);
153 /** executes the current query (the one which has been passed to the last parseSql call)
155 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
>
156 impl_executeCurrentQuery();
158 void createColumnMapping();
160 void setOrderbyColumn( connectivity::OSQLParseNode
* pColumnRef
,
161 connectivity::OSQLParseNode
* pAscendingDescending
);
162 virtual void createTable( ) throw (
163 ::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
167 OConnection
* getOwnConnection() const { return m_pConnection
;}
169 OCommonStatement(OConnection
* _pConnection
);
170 using OCommonStatement_IBASE::operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>;
173 virtual void SAL_CALL
disposing(void);
176 virtual void SAL_CALL
release() throw();
177 virtual void SAL_CALL
acquire() throw();
179 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
);
181 virtual ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw(::com::sun::star::uno::RuntimeException
);
184 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
);
186 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
) ;
187 virtual sal_Int32 SAL_CALL
executeUpdate( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) ;
188 virtual sal_Bool SAL_CALL
execute( const ::rtl::OUString
& sql
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
) ;
189 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
) ;
191 virtual ::com::sun::star::uno::Any SAL_CALL
getWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
192 virtual void SAL_CALL
clearWarnings( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
194 virtual void SAL_CALL
close( ) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
197 using OPropertySetHelper::getFastPropertyValue
;
200 class OStatement
: public OCommonStatement
,
201 public ::com::sun::star::lang::XServiceInfo
206 // ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
207 OStatement( OConnection
* _pConnection
) : OCommonStatement( _pConnection
){}
208 DECLARE_SERVICE_INFO();
210 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
);
211 virtual void SAL_CALL
acquire() throw();
212 virtual void SAL_CALL
release() throw();
216 #endif // CONNECTIVITY_SSTATEMENT_HXX