1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_connectivity.hxx" 26 #include "ado/AResultSetMetaData.hxx" 27 #include <com/sun/star/sdbc/DataType.hpp> 28 #include <com/sun/star/sdbc/ColumnValue.hpp> 29 #include "ado/Awrapado.hxx" 30 #include "connectivity/dbexception.hxx" 31 32 using namespace connectivity; 33 using namespace connectivity::ado; 34 using namespace com::sun::star::uno; 35 using namespace com::sun::star::lang; 36 using namespace com::sun::star::beans; 37 using namespace com::sun::star::sdbc; 38 39 OResultSetMetaData::OResultSetMetaData( ADORecordset* _pRecordSet) 40 : m_pRecordSet(_pRecordSet), 41 m_nColCount(-1) 42 { 43 if ( m_pRecordSet ) 44 m_pRecordSet->AddRef(); 45 } 46 // ------------------------------------------------------------------------- 47 OResultSetMetaData::~OResultSetMetaData() 48 { 49 if ( m_pRecordSet ) 50 m_pRecordSet->Release(); 51 } 52 // ------------------------------------------------------------------------- 53 sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) throw(SQLException, RuntimeException) 54 { 55 WpADOField aField = ADOS::getField(m_pRecordSet,column); 56 if(aField.IsValid() && aField.GetActualSize() != -1) 57 return aField.GetActualSize(); 58 return 0; 59 } 60 // ------------------------------------------------------------------------- 61 62 sal_Int32 SAL_CALL OResultSetMetaData::getColumnType( sal_Int32 column ) throw(SQLException, RuntimeException) 63 { 64 WpADOField aField = ADOS::getField(m_pRecordSet,column); 65 return ADOS::MapADOType2Jdbc(aField.GetADOType()); 66 } 67 // ------------------------------------------------------------------------- 68 69 sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount( ) throw(SQLException, RuntimeException) 70 { 71 if(m_nColCount != -1 ) 72 return m_nColCount; 73 74 if ( !m_pRecordSet ) 75 return 0; 76 77 ADOFields* pFields = NULL; 78 m_pRecordSet->get_Fields(&pFields); 79 WpOLEAppendCollection<ADOFields, ADOField, WpADOField> aFields(pFields); 80 m_nColCount = aFields.GetItemCount(); 81 return m_nColCount; 82 } 83 // ------------------------------------------------------------------------- 84 85 sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive( sal_Int32 column ) throw(SQLException, RuntimeException) 86 { 87 sal_Bool bRet = sal_False; 88 WpADOField aField = ADOS::getField(m_pRecordSet,column); 89 if ( aField.IsValid() ) 90 { 91 WpADOProperties aProps( aField.get_Properties() ); 92 if ( aProps.IsValid() ) 93 bRet = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ISCASESENSITIVE")) ); 94 } 95 return bRet; 96 } 97 // ------------------------------------------------------------------------- 98 99 ::rtl::OUString SAL_CALL OResultSetMetaData::getSchemaName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 100 { 101 return ::rtl::OUString(); 102 } 103 // ------------------------------------------------------------------------- 104 105 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnName( sal_Int32 column ) throw(SQLException, RuntimeException) 106 { 107 WpADOField aField = ADOS::getField(m_pRecordSet,column); 108 if(aField.IsValid()) 109 return aField.GetName(); 110 111 return ::rtl::OUString(); 112 } 113 // ------------------------------------------------------------------------- 114 ::rtl::OUString SAL_CALL OResultSetMetaData::getTableName( sal_Int32 column ) throw(SQLException, RuntimeException) 115 { 116 ::rtl::OUString sTableName; 117 118 WpADOField aField = ADOS::getField(m_pRecordSet,column); 119 if ( aField.IsValid() ) 120 { 121 WpADOProperties aProps( aField.get_Properties() ); 122 if ( aProps.IsValid() ) 123 sTableName = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BASETABLENAME")) ); 124 } 125 return sTableName; 126 } 127 // ------------------------------------------------------------------------- 128 ::rtl::OUString SAL_CALL OResultSetMetaData::getCatalogName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 129 { 130 return ::rtl::OUString(); 131 } 132 // ------------------------------------------------------------------------- 133 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnTypeName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 134 { 135 return ::rtl::OUString(); 136 } 137 // ------------------------------------------------------------------------- 138 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnLabel( sal_Int32 column ) throw(SQLException, RuntimeException) 139 { 140 return getColumnName(column); 141 } 142 // ------------------------------------------------------------------------- 143 ::rtl::OUString SAL_CALL OResultSetMetaData::getColumnServiceName( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 144 { 145 return ::rtl::OUString(); 146 } 147 // ------------------------------------------------------------------------- 148 149 sal_Bool SAL_CALL OResultSetMetaData::isCurrency( sal_Int32 column ) throw(SQLException, RuntimeException) 150 { 151 WpADOField aField = ADOS::getField(m_pRecordSet,column); 152 if(aField.IsValid()) 153 { 154 return ((aField.GetAttributes() & adFldFixed) == adFldFixed) && (aField.GetADOType() == adCurrency); 155 } 156 return sal_False; 157 } 158 // ------------------------------------------------------------------------- 159 160 sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement( sal_Int32 column ) throw(SQLException, RuntimeException) 161 { 162 sal_Bool bRet = sal_False; 163 WpADOField aField = ADOS::getField(m_pRecordSet,column); 164 if ( aField.IsValid() ) 165 { 166 WpADOProperties aProps( aField.get_Properties() ); 167 if ( aProps.IsValid() ) 168 { 169 bRet = OTools::getValue( aProps, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ISAUTOINCREMENT")) ); 170 #if OSL_DEBUG_LEVEL > 0 171 sal_Int32 nCount = aProps.GetItemCount(); 172 for (sal_Int32 i = 0; i<nCount; ++i) 173 { 174 WpADOProperty aProp = aProps.GetItem(i); 175 ::rtl::OUString sName = aProp.GetName(); 176 ::rtl::OUString sVal = aProp.GetValue(); 177 } 178 #endif 179 } 180 } 181 return bRet; 182 } 183 // ------------------------------------------------------------------------- 184 185 186 sal_Bool SAL_CALL OResultSetMetaData::isSigned( sal_Int32 column ) throw(SQLException, RuntimeException) 187 { 188 WpADOField aField = ADOS::getField(m_pRecordSet,column); 189 if(aField.IsValid()) 190 { 191 DataTypeEnum eType = aField.GetADOType(); 192 return !(eType == adUnsignedBigInt || eType == adUnsignedInt || eType == adUnsignedSmallInt || eType == adUnsignedTinyInt); 193 } 194 return sal_False; 195 } 196 // ------------------------------------------------------------------------- 197 sal_Int32 SAL_CALL OResultSetMetaData::getPrecision( sal_Int32 column ) throw(SQLException, RuntimeException) 198 { 199 WpADOField aField = ADOS::getField(m_pRecordSet,column); 200 if(aField.IsValid()) 201 return aField.GetPrecision(); 202 return 0; 203 } 204 // ------------------------------------------------------------------------- 205 sal_Int32 SAL_CALL OResultSetMetaData::getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 206 { 207 WpADOField aField = ADOS::getField(m_pRecordSet,column); 208 if(aField.IsValid()) 209 return aField.GetNumericScale(); 210 return 0; 211 } 212 // ------------------------------------------------------------------------- 213 214 sal_Int32 SAL_CALL OResultSetMetaData::isNullable( sal_Int32 column ) throw(SQLException, RuntimeException) 215 { 216 WpADOField aField = ADOS::getField(m_pRecordSet,column); 217 if(aField.IsValid()) 218 { 219 return (aField.GetAttributes() & adFldIsNullable) == adFldIsNullable; 220 } 221 return sal_False; 222 } 223 // ------------------------------------------------------------------------- 224 225 sal_Bool SAL_CALL OResultSetMetaData::isSearchable( sal_Int32 /*column*/ ) throw(SQLException, RuntimeException) 226 { 227 return sal_True; 228 } 229 // ------------------------------------------------------------------------- 230 231 sal_Bool SAL_CALL OResultSetMetaData::isReadOnly( sal_Int32 column ) throw(SQLException, RuntimeException) 232 { 233 WpADOField aField = ADOS::getField(m_pRecordSet,column); 234 if(aField.IsValid()) 235 { 236 // return (aField.GetStatus() & adFieldReadOnly) == adFieldReadOnly; 237 } 238 return sal_False; 239 } 240 // ------------------------------------------------------------------------- 241 242 sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) throw(SQLException, RuntimeException) 243 { 244 WpADOField aField = ADOS::getField(m_pRecordSet,column); 245 if(aField.IsValid()) 246 { 247 return (aField.GetAttributes() & adFldUpdatable) == adFldUpdatable; 248 } 249 return sal_False; 250 ; 251 } 252 // ------------------------------------------------------------------------- 253 sal_Bool SAL_CALL OResultSetMetaData::isWritable( sal_Int32 column ) throw(SQLException, RuntimeException) 254 { 255 return isDefinitelyWritable(column); 256 } 257 // ------------------------------------------------------------------------- 258 259