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 <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
),
40 MacabResultSetMetaData::~MacabResultSetMetaData()
44 void MacabResultSetMetaData::setMacabFields(const ::rtl::Reference
<connectivity::OSQLColumns
> &xColumns
)
46 static constexpr OUStringLiteral aName
= u
"Name";
47 MacabRecords
*aRecords
;
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
)
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.
78 sal_Int32 SAL_CALL
MacabResultSetMetaData::getColumnType(sal_Int32 column
)
80 MacabRecords
*aRecords
;
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);
97 ::dbtools::throwInvalidIndexException(*this);
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
)
114 OUString SAL_CALL
MacabResultSetMetaData::getSchemaName(sal_Int32
)
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
);
139 OUString SAL_CALL
MacabResultSetMetaData::getTableName(sal_Int32
)
144 OUString SAL_CALL
MacabResultSetMetaData::getCatalogName(sal_Int32
)
149 OUString SAL_CALL
MacabResultSetMetaData::getColumnTypeName(sal_Int32
)
154 OUString SAL_CALL
MacabResultSetMetaData::getColumnLabel(sal_Int32
)
159 OUString SAL_CALL
MacabResultSetMetaData::getColumnServiceName(sal_Int32
)
164 sal_Bool SAL_CALL
MacabResultSetMetaData::isCurrency(sal_Int32
)
169 sal_Bool SAL_CALL
MacabResultSetMetaData::isAutoIncrement(sal_Int32
)
174 sal_Bool SAL_CALL
MacabResultSetMetaData::isSigned(sal_Int32
)
179 sal_Int32 SAL_CALL
MacabResultSetMetaData::getPrecision(sal_Int32
)
184 sal_Int32 SAL_CALL
MacabResultSetMetaData::getScale(sal_Int32
)
189 sal_Int32 SAL_CALL
MacabResultSetMetaData::isNullable(sal_Int32
)
191 return sal_Int32(true);
194 sal_Bool SAL_CALL
MacabResultSetMetaData::isSearchable(sal_Int32
)
199 sal_Bool SAL_CALL
MacabResultSetMetaData::isReadOnly(sal_Int32
)
204 sal_Bool SAL_CALL
MacabResultSetMetaData::isDefinitelyWritable(sal_Int32
)
209 sal_Bool SAL_CALL
MacabResultSetMetaData::isWritable(sal_Int32
)
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */