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
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_connectivity.hxx"
26
27 #include "ParameterSubstitution.hxx"
28 #include "FDatabaseMetaDataResultSet.hxx"
29 #include "FDatabaseMetaDataResultSetMetaData.hxx"
30 #include <com/sun/star/sdbc/DataType.hpp>
31 #include <com/sun/star/sdbc/ColumnSearch.hpp>
32 #include <com/sun/star/sdbc/KeyRule.hpp>
33 #include <com/sun/star/sdbc/ProcedureResult.hpp>
34 #include <com/sun/star/sdbc/IndexType.hpp>
35 #include <comphelper/property.hxx>
36 #include <com/sun/star/lang/DisposedException.hpp>
37 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
38 #include <com/sun/star/sdbc/ResultSetType.hpp>
39 #include <com/sun/star/sdbc/FetchDirection.hpp>
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
41 #include <cppuhelper/typeprovider.hxx>
42 #include <comphelper/sequence.hxx>
43 #include <cppuhelper/factory.hxx>
44 #include <cppuhelper/implementationentry.hxx>
45 #include "connectivity/dbexception.hxx"
46 #include "TConnection.hxx"
47
48 using namespace connectivity;
49 using namespace dbtools;
50 using namespace cppu;
51 //------------------------------------------------------------------------------
52 using namespace ::com::sun::star::beans;
53 using namespace ::com::sun::star::uno;
54 using namespace ::com::sun::star::sdbcx;
55 using namespace ::com::sun::star::sdbc;
56 using namespace ::com::sun::star::container;
57 using namespace ::com::sun::star::lang;
58 // -------------------------------------------------------------------------
ODatabaseMetaDataResultSet()59 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet()
60 :ODatabaseMetaDataResultSet_BASE(m_aMutex)
61 ,::comphelper::OPropertyContainer(ODatabaseMetaDataResultSet_BASE::rBHelper)
62 ,m_aStatement(NULL)
63 ,m_xMetaData(NULL)
64 ,m_bBOF(sal_True)
65 ,m_bEOF(sal_True)
66 {
67 construct();
68 }
69
70 // -------------------------------------------------------------------------
ODatabaseMetaDataResultSet(MetaDataResultSetType _eType)71 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet( MetaDataResultSetType _eType )
72 :ODatabaseMetaDataResultSet_BASE(m_aMutex)
73 ,::comphelper::OPropertyContainer(ODatabaseMetaDataResultSet_BASE::rBHelper)
74 ,m_aStatement(NULL)
75 ,m_xMetaData(NULL)
76 ,m_bBOF(sal_True)
77 ,m_bEOF(sal_True)
78 {
79 construct();
80
81 setType(_eType);
82 }
83
84 // -------------------------------------------------------------------------
~ODatabaseMetaDataResultSet()85 ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
86 {
87 }
88 // -------------------------------------------------------------------------
construct()89 void ODatabaseMetaDataResultSet::construct()
90 {
91 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHSIZE), PROPERTY_ID_FETCHSIZE, 0,&m_nFetchSize, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
92 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETTYPE), PROPERTY_ID_RESULTSETTYPE, PropertyAttribute::READONLY,&m_nResultSetType, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
93 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_FETCHDIRECTION), PROPERTY_ID_FETCHDIRECTION, 0, &m_nFetchDirection, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
94 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_RESULTSETCONCURRENCY), PROPERTY_ID_RESULTSETCONCURRENCY, PropertyAttribute::READONLY,&m_nResultSetConcurrency, ::getCppuType(reinterpret_cast<sal_Int32*>(NULL)));
95 }
96 // -----------------------------------------------------------------------------
setType(MetaDataResultSetType _eType)97 void ODatabaseMetaDataResultSet::setType(MetaDataResultSetType _eType)
98 {
99 switch( _eType )
100 {
101 case eCatalogs: setCatalogsMap(); break;
102 case eSchemas: setSchemasMap(); break;
103 case eColumnPrivileges: setColumnPrivilegesMap(); break;
104 case eColumns: setColumnsMap(); break;
105 case eTables: setTablesMap(); break;
106 case eTableTypes: setTableTypes(); break;
107 case eProcedureColumns: setProcedureColumnsMap(); break;
108 case eProcedures: setProceduresMap(); break;
109 case eExportedKeys: setExportedKeysMap(); break;
110 case eImportedKeys: setImportedKeysMap(); break;
111 case ePrimaryKeys: setPrimaryKeysMap(); break;
112 case eIndexInfo: setIndexInfoMap(); break;
113 case eTablePrivileges: setTablePrivilegesMap(); break;
114 case eCrossReference: setCrossReferenceMap(); break;
115 case eTypeInfo: setTypeInfoMap(); break;
116 case eBestRowIdentifier: setBestRowIdentifierMap(); break;
117 case eVersionColumns: setVersionColumnsMap(); break;
118 default:
119 OSL_ENSURE(0,"Wrong type!");
120 }
121 }
122 // -------------------------------------------------------------------------
disposing(void)123 void ODatabaseMetaDataResultSet::disposing(void)
124 {
125 OPropertySetHelper::disposing();
126
127 ::osl::MutexGuard aGuard(m_aMutex);
128 m_aStatement = NULL;
129 m_xMetaData.clear();
130 m_aRowsIter = m_aRows.end();
131 m_aRows.clear();
132 m_aRowsIter = m_aRows.end();
133 }
134 // -----------------------------------------------------------------------------
acquire()135 void SAL_CALL ODatabaseMetaDataResultSet::acquire() throw()
136 {
137 ODatabaseMetaDataResultSet_BASE::acquire();
138 }
139 // -----------------------------------------------------------------------------
release()140 void SAL_CALL ODatabaseMetaDataResultSet::release() throw()
141 {
142 ODatabaseMetaDataResultSet_BASE::release();
143 }
144 // -------------------------------------------------------------------------
queryInterface(const Type & rType)145 Any SAL_CALL ODatabaseMetaDataResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
146 {
147 Any aRet = OPropertySetHelper::queryInterface(rType);
148 return aRet.hasValue() ? aRet : ODatabaseMetaDataResultSet_BASE::queryInterface(rType);
149 }
150 // -------------------------------------------------------------------------
getTypes()151 Sequence< Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes( ) throw(RuntimeException)
152 {
153 ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< ::com::sun::star::beans::XMultiPropertySet > *)0 ),
154 ::getCppuType( (const Reference< ::com::sun::star::beans::XFastPropertySet > *)0 ),
155 ::getCppuType( (const Reference< ::com::sun::star::beans::XPropertySet > *)0 ));
156
157 return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
158 }
159 // -----------------------------------------------------------------------------
setRows(const ORows & _rRows)160 void ODatabaseMetaDataResultSet::setRows(const ORows& _rRows)
161 {
162 m_aRows = _rRows;
163 m_bBOF = sal_True;
164 m_bEOF = m_aRows.empty();
165 }
166 // -------------------------------------------------------------------------
findColumn(const::rtl::OUString & columnName)167 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
168 {
169 ::osl::MutexGuard aGuard( m_aMutex );
170 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
171
172
173 Reference< XResultSetMetaData > xMeta = getMetaData();
174 sal_Int32 nLen = xMeta->getColumnCount();
175 sal_Int32 i = 1;
176 for(;i<=nLen;++i)
177 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
178 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i))
179 )
180 break;
181 return i;
182 }
183 // -----------------------------------------------------------------------------
checkIndex(sal_Int32 columnIndex)184 void ODatabaseMetaDataResultSet::checkIndex(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc::SQLException)
185 {
186 if(columnIndex >= (sal_Int32)(*m_aRowsIter).size() || columnIndex < 1)
187 ::dbtools::throwInvalidIndexException(*this);
188 }
189 // -------------------------------------------------------------------------
getBinaryStream(sal_Int32)190 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
191 {
192 return NULL;
193 }
194 // -------------------------------------------------------------------------
getCharacterStream(sal_Int32)195 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
196 {
197 return NULL;
198 }
199
200 // -------------------------------------------------------------------------
getBoolean(sal_Int32 columnIndex)201 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
202 {
203 return getValue(columnIndex);
204 }
205 // -------------------------------------------------------------------------
206
getByte(sal_Int32 columnIndex)207 sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
208 {
209 return getValue(columnIndex);
210 }
211 // -------------------------------------------------------------------------
212
getBytes(sal_Int32 columnIndex)213 Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
214 {
215 return getValue(columnIndex);
216 }
217 // -------------------------------------------------------------------------
218
getDate(sal_Int32 columnIndex)219 ::com::sun::star::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
220 {
221 return getValue(columnIndex);
222 }
223 // -------------------------------------------------------------------------
224
getDouble(sal_Int32 columnIndex)225 double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
226 {
227 return getValue(columnIndex);
228 }
229 // -------------------------------------------------------------------------
230
getFloat(sal_Int32 columnIndex)231 float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
232 {
233 return getValue(columnIndex);
234 }
235 // -------------------------------------------------------------------------
236
getInt(sal_Int32 columnIndex)237 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
238 {
239 return getValue(columnIndex);
240 }
241
242 // -------------------------------------------------------------------------
243
getRow()244 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow( ) throw(SQLException, RuntimeException)
245 {
246 return 0;
247 }
248 // -------------------------------------------------------------------------
249
getLong(sal_Int32 columnIndex)250 sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
251 {
252 return getValue(columnIndex);
253 }
254 // -------------------------------------------------------------------------
255
getMetaData()256 Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData( ) throw(SQLException, RuntimeException)
257 {
258 ::osl::MutexGuard aGuard( m_aMutex );
259 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
260
261
262 if(!m_xMetaData.is())
263 m_xMetaData = new ODatabaseMetaDataResultSetMetaData();
264
265 return m_xMetaData;
266 }
267 // -------------------------------------------------------------------------
getArray(sal_Int32)268 Reference< XArray > SAL_CALL ODatabaseMetaDataResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
269 {
270 return NULL;
271 }
272
273 // -------------------------------------------------------------------------
274
getClob(sal_Int32)275 Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
276 {
277 return NULL;
278 }
279 // -------------------------------------------------------------------------
getBlob(sal_Int32)280 Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
281 {
282 return NULL;
283 }
284 // -------------------------------------------------------------------------
285
getRef(sal_Int32)286 Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
287 {
288 return NULL;
289 }
290 // -------------------------------------------------------------------------
291
getObject(sal_Int32 columnIndex,const Reference<::com::sun::star::container::XNameAccess> &)292 Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 columnIndex, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
293 {
294 return getValue(columnIndex).makeAny();
295 }
296 // -------------------------------------------------------------------------
297
getShort(sal_Int32 columnIndex)298 sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
299 {
300 return getValue(columnIndex);
301 }
302 // -------------------------------------------------------------------------
303
getString(sal_Int32 columnIndex)304 ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
305 {
306 return getValue(columnIndex);
307 }
308
309 // -------------------------------------------------------------------------
310
311
getTime(sal_Int32 columnIndex)312 ::com::sun::star::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
313 {
314 return getValue(columnIndex);
315 }
316 // -------------------------------------------------------------------------
317
318
getTimestamp(sal_Int32 columnIndex)319 ::com::sun::star::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
320 {
321 return getValue(columnIndex);
322 }
323 // -------------------------------------------------------------------------
324
isAfterLast()325 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
326 {
327 return m_bEOF;
328 }
329 // -------------------------------------------------------------------------
isFirst()330 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst( ) throw(SQLException, RuntimeException)
331 {
332 ::dbtools::throwFunctionSequenceException(*this);
333 return sal_False;
334 }
335 // -------------------------------------------------------------------------
isLast()336 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast( ) throw(SQLException, RuntimeException)
337 {
338 ::dbtools::throwFunctionSequenceException(*this);
339 return sal_False;
340 }
341 // -------------------------------------------------------------------------
beforeFirst()342 void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
343 {
344 ::dbtools::throwFunctionSequenceException(*this);
345 }
346 // -------------------------------------------------------------------------
afterLast()347 void SAL_CALL ODatabaseMetaDataResultSet::afterLast( ) throw(SQLException, RuntimeException)
348 {
349 ::dbtools::throwFunctionSequenceException(*this);
350 }
351 // -------------------------------------------------------------------------
352
close()353 void SAL_CALL ODatabaseMetaDataResultSet::close( ) throw(SQLException, RuntimeException)
354 {
355 {
356 ::osl::MutexGuard aGuard( m_aMutex );
357 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
358
359 }
360 dispose();
361 }
362 // -------------------------------------------------------------------------
363
first()364 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first( ) throw(SQLException, RuntimeException)
365 {
366 ::dbtools::throwFunctionSequenceException(*this);
367 return sal_False;
368 }
369 // -------------------------------------------------------------------------
370
last()371 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last( ) throw(SQLException, RuntimeException)
372 {
373 ::dbtools::throwFunctionSequenceException(*this);
374 return sal_False;
375 }
376 // -------------------------------------------------------------------------
absolute(sal_Int32)377 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 /*row*/ ) throw(SQLException, RuntimeException)
378 {
379 ::dbtools::throwFunctionSequenceException(*this);
380 return sal_False;
381 }
382 // -------------------------------------------------------------------------
relative(sal_Int32)383 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 /*row*/ ) throw(SQLException, RuntimeException)
384 {
385 ::dbtools::throwFunctionSequenceException(*this);
386 return sal_False;
387 }
388 // -------------------------------------------------------------------------
previous()389 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous( ) throw(SQLException, RuntimeException)
390 {
391 ::dbtools::throwFunctionSequenceException(*this);
392 return sal_False;
393 }
394 // -------------------------------------------------------------------------
getStatement()395 Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( ) throw(SQLException, RuntimeException)
396 {
397 return m_aStatement.get();
398 }
399 // -------------------------------------------------------------------------
400
rowDeleted()401 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted( ) throw(SQLException, RuntimeException)
402 {
403 ::dbtools::throwFunctionSequenceException(*this);
404 return sal_False;
405 }
406 // -------------------------------------------------------------------------
rowInserted()407 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted( ) throw(SQLException, RuntimeException)
408 {
409 ::dbtools::throwFunctionSequenceException(*this);
410 return sal_False;
411 }
412 // -------------------------------------------------------------------------
rowUpdated()413 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
414 {
415 ::dbtools::throwFunctionSequenceException(*this);
416 return sal_False;
417 }
418 // -------------------------------------------------------------------------
419
isBeforeFirst()420 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
421 {
422 return m_bBOF;
423 }
424 // -------------------------------------------------------------------------
425
next()426 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( ) throw(SQLException, RuntimeException)
427 {
428 ::osl::MutexGuard aGuard( m_aMutex );
429 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
430
431 if ( m_bBOF )
432 {
433 m_aRowsIter = m_aRows.begin();
434 m_bBOF = sal_False;
435 }
436 else
437 {
438 if ( m_bEOF )
439 throwFunctionSequenceException( *this );
440 else
441 if ( m_aRowsIter != m_aRows.end() )
442 ++m_aRowsIter;
443 }
444
445 bool bSuccess = m_aRowsIter != m_aRows.end();
446 if ( !bSuccess )
447 {
448 m_bEOF = sal_True;
449 m_bBOF = m_aRows.empty();
450 }
451 return bSuccess;
452 }
453 // -------------------------------------------------------------------------
454
wasNull()455 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull( ) throw(SQLException, RuntimeException)
456 {
457 ::osl::MutexGuard aGuard( m_aMutex );
458 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
459
460
461 if(m_aRowsIter == m_aRows.end() || !(*m_aRowsIter)[m_nColPos].isValid())
462 return sal_True;
463
464 return (*m_aRowsIter)[m_nColPos]->getValue().isNull();
465 }
466 // -------------------------------------------------------------------------
refreshRow()467 void SAL_CALL ODatabaseMetaDataResultSet::refreshRow( ) throw(SQLException, RuntimeException)
468 {
469 }
470 // -------------------------------------------------------------------------
471
cancel()472 void SAL_CALL ODatabaseMetaDataResultSet::cancel( ) throw(RuntimeException)
473 {
474 }
475 // -------------------------------------------------------------------------
clearWarnings()476 void SAL_CALL ODatabaseMetaDataResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
477 {
478 }
479 // -------------------------------------------------------------------------
getWarnings()480 Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings( ) throw(SQLException, RuntimeException)
481 {
482 return Any();
483 }
484 // -------------------------------------------------------------------------
createArrayHelper() const485 ::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const
486 {
487 Sequence< Property > aProps;
488 describeProperties(aProps);
489 return new ::cppu::OPropertyArrayHelper(aProps);
490 }
491 // -------------------------------------------------------------------------
getInfoHelper()492 ::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper()
493 {
494 return *const_cast<ODatabaseMetaDataResultSet*>(this)->getArrayHelper();
495 }
496 // -------------------------------------------------------------------------
setProceduresMap()497 void ODatabaseMetaDataResultSet::setProceduresMap()
498 {
499 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
500 pMetaData->setProceduresMap();
501 m_xMetaData = pMetaData;
502 }
503 // -------------------------------------------------------------------------
setCatalogsMap()504 void ODatabaseMetaDataResultSet::setCatalogsMap()
505 {
506 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
507 pMetaData->setCatalogsMap();
508 m_xMetaData = pMetaData;
509 }
510 // -------------------------------------------------------------------------
setSchemasMap()511 void ODatabaseMetaDataResultSet::setSchemasMap()
512 {
513 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
514 pMetaData->setSchemasMap();
515 m_xMetaData = pMetaData;
516 }
517 // -------------------------------------------------------------------------
setColumnPrivilegesMap()518 void ODatabaseMetaDataResultSet::setColumnPrivilegesMap()
519 {
520 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
521 pMetaData->setColumnPrivilegesMap();
522 m_xMetaData = pMetaData;
523 }
524 // -------------------------------------------------------------------------
setColumnsMap()525 void ODatabaseMetaDataResultSet::setColumnsMap()
526 {
527
528 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
529 pMetaData->setColumnsMap();
530 m_xMetaData = pMetaData;
531 }
532 // -------------------------------------------------------------------------
setTablesMap()533 void ODatabaseMetaDataResultSet::setTablesMap()
534 {
535
536 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
537 pMetaData->setTablesMap();
538 m_xMetaData = pMetaData;
539 }
540 // -------------------------------------------------------------------------
setProcedureColumnsMap()541 void ODatabaseMetaDataResultSet::setProcedureColumnsMap()
542 {
543 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
544 pMetaData->setProcedureColumnsMap();
545 m_xMetaData = pMetaData;
546 }
547 // -------------------------------------------------------------------------
setPrimaryKeysMap()548 void ODatabaseMetaDataResultSet::setPrimaryKeysMap()
549 {
550 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
551 pMetaData->setPrimaryKeysMap();
552 m_xMetaData = pMetaData;
553 }
554 // -------------------------------------------------------------------------
setIndexInfoMap()555 void ODatabaseMetaDataResultSet::setIndexInfoMap()
556 {
557 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
558 pMetaData->setIndexInfoMap();
559 m_xMetaData = pMetaData;
560 }
561 // -------------------------------------------------------------------------
setTablePrivilegesMap()562 void ODatabaseMetaDataResultSet::setTablePrivilegesMap()
563 {
564 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
565 pMetaData->setTablePrivilegesMap();
566 m_xMetaData = pMetaData;
567 }
568 // -------------------------------------------------------------------------
setCrossReferenceMap()569 void ODatabaseMetaDataResultSet::setCrossReferenceMap()
570 {
571 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
572 pMetaData->setCrossReferenceMap();
573 m_xMetaData = pMetaData;
574 }
575 // -------------------------------------------------------------------------
setVersionColumnsMap()576 void ODatabaseMetaDataResultSet::setVersionColumnsMap()
577 {
578 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
579 pMetaData->setVersionColumnsMap();
580 m_xMetaData = pMetaData;
581 }
582 // -------------------------------------------------------------------------
setBestRowIdentifierMap()583 void ODatabaseMetaDataResultSet::setBestRowIdentifierMap()
584 {
585 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
586 pMetaData->setBestRowIdentifierMap();
587 m_xMetaData = pMetaData;
588 }
589 // -------------------------------------------------------------------------
setTypeInfoMap()590 void ODatabaseMetaDataResultSet::setTypeInfoMap()
591 {
592 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
593 pMetaData->setTypeInfoMap();
594 m_xMetaData = pMetaData;
595 }
596 // -------------------------------------------------------------------------
setTableTypes()597 void ODatabaseMetaDataResultSet::setTableTypes()
598 {
599 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
600 pMetaData->setTableTypes();
601 m_xMetaData = pMetaData;
602 }
603 // -------------------------------------------------------------------------
setExportedKeysMap()604 void ODatabaseMetaDataResultSet::setExportedKeysMap()
605 {
606 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
607 pMetaData->setExportedKeysMap();
608 m_xMetaData = pMetaData;
609 }
610 // -------------------------------------------------------------------------
setImportedKeysMap()611 void ODatabaseMetaDataResultSet::setImportedKeysMap()
612 {
613 ODatabaseMetaDataResultSetMetaData* pMetaData = new ODatabaseMetaDataResultSetMetaData();
614 pMetaData->setImportedKeysMap();
615 m_xMetaData = pMetaData;
616 }
617 // -----------------------------------------------------------------------------
getPropertySetInfo()618 Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL ODatabaseMetaDataResultSet::getPropertySetInfo( ) throw(RuntimeException)
619 {
620 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
621 }
622 // -----------------------------------------------------------------------------
operator =(const ORowSetValue & _aValue)623 ORowSetValueDecorator& ORowSetValueDecorator::operator=(const ORowSetValue& _aValue)
624 {
625 m_aValue = _aValue;
626 return *this;
627 }
628 // -----------------------------------------------------------------------------
getValue(sal_Int32 columnIndex)629 const ORowSetValue& ODatabaseMetaDataResultSet::getValue(sal_Int32 columnIndex)
630 {
631 ::osl::MutexGuard aGuard( m_aMutex );
632 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
633
634 if ( isBeforeFirst() || isAfterLast() )
635 ::dbtools::throwFunctionSequenceException( *this );
636
637 checkIndex(columnIndex );
638 m_nColPos = columnIndex;
639
640 if(m_aRowsIter != m_aRows.end() && (*m_aRowsIter)[columnIndex].isValid())
641 return *(*m_aRowsIter)[columnIndex];
642 return m_aEmptyValue;
643 }
644 // -----------------------------------------------------------------------------
645 /// return an empty ORowSetValueDecorator
getEmptyValue()646 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getEmptyValue()
647 {
648 static ORowSetValueDecoratorRef aEmptyValueRef = new ORowSetValueDecorator();
649 return aEmptyValueRef;
650 }
651 // -----------------------------------------------------------------------------
652 /// return an ORowSetValueDecorator with 0 as value
get0Value()653 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::get0Value()
654 {
655 static ORowSetValueDecoratorRef a0ValueRef = new ORowSetValueDecorator((sal_Int32)0);
656 return a0ValueRef;
657 }
658 // -----------------------------------------------------------------------------
659 /// return an ORowSetValueDecorator with 1 as value
get1Value()660 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::get1Value()
661 {
662 static ORowSetValueDecoratorRef a1ValueRef = new ORowSetValueDecorator((sal_Int32)1);
663 return a1ValueRef;
664 }
665 // -----------------------------------------------------------------------------
666 /// return an ORowSetValueDecorator with ColumnSearch::BASIC as value
getBasicValue()667 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getBasicValue()
668 {
669 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(ColumnSearch::BASIC);
670 return aValueRef;
671 }
672 // -----------------------------------------------------------------------------
getSelectValue()673 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getSelectValue()
674 {
675 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("SELECT"));
676 return aValueRef;
677 }
678 // -----------------------------------------------------------------------------
getInsertValue()679 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getInsertValue()
680 {
681 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("INSERT"));
682 return aValueRef;
683 }
684 // -----------------------------------------------------------------------------
getDeleteValue()685 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getDeleteValue()
686 {
687 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("DELETE"));
688 return aValueRef;
689 }
690 // -----------------------------------------------------------------------------
getUpdateValue()691 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getUpdateValue()
692 {
693 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("UPDATE"));
694 return aValueRef;
695 }
696 // -----------------------------------------------------------------------------
getCreateValue()697 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getCreateValue()
698 {
699 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("CREATE"));
700 return aValueRef;
701 }
702 // -----------------------------------------------------------------------------
getReadValue()703 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getReadValue()
704 {
705 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("READ"));
706 return aValueRef;
707 }
708 // -----------------------------------------------------------------------------
getAlterValue()709 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getAlterValue()
710 {
711 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("ALTER"));
712 return aValueRef;
713 }
714 // -----------------------------------------------------------------------------
getDropValue()715 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getDropValue()
716 {
717 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("DROP"));
718 return aValueRef;
719 }
720 // -----------------------------------------------------------------------------
getQuoteValue()721 ORowSetValueDecoratorRef ODatabaseMetaDataResultSet::getQuoteValue()
722 {
723 static ORowSetValueDecoratorRef aValueRef = new ORowSetValueDecorator(::rtl::OUString::createFromAscii("'"));
724 return aValueRef;
725 }
726 // -----------------------------------------------------------------------------
initialize(const Sequence<Any> & _aArguments)727 void SAL_CALL ODatabaseMetaDataResultSet::initialize( const Sequence< Any >& _aArguments ) throw (Exception, RuntimeException)
728 {
729 if ( _aArguments.getLength() == 2 )
730 {
731 sal_Int32 nResultSetType = 0;
732 if ( _aArguments[0] >>= nResultSetType)
733 {
734 setType(static_cast<MetaDataResultSetType>(nResultSetType));
735 Sequence< Sequence<Any> > aRows;
736 if ( _aArguments[1] >>= aRows )
737 {
738 ORows aRowsToSet;
739 const Sequence<Any>* pRowsIter = aRows.getConstArray();
740 const Sequence<Any>* pRowsEnd = pRowsIter + aRows.getLength();
741 for (; pRowsIter != pRowsEnd;++pRowsIter)
742 {
743 ORow aRowToSet;
744 const Any* pRowIter = pRowsIter->getConstArray();
745 const Any* pRowEnd = pRowIter + pRowsIter->getLength();
746 for (; pRowIter != pRowEnd;++pRowIter)
747 {
748 ORowSetValueDecoratorRef aValue;
749 switch( pRowIter->getValueTypeClass() )
750 {
751 case TypeClass_BOOLEAN:
752 {
753 sal_Bool bValue = sal_False;
754 *pRowIter >>= bValue;
755 aValue = new ORowSetValueDecorator(ORowSetValue(bValue));
756 }
757 break;
758 case TypeClass_BYTE:
759 {
760 sal_Int8 nValue(0);
761 *pRowIter >>= nValue;
762 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
763 }
764 break;
765 case TypeClass_SHORT:
766 case TypeClass_UNSIGNED_SHORT:
767 {
768 sal_Int16 nValue(0);
769 *pRowIter >>= nValue;
770 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
771 }
772 break;
773 case TypeClass_LONG:
774 case TypeClass_UNSIGNED_LONG:
775 {
776 sal_Int32 nValue(0);
777 *pRowIter >>= nValue;
778 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
779 }
780 break;
781 case TypeClass_HYPER:
782 case TypeClass_UNSIGNED_HYPER:
783 {
784 sal_Int64 nValue(0);
785 *pRowIter >>= nValue;
786 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
787 }
788 break;
789 case TypeClass_FLOAT:
790 {
791 float nValue(0.0);
792 *pRowIter >>= nValue;
793 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
794 }
795 break;
796 case TypeClass_DOUBLE:
797 {
798 double nValue(0.0);
799 *pRowIter >>= nValue;
800 aValue = new ORowSetValueDecorator(ORowSetValue(nValue));
801 }
802 break;
803 case TypeClass_STRING:
804 {
805 ::rtl::OUString sValue;
806 *pRowIter >>= sValue;
807 aValue = new ORowSetValueDecorator(ORowSetValue(sValue));
808 }
809 break;
810 default:
811 break;
812 }
813 aRowToSet.push_back(aValue);
814 }
815 aRowsToSet.push_back(aRowToSet);
816 } // for (; pRowsIter != pRowsEnd;++pRowsIter
817 setRows(aRowsToSet);
818 }
819 }
820 }
821 }
822 // XServiceInfo
823 // --------------------------------------------------------------------------------
824 //------------------------------------------------------------------------------
getImplementationName_Static()825 rtl::OUString ODatabaseMetaDataResultSet::getImplementationName_Static( ) throw(RuntimeException)
826 {
827 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.helper.DatabaseMetaDataResultSet"));
828 }
829 //------------------------------------------------------------------------------
getSupportedServiceNames_Static()830 Sequence< ::rtl::OUString > ODatabaseMetaDataResultSet::getSupportedServiceNames_Static( ) throw (RuntimeException)
831 {
832 Sequence< ::rtl::OUString > aSNS( 1 );
833 aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.ResultSet");
834 return aSNS;
835 }
836 //------------------------------------------------------------------
getImplementationName()837 ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSet::getImplementationName( ) throw(RuntimeException)
838 {
839 return getImplementationName_Static();
840 }
841
842 //------------------------------------------------------------------
supportsService(const::rtl::OUString & _rServiceName)843 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
844 {
845 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
846 const ::rtl::OUString* pSupported = aSupported.getConstArray();
847 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
848 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
849 ;
850
851 return pSupported != pEnd;
852 }
853 //------------------------------------------------------------------
getSupportedServiceNames()854 Sequence< ::rtl::OUString > SAL_CALL ODatabaseMetaDataResultSet::getSupportedServiceNames( ) throw(RuntimeException)
855 {
856 return getSupportedServiceNames_Static();
857 }
858 // -------------------------------------------------------------------------
859 namespace connectivity
860 {
ODatabaseMetaDataResultSet_CreateInstance(const Reference<XComponentContext> &)861 Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet_CreateInstance(const Reference< XComponentContext >& ) throw( Exception )
862 {
863 return *(new ODatabaseMetaDataResultSet());
864 }
865 }
866
867 // -----------------------------------------------------------------------------
868 namespace
869 {
870 cppu::ImplementationEntry entries[] = {
871 { &ODatabaseMetaDataResultSet_CreateInstance, &ODatabaseMetaDataResultSet::getImplementationName_Static, &ODatabaseMetaDataResultSet::getSupportedServiceNames_Static,
872 &cppu::createSingleComponentFactory, 0, 0 },
873 { &ParameterSubstitution::create, &ParameterSubstitution::getImplementationName_Static, &ParameterSubstitution::getSupportedServiceNames_Static,
874 &cppu::createSingleComponentFactory, 0, 0 },
875 { 0, 0, 0, 0, 0, 0 }
876 };
877 }
878 using ::rtl::OUString;
879 using ::com::sun::star::uno::Reference;
880 using ::com::sun::star::uno::Sequence;
881 using ::com::sun::star::registry::XRegistryKey;
882 using ::com::sun::star::registry::InvalidRegistryException;
883 using ::com::sun::star::registry::InvalidValueException;
884 using ::com::sun::star::lang::XMultiServiceFactory;
885
886 //==========================================================================
887 //= registration
888 //==========================================================================
889 extern "C"
890 {
891
892 //---------------------------------------------------------------------------------------
component_getImplementationEnvironment(const sal_Char ** _ppEnvTypeName,uno_Environment **)893 SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char** _ppEnvTypeName, uno_Environment** /*_ppEnv*/)
894 {
895 *_ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
896 }
897
898 //---------------------------------------------------------------------------------------
component_getFactory(const sal_Char * implName,::com::sun::star::lang::XMultiServiceFactory * serviceManager,void * registryKey)899 SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(const sal_Char* implName, ::com::sun::star::lang::XMultiServiceFactory* serviceManager, void* registryKey)
900 {
901 return cppu::component_getFactoryHelper(implName, serviceManager, registryKey, entries);
902 }
903
904 } // extern "C"
905