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