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"
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()
36 m_pRecordSet
->Release();
39 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize( sal_Int32 column
) throw(SQLException
, RuntimeException
)
42 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
43 nSize
= (*m_mColumnsIter
).second
.getColumnDisplaySize();
46 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
48 nSize
= aField
.GetActualSize();
54 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnType( sal_Int32 column
) throw(SQLException
, RuntimeException
)
57 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
58 nType
= (*m_mColumnsIter
).second
.getColumnType();
61 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
62 nType
= ADOS::MapADOType2Jdbc(aField
.GetADOType());
68 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnCount( ) throw(SQLException
, RuntimeException
)
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();
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();
92 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
94 return aField
.GetName();
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();
113 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
116 return (aField
.GetAttributes() & adFldFixed
) == adFldFixed
;
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();
129 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
132 return (aField
.GetAttributes() & adFldNegativeScale
) == adFldNegativeScale
;
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();
143 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
145 return aField
.GetPrecision();
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();
157 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
159 return aField
.GetNumericScale();
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();
172 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
175 return (aField
.GetAttributes() & adFldIsNullable
) == adFldIsNullable
;
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();
189 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
192 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
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();
206 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
209 return (aField
.GetAttributes() & adFldUpdatable
) == adFldUpdatable
;
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: */