update dev300-m58
[ooovba.git] / connectivity / source / drivers / kab / KPreparedStatement.cxx
blobf26b06d120a662fa6635b89cf682bd48b2414c56
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: KPreparedStatement.cxx,v $
10 * $Revision: 1.6.56.2 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "KPreparedStatement.hxx"
35 #include "propertyids.hxx"
36 #include <connectivity/dbexception.hxx>
37 #include <connectivity/dbtools.hxx>
38 #include "resource/kab_res.hrc"
39 #include "resource/sharedresources.hxx"
41 using namespace connectivity::kab;
42 using namespace com::sun::star::uno;
43 using namespace com::sun::star::lang;
44 using namespace com::sun::star::sdbc;
45 using namespace com::sun::star::util;
47 IMPLEMENT_SERVICE_INFO(KabPreparedStatement, "com.sun.star.sdbc.drivers.KabPreparedStatement", "com.sun.star.sdbc.PreparedStatement");
48 // -------------------------------------------------------------------------
49 void KabPreparedStatement::checkAndResizeParameters(sal_Int32 nParams) throw(SQLException)
51 if ( !m_aParameterRow.isValid() )
52 m_aParameterRow = new OValueVector();
54 if (nParams < 1)
55 ::dbtools::throwInvalidIndexException(*(KabPreparedStatement *) this,Any());
57 if (nParams >= (sal_Int32) (m_aParameterRow->get()).size())
58 (m_aParameterRow->get()).resize(nParams);
60 // -------------------------------------------------------------------------
61 void KabPreparedStatement::setKabFields() const throw(SQLException)
63 ::vos::ORef<connectivity::OSQLColumns> xColumns; // selected columns
65 xColumns = m_aSQLIterator.getSelectColumns();
66 if (!xColumns.isValid())
68 ::connectivity::SharedResources aResources;
69 const ::rtl::OUString sError( aResources.getResourceString(
70 STR_INVALID_COLUMN_SELECTION
71 ) );
72 ::dbtools::throwGenericSQLException(sError,NULL);
74 m_xMetaData->setKabFields(xColumns);
76 // -------------------------------------------------------------------------
77 void KabPreparedStatement::resetParameters() const throw(SQLException)
79 m_nParameterIndex = 0;
81 // -------------------------------------------------------------------------
82 void KabPreparedStatement::getNextParameter(::rtl::OUString &rParameter) const throw(SQLException)
84 if (m_nParameterIndex >= (sal_Int32) (m_aParameterRow->get()).size())
86 ::connectivity::SharedResources aResources;
87 const ::rtl::OUString sError( aResources.getResourceString(
88 STR_INVALID_PARA_COUNT
89 ) );
90 ::dbtools::throwGenericSQLException(sError,*(KabPreparedStatement *) this);
91 } // if (m_nParameterIndex >= (sal_Int32) (*m_aParameterRow).size())
93 rParameter = (m_aParameterRow->get())[m_nParameterIndex];
95 m_nParameterIndex++;
97 // -------------------------------------------------------------------------
98 KabPreparedStatement::KabPreparedStatement(
99 KabConnection* _pConnection,
100 const ::rtl::OUString& sql)
101 : KabPreparedStatement_BASE(_pConnection),
102 m_sSqlStatement(sql),
103 m_bPrepared(sal_False),
104 m_nParameterIndex(0),
105 m_aParameterRow()
108 // -------------------------------------------------------------------------
109 KabPreparedStatement::~KabPreparedStatement()
112 // -------------------------------------------------------------------------
113 void KabPreparedStatement::disposing()
115 KabPreparedStatement_BASE::disposing();
117 if (m_aParameterRow.isValid())
119 m_aParameterRow->get().clear();
120 m_aParameterRow = NULL;
123 // -------------------------------------------------------------------------
124 Reference< XResultSetMetaData > SAL_CALL KabPreparedStatement::getMetaData() throw(SQLException, RuntimeException)
126 ::osl::MutexGuard aGuard( m_aMutex );
127 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed);
129 if (!m_xMetaData.is())
131 m_xMetaData = new KabResultSetMetaData(getOwnConnection());
132 setKabFields();
134 Reference< XResultSetMetaData > xMetaData = m_xMetaData.get();
135 return xMetaData;
137 // -------------------------------------------------------------------------
138 void SAL_CALL KabPreparedStatement::close() throw(SQLException, RuntimeException)
140 ::osl::MutexGuard aGuard( m_aMutex );
141 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed);
143 // Reset last warning message
144 try {
145 clearWarnings ();
146 KabCommonStatement::close();
148 catch (SQLException &) {
149 // If we get an error, ignore
152 // Remove this Statement object from the Connection object's
153 // list
155 // -------------------------------------------------------------------------
156 sal_Bool SAL_CALL KabPreparedStatement::execute() throw(SQLException, RuntimeException)
158 ::osl::MutexGuard aGuard( m_aMutex );
159 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed);
161 Reference< XResultSet> xRS = KabCommonStatement::executeQuery(m_sSqlStatement);
163 return xRS.is();
165 // -------------------------------------------------------------------------
166 sal_Int32 SAL_CALL KabPreparedStatement::executeUpdate() throw(SQLException, RuntimeException)
168 ::osl::MutexGuard aGuard( m_aMutex );
169 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed);
171 // same as in statement with the difference that this statement also can contain parameter
172 return 0;
174 // -------------------------------------------------------------------------
175 Reference< XConnection > SAL_CALL KabPreparedStatement::getConnection() throw(SQLException, RuntimeException)
177 ::osl::MutexGuard aGuard( m_aMutex );
178 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed);
180 return (Reference< XConnection >) m_pConnection;
182 // -------------------------------------------------------------------------
183 Reference< XResultSet > SAL_CALL KabPreparedStatement::executeQuery() throw(SQLException, RuntimeException)
185 ::osl::MutexGuard aGuard( m_aMutex );
186 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed);
188 Reference< XResultSet > rs = KabCommonStatement::executeQuery(m_sSqlStatement);
190 return rs;
192 // -------------------------------------------------------------------------
193 void SAL_CALL KabPreparedStatement::setNull(sal_Int32 parameterIndex, sal_Int32) throw(SQLException, RuntimeException)
195 ::osl::MutexGuard aGuard( m_aMutex );
196 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed);
198 checkAndResizeParameters(parameterIndex);
200 (m_aParameterRow->get())[parameterIndex - 1].setNull();
202 // -------------------------------------------------------------------------
203 void SAL_CALL KabPreparedStatement::setObjectNull(sal_Int32, sal_Int32, const ::rtl::OUString&) throw(SQLException, RuntimeException)
208 ::dbtools::throwFunctionNotSupportedException("setObjectNull", NULL);
210 // -------------------------------------------------------------------------
211 void SAL_CALL KabPreparedStatement::setBoolean(sal_Int32, sal_Bool) throw(SQLException, RuntimeException)
216 ::dbtools::throwFunctionNotSupportedException("setBoolean", NULL);
218 // -------------------------------------------------------------------------
219 void SAL_CALL KabPreparedStatement::setByte(sal_Int32, sal_Int8) throw(SQLException, RuntimeException)
224 ::dbtools::throwFunctionNotSupportedException("setByte", NULL);
226 // -------------------------------------------------------------------------
227 void SAL_CALL KabPreparedStatement::setShort(sal_Int32, sal_Int16) throw(SQLException, RuntimeException)
232 ::dbtools::throwFunctionNotSupportedException("setShort", NULL);
234 // -------------------------------------------------------------------------
235 void SAL_CALL KabPreparedStatement::setInt(sal_Int32, sal_Int32) throw(SQLException, RuntimeException)
240 ::dbtools::throwFunctionNotSupportedException("setInt", NULL);
242 // -------------------------------------------------------------------------
243 void SAL_CALL KabPreparedStatement::setLong(sal_Int32, sal_Int64) throw(SQLException, RuntimeException)
248 ::dbtools::throwFunctionNotSupportedException("", NULL);
250 // -------------------------------------------------------------------------
251 void SAL_CALL KabPreparedStatement::setFloat(sal_Int32, float) throw(SQLException, RuntimeException)
256 ::dbtools::throwFunctionNotSupportedException("setFloat", NULL);
258 // -------------------------------------------------------------------------
259 void SAL_CALL KabPreparedStatement::setDouble(sal_Int32, double) throw(SQLException, RuntimeException)
264 ::dbtools::throwFunctionNotSupportedException("setDouble", NULL);
266 // -------------------------------------------------------------------------
267 void SAL_CALL KabPreparedStatement::setString(sal_Int32 parameterIndex, const ::rtl::OUString &x) throw(SQLException, RuntimeException)
269 ::osl::MutexGuard aGuard( m_aMutex );
270 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed);
272 checkAndResizeParameters(parameterIndex);
274 (m_aParameterRow->get())[parameterIndex - 1] = x;
276 // -------------------------------------------------------------------------
277 void SAL_CALL KabPreparedStatement::setBytes(sal_Int32, const Sequence< sal_Int8 >&) throw(SQLException, RuntimeException)
282 ::dbtools::throwFunctionNotSupportedException("setBytes", NULL);
284 // -------------------------------------------------------------------------
285 void SAL_CALL KabPreparedStatement::setDate(sal_Int32, const Date&) throw(SQLException, RuntimeException)
290 ::dbtools::throwFunctionNotSupportedException("setDate", NULL);
292 // -------------------------------------------------------------------------
293 void SAL_CALL KabPreparedStatement::setTime(sal_Int32, const Time&) throw(SQLException, RuntimeException)
298 ::dbtools::throwFunctionNotSupportedException("setTime", NULL);
300 // -------------------------------------------------------------------------
301 void SAL_CALL KabPreparedStatement::setTimestamp(sal_Int32, const DateTime&) throw(SQLException, RuntimeException)
306 ::dbtools::throwFunctionNotSupportedException("setTimestamp", NULL);
308 // -------------------------------------------------------------------------
309 void SAL_CALL KabPreparedStatement::setBinaryStream(sal_Int32, const Reference< ::com::sun::star::io::XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
314 ::dbtools::throwFunctionNotSupportedException("setBinaryStream", NULL);
316 // -------------------------------------------------------------------------
317 void SAL_CALL KabPreparedStatement::setCharacterStream(sal_Int32, const Reference< ::com::sun::star::io::XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
322 ::dbtools::throwFunctionNotSupportedException("setCharacterStream", NULL);
324 // -------------------------------------------------------------------------
325 void SAL_CALL KabPreparedStatement::setObject(sal_Int32 parameterIndex, const Any& x) throw(SQLException, RuntimeException)
327 if(!::dbtools::implSetObject(this,parameterIndex,x))
329 throw SQLException();
332 // -------------------------------------------------------------------------
333 void SAL_CALL KabPreparedStatement::setObjectWithInfo(sal_Int32, const Any&, sal_Int32, sal_Int32) throw(SQLException, RuntimeException)
338 ::dbtools::throwFunctionNotSupportedException("setObjectWithInfo", NULL);
340 // -------------------------------------------------------------------------
341 void SAL_CALL KabPreparedStatement::setRef(sal_Int32, const Reference< XRef >&) throw(SQLException, RuntimeException)
346 ::dbtools::throwFunctionNotSupportedException("setRef", NULL);
348 // -------------------------------------------------------------------------
349 void SAL_CALL KabPreparedStatement::setBlob(sal_Int32, const Reference< XBlob >&) throw(SQLException, RuntimeException)
354 ::dbtools::throwFunctionNotSupportedException("setBlob", NULL);
356 // -------------------------------------------------------------------------
357 void SAL_CALL KabPreparedStatement::setClob(sal_Int32, const Reference< XClob >&) throw(SQLException, RuntimeException)
362 ::dbtools::throwFunctionNotSupportedException("setClob", NULL);
364 // -------------------------------------------------------------------------
365 void SAL_CALL KabPreparedStatement::setArray(sal_Int32, const Reference< XArray >&) throw(SQLException, RuntimeException)
370 ::dbtools::throwFunctionNotSupportedException("setArray", NULL);
372 // -------------------------------------------------------------------------
373 void SAL_CALL KabPreparedStatement::clearParameters() throw(SQLException, RuntimeException)
375 ::dbtools::throwFunctionNotSupportedException("clearParameters", NULL);
377 // -------------------------------------------------------------------------
378 void KabPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
380 switch (nHandle)
382 case PROPERTY_ID_RESULTSETCONCURRENCY:
383 break;
384 case PROPERTY_ID_RESULTSETTYPE:
385 break;
386 case PROPERTY_ID_FETCHDIRECTION:
387 break;
388 case PROPERTY_ID_USEBOOKMARKS:
389 break;
390 default:
391 KabCommonStatement::setFastPropertyValue_NoBroadcast(nHandle,rValue);