LibreOffice Module connectivity (master) 1
ODatabaseMetaDataResultSet.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <TConnection.hxx>
21
23#include <com/sun/star/sdbc/DataType.hpp>
28#include <odbc/OTools.hxx>
29#include <comphelper/types.hxx>
31
32using namespace ::comphelper;
33
34
35using namespace connectivity::odbc;
36using namespace cppu;
37
38using namespace ::com::sun::star::lang;
39using namespace com::sun::star::uno;
40using namespace com::sun::star::beans;
41using namespace com::sun::star::sdbc;
42using namespace com::sun::star::util;
43
44
45ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet(OConnection* _pConnection)
48
49 ,m_aStatementHandle(_pConnection->createStatementHandle())
50 ,m_pConnection(_pConnection)
51 ,m_nTextEncoding(_pConnection->getTextEncoding())
52 ,m_nRowPos(-1)
53 ,m_nDriverColumnCount(0)
54 ,m_nCurrentFetchState(0)
55 ,m_bWasNull(true)
56 ,m_bEOF(false)
57{
58 OSL_ENSURE(m_pConnection.is(),"ODatabaseMetaDataResultSet::ODatabaseMetaDataResultSet: No parent set!");
59 if( SQL_NULL_HANDLE == m_aStatementHandle )
60 throw RuntimeException();
61
62 osl_atomic_increment( &m_refCount );
63 m_pRowStatusArray.reset( new SQLUSMALLINT[1] ); // the default value
64 osl_atomic_decrement( &m_refCount );
65}
66
67
69{
70 OSL_ENSURE(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed,"Object wasn't disposed!");
71 if(!ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed)
72 {
73 osl_atomic_increment( &m_refCount );
74 dispose();
75 }
76}
77
79{
81
82 ::osl::MutexGuard aGuard(m_aMutex);
83
84 m_pConnection->freeStatementHandle(m_aStatementHandle);
85
86 m_aStatement.clear();
87 m_xMetaData.clear();
88 m_pConnection.clear();
89}
90
92{
94 return aRet.hasValue() ? aRet : ODatabaseMetaDataResultSet_BASE::queryInterface(rType);
95}
96
98{
99 return ::cppu::OPropertySetHelper::createPropertySetInfo(getInfoHelper());
100}
101
103{
104 ODatabaseMetaDataResultSet_BASE::acquire();
105}
106
108{
109 ODatabaseMetaDataResultSet_BASE::release();
110}
111
113{
117
118 return ::comphelper::concatSequences(aTypes.getTypes(),ODatabaseMetaDataResultSet_BASE::getTypes());
119}
120
121sal_Int32 ODatabaseMetaDataResultSet::mapColumn (sal_Int32 column)
122{
123 sal_Int32 map = column;
124
125 if (!m_aColMapping.empty())
126 {
127 // Validate column number
128 map = m_aColMapping[column];
129 }
130
131 return map;
132}
133
134
135sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const OUString& columnName )
136{
137
138 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
139 ::osl::MutexGuard aGuard( m_aMutex );
140
141
143 sal_Int32 nLen = xMeta->getColumnCount();
144 sal_Int32 i = 1;
145 for(;i<=nLen;++i)
146 {
147 if(xMeta->isCaseSensitive(i) ? columnName == xMeta->getColumnName(i) :
148 columnName.equalsIgnoreAsciiCase(xMeta->getColumnName(i)))
149 return i;
150 }
151
153 assert(false);
154 return 0; // Never reached
155}
156
157template < typename T, SQLSMALLINT sqlTypeId > T ODatabaseMetaDataResultSet::getInteger ( sal_Int32 columnIndex )
158{
159 ::cppu::OBroadcastHelper& rBHelper(ODatabaseMetaDataResultSet_BASE::rBHelper);
161 ::osl::MutexGuard aGuard( m_aMutex );
162
163 columnIndex = mapColumn(columnIndex);
164 T nVal = 0;
165 if(columnIndex <= m_nDriverColumnCount)
166 {
167 getValue<T>(m_pConnection.get(), m_aStatementHandle, columnIndex, sqlTypeId, m_bWasNull, **this, nVal);
168
169 if ( !m_aValueRange.empty() )
170 {
171 auto aValueRangeIter = m_aValueRange.find(columnIndex);
172 if ( aValueRangeIter != m_aValueRange.end() )
173 return static_cast<T>(aValueRangeIter->second[nVal]);
174 }
175 }
176 else
177 m_bWasNull = true;
178 return nVal;
179}
180
181
183{
184 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getBinaryStream", *this );
185 return nullptr;
186}
187
189{
190 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getCharacterStream", *this );
191 return nullptr;
192}
193
194
195sal_Bool SAL_CALL ODatabaseMetaDataResultSet::getBoolean( sal_Int32 columnIndex )
196{
197
198 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
199 ::osl::MutexGuard aGuard( m_aMutex );
200
201 columnIndex = mapColumn(columnIndex);
202
203 bool bRet = false;
204 if(columnIndex <= m_nDriverColumnCount)
205 {
206 sal_Int32 nType = getMetaData()->getColumnType(columnIndex);
207 switch(nType)
208 {
209 case DataType::BIT:
210 {
211 sal_Int8 nValue = 0;
212 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,SQL_C_BIT,m_bWasNull,**this,&nValue,sizeof nValue);
213 bRet = nValue != 0;
214 }
215 break;
216 default:
217 bRet = getInt(columnIndex) != 0;
218 }
219 }
220 return bRet;
221}
222
223
224sal_Int8 SAL_CALL ODatabaseMetaDataResultSet::getByte( sal_Int32 columnIndex )
225{
226 return getInteger<sal_Int8, SQL_C_STINYINT>( columnIndex );
227}
228
229
231{
232
233 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
234 ::osl::MutexGuard aGuard( m_aMutex );
235
236
237 columnIndex = mapColumn(columnIndex);
238 if(columnIndex <= m_nDriverColumnCount)
239 {
240 sal_Int32 nType = getMetaData()->getColumnType(columnIndex);
241 switch(nType)
242 {
243 case DataType::CHAR:
244 case DataType::VARCHAR:
245 case DataType::LONGVARCHAR:
246 {
247 OUString const & aRet = OTools::getStringValue(m_pConnection.get(),m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this,m_nTextEncoding);
248 return Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(aRet.getStr()),sizeof(sal_Unicode)*aRet.getLength());
249 }
250 }
251 return OTools::getBytesValue(m_pConnection.get(),m_aStatementHandle,columnIndex,SQL_C_BINARY,m_bWasNull,**this);
252 }
253 else
254 m_bWasNull = true;
255 return Sequence<sal_Int8>();
256}
257
258
259css::util::Date SAL_CALL ODatabaseMetaDataResultSet::getDate( sal_Int32 columnIndex )
260{
261 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
262 ::osl::MutexGuard aGuard( m_aMutex );
263
264
265 columnIndex = mapColumn(columnIndex);
266 if(columnIndex <= m_nDriverColumnCount)
267 {
268 DATE_STRUCT aDate;
269 aDate.day = 0;
270 aDate.month = 0;
271 aDate.year = 0;
272 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_DATE : SQL_C_TYPE_DATE,m_bWasNull,**this,&aDate,sizeof aDate);
273 return Date(aDate.day,aDate.month,aDate.year);
274 }
275 else
276 m_bWasNull = true;
277 return Date();
278}
279
280
281double SAL_CALL ODatabaseMetaDataResultSet::getDouble( sal_Int32 columnIndex )
282{
283
284 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
285 ::osl::MutexGuard aGuard( m_aMutex );
286
287
288 columnIndex = mapColumn(columnIndex);
289 double nValue(0.0);
290 if(columnIndex <= m_nDriverColumnCount)
291 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,SQL_C_DOUBLE,m_bWasNull,**this,&nValue,sizeof nValue);
292 else
293 m_bWasNull = true;
294 return nValue;
295}
296
297
298float SAL_CALL ODatabaseMetaDataResultSet::getFloat( sal_Int32 columnIndex )
299{
300
301 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
302 ::osl::MutexGuard aGuard( m_aMutex );
303
304
305 columnIndex = mapColumn(columnIndex);
306 float nVal(0);
307 if(columnIndex <= m_nDriverColumnCount)
308 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,SQL_C_FLOAT,m_bWasNull,**this,&nVal,sizeof nVal);
309 else
310 m_bWasNull = true;
311 return nVal;
312}
313
314
315sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::getInt( sal_Int32 columnIndex )
316{
317 return getInteger<sal_Int32, SQL_C_SLONG>( columnIndex );
318}
319
320
322{
323 return 0;
324}
325
326
327sal_Int64 SAL_CALL ODatabaseMetaDataResultSet::getLong( sal_Int32 columnIndex )
328{
329 return getInteger<sal_Int64, SQL_C_SBIGINT>( columnIndex );
330}
331
332
334{
335 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
336 ::osl::MutexGuard aGuard( m_aMutex );
337 if (!m_xMetaData.is())
339 return m_xMetaData;
340}
341
343{
344 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getArray", *this );
345 return nullptr;
346}
347
348Reference< XClob > SAL_CALL ODatabaseMetaDataResultSet::getClob( sal_Int32 /*columnIndex*/ )
349{
350 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getClob", *this );
351 return nullptr;
352}
353
354Reference< XBlob > SAL_CALL ODatabaseMetaDataResultSet::getBlob( sal_Int32 /*columnIndex*/ )
355{
356 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getBlob", *this );
357 return nullptr;
358}
359
360
361Reference< XRef > SAL_CALL ODatabaseMetaDataResultSet::getRef( sal_Int32 /*columnIndex*/ )
362{
364 return nullptr;
365}
366
367
368Any SAL_CALL ODatabaseMetaDataResultSet::getObject( sal_Int32 /*columnIndex*/, const Reference< css::container::XNameAccess >& /*typeMap*/ )
369{
370 ::dbtools::throwFunctionNotSupportedSQLException( "XRow::getObject", *this );
371 return Any();
372}
373
374
375sal_Int16 SAL_CALL ODatabaseMetaDataResultSet::getShort( sal_Int32 columnIndex )
376{
377 return getInteger<sal_Int16, SQL_C_SSHORT>( columnIndex );
378}
379
380
381OUString SAL_CALL ODatabaseMetaDataResultSet::getString( sal_Int32 columnIndex )
382{
383
384 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
385 ::osl::MutexGuard aGuard( m_aMutex );
386
387
388 columnIndex = mapColumn(columnIndex);
389 OUString aVal;
390 if(columnIndex <= m_nDriverColumnCount)
392 else
393 m_bWasNull = true;
394
395 return aVal;
396}
397
398
399css::util::Time SAL_CALL ODatabaseMetaDataResultSet::getTime( sal_Int32 columnIndex )
400{
401
402 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
403 ::osl::MutexGuard aGuard( m_aMutex );
404
405
406 columnIndex = mapColumn(columnIndex);
407 TIME_STRUCT aTime={0,0,0};
408 if(columnIndex <= m_nDriverColumnCount)
409 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIME : SQL_C_TYPE_TIME,m_bWasNull,**this,&aTime,sizeof aTime);
410 else
411 m_bWasNull = true;
412 return Time(0, aTime.second,aTime.minute,aTime.hour, false);
413}
414
415
416css::util::DateTime SAL_CALL ODatabaseMetaDataResultSet::getTimestamp( sal_Int32 columnIndex )
417{
418
419 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
420 ::osl::MutexGuard aGuard( m_aMutex );
421
422
423 columnIndex = mapColumn(columnIndex);
424 TIMESTAMP_STRUCT aTime={0,0,0,0,0,0,0};
425 if(columnIndex <= m_nDriverColumnCount)
426 OTools::getValue(m_pConnection.get(),m_aStatementHandle,columnIndex,m_pConnection->useOldDateFormat() ? SQL_C_TIMESTAMP : SQL_C_TYPE_TIMESTAMP, m_bWasNull, **this, &aTime, sizeof aTime);
427 else
428 m_bWasNull = true;
429 return DateTime(aTime.fraction, aTime.second, aTime.minute, aTime.hour,
430 aTime.day, aTime.month, aTime.year, false);
431}
432
433
435{
436
437 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
438 ::osl::MutexGuard aGuard( m_aMutex );
439
440
441 return m_nCurrentFetchState == SQL_NO_DATA;
442}
443
445{
446
447 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
448 ::osl::MutexGuard aGuard( m_aMutex );
449
450
451 return m_nRowPos == 1;
452}
453
455{
456
457 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
458 ::osl::MutexGuard aGuard( m_aMutex );
459
460
461 return m_bEOF && m_nCurrentFetchState != SQL_NO_DATA;
462}
463
465{
466
467 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
468 ::osl::MutexGuard aGuard( m_aMutex );
469
470
471 if(first())
472 previous();
473 m_nCurrentFetchState = SQL_SUCCESS;
474}
475
477{
478
479 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
480 ::osl::MutexGuard aGuard( m_aMutex );
481
482
483 if(last())
484 next();
485}
486
487
489{
490 {
491
492 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
493 ::osl::MutexGuard aGuard( m_aMutex );
494
495 }
496 dispose();
497}
498
499
501{
502
503 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
504 ::osl::MutexGuard aGuard( m_aMutex );
505
506 m_bEOF = false;
507
510 bool bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO );
511 if( bRet )
512 m_nRowPos = 1;
513 return bRet;
514}
515
516
518{
519 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed );
520 ::osl::MutexGuard aGuard( m_aMutex );
521
522
525 // here I know definitely that I stand on the last record
526 bool bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO );
527 if( bRet )
528 m_bEOF = true;
529 return bRet;
530}
531
533{
534
535 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
536 ::osl::MutexGuard aGuard( m_aMutex );
537
538 m_bEOF = false;
539
542 bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
543 if(bRet)
544 m_nRowPos = row;
545 return bRet;
546}
547
549{
550
551 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
552 ::osl::MutexGuard aGuard( m_aMutex );
553
554 m_bEOF = false;
555
558 bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
559 if(bRet)
560 m_nRowPos += row;
561 return bRet;
562}
563
565{
566
567 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
568 ::osl::MutexGuard aGuard( m_aMutex );
569
570 m_bEOF = false;
571
574 bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
575 if(bRet)
576 --m_nRowPos;
577 else if ( m_nCurrentFetchState == SQL_NO_DATA )
578 m_nRowPos = 0;
579 return bRet;
580}
581
583{
584 return nullptr;
585}
586
587
589{
590
591 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
592 ::osl::MutexGuard aGuard( m_aMutex );
593
594
595 return m_pRowStatusArray[0] == SQL_ROW_DELETED;
596}
597
599{
600 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
601 ::osl::MutexGuard aGuard( m_aMutex );
602
603
604 return m_pRowStatusArray[0] == SQL_ROW_ADDED;
605}
606
608{
609
610 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
611 ::osl::MutexGuard aGuard( m_aMutex );
612
613
614 return m_pRowStatusArray[0] == SQL_ROW_UPDATED;
615}
616
617
619{
620
621 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
622 ::osl::MutexGuard aGuard( m_aMutex );
623
624
625 return m_nRowPos == 0;
626}
627
628
630{
631
632 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
633 ::osl::MutexGuard aGuard( m_aMutex );
634
635 m_bEOF = false;
636
637 SQLRETURN nOldFetchStatus = m_nCurrentFetchState;
638 // m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0);
641 bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
642 if(bRet || ( m_nCurrentFetchState == SQL_NO_DATA && nOldFetchStatus != SQL_NO_DATA ) )
643 ++m_nRowPos;
644 return bRet;
645}
646
647
649{
650
651 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
652 ::osl::MutexGuard aGuard( m_aMutex );
653
654
655 return m_bWasNull;
656}
657
659{
660
661 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
662 ::osl::MutexGuard aGuard( m_aMutex );
663
664}
665
666
668{
669
670 checkDisposed(ODatabaseMetaDataResultSet_BASE::rBHelper.bDisposed);
671 ::osl::MutexGuard aGuard( m_aMutex );
672
673
675}
676
678{
679}
680
682{
683 return Any();
684}
685
687{
688 return 1;
689}
690
692{
693 return OUString();
694}
695
696
698{
699
700 return new ::cppu::OPropertyArrayHelper
701 {
702 {
703 {
707 0
708 },
709 {
713 0
714 },
715 {
719 0
720 },
721 {
725 0
726 },
727 {
731 0
732 }
733 }
734 };
735}
736
738{
739 return *getArrayHelper();
740}
741
743 Any & rConvertedValue,
744 Any & rOldValue,
745 sal_Int32 nHandle,
746 const Any& rValue )
747{
748 switch(nHandle)
749 {
753 throw css::lang::IllegalArgumentException();
755 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchDirection());
757 return ::comphelper::tryPropertyValue(rConvertedValue, rOldValue, rValue, getFetchSize());
758 default:
759 ;
760 }
761 return false;
762}
763
764void ODatabaseMetaDataResultSet::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& /*rValue*/ )
765{
766 switch(nHandle)
767 {
773 throw Exception("cannot set prop " + OUString::number(nHandle), nullptr);
774 default:
775 OSL_FAIL("setFastPropertyValue_NoBroadcast: Illegal handle value!");
776 }
777}
778
779void ODatabaseMetaDataResultSet::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
780{
781 switch(nHandle)
782 {
784 rValue <<= getCursorName();
785 break;
787 rValue <<= sal_Int32(css::sdbc::ResultSetConcurrency::READ_ONLY);
788 break;
790 rValue <<= sal_Int32(css::sdbc::ResultSetType::FORWARD_ONLY);
791 break;
793 rValue <<= getFetchDirection();
794 break;
796 rValue <<= getFetchSize();
797 break;
798 }
799}
800
802{
803 ::std::map<sal_Int32,sal_Int32> aMap;
804 aMap[SQL_BIT] = DataType::BIT;
805 aMap[SQL_TINYINT] = DataType::TINYINT;
806 aMap[SQL_SMALLINT] = DataType::SMALLINT;
807 aMap[SQL_INTEGER] = DataType::INTEGER;
808 aMap[SQL_FLOAT] = DataType::FLOAT;
809 aMap[SQL_REAL] = DataType::REAL;
810 aMap[SQL_DOUBLE] = DataType::DOUBLE;
811 aMap[SQL_BIGINT] = DataType::BIGINT;
812
813 aMap[SQL_CHAR] = DataType::CHAR;
814 aMap[SQL_WCHAR] = DataType::CHAR;
815 aMap[SQL_VARCHAR] = DataType::VARCHAR;
816 aMap[SQL_WVARCHAR] = DataType::VARCHAR;
817 aMap[SQL_LONGVARCHAR] = DataType::LONGVARCHAR;
818 aMap[SQL_WLONGVARCHAR] = DataType::LONGVARCHAR;
819
820 aMap[SQL_TYPE_DATE] = DataType::DATE;
821 aMap[SQL_DATE] = DataType::DATE;
822 aMap[SQL_TYPE_TIME] = DataType::TIME;
823 aMap[SQL_TIME] = DataType::TIME;
824 aMap[SQL_TYPE_TIMESTAMP] = DataType::TIMESTAMP;
825 aMap[SQL_TIMESTAMP] = DataType::TIMESTAMP;
826
827 aMap[SQL_DECIMAL] = DataType::DECIMAL;
828 aMap[SQL_NUMERIC] = DataType::NUMERIC;
829
830 aMap[SQL_BINARY] = DataType::BINARY;
831 aMap[SQL_VARBINARY] = DataType::VARBINARY;
832 aMap[SQL_LONGVARBINARY] = DataType::LONGVARBINARY;
833
834 aMap[SQL_GUID] = DataType::VARBINARY;
835
836
837 m_aValueRange[2] = aMap;
838
841}
842
843void ODatabaseMetaDataResultSet::openTables(const Any& catalog, const OUString& schemaPattern,
844 std::u16string_view tableNamePattern,
845 const Sequence< OUString >& types )
846{
847 OString aPKQ,aPKO,aPKN,aCOL;
848 const OUString *pSchemaPat = nullptr;
849
850 if(schemaPattern != "%")
851 pSchemaPat = &schemaPattern;
852 else
853 pSchemaPat = nullptr;
854
855 if ( catalog.hasValue() )
857 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
858 aPKN = OUStringToOString(tableNamePattern,m_nTextEncoding);
859
860 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
861 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
862 *pPKN = aPKN.getStr();
863
864
865 const char *pCOL = nullptr;
866 const char* const pComma = ",";
867 const OUString* pBegin = types.getConstArray();
868 const OUString* pEnd = pBegin + types.getLength();
869 for(;pBegin != pEnd;++pBegin)
870 {
871 aCOL += OUStringToOString(*pBegin,m_nTextEncoding) + pComma;
872 }
873 if ( !aCOL.isEmpty() )
874 {
875 aCOL = aCOL.replaceAt(aCOL.getLength()-1,1,pComma);
876 pCOL = aCOL.getStr();
877 }
878 else
879 pCOL = SQL_ALL_TABLE_TYPES;
880
881 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
882 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
883 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0,
884 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
885 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pCOL)), pCOL ? SQL_NTS : 0);
886 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
888
889}
890
892{
893 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
894 nullptr,0,
895 nullptr,0,
896 nullptr,0,
897 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(SQL_ALL_TABLE_TYPES)),SQL_NTS);
898 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
899
900 m_aColMapping.clear();
901 m_aColMapping.push_back(-1);
902 m_aColMapping.push_back(4);
905}
906
908{
909 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
910 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(SQL_ALL_CATALOGS)),SQL_NTS,
911 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS,
912 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS,
913 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS);
914
915 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
916
917 m_aColMapping.clear();
918 m_aColMapping.push_back(-1);
919 m_aColMapping.push_back(1);
922}
923
925{
926 SQLRETURN nRetcode = N3SQLTables(m_aStatementHandle,
927 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS,
928 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(SQL_ALL_SCHEMAS)),SQL_NTS,
929 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS,
930 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>("")),SQL_NTS);
931 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
932
933 m_aColMapping.clear();
934 m_aColMapping.push_back(-1);
935 m_aColMapping.push_back(2);
938}
939
940void ODatabaseMetaDataResultSet::openColumnPrivileges( const Any& catalog, const OUString& schema,
941 std::u16string_view table,
942 std::u16string_view columnNamePattern )
943{
944 const OUString *pSchemaPat = nullptr;
945
946 if(schema != "%")
947 pSchemaPat = &schema;
948 else
949 pSchemaPat = nullptr;
950
951 OString aPKQ,aPKO,aPKN,aCOL;
952
953 if ( catalog.hasValue() )
955 aPKO = OUStringToOString(schema,m_nTextEncoding);
957 aCOL = OUStringToOString(columnNamePattern,m_nTextEncoding);
958
959 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
960 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
961 *pPKN = aPKN.getStr(),
962 *pCOL = aCOL.getStr();
963
964
965 SQLRETURN nRetcode = N3SQLColumnPrivileges(m_aStatementHandle,
966 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
967 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
968 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
969 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pCOL)), SQL_NTS);
970 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
971
973}
974
975void ODatabaseMetaDataResultSet::openColumns( const Any& catalog, const OUString& schemaPattern,
976 std::u16string_view tableNamePattern, std::u16string_view columnNamePattern )
977{
978 const OUString *pSchemaPat = nullptr;
979
980 if(schemaPattern != "%")
981 pSchemaPat = &schemaPattern;
982 else
983 pSchemaPat = nullptr;
984
985 OString aPKQ,aPKO,aPKN,aCOL;
986 if ( catalog.hasValue() )
988 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
989 aPKN = OUStringToOString(tableNamePattern,m_nTextEncoding);
990 aCOL = OUStringToOString(columnNamePattern,m_nTextEncoding);
991
992 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
993 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
994 *pPKN = aPKN.getStr(),
995 *pCOL = aCOL.getStr();
996
997
998 SQLRETURN nRetcode = N3SQLColumns(m_aStatementHandle,
999 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1000 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0,
1001 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
1002 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pCOL)), SQL_NTS);
1003
1004 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1005 ::std::map<sal_Int32,sal_Int32> aMap;
1006 aMap[SQL_BIT] = DataType::BIT;
1007 aMap[SQL_TINYINT] = DataType::TINYINT;
1008 aMap[SQL_SMALLINT] = DataType::SMALLINT;
1009 aMap[SQL_INTEGER] = DataType::INTEGER;
1010 aMap[SQL_FLOAT] = DataType::FLOAT;
1011 aMap[SQL_REAL] = DataType::REAL;
1012 aMap[SQL_DOUBLE] = DataType::DOUBLE;
1013 aMap[SQL_BIGINT] = DataType::BIGINT;
1014
1015 aMap[SQL_CHAR] = DataType::CHAR;
1016 aMap[SQL_WCHAR] = DataType::CHAR;
1017 aMap[SQL_VARCHAR] = DataType::VARCHAR;
1018 aMap[SQL_WVARCHAR] = DataType::VARCHAR;
1019 aMap[SQL_LONGVARCHAR] = DataType::LONGVARCHAR;
1020 aMap[SQL_WLONGVARCHAR] = DataType::LONGVARCHAR;
1021
1022 aMap[SQL_TYPE_DATE] = DataType::DATE;
1023 aMap[SQL_DATE] = DataType::DATE;
1024 aMap[SQL_TYPE_TIME] = DataType::TIME;
1025 aMap[SQL_TIME] = DataType::TIME;
1026 aMap[SQL_TYPE_TIMESTAMP] = DataType::TIMESTAMP;
1027 aMap[SQL_TIMESTAMP] = DataType::TIMESTAMP;
1028
1029 aMap[SQL_DECIMAL] = DataType::DECIMAL;
1030 aMap[SQL_NUMERIC] = DataType::NUMERIC;
1031
1032 aMap[SQL_BINARY] = DataType::BINARY;
1033 aMap[SQL_VARBINARY] = DataType::VARBINARY;
1034 aMap[SQL_LONGVARBINARY] = DataType::LONGVARBINARY;
1035
1036 aMap[SQL_GUID] = DataType::VARBINARY;
1037
1038 m_aValueRange[5] = aMap;
1040}
1041
1042void ODatabaseMetaDataResultSet::openProcedureColumns( const Any& catalog, const OUString& schemaPattern,
1043 std::u16string_view procedureNamePattern,std::u16string_view columnNamePattern )
1044{
1045 const OUString *pSchemaPat = nullptr;
1046
1047 if(schemaPattern != "%")
1048 pSchemaPat = &schemaPattern;
1049 else
1050 pSchemaPat = nullptr;
1051
1052 OString aPKQ,aPKO,aPKN,aCOL;
1053 if ( catalog.hasValue() )
1055 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
1056 aPKN = OUStringToOString(procedureNamePattern,m_nTextEncoding);
1057 aCOL = OUStringToOString(columnNamePattern,m_nTextEncoding);
1058
1059 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1060 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1061 *pPKN = aPKN.getStr(),
1062 *pCOL = aCOL.getStr();
1063
1064
1065 SQLRETURN nRetcode = N3SQLProcedureColumns(m_aStatementHandle,
1066 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1067 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1068 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
1069 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pCOL)), SQL_NTS);
1070
1071 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1073}
1074
1075void ODatabaseMetaDataResultSet::openProcedures(const Any& catalog, const OUString& schemaPattern,
1076 std::u16string_view procedureNamePattern)
1077{
1078 const OUString *pSchemaPat = nullptr;
1079
1080 if(schemaPattern != "%")
1081 pSchemaPat = &schemaPattern;
1082 else
1083 pSchemaPat = nullptr;
1084
1085 OString aPKQ,aPKO,aPKN;
1086
1087 if ( catalog.hasValue() )
1089 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
1090 aPKN = OUStringToOString(procedureNamePattern,m_nTextEncoding);
1091
1092 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1093 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1094 *pPKN = aPKN.getStr();
1095
1096
1097 SQLRETURN nRetcode = N3SQLProcedures(m_aStatementHandle,
1098 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1099 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1100 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS);
1101 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1103}
1104
1105void ODatabaseMetaDataResultSet::openSpecialColumns(bool _bRowVer,const Any& catalog, const OUString& schema,
1106 std::u16string_view table,sal_Int32 scope, bool nullable )
1107{
1108 // Some ODBC drivers really don't like getting an empty string as tableName
1109 // E.g. psqlodbc up to at least version 09.01.0100 segfaults
1110 if (table.empty())
1111 {
1112 static constexpr OUStringLiteral errMsg
1113 = u"ODBC: Trying to get special columns of empty table name";
1114 static constexpr OUStringLiteral SQLState = u"HY009";
1115 throw SQLException( errMsg, *this, SQLState, -1, Any() );
1116 }
1117
1118 const OUString *pSchemaPat = nullptr;
1119
1120 if(schema != "%")
1121 pSchemaPat = &schema;
1122 else
1123 pSchemaPat = nullptr;
1124
1125 OString aPKQ,aPKO,aPKN;
1126 if ( catalog.hasValue() )
1128 aPKO = OUStringToOString(schema,m_nTextEncoding);
1130
1131 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1132 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1133 *pPKN = aPKN.getStr();
1134
1135
1136 SQLRETURN nRetcode = N3SQLSpecialColumns(m_aStatementHandle,_bRowVer ? SQL_ROWVER : SQL_BEST_ROWID,
1137 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1138 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1139 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
1140 static_cast<SQLSMALLINT>(scope),
1141 nullable ? SQL_NULLABLE : SQL_NO_NULLS);
1142 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1144}
1145
1146void ODatabaseMetaDataResultSet::openVersionColumns(const Any& catalog, const OUString& schema,
1147 std::u16string_view table)
1148{
1149 openSpecialColumns(true,catalog,schema,table,SQL_SCOPE_TRANSACTION,false);
1150}
1151
1152void ODatabaseMetaDataResultSet::openBestRowIdentifier( const Any& catalog, const OUString& schema,
1153 std::u16string_view table,sal_Int32 scope,bool nullable )
1154{
1155 openSpecialColumns(false,catalog,schema,table,scope,nullable);
1156}
1157
1158void ODatabaseMetaDataResultSet::openForeignKeys( const Any& catalog, const OUString* schema,
1159 const OUString* table,
1160 const Any& catalog2, const OUString* schema2,
1161 const OUString* table2)
1162{
1163 OString aPKQ, aPKO, aPKN, aFKQ, aFKO, aFKN;
1164 if ( catalog.hasValue() )
1166 if ( catalog2.hasValue() )
1168
1169 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr;
1170 const char *pPKO = nullptr;
1171 if (schema && !schema->isEmpty())
1172 {
1173 aPKO = OUStringToOString(*schema,m_nTextEncoding);
1174 pPKO = aPKO.getStr();
1175 }
1176 const char *pPKN = nullptr;
1177 if (table)
1178 {
1180 pPKN = aPKN.getStr();
1181 }
1182 const char *pFKQ = catalog2.hasValue() && !aFKQ.isEmpty() ? aFKQ.getStr() : nullptr;
1183 const char *pFKO = nullptr;
1184 if (schema2 && !schema2->isEmpty())
1185 {
1186 aFKO = OUStringToOString(*schema2,m_nTextEncoding);
1187 pFKO = aFKO.getStr();
1188 }
1189 const char *pFKN = nullptr;
1190 if (table2)
1191 {
1192 aFKN = OUStringToOString(*table2,m_nTextEncoding);
1193 pFKN = aFKN.getStr();
1194 }
1195
1196 SQLRETURN nRetcode = N3SQLForeignKeys(m_aStatementHandle,
1197 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1198 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0,
1199 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), pPKN ? SQL_NTS : 0,
1200 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pFKQ)), (catalog2.hasValue() && !aFKQ.isEmpty()) ? SQL_NTS : 0,
1201 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pFKO)), pFKO ? SQL_NTS : 0,
1202 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pFKN)), SQL_NTS
1203 );
1204 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1206}
1207
1208void ODatabaseMetaDataResultSet::openImportedKeys(const Any& catalog, const OUString& schema,
1209 const OUString& table)
1210{
1211
1212 openForeignKeys(Any(),nullptr,nullptr,catalog, schema == "%" ? &schema : nullptr, &table);
1213}
1214
1215void ODatabaseMetaDataResultSet::openExportedKeys(const Any& catalog, const OUString& schema,
1216 const OUString& table)
1217{
1218 openForeignKeys(catalog, schema == "%" ? &schema : nullptr, &table,Any(),nullptr,nullptr);
1219}
1220
1221void ODatabaseMetaDataResultSet::openPrimaryKeys(const Any& catalog, const OUString& schema,
1222 std::u16string_view table)
1223{
1224 const OUString *pSchemaPat = nullptr;
1225
1226 if(schema != "%")
1227 pSchemaPat = &schema;
1228 else
1229 pSchemaPat = nullptr;
1230
1231 OString aPKQ,aPKO,aPKN;
1232
1233 if ( catalog.hasValue() )
1235 aPKO = OUStringToOString(schema,m_nTextEncoding);
1237
1238 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1239 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1240 *pPKN = aPKN.getStr();
1241
1242
1243 SQLRETURN nRetcode = N3SQLPrimaryKeys(m_aStatementHandle,
1244 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1245 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1246 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS);
1247 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1249}
1250
1251void ODatabaseMetaDataResultSet::openTablePrivileges(const Any& catalog, const OUString& schemaPattern,
1252 std::u16string_view tableNamePattern)
1253{
1254 const OUString *pSchemaPat = nullptr;
1255
1256 if(schemaPattern != "%")
1257 pSchemaPat = &schemaPattern;
1258 else
1259 pSchemaPat = nullptr;
1260
1261 OString aPKQ,aPKO,aPKN;
1262
1263 if ( catalog.hasValue() )
1265 aPKO = OUStringToOString(schemaPattern,m_nTextEncoding);
1266 aPKN = OUStringToOString(tableNamePattern,m_nTextEncoding);
1267
1268 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1269 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1270 *pPKN = aPKN.getStr();
1271
1272 SQLRETURN nRetcode = N3SQLTablePrivileges(m_aStatementHandle,
1273 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1274 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1275 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS);
1276 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1278}
1279
1280void ODatabaseMetaDataResultSet::openIndexInfo( const Any& catalog, const OUString& schema,
1281 std::u16string_view table, bool unique, bool approximate )
1282{
1283 const OUString *pSchemaPat = nullptr;
1284
1285 if(schema != "%")
1286 pSchemaPat = &schema;
1287 else
1288 pSchemaPat = nullptr;
1289
1290 OString aPKQ,aPKO,aPKN;
1291
1292 if ( catalog.hasValue() )
1294 aPKO = OUStringToOString(schema,m_nTextEncoding);
1296
1297 const char *pPKQ = catalog.hasValue() && !aPKQ.isEmpty() ? aPKQ.getStr() : nullptr,
1298 *pPKO = pSchemaPat && !pSchemaPat->isEmpty() && !aPKO.isEmpty() ? aPKO.getStr() : nullptr,
1299 *pPKN = aPKN.getStr();
1300
1301 SQLRETURN nRetcode = N3SQLStatistics(m_aStatementHandle,
1302 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKQ)), (catalog.hasValue() && !aPKQ.isEmpty()) ? SQL_NTS : 0,
1303 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKO)), pPKO ? SQL_NTS : 0 ,
1304 reinterpret_cast<SDB_ODBC_CHAR *>(const_cast<char *>(pPKN)), SQL_NTS,
1305 unique ? SQL_INDEX_UNIQUE : SQL_INDEX_ALL,
1306 approximate ? 1 : 0);
1307 OTools::ThrowException(m_pConnection.get(),nRetcode,m_aStatementHandle,SQL_HANDLE_STMT,*this);
1309}
1310
1312{
1313 sal_Int16 nNumResultCols=0;
1315 m_nDriverColumnCount = nNumResultCols;
1316}
1317
1318
1320{
1321 std::map<sal_Int32,SWORD>::iterator aFind = m_aODBCColumnTypes.find(columnIndex);
1322 if ( aFind == m_aODBCColumnTypes.end() )
1323 aFind = m_aODBCColumnTypes.emplace(
1324 columnIndex,
1326 ).first;
1327 return aFind->second;
1328}
1329
1330/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define N3SQLSpecialColumns(a, b, c, d, e, f, g, h, i, j)
Definition: OFunctions.hxx:453
#define N3SQLColumns(a, b, c, d, e, f, g, h, i)
Definition: OFunctions.hxx:392
#define N3SQLCancel(a)
Definition: OFunctions.hxx:501
#define N3SQLColumnPrivileges(a, b, c, d, e, f, g, h, i)
Definition: OFunctions.hxx:380
#define N3SQLForeignKeys(a, b, c, d, e, f, g, h, i, j, k, l, m)
Definition: OFunctions.hxx:408
#define N3SQLProcedureColumns(a, b, c, d, e, f, g, h, i)
Definition: OFunctions.hxx:430
#define N3SQLStatistics(a, b, c, d, e, f, g, h, i)
Definition: OFunctions.hxx:465
#define N3SQLFetchScroll(a, b, c)
Definition: OFunctions.hxx:320
#define N3SQLNumResultCols(a, b)
Definition: OFunctions.hxx:279
#define N3SQLGetTypeInfo(a, b)
Definition: OFunctions.hxx:102
#define N3SQLTablePrivileges(a, b, c, d, e, f, g)
Definition: OFunctions.hxx:475
#define N3SQLPrimaryKeys(a, b, c, d, e, f, g)
Definition: OFunctions.hxx:418
#define N3SQLTables(a, b, c, d, e, f, g, h, i)
Definition: OFunctions.hxx:487
#define N3SQLFetch(a)
Definition: OFunctions.hxx:314
#define N3SQLProcedures(a, b, c, d, e, f, g)
Definition: OFunctions.hxx:440
void disposing(std::unique_lock< std::mutex > &rGuard)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
::dbtools::OPropertyMap & getPropMap()
Definition: TConnection.cxx:68
void openPrimaryKeys(const css::uno::Any &catalog, const OUString &schema, std::u16string_view table)
virtual css::uno::Any SAL_CALL getObject(sal_Int32 columnIndex, const css::uno::Reference< css::container::XNameAccess > &typeMap) override
virtual css::uno::Reference< css::sdbc::XClob > SAL_CALL getClob(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData() override
void openTables(const css::uno::Any &catalog, const OUString &schemaPattern, std::u16string_view tableNamePattern, const css::uno::Sequence< OUString > &types)
virtual sal_Bool SAL_CALL relative(sal_Int32 rows) override
virtual sal_Int64 SAL_CALL getLong(sal_Int32 columnIndex) override
void openIndexInfo(const css::uno::Any &catalog, const OUString &schema, std::u16string_view table, bool unique, bool approximate)
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getBytes(sal_Int32 columnIndex) override
void openTablePrivileges(const css::uno::Any &catalog, const OUString &schemaPattern, std::u16string_view tableNamePattern)
virtual sal_Int32 SAL_CALL findColumn(const OUString &columnName) override
void openExportedKeys(const css::uno::Any &catalog, const OUString &schema, const OUString &table)
virtual sal_Int32 SAL_CALL getInt(sal_Int32 columnIndex) override
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual sal_Int16 SAL_CALL getShort(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL absolute(sal_Int32 row) override
virtual css::uno::Reference< css::sdbc::XArray > SAL_CALL getArray(sal_Int32 columnIndex) override
virtual double SAL_CALL getDouble(sal_Int32 columnIndex) override
virtual sal_Int8 SAL_CALL getByte(sal_Int32 columnIndex) override
void openForeignKeys(const css::uno::Any &catalog, const OUString *schema, const OUString *table, const css::uno::Any &catalog2, const OUString *schema2, const OUString *table2)
void openProcedureColumns(const css::uno::Any &catalog, const OUString &schemaPattern, std::u16string_view procedureNamePattern, std::u16string_view columnNamePattern)
void openImportedKeys(const css::uno::Any &catalog, const OUString &schema, const OUString &table)
void openColumnPrivileges(const css::uno::Any &catalog, const OUString &schema, std::u16string_view table, std::u16string_view columnNamePattern)
std::map< sal_Int32, ::std::map< sal_Int32, sal_Int32 > > m_aValueRange
virtual css::util::Time SAL_CALL getTime(sal_Int32 columnIndex) override
void openSpecialColumns(bool _bRowVer, const css::uno::Any &catalog, const OUString &schema, std::u16string_view table, sal_Int32 scope, bool nullable)
virtual css::util::Date SAL_CALL getDate(sal_Int32 columnIndex) override
void openVersionColumns(const css::uno::Any &catalog, const OUString &schema, std::u16string_view table)
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Reference< css::sdbc::XRef > SAL_CALL getRef(sal_Int32 columnIndex) override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
void openColumns(const css::uno::Any &catalog, const OUString &schemaPattern, std::u16string_view tableNamePattern, std::u16string_view columnNamePattern)
virtual void SAL_CALL release() noexcept override
virtual css::uno::Reference< css::sdbc::XBlob > SAL_CALL getBlob(sal_Int32 columnIndex) override
virtual css::uno::Any SAL_CALL getWarnings() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement() override
virtual OUString SAL_CALL getString(sal_Int32 columnIndex) override
virtual sal_Bool SAL_CALL getBoolean(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getBinaryStream(sal_Int32 columnIndex) override
virtual css::util::DateTime SAL_CALL getTimestamp(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::io::XInputStream > SAL_CALL getCharacterStream(sal_Int32 columnIndex) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
void openProcedures(const css::uno::Any &catalog, const OUString &schemaPattern, std::u16string_view procedureNamePattern)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual float SAL_CALL getFloat(sal_Int32 columnIndex) override
void openBestRowIdentifier(const css::uno::Any &catalog, const OUString &schema, std::u16string_view table, sal_Int32 scope, bool nullable)
css::uno::Reference< css::sdbc::XResultSetMetaData > m_xMetaData
virtual sal_Bool SAL_CALL convertFastPropertyValue(css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
static SQLSMALLINT getColumnODBCType(OConnection const *_pConnection, SQLHANDLE _aStatementHandle, const css::uno::Reference< css::uno::XInterface > &_xInterface, sal_Int32 column)
static void getValue(OConnection const *_pConnection, SQLHANDLE _aStatementHandle, sal_Int32 columnIndex, SQLSMALLINT _nType, bool &_bWasNull, const css::uno::Reference< css::uno::XInterface > &_xInterface, void *_pValue, SQLLEN _nSize)
Definition: OTools.cxx:126
static css::uno::Sequence< sal_Int8 > getBytesValue(const OConnection *_pConnection, SQLHANDLE _aStatementHandle, sal_Int32 columnIndex, SQLSMALLINT _fSqlType, bool &_bWasNull, const css::uno::Reference< css::uno::XInterface > &_xInterface)
Definition: OTools.cxx:361
static OUString getStringValue(OConnection const *_pConnection, SQLHANDLE _aStatementHandle, sal_Int32 columnIndex, SQLSMALLINT _fSqlType, bool &_bWasNull, const css::uno::Reference< css::uno::XInterface > &_xInterface, rtl_TextEncoding _nTextEncoding)
Definition: OTools.cxx:413
static void ThrowException(const OConnection *_pConnection, SQLRETURN _rRetCode, SQLHANDLE _pContext, SQLSMALLINT _nHandleType, const css::uno::Reference< css::uno::XInterface > &_xInterface, bool _bNoFound=true)
Definition: OTools.cxx:302
mutable::osl::Mutex m_aMutex
OBroadcastHelper & rBHelper
css::uno::Type const & get()
const OUString & getNameByIndex(sal_Int32 _nIndex) const
Definition: propertyids.cxx:95
ULONG m_refCount
float u
sal_Int16 nValue
std::mutex m_aMutex
@ table
@ Exception
OUString getString(const Any &_rAny)
Type
::cppu::WeakComponentImplHelper< css::sdbc::XResultSet, css::sdbc::XRow, css::sdbc::XResultSetMetaDataSupplier, css::util::XCancellable, css::sdbc::XWarningsSupplier, css::sdbc::XCloseable, css::sdbc::XColumnLocate > ODatabaseMetaDataResultSet_BASE
void checkDisposed(bool _bThrow)
Definition: dbtools.cxx:1951
void throwFunctionNotSupportedSQLException(const OUString &_rFunctionName, const css::uno::Reference< css::uno::XInterface > &_rxContext)
throws an exception with SQL state IM001, saying that a certain function is not supported
void throwInvalidColumnException(const OUString &_rColumnName, const Reference< XInterface > &_rxContext)
int i
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
Definition: pq_tools.cxx:100
void dispose()
HashMap_OWString_Interface aMap
#define SQL_WCHAR
Definition: odbc.hxx:74
#define SQL_WVARCHAR
Definition: odbc.hxx:77
#define SQL_WLONGVARCHAR
Definition: odbc.hxx:80
#define SDB_ODBC_CHAR
Definition: odbc.hxx:68
const char * columnName
Definition: pq_statics.cxx:56
#define PROPERTY_ID_RESULTSETTYPE
Definition: propertyids.hxx:44
#define PROPERTY_ID_CURSORNAME
Definition: propertyids.hxx:42
#define PROPERTY_ID_RESULTSETCONCURRENCY
Definition: propertyids.hxx:43
#define PROPERTY_ID_FETCHSIZE
Definition: propertyids.hxx:46
#define PROPERTY_ID_FETCHDIRECTION
Definition: propertyids.hxx:45
QPRO_FUNC_TYPE nType
std::map< OUString, rtl::Reference< Entity > > map
unsigned char sal_Bool
sal_uInt16 sal_Unicode
signed char sal_Int8
const SvXMLTokenMapEntry aTypes[]