xref: /AOO41X/main/connectivity/source/drivers/kab/KResultSetMetaData.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 
31 #include "KResultSetMetaData.hxx"
32 #include "kfields.hxx"
33 #include "KDatabaseMetaData.hxx"
34 #include <com/sun/star/sdbc/DataType.hpp>
35 
36 using namespace connectivity::kab;
37 using namespace com::sun::star::uno;
38 using namespace com::sun::star::lang;
39 using namespace com::sun::star::sdbc;
40 
41 KabResultSetMetaData::KabResultSetMetaData(KabConnection* _pConnection)
42     : m_pConnection(_pConnection),
43       m_aKabFields()
44 {
45 }
46 // -------------------------------------------------------------------------
47 KabResultSetMetaData::~KabResultSetMetaData()
48 {
49 }
50 // -------------------------------------------------------------------------
51 void KabResultSetMetaData::setKabFields(const ::vos::ORef<connectivity::OSQLColumns> &xColumns) throw(SQLException)
52 {
53     OSQLColumns::Vector::const_iterator aIter;
54     static const ::rtl::OUString aName(::rtl::OUString::createFromAscii("Name"));
55 
56     for (aIter = xColumns->get().begin(); aIter != xColumns->get().end(); ++aIter)
57     {
58         ::rtl::OUString aFieldName;
59         sal_uInt32 nFieldNumber;
60 
61         (*aIter)->getPropertyValue(aName) >>= aFieldName;
62         nFieldNumber = findKabField(aFieldName);
63         m_aKabFields.push_back(nFieldNumber);
64     }
65 }
66 // -------------------------------------------------------------------------
67 sal_Int32 SAL_CALL KabResultSetMetaData::getColumnDisplaySize(sal_Int32 column) throw(SQLException, RuntimeException)
68 {
69     return m_aKabFields[column - 1] < KAB_DATA_FIELDS? 20: 50;
70 }
71 // -------------------------------------------------------------------------
72 sal_Int32 SAL_CALL KabResultSetMetaData::getColumnType(sal_Int32 column) throw(SQLException, RuntimeException)
73 {
74     return m_aKabFields[column - 1] == KAB_FIELD_REVISION? DataType::TIMESTAMP: DataType::CHAR;
75 }
76 // -------------------------------------------------------------------------
77 sal_Int32 SAL_CALL KabResultSetMetaData::getColumnCount() throw(SQLException, RuntimeException)
78 {
79     return m_aKabFields.size();
80 }
81 // -------------------------------------------------------------------------
82 sal_Bool SAL_CALL KabResultSetMetaData::isCaseSensitive(sal_Int32) throw(SQLException, RuntimeException)
83 {
84     return sal_True;
85 }
86 // -------------------------------------------------------------------------
87 ::rtl::OUString SAL_CALL KabResultSetMetaData::getSchemaName(sal_Int32) throw(SQLException, RuntimeException)
88 {
89     return ::rtl::OUString();
90 }
91 // -------------------------------------------------------------------------
92 ::rtl::OUString SAL_CALL KabResultSetMetaData::getColumnName(sal_Int32 column) throw(SQLException, RuntimeException)
93 {
94     sal_uInt32 nFieldNumber = m_aKabFields[column - 1];
95     ::KABC::Field::List aFields = ::KABC::Field::allFields();
96     QString aQtName;
97 
98     switch (nFieldNumber)
99     {
100         case KAB_FIELD_REVISION:
101             aQtName = KABC::Addressee::revisionLabel();
102             break;
103         default:
104             aQtName = aFields[nFieldNumber - KAB_DATA_FIELDS]->label();
105     }
106     ::rtl::OUString aName((const sal_Unicode *) aQtName.ucs2());
107 
108     return aName;
109 }
110 // -------------------------------------------------------------------------
111 ::rtl::OUString SAL_CALL KabResultSetMetaData::getTableName(sal_Int32) throw(SQLException, RuntimeException)
112 {
113     return KabDatabaseMetaData::getAddressBookTableName();
114 }
115 // -------------------------------------------------------------------------
116 ::rtl::OUString SAL_CALL KabResultSetMetaData::getCatalogName(sal_Int32) throw(SQLException, RuntimeException)
117 {
118     return ::rtl::OUString();
119 }
120 // -------------------------------------------------------------------------
121 ::rtl::OUString SAL_CALL KabResultSetMetaData::getColumnTypeName(sal_Int32) throw(SQLException, RuntimeException)
122 {
123     return ::rtl::OUString();
124 }
125 // -------------------------------------------------------------------------
126 ::rtl::OUString SAL_CALL KabResultSetMetaData::getColumnLabel(sal_Int32) throw(SQLException, RuntimeException)
127 {
128     return ::rtl::OUString();
129 }
130 // -------------------------------------------------------------------------
131 ::rtl::OUString SAL_CALL KabResultSetMetaData::getColumnServiceName(sal_Int32) throw(SQLException, RuntimeException)
132 {
133     return ::rtl::OUString();
134 }
135 // -------------------------------------------------------------------------
136 sal_Bool SAL_CALL KabResultSetMetaData::isCurrency(sal_Int32) throw(SQLException, RuntimeException)
137 {
138     return sal_False;
139 }
140 // -------------------------------------------------------------------------
141 sal_Bool SAL_CALL KabResultSetMetaData::isAutoIncrement(sal_Int32) throw(SQLException, RuntimeException)
142 {
143     return sal_False;
144 }
145 // -------------------------------------------------------------------------
146 sal_Bool SAL_CALL KabResultSetMetaData::isSigned(sal_Int32) throw(SQLException, RuntimeException)
147 {
148     return sal_False;
149 }
150 // -------------------------------------------------------------------------
151 sal_Int32 SAL_CALL KabResultSetMetaData::getPrecision(sal_Int32) throw(SQLException, RuntimeException)
152 {
153     return 0;
154 }
155 // -----------------------------------------------------------------------------
156 sal_Int32 SAL_CALL KabResultSetMetaData::getScale(sal_Int32) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
157 {
158     return 0;
159 }
160 // -------------------------------------------------------------------------
161 sal_Int32 SAL_CALL KabResultSetMetaData::isNullable(sal_Int32) throw(SQLException, RuntimeException)
162 {
163     return (sal_Int32) sal_True;
164 // KDE address book currently does not use NULL values.
165 // But it might do it someday
166 }
167 // -------------------------------------------------------------------------
168 sal_Bool SAL_CALL KabResultSetMetaData::isSearchable(sal_Int32) throw(SQLException, RuntimeException)
169 {
170     return sal_True;
171 }
172 // -------------------------------------------------------------------------
173 sal_Bool SAL_CALL KabResultSetMetaData::isReadOnly(sal_Int32) throw(SQLException, RuntimeException)
174 {
175     return sal_True;
176 }
177 // -------------------------------------------------------------------------
178 sal_Bool SAL_CALL KabResultSetMetaData::isDefinitelyWritable(sal_Int32) throw(SQLException, RuntimeException)
179 {
180     return sal_False;
181 }
182 // -------------------------------------------------------------------------
183 sal_Bool SAL_CALL KabResultSetMetaData::isWritable(sal_Int32) throw(SQLException, RuntimeException)
184 {
185     return sal_False;
186 }
187 // -------------------------------------------------------------------------
188