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