1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "MacabResultSetMetaData.hxx" 32*cdf0e10cSrcweir #include "MacabHeader.hxx" 33*cdf0e10cSrcweir #include "MacabRecords.hxx" 34*cdf0e10cSrcweir #include "MacabAddressBook.hxx" 35*cdf0e10cSrcweir #include "macabutilities.hxx" 36*cdf0e10cSrcweir #include "resource/macab_res.hrc" 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir using namespace connectivity::macab; 39*cdf0e10cSrcweir using namespace com::sun::star::uno; 40*cdf0e10cSrcweir using namespace com::sun::star::lang; 41*cdf0e10cSrcweir using namespace com::sun::star::sdbc; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir MacabResultSetMetaData::MacabResultSetMetaData(MacabConnection* _pConnection, ::rtl::OUString _sTableName) 44*cdf0e10cSrcweir : m_pConnection(_pConnection), 45*cdf0e10cSrcweir m_sTableName(_sTableName), 46*cdf0e10cSrcweir m_aMacabFields() 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir } 49*cdf0e10cSrcweir // ------------------------------------------------------------------------- 50*cdf0e10cSrcweir MacabResultSetMetaData::~MacabResultSetMetaData() 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir } 53*cdf0e10cSrcweir // ------------------------------------------------------------------------- 54*cdf0e10cSrcweir void MacabResultSetMetaData::setMacabFields(const ::vos::ORef<connectivity::OSQLColumns> &xColumns) throw(SQLException) 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir OSQLColumns::Vector::const_iterator aIter; 57*cdf0e10cSrcweir static const ::rtl::OUString aName(::rtl::OUString::createFromAscii("Name")); 58*cdf0e10cSrcweir MacabRecords *aRecords; 59*cdf0e10cSrcweir MacabHeader *aHeader; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir // In case, somehow, we don't have anything with the name m_sTableName 64*cdf0e10cSrcweir if(aRecords == NULL) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir impl_throwError(STR_NO_TABLE); 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir aHeader = aRecords->getHeader(); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir for (aIter = xColumns->get().begin(); aIter != xColumns->get().end(); ++aIter) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir ::rtl::OUString aFieldName; 74*cdf0e10cSrcweir sal_uInt32 nFieldNumber; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir (*aIter)->getPropertyValue(aName) >>= aFieldName; 77*cdf0e10cSrcweir nFieldNumber = aHeader->getColumnNumber(aFieldName); 78*cdf0e10cSrcweir m_aMacabFields.push_back(nFieldNumber); 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir // ------------------------------------------------------------------------- 83*cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnDisplaySize(sal_Int32 column) throw(SQLException, RuntimeException) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir // For now, all columns are the same size. 86*cdf0e10cSrcweir return 50; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir // ------------------------------------------------------------------------- 89*cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnType(sal_Int32 column) throw(SQLException, RuntimeException) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir MacabRecords *aRecords; 92*cdf0e10cSrcweir MacabHeader *aHeader; 93*cdf0e10cSrcweir macabfield *aField; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // In case, somehow, we don't have anything with the name m_sTableName 98*cdf0e10cSrcweir if(aRecords == NULL) 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir impl_throwError(STR_NO_TABLE); 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir aHeader = aRecords->getHeader(); 104*cdf0e10cSrcweir aField = aHeader->get(column-1); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir if(aField == NULL) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir ::dbtools::throwInvalidIndexException(*this,Any()); 109*cdf0e10cSrcweir return -1; 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir return ABTypeToDataType(aField->type); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir // ------------------------------------------------------------------------- 115*cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::getColumnCount() throw(SQLException, RuntimeException) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir return m_aMacabFields.size(); 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir // ------------------------------------------------------------------------- 120*cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isCaseSensitive(sal_Int32) throw(SQLException, RuntimeException) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir return sal_True; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir // ------------------------------------------------------------------------- 125*cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getSchemaName(sal_Int32) throw(SQLException, RuntimeException) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir return ::rtl::OUString(); 128*cdf0e10cSrcweir } 129*cdf0e10cSrcweir // ------------------------------------------------------------------------- 130*cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnName(sal_Int32 column) throw(SQLException, RuntimeException) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir sal_uInt32 nFieldNumber = m_aMacabFields[column - 1]; 133*cdf0e10cSrcweir MacabRecords *aRecords; 134*cdf0e10cSrcweir MacabHeader *aHeader; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir aRecords = m_pConnection->getAddressBook()->getMacabRecords(m_sTableName); 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // In case, somehow, we don't have anything with the name m_sTableName 139*cdf0e10cSrcweir if(aRecords == NULL) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir impl_throwError(STR_NO_TABLE); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir aHeader = aRecords->getHeader(); 145*cdf0e10cSrcweir ::rtl::OUString aName = aHeader->getString(nFieldNumber); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir return aName; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir // ------------------------------------------------------------------------- 150*cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getTableName(sal_Int32) throw(SQLException, RuntimeException) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir return m_sTableName; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir // ------------------------------------------------------------------------- 155*cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getCatalogName(sal_Int32) throw(SQLException, RuntimeException) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir return ::rtl::OUString(); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir // ------------------------------------------------------------------------- 160*cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnTypeName(sal_Int32) throw(SQLException, RuntimeException) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir return ::rtl::OUString(); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir // ------------------------------------------------------------------------- 165*cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnLabel(sal_Int32) throw(SQLException, RuntimeException) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir return ::rtl::OUString(); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir // ------------------------------------------------------------------------- 170*cdf0e10cSrcweir ::rtl::OUString SAL_CALL MacabResultSetMetaData::getColumnServiceName(sal_Int32) throw(SQLException, RuntimeException) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir return ::rtl::OUString(); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir // ------------------------------------------------------------------------- 175*cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isCurrency(sal_Int32) throw(SQLException, RuntimeException) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir return sal_False; 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir // ------------------------------------------------------------------------- 180*cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isAutoIncrement(sal_Int32) throw(SQLException, RuntimeException) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir return sal_False; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir // ------------------------------------------------------------------------- 185*cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isSigned(sal_Int32) throw(SQLException, RuntimeException) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir return sal_False; 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir // ------------------------------------------------------------------------- 190*cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::getPrecision(sal_Int32) throw(SQLException, RuntimeException) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir return 0; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 195*cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::getScale(sal_Int32) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir return 0; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir // ------------------------------------------------------------------------- 200*cdf0e10cSrcweir sal_Int32 SAL_CALL MacabResultSetMetaData::isNullable(sal_Int32) throw(SQLException, RuntimeException) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir return (sal_Int32) sal_True; 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir // ------------------------------------------------------------------------- 205*cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isSearchable(sal_Int32) throw(SQLException, RuntimeException) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir return sal_True; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir // ------------------------------------------------------------------------- 210*cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isReadOnly(sal_Int32) throw(SQLException, RuntimeException) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir return sal_True; 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir // ------------------------------------------------------------------------- 215*cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isDefinitelyWritable(sal_Int32) throw(SQLException, RuntimeException) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir return sal_False; 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir // ------------------------------------------------------------------------- 220*cdf0e10cSrcweir sal_Bool SAL_CALL MacabResultSetMetaData::isWritable(sal_Int32) throw(SQLException, RuntimeException) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir return sal_False; 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir // ------------------------------------------------------------------------- 225