1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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()
34 m_pRecordSet
->Release();
37 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize(sal_Int32 column
)
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
]);
46 nSize
= aField
.GetActualSize();
51 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnType(sal_Int32 column
)
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());
64 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnCount()
68 if (m_nColCount
!= -1)
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();
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();
86 WpADOField aField
= ADOS::getField(m_pRecordSet
, m_vMapping
[column
]);
88 return aField
.GetName();
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();
106 WpADOField aField
= ADOS::getField(m_pRecordSet
, m_vMapping
[column
]);
107 if (aField
.IsValid())
109 return (aField
.GetAttributes() & adFldFixed
) == adFldFixed
;
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();
120 WpADOField aField
= ADOS::getField(m_pRecordSet
, m_vMapping
[column
]);
121 if (aField
.IsValid())
123 return (aField
.GetAttributes() & adFldNegativeScale
) == adFldNegativeScale
;
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();
134 WpADOField aField
= ADOS::getField(m_pRecordSet
, m_vMapping
[column
]);
135 if (aField
.IsValid())
136 return aField
.GetPrecision();
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();
148 WpADOField aField
= ADOS::getField(m_pRecordSet
, m_vMapping
[column
]);
149 if (aField
.IsValid())
150 return aField
.GetNumericScale();
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();
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();
178 WpADOField aField
= ADOS::getField(m_pRecordSet
, m_vMapping
[column
]);
179 if (aField
.IsValid())
181 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
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();
194 WpADOField aField
= ADOS::getField(m_pRecordSet
, m_vMapping
[column
]);
195 if (aField
.IsValid())
197 return (aField
.GetAttributes() & adFldUpdatable
) == adFldUpdatable
;
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: */