Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*************************************************************************
3 : *
4 : * Effective License of whole file:
5 : *
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.
9 : *
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.
14 : *
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
19 : *
20 : * Parts "Copyright by Sun Microsystems, Inc" prior to August 2011:
21 : *
22 : * The Contents of this file are made available subject to the terms of
23 : * the GNU Lesser General Public License Version 2.1
24 : *
25 : * Copyright: 2000 by Sun Microsystems, Inc.
26 : *
27 : * Contributor(s): Joerg Budischewski
28 : *
29 : * All parts contributed on or after August 2011:
30 : *
31 : * Version: MPL 1.1 / GPLv3+ / LGPLv2.1+
32 : *
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/
37 : *
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
41 : * License.
42 : *
43 : * Major Contributor(s):
44 : * [ Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu> ]
45 : *
46 : * All Rights Reserved.
47 : *
48 : * For minor contributions see the git repository.
49 : *
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.
55 : *
56 : ************************************************************************/
57 :
58 : #include <rtl/ustrbuf.hxx>
59 :
60 : #include <com/sun/star/sdbc/XArray.hpp>
61 : #include <com/sun/star/sdbc/DataType.hpp>
62 :
63 :
64 : #include "pq_array.hxx"
65 : #include "pq_statics.hxx"
66 : #include "pq_sequenceresultset.hxx"
67 :
68 : using rtl::OUString;
69 :
70 : using com::sun::star::sdbc::SQLException;
71 : using com::sun::star::uno::Any;
72 :
73 : using com::sun::star::uno::Sequence;
74 : namespace pq_sdbc_driver
75 : {
76 :
77 :
78 0 : ::rtl::OUString Array::getBaseTypeName( )
79 : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
80 : {
81 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM( "varchar" ) );
82 : }
83 :
84 0 : sal_Int32 Array::getBaseType( )
85 : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
86 : {
87 0 : return com::sun::star::sdbc::DataType::VARCHAR;
88 : }
89 :
90 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > Array::getArray(
91 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& /* typeMap */ )
92 : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
93 : {
94 0 : return m_data;
95 : }
96 :
97 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > Array::getArrayAtIndex(
98 : sal_Int32 index,
99 : sal_Int32 count,
100 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& /* typeMap */ )
101 : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
102 : {
103 0 : checkRange( index, count );
104 0 : return Sequence< Any > ( &m_data[index-1], count );
105 : }
106 :
107 0 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > Array::getResultSet(
108 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& typeMap )
109 : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
110 : {
111 0 : return getResultSetAtIndex( 0 , m_data.getLength() , typeMap );
112 : }
113 :
114 0 : ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet > Array::getResultSetAtIndex(
115 : sal_Int32 index,
116 : sal_Int32 count,
117 : const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& /* typeMap */ )
118 : throw (::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
119 : {
120 0 : checkRange( index, count );
121 0 : Sequence< Sequence< Any > > ret( count );
122 :
123 0 : for( int i = 0 ; i < count ; i ++ )
124 : {
125 0 : Sequence< Any > row( 2 );
126 0 : row[0] <<= (sal_Int32) ( i + index );
127 0 : row[1] = m_data[i+index-1];
128 0 : ret[i] = row;
129 0 : }
130 :
131 : return new SequenceResultSet(
132 0 : m_refMutex, m_owner, getStatics().resultSetArrayColumnNames, ret, m_tc );
133 : }
134 :
135 :
136 0 : void Array::checkRange( sal_Int32 index, sal_Int32 count )
137 : {
138 0 : if( index >= 1 && index -1 + count <= m_data.getLength() )
139 0 : return;
140 0 : rtl::OUStringBuffer buf;
141 0 : buf.appendAscii( RTL_CONSTASCII_STRINGPARAM( "Array::getArrayAtIndex(): allowed range for index + count " ) );
142 0 : buf.append( m_data.getLength() );
143 0 : buf.appendAscii( ", got " );
144 0 : buf.append( index );
145 0 : buf.appendAscii( " + " );
146 0 : buf.append( count );
147 :
148 0 : throw SQLException( buf.makeStringAndClear() , *this, rtl::OUString(), 1, Any());
149 :
150 : }
151 :
152 : }
|