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 #include "file/FResultSetMetaData.hxx" 31*cdf0e10cSrcweir #include "file/FTable.hxx" 32*cdf0e10cSrcweir #include <comphelper/extract.hxx> 33*cdf0e10cSrcweir #include "connectivity/dbexception.hxx" 34*cdf0e10cSrcweir #include <comphelper/types.hxx> 35*cdf0e10cSrcweir #include <rtl/logfile.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir using namespace ::comphelper; 38*cdf0e10cSrcweir using namespace connectivity; 39*cdf0e10cSrcweir using namespace dbtools; 40*cdf0e10cSrcweir using namespace connectivity::file; 41*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 42*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 44*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 45*cdf0e10cSrcweir using namespace ::com::sun::star::container; 46*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir // ------------------------------------------------------------------------- 49*cdf0e10cSrcweir OResultSetMetaData::OResultSetMetaData(const ::vos::ORef<connectivity::OSQLColumns>& _rxColumns,const ::rtl::OUString& _aTableName,OFileTable* _pTable) 50*cdf0e10cSrcweir :m_aTableName(_aTableName) 51*cdf0e10cSrcweir ,m_xColumns(_rxColumns) 52*cdf0e10cSrcweir ,m_pTable(_pTable) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::OResultSetMetaData" ); 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir // ------------------------------------------------------------------------- 58*cdf0e10cSrcweir OResultSetMetaData::~OResultSetMetaData() 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir m_xColumns = NULL; 61*cdf0e10cSrcweir } 62*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 63*cdf0e10cSrcweir void OResultSetMetaData::checkColumnIndex(sal_Int32 column) throw(SQLException, RuntimeException) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::checkColumnIndex" ); 66*cdf0e10cSrcweir if(column <= 0 || column > (sal_Int32)(sal_Int32)m_xColumns->get().size()) 67*cdf0e10cSrcweir throwInvalidIndexException(*this); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir // ------------------------------------------------------------------------- 70*cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnDisplaySize" ); 73*cdf0e10cSrcweir return getPrecision(column); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir // ------------------------------------------------------------------------- 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnType" ); 80*cdf0e10cSrcweir checkColumnIndex(column); 81*cdf0e10cSrcweir return getINT32((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir // ------------------------------------------------------------------------- 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnCount" ); 88*cdf0e10cSrcweir return (m_xColumns->get()).size(); 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir // ------------------------------------------------------------------------- 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isCaseSensitive" ); 95*cdf0e10cSrcweir return sal_False; 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir // ------------------------------------------------------------------------- 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getSchemaName" ); 102*cdf0e10cSrcweir return ::rtl::OUString(); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir // ------------------------------------------------------------------------- 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnName" ); 109*cdf0e10cSrcweir checkColumnIndex(column); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir Any aName((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))); 112*cdf0e10cSrcweir return aName.hasValue() ? getString(aName) : getString((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir // ------------------------------------------------------------------------- 115*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getTableName" ); 118*cdf0e10cSrcweir return m_aTableName; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir // ------------------------------------------------------------------------- 121*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getCatalogName" ); 124*cdf0e10cSrcweir return ::rtl::OUString(); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir // ------------------------------------------------------------------------- 127*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnTypeName" ); 130*cdf0e10cSrcweir checkColumnIndex(column); 131*cdf0e10cSrcweir return getString((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir // ------------------------------------------------------------------------- 134*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnLabel" ); 137*cdf0e10cSrcweir return getColumnName(column); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir // ------------------------------------------------------------------------- 140*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnServiceName" ); 143*cdf0e10cSrcweir return ::rtl::OUString(); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir // ------------------------------------------------------------------------- 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isCurrency" ); 150*cdf0e10cSrcweir checkColumnIndex(column); 151*cdf0e10cSrcweir return getBOOL((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir // ------------------------------------------------------------------------- 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 /*setCatalogcolumn*/ ) throw(SQLException, RuntimeException) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isAutoIncrement" ); 158*cdf0e10cSrcweir return sal_False; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir // ------------------------------------------------------------------------- 161*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isSigned" ); 164*cdf0e10cSrcweir return sal_True; 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir // ------------------------------------------------------------------------- 167*cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getPrecision" ); 170*cdf0e10cSrcweir checkColumnIndex(column); 171*cdf0e10cSrcweir return getINT32((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir // ------------------------------------------------------------------------- 174*cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getScale" ); 177*cdf0e10cSrcweir checkColumnIndex(column); 178*cdf0e10cSrcweir return getINT32((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir // ------------------------------------------------------------------------- 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isNullable" ); 185*cdf0e10cSrcweir checkColumnIndex(column); 186*cdf0e10cSrcweir return getINT32((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir // ------------------------------------------------------------------------- 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isSearchable" ); 193*cdf0e10cSrcweir return sal_True; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir // ------------------------------------------------------------------------- 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isReadOnly" ); 200*cdf0e10cSrcweir checkColumnIndex(column); 201*cdf0e10cSrcweir return m_pTable->isReadOnly() || ( 202*cdf0e10cSrcweir (m_xColumns->get())[column-1]->getPropertySetInfo()->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION)) && 203*cdf0e10cSrcweir ::cppu::any2bool((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION)))); 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir // ------------------------------------------------------------------------- 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isDefinitelyWritable" ); 210*cdf0e10cSrcweir return !isReadOnly(column); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir // ------------------------------------------------------------------------- 213*cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException) 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isWritable" ); 216*cdf0e10cSrcweir return !isReadOnly(column); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir // ------------------------------------------------------------------------- 219*cdf0e10cSrcweir 220