Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / mysqlc / source / mysqlc_resultsetmetadata.cxx
blob0693e472442b4b0741b23289c79d745259c3a3ca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "mysqlc_resultsetmetadata.hxx"
21 #include "mysqlc_general.hxx"
22 #include "cppconn/exception.h"
24 #include <rtl/ustrbuf.hxx>
26 using namespace connectivity::mysqlc;
27 using namespace com::sun::star::uno;
28 using namespace com::sun::star::lang;
29 using namespace com::sun::star::sdbc;
30 using ::rtl::OUString;
32 // -------------------------------------------------------------------------
33 OResultSetMetaData::~OResultSetMetaData()
36 /* }}} */
39 /* {{{ OResultSetMetaData::getColumnDisplaySize() -I- */
40 sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize(sal_Int32 column)
41 throw(SQLException, RuntimeException)
43 OSL_TRACE("OResultSetMetaData::getColumnDisplaySize");
45 try {
46 meta->getColumnDisplaySize(column);
47 } catch (const sql::MethodNotImplementedException &) {
48 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getColumnDisplaySize", *this);
49 } catch (const sql::SQLException &e) {
50 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
52 return 0; // fool compiler
54 /* }}} */
57 /* {{{ OResultSetMetaData::getColumnType() -I- */
58 sal_Int32 SAL_CALL OResultSetMetaData::getColumnType(sal_Int32 column)
59 throw(SQLException, RuntimeException)
61 OSL_TRACE("OResultSetMetaData::getColumnType");
62 checkColumnIndex(column);
64 try {
65 return mysqlc_sdbc_driver::mysqlToOOOType(meta->getColumnType(column));
66 } catch (const sql::MethodNotImplementedException &) {
67 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
68 } catch (const sql::SQLException &e) {
69 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
71 return 0; // fool compiler
73 /* }}} */
76 XXX: This method doesn't throw exceptions at all.
77 Should it declare that it throws ?? What if throw() is removed?
78 Does it change the API, the open-close principle?
80 /* {{{ OResultSetMetaData::getColumnCount() -I- */
81 sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount()
82 throw(SQLException, RuntimeException)
84 OSL_TRACE("OResultSetMetaData::getColumnCount");
85 try {
86 return meta->getColumnCount();
87 } catch (const sql::MethodNotImplementedException &) {
88 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
89 } catch (const sql::SQLException &e) {
90 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
92 return 0; // fool compiler
94 /* }}} */
97 /* {{{ OResultSetMetaData::isCaseSensitive() -I- */
98 sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive(sal_Int32 column)
99 throw(SQLException, RuntimeException)
101 OSL_TRACE("OResultSetMetaData::isCaseSensitive");
102 checkColumnIndex(column);
104 try {
105 return meta->isCaseSensitive(column);
106 } catch (const sql::MethodNotImplementedException &) {
107 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
108 } catch (const sql::SQLException &e) {
109 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
111 return sal_False; // fool compiler
113 /* }}} */
116 /* {{{ OResultSetMetaData::getSchemaName() -I- */
117 OUString SAL_CALL OResultSetMetaData::getSchemaName(sal_Int32 column)
118 throw(SQLException, RuntimeException)
120 OSL_TRACE("OResultSetMetaData::getSchemaName");
121 checkColumnIndex(column);
123 try {
124 return convert(meta->getSchemaName(column));
125 } catch (const sql::MethodNotImplementedException &) {
126 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
127 } catch (const sql::SQLException &e) {
128 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
130 return OUString(); // fool compiler
132 /* }}} */
135 /* {{{ OResultSetMetaData::getColumnName() -I- */
136 OUString SAL_CALL OResultSetMetaData::getColumnName(sal_Int32 column)
137 throw(SQLException, RuntimeException)
139 OSL_TRACE("OResultSetMetaData::getColumnName");
140 checkColumnIndex(column);
142 try {
143 return convert( meta->getColumnName( column ) );
144 } catch (const sql::MethodNotImplementedException &) {
145 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
146 } catch (const sql::SQLException &e) {
147 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
149 return OUString(); // fool compiler
151 /* }}} */
154 /* {{{ OResultSetMetaData::getTableName() -I- */
155 OUString SAL_CALL OResultSetMetaData::getTableName(sal_Int32 column)
156 throw(SQLException, RuntimeException)
158 OSL_TRACE("OResultSetMetaData::getTableName");
159 checkColumnIndex(column);
161 try {
162 return convert(meta->getTableName(column));
163 } catch (const sql::MethodNotImplementedException &) {
164 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
165 } catch (const sql::SQLException &e) {
166 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
168 return OUString(); // fool compiler
170 /* }}} */
173 /* {{{ OResultSetMetaData::getCatalogName() -I- */
174 OUString SAL_CALL OResultSetMetaData::getCatalogName(sal_Int32 column)
175 throw(SQLException, RuntimeException)
177 OSL_TRACE("OResultSetMetaData::getCatalogName");
178 checkColumnIndex(column);
180 try {
181 return convert(meta->getCatalogName(column));
182 } catch (const sql::MethodNotImplementedException &) {
183 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
184 } catch (const sql::SQLException &e) {
185 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
187 return OUString(); // fool compiler
189 /* }}} */
192 /* {{{ OResultSetMetaData::getColumnTypeName() -I- */
193 OUString SAL_CALL OResultSetMetaData::getColumnTypeName(sal_Int32 column)
194 throw(SQLException, RuntimeException)
196 OSL_TRACE("OResultSetMetaData::getColumnTypeName");
197 checkColumnIndex(column);
199 try {
200 return convert(meta->getColumnTypeName(column));
201 } catch (const sql::MethodNotImplementedException &) {
202 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
203 } catch (const sql::SQLException &e) {
204 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
206 return OUString(); // fool compiler
208 /* }}} */
211 /* {{{ OResultSetMetaData::getColumnLabel() -I- */
212 OUString SAL_CALL OResultSetMetaData::getColumnLabel(sal_Int32 column)
213 throw(SQLException, RuntimeException)
215 OSL_TRACE("OResultSetMetaData::getColumnLabel");
216 checkColumnIndex(column);
218 try {
219 return convert(meta->getColumnLabel(column));
220 } catch (const sql::MethodNotImplementedException &) {
221 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
222 } catch (const sql::SQLException &e) {
223 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
225 return OUString(); // fool compiler
227 /* }}} */
230 /* {{{ OResultSetMetaData::getColumnServiceName() -I- */
231 OUString SAL_CALL OResultSetMetaData::getColumnServiceName(sal_Int32 column)
232 throw(SQLException, RuntimeException)
234 OSL_TRACE("OResultSetMetaData::getColumnServiceName");
235 checkColumnIndex(column);
237 OUString aRet = OUString();
238 return aRet;
240 /* }}} */
243 /* {{{ OResultSetMetaData::isCurrency() -I- */
244 sal_Bool SAL_CALL OResultSetMetaData::isCurrency(sal_Int32 column)
245 throw(SQLException, RuntimeException)
247 OSL_TRACE("OResultSetMetaData::isCurrency");
248 checkColumnIndex(column);
250 try {
251 return meta->isCurrency(column)? sal_True:sal_False;
252 } catch (const sql::MethodNotImplementedException &) {
253 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
254 } catch (const sql::SQLException &e) {
255 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
257 return sal_False; // fool compiler
259 /* }}} */
262 /* {{{ OResultSetMetaData::isAutoIncrement() -I- */
263 sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement(sal_Int32 column)
264 throw(SQLException, RuntimeException)
266 OSL_TRACE("OResultSetMetaData::isAutoIncrement");
267 checkColumnIndex(column);
269 try {
270 return meta->isAutoIncrement(column)? sal_True:sal_False;
271 } catch (const sql::MethodNotImplementedException &) {
272 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
273 } catch (const sql::SQLException &e) {
274 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
276 return sal_False; // fool compiler
278 /* }}} */
281 /* {{{ OResultSetMetaData::isSigned() -I- */
282 sal_Bool SAL_CALL OResultSetMetaData::isSigned(sal_Int32 column)
283 throw(SQLException, RuntimeException)
285 OSL_TRACE("OResultSetMetaData::isSigned");
286 checkColumnIndex(column);
288 try {
289 return meta->isSigned(column)? sal_True:sal_False;
290 } catch (const sql::MethodNotImplementedException &) {
291 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
292 } catch (const sql::SQLException &e) {
293 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
295 return sal_False; // fool compiler
297 /* }}} */
300 /* {{{ OResultSetMetaData::getPrecision() -I- */
301 sal_Int32 SAL_CALL OResultSetMetaData::getPrecision(sal_Int32 column)
302 throw(SQLException, RuntimeException)
304 OSL_TRACE("OResultSetMetaData::getPrecision");
305 checkColumnIndex(column);
307 try {
308 return meta->getPrecision(column);
309 } catch (const sql::MethodNotImplementedException &) {
310 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getPrecision", *this);
311 } catch (const sql::SQLException &e) {
312 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
314 return 0; // fool compiler
316 /* }}} */
319 /* {{{ OResultSetMetaData::getScale() -I- */
320 sal_Int32 SAL_CALL OResultSetMetaData::getScale(sal_Int32 column)
321 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
323 OSL_TRACE("OResultSetMetaData::getScale");
324 checkColumnIndex(column);
325 try {
326 return meta->getScale(column);
327 } catch (const sql::MethodNotImplementedException &) {
328 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getScale", *this);
329 } catch (const sql::SQLException &e) {
330 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
332 return 0; // fool compiler
334 /* }}} */
337 /* {{{ OResultSetMetaData::isNullable() -I- */
338 sal_Int32 SAL_CALL OResultSetMetaData::isNullable(sal_Int32 column)
339 throw(SQLException, RuntimeException)
341 OSL_TRACE("OResultSetMetaData::isNullable");
342 checkColumnIndex(column);
344 try {
345 return meta->isNullable(column)? sal_True:sal_False;
346 } catch (const sql::MethodNotImplementedException &) {
347 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
348 } catch (const sql::SQLException &e) {
349 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
351 return sal_False; // fool compiler
353 /* }}} */
356 /* {{{ OResultSetMetaData::isSearchable() -I- */
357 sal_Bool SAL_CALL OResultSetMetaData::isSearchable(sal_Int32 column)
358 throw(SQLException, RuntimeException)
360 OSL_TRACE("OResultSetMetaData::isSearchable");
361 checkColumnIndex(column);
363 try {
364 return meta->isSearchable(column)? sal_True:sal_False;
365 } catch (const sql::MethodNotImplementedException &) {
366 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
367 } catch (const sql::SQLException &e) {
368 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
370 return sal_False; // fool compiler
372 /* }}} */
375 /* {{{ OResultSetMetaData::isReadOnly() -I- */
376 sal_Bool SAL_CALL OResultSetMetaData::isReadOnly(sal_Int32 column)
377 throw(SQLException, RuntimeException)
379 OSL_TRACE("OResultSetMetaData::isReadOnly");
380 checkColumnIndex(column);
382 try {
383 return meta->isReadOnly(column)? sal_True:sal_False;
384 } catch (const sql::MethodNotImplementedException &) {
385 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
386 } catch (const sql::SQLException &e) {
387 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
389 return sal_False; // fool compiler
391 /* }}} */
394 /* {{{ OResultSetMetaData::isDefinitelyWritable() -I- */
395 sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable(sal_Int32 column)
396 throw(SQLException, RuntimeException)
398 OSL_TRACE("OResultSetMetaData::isDefinitelyWritable");
399 checkColumnIndex(column);
401 try {
402 return meta->isDefinitelyWritable(column)? sal_True:sal_False;
403 } catch (const sql::MethodNotImplementedException &) {
404 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
405 } catch (const sql::SQLException &e) {
406 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
408 return sal_False; // fool compiler
410 /* }}} */
413 /* {{{ OResultSetMetaData::isWritable() -I- */
414 sal_Bool SAL_CALL OResultSetMetaData::isWritable(sal_Int32 column)
415 throw(SQLException, RuntimeException)
417 OSL_TRACE("OResultSetMetaData::isWritable");
418 checkColumnIndex(column);
420 try {
421 return meta->isWritable(column)? sal_True:sal_False;
422 } catch (const sql::MethodNotImplementedException &) {
423 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
424 } catch (const sql::SQLException &e) {
425 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
427 return sal_False; // fool compiler
429 /* }}} */
432 /* {{{ OResultSetMetaData::checkColumnIndex() -I- */
433 void OResultSetMetaData::checkColumnIndex(sal_Int32 columnIndex)
434 throw (SQLException, RuntimeException)
436 OSL_TRACE("OResultSetMetaData::checkColumnIndex");
437 if (columnIndex < 1 || columnIndex > (sal_Int32) meta->getColumnCount()) {
439 ::rtl::OUStringBuffer buf;
440 buf.appendAscii( "Column index out of range (expected 1 to " );
441 buf.append( sal_Int32( meta->getColumnCount() ) );
442 buf.appendAscii( ", got " );
443 buf.append( sal_Int32( columnIndex ) );
444 buf.append( sal_Unicode( '.' ) );
445 throw SQLException( buf.makeStringAndClear(), *this, OUString(), 1, Any() );
448 /* }}} */
451 * Local variables:
452 * tab-width: 4
453 * c-basic-offset: 4
454 * End:
455 * vim600: noet sw=4 ts=4 fdm=marker
456 * vim<600: noet sw=4 ts=4
459 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */