1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
30*cdf0e10cSrcweir #include "ado/ADatabaseMetaDataResultSetMetaData.hxx"
31*cdf0e10cSrcweir #include "ado/Awrapado.hxx"
32*cdf0e10cSrcweir #include "connectivity/dbexception.hxx"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir using namespace connectivity;
36*cdf0e10cSrcweir using namespace connectivity::ado;
37*cdf0e10cSrcweir using namespace com::sun::star::uno;
38*cdf0e10cSrcweir using namespace com::sun::star::lang;
39*cdf0e10cSrcweir using namespace com::sun::star::beans;
40*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir // -------------------------------------------------------------------------
43*cdf0e10cSrcweir ODatabaseMetaDataResultSetMetaData::~ODatabaseMetaDataResultSetMetaData()
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir 	if(m_pRecordSet)
46*cdf0e10cSrcweir 		m_pRecordSet->Release();
47*cdf0e10cSrcweir }
48*cdf0e10cSrcweir // -------------------------------------------------------------------------
49*cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException)
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir 	sal_Int32 nSize = 0;
52*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
53*cdf0e10cSrcweir 		nSize = (*m_mColumnsIter).second.getColumnDisplaySize();
54*cdf0e10cSrcweir 	else if(m_pRecordSet)
55*cdf0e10cSrcweir 	{
56*cdf0e10cSrcweir 		WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
57*cdf0e10cSrcweir 		if(aField.IsValid())
58*cdf0e10cSrcweir 			nSize = aField.GetActualSize();
59*cdf0e10cSrcweir 	}
60*cdf0e10cSrcweir 	return nSize;
61*cdf0e10cSrcweir }
62*cdf0e10cSrcweir // -------------------------------------------------------------------------
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException)
65*cdf0e10cSrcweir {
66*cdf0e10cSrcweir 	sal_Int32  nType = 0;
67*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
68*cdf0e10cSrcweir 		nType = (*m_mColumnsIter).second.getColumnType();
69*cdf0e10cSrcweir 	else if(m_pRecordSet)
70*cdf0e10cSrcweir 	{
71*cdf0e10cSrcweir 		WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
72*cdf0e10cSrcweir 		nType = ADOS::MapADOType2Jdbc(aField.GetADOType());
73*cdf0e10cSrcweir 	}
74*cdf0e10cSrcweir 	return nType;
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir // -------------------------------------------------------------------------
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnCount(  ) throw(SQLException, RuntimeException)
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir 	if(!m_pRecordSet)
81*cdf0e10cSrcweir 		return 0;
82*cdf0e10cSrcweir 	if(m_nColCount != -1)
83*cdf0e10cSrcweir 		return m_nColCount;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 	if(m_vMapping.size())
86*cdf0e10cSrcweir 		return m_mColumns.size();
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 	ADOFields* pFields	= NULL;
89*cdf0e10cSrcweir 	m_pRecordSet->get_Fields(&pFields);
90*cdf0e10cSrcweir 	WpOLEAppendCollection<ADOFields, ADOField, WpADOField>	aFields(pFields);
91*cdf0e10cSrcweir 	m_nColCount = aFields.GetItemCount();
92*cdf0e10cSrcweir 	return m_nColCount;
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir // -------------------------------------------------------------------------
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException)
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
99*cdf0e10cSrcweir 		return (*m_mColumnsIter).second.getColumnName();
100*cdf0e10cSrcweir 	if(!m_pRecordSet)
101*cdf0e10cSrcweir 		return ::rtl::OUString();
102*cdf0e10cSrcweir 	WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
103*cdf0e10cSrcweir 	if(aField.IsValid())
104*cdf0e10cSrcweir 		return aField.GetName();
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 	return ::rtl::OUString();
107*cdf0e10cSrcweir }
108*cdf0e10cSrcweir // -------------------------------------------------------------------------
109*cdf0e10cSrcweir ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException)
110*cdf0e10cSrcweir {
111*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
112*cdf0e10cSrcweir 		return (*m_mColumnsIter).second.getColumnLabel();
113*cdf0e10cSrcweir 	return getColumnName(column);
114*cdf0e10cSrcweir }
115*cdf0e10cSrcweir // -------------------------------------------------------------------------
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException)
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
120*cdf0e10cSrcweir 		return (*m_mColumnsIter).second.isCurrency();
121*cdf0e10cSrcweir 	if(!m_pRecordSet)
122*cdf0e10cSrcweir 		return 0;
123*cdf0e10cSrcweir 	WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
124*cdf0e10cSrcweir 	if(aField.IsValid())
125*cdf0e10cSrcweir 	{
126*cdf0e10cSrcweir 		return (aField.GetAttributes() & adFldFixed) == adFldFixed;
127*cdf0e10cSrcweir 	}
128*cdf0e10cSrcweir 	return sal_False;
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir // -------------------------------------------------------------------------
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException)
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
136*cdf0e10cSrcweir 		return (*m_mColumnsIter).second.isSigned();
137*cdf0e10cSrcweir 	if(!m_pRecordSet)
138*cdf0e10cSrcweir 		return 0;
139*cdf0e10cSrcweir 	WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
140*cdf0e10cSrcweir 	if(aField.IsValid())
141*cdf0e10cSrcweir 	{
142*cdf0e10cSrcweir 		return (aField.GetAttributes() & adFldNegativeScale) == adFldNegativeScale;
143*cdf0e10cSrcweir 	}
144*cdf0e10cSrcweir 	return sal_False;
145*cdf0e10cSrcweir }
146*cdf0e10cSrcweir // -------------------------------------------------------------------------
147*cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException)
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
150*cdf0e10cSrcweir 		return (*m_mColumnsIter).second.getPrecision();
151*cdf0e10cSrcweir 	if(!m_pRecordSet)
152*cdf0e10cSrcweir 		return 0;
153*cdf0e10cSrcweir 	WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
154*cdf0e10cSrcweir 	if(aField.IsValid())
155*cdf0e10cSrcweir 		return aField.GetPrecision();
156*cdf0e10cSrcweir 	return 0;
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir // -------------------------------------------------------------------------
159*cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
162*cdf0e10cSrcweir 		return (*m_mColumnsIter).second.getScale();
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 	if(!m_pRecordSet)
165*cdf0e10cSrcweir 		return 0;
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir 	WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
168*cdf0e10cSrcweir 	if(aField.IsValid())
169*cdf0e10cSrcweir 		return aField.GetNumericScale();
170*cdf0e10cSrcweir 	return 0;
171*cdf0e10cSrcweir }
172*cdf0e10cSrcweir // -------------------------------------------------------------------------
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir sal_Int32 SAL_CALL ODatabaseMetaDataResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException)
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
177*cdf0e10cSrcweir 		return (*m_mColumnsIter).second.isNullable();
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 	if(!m_pRecordSet)
180*cdf0e10cSrcweir 		return 0;
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 	WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
183*cdf0e10cSrcweir 	if(aField.IsValid())
184*cdf0e10cSrcweir 	{
185*cdf0e10cSrcweir 		return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable;
186*cdf0e10cSrcweir 	}
187*cdf0e10cSrcweir 	return sal_False;
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir // -------------------------------------------------------------------------
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException)
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
194*cdf0e10cSrcweir 		return (*m_mColumnsIter).second.isReadOnly();
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 	if(!m_pRecordSet)
197*cdf0e10cSrcweir 		return 0;
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir 	WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
200*cdf0e10cSrcweir 	if(aField.IsValid())
201*cdf0e10cSrcweir 	{
202*cdf0e10cSrcweir 		//	return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly;
203*cdf0e10cSrcweir 	}
204*cdf0e10cSrcweir 	return sal_False;
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir // -------------------------------------------------------------------------
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
209*cdf0e10cSrcweir {
210*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
211*cdf0e10cSrcweir 		return (*m_mColumnsIter).second.isDefinitelyWritable();
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 	if(!m_pRecordSet)
214*cdf0e10cSrcweir 		return 0;
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 	WpADOField aField = ADOS::getField(m_pRecordSet,m_vMapping[column]);
217*cdf0e10cSrcweir 	if(aField.IsValid())
218*cdf0e10cSrcweir 	{
219*cdf0e10cSrcweir 		return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable;
220*cdf0e10cSrcweir 	}
221*cdf0e10cSrcweir 	return sal_False;
222*cdf0e10cSrcweir ;
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir // -------------------------------------------------------------------------
225*cdf0e10cSrcweir sal_Bool SAL_CALL ODatabaseMetaDataResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException)
226*cdf0e10cSrcweir {
227*cdf0e10cSrcweir 	if(m_mColumns.size() && (m_mColumnsIter = m_mColumns.find(column)) != m_mColumns.end())
228*cdf0e10cSrcweir 		return (*m_mColumnsIter).second.isWritable();
229*cdf0e10cSrcweir 	return isDefinitelyWritable(column);
230*cdf0e10cSrcweir }
231*cdf0e10cSrcweir // -----------------------------------------------------------------------------
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 
234