Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / macab / MacabResultSetMetaData.cxx
blob24cd1de03a131e7f7e026725e1b0d76bc9a37acd
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 "resource/macab_res.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) throw(SQLException)
46 OSQLColumns::Vector::const_iterator aIter;
47 static const OUString aName("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 == NULL)
56 impl_throwError(STR_NO_TABLE);
59 aHeader = aRecords->getHeader();
61 for (aIter = xColumns->get().begin(); aIter != xColumns->get().end(); ++aIter)
63 OUString aFieldName;
64 sal_uInt32 nFieldNumber;
66 (*aIter)->getPropertyValue(aName) >>= aFieldName;
67 nFieldNumber = aHeader->getColumnNumber(aFieldName);
68 m_aMacabFields.push_back(nFieldNumber);
73 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnDisplaySize(sal_Int32 /* column */) throw(SQLException, RuntimeException)
75 // For now, all columns are the same size.
76 return 50;
79 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnType(sal_Int32 column) throw(SQLException, RuntimeException)
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 == NULL)
90 impl_throwError(STR_NO_TABLE);
93 aHeader = aRecords->getHeader();
94 aField = aHeader->get(column-1);
96 if(aField == NULL)
98 ::dbtools::throwInvalidIndexException(*this,Any());
99 return -1;
102 return ABTypeToDataType(aField->type);
105 sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnCount() throw(SQLException, RuntimeException)
107 return m_aMacabFields.size();
110 sal_Bool SAL_CALL MacabResultSetMetaData::isCaseSensitive(sal_Int32) throw(SQLException, RuntimeException)
112 return sal_True;
115 OUString SAL_CALL MacabResultSetMetaData::getSchemaName(sal_Int32) throw(SQLException, RuntimeException)
117 return OUString();
120 OUString SAL_CALL MacabResultSetMetaData::getColumnName(sal_Int32 column) throw(SQLException, RuntimeException)
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 == NULL)
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) throw(SQLException, RuntimeException)
142 return m_sTableName;
145 OUString SAL_CALL MacabResultSetMetaData::getCatalogName(sal_Int32) throw(SQLException, RuntimeException)
147 return OUString();
150 OUString SAL_CALL MacabResultSetMetaData::getColumnTypeName(sal_Int32) throw(SQLException, RuntimeException)
152 return OUString();
155 OUString SAL_CALL MacabResultSetMetaData::getColumnLabel(sal_Int32) throw(SQLException, RuntimeException)
157 return OUString();
160 OUString SAL_CALL MacabResultSetMetaData::getColumnServiceName(sal_Int32) throw(SQLException, RuntimeException)
162 return OUString();
165 sal_Bool SAL_CALL MacabResultSetMetaData::isCurrency(sal_Int32) throw(SQLException, RuntimeException)
167 return sal_False;
170 sal_Bool SAL_CALL MacabResultSetMetaData::isAutoIncrement(sal_Int32) throw(SQLException, RuntimeException)
172 return sal_False;
175 sal_Bool SAL_CALL MacabResultSetMetaData::isSigned(sal_Int32) throw(SQLException, RuntimeException)
177 return sal_False;
180 sal_Int32 SAL_CALL MacabResultSetMetaData::getPrecision(sal_Int32) throw(SQLException, RuntimeException)
182 return 0;
185 sal_Int32 SAL_CALL MacabResultSetMetaData::getScale(sal_Int32) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
187 return 0;
190 sal_Int32 SAL_CALL MacabResultSetMetaData::isNullable(sal_Int32) throw(SQLException, RuntimeException)
192 return (sal_Int32) sal_True;
195 sal_Bool SAL_CALL MacabResultSetMetaData::isSearchable(sal_Int32) throw(SQLException, RuntimeException)
197 return sal_True;
200 sal_Bool SAL_CALL MacabResultSetMetaData::isReadOnly(sal_Int32) throw(SQLException, RuntimeException)
202 return sal_True;
205 sal_Bool SAL_CALL MacabResultSetMetaData::isDefinitelyWritable(sal_Int32) throw(SQLException, RuntimeException)
207 return sal_False;
210 sal_Bool SAL_CALL MacabResultSetMetaData::isWritable(sal_Int32) throw(SQLException, RuntimeException)
212 return sal_False;
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */