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