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 * 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 <rtl/ustrbuf.hxx>
39 #include <com/sun/star/sdbc/XArray.hpp>
40 #include <com/sun/star/sdbc/DataType.hpp>
43 #include "pq_array.hxx"
44 #include "pq_statics.hxx"
45 #include "pq_sequenceresultset.hxx"
48 using com::sun::star::sdbc::SQLException
;
49 using com::sun::star::uno::Any
;
51 using com::sun::star::uno::Sequence
;
52 namespace pq_sdbc_driver
56 OUString
Array::getBaseTypeName( )
57 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
59 return OUString( "varchar" );
62 sal_Int32
Array::getBaseType( )
63 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
65 return com::sun::star::sdbc::DataType::VARCHAR
;
68 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
> Array::getArray(
69 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>& /* typeMap */ )
70 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
75 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
> Array::getArrayAtIndex(
78 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>& /* typeMap */ )
79 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
81 checkRange( index
, count
);
82 return Sequence
< Any
> ( &m_data
[index
-1], count
);
85 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> Array::getResultSet(
86 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>& typeMap
)
87 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
89 return getResultSetAtIndex( 0 , m_data
.getLength() , typeMap
);
92 ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XResultSet
> Array::getResultSetAtIndex(
95 const ::com::sun::star::uno::Reference
< ::com::sun::star::container::XNameAccess
>& /* typeMap */ )
96 throw (::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
98 checkRange( index
, count
);
99 Sequence
< Sequence
< Any
> > ret( count
);
101 for( int i
= 0 ; i
< count
; i
++ )
103 Sequence
< Any
> row( 2 );
104 row
[0] <<= (sal_Int32
) ( i
+ index
);
105 row
[1] = m_data
[i
+index
-1];
109 return new SequenceResultSet(
110 m_refMutex
, m_owner
, getStatics().resultSetArrayColumnNames
, ret
, m_tc
);
114 void Array::checkRange( sal_Int32 index
, sal_Int32 count
)
116 if( index
>= 1 && index
-1 + count
<= m_data
.getLength() )
119 buf
.append( "Array::getArrayAtIndex(): allowed range for index + count " );
120 buf
.append( m_data
.getLength() );
121 buf
.append( ", got " );
126 throw SQLException( buf
.makeStringAndClear() , *this, OUString(), 1, Any());
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */