1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_connectivity.hxx" 30 #include "ado/AResultSetMetaData.hxx" 31 #include <com/sun/star/sdbc/DataType.hpp> 32 #include <com/sun/star/sdbc/ColumnValue.hpp> 33 #include "ado/Awrapado.hxx" 34 #include "connectivity/dbexception.hxx" 35 36 using namespace connectivity; 37 using namespace connectivity::ado; 38 using namespace com::sun::star::uno; 39 using namespace com::sun::star::lang; 40 using namespace com::sun::star::beans; 41 using namespace com::sun::star::sdbc; 42 43 OResultSetMetaData::OResultSetMetaData( ADORecordset* _pRecordSet) 44 : m_pRecordSet(_pRecordSet), 45 m_nColCount(-1) 46 { 47 if ( m_pRecordSet ) 48 m_pRecordSet->AddRef(); 49 } 50 // ------------------------------------------------------------------------- 51 OResultSetMetaData::~OResultSetMetaData() 52 { 53 if ( m_pRecordSet ) 54 m_pRecordSet->Release(); 55 } 56 // ------------------------------------------------------------------------- 57 sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException) 58 { 59 WpADOField aField = ADOS::getField(m_pRecordSet,column); 60 if(aField.IsValid() && aField.GetActualSize() != -1) 61 return aField.GetActualSize(); 62 return 0; 63 } 64 // ------------------------------------------------------------------------- 65 66 sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException) 67 { 68 WpADOField aField = ADOS::getField(m_pRecordSet,column); 69 return ADOS::MapADOType2Jdbc(aField.GetADOType()); 70 } 71 // ------------------------------------------------------------------------- 72 73 sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException) 74 { 75 if(m_nColCount != -1 ) 76 return m_nColCount; 77 78 if ( !m_pRecordSet ) 79 return 0; 80 81 ADOFields* pFields = NULL; 82 m_pRecordSet->get_Fields(&pFields); 83 WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields); 84 m_nColCount = aFields.GetItemCount(); 85 return m_nColCount; 86 } 87 // ------------------------------------------------------------------------- 88 89 sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException) 90 { 91 sal_Bool bRet = sal_False; 92 WpADOField aField = ADOS::getField(m_pRecordSet,column); 93 if ( aField.IsValid() ) 94 { 95 WpADOProperties aProps( aField.get_Properties() ); 96 if ( aProps.IsValid() ) 97 bRet = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ISCASESENSITIVE")) ); 98 } 99 return bRet; 100 } 101 // ------------------------------------------------------------------------- 102 103 ::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 104 { 105 return ::rtl::OUString(); 106 } 107 // ------------------------------------------------------------------------- 108 109 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException) 110 { 111 WpADOField aField = ADOS::getField(m_pRecordSet,column); 112 if(aField.IsValid()) 113 return aField.GetName(); 114 115 return ::rtl::OUString(); 116 } 117 // ------------------------------------------------------------------------- 118 ::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException) 119 { 120 ::rtl::OUString sTableName; 121 122 WpADOField aField = ADOS::getField(m_pRecordSet,column); 123 if ( aField.IsValid() ) 124 { 125 WpADOProperties aProps( aField.get_Properties() ); 126 if ( aProps.IsValid() ) 127 sTableName = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BASETABLENAME")) ); 128 } 129 return sTableName; 130 } 131 // ------------------------------------------------------------------------- 132 ::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 133 { 134 return ::rtl::OUString(); 135 } 136 // ------------------------------------------------------------------------- 137 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 138 { 139 return ::rtl::OUString(); 140 } 141 // ------------------------------------------------------------------------- 142 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException) 143 { 144 return getColumnName(column); 145 } 146 // ------------------------------------------------------------------------- 147 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 148 { 149 return ::rtl::OUString(); 150 } 151 // ------------------------------------------------------------------------- 152 153 sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException) 154 { 155 WpADOField aField = ADOS::getField(m_pRecordSet,column); 156 if(aField.IsValid()) 157 { 158 return ((aField.GetAttributes() & adFldFixed) == adFldFixed) && (aField.GetADOType() == adCurrency); 159 } 160 return sal_False; 161 } 162 // ------------------------------------------------------------------------- 163 164 sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException) 165 { 166 sal_Bool bRet = sal_False; 167 WpADOField aField = ADOS::getField(m_pRecordSet,column); 168 if ( aField.IsValid() ) 169 { 170 WpADOProperties aProps( aField.get_Properties() ); 171 if ( aProps.IsValid() ) 172 { 173 bRet = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ISAUTOINCREMENT")) ); 174 #if OSL_DEBUG_LEVEL > 0 175 sal_Int32 nCount = aProps.GetItemCount(); 176 for (sal_Int32 i = 0; i<nCount; ++i) 177 { 178 WpADOProperty aProp = aProps.GetItem(i); 179 ::rtl::OUString sName = aProp.GetName(); 180 ::rtl::OUString sVal = aProp.GetValue(); 181 } 182 #endif 183 } 184 } 185 return bRet; 186 } 187 // ------------------------------------------------------------------------- 188 189 190 sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException) 191 { 192 WpADOField aField = ADOS::getField(m_pRecordSet,column); 193 if(aField.IsValid()) 194 { 195 DataTypeEnum eType = aField.GetADOType(); 196 return !(eType == adUnsignedBigInt || eType == adUnsignedInt || eType == adUnsignedSmallInt || eType == adUnsignedTinyInt); 197 } 198 return sal_False; 199 } 200 // ------------------------------------------------------------------------- 201 sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException) 202 { 203 WpADOField aField = ADOS::getField(m_pRecordSet,column); 204 if(aField.IsValid()) 205 return aField.GetPrecision(); 206 return 0; 207 } 208 // ------------------------------------------------------------------------- 209 sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 210 { 211 WpADOField aField = ADOS::getField(m_pRecordSet,column); 212 if(aField.IsValid()) 213 return aField.GetNumericScale(); 214 return 0; 215 } 216 // ------------------------------------------------------------------------- 217 218 sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException) 219 { 220 WpADOField aField = ADOS::getField(m_pRecordSet,column); 221 if(aField.IsValid()) 222 { 223 return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable; 224 } 225 return sal_False; 226 } 227 // ------------------------------------------------------------------------- 228 229 sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 230 { 231 return sal_True; 232 } 233 // ------------------------------------------------------------------------- 234 235 sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException) 236 { 237 WpADOField aField = ADOS::getField(m_pRecordSet,column); 238 if(aField.IsValid()) 239 { 240 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly; 241 } 242 return sal_False; 243 } 244 // ------------------------------------------------------------------------- 245 246 sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException) 247 { 248 WpADOField aField = ADOS::getField(m_pRecordSet,column); 249 if(aField.IsValid()) 250 { 251 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable; 252 } 253 return sal_False; 254 ; 255 } 256 // ------------------------------------------------------------------------- 257 sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException) 258 { 259 return isDefinitelyWritable(column); 260 } 261 // ------------------------------------------------------------------------- 262 263