Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / postgresql / pq_preparedstatement.cxx
blob55c0175e48fa94c7d41b8d628ddf6c9045438d4a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * Effective License of whole file:
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software Foundation.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 * MA 02111-1307 USA
20 * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
22 * The Contents of this file are made available subject to the terms of
23 * the GNU Lesser General Public License Version 2.1
25 * Copyright: 2000 by Sun Microsystems, Inc.
27 * Contributor(s): Joerg Budischewski
29 * All parts contributed on or after August 2011:
31 * This Source Code Form is subject to the terms of the Mozilla Public
32 * License, v. 2.0. If a copy of the MPL was not distributed with this
33 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
35 ************************************************************************/
37 #include "pq_preparedstatement.hxx"
38 #include "pq_resultset.hxx"
39 #include "pq_tools.hxx"
40 #include "pq_statics.hxx"
41 #include "pq_statement.hxx"
43 #include <rtl/strbuf.hxx>
44 #include <rtl/ustrbuf.hxx>
47 #include <cppuhelper/typeprovider.hxx>
48 #include <cppuhelper/queryinterface.hxx>
50 #include <com/sun/star/beans/PropertyAttribute.hpp>
52 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
53 #include <com/sun/star/sdbc/ResultSetType.hpp>
55 #include <string.h>
57 #include <connectivity/dbconversion.hxx>
59 using osl::Mutex;
60 using osl::MutexGuard;
63 using com::sun::star::uno::Any;
64 using com::sun::star::uno::makeAny;
65 using com::sun::star::uno::Type;
66 using com::sun::star::uno::RuntimeException;
67 using com::sun::star::uno::Exception;
68 using com::sun::star::uno::Sequence;
69 using com::sun::star::uno::Reference;
70 using com::sun::star::uno::XInterface;
71 using com::sun::star::uno::UNO_QUERY;
73 using com::sun::star::lang::IllegalArgumentException;
75 using com::sun::star::sdbc::XWarningsSupplier;
76 using com::sun::star::sdbc::XCloseable;
77 using com::sun::star::sdbc::XPreparedStatement;
78 using com::sun::star::sdbc::XParameters;
79 using com::sun::star::sdbc::XResultSet;
80 using com::sun::star::sdbc::XRef;
81 using com::sun::star::sdbc::XBlob;
82 using com::sun::star::sdbc::XClob;
83 using com::sun::star::sdbc::XArray;
84 using com::sun::star::sdbc::XConnection;
85 using com::sun::star::sdbc::XGeneratedResultSet;
86 using com::sun::star::sdbc::SQLException;
88 using com::sun::star::beans::Property;
89 using com::sun::star::beans::XPropertySetInfo;
90 using com::sun::star::beans::XPropertySet;
91 using com::sun::star::beans::XMultiPropertySet;
92 using com::sun::star::beans::XFastPropertySet;
94 using namespace dbtools;
96 namespace pq_sdbc_driver
98 static ::cppu::IPropertyArrayHelper & getPreparedStatementPropertyArrayHelper()
100 static ::cppu::IPropertyArrayHelper *pArrayHelper;
101 if( ! pArrayHelper )
103 MutexGuard guard( Mutex::getGlobalMutex() );
104 if( ! pArrayHelper )
106 static Property aTable[] =
108 Property(
109 OUString("CursorName"), 0,
110 ::cppu::UnoType<OUString>::get() , 0 ),
111 Property(
112 OUString("EscapeProcessing"), 1,
113 ::getBooleanCppuType() , 0 ),
114 Property(
115 OUString("FetchDirection"), 2,
116 ::cppu::UnoType<sal_Int32>::get() , 0 ),
117 Property(
118 OUString("FetchSize"), 3,
119 ::cppu::UnoType<sal_Int32>::get() , 0 ),
120 Property(
121 OUString("MaxFieldSize"), 4,
122 ::cppu::UnoType<sal_Int32>::get() , 0 ),
123 Property(
124 OUString("MaxRows"), 5,
125 ::cppu::UnoType<sal_Int32>::get() , 0 ),
126 Property(
127 OUString("QueryTimeOut"), 6,
128 ::cppu::UnoType<sal_Int32>::get() , 0 ),
129 Property(
130 OUString("ResultSetConcurrency"), 7,
131 ::cppu::UnoType<sal_Int32>::get() , 0 ),
132 Property(
133 OUString("ResultSetType"), 8,
134 ::cppu::UnoType<sal_Int32>::get() , 0 )
136 OSL_ASSERT( sizeof(aTable)/ sizeof(Property) == PREPARED_STATEMENT_SIZE );
137 static ::cppu::OPropertyArrayHelper arrayHelper( aTable, PREPARED_STATEMENT_SIZE, sal_True );
138 pArrayHelper = &arrayHelper;
141 return *pArrayHelper;
144 static bool isOperator( char c )
146 static const char * operators = "<>=()!/&%.,;";
148 const char * w = operators;
149 while (*w && *w != c)
151 ++w;
153 return *w != 0;
156 static bool isNamedParameterStart( const OString & o , int index )
158 return o[index] == ':' && (
159 isWhitespace( o[index-1] ) || isOperator(o[index-1]) );
162 static bool isQuoted( const OString & str )
164 return str[0] == '"' || str[0] == '\'';
167 PreparedStatement::PreparedStatement(
168 const ::rtl::Reference< RefCountedMutex > & refMutex,
169 const Reference< XConnection > & conn,
170 struct ConnectionSettings *pSettings,
171 const OString & stmt )
172 : OComponentHelper(refMutex->mutex)
173 , OPropertySetHelper(OComponentHelper::rBHelper)
174 , m_connection(conn)
175 , m_pSettings(pSettings)
176 , m_stmt(stmt)
177 , m_refMutex(refMutex)
178 , m_multipleResultAvailable(false)
179 , m_multipleResultUpdateCount(0)
180 , m_lastOidInserted( InvalidOid )
182 m_props[PREPARED_STATEMENT_QUERY_TIME_OUT] = makeAny( (sal_Int32)0 );
183 m_props[PREPARED_STATEMENT_MAX_ROWS] = makeAny( (sal_Int32)0 );
184 m_props[PREPARED_STATEMENT_RESULT_SET_CONCURRENCY] = makeAny(
185 com::sun::star::sdbc::ResultSetConcurrency::READ_ONLY );
186 m_props[PREPARED_STATEMENT_RESULT_SET_TYPE] = makeAny(
187 com::sun::star::sdbc::ResultSetType::SCROLL_INSENSITIVE );
189 splitSQL( m_stmt, m_splittedStatement );
190 int elements = 0;
191 for( int i = 0, max = m_splittedStatement.size(); i < max ; i ++ )
193 const OString &str = m_splittedStatement[i];
194 // ignore quoted strings ....
195 if( ! isQuoted( str ) )
197 // the ':' cannot be the first or the last part of the
198 // token,
199 // the ? cannot be the first part of the token , so we start
200 // at one
201 for( int index = 1 ; index < str.getLength() ; index ++ )
203 if( str[index] == '?' ||
204 isNamedParameterStart( str , index )
207 elements ++;
212 m_vars = OStringVector ( elements );
215 PreparedStatement::~PreparedStatement()
217 POSTGRE_TRACE( "dtor PreparedStatement" );
220 void PreparedStatement::checkColumnIndex( sal_Int32 parameterIndex )
222 if( parameterIndex < 1 || parameterIndex > (sal_Int32) m_vars.size() )
224 OUStringBuffer buf( 128 );
225 buf.appendAscii( "pq_preparedstatement: parameter index out of range (expected 1 to " );
226 buf.append( (sal_Int32 ) m_vars.size() );
227 buf.appendAscii( ", got " );
228 buf.append( parameterIndex );
229 buf.appendAscii( ", statement '" );
230 buf.append( OStringToOUString( m_stmt, m_pSettings->encoding ) );
231 buf.appendAscii( "')" );
232 throw SQLException( buf.makeStringAndClear(), *this, OUString(), 1, Any () );
235 void PreparedStatement::checkClosed() throw (SQLException, RuntimeException )
237 if( ! m_pSettings || ! m_pSettings->pConnection )
238 throw SQLException(
239 "pq_driver: PreparedStatement or connection has already been closed !",
240 *this, OUString(),1,Any());
243 Any PreparedStatement::queryInterface( const Type & reqType ) throw (RuntimeException, std::exception)
245 Any ret;
247 ret = OComponentHelper::queryInterface( reqType );
248 if( ! ret.hasValue() )
249 ret = ::cppu::queryInterface( reqType,
250 static_cast< XWarningsSupplier * > ( this ),
251 static_cast< XPreparedStatement * > ( this ),
252 static_cast< com::sun::star::sdbc::XResultSetMetaDataSupplier * > ( this ),
253 static_cast< XParameters * > ( this ),
254 static_cast< XCloseable * > ( this ),
255 static_cast< XGeneratedResultSet * > ( this ),
256 static_cast< XPropertySet * > ( this ),
257 static_cast< XMultiPropertySet * > ( this ),
258 static_cast< XFastPropertySet * > ( this ) );
259 return ret;
263 Sequence< Type > PreparedStatement::getTypes() throw ( RuntimeException, std::exception )
265 static cppu::OTypeCollection *pCollection;
266 if( ! pCollection )
268 MutexGuard guard( osl::Mutex::getGlobalMutex() );
269 if( !pCollection )
271 static cppu::OTypeCollection collection(
272 getCppuType( (Reference< XWarningsSupplier> *) 0 ),
273 getCppuType( (Reference< XPreparedStatement> *) 0 ),
274 getCppuType( (Reference< com::sun::star::sdbc::XResultSetMetaDataSupplier> *) 0 ),
275 getCppuType( (Reference< XParameters> *) 0 ),
276 getCppuType( (Reference< XCloseable> *) 0 ),
277 getCppuType( (Reference< XGeneratedResultSet> *) 0 ),
278 getCppuType( (Reference< XPropertySet >*) 0 ),
279 getCppuType( (Reference< XFastPropertySet > *) 0 ),
280 getCppuType( (Reference< XMultiPropertySet > *) 0 ),
281 OComponentHelper::getTypes());
282 pCollection = &collection;
285 return pCollection->getTypes();
288 Sequence< sal_Int8> PreparedStatement::getImplementationId() throw ( RuntimeException, std::exception )
290 return css::uno::Sequence<sal_Int8>();
293 void PreparedStatement::close( ) throw (SQLException, RuntimeException, std::exception)
295 // let the connection die without acquired mutex !
296 Reference< XConnection > r;
297 Reference< XCloseable > resultSet;
299 MutexGuard guard( m_refMutex->mutex );
300 m_pSettings = 0;
301 r = m_connection;
302 m_connection.clear();
304 resultSet = m_lastResultset;
305 m_lastResultset.clear();
307 if( resultSet.is() )
309 resultSet->close();
313 void PreparedStatement::raiseSQLException(
314 const char * errorMsg, const char *errorType )
315 throw( SQLException )
317 OUStringBuffer buf(128);
318 buf.appendAscii( "pq_driver: ");
319 if( errorType )
321 buf.appendAscii( "[" );
322 buf.appendAscii( errorType );
323 buf.appendAscii( "]" );
325 buf.append(
326 OUString( errorMsg, strlen(errorMsg) , m_pSettings->encoding ) );
327 buf.appendAscii( " (caused by statement '" );
328 buf.appendAscii( m_executedStatement.getStr() );
329 buf.appendAscii( "')" );
330 OUString error = buf.makeStringAndClear();
331 log( m_pSettings, LogLevel::ERROR, error );
332 throw SQLException( buf.makeStringAndClear(), *this, OUString(), 1, Any() );
335 Reference< XResultSet > PreparedStatement::executeQuery( )
336 throw (SQLException, RuntimeException, std::exception)
338 Reference< XCloseable > lastResultSet = m_lastResultset;
339 if( lastResultSet.is() )
340 lastResultSet->close();
342 if( ! execute( ) )
344 raiseSQLException( "not a query" );
346 return Reference< XResultSet > ( m_lastResultset, com::sun::star::uno::UNO_QUERY );
349 sal_Int32 PreparedStatement::executeUpdate( )
350 throw (SQLException, RuntimeException, std::exception)
352 if( execute( ) )
354 raiseSQLException( "not a command" );
356 return m_multipleResultUpdateCount;
359 sal_Bool PreparedStatement::execute( )
360 throw (SQLException, RuntimeException, std::exception)
362 osl::MutexGuard guard( m_refMutex->mutex );
364 OStringBuffer buf( m_stmt.getLength() *2 );
366 OStringVector::size_type vars = 0;
367 for( OStringVector::size_type i = 0 ; i < m_splittedStatement.size() ; ++i )
369 // LEM TODO: instead of this manual mucking with SQL
370 // could we use PQexecParams / PQExecPrepared / ...?
371 // Only snafu is giving the types of the parameters and
372 // that it needs $1, $2, etc instead of "?"
373 const OString &str = m_splittedStatement[i];
374 // printf( "Splitted %d %s\n" , i , str.getStr() );
375 if( isQuoted( str ) )
377 buf.append( str );
379 else
381 int start = 0,index;
382 for( index = 1 ; index < str.getLength() ; index ++ )
384 if( str[index] == '?' )
386 buf.append( str.getStr()+start, index - start );
387 buf.append( m_vars[vars] );
388 vars ++;
389 start =index+1;
391 else
393 if ( isNamedParameterStart( str, index ) )
395 buf.append( str.getStr()+start, index -start );
396 buf.append( m_vars[vars] );
398 // skip to the end of the named parameter
399 while ( index < str.getLength()
400 && !( isWhitespace(str[index])
401 || isOperator (str[index])))
403 ++index;
405 start = index;
406 vars ++;
410 // if( index +1 >= str.getLength() )
411 // {
412 buf.append( str.getStr() + start, index -start );
413 // }
417 m_executedStatement = buf.makeStringAndClear();
419 m_lastResultset.clear();
420 m_lastTableInserted = OUString();
422 struct CommandData data;
423 data.refMutex = m_refMutex;
424 data.ppSettings = &m_pSettings;
425 data.pLastOidInserted = &m_lastOidInserted;
426 data.pLastQuery = &m_lastQuery;
427 data.pMultipleResultUpdateCount = &m_multipleResultUpdateCount;
428 data.pMultipleResultAvailable = &m_multipleResultAvailable;
429 data.pLastTableInserted = &m_lastTableInserted;
430 data.pLastResultset = &m_lastResultset;
431 data.owner = *this;
432 data.tableSupplier = Reference< com::sun::star::sdbcx::XTablesSupplier >( m_connection, UNO_QUERY );
433 data.concurrency = extractIntProperty( this, getStatics().RESULT_SET_CONCURRENCY );
435 return executePostgresCommand( m_executedStatement , &data ); // see pq_statement.cxx
438 Reference< XConnection > PreparedStatement::getConnection( )
439 throw (SQLException, RuntimeException, std::exception)
441 Reference< XConnection > ret;
443 MutexGuard guard( m_refMutex->mutex );
444 checkClosed();
445 ret = m_connection;
447 return ret;
451 void PreparedStatement::setNull( sal_Int32 parameterIndex, sal_Int32 sqlType )
452 throw (SQLException, RuntimeException, std::exception)
454 (void)sqlType;
455 MutexGuard guard( m_refMutex->mutex );
456 checkClosed();
457 checkColumnIndex( parameterIndex );
458 m_vars[parameterIndex-1] = OString( "NULL" );
461 void PreparedStatement::setObjectNull(
462 sal_Int32 parameterIndex, sal_Int32 sqlType, const OUString& typeName )
463 throw (SQLException, RuntimeException, std::exception)
465 (void) sqlType; (void) typeName;
466 MutexGuard guard( m_refMutex->mutex );
467 checkClosed();
468 checkColumnIndex( parameterIndex );
469 m_vars[parameterIndex-1] = OString( "NULL" );
473 void PreparedStatement::setBoolean( sal_Int32 parameterIndex, sal_Bool x )
474 throw (SQLException, RuntimeException, std::exception)
476 MutexGuard guard(m_refMutex->mutex );
477 checkClosed();
478 checkColumnIndex( parameterIndex );
479 if( x )
480 m_vars[parameterIndex-1] = OString( "'t'" );
481 else
482 m_vars[parameterIndex-1] = OString( "'f'" );
485 void PreparedStatement::setByte( sal_Int32 parameterIndex, sal_Int8 x )
486 throw (SQLException, RuntimeException, std::exception)
488 setInt(parameterIndex,x);
491 void PreparedStatement::setShort( sal_Int32 parameterIndex, sal_Int16 x )
492 throw (SQLException, RuntimeException, std::exception)
494 setInt(parameterIndex, x );
497 void PreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x )
498 throw (SQLException, RuntimeException, std::exception)
500 // printf( "setString %d %d\n ", parameterIndex, x);
501 MutexGuard guard(m_refMutex->mutex );
502 checkClosed();
503 checkColumnIndex( parameterIndex );
504 OStringBuffer buf( 20 );
505 buf.append( "'" );
506 buf.append( (sal_Int32) x );
507 buf.append( "'" );
508 m_vars[parameterIndex-1] = buf.makeStringAndClear();
511 void PreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x )
512 throw (SQLException, RuntimeException, std::exception)
514 MutexGuard guard(m_refMutex->mutex );
515 checkClosed();
516 checkColumnIndex( parameterIndex );
517 OStringBuffer buf( 20 );
518 buf.append( "'" );
519 buf.append( (sal_Int64) x );
520 buf.append( "'" );
521 m_vars[parameterIndex-1] = buf.makeStringAndClear();
524 void PreparedStatement::setFloat( sal_Int32 parameterIndex, float x )
525 throw (SQLException, RuntimeException, std::exception)
527 MutexGuard guard(m_refMutex->mutex );
528 checkClosed();
529 checkColumnIndex( parameterIndex );
530 OStringBuffer buf( 20 );
531 buf.append( "'" );
532 buf.append( x );
533 buf.append( "'" );
534 m_vars[parameterIndex-1] = buf.makeStringAndClear();
537 void PreparedStatement::setDouble( sal_Int32 parameterIndex, double x )
538 throw (SQLException, RuntimeException, std::exception)
540 MutexGuard guard(m_refMutex->mutex );
541 checkClosed();
542 checkColumnIndex( parameterIndex );
543 OStringBuffer buf( 20 );
544 buf.append( "'" );
545 buf.append( x );
546 buf.append( "'" );
547 m_vars[parameterIndex-1] = buf.makeStringAndClear();
550 void PreparedStatement::setString( sal_Int32 parameterIndex, const OUString& x )
551 throw (SQLException, RuntimeException, std::exception)
553 // printf( "setString %d %s\n ", parameterIndex,
554 // OUStringToOString( x , RTL_TEXTENCODING_ASCII_US ).getStr());
555 MutexGuard guard(m_refMutex->mutex );
556 checkClosed();
557 checkColumnIndex( parameterIndex );
558 OStringBuffer buf( 20 );
559 buf.append( "'" );
560 OString y = OUStringToOString( x, m_pSettings->encoding );
561 buf.ensureCapacity( y.getLength() * 2 + 2 );
562 int len = PQescapeString( ((char*)buf.getStr())+1, y.getStr() , y.getLength() );
563 buf.setLength( 1 + len );
564 buf.append( "'" );
565 m_vars[parameterIndex-1] = buf.makeStringAndClear();
568 void PreparedStatement::setBytes(
569 sal_Int32 parameterIndex, const Sequence< sal_Int8 >& x )
570 throw (SQLException, RuntimeException, std::exception)
572 MutexGuard guard(m_refMutex->mutex );
573 checkClosed();
574 checkColumnIndex( parameterIndex );
575 OStringBuffer buf( 20 );
576 buf.append( "'" );
577 size_t len;
578 unsigned char * escapedString =
579 PQescapeBytea( (unsigned char *)x.getConstArray(), x.getLength(), &len);
580 if( ! escapedString )
582 throw SQLException(
583 "pq_preparedstatement.setBytes: Error during converting bytesequence to an SQL conform string",
584 *this, OUString(), 1, Any() );
586 buf.append( (const sal_Char *)escapedString, len -1 );
587 free( escapedString );
588 buf.append( "'" );
589 m_vars[parameterIndex-1] = buf.makeStringAndClear();
593 void PreparedStatement::setDate( sal_Int32 parameterIndex, const ::com::sun::star::util::Date& x )
594 throw (SQLException, RuntimeException, std::exception)
596 setString( parameterIndex, DBTypeConversion::toDateString( x ) );
599 void PreparedStatement::setTime( sal_Int32 parameterIndex, const ::com::sun::star::util::Time& x )
600 throw (SQLException, RuntimeException, std::exception)
602 setString( parameterIndex, DBTypeConversion::toTimeString( x ) );
605 void PreparedStatement::setTimestamp(
606 sal_Int32 parameterIndex, const ::com::sun::star::util::DateTime& x )
607 throw (SQLException, RuntimeException, std::exception)
609 setString( parameterIndex, DBTypeConversion::toDateTimeString( x ) );
612 void PreparedStatement::setBinaryStream(
613 sal_Int32 parameterIndex,
614 const Reference< ::com::sun::star::io::XInputStream >& x,
615 sal_Int32 length )
616 throw (SQLException, RuntimeException, std::exception)
618 (void) parameterIndex; (void)x; (void) length;
619 throw SQLException(
620 "pq_preparedstatement: setBinaryStream not implemented",
621 *this, OUString(), 1, Any () );
624 void PreparedStatement::setCharacterStream(
625 sal_Int32 parameterIndex,
626 const Reference< ::com::sun::star::io::XInputStream >& x,
627 sal_Int32 length )
628 throw (SQLException, RuntimeException, std::exception)
630 (void) parameterIndex; (void)x; (void) length;
631 throw SQLException(
632 "pq_preparedstatement: setCharacterStream not implemented",
633 *this, OUString(), 1, Any () );
636 void PreparedStatement::setObject( sal_Int32 parameterIndex, const Any& x )
637 throw (SQLException, RuntimeException, std::exception)
639 if( ! implSetObject( this, parameterIndex, x ))
641 OUStringBuffer buf;
642 buf.append( "pq_preparedstatement::setObject: can't convert value of type " );
643 buf.append( x.getValueTypeName() );
644 throw SQLException( buf.makeStringAndClear(), *this, OUString(), 1, Any () );
648 void PreparedStatement::setObjectWithInfo(
649 sal_Int32 parameterIndex,
650 const Any& x,
651 sal_Int32 targetSqlType,
652 sal_Int32 scale )
653 throw (SQLException, RuntimeException, std::exception)
655 (void) scale;
656 if( com::sun::star::sdbc::DataType::DECIMAL == targetSqlType ||
657 com::sun::star::sdbc::DataType::NUMERIC == targetSqlType )
659 double myDouble = 0.0;
660 OUString myString;
661 if( x >>= myDouble )
663 myString = OUString::number( myDouble );
665 else
667 x >>= myString;
669 if( !myString.isEmpty() )
671 // printf( "setObjectWithInfo %s\n", OUStringToOString(myString,RTL_TEXTENCODING_ASCII_US).getStr());
672 setString( parameterIndex, myString );
674 else
676 OUStringBuffer buf;
677 buf.append( "pq_preparedstatement::setObjectWithInfo: can't convert value of type " );
678 buf.append( x.getValueTypeName() );
679 buf.append( " to type DECIMAL or NUMERIC" );
680 throw SQLException( buf.makeStringAndClear(), *this, OUString(), 1, Any () );
683 else
685 setObject( parameterIndex, x );
690 void PreparedStatement::setRef(
691 sal_Int32 parameterIndex,
692 const Reference< XRef >& x )
693 throw (SQLException, RuntimeException, std::exception)
695 (void) parameterIndex; (void)x;
696 throw SQLException(
697 "pq_preparedstatement: setRef not implemented",
698 *this, OUString(), 1, Any () );
701 void PreparedStatement::setBlob(
702 sal_Int32 parameterIndex,
703 const Reference< XBlob >& x )
704 throw (SQLException, RuntimeException, std::exception)
706 (void) parameterIndex; (void)x;
707 throw SQLException(
708 "pq_preparedstatement: setBlob not implemented",
709 *this, OUString(), 1, Any () );
712 void PreparedStatement::setClob(
713 sal_Int32 parameterIndex,
714 const Reference< XClob >& x )
715 throw (SQLException, RuntimeException, std::exception)
717 (void) parameterIndex; (void)x;
718 throw SQLException(
719 "pq_preparedstatement: setClob not implemented",
720 *this, OUString(), 1, Any () );
723 void PreparedStatement::setArray(
724 sal_Int32 parameterIndex,
725 const Reference< XArray >& x )
726 throw (SQLException, RuntimeException, std::exception)
728 setString( parameterIndex, array2String( x->getArray( 0 ) ) );
731 void PreparedStatement::clearParameters( )
732 throw (SQLException, RuntimeException, std::exception)
734 MutexGuard guard(m_refMutex->mutex );
735 m_vars = OStringVector ( m_vars.size() );
738 Any PreparedStatement::getWarnings( )
739 throw (SQLException,RuntimeException, std::exception)
741 return Any();
744 void PreparedStatement::clearWarnings( )
745 throw (SQLException, RuntimeException, std::exception)
749 Reference< ::com::sun::star::sdbc::XResultSetMetaData > PreparedStatement::getMetaData()
750 throw (SQLException,RuntimeException, std::exception)
752 Reference< com::sun::star::sdbc::XResultSetMetaData > ret;
753 Reference< com::sun::star::sdbc::XResultSetMetaDataSupplier > supplier( m_lastResultset, UNO_QUERY );
754 if( supplier.is() )
755 ret = supplier->getMetaData();
756 return ret;
759 ::cppu::IPropertyArrayHelper & PreparedStatement::getInfoHelper()
761 return getPreparedStatementPropertyArrayHelper();
765 sal_Bool PreparedStatement::convertFastPropertyValue(
766 Any & rConvertedValue, Any & rOldValue, sal_Int32 nHandle, const Any& rValue )
767 throw (IllegalArgumentException)
769 bool bRet;
770 rOldValue = m_props[nHandle];
771 switch( nHandle )
773 case PREPARED_STATEMENT_CURSOR_NAME:
775 OUString val;
776 bRet = ( rValue >>= val );
777 rConvertedValue = makeAny( val );
778 break;
780 case PREPARED_STATEMENT_ESCAPE_PROCESSING:
782 bool val(false);
783 bRet = ( rValue >>= val );
784 rConvertedValue = makeAny( val );
785 break;
787 case PREPARED_STATEMENT_FETCH_DIRECTION:
788 case PREPARED_STATEMENT_FETCH_SIZE:
789 case PREPARED_STATEMENT_MAX_FIELD_SIZE:
790 case PREPARED_STATEMENT_MAX_ROWS:
791 case PREPARED_STATEMENT_QUERY_TIME_OUT:
792 case PREPARED_STATEMENT_RESULT_SET_CONCURRENCY:
793 case PREPARED_STATEMENT_RESULT_SET_TYPE:
795 sal_Int32 val;
796 bRet = ( rValue >>= val );
797 rConvertedValue = makeAny( val );
798 break;
800 default:
802 OUStringBuffer buf(128);
803 buf.appendAscii( "pq_statement: Invalid property handle (" );
804 buf.append( nHandle );
805 buf.appendAscii( ")" );
806 throw IllegalArgumentException( buf.makeStringAndClear(), *this, 2 );
809 return bRet;
813 void PreparedStatement::setFastPropertyValue_NoBroadcast(
814 sal_Int32 nHandle,const Any& rValue ) throw (Exception, std::exception)
816 m_props[nHandle] = rValue;
819 void PreparedStatement::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
821 rValue = m_props[nHandle];
824 Reference < XPropertySetInfo > PreparedStatement::getPropertySetInfo()
825 throw(RuntimeException, std::exception)
827 return OPropertySetHelper::createPropertySetInfo( getPreparedStatementPropertyArrayHelper() );
830 void PreparedStatement::disposing()
832 close();
836 Reference< XResultSet > PreparedStatement::getResultSet( )
837 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
839 return Reference< XResultSet > ( m_lastResultset, com::sun::star::uno::UNO_QUERY );
841 sal_Int32 PreparedStatement::getUpdateCount( )
842 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
844 return m_multipleResultUpdateCount;
846 sal_Bool PreparedStatement::getMoreResults( )
847 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException, std::exception)
849 return sal_False;
852 Reference< XResultSet > PreparedStatement::getGeneratedValues( )
853 throw (SQLException, RuntimeException, std::exception)
855 osl::MutexGuard guard( m_refMutex->mutex );
856 return getGeneratedValuesFromLastInsert(
857 m_pSettings, m_connection, m_lastOidInserted, m_lastTableInserted, m_lastQuery );
863 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */