1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26
27 #include "MacabPreparedStatement.hxx"
28 #include "MacabAddressBook.hxx"
29 #include "propertyids.hxx"
30 #include <connectivity/dbexception.hxx>
31 #include "connectivity/dbtools.hxx"
32 #include "resource/macab_res.hrc"
33 #include "resource/sharedresources.hxx"
34
35 using namespace connectivity::macab;
36 using namespace com::sun::star::uno;
37 using namespace com::sun::star::lang;
38 using namespace com::sun::star::sdbc;
39 using namespace com::sun::star::util;
40
41 IMPLEMENT_SERVICE_INFO(MacabPreparedStatement, "com.sun.star.sdbc.drivers.MacabPreparedStatement", "com.sun.star.sdbc.PreparedStatement");
42 // -------------------------------------------------------------------------
checkAndResizeParameters(sal_Int32 nParams)43 void MacabPreparedStatement::checkAndResizeParameters(sal_Int32 nParams) throw(SQLException)
44 {
45 if ( !m_aParameterRow.isValid() )
46 m_aParameterRow = new OValueVector();
47
48 if (nParams < 1)
49 ::dbtools::throwInvalidIndexException(*(MacabPreparedStatement *) this,Any());
50
51 if (nParams >= (sal_Int32) (m_aParameterRow->get()).size())
52 (m_aParameterRow->get()).resize(nParams);
53 }
54 // -------------------------------------------------------------------------
setMacabFields() const55 void MacabPreparedStatement::setMacabFields() const throw(SQLException)
56 {
57 ::vos::ORef<connectivity::OSQLColumns> xColumns; // selected columns
58
59 xColumns = m_aSQLIterator.getSelectColumns();
60 if (!xColumns.isValid())
61 {
62 ::connectivity::SharedResources aResources;
63 const ::rtl::OUString sError( aResources.getResourceString(
64 STR_INVALID_COLUMN_SELECTION
65 ) );
66 ::dbtools::throwGenericSQLException(sError,NULL);
67 }
68 m_xMetaData->setMacabFields(xColumns);
69 }
70 // -------------------------------------------------------------------------
resetParameters() const71 void MacabPreparedStatement::resetParameters() const throw(SQLException)
72 {
73 m_nParameterIndex = 0;
74 }
75 // -------------------------------------------------------------------------
getNextParameter(::rtl::OUString & rParameter) const76 void MacabPreparedStatement::getNextParameter(::rtl::OUString &rParameter) const throw(SQLException)
77 {
78 if (m_nParameterIndex >= (sal_Int32) (m_aParameterRow->get()).size())
79 {
80 ::connectivity::SharedResources aResources;
81 const ::rtl::OUString sError( aResources.getResourceString(
82 STR_INVALID_PARA_COUNT
83 ) );
84 ::dbtools::throwGenericSQLException(sError,*(MacabPreparedStatement *) this);
85 }
86
87 rParameter = (m_aParameterRow->get())[m_nParameterIndex];
88
89 m_nParameterIndex++;
90 }
91 // -------------------------------------------------------------------------
MacabPreparedStatement(MacabConnection * _pConnection,const::rtl::OUString & sql)92 MacabPreparedStatement::MacabPreparedStatement(
93 MacabConnection* _pConnection,
94 const ::rtl::OUString& sql)
95 : MacabPreparedStatement_BASE(_pConnection),
96 m_sSqlStatement(sql),
97 m_bPrepared(sal_False),
98 m_nParameterIndex(0),
99 m_aParameterRow()
100 {
101
102 }
103 // -------------------------------------------------------------------------
~MacabPreparedStatement()104 MacabPreparedStatement::~MacabPreparedStatement()
105 {
106 }
107 // -------------------------------------------------------------------------
disposing()108 void MacabPreparedStatement::disposing()
109 {
110 MacabPreparedStatement_BASE::disposing();
111
112 if (m_aParameterRow.isValid())
113 {
114 m_aParameterRow->get().clear();
115 m_aParameterRow = NULL;
116 }
117 }
118 // -------------------------------------------------------------------------
getMetaData()119 Reference< XResultSetMetaData > SAL_CALL MacabPreparedStatement::getMetaData() throw(SQLException, RuntimeException)
120 {
121 ::osl::MutexGuard aGuard( m_aMutex );
122 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
123
124 if (!m_xMetaData.is())
125 {
126 const OSQLTables& xTabs = m_aSQLIterator.getTables();
127 ::rtl::OUString sTableName = MacabAddressBook::getDefaultTableName();
128
129 if(! xTabs.empty() )
130 {
131
132 // can only deal with one table at a time
133 if(xTabs.size() == 1 && !m_aSQLIterator.hasErrors() )
134 sTableName = xTabs.begin()->first;
135
136 }
137 m_xMetaData = new MacabResultSetMetaData(getOwnConnection(),sTableName);
138 setMacabFields();
139 }
140 Reference< XResultSetMetaData > xMetaData = m_xMetaData.get();
141 return xMetaData;
142 }
143 // -------------------------------------------------------------------------
close()144 void SAL_CALL MacabPreparedStatement::close() throw(SQLException, RuntimeException)
145 {
146 ::osl::MutexGuard aGuard( m_aMutex );
147 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
148
149 // Reset last warning message
150 try {
151 clearWarnings ();
152 MacabCommonStatement::close();
153 }
154 catch (SQLException &) {
155 // If we get an error, ignore
156 }
157
158 // Remove this Statement object from the Connection object's
159 // list
160 }
161 // -------------------------------------------------------------------------
execute()162 sal_Bool SAL_CALL MacabPreparedStatement::execute() throw(SQLException, RuntimeException)
163 {
164 ::osl::MutexGuard aGuard( m_aMutex );
165 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
166
167 Reference< XResultSet> xRS = MacabCommonStatement::executeQuery(m_sSqlStatement);
168
169 return xRS.is();
170 }
171 // -------------------------------------------------------------------------
executeUpdate()172 sal_Int32 SAL_CALL MacabPreparedStatement::executeUpdate() throw(SQLException, RuntimeException)
173 {
174 ::osl::MutexGuard aGuard( m_aMutex );
175 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
176
177 // same as in statement with the difference that this statement also can contain parameter
178 return 0;
179 }
180 // -------------------------------------------------------------------------
getConnection()181 Reference< XConnection > SAL_CALL MacabPreparedStatement::getConnection() throw(SQLException, RuntimeException)
182 {
183 ::osl::MutexGuard aGuard( m_aMutex );
184 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
185
186 return (Reference< XConnection >) m_pConnection;
187 }
188 // -------------------------------------------------------------------------
executeQuery()189 Reference< XResultSet > SAL_CALL MacabPreparedStatement::executeQuery() throw(SQLException, RuntimeException)
190 {
191 ::osl::MutexGuard aGuard( m_aMutex );
192 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
193
194 Reference< XResultSet > rs = MacabCommonStatement::executeQuery(m_sSqlStatement);
195
196 return rs;
197 }
198 // -------------------------------------------------------------------------
setNull(sal_Int32 parameterIndex,sal_Int32)199 void SAL_CALL MacabPreparedStatement::setNull(sal_Int32 parameterIndex, sal_Int32) throw(SQLException, RuntimeException)
200 {
201 ::osl::MutexGuard aGuard( m_aMutex );
202 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
203
204 checkAndResizeParameters(parameterIndex);
205
206 (m_aParameterRow->get())[parameterIndex - 1].setNull();
207 }
208 // -------------------------------------------------------------------------
setObjectNull(sal_Int32,sal_Int32,const::rtl::OUString &)209 void SAL_CALL MacabPreparedStatement::setObjectNull(sal_Int32, sal_Int32, const ::rtl::OUString&) throw(SQLException, RuntimeException)
210 {
211
212
213
214 ::dbtools::throwFunctionNotSupportedException("setObjectNull", NULL);
215 }
216 // -------------------------------------------------------------------------
setBoolean(sal_Int32,sal_Bool)217 void SAL_CALL MacabPreparedStatement::setBoolean(sal_Int32, sal_Bool) throw(SQLException, RuntimeException)
218 {
219
220
221
222 ::dbtools::throwFunctionNotSupportedException("setBoolean", NULL);
223 }
224 // -------------------------------------------------------------------------
setByte(sal_Int32,sal_Int8)225 void SAL_CALL MacabPreparedStatement::setByte(sal_Int32, sal_Int8) throw(SQLException, RuntimeException)
226 {
227
228
229
230 ::dbtools::throwFunctionNotSupportedException("setByte", NULL);
231 }
232 // -------------------------------------------------------------------------
setShort(sal_Int32,sal_Int16)233 void SAL_CALL MacabPreparedStatement::setShort(sal_Int32, sal_Int16) throw(SQLException, RuntimeException)
234 {
235
236
237
238 ::dbtools::throwFunctionNotSupportedException("setShort", NULL);
239 }
240 // -------------------------------------------------------------------------
setInt(sal_Int32,sal_Int32)241 void SAL_CALL MacabPreparedStatement::setInt(sal_Int32, sal_Int32) throw(SQLException, RuntimeException)
242 {
243
244
245
246 ::dbtools::throwFunctionNotSupportedException("setInt", NULL);
247 }
248 // -------------------------------------------------------------------------
setLong(sal_Int32,sal_Int64)249 void SAL_CALL MacabPreparedStatement::setLong(sal_Int32, sal_Int64) throw(SQLException, RuntimeException)
250 {
251
252
253
254 ::dbtools::throwFunctionNotSupportedException("setLong", NULL);
255 }
256 // -------------------------------------------------------------------------
setFloat(sal_Int32,float)257 void SAL_CALL MacabPreparedStatement::setFloat(sal_Int32, float) throw(SQLException, RuntimeException)
258 {
259
260
261
262 ::dbtools::throwFunctionNotSupportedException("setFloat", NULL);
263 }
264 // -------------------------------------------------------------------------
setDouble(sal_Int32,double)265 void SAL_CALL MacabPreparedStatement::setDouble(sal_Int32, double) throw(SQLException, RuntimeException)
266 {
267
268
269
270 ::dbtools::throwFunctionNotSupportedException("setDouble", NULL);
271 }
272 // -------------------------------------------------------------------------
setString(sal_Int32 parameterIndex,const::rtl::OUString & x)273 void SAL_CALL MacabPreparedStatement::setString(sal_Int32 parameterIndex, const ::rtl::OUString &x) throw(SQLException, RuntimeException)
274 {
275 ::osl::MutexGuard aGuard( m_aMutex );
276 checkDisposed(MacabCommonStatement_BASE::rBHelper.bDisposed);
277
278 checkAndResizeParameters(parameterIndex);
279
280 (m_aParameterRow->get())[parameterIndex - 1] = x;
281 }
282 // -------------------------------------------------------------------------
setBytes(sal_Int32,const Sequence<sal_Int8> &)283 void SAL_CALL MacabPreparedStatement::setBytes(sal_Int32, const Sequence< sal_Int8 >&) throw(SQLException, RuntimeException)
284 {
285
286
287
288 ::dbtools::throwFunctionNotSupportedException("setBytes", NULL);
289 }
290 // -------------------------------------------------------------------------
setDate(sal_Int32,const Date &)291 void SAL_CALL MacabPreparedStatement::setDate(sal_Int32, const Date&) throw(SQLException, RuntimeException)
292 {
293
294
295
296 ::dbtools::throwFunctionNotSupportedException("setDate", NULL);
297 }
298 // -------------------------------------------------------------------------
setTime(sal_Int32,const Time &)299 void SAL_CALL MacabPreparedStatement::setTime(sal_Int32, const Time&) throw(SQLException, RuntimeException)
300 {
301
302
303
304 ::dbtools::throwFunctionNotSupportedException("setTime", NULL);
305 }
306 // -------------------------------------------------------------------------
setTimestamp(sal_Int32,const DateTime &)307 void SAL_CALL MacabPreparedStatement::setTimestamp(sal_Int32, const DateTime&) throw(SQLException, RuntimeException)
308 {
309
310
311
312 ::dbtools::throwFunctionNotSupportedException("setTimestamp", NULL);
313 }
314 // -------------------------------------------------------------------------
setBinaryStream(sal_Int32,const Reference<::com::sun::star::io::XInputStream> &,sal_Int32)315 void SAL_CALL MacabPreparedStatement::setBinaryStream(sal_Int32, const Reference< ::com::sun::star::io::XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
316 {
317
318
319
320 ::dbtools::throwFunctionNotSupportedException("setBinaryStream", NULL);
321 }
322 // -------------------------------------------------------------------------
setCharacterStream(sal_Int32,const Reference<::com::sun::star::io::XInputStream> &,sal_Int32)323 void SAL_CALL MacabPreparedStatement::setCharacterStream(sal_Int32, const Reference< ::com::sun::star::io::XInputStream >&, sal_Int32) throw(SQLException, RuntimeException)
324 {
325
326
327
328 ::dbtools::throwFunctionNotSupportedException("setCharacterStream", NULL);
329 }
330 // -------------------------------------------------------------------------
setObject(sal_Int32 parameterIndex,const Any & x)331 void SAL_CALL MacabPreparedStatement::setObject(sal_Int32 parameterIndex, const Any& x) throw(SQLException, RuntimeException)
332 {
333 if(!::dbtools::implSetObject(this,parameterIndex,x))
334 {
335 const ::rtl::OUString sError( m_pConnection->getResources().getResourceStringWithSubstitution(
336 STR_UNKNOWN_PARA_TYPE,
337 "$position$", ::rtl::OUString::valueOf(parameterIndex)
338 ) );
339 ::dbtools::throwGenericSQLException(sError,*this);
340 }
341 }
342 // -------------------------------------------------------------------------
setObjectWithInfo(sal_Int32,const Any &,sal_Int32,sal_Int32)343 void SAL_CALL MacabPreparedStatement::setObjectWithInfo(sal_Int32, const Any&, sal_Int32, sal_Int32) throw(SQLException, RuntimeException)
344 {
345
346
347
348 ::dbtools::throwFunctionNotSupportedException("setObjectWithInfo", NULL);
349 }
350 // -------------------------------------------------------------------------
setRef(sal_Int32,const Reference<XRef> &)351 void SAL_CALL MacabPreparedStatement::setRef(sal_Int32, const Reference< XRef >&) throw(SQLException, RuntimeException)
352 {
353
354
355
356 ::dbtools::throwFunctionNotSupportedException("setRef", NULL);
357 }
358 // -------------------------------------------------------------------------
setBlob(sal_Int32,const Reference<XBlob> &)359 void SAL_CALL MacabPreparedStatement::setBlob(sal_Int32, const Reference< XBlob >&) throw(SQLException, RuntimeException)
360 {
361
362
363
364 ::dbtools::throwFunctionNotSupportedException("setBlob", NULL);
365 }
366 // -------------------------------------------------------------------------
setClob(sal_Int32,const Reference<XClob> &)367 void SAL_CALL MacabPreparedStatement::setClob(sal_Int32, const Reference< XClob >&) throw(SQLException, RuntimeException)
368 {
369
370
371
372 ::dbtools::throwFunctionNotSupportedException("setClob", NULL);
373 }
374 // -------------------------------------------------------------------------
setArray(sal_Int32,const Reference<XArray> &)375 void SAL_CALL MacabPreparedStatement::setArray(sal_Int32, const Reference< XArray >&) throw(SQLException, RuntimeException)
376 {
377
378
379
380 ::dbtools::throwFunctionNotSupportedException("setArray", NULL);
381 }
382 // -------------------------------------------------------------------------
clearParameters()383 void SAL_CALL MacabPreparedStatement::clearParameters() throw(SQLException, RuntimeException)
384 {
385 ::dbtools::throwFunctionNotSupportedException("clearParameters", NULL);
386 }
387 // -------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)388 void MacabPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
389 {
390 switch (nHandle)
391 {
392 case PROPERTY_ID_RESULTSETCONCURRENCY:
393 break;
394 case PROPERTY_ID_RESULTSETTYPE:
395 break;
396 case PROPERTY_ID_FETCHDIRECTION:
397 break;
398 case PROPERTY_ID_USEBOOKMARKS:
399 break;
400 default:
401 MacabCommonStatement::setFastPropertyValue_NoBroadcast(nHandle,rValue);
402 }
403 }
404