merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / evoab2 / NPreparedStatement.cxx
blob3efcdc740ebf6853912a819f91561f590bdacd96
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 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
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>
42 #include "resource/common_res.hrc"
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;
53 IMPLEMENT_SERVICE_INFO(OEvoabPreparedStatement,"com.sun.star.sdbcx.evoab.PreparedStatement","com.sun.star.sdbc.PreparedStatement");
56 OEvoabPreparedStatement::OEvoabPreparedStatement( OEvoabConnection* _pConnection )
57 :OCommonStatement(_pConnection)
58 ,m_sSqlStatement()
59 ,m_xMetaData()
63 // -----------------------------------------------------------------------------
64 void OEvoabPreparedStatement::construct( const ::rtl::OUString& _sql )
66 m_sSqlStatement = _sql;
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" );
72 // create our meta data
73 OEvoabResultSetMetaData* pMeta = new OEvoabResultSetMetaData( m_aQueryData.sTable );
74 m_xMetaData = pMeta;
75 pMeta->setEvoabFields( m_aQueryData.xSelectColumns );
78 // -----------------------------------------------------------------------------
79 OEvoabPreparedStatement::~OEvoabPreparedStatement()
83 // -----------------------------------------------------------------------------
84 void SAL_CALL OEvoabPreparedStatement::acquire() throw()
86 OCommonStatement::acquire();
89 // -----------------------------------------------------------------------------
90 void SAL_CALL OEvoabPreparedStatement::release() throw()
92 OCommonStatement::release();
95 // -----------------------------------------------------------------------------
96 Any SAL_CALL OEvoabPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException)
98 Any aRet = OCommonStatement::queryInterface(rType);
99 if(!aRet.hasValue())
100 aRet = OPreparedStatement_BASE::queryInterface(rType);
101 return aRet;
103 // -------------------------------------------------------------------------
104 Sequence< Type > SAL_CALL OEvoabPreparedStatement::getTypes( ) throw(RuntimeException)
106 return ::comphelper::concatSequences(OPreparedStatement_BASE::getTypes(),OCommonStatement::getTypes());
108 // -------------------------------------------------------------------------
110 Reference< XResultSetMetaData > SAL_CALL OEvoabPreparedStatement::getMetaData( ) throw(SQLException, RuntimeException)
112 ::osl::MutexGuard aGuard( m_aMutex );
113 checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
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;
119 // -------------------------------------------------------------------------
121 void SAL_CALL OEvoabPreparedStatement::close( ) throw(SQLException, RuntimeException)
123 ::osl::MutexGuard aGuard( m_aMutex );
124 checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
126 free_column_resources();
127 // Reset last warning message
128 try {
129 clearWarnings ();
130 OCommonStatement::close();
132 catch (SQLException &) {
133 // If we get an error, ignore
137 // -------------------------------------------------------------------------
139 sal_Bool SAL_CALL OEvoabPreparedStatement::execute( ) throw(SQLException, RuntimeException)
141 ::osl::MutexGuard aGuard( m_aMutex );
142 checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
144 Reference< XResultSet> xRS = impl_executeQuery_throw( m_aQueryData );
145 return xRS.is();
147 // -------------------------------------------------------------------------
149 sal_Int32 SAL_CALL OEvoabPreparedStatement::executeUpdate( ) throw(SQLException, RuntimeException)
151 ::osl::MutexGuard aGuard( m_aMutex );
152 checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
153 ::dbtools::throwFeatureNotImplementedException( "XStatement::executeUpdate", *this );
154 return 0;
156 // -------------------------------------------------------------------------
158 void SAL_CALL OEvoabPreparedStatement::setString( sal_Int32 /*parameterIndex*/, const ::rtl::OUString& /*x*/ ) throw(SQLException, RuntimeException)
160 ::dbtools::throwFunctionNotSupportedException( "XParameters::setString", *this );
162 // -------------------------------------------------------------------------
164 Reference< XConnection > SAL_CALL OEvoabPreparedStatement::getConnection( ) throw(SQLException, RuntimeException)
166 ::osl::MutexGuard aGuard( m_aMutex );
167 checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
169 return impl_getConnection();
171 // -------------------------------------------------------------------------
173 Reference< XResultSet > SAL_CALL OEvoabPreparedStatement::executeQuery( ) throw(SQLException, RuntimeException)
175 ::osl::MutexGuard aGuard( m_aMutex );
176 checkDisposed(OCommonStatement_IBase::rBHelper.bDisposed);
178 return impl_executeQuery_throw( m_aQueryData );
180 // -------------------------------------------------------------------------
182 void SAL_CALL OEvoabPreparedStatement::setBoolean( sal_Int32 /*parameterIndex*/, sal_Bool /*x*/ ) throw(SQLException, RuntimeException)
184 ::dbtools::throwFunctionNotSupportedException( "XParameters::setBoolean", *this );
187 // -------------------------------------------------------------------------
188 void SAL_CALL OEvoabPreparedStatement::setByte( sal_Int32 /*parameterIndex*/, sal_Int8 /*x*/ ) throw(SQLException, RuntimeException)
190 ::dbtools::throwFunctionNotSupportedException( "XParameters::setByte", *this );
192 // -------------------------------------------------------------------------
194 void SAL_CALL OEvoabPreparedStatement::setDate( sal_Int32 /*parameterIndex*/, const Date& /*aData*/ ) throw(SQLException, RuntimeException)
196 ::dbtools::throwFunctionNotSupportedException( "XParameters::setDate", *this );
198 // -------------------------------------------------------------------------
200 void SAL_CALL OEvoabPreparedStatement::setTime( sal_Int32 /*parameterIndex*/, const Time& /*aVal*/ ) throw(SQLException, RuntimeException)
202 ::dbtools::throwFunctionNotSupportedException( "XParameters::setTime", *this );
204 // -------------------------------------------------------------------------
206 void SAL_CALL OEvoabPreparedStatement::setTimestamp( sal_Int32 /*parameterIndex*/, const DateTime& /*aVal*/ ) throw(SQLException, RuntimeException)
208 ::dbtools::throwFunctionNotSupportedException( "XParameters::setTimestamp", *this );
210 // -------------------------------------------------------------------------
212 void SAL_CALL OEvoabPreparedStatement::setDouble( sal_Int32 /*parameterIndex*/, double /*x*/ ) throw(SQLException, RuntimeException)
214 ::dbtools::throwFunctionNotSupportedException( "XParameters::setDouble", *this );
217 // -------------------------------------------------------------------------
219 void SAL_CALL OEvoabPreparedStatement::setFloat( sal_Int32 /*parameterIndex*/, float /*x*/ ) throw(SQLException, RuntimeException)
221 ::dbtools::throwFunctionNotSupportedException( "XParameters::setFloat", *this );
223 // -------------------------------------------------------------------------
225 void SAL_CALL OEvoabPreparedStatement::setInt( sal_Int32 /*parameterIndex*/, sal_Int32 /*x*/ ) throw(SQLException, RuntimeException)
227 ::dbtools::throwFunctionNotSupportedException( "XParameters::setInt", *this );
229 // -------------------------------------------------------------------------
231 void SAL_CALL OEvoabPreparedStatement::setLong( sal_Int32 /*parameterIndex*/, sal_Int64 /*aVal*/ ) throw(SQLException, RuntimeException)
233 ::dbtools::throwFunctionNotSupportedException( "XParameters::setLong", *this );
235 // -------------------------------------------------------------------------
237 void SAL_CALL OEvoabPreparedStatement::setNull( sal_Int32 /*parameterIndex*/, sal_Int32 /*sqlType*/ ) throw(SQLException, RuntimeException)
239 ::dbtools::throwFunctionNotSupportedException( "XParameters::setNull", *this );
241 // -------------------------------------------------------------------------
243 void SAL_CALL OEvoabPreparedStatement::setClob( sal_Int32 /*parameterIndex*/, const Reference< XClob >& /*x*/ ) throw(SQLException, RuntimeException)
245 ::dbtools::throwFunctionNotSupportedException( "XParameters::setClob", *this );
247 // -------------------------------------------------------------------------
249 void SAL_CALL OEvoabPreparedStatement::setBlob( sal_Int32 /*parameterIndex*/, const Reference< XBlob >& /*x*/ ) throw(SQLException, RuntimeException)
251 ::dbtools::throwFunctionNotSupportedException( "XParameters::setBlob", *this );
253 // -------------------------------------------------------------------------
255 void SAL_CALL OEvoabPreparedStatement::setArray( sal_Int32 /*parameterIndex*/, const Reference< XArray >& /*x*/ ) throw(SQLException, RuntimeException)
257 ::dbtools::throwFunctionNotSupportedException( "XParameters::setArray", *this );
259 // -------------------------------------------------------------------------
261 void SAL_CALL OEvoabPreparedStatement::setRef( sal_Int32 /*parameterIndex*/, const Reference< XRef >& /*x*/ ) throw(SQLException, RuntimeException)
263 ::dbtools::throwFunctionNotSupportedException( "XParameters::setRef", *this );
265 // -------------------------------------------------------------------------
267 void SAL_CALL OEvoabPreparedStatement::setObjectWithInfo( sal_Int32 /*parameterIndex*/, const Any& /*x*/, sal_Int32 /*sqlType*/, sal_Int32 /*scale*/ ) throw(SQLException, RuntimeException)
269 ::dbtools::throwFunctionNotSupportedException( "XParameters::setObjectWithInfo", *this );
271 // -------------------------------------------------------------------------
273 void SAL_CALL OEvoabPreparedStatement::setObjectNull( sal_Int32 /*parameterIndex*/, sal_Int32 /*sqlType*/, const ::rtl::OUString& /*typeName*/ ) throw(SQLException, RuntimeException)
275 ::dbtools::throwFunctionNotSupportedException( "XParameters::setObjectNull", *this );
277 // -------------------------------------------------------------------------
279 void SAL_CALL OEvoabPreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x ) throw(SQLException, RuntimeException)
281 if(!::dbtools::implSetObject(this,parameterIndex,x))
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);
290 // -------------------------------------------------------------------------
292 void SAL_CALL OEvoabPreparedStatement::setShort( sal_Int32 /*parameterIndex*/, sal_Int16 /*x*/ ) throw(SQLException, RuntimeException)
294 ::dbtools::throwFunctionNotSupportedException( "XParameters::setShort", *this );
296 // -------------------------------------------------------------------------
298 void SAL_CALL OEvoabPreparedStatement::setBytes( sal_Int32 /*parameterIndex*/, const Sequence< sal_Int8 >& /*x*/ ) throw(SQLException, RuntimeException)
300 ::dbtools::throwFunctionNotSupportedException( "XParameters::setBytes", *this );
302 // -------------------------------------------------------------------------
305 void SAL_CALL OEvoabPreparedStatement::setCharacterStream( sal_Int32 /*parameterIndex*/, const Reference< XInputStream >& /*x*/, sal_Int32 /*length*/ ) throw(SQLException, RuntimeException)
307 ::dbtools::throwFunctionNotSupportedException( "XParameters::setCharacterStream", *this );
309 // -------------------------------------------------------------------------
311 void SAL_CALL OEvoabPreparedStatement::setBinaryStream( sal_Int32 /*parameterIndex*/, const Reference< XInputStream >& /*x*/, sal_Int32 /*length*/ ) throw(SQLException, RuntimeException)
313 ::dbtools::throwFunctionNotSupportedException( "XParameters::setBinaryStream", *this );
315 // -------------------------------------------------------------------------
317 void SAL_CALL OEvoabPreparedStatement::clearParameters( ) throw(SQLException, RuntimeException)
320 // -----------------------------------------------------------------------------
321 Reference< XResultSet > SAL_CALL OEvoabPreparedStatement::getResultSet( ) throw(SQLException, RuntimeException)
323 return NULL;
325 // -----------------------------------------------------------------------------
326 sal_Int32 SAL_CALL OEvoabPreparedStatement::getUpdateCount( ) throw(SQLException, RuntimeException)
328 return 0;
330 // -----------------------------------------------------------------------------
331 sal_Bool SAL_CALL OEvoabPreparedStatement::getMoreResults( ) throw(SQLException, RuntimeException)
333 return sal_False;
335 // -----------------------------------------------------------------------------