Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / postgresql / pq_array.cxx
blob8316a4bd41d736e7814194a4476cb1d013609ece
1 #include <rtl/ustrbuf.hxx>
3 #include <com/sun/star/sdbc/XArray.hpp>
4 #include <com/sun/star/sdbc/DataType.hpp>
7 #include "pq_array.hxx"
8 #include "pq_statics.hxx"
9 #include "pq_sequenceresultset.hxx"
11 using rtl::OUString;
13 using com::sun::star::sdbc::SQLException;
14 using com::sun::star::uno::Any;
16 using com::sun::star::uno::Sequence;
17 namespace pq_sdbc_driver
21 ::rtl::OUString Array::getBaseTypeName( )
22 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
24 return OUString( RTL_CONSTASCII_USTRINGPARAM( "varchar" ) );
27 sal_Int32 Array::getBaseType( )
28 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
30 return com::sun::star::sdbc::DataType::VARCHAR;
33 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > Array::getArray(
34 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap )
35 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
37 return m_data;
40 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > Array::getArrayAtIndex(
41 sal_Int32 index,
42 sal_Int32 count,
43 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap )
44 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
46 checkRange( index, count );
47 return Sequence< Any > ( &m_data[index-1], count );
50 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > Array::getResultSet(
51 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap )
52 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
54 return getResultSetAtIndex( 0 , m_data.getLength() , typeMap );
57 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > Array::getResultSetAtIndex(
58 sal_Int32 index,
59 sal_Int32 count,
60 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap )
61 throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
63 checkRange( index, count );
64 Sequence< Sequence< Any > > ret( count );
66 for( int i = 0 ; i < count ; i ++ )
68 Sequence< Any > row( 2 );
69 row[0] <<= (sal_Int32) ( i + index );
70 row[1] = m_data[i+index-1];
71 ret[i] = row;
74 return new SequenceResultSet(
75 m_refMutex, m_owner, getStatics().resultSetArrayColumnNames, ret, m_tc );
79 void Array::checkRange( sal_Int32 index, sal_Int32 count )
81 if( index >= 1 && index -1 + count <= m_data.getLength() )
82 return;
83 rtl::OUStringBuffer buf;
84 buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "Array::getArrayAtIndex(): allowed range for index + count " ) );
85 buf.append( m_data.getLength() );
86 buf.appendAscii( ", got " );
87 buf.append( index );
88 buf.appendAscii( " + " );
89 buf.append( count );
91 throw SQLException( buf.makeStringAndClear() , *this, rtl::OUString(), 1, Any());