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 
27cdf0e10cSrcweir #include "MacabResultSetMetaData.hxx"
28cdf0e10cSrcweir #include "MacabHeader.hxx"
29cdf0e10cSrcweir #include "MacabRecords.hxx"
30cdf0e10cSrcweir #include "MacabAddressBook.hxx"
31cdf0e10cSrcweir #include "macabutilities.hxx"
32cdf0e10cSrcweir #include "resource/macab_res.hrc"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace connectivity::macab;
35cdf0e10cSrcweir using namespace com::sun::star::uno;
36cdf0e10cSrcweir using namespace com::sun::star::lang;
37cdf0e10cSrcweir using namespace com::sun::star::sdbc;
38cdf0e10cSrcweir 
MacabResultSetMetaData(MacabConnection * _pConnection,::rtl::OUString _sTableName)39cdf0e10cSrcweir MacabResultSetMetaData::MacabResultSetMetaData(MacabConnection* _pConnection, ::rtl::OUString _sTableName)
40cdf0e10cSrcweir 	: m_pConnection(_pConnection),
41cdf0e10cSrcweir 		m_sTableName(_sTableName),
42cdf0e10cSrcweir 	  m_aMacabFields()
43cdf0e10cSrcweir {
44cdf0e10cSrcweir }
45cdf0e10cSrcweir // -------------------------------------------------------------------------
~MacabResultSetMetaData()46cdf0e10cSrcweir MacabResultSetMetaData::~MacabResultSetMetaData()
47cdf0e10cSrcweir {
48cdf0e10cSrcweir }
49cdf0e10cSrcweir // -------------------------------------------------------------------------
setMacabFields(const::vos::ORef<connectivity::OSQLColumns> & xColumns)50cdf0e10cSrcweir void MacabResultSetMetaData::setMacabFields(const ::vos::ORef<connectivity::OSQLColumns> &xColumns) throw(SQLException)
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 	OSQLColumns::Vector::const_iterator aIter;
53cdf0e10cSrcweir 	static const ::rtl::OUString aName(::rtl::OUString::createFromAscii("Name"));
54cdf0e10cSrcweir 	MacabRecords *aRecords;
55cdf0e10cSrcweir 	MacabHeader *aHeader;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	// In case, somehow, we don't have anything with the name m_sTableName
60cdf0e10cSrcweir 	if(aRecords == NULL)
61cdf0e10cSrcweir 	{
62cdf0e10cSrcweir         impl_throwError(STR_NO_TABLE);
63cdf0e10cSrcweir 	}
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	aHeader = aRecords->getHeader();
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	for (aIter = xColumns->get().begin(); aIter != xColumns->get().end(); ++aIter)
68cdf0e10cSrcweir 	{
69cdf0e10cSrcweir 		::rtl::OUString aFieldName;
70cdf0e10cSrcweir 		sal_uInt32 nFieldNumber;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 		(*aIter)->getPropertyValue(aName) >>= aFieldName;
73cdf0e10cSrcweir 		nFieldNumber = aHeader->getColumnNumber(aFieldName);
74cdf0e10cSrcweir 		m_aMacabFields.push_back(nFieldNumber);
75cdf0e10cSrcweir 	}
76cdf0e10cSrcweir 
77cdf0e10cSrcweir }
78cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnDisplaySize(sal_Int32 column)79cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnDisplaySize(sal_Int32 column) throw(SQLException, RuntimeException)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	// For now, all columns are the same size.
82cdf0e10cSrcweir 	return 50;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnType(sal_Int32 column)85cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnType(sal_Int32 column) throw(SQLException, RuntimeException)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	MacabRecords *aRecords;
88cdf0e10cSrcweir 	MacabHeader *aHeader;
89cdf0e10cSrcweir 	macabfield *aField;
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 	aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	// In case, somehow, we don't have anything with the name m_sTableName
94cdf0e10cSrcweir 	if(aRecords == NULL)
95cdf0e10cSrcweir 	{
96cdf0e10cSrcweir         impl_throwError(STR_NO_TABLE);
97cdf0e10cSrcweir 	}
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	aHeader = aRecords->getHeader();
100cdf0e10cSrcweir 	aField = aHeader->get(column-1);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	if(aField == NULL)
103cdf0e10cSrcweir 	{
104cdf0e10cSrcweir         ::dbtools::throwInvalidIndexException(*this,Any());
105cdf0e10cSrcweir 		return -1;
106cdf0e10cSrcweir 	}
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	return ABTypeToDataType(aField->type);
109cdf0e10cSrcweir }
110cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnCount()111cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnCount() throw(SQLException, RuntimeException)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	return m_aMacabFields.size();
114cdf0e10cSrcweir }
115cdf0e10cSrcweir // -------------------------------------------------------------------------
isCaseSensitive(sal_Int32)116cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isCaseSensitive(sal_Int32) throw(SQLException, RuntimeException)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir 	return sal_True;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir // -------------------------------------------------------------------------
getSchemaName(sal_Int32)121cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getSchemaName(sal_Int32) throw(SQLException, RuntimeException)
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	return ::rtl::OUString();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnName(sal_Int32 column)126cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnName(sal_Int32 column) throw(SQLException, RuntimeException)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	sal_uInt32 nFieldNumber = m_aMacabFields[column - 1];
129cdf0e10cSrcweir 	MacabRecords *aRecords;
130cdf0e10cSrcweir 	MacabHeader *aHeader;
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 	// In case, somehow, we don't have anything with the name m_sTableName
135cdf0e10cSrcweir 	if(aRecords == NULL)
136cdf0e10cSrcweir 	{
137cdf0e10cSrcweir 		impl_throwError(STR_NO_TABLE);
138cdf0e10cSrcweir 	}
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	aHeader = aRecords->getHeader();
141cdf0e10cSrcweir 	::rtl::OUString aName = aHeader->getString(nFieldNumber);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 	return aName;
144cdf0e10cSrcweir }
145cdf0e10cSrcweir // -------------------------------------------------------------------------
getTableName(sal_Int32)146cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getTableName(sal_Int32) throw(SQLException, RuntimeException)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir 	return m_sTableName;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir // -------------------------------------------------------------------------
getCatalogName(sal_Int32)151cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getCatalogName(sal_Int32) throw(SQLException, RuntimeException)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	return ::rtl::OUString();
154cdf0e10cSrcweir }
155cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnTypeName(sal_Int32)156cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnTypeName(sal_Int32) throw(SQLException, RuntimeException)
157cdf0e10cSrcweir {
158cdf0e10cSrcweir 	return ::rtl::OUString();
159cdf0e10cSrcweir }
160cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnLabel(sal_Int32)161cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnLabel(sal_Int32) throw(SQLException, RuntimeException)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir 	return ::rtl::OUString();
164cdf0e10cSrcweir }
165cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnServiceName(sal_Int32)166cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnServiceName(sal_Int32) throw(SQLException, RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	return ::rtl::OUString();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir // -------------------------------------------------------------------------
isCurrency(sal_Int32)171cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isCurrency(sal_Int32) throw(SQLException, RuntimeException)
172cdf0e10cSrcweir {
173cdf0e10cSrcweir 	return sal_False;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir // -------------------------------------------------------------------------
isAutoIncrement(sal_Int32)176cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isAutoIncrement(sal_Int32) throw(SQLException, RuntimeException)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir 	return sal_False;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir // -------------------------------------------------------------------------
isSigned(sal_Int32)181cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isSigned(sal_Int32) throw(SQLException, RuntimeException)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir 	return sal_False;
184cdf0e10cSrcweir }
185cdf0e10cSrcweir // -------------------------------------------------------------------------
getPrecision(sal_Int32)186cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::getPrecision(sal_Int32) throw(SQLException, RuntimeException)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir 	return 0;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir // -----------------------------------------------------------------------------
getScale(sal_Int32)191cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::getScale(sal_Int32) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
192cdf0e10cSrcweir {
193cdf0e10cSrcweir 	return 0;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir // -------------------------------------------------------------------------
isNullable(sal_Int32)196cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::isNullable(sal_Int32) throw(SQLException, RuntimeException)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir 	return (sal_Int32) sal_True;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir // -------------------------------------------------------------------------
isSearchable(sal_Int32)201cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isSearchable(sal_Int32) throw(SQLException, RuntimeException)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir 	return sal_True;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir // -------------------------------------------------------------------------
isReadOnly(sal_Int32)206cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isReadOnly(sal_Int32) throw(SQLException, RuntimeException)
207cdf0e10cSrcweir {
208cdf0e10cSrcweir 	return sal_True;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir // -------------------------------------------------------------------------
isDefinitelyWritable(sal_Int32)211cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isDefinitelyWritable(sal_Int32) throw(SQLException, RuntimeException)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir 	return sal_False;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir // -------------------------------------------------------------------------
isWritable(sal_Int32)216cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isWritable(sal_Int32) throw(SQLException, RuntimeException)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	return sal_False;
219cdf0e10cSrcweir }
220cdf0e10cSrcweir // -------------------------------------------------------------------------
221