Bump for 3.6-28
[LibreOffice.git] / connectivity / source / drivers / ado / ADatabaseMetaDataResultSetMetaData.cxx
blobc0be8aa1075de970a17cae93a06babbf007d13a2
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()
44 if(m_pRecordSet)
45 m_pRecordSet->Release();
47 // -------------------------------------------------------------------------
48 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException)
50 sal_Int32 nSize = 0;
51 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
52 nSize = (*m_mColumnsIter).second.getColumnDisplaySize();
53 else if(m_pRecordSet)
55 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
56 if(aField.IsValid())
57 nSize = aField.GetActualSize();
59 return nSize;
61 // -------------------------------------------------------------------------
63 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException)
65 sal_Int32 nType = 0;
66 if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
67 nType = (*m_mColumnsIter).second.getColumnType();
68 else if(m_pRecordSet)
70 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
71 nType = ADOS::MapADOType2Jdbc(aField.GetADOType());
73 return nType;
75 // -------------------------------------------------------------------------
77 sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException)
79 if(!m_pRecordSet)
80 return 0;
81 if(m_nColCount != -1)
82 return m_nColCount;
84 if(m_vMapping.size())
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();
91 return m_nColCount;
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();
99 if(!m_pRecordSet)
100 return ::rtl::OUString();
101 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
102 if(aField.IsValid())
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();
120 if(!m_pRecordSet)
121 return 0;
122 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
123 if(aField.IsValid())
125 return (aField.GetAttributes() & adFldFixed) == adFldFixed;
127 return sal_False;
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();
136 if(!m_pRecordSet)
137 return 0;
138 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
139 if(aField.IsValid())
141 return (aField.GetAttributes() & adFldNegativeScale) == adFldNegativeScale;
143 return sal_False;
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();
150 if(!m_pRecordSet)
151 return 0;
152 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
153 if(aField.IsValid())
154 return aField.GetPrecision();
155 return 0;
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();
163 if(!m_pRecordSet)
164 return 0;
166 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
167 if(aField.IsValid())
168 return aField.GetNumericScale();
169 return 0;
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();
178 if(!m_pRecordSet)
179 return 0;
181 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
182 if(aField.IsValid())
184 return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable;
186 return sal_False;
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();
195 if(!m_pRecordSet)
196 return 0;
198 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
199 if(aField.IsValid())
201 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
203 return sal_False;
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();
212 if(!m_pRecordSet)
213 return 0;
215 WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
216 if(aField.IsValid())
218 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
220 return sal_False;
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: */