Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / connectivity / source / drivers / ado / ADatabaseMetaDataResultSetMetaData.cxx
blob3fa13d06b84a93687cf99055f8a83ed8502bdf13
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>
24 using namespace connectivity;
25 using namespace connectivity::ado;
26 using namespace com::sun::star::uno;
27 using namespace com::sun::star::lang;
28 using namespace com::sun::star::beans;
29 using namespace com::sun::star::sdbc;
31 ODatabaseMetaDataResultSetMetaData::~ODatabaseMetaDataResultSetMetaData()
33 if (m_pRecordSet)
34 m_pRecordSet->Release();
37 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize(sal_Int32 column)
39 sal_Int32 nSize = 0;
40 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
41 nSize = (*m_mColumnsIter).second.getColumnDisplaySize();
42 else if (m_pRecordSet)
44 WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]);
45 if (aField.IsValid())
46 nSize = aField.GetActualSize();
48 return nSize;
51 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnType(sal_Int32 column)
53 sal_Int32 nType = 0;
54 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
55 nType = (*m_mColumnsIter).second.getColumnType();
56 else if (m_pRecordSet)
58 WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]);
59 nType = ADOS::MapADOType2Jdbc(aField.GetADOType());
61 return nType;
64 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnCount()
66 if (!m_pRecordSet)
67 return 0;
68 if (m_nColCount != -1)
69 return m_nColCount;
71 if (m_vMapping.size())
72 return m_mColumns.size();
74 WpOLEAppendCollection<ADOFields, WpADOField> aFields;
75 m_pRecordSet->get_Fields(&aFields);
76 m_nColCount = aFields.GetItemCount();
77 return m_nColCount;
80 OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnName(sal_Int32 column)
82 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
83 return (*m_mColumnsIter).second.getColumnName();
84 if (!m_pRecordSet)
85 return OUString();
86 WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]);
87 if (aField.IsValid())
88 return aField.GetName();
90 return OUString();
93 OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnLabel(sal_Int32 column)
95 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
96 return (*m_mColumnsIter).second.getColumnLabel();
97 return getColumnName(column);
100 sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isCurrency(sal_Int32 column)
102 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
103 return (*m_mColumnsIter).second.isCurrency();
104 if (!m_pRecordSet)
105 return false;
106 WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]);
107 if (aField.IsValid())
109 return (aField.GetAttributes() & adFldFixed) == adFldFixed;
111 return false;
114 sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isSigned(sal_Int32 column)
116 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
117 return (*m_mColumnsIter).second.isSigned();
118 if (!m_pRecordSet)
119 return false;
120 WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]);
121 if (aField.IsValid())
123 return (aField.GetAttributes() & adFldNegativeScale) == adFldNegativeScale;
125 return false;
128 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getPrecision(sal_Int32 column)
130 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
131 return (*m_mColumnsIter).second.getPrecision();
132 if (!m_pRecordSet)
133 return 0;
134 WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]);
135 if (aField.IsValid())
136 return aField.GetPrecision();
137 return 0;
140 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getScale(sal_Int32 column)
142 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
143 return (*m_mColumnsIter).second.getScale();
145 if (!m_pRecordSet)
146 return 0;
148 WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]);
149 if (aField.IsValid())
150 return aField.GetNumericScale();
151 return 0;
154 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::isNullable(sal_Int32 column)
156 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
157 return (*m_mColumnsIter).second.isNullable();
159 if (!m_pRecordSet)
160 return sal_Int32(false);
162 WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]);
163 if (aField.IsValid())
165 return sal_Int32((aField.GetAttributes() & adFldIsNullable) == adFldIsNullable);
167 return sal_Int32(false);
170 sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isReadOnly(sal_Int32 column)
172 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
173 return (*m_mColumnsIter).second.isReadOnly();
175 if (!m_pRecordSet)
176 return false;
178 WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]);
179 if (aField.IsValid())
181 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
183 return false;
186 sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isDefinitelyWritable(sal_Int32 column)
188 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
189 return (*m_mColumnsIter).second.isDefinitelyWritable();
191 if (!m_pRecordSet)
192 return false;
194 WpADOField aField = ADOS::getField(m_pRecordSet, m_vMapping[column]);
195 if (aField.IsValid())
197 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
199 return false;
203 sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isWritable(sal_Int32 column)
205 if (m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
206 return (*m_mColumnsIter).second.isWritable();
207 return isDefinitelyWritable(column);
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */