Update ooo320-m1
[ooovba.git] / connectivity / source / drivers / ado / ADatabaseMetaDataResultSetMetaData.cxx
blob6a9d640b918a0b6a31ed51aa1f0ae9e5c962f837
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ADatabaseMetaDataResultSetMetaData.cxx,v $
10 * $Revision: 1.11 $
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()
48 if(m_pRecordSet)
49 m_pRecordSet->Release();
51 // -------------------------------------------------------------------------
52 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException)
54 sal_Int32 nSize = 0;
55 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
56 nSize = (*m_mColumnsIter).second.getColumnDisplaySize();
57 else if(m_pRecordSet)
59 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
60 if(aField.IsValid())
61 nSize = aField.GetActualSize();
63 return nSize;
65 // -------------------------------------------------------------------------
67 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException)
69 sal_Int32 nType = 0;
70 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
71 nType = (*m_mColumnsIter).second.getColumnType();
72 else if(m_pRecordSet)
74 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
75 nType = ADOS::MapADOType2Jdbc(aField.GetADOType());
77 return nType;
79 // -------------------------------------------------------------------------
81 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException)
83 if(!m_pRecordSet)
84 return 0;
85 if(m_nColCount != -1)
86 return m_nColCount;
88 if(m_vMapping.size())
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();
95 return m_nColCount;
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();
103 if(!m_pRecordSet)
104 return ::rtl::OUString();
105 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
106 if(aField.IsValid())
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();
124 if(!m_pRecordSet)
125 return 0;
126 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
127 if(aField.IsValid())
129 return (aField.GetAttributes() & adFldFixed) == adFldFixed;
131 return sal_False;
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();
140 if(!m_pRecordSet)
141 return 0;
142 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
143 if(aField.IsValid())
145 return (aField.GetAttributes() & adFldNegativeScale) == adFldNegativeScale;
147 return sal_False;
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();
154 if(!m_pRecordSet)
155 return 0;
156 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
157 if(aField.IsValid())
158 return aField.GetPrecision();
159 return 0;
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();
167 if(!m_pRecordSet)
168 return 0;
170 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
171 if(aField.IsValid())
172 return aField.GetNumericScale();
173 return 0;
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();
182 if(!m_pRecordSet)
183 return 0;
185 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
186 if(aField.IsValid())
188 return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable;
190 return sal_False;
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();
199 if(!m_pRecordSet)
200 return 0;
202 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
203 if(aField.IsValid())
205 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
207 return sal_False;
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();
216 if(!m_pRecordSet)
217 return 0;
219 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
220 if(aField.IsValid())
222 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
224 return sal_False;
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 // -----------------------------------------------------------------------------