1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
32 OResultSetMetaData::~OResultSetMetaData()
36 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnDisplaySize(sal_Int32 column
)
37 throw(SQLException
, RuntimeException
, std::exception
)
39 OSL_TRACE("OResultSetMetaData::getColumnDisplaySize");
42 meta
->getColumnDisplaySize(column
);
43 } catch (const sql::MethodNotImplementedException
&) {
44 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getColumnDisplaySize", *this);
45 } catch (const sql::SQLException
&e
) {
46 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
48 return 0; // fool compiler
51 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnType(sal_Int32 column
)
52 throw(SQLException
, RuntimeException
, std::exception
)
54 OSL_TRACE("OResultSetMetaData::getColumnType");
55 checkColumnIndex(column
);
58 return mysqlc_sdbc_driver::mysqlToOOOType(meta
->getColumnType(column
));
59 } catch (const sql::MethodNotImplementedException
&) {
60 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
61 } catch (const sql::SQLException
&e
) {
62 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
64 return 0; // fool compiler
68 XXX: This method doesn't throw exceptions at all.
69 Should it declare that it throws ?? What if throw() is removed?
70 Does it change the API, the open-close principle?
72 sal_Int32 SAL_CALL
OResultSetMetaData::getColumnCount()
73 throw(SQLException
, RuntimeException
, std::exception
)
75 OSL_TRACE("OResultSetMetaData::getColumnCount");
77 return meta
->getColumnCount();
78 } catch (const sql::MethodNotImplementedException
&) {
79 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
80 } catch (const sql::SQLException
&e
) {
81 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
83 return 0; // fool compiler
86 sal_Bool SAL_CALL
OResultSetMetaData::isCaseSensitive(sal_Int32 column
)
87 throw(SQLException
, RuntimeException
, std::exception
)
89 OSL_TRACE("OResultSetMetaData::isCaseSensitive");
90 checkColumnIndex(column
);
93 return meta
->isCaseSensitive(column
);
94 } catch (const sql::MethodNotImplementedException
&) {
95 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
96 } catch (const sql::SQLException
&e
) {
97 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
99 return sal_False
; // fool compiler
102 rtl::OUString SAL_CALL
OResultSetMetaData::getSchemaName(sal_Int32 column
)
103 throw(SQLException
, RuntimeException
, std::exception
)
105 OSL_TRACE("OResultSetMetaData::getSchemaName");
106 checkColumnIndex(column
);
109 return convert(meta
->getSchemaName(column
));
110 } catch (const sql::MethodNotImplementedException
&) {
111 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
112 } catch (const sql::SQLException
&e
) {
113 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
115 return rtl::OUString(); // fool compiler
118 rtl::OUString SAL_CALL
OResultSetMetaData::getColumnName(sal_Int32 column
)
119 throw(SQLException
, RuntimeException
, std::exception
)
121 OSL_TRACE("OResultSetMetaData::getColumnName");
122 checkColumnIndex(column
);
125 return convert( meta
->getColumnName( column
) );
126 } catch (const sql::MethodNotImplementedException
&) {
127 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
128 } catch (const sql::SQLException
&e
) {
129 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
131 return rtl::OUString(); // fool compiler
134 rtl::OUString SAL_CALL
OResultSetMetaData::getTableName(sal_Int32 column
)
135 throw(SQLException
, RuntimeException
, std::exception
)
137 OSL_TRACE("OResultSetMetaData::getTableName");
138 checkColumnIndex(column
);
141 return convert(meta
->getTableName(column
));
142 } catch (const sql::MethodNotImplementedException
&) {
143 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
144 } catch (const sql::SQLException
&e
) {
145 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
147 return rtl::OUString(); // fool compiler
150 rtl::OUString SAL_CALL
OResultSetMetaData::getCatalogName(sal_Int32 column
)
151 throw(SQLException
, RuntimeException
, std::exception
)
153 OSL_TRACE("OResultSetMetaData::getCatalogName");
154 checkColumnIndex(column
);
157 return convert(meta
->getCatalogName(column
));
158 } catch (const sql::MethodNotImplementedException
&) {
159 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
160 } catch (const sql::SQLException
&e
) {
161 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
163 return rtl::OUString(); // fool compiler
166 rtl::OUString SAL_CALL
OResultSetMetaData::getColumnTypeName(sal_Int32 column
)
167 throw(SQLException
, RuntimeException
, std::exception
)
169 OSL_TRACE("OResultSetMetaData::getColumnTypeName");
170 checkColumnIndex(column
);
173 return convert(meta
->getColumnTypeName(column
));
174 } catch (const sql::MethodNotImplementedException
&) {
175 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
176 } catch (const sql::SQLException
&e
) {
177 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
179 return rtl::OUString(); // fool compiler
182 rtl::OUString SAL_CALL
OResultSetMetaData::getColumnLabel(sal_Int32 column
)
183 throw(SQLException
, RuntimeException
, std::exception
)
185 OSL_TRACE("OResultSetMetaData::getColumnLabel");
186 checkColumnIndex(column
);
189 return convert(meta
->getColumnLabel(column
));
190 } catch (const sql::MethodNotImplementedException
&) {
191 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
192 } catch (const sql::SQLException
&e
) {
193 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
195 return rtl::OUString(); // fool compiler
198 rtl::OUString SAL_CALL
OResultSetMetaData::getColumnServiceName(sal_Int32 column
)
199 throw(SQLException
, RuntimeException
, std::exception
)
201 OSL_TRACE("OResultSetMetaData::getColumnServiceName");
202 checkColumnIndex(column
);
204 rtl::OUString aRet
= rtl::OUString();
208 sal_Bool SAL_CALL
OResultSetMetaData::isCurrency(sal_Int32 column
)
209 throw(SQLException
, RuntimeException
, std::exception
)
211 OSL_TRACE("OResultSetMetaData::isCurrency");
212 checkColumnIndex(column
);
215 return meta
->isCurrency(column
)? sal_True
:sal_False
;
216 } catch (const sql::MethodNotImplementedException
&) {
217 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
218 } catch (const sql::SQLException
&e
) {
219 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
221 return sal_False
; // fool compiler
224 sal_Bool SAL_CALL
OResultSetMetaData::isAutoIncrement(sal_Int32 column
)
225 throw(SQLException
, RuntimeException
, std::exception
)
227 OSL_TRACE("OResultSetMetaData::isAutoIncrement");
228 checkColumnIndex(column
);
231 return meta
->isAutoIncrement(column
)? sal_True
:sal_False
;
232 } catch (const sql::MethodNotImplementedException
&) {
233 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
234 } catch (const sql::SQLException
&e
) {
235 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
237 return sal_False
; // fool compiler
240 sal_Bool SAL_CALL
OResultSetMetaData::isSigned(sal_Int32 column
)
241 throw(SQLException
, RuntimeException
, std::exception
)
243 OSL_TRACE("OResultSetMetaData::isSigned");
244 checkColumnIndex(column
);
247 return meta
->isSigned(column
)? sal_True
:sal_False
;
248 } catch (const sql::MethodNotImplementedException
&) {
249 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
250 } catch (const sql::SQLException
&e
) {
251 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
253 return sal_False
; // fool compiler
256 sal_Int32 SAL_CALL
OResultSetMetaData::getPrecision(sal_Int32 column
)
257 throw(SQLException
, RuntimeException
, std::exception
)
259 OSL_TRACE("OResultSetMetaData::getPrecision");
260 checkColumnIndex(column
);
263 return meta
->getPrecision(column
);
264 } catch (const sql::MethodNotImplementedException
&) {
265 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getPrecision", *this);
266 } catch (const sql::SQLException
&e
) {
267 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
269 return 0; // fool compiler
272 sal_Int32 SAL_CALL
OResultSetMetaData::getScale(sal_Int32 column
)
273 throw(::com::sun::star::sdbc::SQLException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
275 OSL_TRACE("OResultSetMetaData::getScale");
276 checkColumnIndex(column
);
278 return meta
->getScale(column
);
279 } catch (const sql::MethodNotImplementedException
&) {
280 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getScale", *this);
281 } catch (const sql::SQLException
&e
) {
282 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
284 return 0; // fool compiler
287 sal_Int32 SAL_CALL
OResultSetMetaData::isNullable(sal_Int32 column
)
288 throw(SQLException
, RuntimeException
, std::exception
)
290 OSL_TRACE("OResultSetMetaData::isNullable");
291 checkColumnIndex(column
);
294 return sal_Int32(bool(meta
->isNullable(column
)));
295 } catch (const sql::MethodNotImplementedException
&) {
296 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
297 } catch (const sql::SQLException
&e
) {
298 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
300 return sal_Int32(false); // fool compiler
303 sal_Bool SAL_CALL
OResultSetMetaData::isSearchable(sal_Int32 column
)
304 throw(SQLException
, RuntimeException
, std::exception
)
306 OSL_TRACE("OResultSetMetaData::isSearchable");
307 checkColumnIndex(column
);
310 return meta
->isSearchable(column
)? sal_True
:sal_False
;
311 } catch (const sql::MethodNotImplementedException
&) {
312 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
313 } catch (const sql::SQLException
&e
) {
314 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
316 return sal_False
; // fool compiler
319 sal_Bool SAL_CALL
OResultSetMetaData::isReadOnly(sal_Int32 column
)
320 throw(SQLException
, RuntimeException
, std::exception
)
322 OSL_TRACE("OResultSetMetaData::isReadOnly");
323 checkColumnIndex(column
);
326 return meta
->isReadOnly(column
)? sal_True
:sal_False
;
327 } catch (const sql::MethodNotImplementedException
&) {
328 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
329 } catch (const sql::SQLException
&e
) {
330 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
332 return sal_False
; // fool compiler
335 sal_Bool SAL_CALL
OResultSetMetaData::isDefinitelyWritable(sal_Int32 column
)
336 throw(SQLException
, RuntimeException
, std::exception
)
338 OSL_TRACE("OResultSetMetaData::isDefinitelyWritable");
339 checkColumnIndex(column
);
342 return meta
->isDefinitelyWritable(column
)? sal_True
:sal_False
;
343 } catch (const sql::MethodNotImplementedException
&) {
344 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
345 } catch (const sql::SQLException
&e
) {
346 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
348 return sal_False
; // fool compiler
351 sal_Bool SAL_CALL
OResultSetMetaData::isWritable(sal_Int32 column
)
352 throw(SQLException
, RuntimeException
, std::exception
)
354 OSL_TRACE("OResultSetMetaData::isWritable");
355 checkColumnIndex(column
);
358 return meta
->isWritable(column
)? sal_True
:sal_False
;
359 } catch (const sql::MethodNotImplementedException
&) {
360 mysqlc_sdbc_driver::throwFeatureNotImplementedException("OResultSetMetaData::getMetaData", *this);
361 } catch (const sql::SQLException
&e
) {
362 mysqlc_sdbc_driver::translateAndThrow(e
, *this, m_encoding
);
364 return sal_False
; // fool compiler
367 void OResultSetMetaData::checkColumnIndex(sal_Int32 columnIndex
)
368 throw (SQLException
, RuntimeException
)
370 OSL_TRACE("OResultSetMetaData::checkColumnIndex");
371 if (columnIndex
< 1 || columnIndex
> (sal_Int32
) meta
->getColumnCount()) {
373 rtl::OUStringBuffer buf
;
374 buf
.appendAscii( "Column index out of range (expected 1 to " );
375 buf
.append( sal_Int32( meta
->getColumnCount() ) );
376 buf
.appendAscii( ", got " );
377 buf
.append( sal_Int32( columnIndex
) );
379 throw SQLException( buf
.makeStringAndClear(), *this, rtl::OUString(), 1, Any() );
388 * vim600: noet sw=4 ts=4 fdm=marker
389 * vim<600: noet sw=4 ts=4
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */