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 #include "TConnection.hxx"
27 
28 #ifndef _CONNECTIVITY_ADO_ADATABASEMETADATARESULTSET_HXX_
29 #include "odbc/ODatabaseMetaDataResultSet.hxx"
30 #endif
31 #include <com/sun/star/sdbc/DataType.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 <cppuhelper/typeprovider.hxx>
41 #include <comphelper/sequence.hxx>
42 #include "odbc/OResultSetMetaData.hxx"
43 #include "odbc/OTools.hxx"
44 #include <comphelper/types.hxx>
45 #include "FDatabaseMetaDataResultSetMetaData.hxx"
46 #include <connectivity/dbexception.hxx>
47 
48 using namespace ::comphelper;
49 
50 
51 using namespace connectivity::odbc;
52 using namespace cppu;
53 //------------------------------------------------------------------------------
54 using namespace ::com::sun::star::lang;
55 using namespace com::sun::star::uno;
56 using namespace com::sun::star::beans;
57 using namespace com::sun::star::sdbc;
58 using namespace com::sun::star::util;
59 
60 // -------------------------------------------------------------------------
ODatabaseMetaDataResultSet(OConnection * _pConnection)61 ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(OConnection* _pConnection)
62 	:ODatabaseMetaDataResultSet_BASE(m_aMutex)
63 	,OPropertySetHelper(ODatabaseMetaDataResultSet_BASE::rBHelper)
64 
65     ,m_aStatementHandle(_pConnection->createStatementHandle())
66 	,m_aStatement(NULL)
67     ,m_xMetaData(NULL)
68     ,m_pRowStatusArray(NULL)
69     ,m_pConnection(_pConnection)
70     ,m_nTextEncoding(_pConnection->getTextEncoding())
71     ,m_nRowPos(-1)
72     ,m_nLastColumnPos(0)
73     ,m_nDriverColumnCount(0)
74     ,m_nCurrentFetchState(0)
75     ,m_bWasNull(sal_True)
76     ,m_bEOF(sal_False)
77 	,m_bFreeHandle(sal_False)
78 {
79 	OSL_ENSURE(m_pConnection,"ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet: No parent set!");
80 	osl_incrementInterlockedCount( &m_refCount );
81 	m_pConnection->acquire();
82 	m_pRowStatusArray = new SQLUSMALLINT[1]; // the default value
83 	osl_decrementInterlockedCount( &m_refCount );
84 	//	allocBuffer();
85 }
86 
87 // -------------------------------------------------------------------------
~ODatabaseMetaDataResultSet()88 ODatabaseMetaDataResultSet::~ODatabaseMetaDataResultSet()
89 {
90 	OSL_ENSURE(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed,"Object wasn't disposed!");
91 	if(!ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed)
92 	{
93 		osl_incrementInterlockedCount( &m_refCount );
94 		dispose();
95 	}
96 	delete [] m_pRowStatusArray;
97 }
98 // -------------------------------------------------------------------------
disposing(void)99 void ODatabaseMetaDataResultSet::disposing(void)
100 {
101 	OPropertySetHelper::disposing();
102 
103 	::osl::MutexGuard aGuard(m_aMutex);
104 	if(m_bFreeHandle)
105 		m_pConnection->freeStatementHandle(m_aStatementHandle);
106 
107 	m_aStatement	= NULL;
108 m_xMetaData.clear();
109 	m_pConnection->release();
110 }
111 // -------------------------------------------------------------------------
queryInterface(const Type & rType)112 Any SAL_CALL ODatabaseMetaDataResultSet::queryInterface( const Type & rType ) throw(RuntimeException)
113 {
114 	Any aRet = OPropertySetHelper::queryInterface(rType);
115 	return aRet.hasValue() ? aRet : ODatabaseMetaDataResultSet_BASE::queryInterface(rType);
116 }
117 // -----------------------------------------------------------------------------
getPropertySetInfo()118 Reference< XPropertySetInfo > SAL_CALL ODatabaseMetaDataResultSet::getPropertySetInfo(  ) throw(RuntimeException)
119 {
120 	return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
121 }
122 // -----------------------------------------------------------------------------
acquire()123 void SAL_CALL ODatabaseMetaDataResultSet::acquire() throw()
124 {
125 	ODatabaseMetaDataResultSet_BASE::acquire();
126 }
127 // -----------------------------------------------------------------------------
release()128 void SAL_CALL ODatabaseMetaDataResultSet::release() throw()
129 {
130 	ODatabaseMetaDataResultSet_BASE::release();
131 }
132 // -------------------------------------------------------------------------
getTypes()133 Sequence< Type > SAL_CALL ODatabaseMetaDataResultSet::getTypes(  ) throw(RuntimeException)
134 {
135 	::cppu::OTypeCollection aTypes(	::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
136 									::getCppuType( (const Reference< XFastPropertySet > *)0 ),
137 									::getCppuType( (const Reference< XPropertySet > *)0 ));
138 
139 	return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
140 }
141 // -----------------------------------------------------------------------------
mapColumn(sal_Int32 column)142 sal_Int32 ODatabaseMetaDataResultSet::mapColumn (sal_Int32	column)
143 {
144 	sal_Int32	map = column;
145 
146 	if (!m_aColMapping.empty())
147 	{
148 		// Validate column number
149 		map = m_aColMapping[column];
150 	}
151 
152 	return map;
153 }
154 // -------------------------------------------------------------------------
155 
findColumn(const::rtl::OUString & columnName)156 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const ::rtl::OUString& columnName ) throw(SQLException, RuntimeException)
157 {
158 
159 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
160 	::osl::MutexGuard aGuard( m_aMutex );
161 
162 
163 	Reference< XResultSetMetaData > xMeta = getMetaData();
164 	sal_Int32 nLen = xMeta->getColumnCount();
165 	sal_Int32 i = 1;
166 	for(;i<=nLen;++i)
167 		if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
168 				columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
169 			break;
170 	return i;
171 }
172 // -------------------------------------------------------------------------
getBinaryStream(sal_Int32)173 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getBinaryStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
174 {
175     ::dbtools::throwFunctionNotSupportedException( "XRow::getBinaryStream", *this );
176 	return NULL;
177 }
178 // -------------------------------------------------------------------------
getCharacterStream(sal_Int32)179 Reference< ::com::sun::star::io::XInputStream > SAL_CALL ODatabaseMetaDataResultSet::getCharacterStream( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
180 {
181     ::dbtools::throwFunctionNotSupportedException( "XRow::getCharacterStream", *this );
182     return NULL;
183 }
184 
185 // -------------------------------------------------------------------------
getBoolean(sal_Int32 columnIndex)186 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
187 {
188 
189 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
190 	::osl::MutexGuard aGuard( m_aMutex );
191 
192 	columnIndex = mapColumn(columnIndex);
193 
194 	sal_Bool bRet = sal_False;
195 	if(columnIndex <= m_nDriverColumnCount)
196 	{
197 		sal_Int32 nType = getMetaData()->getColumnType(columnIndex);
198 		switch(nType)
199 		{
200 			case DataType::BIT:
201 				{
202 					sal_Int8 nValue = 0;
203 					OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BIT,m_bWasNull,**this,&nValue,sizeof nValue);
204 					bRet = nValue != 0;
205 				}
206 				break;
207 			default:
208 				bRet = getInt(columnIndex) != 0;
209 		}
210 	}
211 	return bRet;
212 }
213 // -------------------------------------------------------------------------
214 
getByte(sal_Int32 columnIndex)215 sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
216 {
217 
218 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
219 	::osl::MutexGuard aGuard( m_aMutex );
220 
221 
222 	columnIndex = mapColumn(columnIndex);
223 	sal_Int8  nVal = 0;
224 	if(columnIndex <= m_nDriverColumnCount)
225 	{
226 		OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_TINYINT,m_bWasNull,**this,&nVal,sizeof nVal);
227 
228 		::std::map<sal_Int32, ::connectivity::TInt2IntMap >::iterator	aValueRangeIter;
229 		if ( !m_aValueRange.empty() && (aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end())
230 			return sal_Int8((*aValueRangeIter).second[(sal_Int32)nVal]);
231 	}
232 	else
233 		m_bWasNull = sal_True;
234 	return nVal;
235 }
236 // -------------------------------------------------------------------------
237 
getBytes(sal_Int32 columnIndex)238 Sequence< sal_Int8 > SAL_CALL ODatabaseMetaDataResultSet::getBytes( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
239 {
240 
241 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
242 	::osl::MutexGuard aGuard( m_aMutex );
243 
244 
245 	columnIndex = mapColumn(columnIndex);
246 	if(columnIndex <= m_nDriverColumnCount)
247 	{
248 		sal_Int32 nType = getMetaData()->getColumnType(columnIndex);
249 		switch(nType)
250 		{
251 			case DataType::VARCHAR:
252 			case DataType::LONGVARCHAR:
253 			{
254 				::rtl::OUString aRet = OTools::getStringValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this,m_nTextEncoding);
255 				return Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(aRet.getStr()),sizeof(sal_Unicode)*aRet.getLength());
256             }
257 		}
258 		return OTools::getBytesValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this);
259 	}
260 	else
261 		m_bWasNull = sal_True;
262 	return Sequence<sal_Int8>();
263 }
264 // -------------------------------------------------------------------------
265 
getDate(sal_Int32 columnIndex)266 ::com::sun::star::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
267 {
268 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
269 	::osl::MutexGuard aGuard( m_aMutex );
270 
271 
272 	columnIndex = mapColumn(columnIndex);
273 	if(columnIndex <= m_nDriverColumnCount)
274 	{
275 		DATE_STRUCT aDate;
276 		aDate.day = 0;
277 		aDate.month = 0;
278 		aDate.year = 0;
279 		OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_DATE : SQL_C_TYPE_DATE,m_bWasNull,**this,&aDate,sizeof aDate);
280 		return Date(aDate.day,aDate.month,aDate.year);
281 	}
282 	else
283 		m_bWasNull = sal_True;
284 	return Date();
285 }
286 // -------------------------------------------------------------------------
287 
getDouble(sal_Int32 columnIndex)288 double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
289 {
290 
291 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
292 	::osl::MutexGuard aGuard( m_aMutex );
293 
294 
295 	columnIndex = mapColumn(columnIndex);
296 	double nValue(0.0);
297 	if(columnIndex <= m_nDriverColumnCount)
298 		OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_DOUBLE,m_bWasNull,**this,&nValue,sizeof nValue);
299 	else
300 		m_bWasNull = sal_True;
301 	return nValue;
302 }
303 // -------------------------------------------------------------------------
304 
getFloat(sal_Int32 columnIndex)305 float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
306 {
307 
308 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
309 	::osl::MutexGuard aGuard( m_aMutex );
310 
311 
312 	columnIndex = mapColumn(columnIndex);
313 	float nVal(0);
314 	if(columnIndex <= m_nDriverColumnCount)
315 		OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_FLOAT,m_bWasNull,**this,&nVal,sizeof nVal);
316 	else
317 		m_bWasNull = sal_True;
318 	return nVal;
319 }
320 // -------------------------------------------------------------------------
321 
getInt(sal_Int32 columnIndex)322 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
323 {
324 
325 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
326 	::osl::MutexGuard aGuard( m_aMutex );
327 
328 
329 	columnIndex = mapColumn(columnIndex);
330 	sal_Int32 nVal = 0;
331 	if(columnIndex <= m_nDriverColumnCount)
332 	{
333 		OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_LONG,m_bWasNull,**this,&nVal,sizeof nVal);
334 
335 		::std::map<sal_Int32, ::connectivity::TInt2IntMap >::iterator	aValueRangeIter;
336 		if ( !m_aValueRange.empty() && (aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end())
337 			return (*aValueRangeIter).second[(sal_Int32)nVal];
338 	}
339 	else
340 		m_bWasNull = sal_True;
341 	return nVal;
342 }
343 // -------------------------------------------------------------------------
344 
getRow()345 sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getRow(  ) throw(SQLException, RuntimeException)
346 {
347 	return 0;
348 }
349 // -------------------------------------------------------------------------
350 
getLong(sal_Int32)351 sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
352 {
353     ::dbtools::throwFunctionNotSupportedException( "XRow::getLong", *this );
354     return 0;
355 }
356 // -------------------------------------------------------------------------
357 
getMetaData()358 Reference< XResultSetMetaData > SAL_CALL ODatabaseMetaDataResultSet::getMetaData(  ) throw(SQLException, RuntimeException)
359 {
360 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
361 	::osl::MutexGuard aGuard( m_aMutex );
362 	return m_xMetaData.is() ? m_xMetaData :  (m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle));
363 }
364 // -------------------------------------------------------------------------
getArray(sal_Int32)365 Reference< XArray > SAL_CALL ODatabaseMetaDataResultSet::getArray( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
366 {
367     ::dbtools::throwFunctionNotSupportedException( "XRow::getArray", *this );
368     return NULL;
369 }
370 // -------------------------------------------------------------------------
getClob(sal_Int32)371 Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
372 {
373     ::dbtools::throwFunctionNotSupportedException( "XRow::getClob", *this );
374     return NULL;
375 }
376 // -------------------------------------------------------------------------
getBlob(sal_Int32)377 Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
378 {
379     ::dbtools::throwFunctionNotSupportedException( "XRow::getBlob", *this );
380     return NULL;
381 }
382 // -------------------------------------------------------------------------
383 
getRef(sal_Int32)384 Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 /*columnIndex*/ ) throw(SQLException, RuntimeException)
385 {
386     ::dbtools::throwFunctionNotSupportedException( "XRow::getRef", *this );
387     return NULL;
388 }
389 // -------------------------------------------------------------------------
390 
getObject(sal_Int32,const Reference<::com::sun::star::container::XNameAccess> &)391 Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 /*columnIndex*/, const Reference< ::com::sun::star::container::XNameAccess >& /*typeMap*/ ) throw(SQLException, RuntimeException)
392 {
393     ::dbtools::throwFunctionNotSupportedException( "XRow::getObject", *this );
394     return Any();
395 }
396 // -------------------------------------------------------------------------
397 
getShort(sal_Int32 columnIndex)398 sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
399 {
400 
401 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
402 	::osl::MutexGuard aGuard( m_aMutex );
403 
404 	columnIndex = mapColumn(columnIndex);
405 	sal_Int16 nVal = 0;
406 	if(columnIndex <= m_nDriverColumnCount)
407 	{
408 		OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,SQL_C_SHORT,m_bWasNull,**this,&nVal,sizeof nVal);
409 
410 		::std::map<sal_Int32, ::connectivity::TInt2IntMap >::iterator	aValueRangeIter;
411 		if ( !m_aValueRange.empty() && (aValueRangeIter = m_aValueRange.find(columnIndex)) != m_aValueRange.end())
412 			return sal_Int16((*aValueRangeIter).second[(sal_Int32)nVal]);
413 	}
414 	else
415 		m_bWasNull = sal_True;
416 	return nVal;
417 }
418 // -------------------------------------------------------------------------
419 
getString(sal_Int32 columnIndex)420 ::rtl::OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
421 {
422 
423 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
424 	::osl::MutexGuard aGuard( m_aMutex );
425 
426 
427 	columnIndex = mapColumn(columnIndex);
428 	::rtl::OUString aVal;
429 	if(columnIndex <= m_nDriverColumnCount)
430 		aVal = OTools::getStringValue(m_pConnection,m_aStatementHandle,columnIndex,impl_getColumnType_nothrow(columnIndex),m_bWasNull,**this,m_nTextEncoding);
431 	else
432 		m_bWasNull = sal_True;
433 
434 	return aVal;
435 }
436 
437 // -------------------------------------------------------------------------
438 
439 
getTime(sal_Int32 columnIndex)440 ::com::sun::star::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
441 {
442 
443 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
444 	::osl::MutexGuard aGuard( m_aMutex );
445 
446 
447 	columnIndex = mapColumn(columnIndex);
448 	TIME_STRUCT aTime={0,0,0};
449 	if(columnIndex <= m_nDriverColumnCount)
450 		OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIME : SQL_C_TYPE_TIME,m_bWasNull,**this,&aTime,sizeof aTime);
451 	else
452 		m_bWasNull = sal_True;
453 	return Time(0,aTime.second,aTime.minute,aTime.hour);
454 }
455 // -------------------------------------------------------------------------
456 
457 
getTimestamp(sal_Int32 columnIndex)458 ::com::sun::star::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex ) throw(SQLException, RuntimeException)
459 {
460 
461 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
462 	::osl::MutexGuard aGuard( m_aMutex );
463 
464 
465 	columnIndex = mapColumn(columnIndex);
466 	TIMESTAMP_STRUCT aTime={0,0,0,0,0,0,0};
467 	if(columnIndex <= m_nDriverColumnCount)
468 		OTools::getValue(m_pConnection,m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP,m_bWasNull,**this,&aTime,sizeof aTime);
469 	else
470 		m_bWasNull = sal_True;
471 	return DateTime((sal_uInt16)aTime.fraction*1000,aTime.second,aTime.minute,aTime.hour,aTime.day,aTime.month,aTime.year);
472 }
473 // -------------------------------------------------------------------------
474 
isAfterLast()475 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isAfterLast(  ) throw(SQLException, RuntimeException)
476 {
477 
478 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
479 	::osl::MutexGuard aGuard( m_aMutex );
480 
481 
482 	return m_nCurrentFetchState == SQL_NO_DATA;
483 }
484 // -------------------------------------------------------------------------
isFirst()485 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isFirst(  ) throw(SQLException, RuntimeException)
486 {
487 
488 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
489 	::osl::MutexGuard aGuard( m_aMutex );
490 
491 
492 	return m_nRowPos == 1;
493 }
494 // -------------------------------------------------------------------------
isLast()495 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isLast(  ) throw(SQLException, RuntimeException)
496 {
497 
498 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
499 	::osl::MutexGuard aGuard( m_aMutex );
500 
501 
502 	return m_bEOF && m_nCurrentFetchState != SQL_NO_DATA;
503 }
504 // -------------------------------------------------------------------------
beforeFirst()505 void SAL_CALL ODatabaseMetaDataResultSet::beforeFirst(  ) throw(SQLException, RuntimeException)
506 {
507 
508 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
509 	::osl::MutexGuard aGuard( m_aMutex );
510 
511 
512 	if(first())
513 		previous();
514 	m_nCurrentFetchState = SQL_SUCCESS;
515 }
516 // -------------------------------------------------------------------------
afterLast()517 void SAL_CALL ODatabaseMetaDataResultSet::afterLast(  ) throw(SQLException, RuntimeException)
518 {
519 
520 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
521 	::osl::MutexGuard aGuard( m_aMutex );
522 
523 
524 	if(last())
525 		next();
526 	m_bEOF = sal_True;
527 }
528 // -------------------------------------------------------------------------
529 
close()530 void SAL_CALL ODatabaseMetaDataResultSet::close(  ) throw(SQLException, RuntimeException)
531 {
532 	{
533 
534 		checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
535 		::osl::MutexGuard aGuard( m_aMutex );
536 
537 	}
538 	dispose();
539 }
540 // -------------------------------------------------------------------------
541 
first()542 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::first(  ) throw(SQLException, RuntimeException)
543 {
544 
545 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
546 	::osl::MutexGuard aGuard( m_aMutex );
547 
548 
549 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_FIRST,0);
550 	OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
551     sal_Bool bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO );
552 	if( bRet )
553 		m_nRowPos = 1;
554 	return bRet;
555 }
556 // -------------------------------------------------------------------------
557 
last()558 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::last(  ) throw(SQLException, RuntimeException)
559 {
560 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
561 	::osl::MutexGuard aGuard( m_aMutex );
562 
563 
564 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_LAST,0);
565 	OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
566 	// here I know definitely that I stand on the last record
567 	return (m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO);
568 }
569 // -------------------------------------------------------------------------
absolute(sal_Int32 row)570 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
571 {
572 
573 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
574 	::osl::MutexGuard aGuard( m_aMutex );
575 
576 
577 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_ABSOLUTE,row);
578 	OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
579 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
580 	if(bRet)
581 		m_nRowPos = row;
582 	return bRet;
583 }
584 // -------------------------------------------------------------------------
relative(sal_Int32 row)585 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
586 {
587 
588 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
589 	::osl::MutexGuard aGuard( m_aMutex );
590 
591 
592 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,row);
593 	OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
594 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
595 	if(bRet)
596 		m_nRowPos += row;
597 	return bRet;
598 }
599 // -------------------------------------------------------------------------
previous()600 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::previous(  ) throw(SQLException, RuntimeException)
601 {
602 
603 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
604 	::osl::MutexGuard aGuard( m_aMutex );
605 
606 
607 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
608 	OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
609 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
610 	if(bRet)
611 		--m_nRowPos;
612 	return bRet;
613 }
614 // -------------------------------------------------------------------------
getStatement()615 Reference< XInterface > SAL_CALL ODatabaseMetaDataResultSet::getStatement(  ) throw(SQLException, RuntimeException)
616 {
617 	return NULL;
618 }
619 // -------------------------------------------------------------------------
620 
rowDeleted()621 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowDeleted(  ) throw(SQLException, RuntimeException)
622 {
623 
624 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
625 	::osl::MutexGuard aGuard( m_aMutex );
626 
627 
628 	return m_pRowStatusArray[0] == SQL_ROW_DELETED;
629 }
630 // -------------------------------------------------------------------------
rowInserted()631 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowInserted(  ) throw(SQLException, RuntimeException)
632 {
633 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
634 	::osl::MutexGuard aGuard( m_aMutex );
635 
636 
637 	return m_pRowStatusArray[0] == SQL_ROW_ADDED;
638 }
639 // -------------------------------------------------------------------------
rowUpdated()640 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::rowUpdated(  ) throw(SQLException, RuntimeException)
641 {
642 
643 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
644 	::osl::MutexGuard aGuard( m_aMutex );
645 
646 
647 	return m_pRowStatusArray[0] == SQL_ROW_UPDATED;
648 }
649 // -------------------------------------------------------------------------
650 
isBeforeFirst()651 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::isBeforeFirst(  ) throw(SQLException, RuntimeException)
652 {
653 
654 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
655 	::osl::MutexGuard aGuard( m_aMutex );
656 
657 
658 	return m_nRowPos == 0;
659 }
660 // -------------------------------------------------------------------------
661 
next()662 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::next(  ) throw(SQLException, RuntimeException)
663 {
664 
665 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
666 	::osl::MutexGuard aGuard( m_aMutex );
667 
668 
669 	//	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0);
670 	m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
671 	OTools::ThrowException(m_pConnection,m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
672 	return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
673 }
674 // -------------------------------------------------------------------------
675 
wasNull()676 sal_Bool SAL_CALL ODatabaseMetaDataResultSet::wasNull(  ) throw(SQLException, RuntimeException)
677 {
678 
679 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
680 	::osl::MutexGuard aGuard( m_aMutex );
681 
682 
683 	return m_bWasNull;
684 }
685 // -------------------------------------------------------------------------
refreshRow()686 void SAL_CALL ODatabaseMetaDataResultSet::refreshRow(  ) throw(SQLException, RuntimeException)
687 {
688 
689 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
690 	::osl::MutexGuard aGuard( m_aMutex );
691 
692 }
693 // -------------------------------------------------------------------------
694 
cancel()695 void SAL_CALL ODatabaseMetaDataResultSet::cancel(  ) throw(RuntimeException)
696 {
697 
698 	checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
699 	::osl::MutexGuard aGuard( m_aMutex );
700 
701 
702 	OTools::ThrowException(m_pConnection,N3SQLCancel(m_aStatementHandle),m_aStatementHandle,SQL_HANDLE_STMT,*this);
703 }
704 // -------------------------------------------------------------------------
clearWarnings()705 void SAL_CALL ODatabaseMetaDataResultSet::clearWarnings(  ) throw(SQLException, RuntimeException)
706 {
707 }
708 // -------------------------------------------------------------------------
getWarnings()709 Any SAL_CALL ODatabaseMetaDataResultSet::getWarnings(  ) throw(SQLException, RuntimeException)
710 {
711 	return Any();
712 }
713 //------------------------------------------------------------------------------
getResultSetConcurrency() const714 sal_Int32 ODatabaseMetaDataResultSet::getResultSetConcurrency() const throw(SQLException, RuntimeException)
715 {
716 	return ResultSetConcurrency::READ_ONLY;
717 }
718 //------------------------------------------------------------------------------
getResultSetType() const719 sal_Int32 ODatabaseMetaDataResultSet::getResultSetType() const throw(SQLException, RuntimeException)
720 {
721 	return ResultSetType::FORWARD_ONLY;
722 }
723 //------------------------------------------------------------------------------
getFetchDirection() const724 sal_Int32 ODatabaseMetaDataResultSet::getFetchDirection() const throw(SQLException, RuntimeException)
725 {
726 	return FetchDirection::FORWARD;
727 }
728 //------------------------------------------------------------------------------
getFetchSize() const729 sal_Int32 ODatabaseMetaDataResultSet::getFetchSize() const throw(SQLException, RuntimeException)
730 {
731 	sal_Int32 nValue=1;
732 	return nValue;
733 }
734 //------------------------------------------------------------------------------
getCursorName() const735 ::rtl::OUString ODatabaseMetaDataResultSet::getCursorName() const throw(SQLException, RuntimeException)
736 {
737 	return ::rtl::OUString();
738 }
739 
740 // -------------------------------------------------------------------------
createArrayHelper() const741 ::cppu::IPropertyArrayHelper* ODatabaseMetaDataResultSet::createArrayHelper( ) const
742 {
743 
744 	Sequence< com::sun::star::beans::Property > aProps(5);
745 	com::sun::star::beans::Property* pProperties = aProps.getArray();
746 	sal_Int32 nPos = 0;
747 	DECL_PROP0(CURSORNAME,			::rtl::OUString);
748 	DECL_PROP0(FETCHDIRECTION,		sal_Int32);
749 	DECL_PROP0(FETCHSIZE,			sal_Int32);
750 	DECL_PROP0(RESULTSETCONCURRENCY,sal_Int32);
751 	DECL_PROP0(RESULTSETTYPE,		sal_Int32);
752 
753 	return new ::cppu::OPropertyArrayHelper(aProps);
754 }
755 // -------------------------------------------------------------------------
getInfoHelper()756 ::cppu::IPropertyArrayHelper & ODatabaseMetaDataResultSet::getInfoHelper()
757 {
758 	return *const_cast<ODatabaseMetaDataResultSet*>(this)->getArrayHelper();
759 }
760 // -------------------------------------------------------------------------
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nHandle,const Any & rValue)761 sal_Bool ODatabaseMetaDataResultSet::convertFastPropertyValue(
762 							Any & rConvertedValue,
763 							Any & rOldValue,
764 							sal_Int32 nHandle,
765 							const Any& rValue )
766 								throw (::com::sun::star::lang::IllegalArgumentException)
767 {
768 	switch(nHandle)
769 	{
770 		case PROPERTY_ID_CURSORNAME:
771 		case PROPERTY_ID_RESULTSETCONCURRENCY:
772 		case PROPERTY_ID_RESULTSETTYPE:
773 			throw ::com::sun::star::lang::IllegalArgumentException();
774 		case PROPERTY_ID_FETCHDIRECTION:
775 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
776 		case PROPERTY_ID_FETCHSIZE:
777 			return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
778 		default:
779 			;
780 	}
781 	return sal_False;
782 }
783 // -------------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any &)784 void ODatabaseMetaDataResultSet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& /*rValue*/ ) throw (Exception)
785 {
786 	switch(nHandle)
787 	{
788 		case PROPERTY_ID_CURSORNAME:
789 		case PROPERTY_ID_RESULTSETCONCURRENCY:
790 		case PROPERTY_ID_RESULTSETTYPE:
791 		case PROPERTY_ID_FETCHDIRECTION:
792 		case PROPERTY_ID_FETCHSIZE:
793 			throw Exception();
794 		default:
795 			OSL_ENSURE(0,"setFastPropertyValue_NoBroadcast: Illegal handle value!");
796 	}
797 }
798 // -------------------------------------------------------------------------
getFastPropertyValue(Any & rValue,sal_Int32 nHandle) const799 void ODatabaseMetaDataResultSet::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
800 {
801 	switch(nHandle)
802 	{
803 		case PROPERTY_ID_CURSORNAME:
804 			rValue <<= getCursorName();
805 			break;
806 		case PROPERTY_ID_RESULTSETCONCURRENCY:
807 			rValue <<= getResultSetConcurrency();
808 			break;
809 		case PROPERTY_ID_RESULTSETTYPE:
810 			rValue <<= getResultSetType();
811 			break;
812 		case PROPERTY_ID_FETCHDIRECTION:
813 			rValue <<= getFetchDirection();
814 			break;
815 		case PROPERTY_ID_FETCHSIZE:
816 			rValue <<= getFetchSize();
817 			break;
818 	}
819 }
820 // -------------------------------------------------------------------------
openTypeInfo()821 void ODatabaseMetaDataResultSet::openTypeInfo() throw(SQLException, RuntimeException)
822 {
823 	TInt2IntMap aMap;
824 	aMap[SQL_BIT]				= DataType::BIT;
825 	aMap[SQL_TINYINT]			= DataType::TINYINT;
826 	aMap[SQL_SMALLINT]			= DataType::SMALLINT;
827 	aMap[SQL_INTEGER]			= DataType::INTEGER;
828 	aMap[SQL_FLOAT]				= DataType::FLOAT;
829 	aMap[SQL_REAL]				= DataType::REAL;
830 	aMap[SQL_DOUBLE]			= DataType::DOUBLE;
831 	aMap[SQL_BIGINT]			= DataType::BIGINT;
832 
833 	aMap[SQL_CHAR]				= DataType::CHAR;
834 	aMap[SQL_WCHAR]				= DataType::CHAR;
835 	aMap[SQL_VARCHAR]			= DataType::VARCHAR;
836 	aMap[SQL_WVARCHAR]			= DataType::VARCHAR;
837 	aMap[SQL_LONGVARCHAR]		= DataType::LONGVARCHAR;
838 	aMap[SQL_WLONGVARCHAR]		= DataType::LONGVARCHAR;
839 
840 	aMap[SQL_TYPE_DATE]			= DataType::DATE;
841 	aMap[SQL_DATE]				= DataType::DATE;
842 	aMap[SQL_TYPE_TIME]			= DataType::TIME;
843 	aMap[SQL_TIME]				= DataType::TIME;
844 	aMap[SQL_TYPE_TIMESTAMP]	= DataType::TIMESTAMP;
845 	aMap[SQL_TIMESTAMP]			= DataType::TIMESTAMP;
846 
847 	aMap[SQL_DECIMAL]			= DataType::DECIMAL;
848 	aMap[SQL_NUMERIC]			= DataType::NUMERIC;
849 
850 	aMap[SQL_BINARY]			= DataType::BINARY;
851 	aMap[SQL_VARBINARY]			= DataType::VARBINARY;
852 	aMap[SQL_LONGVARBINARY]		= DataType::LONGVARBINARY;
853 
854 	aMap[SQL_GUID]				= DataType::VARBINARY;
855 
856 
857 	m_aValueRange[2] = aMap;
858 
859 	OTools::ThrowException(m_pConnection,N3SQLGetTypeInfo(m_aStatementHandle, SQL_ALL_TYPES),m_aStatementHandle,SQL_HANDLE_STMT,*this);
860 	checkColumnCount();
861 }
862 //-----------------------------------------------------------------------------
openTables(const Any & catalog,const::rtl::OUString & schemaPattern,const::rtl::OUString & tableNamePattern,const Sequence<::rtl::OUString> & types)863 void ODatabaseMetaDataResultSet::openTables(const Any& catalog, const ::rtl::OUString& schemaPattern,
864 							const ::rtl::OUString& tableNamePattern,
865 							const Sequence< ::rtl::OUString >& types )	throw(SQLException, RuntimeException)
866 {
867 	m_bFreeHandle = sal_True;
868 	::rtl::OString aPKQ,aPKO,aPKN,aCOL;
869 	const ::rtl::OUString *pSchemaPat = NULL;
870 
871 	if(schemaPattern.toChar() != '%')
872 		pSchemaPat = &schemaPattern;
873 	else
874 		pSchemaPat = NULL;
875 
876     if ( catalog.hasValue() )
877 	    aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
878 	aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding);
879 
880 	const char	*pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr()	: NULL,
881 				*pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
882 				*pPKN = (aPKN = ::rtl::OUStringToOString(tableNamePattern,m_nTextEncoding)).getStr();
883 
884 
885 	const char	*pCOL = NULL;
886 	const char* pComma = ",";
887 	const ::rtl::OUString* pBegin = types.getConstArray();
888 	const ::rtl::OUString* pEnd = pBegin + types.getLength();
889 	for(;pBegin != pEnd;++pBegin)
890 	{
891 		aCOL += ::rtl::OUStringToOString(*pBegin,m_nTextEncoding);
892 		aCOL += pComma;
893 	}
894 	if ( aCOL.getLength() )
895 	{
896 		aCOL = aCOL.replaceAt(aCOL.getLength()-1,1,pComma);
897 		pCOL = aCOL.getStr();
898 	}
899 	else
900 		pCOL = SQL_ALL_TABLE_TYPES;
901 
902 	SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
903 							(SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
904 							(SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0,
905 							(SDB_ODBC_CHAR *) pPKN, SQL_NTS,
906 							(SDB_ODBC_CHAR *) pCOL, pCOL ? SQL_NTS : 0);
907 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
908 	checkColumnCount();
909 
910 }
911 //-----------------------------------------------------------------------------
openTablesTypes()912 void ODatabaseMetaDataResultSet::openTablesTypes( )	throw(SQLException, RuntimeException)
913 {
914 	m_bFreeHandle = sal_True;
915 	SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
916 							0,0,
917 							0,0,
918 							0,0,
919 							(SDB_ODBC_CHAR *) SQL_ALL_TABLE_TYPES,SQL_NTS);
920 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
921 
922 	m_aColMapping.clear();
923 	m_aColMapping.push_back(-1);
924 	m_aColMapping.push_back(4);
925 	m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping);
926 	checkColumnCount();
927 }
928 // -------------------------------------------------------------------------
openCatalogs()929 void ODatabaseMetaDataResultSet::openCatalogs() throw(SQLException, RuntimeException)
930 {
931 	m_bFreeHandle = sal_True;
932 	SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
933 							(SDB_ODBC_CHAR *) SQL_ALL_CATALOGS,SQL_NTS,
934 							(SDB_ODBC_CHAR *) "",SQL_NTS,
935 							(SDB_ODBC_CHAR *) "",SQL_NTS,
936 							(SDB_ODBC_CHAR *) "",SQL_NTS);
937 
938 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
939 
940 	m_aColMapping.clear();
941 	m_aColMapping.push_back(-1);
942 	m_aColMapping.push_back(1);
943 	m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping);
944 	checkColumnCount();
945 }
946 // -------------------------------------------------------------------------
openSchemas()947 void ODatabaseMetaDataResultSet::openSchemas() throw(SQLException, RuntimeException)
948 {
949 	m_bFreeHandle = sal_True;
950 	SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
951 							(SDB_ODBC_CHAR *) "",SQL_NTS,
952 							(SDB_ODBC_CHAR *) SQL_ALL_SCHEMAS,SQL_NTS,
953 							(SDB_ODBC_CHAR *) "",SQL_NTS,
954 							(SDB_ODBC_CHAR *) "",SQL_NTS);
955 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
956 
957 	m_aColMapping.clear();
958 	m_aColMapping.push_back(-1);
959 	m_aColMapping.push_back(2);
960 	m_xMetaData = new OResultSetMetaData(m_pConnection,m_aStatementHandle,m_aColMapping);
961 	checkColumnCount();
962 }
963 // -------------------------------------------------------------------------
openColumnPrivileges(const Any & catalog,const::rtl::OUString & schema,const::rtl::OUString & table,const::rtl::OUString & columnNamePattern)964 void ODatabaseMetaDataResultSet::openColumnPrivileges(	const Any& catalog,	const ::rtl::OUString& schema,
965 										const ::rtl::OUString& table,	const ::rtl::OUString& columnNamePattern )
966 										throw(SQLException, RuntimeException)
967 {
968 	const ::rtl::OUString *pSchemaPat = NULL;
969 
970 	if(schema.toChar() != '%')
971 		pSchemaPat = &schema;
972 	else
973 		pSchemaPat = NULL;
974 
975 	m_bFreeHandle = sal_True;
976 	::rtl::OString aPKQ,aPKO,aPKN,aCOL;
977 
978 	if ( catalog.hasValue() )
979 		aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
980 	aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding);
981 
982 	const char	*pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr()	: NULL,
983 				*pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
984 				*pPKN = (aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding)).getStr(),
985 				*pCOL = (aCOL = ::rtl::OUStringToOString(columnNamePattern,m_nTextEncoding)).getStr();
986 
987 
988 	SQLRETURN nRetcode = N3SQLColumnPrivileges(m_aStatementHandle,
989 							(SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
990 							(SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
991 							(SDB_ODBC_CHAR *) pPKN, SQL_NTS,
992 							(SDB_ODBC_CHAR *) pCOL, SQL_NTS);
993 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
994 
995 	checkColumnCount();
996 }
997 // -------------------------------------------------------------------------
openColumns(const Any & catalog,const::rtl::OUString & schemaPattern,const::rtl::OUString & tableNamePattern,const::rtl::OUString & columnNamePattern)998 void ODatabaseMetaDataResultSet::openColumns(	const Any& catalog,				const ::rtl::OUString& schemaPattern,
999 								const ::rtl::OUString& tableNamePattern,	const ::rtl::OUString& columnNamePattern )
1000 								throw(SQLException, RuntimeException)
1001 {
1002 	const ::rtl::OUString *pSchemaPat = NULL;
1003 
1004 	if(schemaPattern.toChar() != '%')
1005 		pSchemaPat = &schemaPattern;
1006 	else
1007 		pSchemaPat = NULL;
1008 
1009 	m_bFreeHandle = sal_True;
1010 	::rtl::OString aPKQ,aPKO,aPKN,aCOL;
1011 	if ( catalog.hasValue() )
1012 		aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1013 	aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding);
1014 
1015 	const char	*pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr()	: NULL,
1016 				*pPKO = pSchemaPat && pSchemaPat->getLength() && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1017 				*pPKN = (aPKN = ::rtl::OUStringToOString(tableNamePattern,m_nTextEncoding)).getStr(),
1018 				*pCOL = (aCOL = ::rtl::OUStringToOString(columnNamePattern,m_nTextEncoding)).getStr();
1019 
1020 
1021 	SQLRETURN nRetcode = N3SQLColumns(m_aStatementHandle,
1022 							(SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1023 							(SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0,
1024 							(SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1025 							(SDB_ODBC_CHAR *) pCOL, SQL_NTS);
1026 
1027 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1028 	TInt2IntMap aMap;
1029 	aMap[SQL_BIT]				= DataType::BIT;
1030 	aMap[SQL_TINYINT]			= DataType::TINYINT;
1031 	aMap[SQL_SMALLINT]			= DataType::SMALLINT;
1032 	aMap[SQL_INTEGER]			= DataType::INTEGER;
1033 	aMap[SQL_FLOAT]				= DataType::FLOAT;
1034 	aMap[SQL_REAL]				= DataType::REAL;
1035 	aMap[SQL_DOUBLE]			= DataType::DOUBLE;
1036 	aMap[SQL_BIGINT]			= DataType::BIGINT;
1037 
1038 	aMap[SQL_CHAR]				= DataType::CHAR;
1039 	aMap[SQL_WCHAR]				= DataType::CHAR;
1040 	aMap[SQL_VARCHAR]			= DataType::VARCHAR;
1041 	aMap[SQL_WVARCHAR]			= DataType::VARCHAR;
1042 	aMap[SQL_LONGVARCHAR]		= DataType::LONGVARCHAR;
1043 	aMap[SQL_WLONGVARCHAR]		= DataType::LONGVARCHAR;
1044 
1045 	aMap[SQL_TYPE_DATE]			= DataType::DATE;
1046 	aMap[SQL_DATE]				= DataType::DATE;
1047 	aMap[SQL_TYPE_TIME]			= DataType::TIME;
1048 	aMap[SQL_TIME]				= DataType::TIME;
1049 	aMap[SQL_TYPE_TIMESTAMP]	= DataType::TIMESTAMP;
1050 	aMap[SQL_TIMESTAMP]			= DataType::TIMESTAMP;
1051 
1052 	aMap[SQL_DECIMAL]			= DataType::DECIMAL;
1053 	aMap[SQL_NUMERIC]			= DataType::NUMERIC;
1054 
1055 	aMap[SQL_BINARY]			= DataType::BINARY;
1056 	aMap[SQL_VARBINARY]			= DataType::VARBINARY;
1057 	aMap[SQL_LONGVARBINARY]		= DataType::LONGVARBINARY;
1058 
1059 	aMap[SQL_GUID]				= DataType::VARBINARY;
1060 
1061 	m_aValueRange[5] = aMap;
1062 	checkColumnCount();
1063 }
1064 // -------------------------------------------------------------------------
openProcedureColumns(const Any & catalog,const::rtl::OUString & schemaPattern,const::rtl::OUString & procedureNamePattern,const::rtl::OUString & columnNamePattern)1065 void ODatabaseMetaDataResultSet::openProcedureColumns(	const Any& catalog,		const ::rtl::OUString& schemaPattern,
1066 								const ::rtl::OUString& procedureNamePattern,const ::rtl::OUString& columnNamePattern )
1067 								throw(SQLException, RuntimeException)
1068 {
1069 	const ::rtl::OUString *pSchemaPat = NULL;
1070 
1071 	if(schemaPattern.toChar() != '%')
1072 		pSchemaPat = &schemaPattern;
1073 	else
1074 		pSchemaPat = NULL;
1075 
1076 	m_bFreeHandle = sal_True;
1077 	::rtl::OString aPKQ,aPKO,aPKN,aCOL;
1078 	if ( catalog.hasValue() )
1079 		aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1080 	aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding);
1081 
1082 	const char	*pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr()	: NULL,
1083 				*pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1084 				*pPKN = (aPKN = ::rtl::OUStringToOString(procedureNamePattern,m_nTextEncoding)).getStr(),
1085 				*pCOL = (aCOL = ::rtl::OUStringToOString(columnNamePattern,m_nTextEncoding)).getStr();
1086 
1087 
1088 	SQLRETURN nRetcode = N3SQLProcedureColumns(m_aStatementHandle,
1089 							(SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1090 							(SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1091 							(SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1092 							(SDB_ODBC_CHAR *) pCOL, SQL_NTS);
1093 
1094 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1095 	checkColumnCount();
1096 }
1097 // -------------------------------------------------------------------------
openProcedures(const Any & catalog,const::rtl::OUString & schemaPattern,const::rtl::OUString & procedureNamePattern)1098 void ODatabaseMetaDataResultSet::openProcedures(const Any& catalog, const ::rtl::OUString& schemaPattern,
1099 								const ::rtl::OUString& procedureNamePattern)
1100 								throw(SQLException, RuntimeException)
1101 {
1102 	const ::rtl::OUString *pSchemaPat = NULL;
1103 
1104 	if(schemaPattern.toChar() != '%')
1105 		pSchemaPat = &schemaPattern;
1106 	else
1107 		pSchemaPat = NULL;
1108 
1109 	m_bFreeHandle = sal_True;
1110 	::rtl::OString aPKQ,aPKO,aPKN,aCOL;
1111 
1112 	if ( catalog.hasValue() )
1113 		aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1114 	aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding);
1115 
1116 	const char	*pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr()	: NULL,
1117 				*pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1118 				*pPKN = (aPKN = ::rtl::OUStringToOString(procedureNamePattern,m_nTextEncoding)).getStr();
1119 
1120 
1121 	SQLRETURN nRetcode = N3SQLProcedures(m_aStatementHandle,
1122 							(SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1123 							(SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1124 							(SDB_ODBC_CHAR *) pPKN, SQL_NTS);
1125 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1126 	checkColumnCount();
1127 }
1128 // -------------------------------------------------------------------------
openSpecialColumns(sal_Bool _bRowVer,const Any & catalog,const::rtl::OUString & schema,const::rtl::OUString & table,sal_Int32 scope,sal_Bool nullable)1129 void ODatabaseMetaDataResultSet::openSpecialColumns(sal_Bool _bRowVer,const Any& catalog, const ::rtl::OUString& schema,
1130 									const ::rtl::OUString& table,sal_Int32 scope, 	sal_Bool nullable )
1131 									throw(SQLException, RuntimeException)
1132 {
1133 	const ::rtl::OUString *pSchemaPat = NULL;
1134 
1135 	if(schema.toChar() != '%')
1136 		pSchemaPat = &schema;
1137 	else
1138 		pSchemaPat = NULL;
1139 
1140 	m_bFreeHandle = sal_True;
1141 	::rtl::OString aPKQ,aPKO,aPKN,aCOL;
1142 	if ( catalog.hasValue() )
1143 	aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1144 	aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding);
1145 
1146 	const char	*pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr()	: NULL,
1147 				*pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1148 				*pPKN = (aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding)).getStr();
1149 
1150 
1151 	SQLRETURN nRetcode = N3SQLSpecialColumns(m_aStatementHandle,_bRowVer ? SQL_ROWVER : SQL_BEST_ROWID,
1152 							(SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1153 							(SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1154 							(SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1155 							(SQLSMALLINT)scope,
1156 							nullable ? SQL_NULLABLE : SQL_NO_NULLS);
1157 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1158 	checkColumnCount();
1159 }
1160 // -------------------------------------------------------------------------
openVersionColumns(const Any & catalog,const::rtl::OUString & schema,const::rtl::OUString & table)1161 void ODatabaseMetaDataResultSet::openVersionColumns(const Any& catalog, const ::rtl::OUString& schema,
1162 									const ::rtl::OUString& table)  throw(SQLException, RuntimeException)
1163 {
1164 	openSpecialColumns(sal_True,catalog,schema,table,SQL_SCOPE_TRANSACTION,sal_False);
1165 }
1166 // -------------------------------------------------------------------------
openBestRowIdentifier(const Any & catalog,const::rtl::OUString & schema,const::rtl::OUString & table,sal_Int32 scope,sal_Bool nullable)1167 void ODatabaseMetaDataResultSet::openBestRowIdentifier( const Any& catalog, const ::rtl::OUString& schema,
1168 										const ::rtl::OUString& table,sal_Int32 scope,sal_Bool nullable ) throw(SQLException, RuntimeException)
1169 {
1170 	openSpecialColumns(sal_False,catalog,schema,table,scope,nullable);
1171 }
1172 // -------------------------------------------------------------------------
openForeignKeys(const Any & catalog,const::rtl::OUString * schema,const::rtl::OUString * table,const Any & catalog2,const::rtl::OUString * schema2,const::rtl::OUString * table2)1173 void ODatabaseMetaDataResultSet::openForeignKeys( const Any& catalog, const ::rtl::OUString* schema,
1174 								  const ::rtl::OUString* table,
1175 								  const Any& catalog2, const ::rtl::OUString* schema2,
1176 								  const ::rtl::OUString* table2) throw(SQLException, RuntimeException)
1177 {
1178 	m_bFreeHandle = sal_True;
1179 
1180 	::rtl::OString aPKQ,aPKO,aPKN, aFKQ, aFKO, aFKN;
1181     if ( catalog.hasValue() )
1182 	    aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1183     if ( catalog2.hasValue() )
1184 	    aFKQ = ::rtl::OUStringToOString(comphelper::getString(catalog2),m_nTextEncoding);
1185 
1186 	const char	*pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr()	: NULL,
1187 				*pPKO = schema && schema->getLength() ? ::rtl::OUStringToOString(*schema,m_nTextEncoding).getStr() : NULL,
1188 				*pPKN = table   ? (aPKN = ::rtl::OUStringToOString(*table,m_nTextEncoding)).getStr(): NULL,
1189 				*pFKQ = catalog2.hasValue() && aFKQ.getLength() ? aFKQ.getStr()	: NULL,
1190 				*pFKO = schema2 && schema2->getLength() ? (aFKO = ::rtl::OUStringToOString(*schema2,m_nTextEncoding)).getStr() : NULL,
1191 				*pFKN = table2  ? (aFKN = ::rtl::OUStringToOString(*table2,m_nTextEncoding)).getStr() : NULL;
1192 
1193 
1194 	SQLRETURN nRetcode = N3SQLForeignKeys(m_aStatementHandle,
1195 							(SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1196 							(SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0,
1197 							(SDB_ODBC_CHAR *) pPKN, pPKN ? SQL_NTS : 0,
1198 							(SDB_ODBC_CHAR *) pFKQ, (catalog2.hasValue() && aFKQ.getLength()) ? SQL_NTS : 0,
1199 							(SDB_ODBC_CHAR *) pFKO, pFKO ? SQL_NTS : 0,
1200 							(SDB_ODBC_CHAR *) pFKN, SQL_NTS
1201 							);
1202 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1203 	checkColumnCount();
1204 }
1205 // -------------------------------------------------------------------------
openImportedKeys(const Any & catalog,const::rtl::OUString & schema,const::rtl::OUString & table)1206 void ODatabaseMetaDataResultSet::openImportedKeys(const Any& catalog, const ::rtl::OUString& schema,
1207 								  const ::rtl::OUString& table)	throw(SQLException, RuntimeException)
1208 {
1209 
1210 	openForeignKeys(Any(),NULL,NULL,catalog,!schema.compareToAscii("%") ? &schema : NULL,&table);
1211 }
1212 // -------------------------------------------------------------------------
openExportedKeys(const Any & catalog,const::rtl::OUString & schema,const::rtl::OUString & table)1213 void ODatabaseMetaDataResultSet::openExportedKeys(const Any& catalog, const ::rtl::OUString& schema,
1214 								  const ::rtl::OUString& table)	throw(SQLException, RuntimeException)
1215 {
1216 	openForeignKeys(catalog,!schema.compareToAscii("%") ? &schema : NULL,&table,Any(),NULL,NULL);
1217 }
1218 // -------------------------------------------------------------------------
openPrimaryKeys(const Any & catalog,const::rtl::OUString & schema,const::rtl::OUString & table)1219 void ODatabaseMetaDataResultSet::openPrimaryKeys(const Any& catalog, const ::rtl::OUString& schema,
1220 								  const ::rtl::OUString& table)	throw(SQLException, RuntimeException)
1221 {
1222 	const ::rtl::OUString *pSchemaPat = NULL;
1223 
1224 	if(schema.toChar() != '%')
1225 		pSchemaPat = &schema;
1226 	else
1227 		pSchemaPat = NULL;
1228 
1229 	m_bFreeHandle = sal_True;
1230 	::rtl::OString aPKQ,aPKO,aPKN,aCOL;
1231 
1232 	if ( catalog.hasValue() )
1233 		aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1234 	aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding);
1235 
1236 	const char	*pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr()	: NULL,
1237 				*pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1238 				*pPKN = (aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding)).getStr();
1239 
1240 
1241 	SQLRETURN nRetcode = N3SQLPrimaryKeys(m_aStatementHandle,
1242 							(SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1243 							(SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1244 							(SDB_ODBC_CHAR *) pPKN, SQL_NTS);
1245 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1246 	checkColumnCount();
1247 }
1248 // -------------------------------------------------------------------------
openTablePrivileges(const Any & catalog,const::rtl::OUString & schemaPattern,const::rtl::OUString & tableNamePattern)1249 void ODatabaseMetaDataResultSet::openTablePrivileges(const Any& catalog, const ::rtl::OUString& schemaPattern,
1250 								  const ::rtl::OUString& tableNamePattern) throw(SQLException, RuntimeException)
1251 {
1252 	const ::rtl::OUString *pSchemaPat = NULL;
1253 
1254 	if(schemaPattern.toChar() != '%')
1255 		pSchemaPat = &schemaPattern;
1256 	else
1257 		pSchemaPat = NULL;
1258 
1259 	m_bFreeHandle = sal_True;
1260 	::rtl::OString aPKQ,aPKO,aPKN;
1261 
1262 	if ( catalog.hasValue() )
1263 		aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1264 	aPKO = ::rtl::OUStringToOString(schemaPattern,m_nTextEncoding);
1265 
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();
1269 
1270 
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();
1277 }
1278 // -------------------------------------------------------------------------
openIndexInfo(const Any & catalog,const::rtl::OUString & schema,const::rtl::OUString & table,sal_Bool unique,sal_Bool approximate)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)
1282 {
1283 	const ::rtl::OUString *pSchemaPat = NULL;
1284 
1285 	if(schema.toChar() != '%')
1286 		pSchemaPat = &schema;
1287 	else
1288 		pSchemaPat = NULL;
1289 
1290 	m_bFreeHandle = sal_True;
1291 	::rtl::OString aPKQ,aPKO,aPKN;
1292 
1293 	if ( catalog.hasValue() )
1294 		aPKQ = ::rtl::OUStringToOString(comphelper::getString(catalog),m_nTextEncoding);
1295 	aPKO = ::rtl::OUStringToOString(schema,m_nTextEncoding);
1296 
1297 	const char	*pPKQ = catalog.hasValue() && aPKQ.getLength() ? aPKQ.getStr()	: NULL,
1298 				*pPKO = pSchemaPat && pSchemaPat->getLength() ? aPKO.getStr() : NULL,
1299 				*pPKN = (aPKN = ::rtl::OUStringToOString(table,m_nTextEncoding)).getStr();
1300 
1301 
1302 	SQLRETURN nRetcode = N3SQLStatistics(m_aStatementHandle,
1303 							(SDB_ODBC_CHAR *) pPKQ, (catalog.hasValue() && aPKQ.getLength()) ? SQL_NTS : 0,
1304 							(SDB_ODBC_CHAR *) pPKO, pPKO ? SQL_NTS : 0 ,
1305 							(SDB_ODBC_CHAR *) pPKN, SQL_NTS,
1306 							unique ? SQL_INDEX_UNIQUE : SQL_INDEX_ALL,
1307 							approximate);
1308 	OTools::ThrowException(m_pConnection,nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1309 	checkColumnCount();
1310 }
1311 // -------------------------------------------------------------------------
checkColumnCount()1312 void ODatabaseMetaDataResultSet::checkColumnCount()
1313 {
1314 	sal_Int16 nNumResultCols=0;
1315 	OTools::ThrowException(m_pConnection,N3SQLNumResultCols(m_aStatementHandle,&nNumResultCols),m_aStatementHandle,SQL_HANDLE_STMT,*this);
1316 	m_nDriverColumnCount = nNumResultCols;
1317 }
1318 // -----------------------------------------------------------------------------
1319 
impl_getColumnType_nothrow(sal_Int32 columnIndex)1320 SWORD ODatabaseMetaDataResultSet::impl_getColumnType_nothrow(sal_Int32 columnIndex)
1321 {
1322     ::std::map<sal_Int32,SWORD>::iterator aFind = m_aODBCColumnTypes.find(columnIndex);
1323     if ( aFind == m_aODBCColumnTypes.end() )
1324         aFind = m_aODBCColumnTypes.insert(::std::map<sal_Int32,SWORD>::value_type(columnIndex,OResultSetMetaData::getColumnODBCType(m_pConnection,m_aStatementHandle,*this,columnIndex))).first;
1325     return aFind->second;
1326 }
1327 
1328