Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / ado / AResultSetMetaData.cxx
blob071172d77ea09f119de8b0a6cd715e9b6bc732b1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AResultSetMetaData.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "ado/AResultSetMetaData.hxx"
34 #include <com/sun/star/sdbc/DataType.hpp>
35 #include <com/sun/star/sdbc/ColumnValue.hpp>
36 #include "ado/Awrapado.hxx"
37 #include "connectivity/dbexception.hxx"
39 using namespace connectivity;
40 using namespace connectivity::ado;
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::lang;
43 using namespace com::sun::star::beans;
44 using namespace com::sun::star::sdbc;
46 OResultSetMetaData::OResultSetMetaData( ADORecordset* _pRecordSet)
47 : m_pRecordSet(_pRecordSet),
48 m_nColCount(-1)
50 if ( m_pRecordSet )
51 m_pRecordSet->AddRef();
53 // -------------------------------------------------------------------------
54 OResultSetMetaData::~OResultSetMetaData()
56 if ( m_pRecordSet )
57 m_pRecordSet->Release();
59 // -------------------------------------------------------------------------
60 sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException)
62 WpADOField aField = ADOS::getField(m_pRecordSet,column);
63 if(aField.IsValid() && aField.GetActualSize() != -1)
64 return aField.GetActualSize();
65 return 0;
67 // -------------------------------------------------------------------------
69 sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException)
71 WpADOField aField = ADOS::getField(m_pRecordSet,column);
72 return ADOS::MapADOType2Jdbc(aField.GetADOType());
74 // -------------------------------------------------------------------------
76 sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException)
78 if(m_nColCount != -1 )
79 return m_nColCount;
81 if ( !m_pRecordSet )
82 return 0;
84 ADOFields* pFields = NULL;
85 m_pRecordSet->get_Fields(&pFields);
86 WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields);
87 m_nColCount = aFields.GetItemCount();
88 return m_nColCount;
90 // -------------------------------------------------------------------------
92 sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException)
94 sal_Bool bRet = sal_False;
95 WpADOField aField = ADOS::getField(m_pRecordSet,column);
96 if ( aField.IsValid() )
98 WpADOProperties aProps( aField.get_Properties() );
99 if ( aProps.IsValid() )
100 bRet = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ISCASESENSITIVE")) );
102 return bRet;
104 // -------------------------------------------------------------------------
106 ::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
108 return ::rtl::OUString();
110 // -------------------------------------------------------------------------
112 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException)
114 WpADOField aField = ADOS::getField(m_pRecordSet,column);
115 if(aField.IsValid())
116 return aField.GetName();
118 return ::rtl::OUString();
120 // -------------------------------------------------------------------------
121 ::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException)
123 ::rtl::OUString sTableName;
125 WpADOField aField = ADOS::getField(m_pRecordSet,column);
126 if ( aField.IsValid() )
128 WpADOProperties aProps( aField.get_Properties() );
129 if ( aProps.IsValid() )
130 sTableName = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BASETABLENAME")) );
132 return sTableName;
134 // -------------------------------------------------------------------------
135 ::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
137 return ::rtl::OUString();
139 // -------------------------------------------------------------------------
140 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
142 return ::rtl::OUString();
144 // -------------------------------------------------------------------------
145 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException)
147 return getColumnName(column);
149 // -------------------------------------------------------------------------
150 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
152 return ::rtl::OUString();
154 // -------------------------------------------------------------------------
156 sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException)
158 WpADOField aField = ADOS::getField(m_pRecordSet,column);
159 if(aField.IsValid())
161 return ((aField.GetAttributes() & adFldFixed) == adFldFixed) && (aField.GetADOType() == adCurrency);
163 return sal_False;
165 // -------------------------------------------------------------------------
167 sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException)
169 sal_Bool bRet = sal_False;
170 WpADOField aField = ADOS::getField(m_pRecordSet,column);
171 if ( aField.IsValid() )
173 WpADOProperties aProps( aField.get_Properties() );
174 if ( aProps.IsValid() )
176 bRet = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ISAUTOINCREMENT")) );
177 #if OSL_DEBUG_LEVEL > 0
178 sal_Int32 nCount = aProps.GetItemCount();
179 for (sal_Int32 i = 0; i<nCount; ++i)
181 WpADOProperty aProp = aProps.GetItem(i);
182 ::rtl::OUString sName = aProp.GetName();
183 ::rtl::OUString sVal = aProp.GetValue();
185 #endif
188 return bRet;
190 // -------------------------------------------------------------------------
193 sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException)
195 WpADOField aField = ADOS::getField(m_pRecordSet,column);
196 if(aField.IsValid())
198 DataTypeEnum eType = aField.GetADOType();
199 return !(eType == adUnsignedBigInt || eType == adUnsignedInt || eType == adUnsignedSmallInt || eType == adUnsignedTinyInt);
201 return sal_False;
203 // -------------------------------------------------------------------------
204 sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException)
206 WpADOField aField = ADOS::getField(m_pRecordSet,column);
207 if(aField.IsValid())
208 return aField.GetPrecision();
209 return 0;
211 // -------------------------------------------------------------------------
212 sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
214 WpADOField aField = ADOS::getField(m_pRecordSet,column);
215 if(aField.IsValid())
216 return aField.GetNumericScale();
217 return 0;
219 // -------------------------------------------------------------------------
221 sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException)
223 WpADOField aField = ADOS::getField(m_pRecordSet,column);
224 if(aField.IsValid())
226 return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable;
228 return sal_False;
230 // -------------------------------------------------------------------------
232 sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
234 return sal_True;
236 // -------------------------------------------------------------------------
238 sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException)
240 WpADOField aField = ADOS::getField(m_pRecordSet,column);
241 if(aField.IsValid())
243 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
245 return sal_False;
247 // -------------------------------------------------------------------------
249 sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
251 WpADOField aField = ADOS::getField(m_pRecordSet,column);
252 if(aField.IsValid())
254 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
256 return sal_False;
259 // -------------------------------------------------------------------------
260 sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
262 return isDefinitelyWritable(column);
264 // -------------------------------------------------------------------------