1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10*9b5730f6SAndrew Rist *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19*9b5730f6SAndrew Rist *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "ado/AResultSetMetaData.hxx"
27cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
28cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
29cdf0e10cSrcweir #include "ado/Awrapado.hxx"
30cdf0e10cSrcweir #include "connectivity/dbexception.hxx"
31cdf0e10cSrcweir
32cdf0e10cSrcweir using namespace connectivity;
33cdf0e10cSrcweir using namespace connectivity::ado;
34cdf0e10cSrcweir using namespace com::sun::star::uno;
35cdf0e10cSrcweir using namespace com::sun::star::lang;
36cdf0e10cSrcweir using namespace com::sun::star::beans;
37cdf0e10cSrcweir using namespace com::sun::star::sdbc;
38cdf0e10cSrcweir
OResultSetMetaData(ADORecordset * _pRecordSet)39cdf0e10cSrcweir OResultSetMetaData::OResultSetMetaData( ADORecordset* _pRecordSet)
40cdf0e10cSrcweir : m_pRecordSet(_pRecordSet),
41cdf0e10cSrcweir m_nColCount(-1)
42cdf0e10cSrcweir {
43cdf0e10cSrcweir if ( m_pRecordSet )
44cdf0e10cSrcweir m_pRecordSet->AddRef();
45cdf0e10cSrcweir }
46cdf0e10cSrcweir // -------------------------------------------------------------------------
~OResultSetMetaData()47cdf0e10cSrcweir OResultSetMetaData::~OResultSetMetaData()
48cdf0e10cSrcweir {
49cdf0e10cSrcweir if ( m_pRecordSet )
50cdf0e10cSrcweir m_pRecordSet->Release();
51cdf0e10cSrcweir }
52cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnDisplaySize(sal_Int32 column)53cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
56cdf0e10cSrcweir if(aField.IsValid() && aField.GetActualSize() != -1)
57cdf0e10cSrcweir return aField.GetActualSize();
58cdf0e10cSrcweir return 0;
59cdf0e10cSrcweir }
60cdf0e10cSrcweir // -------------------------------------------------------------------------
61cdf0e10cSrcweir
getColumnType(sal_Int32 column)62cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
65cdf0e10cSrcweir return ADOS::MapADOType2Jdbc(aField.GetADOType());
66cdf0e10cSrcweir }
67cdf0e10cSrcweir // -------------------------------------------------------------------------
68cdf0e10cSrcweir
getColumnCount()69cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir if(m_nColCount != -1 )
72cdf0e10cSrcweir return m_nColCount;
73cdf0e10cSrcweir
74cdf0e10cSrcweir if ( !m_pRecordSet )
75cdf0e10cSrcweir return 0;
76cdf0e10cSrcweir
77cdf0e10cSrcweir ADOFields* pFields = NULL;
78cdf0e10cSrcweir m_pRecordSet->get_Fields(&pFields);
79cdf0e10cSrcweir WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields);
80cdf0e10cSrcweir m_nColCount = aFields.GetItemCount();
81cdf0e10cSrcweir return m_nColCount;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir // -------------------------------------------------------------------------
84cdf0e10cSrcweir
isCaseSensitive(sal_Int32 column)85cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir sal_Bool bRet = sal_False;
88cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
89cdf0e10cSrcweir if ( aField.IsValid() )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir WpADOProperties aProps( aField.get_Properties() );
92cdf0e10cSrcweir if ( aProps.IsValid() )
93cdf0e10cSrcweir bRet = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ISCASESENSITIVE")) );
94cdf0e10cSrcweir }
95cdf0e10cSrcweir return bRet;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir // -------------------------------------------------------------------------
98cdf0e10cSrcweir
getSchemaName(sal_Int32)99cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir return ::rtl::OUString();
102cdf0e10cSrcweir }
103cdf0e10cSrcweir // -------------------------------------------------------------------------
104cdf0e10cSrcweir
getColumnName(sal_Int32 column)105cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
108cdf0e10cSrcweir if(aField.IsValid())
109cdf0e10cSrcweir return aField.GetName();
110cdf0e10cSrcweir
111cdf0e10cSrcweir return ::rtl::OUString();
112cdf0e10cSrcweir }
113cdf0e10cSrcweir // -------------------------------------------------------------------------
getTableName(sal_Int32 column)114cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir ::rtl::OUString sTableName;
117cdf0e10cSrcweir
118cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
119cdf0e10cSrcweir if ( aField.IsValid() )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir WpADOProperties aProps( aField.get_Properties() );
122cdf0e10cSrcweir if ( aProps.IsValid() )
123cdf0e10cSrcweir sTableName = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BASETABLENAME")) );
124cdf0e10cSrcweir }
125cdf0e10cSrcweir return sTableName;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir // -------------------------------------------------------------------------
getCatalogName(sal_Int32)128cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir return ::rtl::OUString();
131cdf0e10cSrcweir }
132cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnTypeName(sal_Int32)133cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
134cdf0e10cSrcweir {
135cdf0e10cSrcweir return ::rtl::OUString();
136cdf0e10cSrcweir }
137cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnLabel(sal_Int32 column)138cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir return getColumnName(column);
141cdf0e10cSrcweir }
142cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnServiceName(sal_Int32)143cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir return ::rtl::OUString();
146cdf0e10cSrcweir }
147cdf0e10cSrcweir // -------------------------------------------------------------------------
148cdf0e10cSrcweir
isCurrency(sal_Int32 column)149cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
152cdf0e10cSrcweir if(aField.IsValid())
153cdf0e10cSrcweir {
154cdf0e10cSrcweir return ((aField.GetAttributes() & adFldFixed) == adFldFixed) && (aField.GetADOType() == adCurrency);
155cdf0e10cSrcweir }
156cdf0e10cSrcweir return sal_False;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir // -------------------------------------------------------------------------
159cdf0e10cSrcweir
isAutoIncrement(sal_Int32 column)160cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir sal_Bool bRet = sal_False;
163cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
164cdf0e10cSrcweir if ( aField.IsValid() )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir WpADOProperties aProps( aField.get_Properties() );
167cdf0e10cSrcweir if ( aProps.IsValid() )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir bRet = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ISAUTOINCREMENT")) );
170cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
171cdf0e10cSrcweir sal_Int32 nCount = aProps.GetItemCount();
172cdf0e10cSrcweir for (sal_Int32 i = 0; i<nCount; ++i)
173cdf0e10cSrcweir {
174cdf0e10cSrcweir WpADOProperty aProp = aProps.GetItem(i);
175cdf0e10cSrcweir ::rtl::OUString sName = aProp.GetName();
176cdf0e10cSrcweir ::rtl::OUString sVal = aProp.GetValue();
177cdf0e10cSrcweir }
178cdf0e10cSrcweir #endif
179cdf0e10cSrcweir }
180cdf0e10cSrcweir }
181cdf0e10cSrcweir return bRet;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir // -------------------------------------------------------------------------
184cdf0e10cSrcweir
185cdf0e10cSrcweir
isSigned(sal_Int32 column)186cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
189cdf0e10cSrcweir if(aField.IsValid())
190cdf0e10cSrcweir {
191cdf0e10cSrcweir DataTypeEnum eType = aField.GetADOType();
192cdf0e10cSrcweir return !(eType == adUnsignedBigInt || eType == adUnsignedInt || eType == adUnsignedSmallInt || eType == adUnsignedTinyInt);
193cdf0e10cSrcweir }
194cdf0e10cSrcweir return sal_False;
195cdf0e10cSrcweir }
196cdf0e10cSrcweir // -------------------------------------------------------------------------
getPrecision(sal_Int32 column)197cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
200cdf0e10cSrcweir if(aField.IsValid())
201cdf0e10cSrcweir return aField.GetPrecision();
202cdf0e10cSrcweir return 0;
203cdf0e10cSrcweir }
204cdf0e10cSrcweir // -------------------------------------------------------------------------
getScale(sal_Int32 column)205cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
206cdf0e10cSrcweir {
207cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
208cdf0e10cSrcweir if(aField.IsValid())
209cdf0e10cSrcweir return aField.GetNumericScale();
210cdf0e10cSrcweir return 0;
211cdf0e10cSrcweir }
212cdf0e10cSrcweir // -------------------------------------------------------------------------
213cdf0e10cSrcweir
isNullable(sal_Int32 column)214cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException)
215cdf0e10cSrcweir {
216cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
217cdf0e10cSrcweir if(aField.IsValid())
218cdf0e10cSrcweir {
219cdf0e10cSrcweir return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir return sal_False;
222cdf0e10cSrcweir }
223cdf0e10cSrcweir // -------------------------------------------------------------------------
224cdf0e10cSrcweir
isSearchable(sal_Int32)225cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
226cdf0e10cSrcweir {
227cdf0e10cSrcweir return sal_True;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir // -------------------------------------------------------------------------
230cdf0e10cSrcweir
isReadOnly(sal_Int32 column)231cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException)
232cdf0e10cSrcweir {
233cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
234cdf0e10cSrcweir if(aField.IsValid())
235cdf0e10cSrcweir {
236cdf0e10cSrcweir // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir return sal_False;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir // -------------------------------------------------------------------------
241cdf0e10cSrcweir
isDefinitelyWritable(sal_Int32 column)242cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
243cdf0e10cSrcweir {
244cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,column);
245cdf0e10cSrcweir if(aField.IsValid())
246cdf0e10cSrcweir {
247cdf0e10cSrcweir return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir return sal_False;
250cdf0e10cSrcweir ;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir // -------------------------------------------------------------------------
isWritable(sal_Int32 column)253cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
254cdf0e10cSrcweir {
255cdf0e10cSrcweir return isDefinitelyWritable(column);
256cdf0e10cSrcweir }
257cdf0e10cSrcweir // -------------------------------------------------------------------------
258cdf0e10cSrcweir
259