merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / odbcbase / ODatabaseMetaDataResultSet.cxx
blob773b9c0293e87595a0f2b2399e9d2efdc4a1377e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ODatabaseMetaDataResultSet.cxx,v $
10 * $Revision: 1.35 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "TConnection.hxx"
35 #ifndef _CONNECTIVITY_ADO_ADATABASEMETADATARESULTSET_HXX_
36 #include "odbc/ODatabaseMetaDataResultSet.hxx"
37 #endif
38 #include <com/sun/star/sdbc/DataType.hpp>
39 #include <com/sun/star/sdbc/KeyRule.hpp>
40 #include <com/sun/star/sdbc/ProcedureResult.hpp>
41 #include <com/sun/star/sdbc/IndexType.hpp>
42 #include <comphelper/property.hxx>
43 #include <com/sun/star/lang/DisposedException.hpp>
44 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
45 #include <com/sun/star/sdbc/ResultSetType.hpp>
46 #include <com/sun/star/sdbc/FetchDirection.hpp>
47 #include <cppuhelper/typeprovider.hxx>
48 #include <comphelper/sequence.hxx>
49 #include "odbc/OResultSetMetaData.hxx"
50 #include "odbc/OTools.hxx"
51 #include <comphelper/types.hxx>
52 #include "FDatabaseMetaDataResultSetMetaData.hxx"
53 #include <connectivity/dbexception.hxx>
55 using namespace ::comphelper;
58 using namespace connectivity::odbc;
59 using namespace cppu;
60 //------------------------------------------------------------------------------
61 using namespace ::com::sun::star::lang;
62 using namespace com::sun::star::uno;
63 using namespace com::sun::star::beans;
64 using namespace com::sun::star::sdbc;
65 using namespace com::sun::star::util;
67 // -------------------------------------------------------------------------
68 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(OConnection* _pConnection)
69 :ODatabaseMetaDataResultSet_BASE(m_aMutex)
70 ,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper)
72 ,m_aStatementHandle(_pConnection->createStatementHandle())
73 ,m_aStatement(NULL)
74 ,m_xMetaData(NULL)
75 ,m_pRowStatusArray(NULL)
76 ,m_pConnection(_pConnection)
77 ,m_nTextEncoding(_pConnection->getTextEncoding())
78 ,m_nRowPos(-1)
79 ,m_nLastColumnPos(0)
80 ,m_nDriverColumnCount(0)
81 ,m_nCurrentFetchState(0)
82 ,m_bWasNull(sal_True)
83 ,m_bEOF(sal_False)
84 ,m_bFreeHandle(sal_False)
86 OSL_ENSURE(m_pConnection,"ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet: No parent set!");
87 osl_incrementInterlockedCount( &m_refCount );
88 m_pConnection->acquire();
89 m_pRowStatusArray = new SQLUSMALLINT[1]; // the default value
90 osl_decrementInterlockedCount( &m_refCount );
91 // allocBuffer();
94 // -------------------------------------------------------------------------
95 ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
97 OSL_ENSURE(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed,"Object wasn't disposed!");
98 if(!ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed)
100 osl_incrementInterlockedCount( &m_refCount );
101 dispose();
103 delete m_pRowStatusArray;
105 // -------------------------------------------------------------------------
106 void ODatabaseMetaDataResultSet::disposing(void)
108 OPropertySetHelper::disposing();
110 ::osl::MutexGuard aGuard(m_aMutex);
111 if(m_bFreeHandle)
112 m_pConnection->freeStatementHandle(m_aStatementHandle);
114 m_aStatement = NULL;
115 m_xMetaData.clear();
116 m_pConnection->release();
118 // -------------------------------------------------------------------------
119 Any SAL_CALL ODatabaseMetaDataResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
121 Any aRet = OPropertySetHelper::queryInterface(rType);
122 return aRet.hasValue() ? aRet : ODatabaseMetaDataResultSet_BASE::queryInterface(rType);
124 // -----------------------------------------------------------------------------
125 Reference< XPropertySetInfo > SAL_CALL ODatabaseMetaDataResultSet::getPropertySetInfo( ) throw(RuntimeException)
127 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
129 // -----------------------------------------------------------------------------
130 void SAL_CALL ODatabaseMetaDataResultSet::acquire() throw()
132 ODatabaseMetaDataResultSet_BASE::acquire();
134 // -----------------------------------------------------------------------------
135 void SAL_CALL ODatabaseMetaDataResultSet::release() throw()
137 ODatabaseMetaDataResultSet_BASE::release();
139 // -------------------------------------------------------------------------
140 Sequence< Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes( ) throw(RuntimeException)
142 ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
143 ::getCppuType( (const Reference< XFastPropertySet > *)0 ),
144 ::getCppuType( (const Reference< XPropertySet > *)0 ));
146 return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
148 // -----------------------------------------------------------------------------
149 sal_Int32 ODatabaseMetaDataResultSet::mapColumn (sal_Int32 column)
151 sal_Int32 map = column;
153 if (!m_aColMapping.empty())
155 // Validate column number
156 map = m_aColMapping[column];
159 return map;
161 // -------------------------------------------------------------------------
163 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
166 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
167 ::osl::MutexGuard aGuard( m_aMutex );
170 Reference< XResultSetMetaData > xMeta = getMetaData();
171 sal_Int32 nLen = xMeta->getColumnCount();
172 sal_Int32 i = 1;
173 for(;i<=nLen;++i)
174 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
175 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
176 break;
177 return i;
179 // -------------------------------------------------------------------------
180 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
182 ::dbtools::throwFunctionNotSupportedException( "XRow::getBinaryStream", *this );
183 return NULL;
185 // -------------------------------------------------------------------------
186 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
188 ::dbtools::throwFunctionNotSupportedException( "XRow::getCharacterStream", *this );
189 return NULL;
192 // -------------------------------------------------------------------------
193 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
196 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
197 ::osl::MutexGuard aGuard( m_aMutex );
199 columnIndex = mapColumn(columnIndex);
201 sal_Bool bRet = sal_False;
202 if(columnIndex <= m_nDriverColumnCount)
204 sal_Int32 nType = getMetaData()->getColumnType(columnIndex);
205 switch(nType)
207 case DataType::BIT:
209 sal_Int8 nValue = 0;
210 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BIT,m_bWasNull,**this,&nValue,sizeof nValue);
211 bRet = nValue != 0;
213 break;
214 default:
215 bRet = getInt(columnIndex) != 0;
218 return bRet;
220 // -------------------------------------------------------------------------
222 sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
225 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
226 ::osl::MutexGuard aGuard( m_aMutex );
229 columnIndex = mapColumn(columnIndex);
230 sal_Int8 nVal = 0;
231 if(columnIndex <= m_nDriverColumnCount)
233 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_TINYINT,m_bWasNull,**this,&nVal,sizeof nVal);
235 ::std::map<sal_Int32, ::connectivity::TInt2IntMap >::iterator aValueRangeIter;
236 if ( !m_aValueRange.empty() && (aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end())
237 return sal_Int8((*aValueRangeIter).second[(sal_Int32)nVal]);
239 else
240 m_bWasNull = sal_True;
241 return nVal;
243 // -------------------------------------------------------------------------
245 Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
248 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
249 ::osl::MutexGuard aGuard( m_aMutex );
252 columnIndex = mapColumn(columnIndex);
253 if(columnIndex <= m_nDriverColumnCount)
255 sal_Int32 nType = getMetaData()->getColumnType(columnIndex);
256 switch(nType)
258 case DataType::VARCHAR:
259 case DataType::LONGVARCHAR:
261 ::rtl::OUString aRet = OTools::getStringValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this,m_nTextEncoding);
262 return Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(aRet.getStr()),sizeof(sal_Unicode)*aRet.getLength());
265 return OTools::getBytesValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this);
267 else
268 m_bWasNull = sal_True;
269 return Sequence<sal_Int8>();
271 // -------------------------------------------------------------------------
273 ::com::sun::star::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
275 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
276 ::osl::MutexGuard aGuard( m_aMutex );
279 columnIndex = mapColumn(columnIndex);
280 if(columnIndex <= m_nDriverColumnCount)
282 DATE_STRUCT aDate;
283 aDate.day = 0;
284 aDate.month = 0;
285 aDate.year = 0;
286 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_DATE,m_bWasNull,**this,&aDate,sizeof aDate);
287 return Date(aDate.day,aDate.month,aDate.year);
289 else
290 m_bWasNull = sal_True;
291 return Date();
293 // -------------------------------------------------------------------------
295 double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
298 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
299 ::osl::MutexGuard aGuard( m_aMutex );
302 columnIndex = mapColumn(columnIndex);
303 double nValue(0.0);
304 if(columnIndex <= m_nDriverColumnCount)
305 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_DOUBLE,m_bWasNull,**this,&nValue,sizeof nValue);
306 else
307 m_bWasNull = sal_True;
308 return nValue;
310 // -------------------------------------------------------------------------
312 float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
315 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
316 ::osl::MutexGuard aGuard( m_aMutex );
319 columnIndex = mapColumn(columnIndex);
320 float nVal(0);
321 if(columnIndex <= m_nDriverColumnCount)
322 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_FLOAT,m_bWasNull,**this,&nVal,sizeof nVal);
323 else
324 m_bWasNull = sal_True;
325 return nVal;
327 // -------------------------------------------------------------------------
329 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
332 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
333 ::osl::MutexGuard aGuard( m_aMutex );
336 columnIndex = mapColumn(columnIndex);
337 sal_Int32 nVal = 0;
338 if(columnIndex <= m_nDriverColumnCount)
340 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_LONG,m_bWasNull,**this,&nVal,sizeof nVal);
342 ::std::map<sal_Int32, ::connectivity::TInt2IntMap >::iterator aValueRangeIter;
343 if ( !m_aValueRange.empty() && (aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end())
344 return (*aValueRangeIter).second[(sal_Int32)nVal];
346 else
347 m_bWasNull = sal_True;
348 return nVal;
350 // -------------------------------------------------------------------------
352 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow( ) throw(SQLException, RuntimeException)
354 return 0;
356 // -------------------------------------------------------------------------
358 sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
360 ::dbtools::throwFunctionNotSupportedException( "XRow::getLong", *this );
361 return 0;
363 // -------------------------------------------------------------------------
365 Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData( ) throw(SQLException, RuntimeException)
367 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
368 ::osl::MutexGuard aGuard( m_aMutex );
369 return m_xMetaData.is() ? m_xMetaData : (m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle));
371 // -------------------------------------------------------------------------
372 Reference< XArray > SAL_CALL ODatabaseMetaDataResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
374 ::dbtools::throwFunctionNotSupportedException( "XRow::getArray", *this );
375 return NULL;
377 // -------------------------------------------------------------------------
378 Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
380 ::dbtools::throwFunctionNotSupportedException( "XRow::getClob", *this );
381 return NULL;
383 // -------------------------------------------------------------------------
384 Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
386 ::dbtools::throwFunctionNotSupportedException( "XRow::getBlob", *this );
387 return NULL;
389 // -------------------------------------------------------------------------
391 Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
393 ::dbtools::throwFunctionNotSupportedException( "XRow::getRef", *this );
394 return NULL;
396 // -------------------------------------------------------------------------
398 Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 /*columnIndex*/, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
400 ::dbtools::throwFunctionNotSupportedException( "XRow::getObject", *this );
401 return Any();
403 // -------------------------------------------------------------------------
405 sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
408 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
409 ::osl::MutexGuard aGuard( m_aMutex );
411 columnIndex = mapColumn(columnIndex);
412 sal_Int16 nVal = 0;
413 if(columnIndex <= m_nDriverColumnCount)
415 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_SHORT,m_bWasNull,**this,&nVal,sizeof nVal);
417 ::std::map<sal_Int32, ::connectivity::TInt2IntMap >::iterator aValueRangeIter;
418 if ( !m_aValueRange.empty() && (aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end())
419 return sal_Int16((*aValueRangeIter).second[(sal_Int32)nVal]);
421 else
422 m_bWasNull = sal_True;
423 return nVal;
425 // -------------------------------------------------------------------------
427 ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
430 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
431 ::osl::MutexGuard aGuard( m_aMutex );
434 columnIndex = mapColumn(columnIndex);
435 ::rtl::OUString aVal;
436 if(columnIndex <= m_nDriverColumnCount)
437 aVal = OTools::getStringValue(m_pConnection,m_aStatementHandle,columnIndex,(SWORD)SQL_C_WCHAR,m_bWasNull,**this,m_nTextEncoding);
438 else
439 m_bWasNull = sal_True;
441 return aVal;
444 // -------------------------------------------------------------------------
447 ::com::sun::star::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
450 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
451 ::osl::MutexGuard aGuard( m_aMutex );
454 columnIndex = mapColumn(columnIndex);
455 TIME_STRUCT aTime={0,0,0};
456 if(columnIndex <= m_nDriverColumnCount)
457 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_TIME,m_bWasNull,**this,&aTime,sizeof aTime);
458 else
459 m_bWasNull = sal_True;
460 return Time(0,aTime.second,aTime.minute,aTime.hour);
462 // -------------------------------------------------------------------------
465 ::com::sun::star::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
468 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
469 ::osl::MutexGuard aGuard( m_aMutex );
472 columnIndex = mapColumn(columnIndex);
473 TIMESTAMP_STRUCT aTime={0,0,0,0,0,0,0};
474 if(columnIndex <= m_nDriverColumnCount)
475 OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_TIMESTAMP,m_bWasNull,**this,&aTime,sizeof aTime);
476 else
477 m_bWasNull = sal_True;
478 return DateTime((sal_uInt16)aTime.fraction*1000,aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year);
480 // -------------------------------------------------------------------------
482 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast( ) throw(SQLException, RuntimeException)
485 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
486 ::osl::MutexGuard aGuard( m_aMutex );
489 return m_nCurrentFetchState == SQL_NO_DATA;
491 // -------------------------------------------------------------------------
492 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst( ) throw(SQLException, RuntimeException)
495 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
496 ::osl::MutexGuard aGuard( m_aMutex );
499 return m_nRowPos == 1;
501 // -------------------------------------------------------------------------
502 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast( ) throw(SQLException, RuntimeException)
505 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
506 ::osl::MutexGuard aGuard( m_aMutex );
509 return m_bEOF && m_nCurrentFetchState != SQL_NO_DATA;
511 // -------------------------------------------------------------------------
512 void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst( ) throw(SQLException, RuntimeException)
515 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
516 ::osl::MutexGuard aGuard( m_aMutex );
519 if(first())
520 previous();
521 m_nCurrentFetchState = SQL_SUCCESS;
523 // -------------------------------------------------------------------------
524 void SAL_CALL ODatabaseMetaDataResultSet::afterLast( ) throw(SQLException, RuntimeException)
527 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
528 ::osl::MutexGuard aGuard( m_aMutex );
531 if(last())
532 next();
533 m_bEOF = sal_True;
535 // -------------------------------------------------------------------------
537 void SAL_CALL ODatabaseMetaDataResultSet::close( ) throw(SQLException, RuntimeException)
541 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
542 ::osl::MutexGuard aGuard( m_aMutex );
545 dispose();
547 // -------------------------------------------------------------------------
549 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first( ) throw(SQLException, RuntimeException)
552 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
553 ::osl::MutexGuard aGuard( m_aMutex );
556 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_FIRST,0);
557 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
558 sal_Bool bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO );
559 if( bRet )
560 m_nRowPos = 1;
561 return bRet;
563 // -------------------------------------------------------------------------
565 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last( ) throw(SQLException, RuntimeException)
567 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
568 ::osl::MutexGuard aGuard( m_aMutex );
571 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_LAST,0);
572 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
573 // here I know definitely that I stand on the last record
574 return (m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO);
576 // -------------------------------------------------------------------------
577 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
580 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
581 ::osl::MutexGuard aGuard( m_aMutex );
584 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_ABSOLUTE,row);
585 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
586 sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
587 if(bRet)
588 m_nRowPos = row;
589 return bRet;
591 // -------------------------------------------------------------------------
592 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
595 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
596 ::osl::MutexGuard aGuard( m_aMutex );
599 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,row);
600 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
601 sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
602 if(bRet)
603 m_nRowPos += row;
604 return bRet;
606 // -------------------------------------------------------------------------
607 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous( ) throw(SQLException, RuntimeException)
610 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
611 ::osl::MutexGuard aGuard( m_aMutex );
614 m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
615 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
616 sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
617 if(bRet)
618 --m_nRowPos;
619 return bRet;
621 // -------------------------------------------------------------------------
622 Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement( ) throw(SQLException, RuntimeException)
624 return NULL;
626 // -------------------------------------------------------------------------
628 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted( ) throw(SQLException, RuntimeException)
631 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
632 ::osl::MutexGuard aGuard( m_aMutex );
635 return m_pRowStatusArray[0] == SQL_ROW_DELETED;
637 // -------------------------------------------------------------------------
638 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted( ) throw(SQLException, RuntimeException)
640 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
641 ::osl::MutexGuard aGuard( m_aMutex );
644 return m_pRowStatusArray[0] == SQL_ROW_ADDED;
646 // -------------------------------------------------------------------------
647 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated( ) throw(SQLException, RuntimeException)
650 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
651 ::osl::MutexGuard aGuard( m_aMutex );
654 return m_pRowStatusArray[0] == SQL_ROW_UPDATED;
656 // -------------------------------------------------------------------------
658 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst( ) throw(SQLException, RuntimeException)
661 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
662 ::osl::MutexGuard aGuard( m_aMutex );
665 return m_nRowPos == 0;
667 // -------------------------------------------------------------------------
669 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next( ) throw(SQLException, RuntimeException)
672 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
673 ::osl::MutexGuard aGuard( m_aMutex );
676 // m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0);
677 m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
678 OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
679 return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
681 // -------------------------------------------------------------------------
683 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull( ) throw(SQLException, RuntimeException)
686 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
687 ::osl::MutexGuard aGuard( m_aMutex );
690 return m_bWasNull;
692 // -------------------------------------------------------------------------
693 void SAL_CALL ODatabaseMetaDataResultSet::refreshRow( ) throw(SQLException, RuntimeException)
696 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
697 ::osl::MutexGuard aGuard( m_aMutex );
700 // -------------------------------------------------------------------------
702 void SAL_CALL ODatabaseMetaDataResultSet::cancel( ) throw(RuntimeException)
705 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
706 ::osl::MutexGuard aGuard( m_aMutex );
709 OTools::ThrowException(m_pConnection,N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this);
711 // -------------------------------------------------------------------------
712 void SAL_CALL ODatabaseMetaDataResultSet::clearWarnings( ) throw(SQLException, RuntimeException)
715 // -------------------------------------------------------------------------
716 Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings( ) throw(SQLException, RuntimeException)
718 return Any();
720 //------------------------------------------------------------------------------
721 sal_Int32 ODatabaseMetaDataResultSet::getResultSetConcurrency() const throw(SQLException, RuntimeException)
723 return ResultSetConcurrency::READ_ONLY;
725 //------------------------------------------------------------------------------
726 sal_Int32 ODatabaseMetaDataResultSet::getResultSetType() const throw(SQLException, RuntimeException)
728 return ResultSetType::FORWARD_ONLY;
730 //------------------------------------------------------------------------------
731 sal_Int32 ODatabaseMetaDataResultSet::getFetchDirection() const throw(SQLException, RuntimeException)
733 return FetchDirection::FORWARD;
735 //------------------------------------------------------------------------------
736 sal_Int32 ODatabaseMetaDataResultSet::getFetchSize() const throw(SQLException, RuntimeException)
738 sal_Int32 nValue=1;
739 return nValue;
741 //------------------------------------------------------------------------------
742 ::rtl::OUString ODatabaseMetaDataResultSet::getCursorName() const throw(SQLException, RuntimeException)
744 return ::rtl::OUString();
747 // -------------------------------------------------------------------------
748 ::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const
751 Sequence< com::sun::star::beans::Property > aProps(5);
752 com::sun::star::beans::Property* pProperties = aProps.getArray();
753 sal_Int32 nPos = 0;
754 DECL_PROP0(CURSORNAME, ::rtl::OUString);
755 DECL_PROP0(FETCHDIRECTION, sal_Int32);
756 DECL_PROP0(FETCHSIZE, sal_Int32);
757 DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
758 DECL_PROP0(RESULTSETTYPE, sal_Int32);
760 return new ::cppu::OPropertyArrayHelper(aProps);
762 // -------------------------------------------------------------------------
763 ::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper()
765 return *const_cast<ODatabaseMetaDataResultSet*>(this)->getArrayHelper();
767 // -------------------------------------------------------------------------
768 sal_Bool ODatabaseMetaDataResultSet::convertFastPropertyValue(
769 Any & rConvertedValue,
770 Any & rOldValue,
771 sal_Int32 nHandle,
772 const Any& rValue )
773 throw (::com::sun::star::lang::IllegalArgumentException)
775 switch(nHandle)
777 case PROPERTY_ID_CURSORNAME:
778 case PROPERTY_ID_RESULTSETCONCURRENCY:
779 case PROPERTY_ID_RESULTSETTYPE:
780 throw ::com::sun::star::lang::IllegalArgumentException();
781 case PROPERTY_ID_FETCHDIRECTION:
782 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
783 case PROPERTY_ID_FETCHSIZE:
784 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
785 default:
788 return sal_False;
790 // -------------------------------------------------------------------------
791 void ODatabaseMetaDataResultSet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& /*rValue*/ ) throw (Exception)
793 switch(nHandle)
795 case PROPERTY_ID_CURSORNAME:
796 case PROPERTY_ID_RESULTSETCONCURRENCY:
797 case PROPERTY_ID_RESULTSETTYPE:
798 case PROPERTY_ID_FETCHDIRECTION:
799 case PROPERTY_ID_FETCHSIZE:
800 throw Exception();
801 default:
802 OSL_ENSURE(0,"setFastPropertyValue_NoBroadcast: Illegal handle value!");
805 // -------------------------------------------------------------------------
806 void ODatabaseMetaDataResultSet::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
808 switch(nHandle)
810 case PROPERTY_ID_CURSORNAME:
811 rValue <<= getCursorName();
812 break;
813 case PROPERTY_ID_RESULTSETCONCURRENCY:
814 rValue <<= getResultSetConcurrency();
815 break;
816 case PROPERTY_ID_RESULTSETTYPE:
817 rValue <<= getResultSetType();
818 break;
819 case PROPERTY_ID_FETCHDIRECTION:
820 rValue <<= getFetchDirection();
821 break;
822 case PROPERTY_ID_FETCHSIZE:
823 rValue <<= getFetchSize();
824 break;
827 // -------------------------------------------------------------------------
828 void ODatabaseMetaDataResultSet::openTypeInfo() throw(SQLException, RuntimeException)
830 TInt2IntMap aMap;
831 aMap[SQL_BIT] = DataType::BIT;
832 aMap[SQL_TINYINT] = DataType::TINYINT;
833 aMap[SQL_SMALLINT] = DataType::SMALLINT;
834 aMap[SQL_INTEGER] = DataType::INTEGER;
835 aMap[SQL_FLOAT] = DataType::FLOAT;
836 aMap[SQL_REAL] = DataType::REAL;
837 aMap[SQL_DOUBLE] = DataType::DOUBLE;
838 aMap[SQL_BIGINT] = DataType::BIGINT;
840 aMap[SQL_CHAR] = DataType::CHAR;
841 aMap[SQL_WCHAR] = DataType::CHAR;
842 aMap[SQL_VARCHAR] = DataType::VARCHAR;
843 aMap[SQL_WVARCHAR] = DataType::VARCHAR;
844 aMap[SQL_LONGVARCHAR] = DataType::LONGVARCHAR;
845 aMap[SQL_WLONGVARCHAR] = DataType::LONGVARCHAR;
847 aMap[SQL_TYPE_DATE] = DataType::DATE;
848 aMap[SQL_DATE] = DataType::DATE;
849 aMap[SQL_TYPE_TIME] = DataType::TIME;
850 aMap[SQL_TIME] = DataType::TIME;
851 aMap[SQL_TYPE_TIMESTAMP] = DataType::TIMESTAMP;
852 aMap[SQL_TIMESTAMP] = DataType::TIMESTAMP;
854 aMap[SQL_DECIMAL] = DataType::DECIMAL;
855 aMap[SQL_NUMERIC] = DataType::NUMERIC;
857 aMap[SQL_BINARY] = DataType::BINARY;
858 aMap[SQL_VARBINARY] = DataType::VARBINARY;
859 aMap[SQL_LONGVARBINARY] = DataType::LONGVARBINARY;
861 aMap[SQL_GUID] = DataType::VARBINARY;
864 m_aValueRange[2] = aMap;
866 OTools::ThrowException(m_pConnection,N3SQLGetTypeInfo(m_aStatementHandle, SQL_ALL_TYPES),m_aStatementHandle,SQL_HANDLE_STMT,*this);
867 checkColumnCount();
869 //-----------------------------------------------------------------------------
870 void ODatabaseMetaDataResultSet::openTables(const Any& catalog, const ::rtl::OUString& schemaPattern,
871 const ::rtl::OUString& tableNamePattern,
872 const Sequence< ::rtl::OUString >& types ) throw(SQLException, RuntimeException)
874 m_bFreeHandle = sal_True;
875 ::rtl::OString aPKQ,aPKO,aPKN,aCOL;
876 const ::rtl::OUString *pSchemaPat = NULL;
878 if(schemaPattern.toChar() != '%')
879 pSchemaPat = &schemaPattern;
880 else
881 pSchemaPat = NULL;
883 if ( catalog.hasValue() )
884 aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
885 aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding);
887 const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL,
888 *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
889 *pPKN = aPKN = ::rtl::OUStringToOString(tableNamePattern,m_nTextEncoding).getStr();
892 const char *pCOL = NULL;
893 const char* pComma = ",";
894 const ::rtl::OUString* pBegin = types.getConstArray();
895 const ::rtl::OUString* pEnd = pBegin + types.getLength();
896 for(;pBegin != pEnd;++pBegin)
898 aCOL += ::rtl::OUStringToOString(*pBegin,m_nTextEncoding);
899 aCOL += pComma;
901 if ( aCOL.getLength() )
903 aCOL = aCOL.replaceAt(aCOL.getLength()-1,1,pComma);
904 pCOL = aCOL.getStr();
906 else
907 pCOL = SQL_ALL_TABLE_TYPES;
909 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
910 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
911 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0,
912 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
913 (SDB_ODBC_CHAR *) pCOL, pCOL ? SQL_NTS : 0);
914 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
915 checkColumnCount();
918 //-----------------------------------------------------------------------------
919 void ODatabaseMetaDataResultSet::openTablesTypes( ) throw(SQLException, RuntimeException)
921 m_bFreeHandle = sal_True;
922 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
923 0,0,
924 0,0,
925 0,0,
926 (SDB_ODBC_CHAR *) SQL_ALL_TABLE_TYPES,SQL_NTS);
927 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
929 m_aColMapping.clear();
930 m_aColMapping.push_back(-1);
931 m_aColMapping.push_back(4);
932 m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping);
933 checkColumnCount();
935 // -------------------------------------------------------------------------
936 void ODatabaseMetaDataResultSet::openCatalogs() throw(SQLException, RuntimeException)
938 m_bFreeHandle = sal_True;
939 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
940 (SDB_ODBC_CHAR *) SQL_ALL_CATALOGS,SQL_NTS,
941 (SDB_ODBC_CHAR *) "",SQL_NTS,
942 (SDB_ODBC_CHAR *) "",SQL_NTS,
943 (SDB_ODBC_CHAR *) "",SQL_NTS);
945 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
947 m_aColMapping.clear();
948 m_aColMapping.push_back(-1);
949 m_aColMapping.push_back(1);
950 m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping);
951 checkColumnCount();
953 // -------------------------------------------------------------------------
954 void ODatabaseMetaDataResultSet::openSchemas() throw(SQLException, RuntimeException)
956 m_bFreeHandle = sal_True;
957 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
958 (SDB_ODBC_CHAR *) "",SQL_NTS,
959 (SDB_ODBC_CHAR *) SQL_ALL_SCHEMAS,SQL_NTS,
960 (SDB_ODBC_CHAR *) "",SQL_NTS,
961 (SDB_ODBC_CHAR *) "",SQL_NTS);
962 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
964 m_aColMapping.clear();
965 m_aColMapping.push_back(-1);
966 m_aColMapping.push_back(2);
967 m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping);
968 checkColumnCount();
970 // -------------------------------------------------------------------------
971 void ODatabaseMetaDataResultSet::openColumnPrivileges( const Any& catalog, const ::rtl::OUString& schema,
972 const ::rtl::OUString& table, const ::rtl::OUString& columnNamePattern )
973 throw(SQLException, RuntimeException)
975 const ::rtl::OUString *pSchemaPat = NULL;
977 if(schema.toChar() != '%')
978 pSchemaPat = &schema;
979 else
980 pSchemaPat = NULL;
982 m_bFreeHandle = sal_True;
983 ::rtl::OString aPKQ,aPKO,aPKN,aCOL;
985 aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
986 aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding);
988 const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL,
989 *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
990 *pPKN = aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding).getStr(),
991 *pCOL = aCOL = ::rtl::OUStringToOString(columnNamePattern,m_nTextEncoding).getStr();
994 SQLRETURN nRetcode = N3SQLColumnPrivileges(m_aStatementHandle,
995 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
996 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
997 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
998 (SDB_ODBC_CHAR *) pCOL, SQL_NTS);
999 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1001 checkColumnCount();
1003 // -------------------------------------------------------------------------
1004 void ODatabaseMetaDataResultSet::openColumns( const Any& catalog, const ::rtl::OUString& schemaPattern,
1005 const ::rtl::OUString& tableNamePattern, const ::rtl::OUString& columnNamePattern )
1006 throw(SQLException, RuntimeException)
1008 const ::rtl::OUString *pSchemaPat = NULL;
1010 if(schemaPattern.toChar() != '%')
1011 pSchemaPat = &schemaPattern;
1012 else
1013 pSchemaPat = NULL;
1015 m_bFreeHandle = sal_True;
1016 ::rtl::OString aPKQ,aPKO,aPKN,aCOL;
1017 aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1018 aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding);
1020 const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL,
1021 *pPKO = pSchemaPat && pSchemaPat->getLength() && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1022 *pPKN = aPKN = ::rtl::OUStringToOString(tableNamePattern,m_nTextEncoding).getStr(),
1023 *pCOL = aCOL = ::rtl::OUStringToOString(columnNamePattern,m_nTextEncoding).getStr();
1026 SQLRETURN nRetcode = N3SQLColumns(m_aStatementHandle,
1027 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1028 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0,
1029 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1030 (SDB_ODBC_CHAR *) pCOL, SQL_NTS);
1032 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1033 TInt2IntMap aMap;
1034 aMap[SQL_BIT] = DataType::BIT;
1035 aMap[SQL_TINYINT] = DataType::TINYINT;
1036 aMap[SQL_SMALLINT] = DataType::SMALLINT;
1037 aMap[SQL_INTEGER] = DataType::INTEGER;
1038 aMap[SQL_FLOAT] = DataType::FLOAT;
1039 aMap[SQL_REAL] = DataType::REAL;
1040 aMap[SQL_DOUBLE] = DataType::DOUBLE;
1041 aMap[SQL_BIGINT] = DataType::BIGINT;
1043 aMap[SQL_CHAR] = DataType::CHAR;
1044 aMap[SQL_WCHAR] = DataType::CHAR;
1045 aMap[SQL_VARCHAR] = DataType::VARCHAR;
1046 aMap[SQL_WVARCHAR] = DataType::VARCHAR;
1047 aMap[SQL_LONGVARCHAR] = DataType::LONGVARCHAR;
1048 aMap[SQL_WLONGVARCHAR] = DataType::LONGVARCHAR;
1050 aMap[SQL_TYPE_DATE] = DataType::DATE;
1051 aMap[SQL_DATE] = DataType::DATE;
1052 aMap[SQL_TYPE_TIME] = DataType::TIME;
1053 aMap[SQL_TIME] = DataType::TIME;
1054 aMap[SQL_TYPE_TIMESTAMP] = DataType::TIMESTAMP;
1055 aMap[SQL_TIMESTAMP] = DataType::TIMESTAMP;
1057 aMap[SQL_DECIMAL] = DataType::DECIMAL;
1058 aMap[SQL_NUMERIC] = DataType::NUMERIC;
1060 aMap[SQL_BINARY] = DataType::BINARY;
1061 aMap[SQL_VARBINARY] = DataType::VARBINARY;
1062 aMap[SQL_LONGVARBINARY] = DataType::LONGVARBINARY;
1064 aMap[SQL_GUID] = DataType::VARBINARY;
1066 m_aValueRange[5] = aMap;
1067 checkColumnCount();
1069 // -------------------------------------------------------------------------
1070 void ODatabaseMetaDataResultSet::openProcedureColumns( const Any& catalog, const ::rtl::OUString& schemaPattern,
1071 const ::rtl::OUString& procedureNamePattern,const ::rtl::OUString& columnNamePattern )
1072 throw(SQLException, RuntimeException)
1074 const ::rtl::OUString *pSchemaPat = NULL;
1076 if(schemaPattern.toChar() != '%')
1077 pSchemaPat = &schemaPattern;
1078 else
1079 pSchemaPat = NULL;
1081 m_bFreeHandle = sal_True;
1082 ::rtl::OString aPKQ,aPKO,aPKN,aCOL;
1083 aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1084 aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding);
1086 const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL,
1087 *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1088 *pPKN = aPKN = ::rtl::OUStringToOString(procedureNamePattern,m_nTextEncoding).getStr(),
1089 *pCOL = aCOL = ::rtl::OUStringToOString(columnNamePattern,m_nTextEncoding).getStr();
1092 SQLRETURN nRetcode = N3SQLProcedureColumns(m_aStatementHandle,
1093 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1094 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1095 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1096 (SDB_ODBC_CHAR *) pCOL, SQL_NTS);
1098 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1099 checkColumnCount();
1101 // -------------------------------------------------------------------------
1102 void ODatabaseMetaDataResultSet::openProcedures(const Any& catalog, const ::rtl::OUString& schemaPattern,
1103 const ::rtl::OUString& procedureNamePattern)
1104 throw(SQLException, RuntimeException)
1106 const ::rtl::OUString *pSchemaPat = NULL;
1108 if(schemaPattern.toChar() != '%')
1109 pSchemaPat = &schemaPattern;
1110 else
1111 pSchemaPat = NULL;
1113 m_bFreeHandle = sal_True;
1114 ::rtl::OString aPKQ,aPKO,aPKN,aCOL;
1116 aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1117 aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding);
1119 const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL,
1120 *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1121 *pPKN = aPKN = ::rtl::OUStringToOString(procedureNamePattern,m_nTextEncoding).getStr();
1124 SQLRETURN nRetcode = N3SQLProcedures(m_aStatementHandle,
1125 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1126 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1127 (SDB_ODBC_CHAR *) pPKN, SQL_NTS);
1128 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1129 checkColumnCount();
1131 // -------------------------------------------------------------------------
1132 void ODatabaseMetaDataResultSet::openSpecialColumns(sal_Bool _bRowVer,const Any& catalog, const ::rtl::OUString& schema,
1133 const ::rtl::OUString& table,sal_Int32 scope, sal_Bool nullable )
1134 throw(SQLException, RuntimeException)
1136 const ::rtl::OUString *pSchemaPat = NULL;
1138 if(schema.toChar() != '%')
1139 pSchemaPat = &schema;
1140 else
1141 pSchemaPat = NULL;
1143 m_bFreeHandle = sal_True;
1144 ::rtl::OString aPKQ,aPKO,aPKN,aCOL;
1145 aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1146 aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding);
1148 const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL,
1149 *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1150 *pPKN = aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding).getStr();
1153 SQLRETURN nRetcode = N3SQLSpecialColumns(m_aStatementHandle,_bRowVer ? SQL_ROWVER : SQL_BEST_ROWID,
1154 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1155 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1156 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1157 (SQLSMALLINT)scope,
1158 nullable ? SQL_NULLABLE : SQL_NO_NULLS);
1159 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1160 checkColumnCount();
1162 // -------------------------------------------------------------------------
1163 void ODatabaseMetaDataResultSet::openVersionColumns(const Any& catalog, const ::rtl::OUString& schema,
1164 const ::rtl::OUString& table) throw(SQLException, RuntimeException)
1166 openSpecialColumns(sal_True,catalog,schema,table,SQL_SCOPE_TRANSACTION,sal_False);
1168 // -------------------------------------------------------------------------
1169 void ODatabaseMetaDataResultSet::openBestRowIdentifier( const Any& catalog, const ::rtl::OUString& schema,
1170 const ::rtl::OUString& table,sal_Int32 scope,sal_Bool nullable ) throw(SQLException, RuntimeException)
1172 openSpecialColumns(sal_False,catalog,schema,table,scope,nullable);
1174 // -------------------------------------------------------------------------
1175 void ODatabaseMetaDataResultSet::openForeignKeys( const Any& catalog, const ::rtl::OUString* schema,
1176 const ::rtl::OUString* table,
1177 const Any& catalog2, const ::rtl::OUString* schema2,
1178 const ::rtl::OUString* table2) throw(SQLException, RuntimeException)
1180 m_bFreeHandle = sal_True;
1182 ::rtl::OString aPKQ,aPKO,aPKN, aFKQ, aFKO, aFKN;
1183 if ( catalog.hasValue() )
1184 aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1185 if ( catalog2.hasValue() )
1186 aFKQ = ::rtl::OUStringToOString(comphelper::getString(catalog2),m_nTextEncoding);
1188 const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL,
1189 *pPKO = schema && schema->getLength() ? ::rtl::OUStringToOString(*schema,m_nTextEncoding).getStr() : NULL,
1190 *pPKN = table ? (aPKN = ::rtl::OUStringToOString(*table,m_nTextEncoding)).getStr(): NULL,
1191 *pFKQ = catalog2.hasValue() && aFKQ.getLength() ? aFKQ.getStr() : NULL,
1192 *pFKO = schema2 && schema2->getLength() ? (aFKO = ::rtl::OUStringToOString(*schema2,m_nTextEncoding)).getStr() : NULL,
1193 *pFKN = table2 ? (aFKN = ::rtl::OUStringToOString(*table2,m_nTextEncoding)).getStr() : NULL;
1196 SQLRETURN nRetcode = N3SQLForeignKeys(m_aStatementHandle,
1197 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1198 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0,
1199 (SDB_ODBC_CHAR *) pPKN, pPKN ? SQL_NTS : 0,
1200 (SDB_ODBC_CHAR *) pFKQ, (catalog2.hasValue() && aFKQ.getLength()) ? SQL_NTS : 0,
1201 (SDB_ODBC_CHAR *) pFKO, pFKO ? SQL_NTS : 0,
1202 (SDB_ODBC_CHAR *) pFKN, SQL_NTS
1204 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1205 checkColumnCount();
1207 // -------------------------------------------------------------------------
1208 void ODatabaseMetaDataResultSet::openImportedKeys(const Any& catalog, const ::rtl::OUString& schema,
1209 const ::rtl::OUString& table) throw(SQLException, RuntimeException)
1212 openForeignKeys(Any(),NULL,NULL,catalog,!schema.compareToAscii("%") ? &schema : NULL,&table);
1214 // -------------------------------------------------------------------------
1215 void ODatabaseMetaDataResultSet::openExportedKeys(const Any& catalog, const ::rtl::OUString& schema,
1216 const ::rtl::OUString& table) throw(SQLException, RuntimeException)
1218 openForeignKeys(catalog,!schema.compareToAscii("%") ? &schema : NULL,&table,Any(),NULL,NULL);
1220 // -------------------------------------------------------------------------
1221 void ODatabaseMetaDataResultSet::openPrimaryKeys(const Any& catalog, const ::rtl::OUString& schema,
1222 const ::rtl::OUString& table) throw(SQLException, RuntimeException)
1224 const ::rtl::OUString *pSchemaPat = NULL;
1226 if(schema.toChar() != '%')
1227 pSchemaPat = &schema;
1228 else
1229 pSchemaPat = NULL;
1231 m_bFreeHandle = sal_True;
1232 ::rtl::OString aPKQ,aPKO,aPKN,aCOL;
1234 aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1235 aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding);
1237 const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL,
1238 *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1239 *pPKN = (aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding)).getStr();
1242 SQLRETURN nRetcode = N3SQLPrimaryKeys(m_aStatementHandle,
1243 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1244 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1245 (SDB_ODBC_CHAR *) pPKN, SQL_NTS);
1246 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1247 checkColumnCount();
1249 // -------------------------------------------------------------------------
1250 void ODatabaseMetaDataResultSet::openTablePrivileges(const Any& catalog, const ::rtl::OUString& schemaPattern,
1251 const ::rtl::OUString& tableNamePattern) throw(SQLException, RuntimeException)
1253 const ::rtl::OUString *pSchemaPat = NULL;
1255 if(schemaPattern.toChar() != '%')
1256 pSchemaPat = &schemaPattern;
1257 else
1258 pSchemaPat = NULL;
1260 m_bFreeHandle = sal_True;
1261 ::rtl::OString aPKQ,aPKO,aPKN;
1263 aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1264 aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding);
1266 const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL,
1267 *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1268 *pPKN = (aPKN = ::rtl::OUStringToOString(tableNamePattern,m_nTextEncoding)).getStr();
1271 SQLRETURN nRetcode = N3SQLTablePrivileges(m_aStatementHandle,
1272 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1273 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1274 (SDB_ODBC_CHAR *) pPKN, SQL_NTS);
1275 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1276 checkColumnCount();
1278 // -------------------------------------------------------------------------
1279 void ODatabaseMetaDataResultSet::openIndexInfo( const Any& catalog, const ::rtl::OUString& schema,
1280 const ::rtl::OUString& table,sal_Bool unique,sal_Bool approximate )
1281 throw(SQLException, RuntimeException)
1283 const ::rtl::OUString *pSchemaPat = NULL;
1285 if(schema.toChar() != '%')
1286 pSchemaPat = &schema;
1287 else
1288 pSchemaPat = NULL;
1290 m_bFreeHandle = sal_True;
1291 ::rtl::OString aPKQ,aPKO,aPKN;
1293 aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1294 aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding);
1296 const char *pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr() : NULL,
1297 *pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1298 *pPKN = (aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding)).getStr();
1301 SQLRETURN nRetcode = N3SQLStatistics(m_aStatementHandle,
1302 (SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1303 (SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1304 (SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1305 unique ? SQL_INDEX_UNIQUE : SQL_INDEX_ALL,
1306 approximate);
1307 OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1308 checkColumnCount();
1310 // -------------------------------------------------------------------------
1311 void ODatabaseMetaDataResultSet::checkColumnCount()
1313 sal_Int16 nNumResultCols=0;
1314 OTools::ThrowException(m_pConnection,N3SQLNumResultCols(m_aStatementHandle,&nNumResultCols),m_aStatementHandle,SQL_HANDLE_STMT,*this);
1315 m_nDriverColumnCount = nNumResultCols;
1317 // -----------------------------------------------------------------------------