Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / ado / ADatabaseMetaDataResultSetMetaData.cxx
blob011e347625d4d9dd3b7780f277d3b1354b01c44f
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/ADatabaseMetaDataResultSetMetaData.hxx"
21 #include "ado/Awrapado.hxx"
22 #include "connectivity/dbexception.hxx"
25 using namespace connectivity;
26 using namespace connectivity::ado;
27 using namespace com::sun::star::uno;
28 using namespace com::sun::star::lang;
29 using namespace com::sun::star::beans;
30 using namespace com::sun::star::sdbc;
33 ODatabaseMetaDataResultSetMetaData::~ODatabaseMetaDataResultSetMetaData()
35 if(m_pRecordSet)
36 m_pRecordSet->Release();
39 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException)
41 sal_Int32 nSize = 0;
42 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
43 nSize = (*m_mColumnsIter).second.getColumnDisplaySize();
44 else if(m_pRecordSet)
46 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
47 if(aField.IsValid())
48 nSize = aField.GetActualSize();
50 return nSize;
54 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException)
56 sal_Int32 nType = 0;
57 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
58 nType = (*m_mColumnsIter).second.getColumnType();
59 else if(m_pRecordSet)
61 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
62 nType = ADOS::MapADOType2Jdbc(aField.GetADOType());
64 return nType;
68 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException)
70 if(!m_pRecordSet)
71 return 0;
72 if(m_nColCount != -1)
73 return m_nColCount;
75 if(m_vMapping.size())
76 return m_mColumns.size();
78 ADOFields* pFields = NULL;
79 m_pRecordSet->get_Fields(&pFields);
80 WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields);
81 m_nColCount = aFields.GetItemCount();
82 return m_nColCount;
86 OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException)
88 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
89 return (*m_mColumnsIter).second.getColumnName();
90 if(!m_pRecordSet)
91 return OUString();
92 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
93 if(aField.IsValid())
94 return aField.GetName();
96 return OUString();
99 OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException)
101 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
102 return (*m_mColumnsIter).second.getColumnLabel();
103 return getColumnName(column);
107 sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException)
109 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
110 return (*m_mColumnsIter).second.isCurrency();
111 if(!m_pRecordSet)
112 return 0;
113 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
114 if(aField.IsValid())
116 return (aField.GetAttributes() & adFldFixed) == adFldFixed;
118 return sal_False;
123 sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException)
125 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
126 return (*m_mColumnsIter).second.isSigned();
127 if(!m_pRecordSet)
128 return 0;
129 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
130 if(aField.IsValid())
132 return (aField.GetAttributes() & adFldNegativeScale) == adFldNegativeScale;
134 return sal_False;
137 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException)
139 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
140 return (*m_mColumnsIter).second.getPrecision();
141 if(!m_pRecordSet)
142 return 0;
143 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
144 if(aField.IsValid())
145 return aField.GetPrecision();
146 return 0;
149 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
151 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
152 return (*m_mColumnsIter).second.getScale();
154 if(!m_pRecordSet)
155 return 0;
157 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
158 if(aField.IsValid())
159 return aField.GetNumericScale();
160 return 0;
164 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException)
166 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
167 return (*m_mColumnsIter).second.isNullable();
169 if(!m_pRecordSet)
170 return 0;
172 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
173 if(aField.IsValid())
175 return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable;
177 return sal_False;
181 sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException)
183 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
184 return (*m_mColumnsIter).second.isReadOnly();
186 if(!m_pRecordSet)
187 return 0;
189 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
190 if(aField.IsValid())
192 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
194 return sal_False;
198 sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
200 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
201 return (*m_mColumnsIter).second.isDefinitelyWritable();
203 if(!m_pRecordSet)
204 return 0;
206 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
207 if(aField.IsValid())
209 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
211 return sal_False;
215 sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
217 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
218 return (*m_mColumnsIter).second.isWritable();
219 return isDefinitelyWritable(column);
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */