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