Use correct object
[LibreOffice.git] / connectivity / source / drivers / macab / MacabResultSetMetaData.cxx
blobe08d92cfceb6a762c3a99c06d84e83931ae8500d
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 <connectivity/dbexception.hxx>
27 #include <strings.hrc>
29 using namespace connectivity::macab;
30 using namespace com::sun::star::uno;
31 using namespace com::sun::star::lang;
32 using namespace com::sun::star::sdbc;
34 MacabResultSetMetaData::MacabResultSetMetaData(MacabConnection* _pConnection, OUString const & _sTableName)
35 : m_pConnection(_pConnection),
36 m_sTableName(_sTableName),
37 m_aMacabFields()
41 MacabResultSetMetaData::~MacabResultSetMetaData()
45 void MacabResultSetMetaData::setMacabFields(const ::rtl::Reference<connectivity::OSQLColumns> &xColumns)
47 static constexpr OUStringLiteral aName = u"Name";
48 MacabRecords *aRecords;
49 MacabHeader *aHeader;
51 aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
53 // In case, somehow, we don't have anything with the name m_sTableName
54 if(aRecords == nullptr)
56 impl_throwError(STR_NO_TABLE);
59 aHeader = aRecords->getHeader();
61 for (const auto& rxColumn : *xColumns)
63 OUString aFieldName;
64 sal_uInt32 nFieldNumber;
66 rxColumn->getPropertyValue(aName) >>= aFieldName;
67 nFieldNumber = aHeader->getColumnNumber(aFieldName);
68 m_aMacabFields.push_back(nFieldNumber);
73 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnDisplaySize(sal_Int32 /* column */)
75 // For now, all columns are the same size.
76 return 50;
79 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnType(sal_Int32 column)
81 MacabRecords *aRecords;
82 MacabHeader *aHeader;
83 macabfield *aField;
85 aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
87 // In case, somehow, we don't have anything with the name m_sTableName
88 if(aRecords == nullptr)
90 impl_throwError(STR_NO_TABLE);
93 aHeader = aRecords->getHeader();
94 aField = aHeader->get(column-1);
96 if(aField == nullptr)
98 ::dbtools::throwInvalidIndexException(*this);
99 return -1;
102 return ABTypeToDataType(aField->type);
105 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnCount()
107 return m_aMacabFields.size();
110 sal_Bool SAL_CALL MacabResultSetMetaData::isCaseSensitive(sal_Int32)
112 return true;
115 OUString SAL_CALL MacabResultSetMetaData::getSchemaName(sal_Int32)
117 return OUString();
120 OUString SAL_CALL MacabResultSetMetaData::getColumnName(sal_Int32 column)
122 sal_uInt32 nFieldNumber = m_aMacabFields[column - 1];
123 MacabRecords *aRecords;
124 MacabHeader *aHeader;
126 aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName);
128 // In case, somehow, we don't have anything with the name m_sTableName
129 if(aRecords == nullptr)
131 impl_throwError(STR_NO_TABLE);
134 aHeader = aRecords->getHeader();
135 OUString aName = aHeader->getString(nFieldNumber);
137 return aName;
140 OUString SAL_CALL MacabResultSetMetaData::getTableName(sal_Int32)
142 return m_sTableName;
145 OUString SAL_CALL MacabResultSetMetaData::getCatalogName(sal_Int32)
147 return OUString();
150 OUString SAL_CALL MacabResultSetMetaData::getColumnTypeName(sal_Int32)
152 return OUString();
155 OUString SAL_CALL MacabResultSetMetaData::getColumnLabel(sal_Int32)
157 return OUString();
160 OUString SAL_CALL MacabResultSetMetaData::getColumnServiceName(sal_Int32)
162 return OUString();
165 sal_Bool SAL_CALL MacabResultSetMetaData::isCurrency(sal_Int32)
167 return false;
170 sal_Bool SAL_CALL MacabResultSetMetaData::isAutoIncrement(sal_Int32)
172 return false;
175 sal_Bool SAL_CALL MacabResultSetMetaData::isSigned(sal_Int32)
177 return false;
180 sal_Int32 SAL_CALL MacabResultSetMetaData::getPrecision(sal_Int32)
182 return 0;
185 sal_Int32 SAL_CALL MacabResultSetMetaData::getScale(sal_Int32)
187 return 0;
190 sal_Int32 SAL_CALL MacabResultSetMetaData::isNullable(sal_Int32)
192 return sal_Int32(true);
195 sal_Bool SAL_CALL MacabResultSetMetaData::isSearchable(sal_Int32)
197 return true;
200 sal_Bool SAL_CALL MacabResultSetMetaData::isReadOnly(sal_Int32)
202 return true;
205 sal_Bool SAL_CALL MacabResultSetMetaData::isDefinitelyWritable(sal_Int32)
207 return false;
210 sal_Bool SAL_CALL MacabResultSetMetaData::isWritable(sal_Int32)
212 return false;
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */