1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "ado/ADatabaseMetaDataResultSetMetaData.hxx"
30 #include "ado/Awrapado.hxx"
31 #include "connectivity/dbexception.hxx"
34 using namespace connectivity
;
35 using namespace connectivity::ado
;
36 using namespace com::sun::star::uno
;
37 using namespace com::sun::star::lang
;
38 using namespace com::sun::star::beans
;
39 using namespace com::sun::star::sdbc
;
41 // -------------------------------------------------------------------------
42 ODatabaseMetaDataResultSetMetaData::~ODatabaseMetaDataResultSetMetaData()
45 m_pRecordSet
->Release();
47 // -------------------------------------------------------------------------
48 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize( sal_Int32 column
) throw(SQLException
, RuntimeException
)
51 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
52 nSize
= (*m_mColumnsIter
).second
.getColumnDisplaySize();
55 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
57 nSize
= aField
.GetActualSize();
61 // -------------------------------------------------------------------------
63 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnType( sal_Int32 column
) throw(SQLException
, RuntimeException
)
66 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
67 nType
= (*m_mColumnsIter
).second
.getColumnType();
70 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
71 nType
= ADOS::MapADOType2Jdbc(aField
.GetADOType());
75 // -------------------------------------------------------------------------
77 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnCount( ) throw(SQLException
, RuntimeException
)
85 return m_mColumns
.size();
87 ADOFields
* pFields
= NULL
;
88 m_pRecordSet
->get_Fields(&pFields
);
89 WpOLEAppendCollection
<ADOFields
, ADOField
, WpADOField
> aFields(pFields
);
90 m_nColCount
= aFields
.GetItemCount();
93 // -------------------------------------------------------------------------
95 ::rtl::OUString SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnName( sal_Int32 column
) throw(SQLException
, RuntimeException
)
97 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
98 return (*m_mColumnsIter
).second
.getColumnName();
100 return ::rtl::OUString();
101 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
103 return aField
.GetName();
105 return ::rtl::OUString();
107 // -------------------------------------------------------------------------
108 ::rtl::OUString SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnLabel( sal_Int32 column
) throw(SQLException
, RuntimeException
)
110 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
111 return (*m_mColumnsIter
).second
.getColumnLabel();
112 return getColumnName(column
);
114 // -------------------------------------------------------------------------
116 sal_Bool SAL_CALL
ODatabaseMetaDataResultSetMetaData::isCurrency( sal_Int32 column
) throw(SQLException
, RuntimeException
)
118 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
119 return (*m_mColumnsIter
).second
.isCurrency();
122 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
125 return (aField
.GetAttributes() & adFldFixed
) == adFldFixed
;
129 // -------------------------------------------------------------------------
132 sal_Bool SAL_CALL
ODatabaseMetaDataResultSetMetaData::isSigned( sal_Int32 column
) throw(SQLException
, RuntimeException
)
134 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
135 return (*m_mColumnsIter
).second
.isSigned();
138 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
141 return (aField
.GetAttributes() & adFldNegativeScale
) == adFldNegativeScale
;
145 // -------------------------------------------------------------------------
146 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getPrecision( sal_Int32 column
) throw(SQLException
, RuntimeException
)
148 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
149 return (*m_mColumnsIter
).second
.getPrecision();
152 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
154 return aField
.GetPrecision();
157 // -------------------------------------------------------------------------
158 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getScale( sal_Int32 column
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
160 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
161 return (*m_mColumnsIter
).second
.getScale();
166 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
168 return aField
.GetNumericScale();
171 // -------------------------------------------------------------------------
173 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::isNullable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
175 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
176 return (*m_mColumnsIter
).second
.isNullable();
181 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
184 return (aField
.GetAttributes() & adFldIsNullable
) == adFldIsNullable
;
188 // -------------------------------------------------------------------------
190 sal_Bool SAL_CALL
ODatabaseMetaDataResultSetMetaData::isReadOnly( sal_Int32 column
) throw(SQLException
, RuntimeException
)
192 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
193 return (*m_mColumnsIter
).second
.isReadOnly();
198 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
201 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
205 // -------------------------------------------------------------------------
207 sal_Bool SAL_CALL
ODatabaseMetaDataResultSetMetaData::isDefinitelyWritable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
209 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
210 return (*m_mColumnsIter
).second
.isDefinitelyWritable();
215 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
218 return (aField
.GetAttributes() & adFldUpdatable
) == adFldUpdatable
;
223 // -------------------------------------------------------------------------
224 sal_Bool SAL_CALL
ODatabaseMetaDataResultSetMetaData::isWritable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
226 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
227 return (*m_mColumnsIter
).second
.isWritable();
228 return isDefinitelyWritable(column
);
230 // -----------------------------------------------------------------------------
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */