1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
),
41 MacabResultSetMetaData::~MacabResultSetMetaData()
45 void MacabResultSetMetaData::setMacabFields(const ::rtl::Reference
<connectivity::OSQLColumns
> &xColumns
)
47 static constexpr OUStringLiteral aName
= u
"Name";
48 MacabRecords
*aRecords
;
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
)
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.
79 sal_Int32 SAL_CALL
MacabResultSetMetaData::getColumnType(sal_Int32 column
)
81 MacabRecords
*aRecords
;
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);
98 ::dbtools::throwInvalidIndexException(*this);
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
)
115 OUString SAL_CALL
MacabResultSetMetaData::getSchemaName(sal_Int32
)
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
);
140 OUString SAL_CALL
MacabResultSetMetaData::getTableName(sal_Int32
)
145 OUString SAL_CALL
MacabResultSetMetaData::getCatalogName(sal_Int32
)
150 OUString SAL_CALL
MacabResultSetMetaData::getColumnTypeName(sal_Int32
)
155 OUString SAL_CALL
MacabResultSetMetaData::getColumnLabel(sal_Int32
)
160 OUString SAL_CALL
MacabResultSetMetaData::getColumnServiceName(sal_Int32
)
165 sal_Bool SAL_CALL
MacabResultSetMetaData::isCurrency(sal_Int32
)
170 sal_Bool SAL_CALL
MacabResultSetMetaData::isAutoIncrement(sal_Int32
)
175 sal_Bool SAL_CALL
MacabResultSetMetaData::isSigned(sal_Int32
)
180 sal_Int32 SAL_CALL
MacabResultSetMetaData::getPrecision(sal_Int32
)
185 sal_Int32 SAL_CALL
MacabResultSetMetaData::getScale(sal_Int32
)
190 sal_Int32 SAL_CALL
MacabResultSetMetaData::isNullable(sal_Int32
)
192 return sal_Int32(true);
195 sal_Bool SAL_CALL
MacabResultSetMetaData::isSearchable(sal_Int32
)
200 sal_Bool SAL_CALL
MacabResultSetMetaData::isReadOnly(sal_Int32
)
205 sal_Bool SAL_CALL
MacabResultSetMetaData::isDefinitelyWritable(sal_Int32
)
210 sal_Bool SAL_CALL
MacabResultSetMetaData::isWritable(sal_Int32
)
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */