1 /************************************************************************* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * Copyright 2008 by Sun Microsystems, Inc. 5 * 6 * OpenOffice.org - a multi-platform office productivity suite 7 * 8 * $RCSfile: mysqlc_resultsetmetadata.cxx,v $ 9 * 10 * $Revision: 1.1.2.4 $ 11 * 12 * This file is part of OpenOffice.org. 13 * 14 * OpenOffice.org is free software: you can redistribute it and/or modify 15 * it under the terms of the GNU Lesser General Public License version 3 16 * only, as published by the Free Software Foundation. 17 * 18 * OpenOffice.org is distributed in the hope that it will be useful, 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 * GNU Lesser General Public License version 3 for more details 22 * (a copy is included in the LICENSE file that accompanied this code). 23 * 24 * You should have received a copy of the GNU Lesser General Public License 25 * version 3 along with OpenOffice.org. If not, see 26 * <http://www.openoffice.org/license.html> 27 * for a copy of the LGPLv3 License. 28 ************************************************************************/ 29 30 #include "mysqlc_resultsetmetadata.hxx" 31 #include "mysqlc_general.hxx" 32 #include "cppconn/exception.h" 33 34 #include <rtl/ustrbuf.hxx> 35 36 using namespace connectivity::mysqlc; 37 using namespace com::sun::star::uno; 38 using namespace com::sun::star::lang; 39 using namespace com::sun::star::sdbc; 40 using ::rtl::OUString; 41 42 // ------------------------------------------------------------------------- 43 OResultSetMetaData::~OResultSetMetaData() 44 { 45 } 46 /* }}} */ 47 48 49 /* {{{ OResultSetMetaData::getColumnDisplaySize() -I- */ 50 sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize(sal_Int32 column) 51 throw(SQLException, RuntimeException) 52 { 53 OSL_TRACE("OResultSetMetaData::getColumnDisplaySize"); 54 55 try { 56 meta->getColumnDisplaySize(column); 57 } catch (sql::MethodNotImplementedException) { 58 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getColumnDisplaySize", *this); 59 } catch (sql::SQLException &e) { 60 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 61 } 62 return 0; // fool compiler 63 } 64 /* }}} */ 65 66 67 /* {{{ OResultSetMetaData::getColumnType() -I- */ 68 sal_Int32 SAL_CALL OResultSetMetaData::getColumnType(sal_Int32 column) 69 throw(SQLException, RuntimeException) 70 { 71 OSL_TRACE("OResultSetMetaData::getColumnType"); 72 checkColumnIndex(column); 73 74 try { 75 return mysqlc_sdbc_driver::mysqlToOOOType(meta->getColumnType(column)); 76 } catch (sql::MethodNotImplementedException) { 77 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 78 } catch (sql::SQLException &e) { 79 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 80 } 81 return 0; // fool compiler 82 } 83 /* }}} */ 84 85 /* 86 XXX: This method doesn't throw exceptions at all. 87 Should it declare that it throws ?? What if throw() is removed? 88 Does it change the API, the open-close principle? 89 */ 90 /* {{{ OResultSetMetaData::getColumnCount() -I- */ 91 sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount() 92 throw(SQLException, RuntimeException) 93 { 94 OSL_TRACE("OResultSetMetaData::getColumnCount"); 95 try { 96 return meta->getColumnCount(); 97 } catch (sql::MethodNotImplementedException) { 98 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 99 } catch (sql::SQLException &e) { 100 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 101 } 102 return 0; // fool compiler 103 } 104 /* }}} */ 105 106 107 /* {{{ OResultSetMetaData::isCaseSensitive() -I- */ 108 sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive(sal_Int32 column) 109 throw(SQLException, RuntimeException) 110 { 111 OSL_TRACE("OResultSetMetaData::isCaseSensitive"); 112 checkColumnIndex(column); 113 114 try { 115 return meta->isCaseSensitive(column); 116 } catch (sql::MethodNotImplementedException) { 117 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 118 } catch (sql::SQLException &e) { 119 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 120 } 121 return sal_False; // fool compiler 122 } 123 /* }}} */ 124 125 126 /* {{{ OResultSetMetaData::getSchemaName() -I- */ 127 OUString SAL_CALL OResultSetMetaData::getSchemaName(sal_Int32 column) 128 throw(SQLException, RuntimeException) 129 { 130 OSL_TRACE("OResultSetMetaData::getSchemaName"); 131 checkColumnIndex(column); 132 133 try { 134 return convert(meta->getSchemaName(column)); 135 } catch (sql::MethodNotImplementedException) { 136 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 137 } catch (sql::SQLException &e) { 138 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 139 } 140 return OUString(); // fool compiler 141 } 142 /* }}} */ 143 144 145 /* {{{ OResultSetMetaData::getColumnName() -I- */ 146 OUString SAL_CALL OResultSetMetaData::getColumnName(sal_Int32 column) 147 throw(SQLException, RuntimeException) 148 { 149 OSL_TRACE("OResultSetMetaData::getColumnName"); 150 checkColumnIndex(column); 151 152 try { 153 return convert( meta->getColumnName( column ) ); 154 } catch (sql::MethodNotImplementedException) { 155 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 156 } catch (sql::SQLException &e) { 157 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 158 } 159 return OUString(); // fool compiler 160 } 161 /* }}} */ 162 163 164 /* {{{ OResultSetMetaData::getTableName() -I- */ 165 OUString SAL_CALL OResultSetMetaData::getTableName(sal_Int32 column) 166 throw(SQLException, RuntimeException) 167 { 168 OSL_TRACE("OResultSetMetaData::getTableName"); 169 checkColumnIndex(column); 170 171 try { 172 return convert(meta->getTableName(column)); 173 } catch (sql::MethodNotImplementedException) { 174 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 175 } catch (sql::SQLException &e) { 176 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 177 } 178 return OUString(); // fool compiler 179 } 180 /* }}} */ 181 182 183 /* {{{ OResultSetMetaData::getCatalogName() -I- */ 184 OUString SAL_CALL OResultSetMetaData::getCatalogName(sal_Int32 column) 185 throw(SQLException, RuntimeException) 186 { 187 OSL_TRACE("OResultSetMetaData::getCatalogName"); 188 checkColumnIndex(column); 189 190 try { 191 return convert(meta->getCatalogName(column)); 192 } catch (sql::MethodNotImplementedException) { 193 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 194 } catch (sql::SQLException &e) { 195 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 196 } 197 return OUString(); // fool compiler 198 } 199 /* }}} */ 200 201 202 /* {{{ OResultSetMetaData::getColumnTypeName() -I- */ 203 OUString SAL_CALL OResultSetMetaData::getColumnTypeName(sal_Int32 column) 204 throw(SQLException, RuntimeException) 205 { 206 OSL_TRACE("OResultSetMetaData::getColumnTypeName"); 207 checkColumnIndex(column); 208 209 try { 210 return convert(meta->getColumnTypeName(column)); 211 } catch (sql::MethodNotImplementedException) { 212 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 213 } catch (sql::SQLException &e) { 214 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 215 } 216 return OUString(); // fool compiler 217 } 218 /* }}} */ 219 220 221 /* {{{ OResultSetMetaData::getColumnLabel() -I- */ 222 OUString SAL_CALL OResultSetMetaData::getColumnLabel(sal_Int32 column) 223 throw(SQLException, RuntimeException) 224 { 225 OSL_TRACE("OResultSetMetaData::getColumnLabel"); 226 checkColumnIndex(column); 227 228 try { 229 return convert(meta->getColumnLabel(column)); 230 } catch (sql::MethodNotImplementedException) { 231 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 232 } catch (sql::SQLException &e) { 233 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 234 } 235 return OUString(); // fool compiler 236 } 237 /* }}} */ 238 239 240 /* {{{ OResultSetMetaData::getColumnServiceName() -I- */ 241 OUString SAL_CALL OResultSetMetaData::getColumnServiceName(sal_Int32 column) 242 throw(SQLException, RuntimeException) 243 { 244 OSL_TRACE("OResultSetMetaData::getColumnServiceName"); 245 checkColumnIndex(column); 246 247 OUString aRet = OUString(); 248 return aRet; 249 } 250 /* }}} */ 251 252 253 /* {{{ OResultSetMetaData::isCurrency() -I- */ 254 sal_Bool SAL_CALL OResultSetMetaData::isCurrency(sal_Int32 column) 255 throw(SQLException, RuntimeException) 256 { 257 OSL_TRACE("OResultSetMetaData::isCurrency"); 258 checkColumnIndex(column); 259 260 try { 261 return meta->isCurrency(column)? sal_True:sal_False; 262 } catch (sql::MethodNotImplementedException) { 263 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 264 } catch (sql::SQLException &e) { 265 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 266 } 267 return sal_False; // fool compiler 268 } 269 /* }}} */ 270 271 272 /* {{{ OResultSetMetaData::isAutoIncrement() -I- */ 273 sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement(sal_Int32 column) 274 throw(SQLException, RuntimeException) 275 { 276 OSL_TRACE("OResultSetMetaData::isAutoIncrement"); 277 checkColumnIndex(column); 278 279 try { 280 return meta->isAutoIncrement(column)? sal_True:sal_False; 281 } catch (sql::MethodNotImplementedException) { 282 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 283 } catch (sql::SQLException &e) { 284 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 285 } 286 return sal_False; // fool compiler 287 } 288 /* }}} */ 289 290 291 /* {{{ OResultSetMetaData::isSigned() -I- */ 292 sal_Bool SAL_CALL OResultSetMetaData::isSigned(sal_Int32 column) 293 throw(SQLException, RuntimeException) 294 { 295 OSL_TRACE("OResultSetMetaData::isSigned"); 296 checkColumnIndex(column); 297 298 try { 299 return meta->isSigned(column)? sal_True:sal_False; 300 } catch (sql::MethodNotImplementedException) { 301 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 302 } catch (sql::SQLException &e) { 303 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 304 } 305 return sal_False; // fool compiler 306 } 307 /* }}} */ 308 309 310 /* {{{ OResultSetMetaData::getPrecision() -I- */ 311 sal_Int32 SAL_CALL OResultSetMetaData::getPrecision(sal_Int32 column) 312 throw(SQLException, RuntimeException) 313 { 314 OSL_TRACE("OResultSetMetaData::getPrecision"); 315 checkColumnIndex(column); 316 317 try { 318 return meta->getPrecision(column); 319 } catch (sql::MethodNotImplementedException) { 320 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getPrecision", *this); 321 } catch (sql::SQLException &e) { 322 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 323 } 324 return 0; // fool compiler 325 } 326 /* }}} */ 327 328 329 /* {{{ OResultSetMetaData::getScale() -I- */ 330 sal_Int32 SAL_CALL OResultSetMetaData::getScale(sal_Int32 column) 331 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException) 332 { 333 OSL_TRACE("OResultSetMetaData::getScale"); 334 checkColumnIndex(column); 335 try { 336 return meta->getScale(column); 337 } catch (sql::MethodNotImplementedException) { 338 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getScale", *this); 339 } catch (sql::SQLException &e) { 340 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 341 } 342 return 0; // fool compiler 343 } 344 /* }}} */ 345 346 347 /* {{{ OResultSetMetaData::isNullable() -I- */ 348 sal_Int32 SAL_CALL OResultSetMetaData::isNullable(sal_Int32 column) 349 throw(SQLException, RuntimeException) 350 { 351 OSL_TRACE("OResultSetMetaData::isNullable"); 352 checkColumnIndex(column); 353 354 try { 355 return meta->isNullable(column)? sal_True:sal_False; 356 } catch (sql::MethodNotImplementedException) { 357 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 358 } catch (sql::SQLException &e) { 359 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 360 } 361 return sal_False; // fool compiler 362 } 363 /* }}} */ 364 365 366 /* {{{ OResultSetMetaData::isSearchable() -I- */ 367 sal_Bool SAL_CALL OResultSetMetaData::isSearchable(sal_Int32 column) 368 throw(SQLException, RuntimeException) 369 { 370 OSL_TRACE("OResultSetMetaData::isSearchable"); 371 checkColumnIndex(column); 372 373 try { 374 return meta->isSearchable(column)? sal_True:sal_False; 375 } catch (sql::MethodNotImplementedException) { 376 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 377 } catch (sql::SQLException &e) { 378 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 379 } 380 return sal_False; // fool compiler 381 } 382 /* }}} */ 383 384 385 /* {{{ OResultSetMetaData::isReadOnly() -I- */ 386 sal_Bool SAL_CALL OResultSetMetaData::isReadOnly(sal_Int32 column) 387 throw(SQLException, RuntimeException) 388 { 389 OSL_TRACE("OResultSetMetaData::isReadOnly"); 390 checkColumnIndex(column); 391 392 try { 393 return meta->isReadOnly(column)? sal_True:sal_False; 394 } catch (sql::MethodNotImplementedException) { 395 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 396 } catch (sql::SQLException &e) { 397 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 398 } 399 return sal_False; // fool compiler 400 } 401 /* }}} */ 402 403 404 /* {{{ OResultSetMetaData::isDefinitelyWritable() -I- */ 405 sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable(sal_Int32 column) 406 throw(SQLException, RuntimeException) 407 { 408 OSL_TRACE("OResultSetMetaData::isDefinitelyWritable"); 409 checkColumnIndex(column); 410 411 try { 412 return meta->isDefinitelyWritable(column)? sal_True:sal_False; 413 } catch (sql::MethodNotImplementedException) { 414 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 415 } catch (sql::SQLException &e) { 416 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 417 } 418 return sal_False; // fool compiler 419 } 420 /* }}} */ 421 422 423 /* {{{ OResultSetMetaData::isWritable() -I- */ 424 sal_Bool SAL_CALL OResultSetMetaData::isWritable(sal_Int32 column) 425 throw(SQLException, RuntimeException) 426 { 427 OSL_TRACE("OResultSetMetaData::isWritable"); 428 checkColumnIndex(column); 429 430 try { 431 return meta->isWritable(column)? sal_True:sal_False; 432 } catch (sql::MethodNotImplementedException) { 433 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this); 434 } catch (sql::SQLException &e) { 435 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding); 436 } 437 return sal_False; // fool compiler 438 } 439 /* }}} */ 440 441 442 /* {{{ OResultSetMetaData::checkColumnIndex() -I- */ 443 void OResultSetMetaData::checkColumnIndex(sal_Int32 columnIndex) 444 throw (SQLException, RuntimeException) 445 { 446 OSL_TRACE("OResultSetMetaData::checkColumnIndex"); 447 if (columnIndex < 1 || columnIndex > (sal_Int32) meta->getColumnCount()) { 448 449 ::rtl::OUStringBuffer buf; 450 buf.appendAscii( "Column index out of range (expected 1 to " ); 451 buf.append( sal_Int32( meta->getColumnCount() ) ); 452 buf.appendAscii( ", got " ); 453 buf.append( sal_Int32( columnIndex ) ); 454 buf.append( sal_Unicode( '.' ) ); 455 throw SQLException( buf.makeStringAndClear(), *this, OUString(), 1, Any() ); 456 } 457 } 458 /* }}} */ 459 460 /* 461 * Local variables: 462 * tab-width: 4 463 * c-basic-offset: 4 464 * End: 465 * vim600: noet sw=4 ts=4 fdm=marker 466 * vim<600: noet sw=4 ts=4 467 */ 468 469