Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / ado / AResultSetMetaData.cxx
blob9c4912350f1149c5dcbb8d436cd83a1cc99b0d86
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ado/AResultSetMetaData.hxx"
21 #include <com/sun/star/sdbc/DataType.hpp>
22 #include <com/sun/star/sdbc/ColumnValue.hpp>
23 #include "ado/Awrapado.hxx"
24 #include "connectivity/dbexception.hxx"
26 using namespace connectivity;
27 using namespace connectivity::ado;
28 using namespace com::sun::star::uno;
29 using namespace com::sun::star::lang;
30 using namespace com::sun::star::beans;
31 using namespace com::sun::star::sdbc;
33 OResultSetMetaData::OResultSetMetaData( ADORecordset* _pRecordSet)
34 : m_pRecordSet(_pRecordSet),
35 m_nColCount(-1)
37 if ( m_pRecordSet )
38 m_pRecordSet->AddRef();
41 OResultSetMetaData::~OResultSetMetaData()
43 if ( m_pRecordSet )
44 m_pRecordSet->Release();
47 sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException)
49 WpADOField aField = ADOS::getField(m_pRecordSet,column);
50 if(aField.IsValid() && aField.GetActualSize() != -1)
51 return aField.GetActualSize();
52 return 0;
56 sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException)
58 WpADOField aField = ADOS::getField(m_pRecordSet,column);
59 return ADOS::MapADOType2Jdbc(aField.GetADOType());
63 sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException)
65 if(m_nColCount != -1 )
66 return m_nColCount;
68 if ( !m_pRecordSet )
69 return 0;
71 ADOFields* pFields = NULL;
72 m_pRecordSet->get_Fields(&pFields);
73 WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields);
74 m_nColCount = aFields.GetItemCount();
75 return m_nColCount;
79 sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException)
81 sal_Bool bRet = sal_False;
82 WpADOField aField = ADOS::getField(m_pRecordSet,column);
83 if ( aField.IsValid() )
85 WpADOProperties aProps( aField.get_Properties() );
86 if ( aProps.IsValid() )
87 bRet = OTools::getValue( aProps, OUString("ISCASESENSITIVE") );
89 return bRet;
93 OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
95 return OUString();
99 OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException)
101 WpADOField aField = ADOS::getField(m_pRecordSet,column);
102 if(aField.IsValid())
103 return aField.GetName();
105 return OUString();
108 OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException)
110 OUString sTableName;
112 WpADOField aField = ADOS::getField(m_pRecordSet,column);
113 if ( aField.IsValid() )
115 WpADOProperties aProps( aField.get_Properties() );
116 if ( aProps.IsValid() )
117 sTableName = OTools::getValue( aProps, OUString("BASETABLENAME") );
119 return sTableName;
122 OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
124 return OUString();
127 OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
129 return OUString();
132 OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException)
134 return getColumnName(column);
137 OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
139 return OUString();
143 sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException)
145 WpADOField aField = ADOS::getField(m_pRecordSet,column);
146 if(aField.IsValid())
148 return ((aField.GetAttributes() & adFldFixed) == adFldFixed) && (aField.GetADOType() == adCurrency);
150 return sal_False;
154 sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException)
156 sal_Bool bRet = sal_False;
157 WpADOField aField = ADOS::getField(m_pRecordSet,column);
158 if ( aField.IsValid() )
160 WpADOProperties aProps( aField.get_Properties() );
161 if ( aProps.IsValid() )
163 bRet = OTools::getValue( aProps, OUString("ISAUTOINCREMENT") );
164 #if OSL_DEBUG_LEVEL > 0
165 sal_Int32 nCount = aProps.GetItemCount();
166 for (sal_Int32 i = 0; i<nCount; ++i)
168 WpADOProperty aProp = aProps.GetItem(i);
169 OUString sName = aProp.GetName();
170 OUString sVal = aProp.GetValue();
172 #endif
175 return bRet;
180 sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException)
182 WpADOField aField = ADOS::getField(m_pRecordSet,column);
183 if(aField.IsValid())
185 DataTypeEnum eType = aField.GetADOType();
186 return !(eType == adUnsignedBigInt || eType == adUnsignedInt || eType == adUnsignedSmallInt || eType == adUnsignedTinyInt);
188 return sal_False;
191 sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException)
193 WpADOField aField = ADOS::getField(m_pRecordSet,column);
194 if(aField.IsValid())
195 return aField.GetPrecision();
196 return 0;
199 sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
201 WpADOField aField = ADOS::getField(m_pRecordSet,column);
202 if(aField.IsValid())
203 return aField.GetNumericScale();
204 return 0;
208 sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException)
210 WpADOField aField = ADOS::getField(m_pRecordSet,column);
211 if(aField.IsValid())
213 return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable;
215 return sal_False;
219 sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException)
221 return sal_True;
225 sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException)
227 WpADOField aField = ADOS::getField(m_pRecordSet,column);
228 if(aField.IsValid())
230 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
232 return sal_False;
236 sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
238 WpADOField aField = ADOS::getField(m_pRecordSet,column);
239 if(aField.IsValid())
241 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
243 return sal_False;
247 sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
249 return isDefinitelyWritable(column);
253 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */