xref: /AOO41X/main/connectivity/source/drivers/kab/KResultSetMetaData.cxx (revision 73d9b18ad12b526a229c2c5ca3fb0f85a41c2f42)
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 
37 KabResultSetMetaData::KabResultSetMetaData(KabConnection* _pConnection)
38 	: m_pConnection(_pConnection),
39 	  m_aKabFields()
40 {
41 }
42 // -------------------------------------------------------------------------
43 KabResultSetMetaData::~KabResultSetMetaData()
44 {
45 }
46 // -------------------------------------------------------------------------
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 // -------------------------------------------------------------------------
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 // -------------------------------------------------------------------------
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 // -------------------------------------------------------------------------
73 sal_Int32 SAL_CALL KabResultSetMetaData::getColumnCount() throw(SQLException, RuntimeException)
74 {
75 	return m_aKabFields.size();
76 }
77 // -------------------------------------------------------------------------
78 sal_Bool SAL_CALL KabResultSetMetaData::isCaseSensitive(sal_Int32) throw(SQLException, RuntimeException)
79 {
80 	return sal_True;
81 }
82 // -------------------------------------------------------------------------
83 ::rtl::OUString SAL_CALL KabResultSetMetaData::getSchemaName(sal_Int32) throw(SQLException, RuntimeException)
84 {
85 	return ::rtl::OUString();
86 }
87 // -------------------------------------------------------------------------
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 // -------------------------------------------------------------------------
107 ::rtl::OUString SAL_CALL KabResultSetMetaData::getTableName(sal_Int32) throw(SQLException, RuntimeException)
108 {
109 	return KabDatabaseMetaData::getAddressBookTableName();
110 }
111 // -------------------------------------------------------------------------
112 ::rtl::OUString SAL_CALL KabResultSetMetaData::getCatalogName(sal_Int32) throw(SQLException, RuntimeException)
113 {
114 	return ::rtl::OUString();
115 }
116 // -------------------------------------------------------------------------
117 ::rtl::OUString SAL_CALL KabResultSetMetaData::getColumnTypeName(sal_Int32) throw(SQLException, RuntimeException)
118 {
119 	return ::rtl::OUString();
120 }
121 // -------------------------------------------------------------------------
122 ::rtl::OUString SAL_CALL KabResultSetMetaData::getColumnLabel(sal_Int32) throw(SQLException, RuntimeException)
123 {
124 	return ::rtl::OUString();
125 }
126 // -------------------------------------------------------------------------
127 ::rtl::OUString SAL_CALL KabResultSetMetaData::getColumnServiceName(sal_Int32) throw(SQLException, RuntimeException)
128 {
129 	return ::rtl::OUString();
130 }
131 // -------------------------------------------------------------------------
132 sal_Bool SAL_CALL KabResultSetMetaData::isCurrency(sal_Int32) throw(SQLException, RuntimeException)
133 {
134 	return sal_False;
135 }
136 // -------------------------------------------------------------------------
137 sal_Bool SAL_CALL KabResultSetMetaData::isAutoIncrement(sal_Int32) throw(SQLException, RuntimeException)
138 {
139 	return sal_False;
140 }
141 // -------------------------------------------------------------------------
142 sal_Bool SAL_CALL KabResultSetMetaData::isSigned(sal_Int32) throw(SQLException, RuntimeException)
143 {
144 	return sal_False;
145 }
146 // -------------------------------------------------------------------------
147 sal_Int32 SAL_CALL KabResultSetMetaData::getPrecision(sal_Int32) throw(SQLException, RuntimeException)
148 {
149 	return 0;
150 }
151 // -----------------------------------------------------------------------------
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 // -------------------------------------------------------------------------
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 // -------------------------------------------------------------------------
164 sal_Bool SAL_CALL KabResultSetMetaData::isSearchable(sal_Int32) throw(SQLException, RuntimeException)
165 {
166 	return sal_True;
167 }
168 // -------------------------------------------------------------------------
169 sal_Bool SAL_CALL KabResultSetMetaData::isReadOnly(sal_Int32) throw(SQLException, RuntimeException)
170 {
171 	return sal_True;
172 }
173 // -------------------------------------------------------------------------
174 sal_Bool SAL_CALL KabResultSetMetaData::isDefinitelyWritable(sal_Int32) throw(SQLException, RuntimeException)
175 {
176 	return sal_False;
177 }
178 // -------------------------------------------------------------------------
179 sal_Bool SAL_CALL KabResultSetMetaData::isWritable(sal_Int32) throw(SQLException, RuntimeException)
180 {
181 	return sal_False;
182 }
183 // -------------------------------------------------------------------------
184