xref: /AOO41X/main/connectivity/source/drivers/evoab2/NPreparedStatement.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1  /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 
31 #include <stdio.h>
32 #include <osl/diagnose.h>
33 #include "NPreparedStatement.hxx"
34 #include <com/sun/star/sdbc/DataType.hpp>
35 #include <cppuhelper/typeprovider.hxx>
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include "propertyids.hxx"
38 #include <connectivity/dbexception.hxx>
39 #include <connectivity/dbtools.hxx>
40 #include <tools/diagnose_ex.h>
41 
42 #include "resource/common_res.hrc"
43 
44 using namespace connectivity::evoab;
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(OEvoabPreparedStatement,"com.sun.star.sdbcx.evoab.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
54 
55 
56 OEvoabPreparedStatement::OEvoabPreparedStatement( OEvoabConnection* _pConnection )
57     :OCommonStatement(_pConnection)
58     ,m_sSqlStatement()
59     ,m_xMetaData()
60 {
61 }
62 
63 // -----------------------------------------------------------------------------
64 void OEvoabPreparedStatement::construct( const ::rtl::OUString& _sql )
65 {
66     m_sSqlStatement = _sql;
67 
68     m_aQueryData = impl_getEBookQuery_throw( m_sSqlStatement );
69     ENSURE_OR_THROW( m_aQueryData.getQuery(), "no EBookQuery" );
70     ENSURE_OR_THROW( m_aQueryData.xSelectColumns.isValid(), "no SelectColumn" );
71 
72     // create our meta data
73     OEvoabResultSetMetaData* pMeta = new OEvoabResultSetMetaData( m_aQueryData.sTable );
74 	m_xMetaData = pMeta;
75 	pMeta->setEvoabFields( m_aQueryData.xSelectColumns );
76 }
77 
78 // -----------------------------------------------------------------------------
79 OEvoabPreparedStatement::~OEvoabPreparedStatement()
80 {
81 }
82 
83 // -----------------------------------------------------------------------------
84 void SAL_CALL OEvoabPreparedStatement::acquire() throw()
85 {
86     OCommonStatement::acquire();
87 }
88 
89 // -----------------------------------------------------------------------------
90 void SAL_CALL OEvoabPreparedStatement::release() throw()
91 {
92     OCommonStatement::release();
93 }
94 
95 // -----------------------------------------------------------------------------
96 Any SAL_CALL OEvoabPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException)
97 {
98     Any aRet = OCommonStatement::queryInterface(rType);
99     if(!aRet.hasValue())
100         aRet = OPreparedStatement_BASE::queryInterface(rType);
101     return aRet;
102 }
103 // -------------------------------------------------------------------------
104 Sequence< Type > SAL_CALL OEvoabPreparedStatement::getTypes(  ) throw(RuntimeException)
105 {
106     return ::comphelper::concatSequences(OPreparedStatement_BASE::getTypes(),OCommonStatement::getTypes());
107 }
108 // -------------------------------------------------------------------------
109 
110 Reference< XResultSetMetaData > SAL_CALL OEvoabPreparedStatement::getMetaData(  ) throw(SQLException, RuntimeException)
111 {
112     ::osl::MutexGuard aGuard( m_aMutex );
113     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
114 
115     // the meta data should have been created at construction time
116     ENSURE_OR_THROW( m_xMetaData.is(), "internal error: no meta data" );
117     return m_xMetaData;
118 }
119 // -------------------------------------------------------------------------
120 
121 void SAL_CALL OEvoabPreparedStatement::close(  ) throw(SQLException, RuntimeException)
122 {
123     ::osl::MutexGuard aGuard( m_aMutex );
124     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
125 
126     free_column_resources();
127     // Reset last warning message
128     try {
129         clearWarnings ();
130         OCommonStatement::close();
131     }
132     catch (SQLException &) {
133         // If we get an error, ignore
134     }
135 
136 }
137 // -------------------------------------------------------------------------
138 
139 sal_Bool SAL_CALL OEvoabPreparedStatement::execute(  ) throw(SQLException, RuntimeException)
140 {
141     ::osl::MutexGuard aGuard( m_aMutex );
142     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
143 
144     Reference< XResultSet> xRS = impl_executeQuery_throw( m_aQueryData );
145     return xRS.is();
146 }
147 // -------------------------------------------------------------------------
148 
149 sal_Int32 SAL_CALL OEvoabPreparedStatement::executeUpdate(  ) throw(SQLException, RuntimeException)
150 {
151     ::osl::MutexGuard aGuard( m_aMutex );
152     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
153     ::dbtools::throwFeatureNotImplementedException( "XStatement::executeUpdate", *this );
154     return 0;
155 }
156 // -------------------------------------------------------------------------
157 
158 void SAL_CALL OEvoabPreparedStatement::setString( sal_Int32 /*parameterIndex*/, const ::rtl::OUString& /*x*/ ) throw(SQLException, RuntimeException)
159 {
160     ::dbtools::throwFunctionNotSupportedException( "XParameters::setString", *this );
161 }
162 // -------------------------------------------------------------------------
163 
164 Reference< XConnection > SAL_CALL OEvoabPreparedStatement::getConnection(  ) throw(SQLException, RuntimeException)
165 {
166     ::osl::MutexGuard aGuard( m_aMutex );
167     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
168 
169     return impl_getConnection();
170 }
171 // -------------------------------------------------------------------------
172 
173 Reference< XResultSet > SAL_CALL OEvoabPreparedStatement::executeQuery(  ) throw(SQLException, RuntimeException)
174 {
175     ::osl::MutexGuard aGuard( m_aMutex );
176     checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
177 
178     return impl_executeQuery_throw( m_aQueryData );
179 }
180 // -------------------------------------------------------------------------
181 
182 void SAL_CALL OEvoabPreparedStatement::setBoolean( sal_Int32 /*parameterIndex*/, sal_Bool /*x*/ ) throw(SQLException, RuntimeException)
183 {
184     ::dbtools::throwFunctionNotSupportedException( "XParameters::setBoolean", *this );
185 
186 }
187 // -------------------------------------------------------------------------
188 void SAL_CALL OEvoabPreparedStatement::setByte( sal_Int32 /*parameterIndex*/, sal_Int8 /*x*/ ) throw(SQLException, RuntimeException)
189 {
190     ::dbtools::throwFunctionNotSupportedException( "XParameters::setByte", *this );
191 }
192 // -------------------------------------------------------------------------
193 
194 void SAL_CALL OEvoabPreparedStatement::setDate( sal_Int32 /*parameterIndex*/, const Date& /*aData*/ ) throw(SQLException, RuntimeException)
195 {
196     ::dbtools::throwFunctionNotSupportedException( "XParameters::setDate", *this );
197 }
198 // -------------------------------------------------------------------------
199 
200 void SAL_CALL OEvoabPreparedStatement::setTime( sal_Int32 /*parameterIndex*/, const Time& /*aVal*/ ) throw(SQLException, RuntimeException)
201 {
202     ::dbtools::throwFunctionNotSupportedException( "XParameters::setTime", *this );
203 }
204 // -------------------------------------------------------------------------
205 
206 void SAL_CALL OEvoabPreparedStatement::setTimestamp( sal_Int32 /*parameterIndex*/, const DateTime& /*aVal*/ ) throw(SQLException, RuntimeException)
207 {
208     ::dbtools::throwFunctionNotSupportedException( "XParameters::setTimestamp", *this );
209 }
210 // -------------------------------------------------------------------------
211 
212 void SAL_CALL OEvoabPreparedStatement::setDouble( sal_Int32 /*parameterIndex*/, double /*x*/ ) throw(SQLException, RuntimeException)
213 {
214     ::dbtools::throwFunctionNotSupportedException( "XParameters::setDouble", *this );
215 }
216 
217 // -------------------------------------------------------------------------
218 
219 void SAL_CALL OEvoabPreparedStatement::setFloat( sal_Int32 /*parameterIndex*/, float /*x*/ ) throw(SQLException, RuntimeException)
220 {
221     ::dbtools::throwFunctionNotSupportedException( "XParameters::setFloat", *this );
222 }
223 // -------------------------------------------------------------------------
224 
225 void SAL_CALL OEvoabPreparedStatement::setInt( sal_Int32 /*parameterIndex*/, sal_Int32 /*x*/ ) throw(SQLException, RuntimeException)
226 {
227     ::dbtools::throwFunctionNotSupportedException( "XParameters::setInt", *this );
228 }
229 // -------------------------------------------------------------------------
230 
231 void SAL_CALL OEvoabPreparedStatement::setLong( sal_Int32 /*parameterIndex*/, sal_Int64 /*aVal*/ ) throw(SQLException, RuntimeException)
232 {
233     ::dbtools::throwFunctionNotSupportedException( "XParameters::setLong", *this );
234 }
235 // -------------------------------------------------------------------------
236 
237 void SAL_CALL OEvoabPreparedStatement::setNull( sal_Int32 /*parameterIndex*/, sal_Int32 /*sqlType*/ ) throw(SQLException, RuntimeException)
238 {
239     ::dbtools::throwFunctionNotSupportedException( "XParameters::setNull", *this );
240 }
241 // -------------------------------------------------------------------------
242 
243 void SAL_CALL OEvoabPreparedStatement::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) throw(SQLException, RuntimeException)
244 {
245     ::dbtools::throwFunctionNotSupportedException( "XParameters::setClob", *this );
246 }
247 // -------------------------------------------------------------------------
248 
249 void SAL_CALL OEvoabPreparedStatement::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) throw(SQLException, RuntimeException)
250 {
251     ::dbtools::throwFunctionNotSupportedException( "XParameters::setBlob", *this );
252 }
253 // -------------------------------------------------------------------------
254 
255 void SAL_CALL OEvoabPreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) throw(SQLException, RuntimeException)
256 {
257     ::dbtools::throwFunctionNotSupportedException( "XParameters::setArray", *this );
258 }
259 // -------------------------------------------------------------------------
260 
261 void SAL_CALL OEvoabPreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) throw(SQLException, RuntimeException)
262 {
263     ::dbtools::throwFunctionNotSupportedException( "XParameters::setRef", *this );
264 }
265 // -------------------------------------------------------------------------
266 
267 void SAL_CALL OEvoabPreparedStatement::setObjectWithInfo( sal_Int32 /*parameterIndex*/, const Any& /*x*/, sal_Int32 /*sqlType*/, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
268 {
269     ::dbtools::throwFunctionNotSupportedException( "XParameters::setObjectWithInfo", *this );
270 }
271 // -------------------------------------------------------------------------
272 
273 void SAL_CALL OEvoabPreparedStatement::setObjectNull( sal_Int32 /*parameterIndex*/, sal_Int32 /*sqlType*/, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, RuntimeException)
274 {
275     ::dbtools::throwFunctionNotSupportedException( "XParameters::setObjectNull", *this );
276 }
277 // -------------------------------------------------------------------------
278 
279 void SAL_CALL OEvoabPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException)
280 {
281     if(!::dbtools::implSetObject(this,parameterIndex,x))
282     {
283         const ::rtl::OUString sError( getOwnConnection()->getResources().getResourceStringWithSubstitution(
284                 STR_UNKNOWN_PARA_TYPE,
285                 "$position$", ::rtl::OUString::valueOf(parameterIndex)
286              ) );
287         ::dbtools::throwGenericSQLException(sError,*this);
288     }
289 }
290 // -------------------------------------------------------------------------
291 
292 void SAL_CALL OEvoabPreparedStatement::setShort( sal_Int32 /*parameterIndex*/, sal_Int16 /*x*/ ) throw(SQLException, RuntimeException)
293 {
294     ::dbtools::throwFunctionNotSupportedException( "XParameters::setShort", *this );
295 }
296 // -------------------------------------------------------------------------
297 
298 void SAL_CALL OEvoabPreparedStatement::setBytes( sal_Int32 /*parameterIndex*/, const Sequence< sal_Int8 >& /*x*/ ) throw(SQLException, RuntimeException)
299 {
300     ::dbtools::throwFunctionNotSupportedException( "XParameters::setBytes", *this );
301 }
302 // -------------------------------------------------------------------------
303 
304 
305 void SAL_CALL OEvoabPreparedStatement::setCharacterStream( sal_Int32 /*parameterIndex*/, const Reference< XInputStream >& /*x*/, sal_Int32 /*length*/ ) throw(SQLException, RuntimeException)
306 {
307     ::dbtools::throwFunctionNotSupportedException( "XParameters::setCharacterStream", *this );
308 }
309 // -------------------------------------------------------------------------
310 
311 void SAL_CALL OEvoabPreparedStatement::setBinaryStream( sal_Int32 /*parameterIndex*/, const Reference< XInputStream >& /*x*/, sal_Int32 /*length*/ ) throw(SQLException, RuntimeException)
312 {
313     ::dbtools::throwFunctionNotSupportedException( "XParameters::setBinaryStream", *this );
314 }
315 // -------------------------------------------------------------------------
316 
317 void SAL_CALL OEvoabPreparedStatement::clearParameters(  ) throw(SQLException, RuntimeException)
318 {
319 }
320 // -----------------------------------------------------------------------------
321 Reference< XResultSet > SAL_CALL OEvoabPreparedStatement::getResultSet(  ) throw(SQLException, RuntimeException)
322 {
323     return NULL;
324 }
325 // -----------------------------------------------------------------------------
326 sal_Int32 SAL_CALL OEvoabPreparedStatement::getUpdateCount(  ) throw(SQLException, RuntimeException)
327 {
328     return 0;
329 }
330 // -----------------------------------------------------------------------------
331 sal_Bool SAL_CALL OEvoabPreparedStatement::getMoreResults(  ) throw(SQLException, RuntimeException)
332 {
333     return sal_False;
334 }
335 // -----------------------------------------------------------------------------
336