1 /*************************************************************************
2  *
3  *  The Contents of this file are made available subject to the terms of
4  *  the BSD license.
5  *
6  *  Copyright 2000, 2010 Oracle and/or its affiliates.
7  *  All rights reserved.
8  *
9  *  Redistribution and use in source and binary forms, with or without
10  *  modification, are permitted provided that the following conditions
11  *  are met:
12  *  1. Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *  2. Redistributions in binary form must reproduce the above copyright
15  *     notice, this list of conditions and the following disclaimer in the
16  *     documentation and/or other materials provided with the distribution.
17  *  3. Neither the name of Sun Microsystems, Inc. nor the names of its
18  *     contributors may be used to endorse or promote products derived
19  *     from this software without specific prior written permission.
20  *
21  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
30  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
31  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  *************************************************************************/
34 
35 #include <stdio.h>
36 #include <osl/diagnose.h>
37 #include "SPreparedStatement.hxx"
38 #include <com/sun/star/sdbc/DataType.hpp>
39 #include "SResultSetMetaData.hxx"
40 #include <cppuhelper/typeprovider.hxx>
41 #include <com/sun/star/lang/DisposedException.hpp>
42 #include "propertyids.hxx"
43 
44 using namespace connectivity::skeleton;
45 using namespace com::sun::star::uno;
46 using namespace com::sun::star::lang;
47 using namespace com::sun::star::beans;
48 using namespace com::sun::star::sdbc;
49 using namespace com::sun::star::container;
50 using namespace com::sun::star::io;
51 using namespace com::sun::star::util;
52 
53 IMPLEMENT_SERVICE_INFO(OPreparedStatement,"com.sun.star.sdbcx.skeleton.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
54 
55 
56 OPreparedStatement::OPreparedStatement( OConnection* _pConnection,const TTypeInfoVector& _TypeInfo,const ::rtl::OUString& sql)
57 	:OStatement_BASE2(_pConnection)
58 	,m_aTypeInfo(_TypeInfo)
59 	,m_bPrepared(sal_False)
60 	,m_sSqlStatement(sql)
61 	,m_nNumParams(0)
62 {
63 }
64 // -----------------------------------------------------------------------------
65 OPreparedStatement::~OPreparedStatement()
66 {
67 }
68 // -----------------------------------------------------------------------------
69 void SAL_CALL OPreparedStatement::acquire() throw()
70 {
71 	OStatement_BASE2::acquire();
72 }
73 // -----------------------------------------------------------------------------
74 void SAL_CALL OPreparedStatement::release() throw()
75 {
76 	OStatement_BASE2::release();
77 }
78 // -----------------------------------------------------------------------------
79 Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException)
80 {
81 	Any aRet = OStatement_BASE2::queryInterface(rType);
82 	if(!aRet.hasValue())
83 		aRet = OPreparedStatement_BASE::queryInterface(rType);
84 	return aRet;
85 }
86 // -------------------------------------------------------------------------
87 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OPreparedStatement::getTypes(  ) throw(::com::sun::star::uno::RuntimeException)
88 {
89 	return concatSequences(OPreparedStatement_BASE::getTypes(),OStatement_BASE2::getTypes());
90 }
91 // -------------------------------------------------------------------------
92 
93 Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData(  ) throw(SQLException, RuntimeException)
94 {
95 	::osl::MutexGuard aGuard( m_aMutex );
96 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
97 
98 	if(!m_xMetaData.is())
99 		m_xMetaData = new OResultSetMetaData(getOwnConnection());
100 	return m_xMetaData;
101 }
102 // -------------------------------------------------------------------------
103 
104 void SAL_CALL OPreparedStatement::close(  ) throw(SQLException, RuntimeException)
105 {
106 	::osl::MutexGuard aGuard( m_aMutex );
107 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
108 
109 
110 	// Reset last warning message
111 
112 	try {
113 		clearWarnings ();
114 		OStatement_BASE2::close();
115 	}
116 	catch (SQLException &) {
117 		// If we get an error, ignore
118 	}
119 
120 	// Remove this Statement object from the Connection object's
121 	// list
122 }
123 // -------------------------------------------------------------------------
124 
125 sal_Bool SAL_CALL OPreparedStatement::execute(  ) throw(SQLException, RuntimeException)
126 {
127 	::osl::MutexGuard aGuard( m_aMutex );
128 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
129 
130 
131 	// same as in statement with the difference that this statement also can contain parameter
132 	return sal_False;
133 }
134 // -------------------------------------------------------------------------
135 
136 sal_Int32 SAL_CALL OPreparedStatement::executeUpdate(  ) throw(SQLException, RuntimeException)
137 {
138 	::osl::MutexGuard aGuard( m_aMutex );
139 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
140 
141 	// same as in statement with the difference that this statement also can contain parameter
142 	return 0;
143 }
144 // -------------------------------------------------------------------------
145 
146 void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
147 {
148 	::osl::MutexGuard aGuard( m_aMutex );
149 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
150 }
151 // -------------------------------------------------------------------------
152 
153 Reference< XConnection > SAL_CALL OPreparedStatement::getConnection(  ) throw(SQLException, RuntimeException)
154 {
155 	::osl::MutexGuard aGuard( m_aMutex );
156 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
157 
158 	return (Reference< XConnection >)m_pConnection;
159 }
160 // -------------------------------------------------------------------------
161 
162 Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery(  ) throw(SQLException, RuntimeException)
163 {
164 	::osl::MutexGuard aGuard( m_aMutex );
165 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
166 
167 	Reference< XResultSet > rs = NULL;
168 
169 
170 	return rs;
171 }
172 // -------------------------------------------------------------------------
173 
174 void SAL_CALL OPreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(SQLException, RuntimeException)
175 {
176 	::osl::MutexGuard aGuard( m_aMutex );
177 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
178 
179 }
180 // -------------------------------------------------------------------------
181 void SAL_CALL OPreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(SQLException, RuntimeException)
182 {
183 	::osl::MutexGuard aGuard( m_aMutex );
184 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
185 
186 
187 }
188 // -------------------------------------------------------------------------
189 
190 void SAL_CALL OPreparedStatement::setDate( sal_Int32 parameterIndex, const Date& aData ) throw(SQLException, RuntimeException)
191 {
192 	::osl::MutexGuard aGuard( m_aMutex );
193 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
194 
195 }
196 // -------------------------------------------------------------------------
197 
198 
199 void SAL_CALL OPreparedStatement::setTime( sal_Int32 parameterIndex, const Time& aVal ) throw(SQLException, RuntimeException)
200 {
201 	::osl::MutexGuard aGuard( m_aMutex );
202 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
203 
204 }
205 // -------------------------------------------------------------------------
206 
207 void SAL_CALL OPreparedStatement::setTimestamp( sal_Int32 parameterIndex, const DateTime& aVal ) throw(SQLException, RuntimeException)
208 {
209 	::osl::MutexGuard aGuard( m_aMutex );
210 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
211 
212 }
213 // -------------------------------------------------------------------------
214 
215 void SAL_CALL OPreparedStatement::setDouble( sal_Int32 parameterIndex, double x ) throw(SQLException, RuntimeException)
216 {
217 	::osl::MutexGuard aGuard( m_aMutex );
218 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
219 
220 }
221 
222 // -------------------------------------------------------------------------
223 
224 void SAL_CALL OPreparedStatement::setFloat( sal_Int32 parameterIndex, float x ) throw(SQLException, RuntimeException)
225 {
226 	::osl::MutexGuard aGuard( m_aMutex );
227 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
228 
229 }
230 // -------------------------------------------------------------------------
231 
232 void SAL_CALL OPreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x ) throw(SQLException, RuntimeException)
233 {
234 	::osl::MutexGuard aGuard( m_aMutex );
235 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
236 
237 }
238 // -------------------------------------------------------------------------
239 
240 void SAL_CALL OPreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 aVal ) throw(SQLException, RuntimeException)
241 {
242 	::osl::MutexGuard aGuard( m_aMutex );
243 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
244 
245 }
246 // -------------------------------------------------------------------------
247 
248 void SAL_CALL OPreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(SQLException, RuntimeException)
249 {
250 	::osl::MutexGuard aGuard( m_aMutex );
251 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
252 
253 }
254 // -------------------------------------------------------------------------
255 
256 void SAL_CALL OPreparedStatement::setClob( sal_Int32 parameterIndex, const Reference< XClob >& x ) throw(SQLException, RuntimeException)
257 {
258 	::osl::MutexGuard aGuard( m_aMutex );
259 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
260 
261 }
262 // -------------------------------------------------------------------------
263 
264 void SAL_CALL OPreparedStatement::setBlob( sal_Int32 parameterIndex, const Reference< XBlob >& x ) throw(SQLException, RuntimeException)
265 {
266 	::osl::MutexGuard aGuard( m_aMutex );
267 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
268 
269 }
270 // -------------------------------------------------------------------------
271 
272 void SAL_CALL OPreparedStatement::setArray( sal_Int32 parameterIndex, const Reference< XArray >& x ) throw(SQLException, RuntimeException)
273 {
274 	::osl::MutexGuard aGuard( m_aMutex );
275 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
276 
277 }
278 // -------------------------------------------------------------------------
279 
280 void SAL_CALL OPreparedStatement::setRef( sal_Int32 parameterIndex, const Reference< XRef >& x ) throw(SQLException, RuntimeException)
281 {
282 	::osl::MutexGuard aGuard( m_aMutex );
283 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
284 
285 }
286 // -------------------------------------------------------------------------
287 
288 void SAL_CALL OPreparedStatement::setObjectWithInfo( sal_Int32 parameterIndex, const Any& x, sal_Int32 sqlType, sal_Int32 scale ) throw(SQLException, RuntimeException)
289 {
290 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
291 	::osl::MutexGuard aGuard( m_aMutex );
292 
293 }
294 // -------------------------------------------------------------------------
295 
296 void SAL_CALL OPreparedStatement::setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName ) throw(SQLException, RuntimeException)
297 {
298 	::osl::MutexGuard aGuard( m_aMutex );
299 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
300 
301 }
302 // -------------------------------------------------------------------------
303 
304 void SAL_CALL OPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException)
305 {
306 	::osl::MutexGuard aGuard( m_aMutex );
307 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
308 
309 }
310 // -------------------------------------------------------------------------
311 
312 void SAL_CALL OPreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x ) throw(SQLException, RuntimeException)
313 {
314 	::osl::MutexGuard aGuard( m_aMutex );
315 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
316 
317 }
318 // -------------------------------------------------------------------------
319 
320 void SAL_CALL OPreparedStatement::setBytes( sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x ) throw(SQLException, RuntimeException)
321 {
322 	::osl::MutexGuard aGuard( m_aMutex );
323 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
324 
325 }
326 // -------------------------------------------------------------------------
327 
328 
329 void SAL_CALL OPreparedStatement::setCharacterStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
330 {
331 	::osl::MutexGuard aGuard( m_aMutex );
332 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
333 
334 }
335 // -------------------------------------------------------------------------
336 
337 void SAL_CALL OPreparedStatement::setBinaryStream( sal_Int32 parameterIndex, const Reference< ::com::sun::star::io::XInputStream >& x, sal_Int32 length ) throw(SQLException, RuntimeException)
338 {
339 	::osl::MutexGuard aGuard( m_aMutex );
340 	checkDisposed(OStatement_BASE::rBHelper.bDisposed);
341 
342 }
343 // -------------------------------------------------------------------------
344 
345 void SAL_CALL OPreparedStatement::clearParameters(  ) throw(SQLException, RuntimeException)
346 {
347 }
348 // -------------------------------------------------------------------------
349 void SAL_CALL OPreparedStatement::clearBatch(  ) throw(SQLException, RuntimeException)
350 {
351 }
352 // -------------------------------------------------------------------------
353 
354 void SAL_CALL OPreparedStatement::addBatch( ) throw(SQLException, RuntimeException)
355 {
356 }
357 // -------------------------------------------------------------------------
358 
359 Sequence< sal_Int32 > SAL_CALL OPreparedStatement::executeBatch(  ) throw(SQLException, RuntimeException)
360 {
361 	return Sequence< sal_Int32 > ();
362 }
363 // -------------------------------------------------------------------------
364 void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
365 {
366 	switch(nHandle)
367 	{
368 		case PROPERTY_ID_RESULTSETCONCURRENCY:
369 			break;
370 		case PROPERTY_ID_RESULTSETTYPE:
371 			break;
372 		case PROPERTY_ID_FETCHDIRECTION:
373 			break;
374 		case PROPERTY_ID_USEBOOKMARKS:
375 			break;
376 		default:
377 			OStatement_Base::setFastPropertyValue_NoBroadcast(nHandle,rValue);
378 	}
379 }
380 // -----------------------------------------------------------------------------
381 void OPreparedStatement::checkParameterIndex(sal_Int32 _parameterIndex)
382 {
383 	if(	!_parameterIndex || _parameterIndex > m_nNumParams)
384 		throw SQLException();
385 }
386 // -----------------------------------------------------------------------------
387 
388 
389