tdf#144694 In direct SQL dialog, activate options 'Run SQL command
[LibreOffice.git] / connectivity / source / drivers / macab / MacabDatabaseMetaData.cxx
blobb0b04fc08f21b34d710a90103c6047351e1c1ac1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "MacabDatabaseMetaData.hxx"
22 #include "MacabAddressBook.hxx"
23 #include "MacabHeader.hxx"
24 #include "MacabGroup.hxx"
25 #include "macabutilities.hxx"
27 #include "MacabDriver.hxx"
28 #include <FDatabaseMetaDataResultSet.hxx>
29 #include <OTypeInfo.hxx>
30 #include <com/sun/star/sdbc/ColumnSearch.hpp>
31 #include <com/sun/star/sdbc/ColumnValue.hpp>
32 #include <com/sun/star/sdbc/ResultSetType.hpp>
33 #include <com/sun/star/sdbc/SQLException.hpp>
34 #include <com/sun/star/sdbc/TransactionIsolation.hpp>
35 #include <rtl/ref.hxx>
37 #include <vector>
39 using namespace connectivity::macab;
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::lang;
42 using namespace com::sun::star::beans;
43 using namespace com::sun::star::sdbc;
45 MacabDatabaseMetaData::MacabDatabaseMetaData(MacabConnection* _pCon)
46 : m_xConnection(_pCon),
47 m_bUseCatalog(true)
49 OSL_ENSURE(_pCon,"MacabDatabaseMetaData::MacabDatabaseMetaData: No connection set!");
51 osl_atomic_increment( &m_refCount );
52 m_bUseCatalog = !(usesLocalFiles() || usesLocalFilePerTable());
53 osl_atomic_decrement( &m_refCount );
56 MacabDatabaseMetaData::~MacabDatabaseMetaData()
60 OUString SAL_CALL MacabDatabaseMetaData::getCatalogSeparator( )
62 if (m_bUseCatalog)
63 { // do some special here for you database
66 return OUString();
69 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxBinaryLiteralLength( )
71 return 0; // 0 means no limit
74 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxRowSize( )
76 return 0; // 0 means no limit
79 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxCatalogNameLength( )
81 return 0; // 0 means no limit
84 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxCharLiteralLength( )
86 return 0; // 0 means no limit
89 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnNameLength( )
91 return 0; // 0 means no limit
94 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnsInIndex( )
96 return 0; // 0 means no limit
99 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxCursorNameLength( )
101 return 0; // 0 means no limit
104 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxConnections( )
106 return 0; // 0 means no limit
109 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnsInTable( )
111 return 0; // 0 means no limit
114 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxStatementLength( )
116 return 0; // 0 means no limit
119 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxTableNameLength( )
121 return 0; // 0 means no limit
124 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxTablesInSelect( )
126 // MaxTablesInSelect describes how many tables can participate in the FROM part of a given SELECT statement,
127 // currently, the resultset/statement implementations can cope with one table only
128 return 1;
131 sal_Bool SAL_CALL MacabDatabaseMetaData::doesMaxRowSizeIncludeBlobs( )
133 return false;
136 sal_Bool SAL_CALL MacabDatabaseMetaData::storesLowerCaseQuotedIdentifiers( )
138 return false;
141 sal_Bool SAL_CALL MacabDatabaseMetaData::storesLowerCaseIdentifiers( )
143 return false;
146 sal_Bool SAL_CALL MacabDatabaseMetaData::storesMixedCaseQuotedIdentifiers( )
148 return false;
151 sal_Bool SAL_CALL MacabDatabaseMetaData::storesMixedCaseIdentifiers( )
153 return false;
156 sal_Bool SAL_CALL MacabDatabaseMetaData::storesUpperCaseQuotedIdentifiers( )
158 return false;
161 sal_Bool SAL_CALL MacabDatabaseMetaData::storesUpperCaseIdentifiers( )
163 return false;
166 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsAlterTableWithAddColumn( )
168 return false;
171 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsAlterTableWithDropColumn( )
173 return false;
176 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxIndexLength( )
178 return 0; // 0 means no limit
181 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsNonNullableColumns( )
183 return false;
186 OUString SAL_CALL MacabDatabaseMetaData::getCatalogTerm( )
188 return OUString();
191 OUString SAL_CALL MacabDatabaseMetaData::getIdentifierQuoteString( )
193 // normally this is "
194 return "\"";
197 OUString SAL_CALL MacabDatabaseMetaData::getExtraNameCharacters( )
199 return OUString();
202 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsDifferentTableCorrelationNames( )
204 return false;
207 sal_Bool SAL_CALL MacabDatabaseMetaData::isCatalogAtStart( )
209 return false;
212 sal_Bool SAL_CALL MacabDatabaseMetaData::dataDefinitionIgnoredInTransactions( )
214 return true;
217 sal_Bool SAL_CALL MacabDatabaseMetaData::dataDefinitionCausesTransactionCommit( )
219 return true;
222 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsDataManipulationTransactionsOnly( )
224 return true;
227 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsDataDefinitionAndDataManipulationTransactions( )
229 return true;
232 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsPositionedDelete( )
234 return false;
237 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsPositionedUpdate( )
239 return false;
242 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOpenStatementsAcrossRollback( )
244 return false;
247 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOpenStatementsAcrossCommit( )
249 return false;
252 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOpenCursorsAcrossCommit( )
254 return false;
257 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOpenCursorsAcrossRollback( )
259 return false;
262 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsTransactionIsolationLevel( sal_Int32 )
264 return false;
267 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSchemasInDataManipulation( )
269 return false;
272 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsANSI92FullSQL( )
274 return false;
277 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsANSI92EntryLevelSQL( )
279 return true; // should be supported at least
282 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsIntegrityEnhancementFacility( )
284 return false;
287 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSchemasInIndexDefinitions( )
289 return false;
292 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSchemasInTableDefinitions( )
294 return false;
297 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCatalogsInTableDefinitions( )
299 return false;
302 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCatalogsInIndexDefinitions( )
304 return false;
307 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCatalogsInDataManipulation( )
309 return false;
312 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOuterJoins( )
314 return false;
317 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxStatements( )
319 return 0; // 0 means no limit
322 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxProcedureNameLength( )
324 return 0; // 0 means no limit
327 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxSchemaNameLength( )
329 return 0; // 0 means no limit
332 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsTransactions( )
334 return false;
337 sal_Bool SAL_CALL MacabDatabaseMetaData::allProceduresAreCallable( )
339 return false;
342 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsStoredProcedures( )
344 return false;
347 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSelectForUpdate( )
349 return false;
352 sal_Bool SAL_CALL MacabDatabaseMetaData::allTablesAreSelectable( )
354 return false;
357 sal_Bool SAL_CALL MacabDatabaseMetaData::isReadOnly( )
359 // for the moment, we have read-only addresses, but this might change in the future
360 return true;
363 sal_Bool SAL_CALL MacabDatabaseMetaData::usesLocalFiles( )
365 return false;
368 sal_Bool SAL_CALL MacabDatabaseMetaData::usesLocalFilePerTable( )
370 return false;
373 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsTypeConversion( )
375 return false;
378 sal_Bool SAL_CALL MacabDatabaseMetaData::nullPlusNonNullIsNull( )
380 return false;
383 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsColumnAliasing( )
385 return false;
388 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsTableCorrelationNames( )
390 return false;
393 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsConvert( sal_Int32, sal_Int32 )
395 return false;
398 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsExpressionsInOrderBy( )
400 return false;
403 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsGroupBy( )
405 return false;
408 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsGroupByBeyondSelect( )
410 return false;
413 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsGroupByUnrelated( )
415 return false;
418 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsMultipleTransactions( )
420 return false;
423 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsMultipleResultSets( )
425 return false;
428 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsLikeEscapeClause( )
430 return false;
433 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOrderByUnrelated( )
435 return false;
438 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsUnion( )
440 return false;
443 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsUnionAll( )
445 return false;
448 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsMixedCaseIdentifiers( )
450 return false;
453 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsMixedCaseQuotedIdentifiers( )
455 return false;
458 sal_Bool SAL_CALL MacabDatabaseMetaData::nullsAreSortedAtEnd( )
460 return false;
463 sal_Bool SAL_CALL MacabDatabaseMetaData::nullsAreSortedAtStart( )
465 return false;
468 sal_Bool SAL_CALL MacabDatabaseMetaData::nullsAreSortedHigh( )
470 return false;
473 sal_Bool SAL_CALL MacabDatabaseMetaData::nullsAreSortedLow( )
475 return false;
478 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSchemasInProcedureCalls( )
480 return false;
483 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSchemasInPrivilegeDefinitions( )
485 return false;
488 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCatalogsInProcedureCalls( )
490 return false;
493 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCatalogsInPrivilegeDefinitions( )
495 return false;
498 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCorrelatedSubqueries( )
500 return false;
503 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSubqueriesInComparisons( )
505 return false;
508 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSubqueriesInExists( )
510 return false;
513 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSubqueriesInIns( )
515 return false;
518 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSubqueriesInQuantifieds( )
520 return false;
523 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsANSI92IntermediateSQL( )
525 return false;
528 OUString SAL_CALL MacabDatabaseMetaData::getURL( )
530 // if someday we support more than the default address book,
531 // this method should return the URL which was used to create it
532 return "sdbc:address:macab:";
535 OUString SAL_CALL MacabDatabaseMetaData::getUserName( )
537 return OUString();
540 OUString SAL_CALL MacabDatabaseMetaData::getDriverName( )
542 return "macab";
545 OUString SAL_CALL MacabDatabaseMetaData::getDriverVersion()
547 return MACAB_DRIVER_VERSION;
550 OUString SAL_CALL MacabDatabaseMetaData::getDatabaseProductVersion( )
552 return OUString();
555 OUString SAL_CALL MacabDatabaseMetaData::getDatabaseProductName( )
557 return OUString();
560 OUString SAL_CALL MacabDatabaseMetaData::getProcedureTerm( )
562 return OUString();
565 OUString SAL_CALL MacabDatabaseMetaData::getSchemaTerm( )
567 return OUString();
570 sal_Int32 SAL_CALL MacabDatabaseMetaData::getDriverMajorVersion( )
572 return MACAB_DRIVER_VERSION_MAJOR;
575 sal_Int32 SAL_CALL MacabDatabaseMetaData::getDefaultTransactionIsolation( )
577 return TransactionIsolation::NONE;
580 sal_Int32 SAL_CALL MacabDatabaseMetaData::getDriverMinorVersion( )
582 return MACAB_DRIVER_VERSION_MINOR;
585 OUString SAL_CALL MacabDatabaseMetaData::getSQLKeywords( )
587 return OUString();
590 OUString SAL_CALL MacabDatabaseMetaData::getSearchStringEscape( )
592 return OUString();
595 OUString SAL_CALL MacabDatabaseMetaData::getStringFunctions( )
597 return OUString();
600 OUString SAL_CALL MacabDatabaseMetaData::getTimeDateFunctions( )
602 return OUString();
605 OUString SAL_CALL MacabDatabaseMetaData::getSystemFunctions( )
607 return OUString();
610 OUString SAL_CALL MacabDatabaseMetaData::getNumericFunctions( )
612 return OUString();
615 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsExtendedSQLGrammar( )
617 return false;
620 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCoreSQLGrammar( )
622 return false;
625 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsMinimumSQLGrammar( )
627 return true;
630 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsFullOuterJoins( )
632 return false;
635 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsLimitedOuterJoins( )
637 return false;
640 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnsInGroupBy( )
642 return 0; // 0 means no limit
645 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnsInOrderBy( )
647 return 0; // 0 means no limit
650 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnsInSelect( )
652 return 0; // 0 means no limit
655 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxUserNameLength( )
657 return 0; // 0 means no limit
660 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsResultSetType( sal_Int32 setType )
662 switch (setType)
664 case ResultSetType::FORWARD_ONLY:
665 case ResultSetType::SCROLL_INSENSITIVE:
666 return true;
668 return false;
671 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 )
673 switch (setType)
675 case ResultSetType::FORWARD_ONLY:
676 case ResultSetType::SCROLL_INSENSITIVE:
677 return true;
679 return false;
682 sal_Bool SAL_CALL MacabDatabaseMetaData::ownUpdatesAreVisible( sal_Int32 )
684 return false;
687 sal_Bool SAL_CALL MacabDatabaseMetaData::ownDeletesAreVisible( sal_Int32 )
689 return false;
692 sal_Bool SAL_CALL MacabDatabaseMetaData::ownInsertsAreVisible( sal_Int32 )
694 return false;
697 sal_Bool SAL_CALL MacabDatabaseMetaData::othersUpdatesAreVisible( sal_Int32 )
699 return false;
702 sal_Bool SAL_CALL MacabDatabaseMetaData::othersDeletesAreVisible( sal_Int32 )
704 return false;
707 sal_Bool SAL_CALL MacabDatabaseMetaData::othersInsertsAreVisible( sal_Int32 )
709 return false;
712 sal_Bool SAL_CALL MacabDatabaseMetaData::updatesAreDetected( sal_Int32 )
714 return false;
717 sal_Bool SAL_CALL MacabDatabaseMetaData::deletesAreDetected( sal_Int32 )
719 return false;
722 sal_Bool SAL_CALL MacabDatabaseMetaData::insertsAreDetected( sal_Int32 )
724 return false;
727 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsBatchUpdates( )
729 return false;
732 Reference< XConnection > SAL_CALL MacabDatabaseMetaData::getConnection( )
734 return m_xConnection;
737 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTableTypes( )
739 rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes);
741 static ODatabaseMetaDataResultSet::ORows aRows = []
743 static constexpr OUStringLiteral aTable = u"TABLE";
744 ODatabaseMetaDataResultSet::ORows tmp;
745 ODatabaseMetaDataResultSet::ORow aRow(2);
746 aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue();
747 aRow[1] = new ORowSetValueDecorator(OUString(aTable));
748 tmp.push_back(aRow);
749 return tmp;
750 }();
751 pResult->setRows(std::vector(aRows));
752 return pResult;
755 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTypeInfo( )
757 rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo);
759 static ODatabaseMetaDataResultSet::ORows aRows = []()
761 ODatabaseMetaDataResultSet::ORows tmp;
762 ODatabaseMetaDataResultSet::ORow aRow(19);
764 // We support four types: char, timestamp, integer, float
765 aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue();
766 aRow[1] = new ORowSetValueDecorator(OUString("CHAR"));
767 aRow[2] = new ORowSetValueDecorator(DataType::CHAR);
768 aRow[3] = new ORowSetValueDecorator(sal_Int32(254));
769 aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
770 aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
771 aRow[6] = ODatabaseMetaDataResultSet::getEmptyValue();
772 aRow[7] = new ORowSetValueDecorator(sal_Int32(ColumnValue::NULLABLE));
773 aRow[8] = ODatabaseMetaDataResultSet::get1Value();
774 aRow[9] = new ORowSetValueDecorator(sal_Int32(ColumnSearch::CHAR));
775 aRow[10] = ODatabaseMetaDataResultSet::get1Value();
776 aRow[11] = ODatabaseMetaDataResultSet::get0Value();
777 aRow[12] = ODatabaseMetaDataResultSet::get0Value();
778 aRow[13] = ODatabaseMetaDataResultSet::getEmptyValue();
779 aRow[14] = ODatabaseMetaDataResultSet::get0Value();
780 aRow[15] = ODatabaseMetaDataResultSet::get0Value();
781 aRow[16] = ODatabaseMetaDataResultSet::getEmptyValue();
782 aRow[17] = ODatabaseMetaDataResultSet::getEmptyValue();
783 aRow[18] = new ORowSetValueDecorator(sal_Int32(10));
785 tmp.push_back(aRow);
787 aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
788 aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP);
789 aRow[3] = new ORowSetValueDecorator(sal_Int32(19));
790 aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
791 aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
792 tmp.push_back(aRow);
794 aRow[1] = new ORowSetValueDecorator(OUString("INTEGER"));
795 aRow[2] = new ORowSetValueDecorator(DataType::INTEGER);
796 aRow[3] = new ORowSetValueDecorator(sal_Int32(20));
797 aRow[15] = new ORowSetValueDecorator(sal_Int32(20));
798 tmp.push_back(aRow);
800 aRow[1] = new ORowSetValueDecorator(OUString("FLOAT"));
801 aRow[2] = new ORowSetValueDecorator(DataType::FLOAT);
802 aRow[3] = new ORowSetValueDecorator(sal_Int32(20));
803 aRow[15] = new ORowSetValueDecorator(sal_Int32(15));
804 tmp.push_back(aRow);
806 return tmp;
807 }();
808 pResult->setRows(std::vector(aRows));
809 return pResult;
812 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getCatalogs( )
814 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCatalogs );
817 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getSchemas( )
819 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eSchemas );
822 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getColumnPrivileges(
823 const Any&, const OUString&, const OUString&,
824 const OUString& )
826 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumnPrivileges );
829 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getColumns(
830 const Any&,
831 const OUString&,
832 const OUString& tableNamePattern,
833 const OUString& columnNamePattern)
835 rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
836 MacabRecords *aRecords;
837 OUString sTableName;
839 aRecords = m_xConnection->getAddressBook()->getMacabRecordsMatch(tableNamePattern);
841 ODatabaseMetaDataResultSet::ORows aRows;
842 if(aRecords != nullptr)
844 MacabHeader *aHeader = aRecords->getHeader();
845 sTableName = aRecords->getName();
847 ODatabaseMetaDataResultSet::ORow aRow(19);
849 aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue();
850 aRow[1] = ODatabaseMetaDataResultSet::getEmptyValue();
851 aRow[2] = ODatabaseMetaDataResultSet::getEmptyValue();
852 aRow[3] = new ORowSetValueDecorator(sTableName);
853 aRow[8] = ODatabaseMetaDataResultSet::getEmptyValue();
854 aRow[9] = ODatabaseMetaDataResultSet::get0Value();
855 aRow[10] = new ORowSetValueDecorator(sal_Int32(10));
856 aRow[11] = ODatabaseMetaDataResultSet::get1Value();
857 aRow[12] = ODatabaseMetaDataResultSet::getEmptyValue();
858 aRow[13] = ODatabaseMetaDataResultSet::getEmptyValue();
859 aRow[14] = ODatabaseMetaDataResultSet::getEmptyValue();
860 aRow[15] = ODatabaseMetaDataResultSet::getEmptyValue();
861 aRow[16] = new ORowSetValueDecorator(sal_Int32(254));
862 aRow[18] = new ORowSetValueDecorator(OUString("YES"));
864 sal_Int32 nPosition = 1;
865 OUString sName;
867 MacabHeader::iterator aField;
869 for ( aField = aHeader->begin();
870 aField != aHeader->end();
871 ++aField, ++nPosition)
874 sName = CFStringToOUString(static_cast<CFStringRef>((*aField)->value));
875 if (match(columnNamePattern, sName, '\0'))
877 aRow[4] = new ORowSetValueDecorator(sName);
878 aRow[17] = new ORowSetValueDecorator(nPosition);
879 switch((*aField)->type)
881 case kABStringProperty:
882 aRow[5] = new ORowSetValueDecorator(DataType::CHAR);
883 aRow[6] = new ORowSetValueDecorator(OUString("CHAR"));
884 aRow[7] = new ORowSetValueDecorator(sal_Int32(256));
885 aRows.push_back(aRow);
886 break;
887 case kABDateProperty:
888 aRow[5] = new ORowSetValueDecorator(DataType::TIMESTAMP);
889 aRow[6] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
890 aRows.push_back(aRow);
891 break;
892 case kABIntegerProperty:
893 aRow[5] = new ORowSetValueDecorator(DataType::INTEGER);
894 aRow[6] = new ORowSetValueDecorator(OUString("INTEGER"));
895 aRow[7] = new ORowSetValueDecorator(sal_Int32(20));
896 aRows.push_back(aRow);
897 break;
898 case kABRealProperty:
899 aRow[5] = new ORowSetValueDecorator(DataType::FLOAT);
900 aRow[6] = new ORowSetValueDecorator(OUString("FLOAT"));
901 aRow[7] = new ORowSetValueDecorator(sal_Int32(15));
902 aRows.push_back(aRow);
903 break;
904 default:
906 // shouldn't happen -- throw an error...?
911 pResult->setRows(std::move(aRows));
912 return pResult;
915 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTables(
916 const Any&,
917 const OUString&,
918 const OUString&,
919 const Sequence< OUString >& types)
921 rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTables);
923 // check whether we have tables in the requested types
924 // for the moment, we answer only the "TABLE" table type
925 // when no types are given at all, we return all the tables
926 static constexpr OUString aTable = u"TABLE"_ustr;
927 bool bTableFound = false;
928 const OUString* p = types.getConstArray(),
929 * pEnd = p + types.getLength();
931 if (p == pEnd)
933 bTableFound = true;
935 else while (p < pEnd)
937 if (match(*p, aTable, '\0'))
939 bTableFound = true;
940 break;
942 p++;
944 if (!bTableFound)
945 return pResult;
947 static ODatabaseMetaDataResultSet::ORows aRows = [&]()
949 ODatabaseMetaDataResultSet::ORows tmp;
950 ODatabaseMetaDataResultSet::ORow aRow(6);
952 MacabRecords *xRecords = m_xConnection->getAddressBook()->getMacabRecords();
953 std::vector<MacabGroup *> xGroups = m_xConnection->getAddressBook()->getMacabGroups();
954 sal_Int32 i, nGroups;
955 nGroups = xGroups.size();
957 aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue();
958 aRow[1] = ODatabaseMetaDataResultSet::getEmptyValue();
959 aRow[2] = ODatabaseMetaDataResultSet::getEmptyValue();
960 aRow[3] = new ORowSetValueDecorator(xRecords->getName());
961 aRow[4] = new ORowSetValueDecorator(aTable);
962 aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue();
963 tmp.push_back(aRow);
965 for(i = 0; i < nGroups; i++)
967 aRow[3] = new ORowSetValueDecorator(xGroups[i]->getName());
968 tmp.push_back(aRow);
970 return tmp;
971 }();
972 pResult->setRows(std::vector(aRows));
973 return pResult;
976 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getProcedureColumns(
977 const Any&, const OUString&,
978 const OUString&, const OUString& )
980 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedureColumns );
983 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getProcedures(
984 const Any&, const OUString&,
985 const OUString& )
987 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedures );
990 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getVersionColumns(
991 const Any&, const OUString&, const OUString& table )
993 rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eVersionColumns);
995 ODatabaseMetaDataResultSet::ORows aRows;
997 if (m_xConnection->getAddressBook()->getMacabRecords(table) != nullptr)
999 ODatabaseMetaDataResultSet::ORow aRow( 9 );
1001 OUString sName = CFStringToOUString(kABModificationDateProperty);
1003 aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue();
1004 aRow[1] = ODatabaseMetaDataResultSet::getEmptyValue();
1005 aRow[2] = new ORowSetValueDecorator(sName);
1006 aRow[3] = new ORowSetValueDecorator(DataType::TIMESTAMP);
1007 aRow[4] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
1009 aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue();
1010 aRow[6] = ODatabaseMetaDataResultSet::getEmptyValue();
1011 aRow[7] = ODatabaseMetaDataResultSet::getEmptyValue();
1012 aRow[8] = ODatabaseMetaDataResultSet::getEmptyValue();
1014 aRows.push_back(aRow);
1016 pResult->setRows(std::move(aRows));
1017 return pResult;
1020 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getExportedKeys(
1021 const Any&, const OUString&, const OUString& )
1023 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eExportedKeys );
1026 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getImportedKeys(
1027 const Any&, const OUString&, const OUString& )
1029 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eImportedKeys );
1032 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getPrimaryKeys(
1033 const Any&, const OUString&, const OUString& )
1035 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::ePrimaryKeys );
1038 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getIndexInfo(
1039 const Any&, const OUString&, const OUString&,
1040 sal_Bool, sal_Bool )
1042 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eIndexInfo );
1045 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getBestRowIdentifier(
1046 const Any&, const OUString&, const OUString&, sal_Int32,
1047 sal_Bool )
1049 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eBestRowIdentifier );
1052 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTablePrivileges(
1053 const Any&, const OUString&, const OUString& )
1055 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges );
1058 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getCrossReference(
1059 const Any&, const OUString&,
1060 const OUString&, const Any&,
1061 const OUString&, const OUString& )
1063 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCrossReference );
1066 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getUDTs( const Any&, const OUString&, const OUString&, const Sequence< sal_Int32 >& )
1068 OSL_FAIL("Not implemented yet!");
1069 throw SQLException();
1073 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */