1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ADatabaseMetaDataResultSetMetaData.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "ado/ADatabaseMetaDataResultSetMetaData.hxx"
34 #include "ado/Awrapado.hxx"
35 #include "connectivity/dbexception.hxx"
38 using namespace connectivity
;
39 using namespace connectivity::ado
;
40 using namespace com::sun::star::uno
;
41 using namespace com::sun::star::lang
;
42 using namespace com::sun::star::beans
;
43 using namespace com::sun::star::sdbc
;
45 // -------------------------------------------------------------------------
46 ODatabaseMetaDataResultSetMetaData::~ODatabaseMetaDataResultSetMetaData()
49 m_pRecordSet
->Release();
51 // -------------------------------------------------------------------------
52 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize( sal_Int32 column
) throw(SQLException
, RuntimeException
)
55 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
56 nSize
= (*m_mColumnsIter
).second
.getColumnDisplaySize();
59 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
61 nSize
= aField
.GetActualSize();
65 // -------------------------------------------------------------------------
67 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnType( sal_Int32 column
) throw(SQLException
, RuntimeException
)
70 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
71 nType
= (*m_mColumnsIter
).second
.getColumnType();
74 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
75 nType
= ADOS::MapADOType2Jdbc(aField
.GetADOType());
79 // -------------------------------------------------------------------------
81 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnCount( ) throw(SQLException
, RuntimeException
)
89 return m_mColumns
.size();
91 ADOFields
* pFields
= NULL
;
92 m_pRecordSet
->get_Fields(&pFields
);
93 WpOLEAppendCollection
<ADOFields
, ADOField
, WpADOField
> aFields(pFields
);
94 m_nColCount
= aFields
.GetItemCount();
97 // -------------------------------------------------------------------------
99 ::rtl::OUString SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnName( 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
.getColumnName();
104 return ::rtl::OUString();
105 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
107 return aField
.GetName();
109 return ::rtl::OUString();
111 // -------------------------------------------------------------------------
112 ::rtl::OUString SAL_CALL
ODatabaseMetaDataResultSetMetaData::getColumnLabel( sal_Int32 column
) throw(SQLException
, RuntimeException
)
114 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
115 return (*m_mColumnsIter
).second
.getColumnLabel();
116 return getColumnName(column
);
118 // -------------------------------------------------------------------------
120 sal_Bool SAL_CALL
ODatabaseMetaDataResultSetMetaData::isCurrency( sal_Int32 column
) throw(SQLException
, RuntimeException
)
122 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
123 return (*m_mColumnsIter
).second
.isCurrency();
126 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
129 return (aField
.GetAttributes() & adFldFixed
) == adFldFixed
;
133 // -------------------------------------------------------------------------
136 sal_Bool SAL_CALL
ODatabaseMetaDataResultSetMetaData::isSigned( sal_Int32 column
) throw(SQLException
, RuntimeException
)
138 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
139 return (*m_mColumnsIter
).second
.isSigned();
142 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
145 return (aField
.GetAttributes() & adFldNegativeScale
) == adFldNegativeScale
;
149 // -------------------------------------------------------------------------
150 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getPrecision( sal_Int32 column
) throw(SQLException
, RuntimeException
)
152 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
153 return (*m_mColumnsIter
).second
.getPrecision();
156 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
158 return aField
.GetPrecision();
161 // -------------------------------------------------------------------------
162 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::getScale( sal_Int32 column
) throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
)
164 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
165 return (*m_mColumnsIter
).second
.getScale();
170 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
172 return aField
.GetNumericScale();
175 // -------------------------------------------------------------------------
177 sal_Int32 SAL_CALL
ODatabaseMetaDataResultSetMetaData::isNullable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
179 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
180 return (*m_mColumnsIter
).second
.isNullable();
185 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
188 return (aField
.GetAttributes() & adFldIsNullable
) == adFldIsNullable
;
192 // -------------------------------------------------------------------------
194 sal_Bool SAL_CALL
ODatabaseMetaDataResultSetMetaData::isReadOnly( sal_Int32 column
) throw(SQLException
, RuntimeException
)
196 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
197 return (*m_mColumnsIter
).second
.isReadOnly();
202 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
205 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
209 // -------------------------------------------------------------------------
211 sal_Bool SAL_CALL
ODatabaseMetaDataResultSetMetaData::isDefinitelyWritable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
213 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
214 return (*m_mColumnsIter
).second
.isDefinitelyWritable();
219 WpADOField aField
= ADOS::getField(m_pRecordSet
,m_vMapping
[column
]);
222 return (aField
.GetAttributes() & adFldUpdatable
) == adFldUpdatable
;
227 // -------------------------------------------------------------------------
228 sal_Bool SAL_CALL
ODatabaseMetaDataResultSetMetaData::isWritable( sal_Int32 column
) throw(SQLException
, RuntimeException
)
230 if(m_mColumns
.size() && (m_mColumnsIter
= m_mColumns
.find(column
)) != m_mColumns
.end())
231 return (*m_mColumnsIter
).second
.isWritable();
232 return isDefinitelyWritable(column
);
234 // -----------------------------------------------------------------------------