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,
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 * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
33 * The contents of this file are subject to the Mozilla Public License Version
34 * 1.1 (the "License"); you may not use this file except in compliance with
35 * the License or as specified alternatively below. You may obtain a copy of
36 * the License at http://www.mozilla.org/MPL/
38 * Software distributed under the License is distributed on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
40 * for the specific language governing rights and limitations under the
43 * Major Contributor(s):
44 * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
46 * All Rights Reserved.
48 * For minor contributions see the git repository.
50 * Alternatively, the contents of this file may be used under the terms of
51 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
52 * the GNU Lesser General Public License Version 2.1 or later (the "LGPLv2.1+"),
53 * in which case the provisions of the GPLv3+ or the LGPLv2.1+ are applicable
54 * instead of those above.
56 ************************************************************************/
58 #include "pq_preparedstatement.hxx"
59 #include "pq_resultset.hxx"
60 #include "pq_tools.hxx"
61 #include "pq_statics.hxx"
62 #include "pq_statement.hxx"
64 #include <rtl/strbuf.hxx>
65 #include <rtl/ustrbuf.hxx>
68 #include <cppuhelper/typeprovider.hxx>
69 #include <cppuhelper/queryinterface.hxx>
71 #include <com/sun/star/beans/PropertyAttribute.hpp>
73 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
74 #include <com/sun/star/sdbc/ResultSetType.hpp>
79 using osl::MutexGuard
;
82 using rtl::OUStringToOString
;
83 using rtl::OStringToOUString
;
84 using rtl::OUStringBuffer
;
85 using rtl::OStringBuffer
;
88 using com::sun::star::uno::Any
;
89 using com::sun::star::uno::makeAny
;
90 using com::sun::star::uno::Type
;
91 using com::sun::star::uno::RuntimeException
;
92 using com::sun::star::uno::Exception
;
93 using com::sun::star::uno::Sequence
;
94 using com::sun::star::uno::Reference
;
95 using com::sun::star::uno::XInterface
;
96 using com::sun::star::uno::UNO_QUERY
;
98 using com::sun::star::lang::IllegalArgumentException
;
100 using com::sun::star::sdbc::XWarningsSupplier
;
101 using com::sun::star::sdbc::XCloseable
;
102 using com::sun::star::sdbc::XPreparedStatement
;
103 using com::sun::star::sdbc::XParameters
;
104 using com::sun::star::sdbc::XResultSet
;
105 using com::sun::star::sdbc::XRef
;
106 using com::sun::star::sdbc::XBlob
;
107 using com::sun::star::sdbc::XClob
;
108 using com::sun::star::sdbc::XArray
;
109 using com::sun::star::sdbc::XConnection
;
110 using com::sun::star::sdbc::XGeneratedResultSet
;
111 using com::sun::star::sdbc::SQLException
;
113 using com::sun::star::beans::Property
;
114 using com::sun::star::beans::XPropertySetInfo
;
115 using com::sun::star::beans::XPropertySet
;
116 using com::sun::star::beans::XMultiPropertySet
;
117 using com::sun::star::beans::XFastPropertySet
;
119 #define ASCII_STR(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
120 namespace pq_sdbc_driver
122 static ::cppu::IPropertyArrayHelper
& getPreparedStatementPropertyArrayHelper()
124 static ::cppu::IPropertyArrayHelper
*pArrayHelper
;
127 MutexGuard
guard( Mutex::getGlobalMutex() );
130 static Property aTable
[] =
133 OUString( RTL_CONSTASCII_USTRINGPARAM("CursorName") ), 0,
134 ::getCppuType( (OUString
*)0) , 0 ),
136 OUString( RTL_CONSTASCII_USTRINGPARAM("EscapeProcessing") ), 1,
137 ::getBooleanCppuType() , 0 ),
139 OUString( RTL_CONSTASCII_USTRINGPARAM("FetchDirection") ), 2,
140 ::getCppuType( (sal_Int32
*)0) , 0 ),
142 OUString( RTL_CONSTASCII_USTRINGPARAM("FetchSize") ), 3,
143 ::getCppuType( (sal_Int32
*)0) , 0 ),
145 OUString( RTL_CONSTASCII_USTRINGPARAM("MaxFieldSize") ), 4,
146 ::getCppuType( (sal_Int32
*)0) , 0 ),
148 OUString( RTL_CONSTASCII_USTRINGPARAM("MaxRows") ), 5,
149 ::getCppuType( (sal_Int32
*)0) , 0 ),
151 OUString( RTL_CONSTASCII_USTRINGPARAM("QueryTimeOut") ), 6,
152 ::getCppuType( (sal_Int32
*)0) , 0 ),
154 OUString( RTL_CONSTASCII_USTRINGPARAM("ResultSetConcurrency") ), 7,
155 ::getCppuType( (sal_Int32
*)0) , 0 ),
157 OUString( RTL_CONSTASCII_USTRINGPARAM("ResultSetType") ), 8,
158 ::getCppuType( (sal_Int32
*)0) , 0 )
160 OSL_ASSERT( sizeof(aTable
)/ sizeof(Property
) == PREPARED_STATEMENT_SIZE
);
161 static ::cppu::OPropertyArrayHelper
arrayHelper( aTable
, PREPARED_STATEMENT_SIZE
, sal_True
);
162 pArrayHelper
= &arrayHelper
;
165 return *pArrayHelper
;
168 static bool isOperator( char c
)
170 static const char * operators
= "<>=()!/&%.,;";
172 const char * w
= operators
;
173 for( ; *w
&& *w
!= c
; w
++);
177 static bool isNamedParameterStart( const rtl::OString
& o
, int index
)
179 return o
[index
] == ':' && (
180 isWhitespace( o
[index
-1] ) || isOperator(o
[index
-1]) );
183 static bool isQuoted( const rtl::OString
& str
)
185 return str
[0] == '"' || str
[0] == '\'';
188 PreparedStatement::PreparedStatement(
189 const ::rtl::Reference
< RefCountedMutex
> & refMutex
,
190 const Reference
< XConnection
> & conn
,
191 struct ConnectionSettings
*pSettings
,
192 const ::rtl::OString
& stmt
)
193 : OComponentHelper( refMutex
->mutex
),
194 OPropertySetHelper( OComponentHelper::rBHelper
),
195 m_connection( conn
),
196 m_pSettings( pSettings
),
198 m_refMutex( refMutex
),
199 m_lastOidInserted( InvalidOid
)
201 m_props
[PREPARED_STATEMENT_QUERY_TIME_OUT
] = makeAny( (sal_Int32
)0 );
202 m_props
[PREPARED_STATEMENT_MAX_ROWS
] = makeAny( (sal_Int32
)0 );
203 m_props
[PREPARED_STATEMENT_RESULT_SET_CONCURRENCY
] = makeAny(
204 com::sun::star::sdbc::ResultSetConcurrency::READ_ONLY
);
205 m_props
[PREPARED_STATEMENT_RESULT_SET_TYPE
] = makeAny(
206 com::sun::star::sdbc::ResultSetType::SCROLL_INSENSITIVE
);
208 splitSQL( m_stmt
, m_splittedStatement
);
210 for( int i
= 0, max
= m_splittedStatement
.size(); i
< max
; i
++ )
212 const OString
&str
= m_splittedStatement
[i
];
213 // ignore quoted strings ....
214 if( ! isQuoted( str
) )
216 // the ':' cannot be the first or the last part of the
218 // the ? cannot be the first part of the token , so we start
220 for( int index
= 1 ; index
< str
.getLength() ; index
++ )
222 if( str
[index
] == '?' ||
223 isNamedParameterStart( str
, index
)
231 m_vars
= OStringVector ( elements
);
234 PreparedStatement::~PreparedStatement()
236 POSTGRE_TRACE( "dtor PreparedStatement" );
239 void PreparedStatement::checkColumnIndex( sal_Int32 parameterIndex
)
241 if( parameterIndex
< 1 || parameterIndex
> (sal_Int32
) m_vars
.size() )
243 OUStringBuffer
buf( 128 );
244 buf
.appendAscii( "pq_preparedstatement: parameter index out of range (expected 1 to " );
245 buf
.append( (sal_Int32
) m_vars
.size() );
246 buf
.appendAscii( ", got " );
247 buf
.append( parameterIndex
);
248 buf
.appendAscii( ", statement '" );
249 buf
.append( OStringToOUString( m_stmt
, m_pSettings
->encoding
) );
250 buf
.appendAscii( "')" );
251 throw SQLException( buf
.makeStringAndClear(), *this, OUString(), 1, Any () );
254 void PreparedStatement::checkClosed() throw (SQLException
, RuntimeException
)
256 if( ! m_pSettings
|| ! m_pSettings
->pConnection
)
258 ASCII_STR("pq_driver: PreparedStatement or connection has already been closed !" ),
259 *this, OUString(),1,Any());
262 Any
PreparedStatement::queryInterface( const Type
& reqType
) throw (RuntimeException
)
266 ret
= OComponentHelper::queryInterface( reqType
);
267 if( ! ret
.hasValue() )
268 ret
= ::cppu::queryInterface( reqType
,
269 static_cast< XWarningsSupplier
* > ( this ),
270 static_cast< XPreparedStatement
* > ( this ),
271 static_cast< com::sun::star::sdbc::XResultSetMetaDataSupplier
* > ( this ),
272 static_cast< XParameters
* > ( this ),
273 static_cast< XCloseable
* > ( this ),
274 static_cast< XGeneratedResultSet
* > ( this ),
275 static_cast< XPropertySet
* > ( this ),
276 static_cast< XMultiPropertySet
* > ( this ),
277 static_cast< XFastPropertySet
* > ( this ) );
282 Sequence
< Type
> PreparedStatement::getTypes() throw ( RuntimeException
)
284 static cppu::OTypeCollection
*pCollection
;
287 MutexGuard
guard( osl::Mutex::getGlobalMutex() );
290 static cppu::OTypeCollection
collection(
291 getCppuType( (Reference
< XWarningsSupplier
> *) 0 ),
292 getCppuType( (Reference
< XPreparedStatement
> *) 0 ),
293 getCppuType( (Reference
< com::sun::star::sdbc::XResultSetMetaDataSupplier
> *) 0 ),
294 getCppuType( (Reference
< XParameters
> *) 0 ),
295 getCppuType( (Reference
< XCloseable
> *) 0 ),
296 getCppuType( (Reference
< XGeneratedResultSet
> *) 0 ),
297 getCppuType( (Reference
< XPropertySet
>*) 0 ),
298 getCppuType( (Reference
< XFastPropertySet
> *) 0 ),
299 getCppuType( (Reference
< XMultiPropertySet
> *) 0 ),
300 OComponentHelper::getTypes());
301 pCollection
= &collection
;
304 return pCollection
->getTypes();
307 Sequence
< sal_Int8
> PreparedStatement::getImplementationId() throw ( RuntimeException
)
309 static cppu::OImplementationId
*pId
;
312 MutexGuard
guard( osl::Mutex::getGlobalMutex() );
315 static cppu::OImplementationId
id(sal_False
);
319 return pId
->getImplementationId();
322 void PreparedStatement::close( ) throw (SQLException
, RuntimeException
)
324 // let the connection die without acquired mutex !
325 Reference
< XConnection
> r
;
326 Reference
< XCloseable
> resultSet
;
328 MutexGuard
guard( m_refMutex
->mutex
);
331 m_connection
.clear();
333 resultSet
= m_lastResultset
;
334 m_lastResultset
.clear();
342 void PreparedStatement::raiseSQLException(
343 const char * errorMsg
, const char *errorType
)
344 throw( SQLException
)
346 OUStringBuffer
buf(128);
347 buf
.appendAscii( "pq_driver: ");
350 buf
.appendAscii( "[" );
351 buf
.appendAscii( errorType
);
352 buf
.appendAscii( "]" );
355 rtl::OUString( errorMsg
, strlen(errorMsg
) , m_pSettings
->encoding
) );
356 buf
.appendAscii( " (caused by statement '" );
357 buf
.appendAscii( m_executedStatement
.getStr() );
358 buf
.appendAscii( "')" );
359 OUString error
= buf
.makeStringAndClear();
360 log( m_pSettings
, LogLevel::ERROR
, error
);
361 throw SQLException( buf
.makeStringAndClear(), *this, OUString(), 1, Any() );
364 Reference
< XResultSet
> PreparedStatement::executeQuery( )
365 throw (SQLException
, RuntimeException
)
367 Reference
< XCloseable
> lastResultSet
= m_lastResultset
;
368 if( lastResultSet
.is() )
369 lastResultSet
->close();
373 raiseSQLException( "not a query" );
375 return Reference
< XResultSet
> ( m_lastResultset
, com::sun::star::uno::UNO_QUERY
);
378 sal_Int32
PreparedStatement::executeUpdate( )
379 throw (SQLException
, RuntimeException
)
383 raiseSQLException( "not a command" );
385 return m_multipleResultUpdateCount
;
388 sal_Bool
PreparedStatement::execute( )
389 throw (SQLException
, RuntimeException
)
391 osl::MutexGuard
guard( m_refMutex
->mutex
);
393 OStringBuffer
buf( m_stmt
.getLength() *2 );
395 OStringVector::size_type vars
= 0;
396 for( OStringVector::size_type i
= 0 ; i
< m_splittedStatement
.size() ; ++i
)
398 // LEM TODO: instead of this manual mucking with SQL
399 // could we use PQexecParams / PQExecPrepared / ...?
400 // Only snafu is giving the types of the parameters and
401 // that it needs $1, $2, etc instead of "?"
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
)
480 MutexGuard
guard( m_refMutex
->mutex
);
482 checkColumnIndex( parameterIndex
);
483 m_vars
[parameterIndex
-1] = OString( "NULL" );
486 void PreparedStatement::setObjectNull(
487 sal_Int32 parameterIndex
, sal_Int32 sqlType
, const ::rtl::OUString
& typeName
)
488 throw (SQLException
, RuntimeException
)
490 (void) sqlType
; (void) typeName
;
491 MutexGuard
guard( m_refMutex
->mutex
);
493 checkColumnIndex( parameterIndex
);
494 m_vars
[parameterIndex
-1] = OString( "NULL" );
498 void PreparedStatement::setBoolean( sal_Int32 parameterIndex
, sal_Bool x
)
499 throw (SQLException
, RuntimeException
)
501 MutexGuard
guard(m_refMutex
->mutex
);
503 checkColumnIndex( parameterIndex
);
505 m_vars
[parameterIndex
-1] = OString( "'t'" );
507 m_vars
[parameterIndex
-1] = OString( "'f'" );
510 void PreparedStatement::setByte( sal_Int32 parameterIndex
, sal_Int8 x
)
511 throw (SQLException
, RuntimeException
)
513 setInt(parameterIndex
,x
);
516 void PreparedStatement::setShort( sal_Int32 parameterIndex
, sal_Int16 x
)
517 throw (SQLException
, RuntimeException
)
519 setInt(parameterIndex
, x
);
522 void PreparedStatement::setInt( sal_Int32 parameterIndex
, sal_Int32 x
)
523 throw (SQLException
, RuntimeException
)
525 // printf( "setString %d %d\n ", parameterIndex, x);
526 MutexGuard
guard(m_refMutex
->mutex
);
528 checkColumnIndex( parameterIndex
);
529 OStringBuffer
buf( 20 );
531 buf
.append( (sal_Int32
) x
);
533 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
536 void PreparedStatement::setLong( sal_Int32 parameterIndex
, sal_Int64 x
)
537 throw (SQLException
, RuntimeException
)
539 MutexGuard
guard(m_refMutex
->mutex
);
541 checkColumnIndex( parameterIndex
);
542 OStringBuffer
buf( 20 );
544 buf
.append( (sal_Int64
) x
);
546 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
549 void PreparedStatement::setFloat( sal_Int32 parameterIndex
, float x
)
550 throw (SQLException
, RuntimeException
)
552 MutexGuard
guard(m_refMutex
->mutex
);
554 checkColumnIndex( parameterIndex
);
555 OStringBuffer
buf( 20 );
559 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
562 void PreparedStatement::setDouble( sal_Int32 parameterIndex
, double x
)
563 throw (SQLException
, RuntimeException
)
565 MutexGuard
guard(m_refMutex
->mutex
);
567 checkColumnIndex( parameterIndex
);
568 OStringBuffer
buf( 20 );
572 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
575 void PreparedStatement::setString( sal_Int32 parameterIndex
, const ::rtl::OUString
& x
)
576 throw (SQLException
, RuntimeException
)
578 // printf( "setString %d %s\n ", parameterIndex,
579 // OUStringToOString( x , RTL_TEXTENCODING_ASCII_US ).getStr());
580 MutexGuard
guard(m_refMutex
->mutex
);
582 checkColumnIndex( parameterIndex
);
583 OStringBuffer
buf( 20 );
585 OString y
= OUStringToOString( x
, m_pSettings
->encoding
);
586 buf
.ensureCapacity( y
.getLength() * 2 + 2 );
587 int len
= PQescapeString( ((char*)buf
.getStr())+1, y
.getStr() , y
.getLength() );
588 buf
.setLength( 1 + len
);
590 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
593 void PreparedStatement::setBytes(
594 sal_Int32 parameterIndex
, const Sequence
< sal_Int8
>& x
)
595 throw (SQLException
, RuntimeException
)
597 MutexGuard
guard(m_refMutex
->mutex
);
599 checkColumnIndex( parameterIndex
);
600 OStringBuffer
buf( 20 );
603 unsigned char * escapedString
=
604 PQescapeBytea( (unsigned char *)x
.getConstArray(), x
.getLength(), &len
);
605 if( ! escapedString
)
608 ASCII_STR("pq_preparedstatement.setBytes: Error during converting bytesequence to an SQL conform string" ),
609 *this, OUString(), 1, Any() );
611 buf
.append( (const sal_Char
*)escapedString
, len
-1 );
612 free( escapedString
);
614 m_vars
[parameterIndex
-1] = buf
.makeStringAndClear();
618 void PreparedStatement::setDate( sal_Int32 parameterIndex
, const ::com::sun::star::util::Date
& x
)
619 throw (SQLException
, RuntimeException
)
621 setString( parameterIndex
, date2String( x
) );
624 void PreparedStatement::setTime( sal_Int32 parameterIndex
, const ::com::sun::star::util::Time
& x
)
625 throw (SQLException
, RuntimeException
)
627 setString( parameterIndex
, time2String( x
) );
630 void PreparedStatement::setTimestamp(
631 sal_Int32 parameterIndex
, const ::com::sun::star::util::DateTime
& x
)
632 throw (SQLException
, RuntimeException
)
634 setString( parameterIndex
, dateTime2String( x
) );
637 void PreparedStatement::setBinaryStream(
638 sal_Int32 parameterIndex
,
639 const Reference
< ::com::sun::star::io::XInputStream
>& x
,
641 throw (SQLException
, RuntimeException
)
643 (void) parameterIndex
; (void)x
; (void) length
;
645 ASCII_STR( "pq_preparedstatement: setBinaryStream not implemented" ),
646 *this, OUString(), 1, Any () );
649 void PreparedStatement::setCharacterStream(
650 sal_Int32 parameterIndex
,
651 const Reference
< ::com::sun::star::io::XInputStream
>& x
,
653 throw (SQLException
, RuntimeException
)
655 (void) parameterIndex
; (void)x
; (void) length
;
657 ASCII_STR( "pq_preparedstatement: setCharacterStream not implemented" ),
658 *this, OUString(), 1, Any () );
661 void PreparedStatement::setObject( sal_Int32 parameterIndex
, const Any
& x
)
662 throw (SQLException
, RuntimeException
)
664 if( ! implSetObject( this, parameterIndex
, x
))
667 buf
.append( ASCII_STR("pq_preparedstatement::setObject: can't convert value of type " ) );
668 buf
.append( x
.getValueTypeName() );
669 throw SQLException( buf
.makeStringAndClear(), *this, OUString(), 1, Any () );
673 void PreparedStatement::setObjectWithInfo(
674 sal_Int32 parameterIndex
,
676 sal_Int32 targetSqlType
,
678 throw (SQLException
, RuntimeException
)
681 if( com::sun::star::sdbc::DataType::DECIMAL
== targetSqlType
||
682 com::sun::star::sdbc::DataType::NUMERIC
== targetSqlType
)
684 double myDouble
= 0.0;
688 myString
= OUString::valueOf( myDouble
);
694 if( myString
.getLength() )
696 // printf( "setObjectWithInfo %s\n", OUStringToOString(myString,RTL_TEXTENCODING_ASCII_US).getStr());
697 setString( parameterIndex
, myString
);
702 buf
.append( ASCII_STR("pq_preparedstatement::setObjectWithInfo: can't convert value of type " ) );
703 buf
.append( x
.getValueTypeName() );
704 buf
.append( ASCII_STR(" to type DECIMAL or NUMERIC" ) );
705 throw SQLException( buf
.makeStringAndClear(), *this, OUString(), 1, Any () );
710 setObject( parameterIndex
, x
);
715 void PreparedStatement::setRef(
716 sal_Int32 parameterIndex
,
717 const Reference
< XRef
>& x
)
718 throw (SQLException
, RuntimeException
)
720 (void) parameterIndex
; (void)x
;
722 ASCII_STR( "pq_preparedstatement: setRef not implemented" ),
723 *this, OUString(), 1, Any () );
726 void PreparedStatement::setBlob(
727 sal_Int32 parameterIndex
,
728 const Reference
< XBlob
>& x
)
729 throw (SQLException
, RuntimeException
)
731 (void) parameterIndex
; (void)x
;
733 ASCII_STR( "pq_preparedstatement: setBlob not implemented" ),
734 *this, OUString(), 1, Any () );
737 void PreparedStatement::setClob(
738 sal_Int32 parameterIndex
,
739 const Reference
< XClob
>& x
)
740 throw (SQLException
, RuntimeException
)
742 (void) parameterIndex
; (void)x
;
744 ASCII_STR( "pq_preparedstatement: setClob not implemented" ),
745 *this, OUString(), 1, Any () );
748 void PreparedStatement::setArray(
749 sal_Int32 parameterIndex
,
750 const Reference
< XArray
>& x
)
751 throw (SQLException
, RuntimeException
)
753 setString( parameterIndex
, array2String( x
->getArray( 0 ) ) );
756 void PreparedStatement::clearParameters( )
757 throw (SQLException
, RuntimeException
)
759 MutexGuard
guard(m_refMutex
->mutex
);
760 m_vars
= OStringVector ( m_vars
.size() );
763 Any
PreparedStatement::getWarnings( )
764 throw (SQLException
,RuntimeException
)
769 void PreparedStatement::clearWarnings( )
770 throw (SQLException
, RuntimeException
)
774 Reference
< ::com::sun::star::sdbc::XResultSetMetaData
> PreparedStatement::getMetaData()
775 throw (SQLException
,RuntimeException
)
777 Reference
< com::sun::star::sdbc::XResultSetMetaData
> ret
;
778 Reference
< com::sun::star::sdbc::XResultSetMetaDataSupplier
> supplier( m_lastResultset
, UNO_QUERY
);
780 ret
= supplier
->getMetaData();
784 ::cppu::IPropertyArrayHelper
& PreparedStatement::getInfoHelper()
786 return getPreparedStatementPropertyArrayHelper();
790 sal_Bool
PreparedStatement::convertFastPropertyValue(
791 Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nHandle
, const Any
& rValue
)
792 throw (IllegalArgumentException
)
795 rOldValue
= m_props
[nHandle
];
798 case PREPARED_STATEMENT_CURSOR_NAME
:
801 bRet
= ( rValue
>>= val
);
802 rConvertedValue
= makeAny( val
);
805 case PREPARED_STATEMENT_ESCAPE_PROCESSING
:
808 bRet
= ( rValue
>>= val
);
809 rConvertedValue
= makeAny( val
);
812 case PREPARED_STATEMENT_FETCH_DIRECTION
:
813 case PREPARED_STATEMENT_FETCH_SIZE
:
814 case PREPARED_STATEMENT_MAX_FIELD_SIZE
:
815 case PREPARED_STATEMENT_MAX_ROWS
:
816 case PREPARED_STATEMENT_QUERY_TIME_OUT
:
817 case PREPARED_STATEMENT_RESULT_SET_CONCURRENCY
:
818 case PREPARED_STATEMENT_RESULT_SET_TYPE
:
821 bRet
= ( rValue
>>= val
);
822 rConvertedValue
= makeAny( val
);
827 OUStringBuffer
buf(128);
828 buf
.appendAscii( "pq_statement: Invalid property handle (" );
829 buf
.append( nHandle
);
830 buf
.appendAscii( ")" );
831 throw IllegalArgumentException( buf
.makeStringAndClear(), *this, 2 );
838 void PreparedStatement::setFastPropertyValue_NoBroadcast(
839 sal_Int32 nHandle
,const Any
& rValue
) throw (Exception
)
841 m_props
[nHandle
] = rValue
;
844 void PreparedStatement::getFastPropertyValue( Any
& rValue
, sal_Int32 nHandle
) const
846 rValue
= m_props
[nHandle
];
849 Reference
< XPropertySetInfo
> PreparedStatement::getPropertySetInfo()
850 throw(RuntimeException
)
852 return OPropertySetHelper::createPropertySetInfo( getPreparedStatementPropertyArrayHelper() );
855 void PreparedStatement::disposing()
861 Reference
< XResultSet
> PreparedStatement::getResultSet( )
862 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
864 return Reference
< XResultSet
> ( m_lastResultset
, com::sun::star::uno::UNO_QUERY
);
866 sal_Int32
PreparedStatement::getUpdateCount( )
867 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
869 return m_multipleResultUpdateCount
;
871 sal_Bool
PreparedStatement::getMoreResults( )
872 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
877 Reference
< XResultSet
> PreparedStatement::getGeneratedValues( )
878 throw (SQLException
, RuntimeException
)
880 osl::MutexGuard
guard( m_refMutex
->mutex
);
881 return getGeneratedValuesFromLastInsert(
882 m_pSettings
, m_connection
, m_lastOidInserted
, m_lastTableInserted
, m_lastQuery
);