LibreOffice Module connectivity (master) 1
MacabResultSetMetaData.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
22#include "MacabHeader.hxx"
23#include "MacabRecords.hxx"
24#include "MacabAddressBook.hxx"
25#include "macabutilities.hxx"
27#include <strings.hrc>
28
29using namespace connectivity::macab;
30using namespace com::sun::star::uno;
31using namespace com::sun::star::lang;
32using namespace com::sun::star::sdbc;
33
34MacabResultSetMetaData::MacabResultSetMetaData(MacabConnection* _pConnection, OUString const & _sTableName)
35 : m_pConnection(_pConnection),
36 m_sTableName(_sTableName),
37 m_aMacabFields()
38{
39}
40
42{
43}
44
45void MacabResultSetMetaData::setMacabFields(const ::rtl::Reference<connectivity::OSQLColumns> &xColumns)
46{
47 static constexpr OUStringLiteral aName = u"Name";
48 MacabRecords *aRecords;
49 MacabHeader *aHeader;
50
52
53 // In case, somehow, we don't have anything with the name m_sTableName
54 if(aRecords == nullptr)
55 {
56 impl_throwError(STR_NO_TABLE);
57 }
58
59 aHeader = aRecords->getHeader();
60
61 for (const auto& rxColumn : *xColumns)
62 {
63 OUString aFieldName;
64 sal_uInt32 nFieldNumber;
65
66 rxColumn->getPropertyValue(aName) >>= aFieldName;
67 nFieldNumber = aHeader->getColumnNumber(aFieldName);
68 m_aMacabFields.push_back(nFieldNumber);
69 }
70
71}
72
73sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnDisplaySize(sal_Int32 /* column */)
74{
75 // For now, all columns are the same size.
76 return 50;
77}
78
79sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnType(sal_Int32 column)
80{
81 MacabRecords *aRecords;
82 MacabHeader *aHeader;
83 macabfield *aField;
84
86
87 // In case, somehow, we don't have anything with the name m_sTableName
88 if(aRecords == nullptr)
89 {
90 impl_throwError(STR_NO_TABLE);
91 }
92
93 aHeader = aRecords->getHeader();
94 aField = aHeader->get(column-1);
95
96 if(aField == nullptr)
97 {
99 return -1;
100 }
101
102 return ABTypeToDataType(aField->type);
103}
104
106{
107 return m_aMacabFields.size();
108}
109
111{
112 return true;
113}
114
115OUString SAL_CALL MacabResultSetMetaData::getSchemaName(sal_Int32)
116{
117 return OUString();
118}
119
120OUString SAL_CALL MacabResultSetMetaData::getColumnName(sal_Int32 column)
121{
122 sal_uInt32 nFieldNumber = m_aMacabFields[column - 1];
123 MacabRecords *aRecords;
124 MacabHeader *aHeader;
125
127
128 // In case, somehow, we don't have anything with the name m_sTableName
129 if(aRecords == nullptr)
130 {
131 impl_throwError(STR_NO_TABLE);
132 }
133
134 aHeader = aRecords->getHeader();
135 OUString aName = aHeader->getString(nFieldNumber);
136
137 return aName;
138}
139
140OUString SAL_CALL MacabResultSetMetaData::getTableName(sal_Int32)
141{
142 return m_sTableName;
143}
144
145OUString SAL_CALL MacabResultSetMetaData::getCatalogName(sal_Int32)
146{
147 return OUString();
148}
149
151{
152 return OUString();
153}
154
155OUString SAL_CALL MacabResultSetMetaData::getColumnLabel(sal_Int32)
156{
157 return OUString();
158}
159
161{
162 return OUString();
163}
164
166{
167 return false;
168}
169
171{
172 return false;
173}
174
176{
177 return false;
178}
179
180sal_Int32 SAL_CALL MacabResultSetMetaData::getPrecision(sal_Int32)
181{
182 return 0;
183}
184
185sal_Int32 SAL_CALL MacabResultSetMetaData::getScale(sal_Int32)
186{
187 return 0;
188}
189
190sal_Int32 SAL_CALL MacabResultSetMetaData::isNullable(sal_Int32)
191{
192 return sal_Int32(true);
193}
194
196{
197 return true;
198}
199
201{
202 return true;
203}
204
206{
207 return false;
208}
209
211{
212 return false;
213}
214
215
216/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString m_sTableName
MacabAddressBook * getAddressBook() const
sal_Int32 getColumnNumber(std::u16string_view s) const
OUString getString(const sal_Int32 i) const
macabfield * get(const sal_Int32 i) const
MacabHeader * getHeader() const
virtual sal_Bool SAL_CALL isAutoIncrement(sal_Int32 column) override
virtual sal_Bool SAL_CALL isSearchable(sal_Int32 column) override
virtual sal_Bool SAL_CALL isCurrency(sal_Int32 column) override
virtual OUString SAL_CALL getColumnTypeName(sal_Int32 column) override
virtual sal_Int32 SAL_CALL getColumnDisplaySize(sal_Int32 column) override
virtual sal_Int32 SAL_CALL getPrecision(sal_Int32 column) override
virtual OUString SAL_CALL getSchemaName(sal_Int32 column) override
virtual sal_Bool SAL_CALL isCaseSensitive(sal_Int32 column) override
virtual OUString SAL_CALL getColumnName(sal_Int32 column) override
virtual OUString SAL_CALL getCatalogName(sal_Int32 column) override
virtual sal_Bool SAL_CALL isSigned(sal_Int32 column) override
virtual OUString SAL_CALL getColumnServiceName(sal_Int32 column) override
virtual sal_Bool SAL_CALL isWritable(sal_Int32 column) override
virtual sal_Bool SAL_CALL isDefinitelyWritable(sal_Int32 column) override
virtual sal_Int32 SAL_CALL isNullable(sal_Int32 column) override
virtual sal_Int32 SAL_CALL getColumnType(sal_Int32 column) override
virtual OUString SAL_CALL getTableName(sal_Int32 column) override
virtual sal_Int32 SAL_CALL getColumnCount() override
virtual sal_Int32 SAL_CALL getScale(sal_Int32 column) override
virtual OUString SAL_CALL getColumnLabel(sal_Int32 column) override
virtual sal_Bool SAL_CALL isReadOnly(sal_Int32 column) override
void setMacabFields(const ::rtl::Reference< connectivity::OSQLColumns > &xColumns)
float u
OUString aName
sal_Int32 ABTypeToDataType(const ABPropertyType _abType)
void impl_throwError(TranslateId pErrorId)
void throwInvalidIndexException(const css::uno::Reference< css::uno::XInterface > &Context, const css::uno::Any &Next)
throw an invalid index sqlexception
unsigned char sal_Bool