1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "KPreparedStatement.hxx"
22 #include "propertyids.hxx"
23 #include <connectivity/dbexception.hxx>
24 #include <connectivity/dbtools.hxx>
25 #include "resource/kab_res.hrc"
26 #include "resource/sharedresources.hxx"
28 using namespace connectivity::kab
;
29 using namespace com::sun::star::uno
;
30 using namespace com::sun::star::lang
;
31 using namespace com::sun::star::sdbc
;
32 using namespace com::sun::star::util
;
34 IMPLEMENT_SERVICE_INFO(KabPreparedStatement
, "com.sun.star.sdbc.drivers.KabPreparedStatement", "com.sun.star.sdbc.PreparedStatement");
35 // -------------------------------------------------------------------------
36 void KabPreparedStatement::checkAndResizeParameters(sal_Int32 nParams
) throw(SQLException
)
38 if ( !m_aParameterRow
.is() )
39 m_aParameterRow
= new OValueVector();
42 ::dbtools::throwInvalidIndexException(*(KabPreparedStatement
*) this,Any());
44 if (nParams
>= (sal_Int32
) (m_aParameterRow
->get()).size())
45 (m_aParameterRow
->get()).resize(nParams
);
47 // -------------------------------------------------------------------------
48 void KabPreparedStatement::setKabFields() const throw(SQLException
)
50 ::rtl::Reference
<connectivity::OSQLColumns
> xColumns
; // selected columns
52 xColumns
= m_aSQLIterator
.getSelectColumns();
55 ::connectivity::SharedResources aResources
;
56 const OUString
sError( aResources
.getResourceString(
57 STR_INVALID_COLUMN_SELECTION
59 ::dbtools::throwGenericSQLException(sError
,NULL
);
61 m_xMetaData
->setKabFields(xColumns
);
63 // -------------------------------------------------------------------------
64 void KabPreparedStatement::resetParameters() const throw(SQLException
)
66 m_nParameterIndex
= 0;
68 // -------------------------------------------------------------------------
69 void KabPreparedStatement::getNextParameter(OUString
&rParameter
) const throw(SQLException
)
71 if (m_nParameterIndex
>= (sal_Int32
) (m_aParameterRow
->get()).size())
73 ::connectivity::SharedResources aResources
;
74 const OUString
sError( aResources
.getResourceString(
75 STR_INVALID_PARA_COUNT
77 ::dbtools::throwGenericSQLException(sError
,*(KabPreparedStatement
*) this);
78 } // if (m_nParameterIndex >= (sal_Int32) (*m_aParameterRow).size())
80 rParameter
= (m_aParameterRow
->get())[m_nParameterIndex
];
84 // -------------------------------------------------------------------------
85 KabPreparedStatement::KabPreparedStatement(
86 KabConnection
* _pConnection
,
88 : KabPreparedStatement_BASE(_pConnection
),
90 m_bPrepared(sal_False
),
95 // -------------------------------------------------------------------------
96 KabPreparedStatement::~KabPreparedStatement()
99 // -------------------------------------------------------------------------
100 void KabPreparedStatement::disposing()
102 KabPreparedStatement_BASE::disposing();
104 if (m_aParameterRow
.is())
106 m_aParameterRow
->get().clear();
107 m_aParameterRow
= NULL
;
110 // -------------------------------------------------------------------------
111 Reference
< XResultSetMetaData
> SAL_CALL
KabPreparedStatement::getMetaData() throw(SQLException
, RuntimeException
)
113 ::osl::MutexGuard
aGuard( m_aMutex
);
114 checkDisposed(KabCommonStatement_BASE::rBHelper
.bDisposed
);
116 if (!m_xMetaData
.is())
118 m_xMetaData
= new KabResultSetMetaData
;
121 Reference
< XResultSetMetaData
> xMetaData
= m_xMetaData
.get();
124 // -------------------------------------------------------------------------
125 void SAL_CALL
KabPreparedStatement::close() throw(SQLException
, RuntimeException
)
127 ::osl::MutexGuard
aGuard( m_aMutex
);
128 checkDisposed(KabCommonStatement_BASE::rBHelper
.bDisposed
);
130 // Reset last warning message
133 KabCommonStatement::close();
135 catch (SQLException
&) {
136 // If we get an error, ignore
139 // Remove this Statement object from the Connection object's
142 // -------------------------------------------------------------------------
143 sal_Bool SAL_CALL
KabPreparedStatement::execute() throw(SQLException
, RuntimeException
)
145 ::osl::MutexGuard
aGuard( m_aMutex
);
146 checkDisposed(KabCommonStatement_BASE::rBHelper
.bDisposed
);
148 Reference
< XResultSet
> xRS
= KabCommonStatement::executeQuery(m_sSqlStatement
);
152 // -------------------------------------------------------------------------
153 sal_Int32 SAL_CALL
KabPreparedStatement::executeUpdate() throw(SQLException
, RuntimeException
)
155 ::osl::MutexGuard
aGuard( m_aMutex
);
156 checkDisposed(KabCommonStatement_BASE::rBHelper
.bDisposed
);
158 // same as in statement with the difference that this statement also can contain parameter
161 // -------------------------------------------------------------------------
162 Reference
< XConnection
> SAL_CALL
KabPreparedStatement::getConnection() throw(SQLException
, RuntimeException
)
164 ::osl::MutexGuard
aGuard( m_aMutex
);
165 checkDisposed(KabCommonStatement_BASE::rBHelper
.bDisposed
);
167 return (Reference
< XConnection
>) m_pConnection
;
169 // -------------------------------------------------------------------------
170 Reference
< XResultSet
> SAL_CALL
KabPreparedStatement::executeQuery() throw(SQLException
, RuntimeException
)
172 ::osl::MutexGuard
aGuard( m_aMutex
);
173 checkDisposed(KabCommonStatement_BASE::rBHelper
.bDisposed
);
175 Reference
< XResultSet
> rs
= KabCommonStatement::executeQuery(m_sSqlStatement
);
179 // -------------------------------------------------------------------------
180 void SAL_CALL
KabPreparedStatement::setNull(sal_Int32 parameterIndex
, sal_Int32
) throw(SQLException
, RuntimeException
)
182 ::osl::MutexGuard
aGuard( m_aMutex
);
183 checkDisposed(KabCommonStatement_BASE::rBHelper
.bDisposed
);
185 checkAndResizeParameters(parameterIndex
);
187 (m_aParameterRow
->get())[parameterIndex
- 1].setNull();
189 // -------------------------------------------------------------------------
190 void SAL_CALL
KabPreparedStatement::setObjectNull(sal_Int32
, sal_Int32
, const OUString
&) throw(SQLException
, RuntimeException
)
195 ::dbtools::throwFunctionNotSupportedException("setObjectNull", NULL
);
197 // -------------------------------------------------------------------------
198 void SAL_CALL
KabPreparedStatement::setBoolean(sal_Int32
, sal_Bool
) throw(SQLException
, RuntimeException
)
203 ::dbtools::throwFunctionNotSupportedException("setBoolean", NULL
);
205 // -------------------------------------------------------------------------
206 void SAL_CALL
KabPreparedStatement::setByte(sal_Int32
, sal_Int8
) throw(SQLException
, RuntimeException
)
211 ::dbtools::throwFunctionNotSupportedException("setByte", NULL
);
213 // -------------------------------------------------------------------------
214 void SAL_CALL
KabPreparedStatement::setShort(sal_Int32
, sal_Int16
) throw(SQLException
, RuntimeException
)
219 ::dbtools::throwFunctionNotSupportedException("setShort", NULL
);
221 // -------------------------------------------------------------------------
222 void SAL_CALL
KabPreparedStatement::setInt(sal_Int32
, sal_Int32
) throw(SQLException
, RuntimeException
)
227 ::dbtools::throwFunctionNotSupportedException("setInt", NULL
);
229 // -------------------------------------------------------------------------
230 void SAL_CALL
KabPreparedStatement::setLong(sal_Int32
, sal_Int64
) throw(SQLException
, RuntimeException
)
235 ::dbtools::throwFunctionNotSupportedException("", NULL
);
237 // -------------------------------------------------------------------------
238 void SAL_CALL
KabPreparedStatement::setFloat(sal_Int32
, float) throw(SQLException
, RuntimeException
)
243 ::dbtools::throwFunctionNotSupportedException("setFloat", NULL
);
245 // -------------------------------------------------------------------------
246 void SAL_CALL
KabPreparedStatement::setDouble(sal_Int32
, double) throw(SQLException
, RuntimeException
)
251 ::dbtools::throwFunctionNotSupportedException("setDouble", NULL
);
253 // -------------------------------------------------------------------------
254 void SAL_CALL
KabPreparedStatement::setString(sal_Int32 parameterIndex
, const OUString
&x
) throw(SQLException
, RuntimeException
)
256 ::osl::MutexGuard
aGuard( m_aMutex
);
257 checkDisposed(KabCommonStatement_BASE::rBHelper
.bDisposed
);
259 checkAndResizeParameters(parameterIndex
);
261 (m_aParameterRow
->get())[parameterIndex
- 1] = x
;
263 // -------------------------------------------------------------------------
264 void SAL_CALL
KabPreparedStatement::setBytes(sal_Int32
, const Sequence
< sal_Int8
>&) throw(SQLException
, RuntimeException
)
269 ::dbtools::throwFunctionNotSupportedException("setBytes", NULL
);
271 // -------------------------------------------------------------------------
272 void SAL_CALL
KabPreparedStatement::setDate(sal_Int32
, const Date
&) throw(SQLException
, RuntimeException
)
277 ::dbtools::throwFunctionNotSupportedException("setDate", NULL
);
279 // -------------------------------------------------------------------------
280 void SAL_CALL
KabPreparedStatement::setTime(sal_Int32
, const Time
&) throw(SQLException
, RuntimeException
)
285 ::dbtools::throwFunctionNotSupportedException("setTime", NULL
);
287 // -------------------------------------------------------------------------
288 void SAL_CALL
KabPreparedStatement::setTimestamp(sal_Int32
, const DateTime
&) throw(SQLException
, RuntimeException
)
293 ::dbtools::throwFunctionNotSupportedException("setTimestamp", NULL
);
295 // -------------------------------------------------------------------------
296 void SAL_CALL
KabPreparedStatement::setBinaryStream(sal_Int32
, const Reference
< ::com::sun::star::io::XInputStream
>&, sal_Int32
) throw(SQLException
, RuntimeException
)
301 ::dbtools::throwFunctionNotSupportedException("setBinaryStream", NULL
);
303 // -------------------------------------------------------------------------
304 void SAL_CALL
KabPreparedStatement::setCharacterStream(sal_Int32
, const Reference
< ::com::sun::star::io::XInputStream
>&, sal_Int32
) throw(SQLException
, RuntimeException
)
309 ::dbtools::throwFunctionNotSupportedException("setCharacterStream", NULL
);
311 // -------------------------------------------------------------------------
312 void SAL_CALL
KabPreparedStatement::setObject(sal_Int32 parameterIndex
, const Any
& x
) throw(SQLException
, RuntimeException
)
314 if(!::dbtools::implSetObject(this,parameterIndex
,x
))
316 throw SQLException();
319 // -------------------------------------------------------------------------
320 void SAL_CALL
KabPreparedStatement::setObjectWithInfo(sal_Int32
, const Any
&, sal_Int32
, sal_Int32
) throw(SQLException
, RuntimeException
)
325 ::dbtools::throwFunctionNotSupportedException("setObjectWithInfo", NULL
);
327 // -------------------------------------------------------------------------
328 void SAL_CALL
KabPreparedStatement::setRef(sal_Int32
, const Reference
< XRef
>&) throw(SQLException
, RuntimeException
)
333 ::dbtools::throwFunctionNotSupportedException("setRef", NULL
);
335 // -------------------------------------------------------------------------
336 void SAL_CALL
KabPreparedStatement::setBlob(sal_Int32
, const Reference
< XBlob
>&) throw(SQLException
, RuntimeException
)
341 ::dbtools::throwFunctionNotSupportedException("setBlob", NULL
);
343 // -------------------------------------------------------------------------
344 void SAL_CALL
KabPreparedStatement::setClob(sal_Int32
, const Reference
< XClob
>&) throw(SQLException
, RuntimeException
)
349 ::dbtools::throwFunctionNotSupportedException("setClob", NULL
);
351 // -------------------------------------------------------------------------
352 void SAL_CALL
KabPreparedStatement::setArray(sal_Int32
, const Reference
< XArray
>&) throw(SQLException
, RuntimeException
)
357 ::dbtools::throwFunctionNotSupportedException("setArray", NULL
);
359 // -------------------------------------------------------------------------
360 void SAL_CALL
KabPreparedStatement::clearParameters() throw(SQLException
, RuntimeException
)
362 ::dbtools::throwFunctionNotSupportedException("clearParameters", NULL
);
364 // -------------------------------------------------------------------------
365 void KabPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
) throw (Exception
)
369 case PROPERTY_ID_RESULTSETCONCURRENCY
:
371 case PROPERTY_ID_RESULTSETTYPE
:
373 case PROPERTY_ID_FETCHDIRECTION
:
375 case PROPERTY_ID_USEBOOKMARKS
:
378 KabCommonStatement::setFastPropertyValue_NoBroadcast(nHandle
,rValue
);
382 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */