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