1*9b5730f6SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9b5730f6SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9b5730f6SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9b5730f6SAndrew Rist * distributed with this work for additional information 6*9b5730f6SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9b5730f6SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9b5730f6SAndrew Rist * "License"); you may not use this file except in compliance 9*9b5730f6SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9b5730f6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9b5730f6SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9b5730f6SAndrew Rist * software distributed under the License is distributed on an 15*9b5730f6SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9b5730f6SAndrew Rist * KIND, either express or implied. See the License for the 17*9b5730f6SAndrew Rist * specific language governing permissions and limitations 18*9b5730f6SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9b5730f6SAndrew Rist *************************************************************/ 21*9b5730f6SAndrew Rist 22*9b5730f6SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_connectivity.hxx" 26cdf0e10cSrcweir #include "file/FResultSetMetaData.hxx" 27cdf0e10cSrcweir #include "file/FTable.hxx" 28cdf0e10cSrcweir #include <comphelper/extract.hxx> 29cdf0e10cSrcweir #include "connectivity/dbexception.hxx" 30cdf0e10cSrcweir #include <comphelper/types.hxx> 31cdf0e10cSrcweir #include <rtl/logfile.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace ::comphelper; 34cdf0e10cSrcweir using namespace connectivity; 35cdf0e10cSrcweir using namespace dbtools; 36cdf0e10cSrcweir using namespace connectivity::file; 37cdf0e10cSrcweir using namespace ::com::sun::star::beans; 38cdf0e10cSrcweir using namespace ::com::sun::star::uno; 39cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 40cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 41cdf0e10cSrcweir using namespace ::com::sun::star::container; 42cdf0e10cSrcweir using namespace ::com::sun::star::lang; 43cdf0e10cSrcweir 44cdf0e10cSrcweir // ------------------------------------------------------------------------- 45cdf0e10cSrcweir OResultSetMetaData::OResultSetMetaData(const ::vos::ORef<connectivity::OSQLColumns>& _rxColumns,const ::rtl::OUString& _aTableName,OFileTable* _pTable) 46cdf0e10cSrcweir :m_aTableName(_aTableName) 47cdf0e10cSrcweir ,m_xColumns(_rxColumns) 48cdf0e10cSrcweir ,m_pTable(_pTable) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::OResultSetMetaData" ); 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir // ------------------------------------------------------------------------- 54cdf0e10cSrcweir OResultSetMetaData::~OResultSetMetaData() 55cdf0e10cSrcweir { 56cdf0e10cSrcweir m_xColumns = NULL; 57cdf0e10cSrcweir } 58cdf0e10cSrcweir // ----------------------------------------------------------------------------- 59cdf0e10cSrcweir void OResultSetMetaData::checkColumnIndex(sal_Int32 column) throw(SQLException, RuntimeException) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::checkColumnIndex" ); 62cdf0e10cSrcweir if(column <= 0 || column > (sal_Int32)(sal_Int32)m_xColumns->get().size()) 63cdf0e10cSrcweir throwInvalidIndexException(*this); 64cdf0e10cSrcweir } 65cdf0e10cSrcweir // ------------------------------------------------------------------------- 66cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException) 67cdf0e10cSrcweir { 68cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnDisplaySize" ); 69cdf0e10cSrcweir return getPrecision(column); 70cdf0e10cSrcweir } 71cdf0e10cSrcweir // ------------------------------------------------------------------------- 72cdf0e10cSrcweir 73cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException) 74cdf0e10cSrcweir { 75cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnType" ); 76cdf0e10cSrcweir checkColumnIndex(column); 77cdf0e10cSrcweir return getINT32((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE))); 78cdf0e10cSrcweir } 79cdf0e10cSrcweir // ------------------------------------------------------------------------- 80cdf0e10cSrcweir 81cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException) 82cdf0e10cSrcweir { 83cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnCount" ); 84cdf0e10cSrcweir return (m_xColumns->get()).size(); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir // ------------------------------------------------------------------------- 87cdf0e10cSrcweir 88cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isCaseSensitive" ); 91cdf0e10cSrcweir return sal_False; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir // ------------------------------------------------------------------------- 94cdf0e10cSrcweir 95cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getSchemaName" ); 98cdf0e10cSrcweir return ::rtl::OUString(); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir // ------------------------------------------------------------------------- 101cdf0e10cSrcweir 102cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnName" ); 105cdf0e10cSrcweir checkColumnIndex(column); 106cdf0e10cSrcweir 107cdf0e10cSrcweir Any aName((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))); 108cdf0e10cSrcweir return aName.hasValue() ? getString(aName) : getString((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_NAME))); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir // ------------------------------------------------------------------------- 111cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getTableName" ); 114cdf0e10cSrcweir return m_aTableName; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir // ------------------------------------------------------------------------- 117cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getCatalogName" ); 120cdf0e10cSrcweir return ::rtl::OUString(); 121cdf0e10cSrcweir } 122cdf0e10cSrcweir // ------------------------------------------------------------------------- 123cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 column ) throw(SQLException, RuntimeException) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnTypeName" ); 126cdf0e10cSrcweir checkColumnIndex(column); 127cdf0e10cSrcweir return getString((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPENAME))); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir // ------------------------------------------------------------------------- 130cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnLabel" ); 133cdf0e10cSrcweir return getColumnName(column); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir // ------------------------------------------------------------------------- 136cdf0e10cSrcweir ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getColumnServiceName" ); 139cdf0e10cSrcweir return ::rtl::OUString(); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir // ------------------------------------------------------------------------- 142cdf0e10cSrcweir 143cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isCurrency" ); 146cdf0e10cSrcweir checkColumnIndex(column); 147cdf0e10cSrcweir return getBOOL((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY))); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir // ------------------------------------------------------------------------- 150cdf0e10cSrcweir 151cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 /*setCatalogcolumn*/ ) throw(SQLException, RuntimeException) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isAutoIncrement" ); 154cdf0e10cSrcweir return sal_False; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir // ------------------------------------------------------------------------- 157cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isSigned" ); 160cdf0e10cSrcweir return sal_True; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir // ------------------------------------------------------------------------- 163cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getPrecision" ); 166cdf0e10cSrcweir checkColumnIndex(column); 167cdf0e10cSrcweir return getINT32((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION))); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir // ------------------------------------------------------------------------- 170cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::getScale" ); 173cdf0e10cSrcweir checkColumnIndex(column); 174cdf0e10cSrcweir return getINT32((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_SCALE))); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir // ------------------------------------------------------------------------- 177cdf0e10cSrcweir 178cdf0e10cSrcweir sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isNullable" ); 181cdf0e10cSrcweir checkColumnIndex(column); 182cdf0e10cSrcweir return getINT32((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISNULLABLE))); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir // ------------------------------------------------------------------------- 185cdf0e10cSrcweir 186cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isSearchable" ); 189cdf0e10cSrcweir return sal_True; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir // ------------------------------------------------------------------------- 192cdf0e10cSrcweir 193cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isReadOnly" ); 196cdf0e10cSrcweir checkColumnIndex(column); 197cdf0e10cSrcweir return m_pTable->isReadOnly() || ( 198cdf0e10cSrcweir (m_xColumns->get())[column-1]->getPropertySetInfo()->hasPropertyByName(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION)) && 199cdf0e10cSrcweir ::cppu::any2bool((m_xColumns->get())[column-1]->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FUNCTION)))); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir // ------------------------------------------------------------------------- 202cdf0e10cSrcweir 203cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException) 204cdf0e10cSrcweir { 205cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isDefinitelyWritable" ); 206cdf0e10cSrcweir return !isReadOnly(column); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir // ------------------------------------------------------------------------- 209cdf0e10cSrcweir sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "file", "Ocke.Janssen@sun.com", "OResultSetMetaData::isWritable" ); 212cdf0e10cSrcweir return !isReadOnly(column); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir // ------------------------------------------------------------------------- 215cdf0e10cSrcweir 216