1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9b5730f6SAndrew Rist * distributed with this work for additional information
6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at
10*9b5730f6SAndrew Rist *
11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist *
13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the
17*9b5730f6SAndrew Rist * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist * under the License.
19*9b5730f6SAndrew Rist *
20*9b5730f6SAndrew Rist *************************************************************/
21*9b5730f6SAndrew Rist
22*9b5730f6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "ado/ADatabaseMetaDataResultSetMetaData.hxx"
27cdf0e10cSrcweir #include "ado/Awrapado.hxx"
28cdf0e10cSrcweir #include "connectivity/dbexception.hxx"
29cdf0e10cSrcweir
30cdf0e10cSrcweir
31cdf0e10cSrcweir using namespace connectivity;
32cdf0e10cSrcweir using namespace connectivity::ado;
33cdf0e10cSrcweir using namespace com::sun::star::uno;
34cdf0e10cSrcweir using namespace com::sun::star::lang;
35cdf0e10cSrcweir using namespace com::sun::star::beans;
36cdf0e10cSrcweir using namespace com::sun::star::sdbc;
37cdf0e10cSrcweir
38cdf0e10cSrcweir // -------------------------------------------------------------------------
~ODatabaseMetaDataResultSetMetaData()39cdf0e10cSrcweir ODatabaseMetaDataResultSetMetaData::~ODatabaseMetaDataResultSetMetaData()
40cdf0e10cSrcweir {
41cdf0e10cSrcweir if(m_pRecordSet)
42cdf0e10cSrcweir m_pRecordSet->Release();
43cdf0e10cSrcweir }
44cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnDisplaySize(sal_Int32 column)45cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir sal_Int32 nSize = 0;
48cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
49cdf0e10cSrcweir nSize = (*m_mColumnsIter).second.getColumnDisplaySize();
50cdf0e10cSrcweir else if(m_pRecordSet)
51cdf0e10cSrcweir {
52cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
53cdf0e10cSrcweir if(aField.IsValid())
54cdf0e10cSrcweir nSize = aField.GetActualSize();
55cdf0e10cSrcweir }
56cdf0e10cSrcweir return nSize;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir // -------------------------------------------------------------------------
59cdf0e10cSrcweir
getColumnType(sal_Int32 column)60cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir sal_Int32 nType = 0;
63cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
64cdf0e10cSrcweir nType = (*m_mColumnsIter).second.getColumnType();
65cdf0e10cSrcweir else if(m_pRecordSet)
66cdf0e10cSrcweir {
67cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
68cdf0e10cSrcweir nType = ADOS::MapADOType2Jdbc(aField.GetADOType());
69cdf0e10cSrcweir }
70cdf0e10cSrcweir return nType;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir // -------------------------------------------------------------------------
73cdf0e10cSrcweir
getColumnCount()74cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException)
75cdf0e10cSrcweir {
76cdf0e10cSrcweir if(!m_pRecordSet)
77cdf0e10cSrcweir return 0;
78cdf0e10cSrcweir if(m_nColCount != -1)
79cdf0e10cSrcweir return m_nColCount;
80cdf0e10cSrcweir
81cdf0e10cSrcweir if(m_vMapping.size())
82cdf0e10cSrcweir return m_mColumns.size();
83cdf0e10cSrcweir
84cdf0e10cSrcweir ADOFields* pFields = NULL;
85cdf0e10cSrcweir m_pRecordSet->get_Fields(&pFields);
86cdf0e10cSrcweir WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields);
87cdf0e10cSrcweir m_nColCount = aFields.GetItemCount();
88cdf0e10cSrcweir return m_nColCount;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir // -------------------------------------------------------------------------
91cdf0e10cSrcweir
getColumnName(sal_Int32 column)92cdf0e10cSrcweir ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException)
93cdf0e10cSrcweir {
94cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
95cdf0e10cSrcweir return (*m_mColumnsIter).second.getColumnName();
96cdf0e10cSrcweir if(!m_pRecordSet)
97cdf0e10cSrcweir return ::rtl::OUString();
98cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
99cdf0e10cSrcweir if(aField.IsValid())
100cdf0e10cSrcweir return aField.GetName();
101cdf0e10cSrcweir
102cdf0e10cSrcweir return ::rtl::OUString();
103cdf0e10cSrcweir }
104cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnLabel(sal_Int32 column)105cdf0e10cSrcweir ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
108cdf0e10cSrcweir return (*m_mColumnsIter).second.getColumnLabel();
109cdf0e10cSrcweir return getColumnName(column);
110cdf0e10cSrcweir }
111cdf0e10cSrcweir // -------------------------------------------------------------------------
112cdf0e10cSrcweir
isCurrency(sal_Int32 column)113cdf0e10cSrcweir sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException)
114cdf0e10cSrcweir {
115cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
116cdf0e10cSrcweir return (*m_mColumnsIter).second.isCurrency();
117cdf0e10cSrcweir if(!m_pRecordSet)
118cdf0e10cSrcweir return 0;
119cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
120cdf0e10cSrcweir if(aField.IsValid())
121cdf0e10cSrcweir {
122cdf0e10cSrcweir return (aField.GetAttributes() & adFldFixed) == adFldFixed;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir return sal_False;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir // -------------------------------------------------------------------------
127cdf0e10cSrcweir
128cdf0e10cSrcweir
isSigned(sal_Int32 column)129cdf0e10cSrcweir sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
132cdf0e10cSrcweir return (*m_mColumnsIter).second.isSigned();
133cdf0e10cSrcweir if(!m_pRecordSet)
134cdf0e10cSrcweir return 0;
135cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
136cdf0e10cSrcweir if(aField.IsValid())
137cdf0e10cSrcweir {
138cdf0e10cSrcweir return (aField.GetAttributes() & adFldNegativeScale) == adFldNegativeScale;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir return sal_False;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir // -------------------------------------------------------------------------
getPrecision(sal_Int32 column)143cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
146cdf0e10cSrcweir return (*m_mColumnsIter).second.getPrecision();
147cdf0e10cSrcweir if(!m_pRecordSet)
148cdf0e10cSrcweir return 0;
149cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
150cdf0e10cSrcweir if(aField.IsValid())
151cdf0e10cSrcweir return aField.GetPrecision();
152cdf0e10cSrcweir return 0;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir // -------------------------------------------------------------------------
getScale(sal_Int32 column)155cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
156cdf0e10cSrcweir {
157cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
158cdf0e10cSrcweir return (*m_mColumnsIter).second.getScale();
159cdf0e10cSrcweir
160cdf0e10cSrcweir if(!m_pRecordSet)
161cdf0e10cSrcweir return 0;
162cdf0e10cSrcweir
163cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
164cdf0e10cSrcweir if(aField.IsValid())
165cdf0e10cSrcweir return aField.GetNumericScale();
166cdf0e10cSrcweir return 0;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir // -------------------------------------------------------------------------
169cdf0e10cSrcweir
isNullable(sal_Int32 column)170cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException)
171cdf0e10cSrcweir {
172cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
173cdf0e10cSrcweir return (*m_mColumnsIter).second.isNullable();
174cdf0e10cSrcweir
175cdf0e10cSrcweir if(!m_pRecordSet)
176cdf0e10cSrcweir return 0;
177cdf0e10cSrcweir
178cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
179cdf0e10cSrcweir if(aField.IsValid())
180cdf0e10cSrcweir {
181cdf0e10cSrcweir return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir return sal_False;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir // -------------------------------------------------------------------------
186cdf0e10cSrcweir
isReadOnly(sal_Int32 column)187cdf0e10cSrcweir sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
190cdf0e10cSrcweir return (*m_mColumnsIter).second.isReadOnly();
191cdf0e10cSrcweir
192cdf0e10cSrcweir if(!m_pRecordSet)
193cdf0e10cSrcweir return 0;
194cdf0e10cSrcweir
195cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
196cdf0e10cSrcweir if(aField.IsValid())
197cdf0e10cSrcweir {
198cdf0e10cSrcweir // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir return sal_False;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir // -------------------------------------------------------------------------
203cdf0e10cSrcweir
isDefinitelyWritable(sal_Int32 column)204cdf0e10cSrcweir sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
205cdf0e10cSrcweir {
206cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
207cdf0e10cSrcweir return (*m_mColumnsIter).second.isDefinitelyWritable();
208cdf0e10cSrcweir
209cdf0e10cSrcweir if(!m_pRecordSet)
210cdf0e10cSrcweir return 0;
211cdf0e10cSrcweir
212cdf0e10cSrcweir WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
213cdf0e10cSrcweir if(aField.IsValid())
214cdf0e10cSrcweir {
215cdf0e10cSrcweir return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir return sal_False;
218cdf0e10cSrcweir ;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir // -------------------------------------------------------------------------
isWritable(sal_Int32 column)221cdf0e10cSrcweir sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
222cdf0e10cSrcweir {
223cdf0e10cSrcweir if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
224cdf0e10cSrcweir return (*m_mColumnsIter).second.isWritable();
225cdf0e10cSrcweir return isDefinitelyWritable(column);
226cdf0e10cSrcweir }
227cdf0e10cSrcweir // -----------------------------------------------------------------------------
228cdf0e10cSrcweir
229cdf0e10cSrcweir
230