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 "KPreparedStatement.hxx" 32 #include "propertyids.hxx" 33 #include <connectivity/dbexception.hxx> 34 #include <connectivity/dbtools.hxx> 35 #include "resource/kab_res.hrc" 36 #include "resource/sharedresources.hxx" 37 38 using namespace connectivity::kab; 39 using namespace com::sun::star::uno; 40 using namespace com::sun::star::lang; 41 using namespace com::sun::star::sdbc; 42 using namespace com::sun::star::util; 43 44 IMPLEMENT_SERVICE_INFO(KabPreparedStatement, "com.sun.star.sdbc.drivers.KabPreparedStatement", "com.sun.star.sdbc.PreparedStatement"); 45 // ------------------------------------------------------------------------- 46 void KabPreparedStatement::checkAndResizeParameters(sal_Int32 nParams) throw(SQLException) 47 { 48 if ( !m_aParameterRow.isValid() ) 49 m_aParameterRow = new OValueVector(); 50 51 if (nParams < 1) 52 ::dbtools::throwInvalidIndexException(*(KabPreparedStatement *) this,Any()); 53 54 if (nParams >= (sal_Int32) (m_aParameterRow->get()).size()) 55 (m_aParameterRow->get()).resize(nParams); 56 } 57 // ------------------------------------------------------------------------- 58 void KabPreparedStatement::setKabFields() const throw(SQLException) 59 { 60 ::vos::ORef<connectivity::OSQLColumns> xColumns; // selected columns 61 62 xColumns = m_aSQLIterator.getSelectColumns(); 63 if (!xColumns.isValid()) 64 { 65 ::connectivity::SharedResources aResources; 66 const ::rtl::OUString sError( aResources.getResourceString( 67 STR_INVALID_COLUMN_SELECTION 68 ) ); 69 ::dbtools::throwGenericSQLException(sError,NULL); 70 } 71 m_xMetaData->setKabFields(xColumns); 72 } 73 // ------------------------------------------------------------------------- 74 void KabPreparedStatement::resetParameters() const throw(SQLException) 75 { 76 m_nParameterIndex = 0; 77 } 78 // ------------------------------------------------------------------------- 79 void KabPreparedStatement::getNextParameter(::rtl::OUString &rParameter) const throw(SQLException) 80 { 81 if (m_nParameterIndex >= (sal_Int32) (m_aParameterRow->get()).size()) 82 { 83 ::connectivity::SharedResources aResources; 84 const ::rtl::OUString sError( aResources.getResourceString( 85 STR_INVALID_PARA_COUNT 86 ) ); 87 ::dbtools::throwGenericSQLException(sError,*(KabPreparedStatement *) this); 88 } // if (m_nParameterIndex >= (sal_Int32) (*m_aParameterRow).size()) 89 90 rParameter = (m_aParameterRow->get())[m_nParameterIndex]; 91 92 m_nParameterIndex++; 93 } 94 // ------------------------------------------------------------------------- 95 KabPreparedStatement::KabPreparedStatement( 96 KabConnection* _pConnection, 97 const ::rtl::OUString& sql) 98 : KabPreparedStatement_BASE(_pConnection), 99 m_sSqlStatement(sql), 100 m_bPrepared(sal_False), 101 m_nParameterIndex(0), 102 m_aParameterRow() 103 { 104 } 105 // ------------------------------------------------------------------------- 106 KabPreparedStatement::~KabPreparedStatement() 107 { 108 } 109 // ------------------------------------------------------------------------- 110 void KabPreparedStatement::disposing() 111 { 112 KabPreparedStatement_BASE::disposing(); 113 114 if (m_aParameterRow.isValid()) 115 { 116 m_aParameterRow->get().clear(); 117 m_aParameterRow = NULL; 118 } 119 } 120 // ------------------------------------------------------------------------- 121 Reference< XResultSetMetaData > SAL_CALL KabPreparedStatement::getMetaData() throw(SQLException, RuntimeException) 122 { 123 ::osl::MutexGuard aGuard( m_aMutex ); 124 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 125 126 if (!m_xMetaData.is()) 127 { 128 m_xMetaData = new KabResultSetMetaData(getOwnConnection()); 129 setKabFields(); 130 } 131 Reference< XResultSetMetaData > xMetaData = m_xMetaData.get(); 132 return xMetaData; 133 } 134 // ------------------------------------------------------------------------- 135 void SAL_CALL KabPreparedStatement::close() throw(SQLException, RuntimeException) 136 { 137 ::osl::MutexGuard aGuard( m_aMutex ); 138 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 139 140 // Reset last warning message 141 try { 142 clearWarnings (); 143 KabCommonStatement::close(); 144 } 145 catch (SQLException &) { 146 // If we get an error, ignore 147 } 148 149 // Remove this Statement object from the Connection object's 150 // list 151 } 152 // ------------------------------------------------------------------------- 153 sal_Bool SAL_CALL KabPreparedStatement::execute() throw(SQLException, RuntimeException) 154 { 155 ::osl::MutexGuard aGuard( m_aMutex ); 156 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 157 158 Reference< XResultSet> xRS = KabCommonStatement::executeQuery(m_sSqlStatement); 159 160 return xRS.is(); 161 } 162 // ------------------------------------------------------------------------- 163 sal_Int32 SAL_CALL KabPreparedStatement::executeUpdate() throw(SQLException, RuntimeException) 164 { 165 ::osl::MutexGuard aGuard( m_aMutex ); 166 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 167 168 // same as in statement with the difference that this statement also can contain parameter 169 return 0; 170 } 171 // ------------------------------------------------------------------------- 172 Reference< XConnection > SAL_CALL KabPreparedStatement::getConnection() throw(SQLException, RuntimeException) 173 { 174 ::osl::MutexGuard aGuard( m_aMutex ); 175 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 176 177 return (Reference< XConnection >) m_pConnection; 178 } 179 // ------------------------------------------------------------------------- 180 Reference< XResultSet > SAL_CALL KabPreparedStatement::executeQuery() throw(SQLException, RuntimeException) 181 { 182 ::osl::MutexGuard aGuard( m_aMutex ); 183 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 184 185 Reference< XResultSet > rs = KabCommonStatement::executeQuery(m_sSqlStatement); 186 187 return rs; 188 } 189 // ------------------------------------------------------------------------- 190 void SAL_CALL KabPreparedStatement::setNull(sal_Int32 parameterIndex, sal_Int32) throw(SQLException, RuntimeException) 191 { 192 ::osl::MutexGuard aGuard( m_aMutex ); 193 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 194 195 checkAndResizeParameters(parameterIndex); 196 197 (m_aParameterRow->get())[parameterIndex - 1].setNull(); 198 } 199 // ------------------------------------------------------------------------- 200 void SAL_CALL KabPreparedStatement::setObjectNull(sal_Int32, sal_Int32, const ::rtl::OUString&) throw(SQLException, RuntimeException) 201 { 202 203 204 205 ::dbtools::throwFunctionNotSupportedException("setObjectNull", NULL); 206 } 207 // ------------------------------------------------------------------------- 208 void SAL_CALL KabPreparedStatement::setBoolean(sal_Int32, sal_Bool) throw(SQLException, RuntimeException) 209 { 210 211 212 213 ::dbtools::throwFunctionNotSupportedException("setBoolean", NULL); 214 } 215 // ------------------------------------------------------------------------- 216 void SAL_CALL KabPreparedStatement::setByte(sal_Int32, sal_Int8) throw(SQLException, RuntimeException) 217 { 218 219 220 221 ::dbtools::throwFunctionNotSupportedException("setByte", NULL); 222 } 223 // ------------------------------------------------------------------------- 224 void SAL_CALL KabPreparedStatement::setShort(sal_Int32, sal_Int16) throw(SQLException, RuntimeException) 225 { 226 227 228 229 ::dbtools::throwFunctionNotSupportedException("setShort", NULL); 230 } 231 // ------------------------------------------------------------------------- 232 void SAL_CALL KabPreparedStatement::setInt(sal_Int32, sal_Int32) throw(SQLException, RuntimeException) 233 { 234 235 236 237 ::dbtools::throwFunctionNotSupportedException("setInt", NULL); 238 } 239 // ------------------------------------------------------------------------- 240 void SAL_CALL KabPreparedStatement::setLong(sal_Int32, sal_Int64) throw(SQLException, RuntimeException) 241 { 242 243 244 245 ::dbtools::throwFunctionNotSupportedException("", NULL); 246 } 247 // ------------------------------------------------------------------------- 248 void SAL_CALL KabPreparedStatement::setFloat(sal_Int32, float) throw(SQLException, RuntimeException) 249 { 250 251 252 253 ::dbtools::throwFunctionNotSupportedException("setFloat", NULL); 254 } 255 // ------------------------------------------------------------------------- 256 void SAL_CALL KabPreparedStatement::setDouble(sal_Int32, double) throw(SQLException, RuntimeException) 257 { 258 259 260 261 ::dbtools::throwFunctionNotSupportedException("setDouble", NULL); 262 } 263 // ------------------------------------------------------------------------- 264 void SAL_CALL KabPreparedStatement::setString(sal_Int32 parameterIndex, const ::rtl::OUString &x) throw(SQLException, RuntimeException) 265 { 266 ::osl::MutexGuard aGuard( m_aMutex ); 267 checkDisposed(KabCommonStatement_BASE::rBHelper.bDisposed); 268 269 checkAndResizeParameters(parameterIndex); 270 271 (m_aParameterRow->get())[parameterIndex - 1] = x; 272 } 273 // ------------------------------------------------------------------------- 274 void SAL_CALL KabPreparedStatement::setBytes(sal_Int32, const Sequence< sal_Int8 >&) throw(SQLException, RuntimeException) 275 { 276 277 278 279 ::dbtools::throwFunctionNotSupportedException("setBytes", NULL); 280 } 281 // ------------------------------------------------------------------------- 282 void SAL_CALL KabPreparedStatement::setDate(sal_Int32, const Date&) throw(SQLException, RuntimeException) 283 { 284 285 286 287 ::dbtools::throwFunctionNotSupportedException("setDate", NULL); 288 } 289 // ------------------------------------------------------------------------- 290 void SAL_CALL KabPreparedStatement::setTime(sal_Int32, const Time&) throw(SQLException, RuntimeException) 291 { 292 293 294 295 ::dbtools::throwFunctionNotSupportedException("setTime", NULL); 296 } 297 // ------------------------------------------------------------------------- 298 void SAL_CALL KabPreparedStatement::setTimestamp(sal_Int32, const DateTime&) throw(SQLException, RuntimeException) 299 { 300 301 302 303 ::dbtools::throwFunctionNotSupportedException("setTimestamp", NULL); 304 } 305 // ------------------------------------------------------------------------- 306 void SAL_CALL KabPreparedStatement::setBinaryStream(sal_Int32, const Reference< ::com::sun::star::io::XInputStream >&, sal_Int32) throw(SQLException, RuntimeException) 307 { 308 309 310 311 ::dbtools::throwFunctionNotSupportedException("setBinaryStream", NULL); 312 } 313 // ------------------------------------------------------------------------- 314 void SAL_CALL KabPreparedStatement::setCharacterStream(sal_Int32, const Reference< ::com::sun::star::io::XInputStream >&, sal_Int32) throw(SQLException, RuntimeException) 315 { 316 317 318 319 ::dbtools::throwFunctionNotSupportedException("setCharacterStream", NULL); 320 } 321 // ------------------------------------------------------------------------- 322 void SAL_CALL KabPreparedStatement::setObject(sal_Int32 parameterIndex, const Any& x) throw(SQLException, RuntimeException) 323 { 324 if(!::dbtools::implSetObject(this,parameterIndex,x)) 325 { 326 throw SQLException(); 327 } 328 } 329 // ------------------------------------------------------------------------- 330 void SAL_CALL KabPreparedStatement::setObjectWithInfo(sal_Int32, const Any&, sal_Int32, sal_Int32) throw(SQLException, RuntimeException) 331 { 332 333 334 335 ::dbtools::throwFunctionNotSupportedException("setObjectWithInfo", NULL); 336 } 337 // ------------------------------------------------------------------------- 338 void SAL_CALL KabPreparedStatement::setRef(sal_Int32, const Reference< XRef >&) throw(SQLException, RuntimeException) 339 { 340 341 342 343 ::dbtools::throwFunctionNotSupportedException("setRef", NULL); 344 } 345 // ------------------------------------------------------------------------- 346 void SAL_CALL KabPreparedStatement::setBlob(sal_Int32, const Reference< XBlob >&) throw(SQLException, RuntimeException) 347 { 348 349 350 351 ::dbtools::throwFunctionNotSupportedException("setBlob", NULL); 352 } 353 // ------------------------------------------------------------------------- 354 void SAL_CALL KabPreparedStatement::setClob(sal_Int32, const Reference< XClob >&) throw(SQLException, RuntimeException) 355 { 356 357 358 359 ::dbtools::throwFunctionNotSupportedException("setClob", NULL); 360 } 361 // ------------------------------------------------------------------------- 362 void SAL_CALL KabPreparedStatement::setArray(sal_Int32, const Reference< XArray >&) throw(SQLException, RuntimeException) 363 { 364 365 366 367 ::dbtools::throwFunctionNotSupportedException("setArray", NULL); 368 } 369 // ------------------------------------------------------------------------- 370 void SAL_CALL KabPreparedStatement::clearParameters() throw(SQLException, RuntimeException) 371 { 372 ::dbtools::throwFunctionNotSupportedException("clearParameters", NULL); 373 } 374 // ------------------------------------------------------------------------- 375 void KabPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception) 376 { 377 switch (nHandle) 378 { 379 case PROPERTY_ID_RESULTSETCONCURRENCY: 380 break; 381 case PROPERTY_ID_RESULTSETTYPE: 382 break; 383 case PROPERTY_ID_FETCHDIRECTION: 384 break; 385 case PROPERTY_ID_USEBOOKMARKS: 386 break; 387 default: 388 KabCommonStatement::setFastPropertyValue_NoBroadcast(nHandle,rValue); 389 } 390 } 391