bump product version to 4.1.6.2
[LibreOffice.git] / mysqlc / source / mysqlc_resultsetmetadata.cxx
blob0d0c2732d210f40a67348943bf0c44cd78722d29
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;
31 // -------------------------------------------------------------------------
32 OResultSetMetaData::~OResultSetMetaData()
35 /* }}} */
38 /* {{{ OResultSetMetaData::getColumnDisplaySize() -I- */
39 sal_Int32 SAL_CALL OResultSetMetaData::getColumnDisplaySize(sal_Int32 column)
40 throw(SQLException, RuntimeException)
42 OSL_TRACE("OResultSetMetaData::getColumnDisplaySize");
44 try {
45 meta->getColumnDisplaySize(column);
46 } catch (const sql::MethodNotImplementedException &) {
47 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getColumnDisplaySize", *this);
48 } catch (const sql::SQLException &e) {
49 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
51 return 0; // fool compiler
53 /* }}} */
56 /* {{{ OResultSetMetaData::getColumnType() -I- */
57 sal_Int32 SAL_CALL OResultSetMetaData::getColumnType(sal_Int32 column)
58 throw(SQLException, RuntimeException)
60 OSL_TRACE("OResultSetMetaData::getColumnType");
61 checkColumnIndex(column);
63 try {
64 return mysqlc_sdbc_driver::mysqlToOOOType(meta->getColumnType(column));
65 } catch (const sql::MethodNotImplementedException &) {
66 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
67 } catch (const sql::SQLException &e) {
68 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
70 return 0; // fool compiler
72 /* }}} */
75 XXX: This method doesn't throw exceptions at all.
76 Should it declare that it throws ?? What if throw() is removed?
77 Does it change the API, the open-close principle?
79 /* {{{ OResultSetMetaData::getColumnCount() -I- */
80 sal_Int32 SAL_CALL OResultSetMetaData::getColumnCount()
81 throw(SQLException, RuntimeException)
83 OSL_TRACE("OResultSetMetaData::getColumnCount");
84 try {
85 return meta->getColumnCount();
86 } catch (const sql::MethodNotImplementedException &) {
87 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
88 } catch (const sql::SQLException &e) {
89 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
91 return 0; // fool compiler
93 /* }}} */
96 /* {{{ OResultSetMetaData::isCaseSensitive() -I- */
97 sal_Bool SAL_CALL OResultSetMetaData::isCaseSensitive(sal_Int32 column)
98 throw(SQLException, RuntimeException)
100 OSL_TRACE("OResultSetMetaData::isCaseSensitive");
101 checkColumnIndex(column);
103 try {
104 return meta->isCaseSensitive(column);
105 } catch (const sql::MethodNotImplementedException &) {
106 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
107 } catch (const sql::SQLException &e) {
108 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
110 return sal_False; // fool compiler
112 /* }}} */
115 /* {{{ OResultSetMetaData::getSchemaName() -I- */
116 OUString SAL_CALL OResultSetMetaData::getSchemaName(sal_Int32 column)
117 throw(SQLException, RuntimeException)
119 OSL_TRACE("OResultSetMetaData::getSchemaName");
120 checkColumnIndex(column);
122 try {
123 return convert(meta->getSchemaName(column));
124 } catch (const sql::MethodNotImplementedException &) {
125 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
126 } catch (const sql::SQLException &e) {
127 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
129 return OUString(); // fool compiler
131 /* }}} */
134 /* {{{ OResultSetMetaData::getColumnName() -I- */
135 OUString SAL_CALL OResultSetMetaData::getColumnName(sal_Int32 column)
136 throw(SQLException, RuntimeException)
138 OSL_TRACE("OResultSetMetaData::getColumnName");
139 checkColumnIndex(column);
141 try {
142 return convert( meta->getColumnName( column ) );
143 } catch (const sql::MethodNotImplementedException &) {
144 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
145 } catch (const sql::SQLException &e) {
146 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
148 return OUString(); // fool compiler
150 /* }}} */
153 /* {{{ OResultSetMetaData::getTableName() -I- */
154 OUString SAL_CALL OResultSetMetaData::getTableName(sal_Int32 column)
155 throw(SQLException, RuntimeException)
157 OSL_TRACE("OResultSetMetaData::getTableName");
158 checkColumnIndex(column);
160 try {
161 return convert(meta->getTableName(column));
162 } catch (const sql::MethodNotImplementedException &) {
163 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
164 } catch (const sql::SQLException &e) {
165 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
167 return OUString(); // fool compiler
169 /* }}} */
172 /* {{{ OResultSetMetaData::getCatalogName() -I- */
173 OUString SAL_CALL OResultSetMetaData::getCatalogName(sal_Int32 column)
174 throw(SQLException, RuntimeException)
176 OSL_TRACE("OResultSetMetaData::getCatalogName");
177 checkColumnIndex(column);
179 try {
180 return convert(meta->getCatalogName(column));
181 } catch (const sql::MethodNotImplementedException &) {
182 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
183 } catch (const sql::SQLException &e) {
184 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
186 return OUString(); // fool compiler
188 /* }}} */
191 /* {{{ OResultSetMetaData::getColumnTypeName() -I- */
192 OUString SAL_CALL OResultSetMetaData::getColumnTypeName(sal_Int32 column)
193 throw(SQLException, RuntimeException)
195 OSL_TRACE("OResultSetMetaData::getColumnTypeName");
196 checkColumnIndex(column);
198 try {
199 return convert(meta->getColumnTypeName(column));
200 } catch (const sql::MethodNotImplementedException &) {
201 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
202 } catch (const sql::SQLException &e) {
203 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
205 return OUString(); // fool compiler
207 /* }}} */
210 /* {{{ OResultSetMetaData::getColumnLabel() -I- */
211 OUString SAL_CALL OResultSetMetaData::getColumnLabel(sal_Int32 column)
212 throw(SQLException, RuntimeException)
214 OSL_TRACE("OResultSetMetaData::getColumnLabel");
215 checkColumnIndex(column);
217 try {
218 return convert(meta->getColumnLabel(column));
219 } catch (const sql::MethodNotImplementedException &) {
220 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
221 } catch (const sql::SQLException &e) {
222 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
224 return OUString(); // fool compiler
226 /* }}} */
229 /* {{{ OResultSetMetaData::getColumnServiceName() -I- */
230 OUString SAL_CALL OResultSetMetaData::getColumnServiceName(sal_Int32 column)
231 throw(SQLException, RuntimeException)
233 OSL_TRACE("OResultSetMetaData::getColumnServiceName");
234 checkColumnIndex(column);
236 OUString aRet = OUString();
237 return aRet;
239 /* }}} */
242 /* {{{ OResultSetMetaData::isCurrency() -I- */
243 sal_Bool SAL_CALL OResultSetMetaData::isCurrency(sal_Int32 column)
244 throw(SQLException, RuntimeException)
246 OSL_TRACE("OResultSetMetaData::isCurrency");
247 checkColumnIndex(column);
249 try {
250 return meta->isCurrency(column)? sal_True:sal_False;
251 } catch (const sql::MethodNotImplementedException &) {
252 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
253 } catch (const sql::SQLException &e) {
254 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
256 return sal_False; // fool compiler
258 /* }}} */
261 /* {{{ OResultSetMetaData::isAutoIncrement() -I- */
262 sal_Bool SAL_CALL OResultSetMetaData::isAutoIncrement(sal_Int32 column)
263 throw(SQLException, RuntimeException)
265 OSL_TRACE("OResultSetMetaData::isAutoIncrement");
266 checkColumnIndex(column);
268 try {
269 return meta->isAutoIncrement(column)? sal_True:sal_False;
270 } catch (const sql::MethodNotImplementedException &) {
271 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
272 } catch (const sql::SQLException &e) {
273 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
275 return sal_False; // fool compiler
277 /* }}} */
280 /* {{{ OResultSetMetaData::isSigned() -I- */
281 sal_Bool SAL_CALL OResultSetMetaData::isSigned(sal_Int32 column)
282 throw(SQLException, RuntimeException)
284 OSL_TRACE("OResultSetMetaData::isSigned");
285 checkColumnIndex(column);
287 try {
288 return meta->isSigned(column)? sal_True:sal_False;
289 } catch (const sql::MethodNotImplementedException &) {
290 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
291 } catch (const sql::SQLException &e) {
292 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
294 return sal_False; // fool compiler
296 /* }}} */
299 /* {{{ OResultSetMetaData::getPrecision() -I- */
300 sal_Int32 SAL_CALL OResultSetMetaData::getPrecision(sal_Int32 column)
301 throw(SQLException, RuntimeException)
303 OSL_TRACE("OResultSetMetaData::getPrecision");
304 checkColumnIndex(column);
306 try {
307 return meta->getPrecision(column);
308 } catch (const sql::MethodNotImplementedException &) {
309 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getPrecision", *this);
310 } catch (const sql::SQLException &e) {
311 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
313 return 0; // fool compiler
315 /* }}} */
318 /* {{{ OResultSetMetaData::getScale() -I- */
319 sal_Int32 SAL_CALL OResultSetMetaData::getScale(sal_Int32 column)
320 throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException)
322 OSL_TRACE("OResultSetMetaData::getScale");
323 checkColumnIndex(column);
324 try {
325 return meta->getScale(column);
326 } catch (const sql::MethodNotImplementedException &) {
327 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getScale", *this);
328 } catch (const sql::SQLException &e) {
329 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
331 return 0; // fool compiler
333 /* }}} */
336 /* {{{ OResultSetMetaData::isNullable() -I- */
337 sal_Int32 SAL_CALL OResultSetMetaData::isNullable(sal_Int32 column)
338 throw(SQLException, RuntimeException)
340 OSL_TRACE("OResultSetMetaData::isNullable");
341 checkColumnIndex(column);
343 try {
344 return meta->isNullable(column)? sal_True:sal_False;
345 } catch (const sql::MethodNotImplementedException &) {
346 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
347 } catch (const sql::SQLException &e) {
348 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
350 return sal_False; // fool compiler
352 /* }}} */
355 /* {{{ OResultSetMetaData::isSearchable() -I- */
356 sal_Bool SAL_CALL OResultSetMetaData::isSearchable(sal_Int32 column)
357 throw(SQLException, RuntimeException)
359 OSL_TRACE("OResultSetMetaData::isSearchable");
360 checkColumnIndex(column);
362 try {
363 return meta->isSearchable(column)? sal_True:sal_False;
364 } catch (const sql::MethodNotImplementedException &) {
365 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
366 } catch (const sql::SQLException &e) {
367 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
369 return sal_False; // fool compiler
371 /* }}} */
374 /* {{{ OResultSetMetaData::isReadOnly() -I- */
375 sal_Bool SAL_CALL OResultSetMetaData::isReadOnly(sal_Int32 column)
376 throw(SQLException, RuntimeException)
378 OSL_TRACE("OResultSetMetaData::isReadOnly");
379 checkColumnIndex(column);
381 try {
382 return meta->isReadOnly(column)? sal_True:sal_False;
383 } catch (const sql::MethodNotImplementedException &) {
384 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
385 } catch (const sql::SQLException &e) {
386 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
388 return sal_False; // fool compiler
390 /* }}} */
393 /* {{{ OResultSetMetaData::isDefinitelyWritable() -I- */
394 sal_Bool SAL_CALL OResultSetMetaData::isDefinitelyWritable(sal_Int32 column)
395 throw(SQLException, RuntimeException)
397 OSL_TRACE("OResultSetMetaData::isDefinitelyWritable");
398 checkColumnIndex(column);
400 try {
401 return meta->isDefinitelyWritable(column)? sal_True:sal_False;
402 } catch (const sql::MethodNotImplementedException &) {
403 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
404 } catch (const sql::SQLException &e) {
405 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
407 return sal_False; // fool compiler
409 /* }}} */
412 /* {{{ OResultSetMetaData::isWritable() -I- */
413 sal_Bool SAL_CALL OResultSetMetaData::isWritable(sal_Int32 column)
414 throw(SQLException, RuntimeException)
416 OSL_TRACE("OResultSetMetaData::isWritable");
417 checkColumnIndex(column);
419 try {
420 return meta->isWritable(column)? sal_True:sal_False;
421 } catch (const sql::MethodNotImplementedException &) {
422 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
423 } catch (const sql::SQLException &e) {
424 mysqlc_sdbc_driver::translateAndThrow(e, *this, m_encoding);
426 return sal_False; // fool compiler
428 /* }}} */
431 /* {{{ OResultSetMetaData::checkColumnIndex() -I- */
432 void OResultSetMetaData::checkColumnIndex(sal_Int32 columnIndex)
433 throw (SQLException, RuntimeException)
435 OSL_TRACE("OResultSetMetaData::checkColumnIndex");
436 if (columnIndex < 1 || columnIndex > (sal_Int32) meta->getColumnCount()) {
438 OUStringBuffer buf;
439 buf.appendAscii( "Column index out of range (expected 1 to " );
440 buf.append( sal_Int32( meta->getColumnCount() ) );
441 buf.appendAscii( ", got " );
442 buf.append( sal_Int32( columnIndex ) );
443 buf.append( sal_Unicode( '.' ) );
444 throw SQLException( buf.makeStringAndClear(), *this, OUString(), 1, Any() );
447 /* }}} */
450 * Local variables:
451 * tab-width: 4
452 * c-basic-offset: 4
453 * End:
454 * vim600: noet sw=4 ts=4 fdm=marker
455 * vim<600: noet sw=4 ts=4
458 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */