1 /*************************************************************************
3 * $RCSfile: pq_preparedstatement.cxx,v $
5 * $Revision: 1.1.2.10 $
7 * last change: $Author: jbu $ $Date: 2008/07/07 21:37:11 $
9 * The Contents of this file are made available subject to the terms of
10 * either of the following licenses
12 * - GNU Lesser General Public License Version 2.1
13 * - Sun Industry Standards Source License Version 1.1
15 * Sun Microsystems Inc., October, 2000
17 * GNU Lesser General Public License Version 2.1
18 * =============================================
19 * Copyright 2000 by Sun Microsystems, Inc.
20 * 901 San Antonio Road, Palo Alto, CA 94303, USA
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License version 2.1, as published by the Free Software Foundation.
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
37 * Sun Industry Standards Source License Version 1.1
38 * =================================================
39 * The contents of this file are subject to the Sun Industry Standards
40 * Source License Version 1.1 (the "License"); You may not use this file
41 * except in compliance with the License. You may obtain a copy of the
42 * License at http://www.openoffice.org/license.html.
44 * Software provided under this License is provided on an "AS IS" basis,
45 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
46 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
47 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
48 * See the License for the specific provisions governing your rights and
49 * obligations concerning the Software.
51 * The Initial Developer of the Original Code is: Joerg Budischewski
53 * Copyright: 2000 by Sun Microsystems, Inc.
55 * All Rights Reserved.
57 * Contributor(s): Joerg Budischewski
60 ************************************************************************/
62 #include "pq_preparedstatement.hxx"
63 #include "pq_resultset.hxx"
64 #include "pq_tools.hxx"
65 #include "pq_statics.hxx"
66 #include "pq_statement.hxx"
68 #include <rtl/strbuf.hxx>
69 #include <rtl/ustrbuf.hxx>
72 #include <cppuhelper/typeprovider.hxx>
73 #include <cppuhelper/queryinterface.hxx>
75 #include <com/sun/star/beans/PropertyAttribute.hpp>
77 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
78 #include <com/sun/star/sdbc/ResultSetType.hpp>
83 using osl::MutexGuard
;
86 using rtl::OUStringToOString
;
87 using rtl::OStringToOUString
;
88 using rtl::OUStringBuffer
;
89 using rtl::OStringBuffer
;
92 using com::sun::star::uno::Any
;
93 using com::sun::star::uno::makeAny
;
94 using com::sun::star::uno::Type
;
95 using com::sun::star::uno::RuntimeException
;
96 using com::sun::star::uno::Exception
;
97 using com::sun::star::uno::Sequence
;
98 using com::sun::star::uno::Reference
;
99 using com::sun::star::uno::XInterface
;
100 using com::sun::star::uno::UNO_QUERY
;
102 using com::sun::star::lang::IllegalArgumentException
;
104 using com::sun::star::sdbc::XWarningsSupplier
;
105 using com::sun::star::sdbc::XCloseable
;
106 using com::sun::star::sdbc::XPreparedStatement
;
107 using com::sun::star::sdbc::XParameters
;
108 using com::sun::star::sdbc::XResultSet
;
109 using com::sun::star::sdbc::XRef
;
110 using com::sun::star::sdbc::XBlob
;
111 using com::sun::star::sdbc::XClob
;
112 using com::sun::star::sdbc::XArray
;
113 using com::sun::star::sdbc::XConnection
;
114 using com::sun::star::sdbc::XGeneratedResultSet
;
115 using com::sun::star::sdbc::SQLException
;
117 using com::sun::star::beans::Property
;
118 using com::sun::star::beans::XPropertySetInfo
;
119 using com::sun::star::beans::XPropertySet
;
120 using com::sun::star::beans::XMultiPropertySet
;
121 using com::sun::star::beans::XFastPropertySet
;
123 #define ASCII_STR(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
124 namespace pq_sdbc_driver
126 static ::cppu::IPropertyArrayHelper
& getPreparedStatementPropertyArrayHelper()
128 static ::cppu::IPropertyArrayHelper
*pArrayHelper
;
131 MutexGuard
guard( Mutex::getGlobalMutex() );
134 static Property aTable
[] =
137 OUString( RTL_CONSTASCII_USTRINGPARAM("CursorName") ), 0,
138 ::getCppuType( (OUString
*)0) , 0 ),
140 OUString( RTL_CONSTASCII_USTRINGPARAM("EscapeProcessing") ), 1,
141 ::getBooleanCppuType() , 0 ),
143 OUString( RTL_CONSTASCII_USTRINGPARAM("FetchDirection") ), 2,
144 ::getCppuType( (sal_Int32
*)0) , 0 ),
146 OUString( RTL_CONSTASCII_USTRINGPARAM("FetchSize") ), 3,
147 ::getCppuType( (sal_Int32
*)0) , 0 ),
149 OUString( RTL_CONSTASCII_USTRINGPARAM("MaxFieldSize") ), 4,
150 ::getCppuType( (sal_Int32
*)0) , 0 ),
152 OUString( RTL_CONSTASCII_USTRINGPARAM("MaxRows") ), 5,
153 ::getCppuType( (sal_Int32
*)0) , 0 ),
155 OUString( RTL_CONSTASCII_USTRINGPARAM("QueryTimeOut") ), 6,
156 ::getCppuType( (sal_Int32
*)0) , 0 ),
158 OUString( RTL_CONSTASCII_USTRINGPARAM("ResultSetConcurrency") ), 7,
159 ::getCppuType( (sal_Int32
*)0) , 0 ),
161 OUString( RTL_CONSTASCII_USTRINGPARAM("ResultSetType") ), 8,
162 ::getCppuType( (sal_Int32
*)0) , 0 )
164 OSL_ASSERT( sizeof(aTable
)/ sizeof(Property
) == PREPARED_STATEMENT_SIZE
);
165 static ::cppu::OPropertyArrayHelper
arrayHelper( aTable
, PREPARED_STATEMENT_SIZE
, sal_True
);
166 pArrayHelper
= &arrayHelper
;
169 return *pArrayHelper
;
172 static bool isOperator( char c
)
174 static const char * operators
= "<>=()!/&%.,;";
176 const char * w
= operators
;
177 for( ; *w
&& *w
!= c
; w
++);
181 static bool isNamedParameterStart( const rtl::OString
& o
, int index
)
183 return o
[index
] == ':' && (
184 isWhitespace( o
[index
-1] ) || isOperator(o
[index
-1]) );
187 static bool isQuoted( const rtl::OString
& str
)
189 return str
[0] == '"' || str
[0] == '\'';
192 PreparedStatement::PreparedStatement(
193 const ::rtl::Reference
< RefCountedMutex
> & refMutex
,
194 const Reference
< XConnection
> & conn
,
195 struct ConnectionSettings
*pSettings
,
196 const ::rtl::OString
& stmt
)
197 : OComponentHelper( refMutex
->mutex
),
198 OPropertySetHelper( OComponentHelper::rBHelper
),
199 m_refMutex( refMutex
),
200 m_connection( conn
),
201 m_pSettings( pSettings
),
203 m_lastOidInserted( InvalidOid
)
205 m_props
[PREPARED_STATEMENT_QUERY_TIME_OUT
] = makeAny( (sal_Int32
)0 );
206 m_props
[PREPARED_STATEMENT_MAX_ROWS
] = makeAny( (sal_Int32
)0 );
207 m_props
[PREPARED_STATEMENT_RESULT_SET_CONCURRENCY
] = makeAny(
208 com::sun::star::sdbc::ResultSetConcurrency::READ_ONLY
);
209 m_props
[PREPARED_STATEMENT_RESULT_SET_TYPE
] = makeAny(
210 com::sun::star::sdbc::ResultSetType::SCROLL_INSENSITIVE
);
212 splitSQL( m_stmt
, m_splittedStatement
);
214 for( int i
= 0, max
= m_splittedStatement
.size(); i
< max
; i
++ )
216 const OString
&str
= m_splittedStatement
[i
];
217 // ignore quoted strings ....
218 if( ! isQuoted( str
) )
220 // the ':' cannot be the first or the last part of the
222 // the ? cannot be the first part of the token , so we start
224 for( int index
= 1 ; index
< str
.getLength() ; index
++ )
226 if( str
[index
] == '?' ||
227 isNamedParameterStart( str
, index
)
235 m_vars
= OStringVector ( elements
);
238 PreparedStatement::~PreparedStatement()
240 POSTGRE_TRACE( "dtor PreparedStatement" );
243 void PreparedStatement::checkColumnIndex( sal_Int32 parameterIndex
)
245 if( parameterIndex
< 1 || parameterIndex
> (sal_Int32
) m_vars
.size() )
247 OUStringBuffer
buf( 128 );
248 buf
.appendAscii( "pq_preparedstatement: parameter index out of range (expected 1 to " );
249 buf
.append( (sal_Int32
) m_vars
.size() );
250 buf
.appendAscii( ", got " );
251 buf
.append( parameterIndex
);
252 buf
.appendAscii( ", statement '" );
253 buf
.append( OStringToOUString( m_stmt
, m_pSettings
->encoding
) );
254 buf
.appendAscii( "')" );
255 throw SQLException( buf
.makeStringAndClear(), *this, OUString(), 1, Any () );
258 void PreparedStatement::checkClosed() throw (SQLException
, RuntimeException
)
260 if( ! m_pSettings
|| ! m_pSettings
->pConnection
)
262 ASCII_STR("pq_driver: PreparedStatement or connection has already been closed !" ),
263 *this, OUString(),1,Any());
266 Any
PreparedStatement::queryInterface( const Type
& reqType
) throw (RuntimeException
)
270 ret
= OComponentHelper::queryInterface( reqType
);
271 if( ! ret
.hasValue() )
272 ret
= ::cppu::queryInterface( reqType
,
273 static_cast< XWarningsSupplier
* > ( this ),
274 static_cast< XPreparedStatement
* > ( this ),
275 static_cast< com::sun::star::sdbc::XResultSetMetaDataSupplier
* > ( this ),
276 static_cast< XParameters
* > ( this ),
277 static_cast< XCloseable
* > ( this ),
278 static_cast< XGeneratedResultSet
* > ( this ),
279 static_cast< XPropertySet
* > ( this ),
280 static_cast< XMultiPropertySet
* > ( this ),
281 static_cast< XFastPropertySet
* > ( this ) );
286 Sequence
< Type
> PreparedStatement::getTypes() throw ( RuntimeException
)
288 static cppu::OTypeCollection
*pCollection
;
291 MutexGuard
guard( osl::Mutex::getGlobalMutex() );
294 static cppu::OTypeCollection
collection(
295 getCppuType( (Reference
< XWarningsSupplier
> *) 0 ),
296 getCppuType( (Reference
< XPreparedStatement
> *) 0 ),
297 getCppuType( (Reference
< com::sun::star::sdbc::XResultSetMetaDataSupplier
> *) 0 ),
298 getCppuType( (Reference
< XParameters
> *) 0 ),
299 getCppuType( (Reference
< XCloseable
> *) 0 ),
300 getCppuType( (Reference
< XGeneratedResultSet
> *) 0 ),
301 getCppuType( (Reference
< XPropertySet
>*) 0 ),
302 getCppuType( (Reference
< XFastPropertySet
> *) 0 ),
303 getCppuType( (Reference
< XMultiPropertySet
> *) 0 ),
304 OComponentHelper::getTypes());
305 pCollection
= &collection
;
308 return pCollection
->getTypes();
311 Sequence
< sal_Int8
> PreparedStatement::getImplementationId() throw ( RuntimeException
)
313 static cppu::OImplementationId
*pId
;
316 MutexGuard
guard( osl::Mutex::getGlobalMutex() );
319 static cppu::OImplementationId
id(sal_False
);
323 return pId
->getImplementationId();
326 void PreparedStatement::close( ) throw (SQLException
, RuntimeException
)
328 // let the connection die without acquired mutex !
329 Reference
< XConnection
> r
;
330 Reference
< XCloseable
> resultSet
;
332 MutexGuard
guard( m_refMutex
->mutex
);
335 m_connection
.clear();
337 resultSet
= m_lastResultset
;
338 m_lastResultset
.clear();
346 void PreparedStatement::raiseSQLException(
347 const char * errorMsg
, const char *errorType
)
348 throw( SQLException
)
350 OUStringBuffer
buf(128);
351 buf
.appendAscii( "pq_driver: ");
354 buf
.appendAscii( "[" );
355 buf
.appendAscii( errorType
);
356 buf
.appendAscii( "]" );
359 rtl::OUString( errorMsg
, strlen(errorMsg
) , m_pSettings
->encoding
) );
360 buf
.appendAscii( " (caused by statement '" );
361 buf
.appendAscii( m_executedStatement
);
362 buf
.appendAscii( "')" );
363 OUString error
= buf
.makeStringAndClear();
364 log( m_pSettings
, LogLevel::ERROR
, error
);
365 throw SQLException( buf
.makeStringAndClear(), *this, OUString(), 1, Any() );
368 Reference
< XResultSet
> PreparedStatement::executeQuery( )
369 throw (SQLException
, RuntimeException
)
371 Reference
< XCloseable
> lastResultSet
= m_lastResultset
;
372 if( lastResultSet
.is() )
373 lastResultSet
->close();
377 raiseSQLException( "not a query" );
379 return Reference
< XResultSet
> ( m_lastResultset
, com::sun::star::uno::UNO_QUERY
);
382 sal_Int32
PreparedStatement::executeUpdate( )
383 throw (SQLException
, RuntimeException
)
387 raiseSQLException( "not a command" );
389 return m_multipleResultUpdateCount
;
392 sal_Bool
PreparedStatement::execute( )
393 throw (SQLException
, RuntimeException
)
395 osl::MutexGuard
guard( m_refMutex
->mutex
);
397 OStringBuffer
buf( m_stmt
.getLength() *2 );
400 for( int i
= 0 ; i
< m_splittedStatement
.size() ; i
++ )
402 const OString
&str
= m_splittedStatement
[i
];
403 // printf( "Splitted %d %s\n" , i , str.getStr() );
404 if( isQuoted( str
) )
411 for( index
= 1 ; index
< str
.getLength() ; index
++ )
413 if( str
[index
] == '?' )
415 buf
.append( str
.getStr()+start
, index
- start
);
416 buf
.append( m_vars
[vars
] );
422 if ( isNamedParameterStart( str
, index
) )
424 buf
.append( str
.getStr()+start
, index
-start
);
425 buf
.append( m_vars
[vars
] );
427 // skip to the end of the named parameter
428 for( ; index
< str
.getLength() &&
429 ! ( isWhitespace( str
[index
] ) || isOperator( str
[index
] ) ) ; index
++ );
435 // if( index +1 >= str.getLength() )
437 buf
.append( str
.getStr() + start
, index
-start
);
442 m_executedStatement
= buf
.makeStringAndClear();
444 m_lastResultset
.clear();
445 m_lastTableInserted
= rtl::OUString();
447 struct CommandData data
;
448 data
.refMutex
= m_refMutex
;
449 data
.ppSettings
= &m_pSettings
;
450 data
.pLastOidInserted
= &m_lastOidInserted
;
451 data
.pLastQuery
= &m_lastQuery
;
452 data
.pMultipleResultUpdateCount
= &m_multipleResultUpdateCount
;
453 data
.pMultipleResultAvailable
= &m_multipleResultAvailable
;
454 data
.pLastTableInserted
= &m_lastTableInserted
;
455 data
.pLastResultset
= &m_lastResultset
;
457 data
.tableSupplier
= Reference
< com::sun::star::sdbcx::XTablesSupplier
>( m_connection
, UNO_QUERY
);
458 data
.concurrency
= extractIntProperty( this, getStatics().RESULT_SET_CONCURRENCY
);
460 return executePostgresCommand( m_executedStatement
, &data
); // see pq_statement.cxx
463 Reference
< XConnection
> PreparedStatement::getConnection( )
464 throw (SQLException
, RuntimeException
)
466 Reference
< XConnection
> ret
;
468 MutexGuard
guard( m_refMutex
->mutex
);
476 void PreparedStatement::setNull( sal_Int32 parameterIndex
, sal_Int32 sqlType
)
477 throw (SQLException
, RuntimeException
)
479 MutexGuard
guard( m_refMutex
->mutex
);
481 checkColumnIndex( parameterIndex
);
482 m_vars
[parameterIndex
-1] = OString( "NULL" );
485 void PreparedStatement::setObjectNull(
486 sal_Int32 parameterIndex
, sal_Int32 sqlType
, const ::rtl::OUString
& typeName
)
487 throw (SQLException
, RuntimeException
)
489 MutexGuard
guard( m_refMutex
->mutex
);
491 checkColumnIndex( parameterIndex
);
492 m_vars
[parameterIndex
-1] = OString( "NULL" );
496 void PreparedStatement::setBoolean( sal_Int32 parameterIndex
, sal_Bool x
)
497 throw (SQLException
, RuntimeException
)
499 MutexGuard
guard(m_refMutex
->mutex
);
501 checkColumnIndex( parameterIndex
);
503 m_vars
[parameterIndex
-1] = OString( "'t'" );
505 m_vars
[parameterIndex
-1] = OString( "'f'" );
508 void PreparedStatement::setByte( sal_Int32 parameterIndex
, sal_Int8 x
)
509 throw (SQLException
, RuntimeException
)
511 setInt(parameterIndex
,x
);
514 void PreparedStatement::setShort( sal_Int32 parameterIndex
, sal_Int16 x
)
515 throw (SQLException
, RuntimeException
)
517 setInt(parameterIndex
, x
);
520 void PreparedStatement::setInt( sal_Int32 parameterIndex
, sal_Int32 x
)
521 throw (SQLException
, RuntimeException
)
523 // printf( "setString %d %d\n ", parameterIndex, x);
524 MutexGuard
guard(m_refMutex
->mutex
);
526 checkColumnIndex( parameterIndex
);
527 OStringBuffer
buf( 20 );
529 buf
.append( (sal_Int32
) x
);
531 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
534 void PreparedStatement::setLong( sal_Int32 parameterIndex
, sal_Int64 x
)
535 throw (SQLException
, RuntimeException
)
537 MutexGuard
guard(m_refMutex
->mutex
);
539 checkColumnIndex( parameterIndex
);
540 OStringBuffer
buf( 20 );
542 buf
.append( (sal_Int64
) x
);
544 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
547 void PreparedStatement::setFloat( sal_Int32 parameterIndex
, float x
)
548 throw (SQLException
, RuntimeException
)
550 MutexGuard
guard(m_refMutex
->mutex
);
552 checkColumnIndex( parameterIndex
);
553 OStringBuffer
buf( 20 );
557 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
560 void PreparedStatement::setDouble( sal_Int32 parameterIndex
, double x
)
561 throw (SQLException
, RuntimeException
)
563 MutexGuard
guard(m_refMutex
->mutex
);
565 checkColumnIndex( parameterIndex
);
566 OStringBuffer
buf( 20 );
570 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
573 void PreparedStatement::setString( sal_Int32 parameterIndex
, const ::rtl::OUString
& x
)
574 throw (SQLException
, RuntimeException
)
576 // printf( "setString %d %s\n ", parameterIndex,
577 // OUStringToOString( x , RTL_TEXTENCODING_ASCII_US ).getStr());
578 MutexGuard
guard(m_refMutex
->mutex
);
580 checkColumnIndex( parameterIndex
);
581 OStringBuffer
buf( 20 );
583 OString y
= OUStringToOString( x
, m_pSettings
->encoding
);
584 buf
.ensureCapacity( y
.getLength() * 2 + 2 );
585 int len
= PQescapeString( ((char*)buf
.getStr())+1, y
.getStr() , y
.getLength() );
586 buf
.setLength( 1 + len
);
588 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
591 void PreparedStatement::setBytes(
592 sal_Int32 parameterIndex
, const Sequence
< sal_Int8
>& x
)
593 throw (SQLException
, RuntimeException
)
595 MutexGuard
guard(m_refMutex
->mutex
);
597 checkColumnIndex( parameterIndex
);
598 OStringBuffer
buf( 20 );
601 unsigned char * escapedString
=
602 PQescapeBytea( (unsigned char *)x
.getConstArray(), x
.getLength(), &len
);
603 if( ! escapedString
)
606 ASCII_STR("pq_preparedstatement.setBytes: Error during converting bytesequence to an SQL conform string" ),
607 *this, OUString(), 1, Any() );
609 buf
.append( (const sal_Char
*)escapedString
, len
-1 );
610 free( escapedString
);
612 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
616 void PreparedStatement::setDate( sal_Int32 parameterIndex
, const ::com::sun::star::util::Date
& x
)
617 throw (SQLException
, RuntimeException
)
619 setString( parameterIndex
, date2String( x
) );
622 void PreparedStatement::setTime( sal_Int32 parameterIndex
, const ::com::sun::star::util::Time
& x
)
623 throw (SQLException
, RuntimeException
)
625 setString( parameterIndex
, time2String( x
) );
628 void PreparedStatement::setTimestamp(
629 sal_Int32 parameterIndex
, const ::com::sun::star::util::DateTime
& x
)
630 throw (SQLException
, RuntimeException
)
632 setString( parameterIndex
, dateTime2String( x
) );
635 void PreparedStatement::setBinaryStream(
636 sal_Int32 parameterIndex
,
637 const Reference
< ::com::sun::star::io::XInputStream
>& x
,
639 throw (SQLException
, RuntimeException
)
642 ASCII_STR( "pq_preparedstatement: setBinaryStream not implemented" ),
643 *this, OUString(), 1, Any () );
646 void PreparedStatement::setCharacterStream(
647 sal_Int32 parameterIndex
,
648 const Reference
< ::com::sun::star::io::XInputStream
>& x
,
650 throw (SQLException
, RuntimeException
)
653 ASCII_STR( "pq_preparedstatement: setCharacterStream not implemented" ),
654 *this, OUString(), 1, Any () );
657 void PreparedStatement::setObject( sal_Int32 parameterIndex
, const Any
& x
)
658 throw (SQLException
, RuntimeException
)
660 if( ! implSetObject( this, parameterIndex
, x
))
663 buf
.append( ASCII_STR("pq_preparedstatement::setObject: can't convert value of type " ) );
664 buf
.append( x
.getValueTypeName() );
665 throw SQLException( buf
.makeStringAndClear(), *this, OUString(), 1, Any () );
669 void PreparedStatement::setObjectWithInfo(
670 sal_Int32 parameterIndex
,
672 sal_Int32 targetSqlType
,
674 throw (SQLException
, RuntimeException
)
676 if( com::sun::star::sdbc::DataType::DECIMAL
== targetSqlType
||
677 com::sun::star::sdbc::DataType::NUMERIC
== targetSqlType
)
683 myString
= OUString::valueOf( myDouble
);
689 if( myString
.getLength() )
691 // printf( "setObjectWithInfo %s\n", OUStringToOString(myString,RTL_TEXTENCODING_ASCII_US).getStr());
692 setString( parameterIndex
, myString
);
697 buf
.append( ASCII_STR("pq_preparedstatement::setObjectWithInfo: can't convert value of type " ) );
698 buf
.append( x
.getValueTypeName() );
699 buf
.append( ASCII_STR(" to type DECIMAL or NUMERIC" ) );
700 throw SQLException( buf
.makeStringAndClear(), *this, OUString(), 1, Any () );
705 setObject( parameterIndex
, x
);
710 void PreparedStatement::setRef(
711 sal_Int32 parameterIndex
,
712 const Reference
< XRef
>& x
)
713 throw (SQLException
, RuntimeException
)
716 ASCII_STR( "pq_preparedstatement: setRef not implemented" ),
717 *this, OUString(), 1, Any () );
721 void PreparedStatement::setBlob(
722 sal_Int32 parameterIndex
,
723 const Reference
< XBlob
>& x
)
724 throw (SQLException
, RuntimeException
)
727 ASCII_STR( "pq_preparedstatement: setBlob not implemented" ),
728 *this, OUString(), 1, Any () );
731 void PreparedStatement::setClob(
732 sal_Int32 parameterIndex
,
733 const Reference
< XClob
>& x
)
734 throw (SQLException
, RuntimeException
)
737 ASCII_STR( "pq_preparedstatement: setClob not implemented" ),
738 *this, OUString(), 1, Any () );
741 void PreparedStatement::setArray(
742 sal_Int32 parameterIndex
,
743 const Reference
< XArray
>& x
)
744 throw (SQLException
, RuntimeException
)
746 setString( parameterIndex
, array2String( x
->getArray( 0 ) ) );
748 // throw SQLException(
749 // ASCII_STR( "pq_preparedstatement: setArray not implemented" ),
750 // *this, OUString(), 1, Any () );
753 void PreparedStatement::clearParameters( )
754 throw (SQLException
, RuntimeException
)
756 MutexGuard
guard(m_refMutex
->mutex
);
757 m_vars
= OStringVector ( m_vars
.size() );
760 Any
PreparedStatement::getWarnings( )
761 throw (SQLException
,RuntimeException
)
766 void PreparedStatement::clearWarnings( )
767 throw (SQLException
, RuntimeException
)
771 Reference
< ::com::sun::star::sdbc::XResultSetMetaData
> PreparedStatement::getMetaData()
772 throw (SQLException
,RuntimeException
)
774 Reference
< com::sun::star::sdbc::XResultSetMetaData
> ret
;
775 Reference
< com::sun::star::sdbc::XResultSetMetaDataSupplier
> supplier( m_lastResultset
, UNO_QUERY
);
777 ret
= supplier
->getMetaData();
781 ::cppu::IPropertyArrayHelper
& PreparedStatement::getInfoHelper()
783 return getPreparedStatementPropertyArrayHelper();
787 sal_Bool
PreparedStatement::convertFastPropertyValue(
788 Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nHandle
, const Any
& rValue
)
789 throw (IllegalArgumentException
)
792 rOldValue
= m_props
[nHandle
];
795 case PREPARED_STATEMENT_CURSOR_NAME
:
798 bRet
= ( rValue
>>= val
);
799 rConvertedValue
= makeAny( val
);
802 case PREPARED_STATEMENT_ESCAPE_PROCESSING
:
805 bRet
= ( rValue
>>= val
);
806 rConvertedValue
= makeAny( val
);
809 case PREPARED_STATEMENT_FETCH_DIRECTION
:
810 case PREPARED_STATEMENT_FETCH_SIZE
:
811 case PREPARED_STATEMENT_MAX_FIELD_SIZE
:
812 case PREPARED_STATEMENT_MAX_ROWS
:
813 case PREPARED_STATEMENT_QUERY_TIME_OUT
:
814 case PREPARED_STATEMENT_RESULT_SET_CONCURRENCY
:
815 case PREPARED_STATEMENT_RESULT_SET_TYPE
:
818 bRet
= ( rValue
>>= val
);
819 rConvertedValue
= makeAny( val
);
824 OUStringBuffer
buf(128);
825 buf
.appendAscii( "pq_statement: Invalid property handle (" );
826 buf
.append( nHandle
);
827 buf
.appendAscii( ")" );
828 throw IllegalArgumentException( buf
.makeStringAndClear(), *this, 2 );
835 void PreparedStatement::setFastPropertyValue_NoBroadcast(
836 sal_Int32 nHandle
,const Any
& rValue
) throw (Exception
)
838 m_props
[nHandle
] = rValue
;
841 void PreparedStatement::getFastPropertyValue( Any
& rValue
, sal_Int32 nHandle
) const
843 rValue
= m_props
[nHandle
];
846 Reference
< XPropertySetInfo
> PreparedStatement::getPropertySetInfo()
847 throw(RuntimeException
)
849 return OPropertySetHelper::createPropertySetInfo( getPreparedStatementPropertyArrayHelper() );
852 void PreparedStatement::disposing()
858 Reference
< XResultSet
> PreparedStatement::getResultSet( )
859 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
861 return Reference
< XResultSet
> ( m_lastResultset
, com::sun::star::uno::UNO_QUERY
);
863 sal_Int32
PreparedStatement::getUpdateCount( )
864 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
866 return m_multipleResultUpdateCount
;
868 sal_Bool
PreparedStatement::getMoreResults( )
869 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
874 Reference
< XResultSet
> PreparedStatement::getGeneratedValues( )
875 throw (SQLException
, RuntimeException
)
877 osl::MutexGuard
guard( m_refMutex
->mutex
);
878 return getGeneratedValuesFromLastInsert(
879 m_pSettings
, m_connection
, m_lastOidInserted
, m_lastTableInserted
, m_lastQuery
);