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 "KResultSetMetaData.hxx"
28cdf0e10cSrcweir #include "kfields.hxx"
29cdf0e10cSrcweir #include "KDatabaseMetaData.hxx"
30cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace connectivity::kab;
33cdf0e10cSrcweir using namespace com::sun::star::uno;
34cdf0e10cSrcweir using namespace com::sun::star::lang;
35cdf0e10cSrcweir using namespace com::sun::star::sdbc;
36cdf0e10cSrcweir 
KabResultSetMetaData(KabConnection * _pConnection)37cdf0e10cSrcweir KabResultSetMetaData::KabResultSetMetaData(KabConnection* _pConnection)
38cdf0e10cSrcweir 	: m_pConnection(_pConnection),
39cdf0e10cSrcweir 	  m_aKabFields()
40cdf0e10cSrcweir {
41cdf0e10cSrcweir }
42cdf0e10cSrcweir // -------------------------------------------------------------------------
~KabResultSetMetaData()43cdf0e10cSrcweir KabResultSetMetaData::~KabResultSetMetaData()
44cdf0e10cSrcweir {
45cdf0e10cSrcweir }
46cdf0e10cSrcweir // -------------------------------------------------------------------------
setKabFields(const::vos::ORef<connectivity::OSQLColumns> & xColumns)47cdf0e10cSrcweir void KabResultSetMetaData::setKabFields(const ::vos::ORef<connectivity::OSQLColumns> &xColumns) throw(SQLException)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir 	OSQLColumns::Vector::const_iterator aIter;
50cdf0e10cSrcweir 	static const ::rtl::OUString aName(::rtl::OUString::createFromAscii("Name"));
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 	for (aIter = xColumns->get().begin(); aIter != xColumns->get().end(); ++aIter)
53cdf0e10cSrcweir 	{
54cdf0e10cSrcweir 		::rtl::OUString aFieldName;
55cdf0e10cSrcweir 		sal_uInt32 nFieldNumber;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 		(*aIter)->getPropertyValue(aName) >>= aFieldName;
58cdf0e10cSrcweir 		nFieldNumber = findKabField(aFieldName);
59cdf0e10cSrcweir 		m_aKabFields.push_back(nFieldNumber);
60cdf0e10cSrcweir 	}
61cdf0e10cSrcweir }
62cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnDisplaySize(sal_Int32 column)63cdf0e10cSrcweir sal_Int32 SAL_CALL KabResultSetMetaData::getColumnDisplaySize(sal_Int32 column) throw(SQLException, RuntimeException)
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	return m_aKabFields[column - 1] < KAB_DATA_FIELDS? 20: 50;
66cdf0e10cSrcweir }
67cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnType(sal_Int32 column)68cdf0e10cSrcweir sal_Int32 SAL_CALL KabResultSetMetaData::getColumnType(sal_Int32 column) throw(SQLException, RuntimeException)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	return m_aKabFields[column - 1] == KAB_FIELD_REVISION? DataType::TIMESTAMP: DataType::CHAR;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnCount()73cdf0e10cSrcweir sal_Int32 SAL_CALL KabResultSetMetaData::getColumnCount() throw(SQLException, RuntimeException)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	return m_aKabFields.size();
76cdf0e10cSrcweir }
77cdf0e10cSrcweir // -------------------------------------------------------------------------
isCaseSensitive(sal_Int32)78cdf0e10cSrcweir sal_Bool SAL_CALL KabResultSetMetaData::isCaseSensitive(sal_Int32) throw(SQLException, RuntimeException)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	return sal_True;
81cdf0e10cSrcweir }
82cdf0e10cSrcweir // -------------------------------------------------------------------------
getSchemaName(sal_Int32)83cdf0e10cSrcweir ::rtl::OUString SAL_CALL KabResultSetMetaData::getSchemaName(sal_Int32) throw(SQLException, RuntimeException)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir 	return ::rtl::OUString();
86cdf0e10cSrcweir }
87cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnName(sal_Int32 column)88cdf0e10cSrcweir ::rtl::OUString SAL_CALL KabResultSetMetaData::getColumnName(sal_Int32 column) throw(SQLException, RuntimeException)
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	sal_uInt32 nFieldNumber = m_aKabFields[column - 1];
91cdf0e10cSrcweir 	::KABC::Field::List aFields = ::KABC::Field::allFields();
92cdf0e10cSrcweir 	QString aQtName;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	switch (nFieldNumber)
95cdf0e10cSrcweir 	{
96cdf0e10cSrcweir 		case KAB_FIELD_REVISION:
97cdf0e10cSrcweir 			aQtName = KABC::Addressee::revisionLabel();
98cdf0e10cSrcweir 			break;
99cdf0e10cSrcweir 		default:
100cdf0e10cSrcweir 			aQtName = aFields[nFieldNumber - KAB_DATA_FIELDS]->label();
101cdf0e10cSrcweir 	}
102cdf0e10cSrcweir 	::rtl::OUString aName((const sal_Unicode *) aQtName.ucs2());
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	return aName;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir // -------------------------------------------------------------------------
getTableName(sal_Int32)107cdf0e10cSrcweir ::rtl::OUString SAL_CALL KabResultSetMetaData::getTableName(sal_Int32) throw(SQLException, RuntimeException)
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	return KabDatabaseMetaData::getAddressBookTableName();
110cdf0e10cSrcweir }
111cdf0e10cSrcweir // -------------------------------------------------------------------------
getCatalogName(sal_Int32)112cdf0e10cSrcweir ::rtl::OUString SAL_CALL KabResultSetMetaData::getCatalogName(sal_Int32) throw(SQLException, RuntimeException)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir 	return ::rtl::OUString();
115cdf0e10cSrcweir }
116cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnTypeName(sal_Int32)117cdf0e10cSrcweir ::rtl::OUString SAL_CALL KabResultSetMetaData::getColumnTypeName(sal_Int32) throw(SQLException, RuntimeException)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir 	return ::rtl::OUString();
120cdf0e10cSrcweir }
121cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnLabel(sal_Int32)122cdf0e10cSrcweir ::rtl::OUString SAL_CALL KabResultSetMetaData::getColumnLabel(sal_Int32) throw(SQLException, RuntimeException)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir 	return ::rtl::OUString();
125cdf0e10cSrcweir }
126cdf0e10cSrcweir // -------------------------------------------------------------------------
getColumnServiceName(sal_Int32)127cdf0e10cSrcweir ::rtl::OUString SAL_CALL KabResultSetMetaData::getColumnServiceName(sal_Int32) throw(SQLException, RuntimeException)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	return ::rtl::OUString();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir // -------------------------------------------------------------------------
isCurrency(sal_Int32)132cdf0e10cSrcweir sal_Bool SAL_CALL KabResultSetMetaData::isCurrency(sal_Int32) throw(SQLException, RuntimeException)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	return sal_False;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir // -------------------------------------------------------------------------
isAutoIncrement(sal_Int32)137cdf0e10cSrcweir sal_Bool SAL_CALL KabResultSetMetaData::isAutoIncrement(sal_Int32) throw(SQLException, RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir 	return sal_False;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir // -------------------------------------------------------------------------
isSigned(sal_Int32)142cdf0e10cSrcweir sal_Bool SAL_CALL KabResultSetMetaData::isSigned(sal_Int32) throw(SQLException, RuntimeException)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	return sal_False;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir // -------------------------------------------------------------------------
getPrecision(sal_Int32)147cdf0e10cSrcweir sal_Int32 SAL_CALL KabResultSetMetaData::getPrecision(sal_Int32) throw(SQLException, RuntimeException)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	return 0;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir // -----------------------------------------------------------------------------
getScale(sal_Int32)152cdf0e10cSrcweir sal_Int32 SAL_CALL KabResultSetMetaData::getScale(sal_Int32) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
153cdf0e10cSrcweir {
154cdf0e10cSrcweir 	return 0;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir // -------------------------------------------------------------------------
isNullable(sal_Int32)157cdf0e10cSrcweir sal_Int32 SAL_CALL KabResultSetMetaData::isNullable(sal_Int32) throw(SQLException, RuntimeException)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	return (sal_Int32) sal_True;
160cdf0e10cSrcweir // KDE address book currently does not use NULL values.
161cdf0e10cSrcweir // But it might do it someday
162cdf0e10cSrcweir }
163cdf0e10cSrcweir // -------------------------------------------------------------------------
isSearchable(sal_Int32)164cdf0e10cSrcweir sal_Bool SAL_CALL KabResultSetMetaData::isSearchable(sal_Int32) throw(SQLException, RuntimeException)
165cdf0e10cSrcweir {
166cdf0e10cSrcweir 	return sal_True;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir // -------------------------------------------------------------------------
isReadOnly(sal_Int32)169cdf0e10cSrcweir sal_Bool SAL_CALL KabResultSetMetaData::isReadOnly(sal_Int32) throw(SQLException, RuntimeException)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir 	return sal_True;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir // -------------------------------------------------------------------------
isDefinitelyWritable(sal_Int32)174cdf0e10cSrcweir sal_Bool SAL_CALL KabResultSetMetaData::isDefinitelyWritable(sal_Int32) throw(SQLException, RuntimeException)
175cdf0e10cSrcweir {
176cdf0e10cSrcweir 	return sal_False;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir // -------------------------------------------------------------------------
isWritable(sal_Int32)179cdf0e10cSrcweir sal_Bool SAL_CALL KabResultSetMetaData::isWritable(sal_Int32) throw(SQLException, RuntimeException)
180cdf0e10cSrcweir {
181cdf0e10cSrcweir 	return sal_False;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir // -------------------------------------------------------------------------
184