bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / macab / MacabResultSetMetaData.cxx
blobd0ed7298f92bd221d19d9141166f66bd32aa824a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "MacabResultSetMetaData.hxx"
22 #include "MacabHeader.hxx"
23 #include "MacabRecords.hxx"
24 #include "MacabAddressBook.hxx"
25 #include "macabutilities.hxx"
26 #include <strings.hrc>
28 using namespace connectivity::macab;
29 using namespace com::sun::star::uno;
30 using namespace com::sun::star::lang;
31 using namespace com::sun::star::sdbc;
33 MacabResultSetMetaData::MacabResultSetMetaData(MacabConnection* _pConnection, OUString const & _sTableName)
34 : m_pConnection(_pConnection),
35 m_sTableName(_sTableName),
36 m_aMacabFields()
40 MacabResultSetMetaData::~MacabResultSetMetaData()
44 void MacabResultSetMetaData::setMacabFields(const ::rtl::Reference<connectivity::OSQLColumns> &xColumns)
46 static constexpr OUStringLiteral aName = u"Name";
47 MacabRecords *aRecords;
48 MacabHeader *aHeader;
50 aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
52 // In case, somehow, we don't have anything with the name m_sTableName
53 if(aRecords == nullptr)
55 impl_throwError(STR_NO_TABLE);
58 aHeader = aRecords->getHeader();
60 for (const auto& rxColumn : *xColumns)
62 OUString aFieldName;
63 sal_uInt32 nFieldNumber;
65 rxColumn->getPropertyValue(aName) >>= aFieldName;
66 nFieldNumber = aHeader->getColumnNumber(aFieldName);
67 m_aMacabFields.push_back(nFieldNumber);
72 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnDisplaySize(sal_Int32 /* column */)
74 // For now, all columns are the same size.
75 return 50;
78 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnType(sal_Int32 column)
80 MacabRecords *aRecords;
81 MacabHeader *aHeader;
82 macabfield *aField;
84 aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
86 // In case, somehow, we don't have anything with the name m_sTableName
87 if(aRecords == nullptr)
89 impl_throwError(STR_NO_TABLE);
92 aHeader = aRecords->getHeader();
93 aField = aHeader->get(column-1);
95 if(aField == nullptr)
97 ::dbtools::throwInvalidIndexException(*this);
98 return -1;
101 return ABTypeToDataType(aField->type);
104 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnCount()
106 return m_aMacabFields.size();
109 sal_Bool SAL_CALL MacabResultSetMetaData::isCaseSensitive(sal_Int32)
111 return true;
114 OUString SAL_CALL MacabResultSetMetaData::getSchemaName(sal_Int32)
116 return OUString();
119 OUString SAL_CALL MacabResultSetMetaData::getColumnName(sal_Int32 column)
121 sal_uInt32 nFieldNumber = m_aMacabFields[column - 1];
122 MacabRecords *aRecords;
123 MacabHeader *aHeader;
125 aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
127 // In case, somehow, we don't have anything with the name m_sTableName
128 if(aRecords == nullptr)
130 impl_throwError(STR_NO_TABLE);
133 aHeader = aRecords->getHeader();
134 OUString aName = aHeader->getString(nFieldNumber);
136 return aName;
139 OUString SAL_CALL MacabResultSetMetaData::getTableName(sal_Int32)
141 return m_sTableName;
144 OUString SAL_CALL MacabResultSetMetaData::getCatalogName(sal_Int32)
146 return OUString();
149 OUString SAL_CALL MacabResultSetMetaData::getColumnTypeName(sal_Int32)
151 return OUString();
154 OUString SAL_CALL MacabResultSetMetaData::getColumnLabel(sal_Int32)
156 return OUString();
159 OUString SAL_CALL MacabResultSetMetaData::getColumnServiceName(sal_Int32)
161 return OUString();
164 sal_Bool SAL_CALL MacabResultSetMetaData::isCurrency(sal_Int32)
166 return false;
169 sal_Bool SAL_CALL MacabResultSetMetaData::isAutoIncrement(sal_Int32)
171 return false;
174 sal_Bool SAL_CALL MacabResultSetMetaData::isSigned(sal_Int32)
176 return false;
179 sal_Int32 SAL_CALL MacabResultSetMetaData::getPrecision(sal_Int32)
181 return 0;
184 sal_Int32 SAL_CALL MacabResultSetMetaData::getScale(sal_Int32)
186 return 0;
189 sal_Int32 SAL_CALL MacabResultSetMetaData::isNullable(sal_Int32)
191 return sal_Int32(true);
194 sal_Bool SAL_CALL MacabResultSetMetaData::isSearchable(sal_Int32)
196 return true;
199 sal_Bool SAL_CALL MacabResultSetMetaData::isReadOnly(sal_Int32)
201 return true;
204 sal_Bool SAL_CALL MacabResultSetMetaData::isDefinitelyWritable(sal_Int32)
206 return false;
209 sal_Bool SAL_CALL MacabResultSetMetaData::isWritable(sal_Int32)
211 return false;
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */