1 /*************************************************************************
3 * $RCSfile: pq_preparedstatement.hxx,v $
7 * last change: $Author: jbu $ $Date: 2006/01/22 15:14:29 $
9 * The Contents of this file are made available subject to the terms of
10 * either of the following licenses
12 * - GNU Lesser General Public License Version 2.1
13 * - Sun Industry Standards Source License Version 1.1
15 * Sun Microsystems Inc., October, 2000
17 * GNU Lesser General Public License Version 2.1
18 * =============================================
19 * Copyright 2000 by Sun Microsystems, Inc.
20 * 901 San Antonio Road, Palo Alto, CA 94303, USA
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License version 2.1, as published by the Free Software Foundation.
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37 * Sun Industry Standards Source License Version 1.1
38 * =================================================
39 * The contents of this file are subject to the Sun Industry Standards
40 * Source License Version 1.1 (the "License"); You may not use this file
41 * except in compliance with the License. You may obtain a copy of the
42 * License at http://www.openoffice.org/license.html.
44 * Software provided under this License is provided on an "AS IS" basis,
45 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
46 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
47 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
48 * See the License for the specific provisions governing your rights and
49 * obligations concerning the Software.
51 * The Initial Developer of the Original Code is: Joerg Budischewski
53 * Copyright: 2000 by Sun Microsystems, Inc.
55 * All Rights Reserved.
57 * Contributor(s): Joerg Budischewski
60 ************************************************************************/
62 #ifndef _PQ_PREPARED_STATEMENT_HXX_
63 #define _PQ_PREPARED_STATEMENT_HXX_
68 #include <cppuhelper/propshlp.hxx>
69 #include <cppuhelper/component.hxx>
71 #include <com/sun/star/sdbc/XParameters.hpp>
72 #include <com/sun/star/sdbc/XMultipleResults.hpp>
73 #include <com/sun/star/sdbc/XGeneratedResultSet.hpp>
74 #include <com/sun/star/sdbc/XResultSetMetaDataSupplier.hpp>
76 #include "pq_connection.hxx"
77 namespace rtl
{ class OString
; }
78 namespace pq_sdbc_driver
81 static const sal_Int32 PREPARED_STATEMENT_CURSOR_NAME
= 0;
82 static const sal_Int32 PREPARED_STATEMENT_ESCAPE_PROCESSING
= 1;
83 static const sal_Int32 PREPARED_STATEMENT_FETCH_DIRECTION
= 2;
84 static const sal_Int32 PREPARED_STATEMENT_FETCH_SIZE
= 3;
85 static const sal_Int32 PREPARED_STATEMENT_MAX_FIELD_SIZE
= 4;
86 static const sal_Int32 PREPARED_STATEMENT_MAX_ROWS
= 5;
87 static const sal_Int32 PREPARED_STATEMENT_QUERY_TIME_OUT
= 6;
88 static const sal_Int32 PREPARED_STATEMENT_RESULT_SET_CONCURRENCY
= 7;
89 static const sal_Int32 PREPARED_STATEMENT_RESULT_SET_TYPE
= 8;
91 #define PREPARED_STATEMENT_SIZE 9
94 class PreparedStatement
: public cppu::OComponentHelper
,
95 public cppu::OPropertySetHelper
,
96 public com::sun::star::sdbc::XPreparedStatement
,
97 public com::sun::star::sdbc::XParameters
,
98 public com::sun::star::sdbc::XCloseable
,
99 public com::sun::star::sdbc::XWarningsSupplier
,
100 public com::sun::star::sdbc::XMultipleResults
,
101 public com::sun::star::sdbc::XGeneratedResultSet
,
102 public com::sun::star::sdbc::XResultSetMetaDataSupplier
105 com::sun::star::uno::Any m_props
[PREPARED_STATEMENT_SIZE
];
106 com::sun::star::uno::Reference
< com::sun::star::sdbc::XConnection
> m_connection
;
107 ConnectionSettings
*m_pSettings
;
108 ::com::sun::star::uno::Reference
< com::sun::star::sdbc::XCloseable
> m_lastResultset
;
109 ::rtl::OString m_stmt
;
110 ::rtl::OString m_executedStatement
;
111 ::rtl::Reference
< RefCountedMutex
> m_refMutex
;
112 OStringVector m_vars
;
113 OStringVector m_splittedStatement
;
114 sal_Bool m_multipleResultAvailable
;
115 sal_Int32 m_multipleResultUpdateCount
;
116 sal_Int32 m_lastOidInserted
;
117 rtl::OUString m_lastTableInserted
;
118 rtl::OString m_lastQuery
;
122 * @param ppConnection The piece of memory, pConnection points to, is accessisble
123 * as long as a reference to paramenter con is held.
125 PreparedStatement( const rtl::Reference
< RefCountedMutex
> & refMutex
,
126 const com::sun::star::uno::Reference
< com::sun::star::sdbc::XConnection
> & con
,
127 struct ConnectionSettings
*pSettings
,
128 const rtl::OString
&stmt
);
130 virtual ~PreparedStatement();
131 public: // XInterface
132 virtual void SAL_CALL
acquire() throw() { OComponentHelper::acquire(); }
133 virtual void SAL_CALL
release() throw() { OComponentHelper::release(); }
134 virtual com::sun::star::uno::Any SAL_CALL
queryInterface( const com::sun::star::uno::Type
& reqType
)
135 throw (com::sun::star::uno::RuntimeException
);
137 public: // XCloseable
138 virtual void SAL_CALL
close( )
139 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
141 public: // XPreparedStatement
142 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> SAL_CALL
executeQuery()
143 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
144 virtual sal_Int32 SAL_CALL
executeUpdate( )
145 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
146 virtual sal_Bool SAL_CALL
execute( )
147 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
148 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XConnection
> SAL_CALL
getConnection( )
149 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
150 public: // XParameters
151 virtual void SAL_CALL
setNull( sal_Int32 parameterIndex
, sal_Int32 sqlType
)
152 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
153 virtual void SAL_CALL
setObjectNull(
154 sal_Int32 parameterIndex
, sal_Int32 sqlType
, const ::rtl::OUString
& typeName
)
155 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
156 virtual void SAL_CALL
setBoolean( sal_Int32 parameterIndex
, sal_Bool x
)
157 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
158 virtual void SAL_CALL
setByte( sal_Int32 parameterIndex
, sal_Int8 x
)
159 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
160 virtual void SAL_CALL
setShort( sal_Int32 parameterIndex
, sal_Int16 x
)
161 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
162 virtual void SAL_CALL
setInt( sal_Int32 parameterIndex
, sal_Int32 x
)
163 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
164 virtual void SAL_CALL
setLong( sal_Int32 parameterIndex
, sal_Int64 x
)
165 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
166 virtual void SAL_CALL
setFloat( sal_Int32 parameterIndex
, float x
)
167 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
168 virtual void SAL_CALL
setDouble( sal_Int32 parameterIndex
, double x
)
169 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
170 virtual void SAL_CALL
setString( sal_Int32 parameterIndex
, const ::rtl::OUString
& x
)
171 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
172 virtual void SAL_CALL
setBytes(
173 sal_Int32 parameterIndex
, const ::com::sun::star::uno::Sequence
< sal_Int8
>& x
)
174 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
175 virtual void SAL_CALL
setDate( sal_Int32 parameterIndex
, const ::com::sun::star::util::Date
& x
)
176 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
177 virtual void SAL_CALL
setTime( sal_Int32 parameterIndex
, const ::com::sun::star::util::Time
& x
)
178 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
179 virtual void SAL_CALL
setTimestamp(
180 sal_Int32 parameterIndex
, const ::com::sun::star::util::DateTime
& x
)
181 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
182 virtual void SAL_CALL
setBinaryStream(
183 sal_Int32 parameterIndex
,
184 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& x
,
186 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
187 virtual void SAL_CALL
setCharacterStream(
188 sal_Int32 parameterIndex
,
189 const ::com::sun::star::uno::Reference
< ::com::sun::star::io::XInputStream
>& x
,
191 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
192 virtual void SAL_CALL
setObject( sal_Int32 parameterIndex
, const ::com::sun::star::uno::Any
& x
)
193 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
194 virtual void SAL_CALL
setObjectWithInfo(
195 sal_Int32 parameterIndex
,
196 const ::com::sun::star::uno::Any
& x
,
197 sal_Int32 targetSqlType
,
199 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
200 virtual void SAL_CALL
setRef(
201 sal_Int32 parameterIndex
,
202 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRef
>& x
)
203 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
204 virtual void SAL_CALL
setBlob(
205 sal_Int32 parameterIndex
,
206 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XBlob
>& x
)
207 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
208 virtual void SAL_CALL
setClob(
209 sal_Int32 parameterIndex
,
210 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XClob
>& x
)
211 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
212 virtual void SAL_CALL
setArray(
213 sal_Int32 parameterIndex
,
214 const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XArray
>& x
)
215 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
216 virtual void SAL_CALL
clearParameters( )
217 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
219 public: // XWarningsSupplier
220 virtual ::com::sun::star::uno::Any SAL_CALL
getWarnings( )
221 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
222 virtual void SAL_CALL
clearWarnings( )
223 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
225 public: // XTypeProvider, first implemented by OPropertySetHelper
226 virtual com::sun::star::uno::Sequence
< com::sun::star::uno::Type
> SAL_CALL
getTypes()
227 throw( com::sun::star::uno::RuntimeException
);
228 virtual com::sun::star::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId()
229 throw( com::sun::star::uno::RuntimeException
);
231 public: // OPropertySetHelper
232 virtual cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
234 virtual sal_Bool SAL_CALL
convertFastPropertyValue(
235 ::com::sun::star::uno::Any
& rConvertedValue
,
236 ::com::sun::star::uno::Any
& rOldValue
,
238 const ::com::sun::star::uno::Any
& rValue
)
239 throw (::com::sun::star::lang::IllegalArgumentException
);
241 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast(
243 const ::com::sun::star::uno::Any
& rValue
)
244 throw (::com::sun::star::uno::Exception
);
246 virtual void SAL_CALL
getFastPropertyValue(
247 ::com::sun::star::uno::Any
& rValue
,
248 sal_Int32 nHandle
) const;
251 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo()
252 throw(com::sun::star::uno::RuntimeException
);
254 public: // XGeneratedResultSet
255 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> SAL_CALL
256 getGeneratedValues( )
257 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
259 public: // XMultipleResults
260 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> SAL_CALL
getResultSet( )
261 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
262 virtual sal_Int32 SAL_CALL
getUpdateCount( )
263 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
264 virtual sal_Bool SAL_CALL
getMoreResults( )
265 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
267 public: // XResultSetMetaDataSupplier (is required by framework (see
268 // dbaccess/source/core/api/preparedstatement.cxx::getMetaData() )
269 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSetMetaData
> SAL_CALL
getMetaData( )
270 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
);
272 public: // OComponentHelper
273 virtual void SAL_CALL
disposing();
276 void checkColumnIndex( sal_Int32 parameterIndex
);
277 void checkClosed() throw (com::sun::star::sdbc::SQLException
, com::sun::star::uno::RuntimeException
);
278 void raiseSQLException( const char * errorMsg
, const char *errorType
= 0 )
279 throw ( com::sun::star::sdbc::SQLException
);
280 // PGresult *pgExecute( ::rtl::OString *pQuery );