bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / macab / MacabDatabaseMetaData.cxx
blob807cd8583e42b14eff3245b197b72879d1a98156
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/TransactionIsolation.hpp>
34 #include <rtl/ref.hxx>
36 #include <vector>
38 using namespace connectivity::macab;
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::lang;
41 using namespace com::sun::star::beans;
42 using namespace com::sun::star::sdbc;
44 MacabDatabaseMetaData::MacabDatabaseMetaData(MacabConnection* _pCon)
45 : m_xConnection(_pCon),
46 m_bUseCatalog(true)
48 OSL_ENSURE(_pCon,"MacabDatabaseMetaData::MacabDatabaseMetaData: No connection set!");
50 osl_atomic_increment( &m_refCount );
51 m_bUseCatalog = !(usesLocalFiles() || usesLocalFilePerTable());
52 osl_atomic_decrement( &m_refCount );
55 MacabDatabaseMetaData::~MacabDatabaseMetaData()
59 OUString SAL_CALL MacabDatabaseMetaData::getCatalogSeparator( )
61 if (m_bUseCatalog)
62 { // do some special here for you database
65 return OUString();
68 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxBinaryLiteralLength( )
70 return 0; // 0 means no limit
73 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxRowSize( )
75 return 0; // 0 means no limit
78 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxCatalogNameLength( )
80 return 0; // 0 means no limit
83 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxCharLiteralLength( )
85 return 0; // 0 means no limit
88 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnNameLength( )
90 return 0; // 0 means no limit
93 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnsInIndex( )
95 return 0; // 0 means no limit
98 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxCursorNameLength( )
100 return 0; // 0 means no limit
103 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxConnections( )
105 return 0; // 0 means no limit
108 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnsInTable( )
110 return 0; // 0 means no limit
113 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxStatementLength( )
115 return 0; // 0 means no limit
118 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxTableNameLength( )
120 return 0; // 0 means no limit
123 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxTablesInSelect( )
125 // MaxTablesInSelect describes how many tables can participate in the FROM part of a given SELECT statement,
126 // currently, the resultset/statement implementations can cope with one table only
127 return 1;
130 sal_Bool SAL_CALL MacabDatabaseMetaData::doesMaxRowSizeIncludeBlobs( )
132 return false;
135 sal_Bool SAL_CALL MacabDatabaseMetaData::storesLowerCaseQuotedIdentifiers( )
137 return false;
140 sal_Bool SAL_CALL MacabDatabaseMetaData::storesLowerCaseIdentifiers( )
142 return false;
145 sal_Bool SAL_CALL MacabDatabaseMetaData::storesMixedCaseQuotedIdentifiers( )
147 return false;
150 sal_Bool SAL_CALL MacabDatabaseMetaData::storesMixedCaseIdentifiers( )
152 return false;
155 sal_Bool SAL_CALL MacabDatabaseMetaData::storesUpperCaseQuotedIdentifiers( )
157 return false;
160 sal_Bool SAL_CALL MacabDatabaseMetaData::storesUpperCaseIdentifiers( )
162 return false;
165 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsAlterTableWithAddColumn( )
167 return false;
170 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsAlterTableWithDropColumn( )
172 return false;
175 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxIndexLength( )
177 return 0; // 0 means no limit
180 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsNonNullableColumns( )
182 return false;
185 OUString SAL_CALL MacabDatabaseMetaData::getCatalogTerm( )
187 return OUString();
190 OUString SAL_CALL MacabDatabaseMetaData::getIdentifierQuoteString( )
192 // normally this is "
193 return "\"";
196 OUString SAL_CALL MacabDatabaseMetaData::getExtraNameCharacters( )
198 return OUString();
201 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsDifferentTableCorrelationNames( )
203 return false;
206 sal_Bool SAL_CALL MacabDatabaseMetaData::isCatalogAtStart( )
208 return false;
211 sal_Bool SAL_CALL MacabDatabaseMetaData::dataDefinitionIgnoredInTransactions( )
213 return true;
216 sal_Bool SAL_CALL MacabDatabaseMetaData::dataDefinitionCausesTransactionCommit( )
218 return true;
221 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsDataManipulationTransactionsOnly( )
223 return true;
226 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsDataDefinitionAndDataManipulationTransactions( )
228 return true;
231 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsPositionedDelete( )
233 return false;
236 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsPositionedUpdate( )
238 return false;
241 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOpenStatementsAcrossRollback( )
243 return false;
246 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOpenStatementsAcrossCommit( )
248 return false;
251 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOpenCursorsAcrossCommit( )
253 return false;
256 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOpenCursorsAcrossRollback( )
258 return false;
261 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsTransactionIsolationLevel( sal_Int32 )
263 return false;
266 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSchemasInDataManipulation( )
268 return false;
271 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsANSI92FullSQL( )
273 return false;
276 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsANSI92EntryLevelSQL( )
278 return true; // should be supported at least
281 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsIntegrityEnhancementFacility( )
283 return false;
286 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSchemasInIndexDefinitions( )
288 return false;
291 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSchemasInTableDefinitions( )
293 return false;
296 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCatalogsInTableDefinitions( )
298 return false;
301 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCatalogsInIndexDefinitions( )
303 return false;
306 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCatalogsInDataManipulation( )
308 return false;
311 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOuterJoins( )
313 return false;
316 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxStatements( )
318 return 0; // 0 means no limit
321 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxProcedureNameLength( )
323 return 0; // 0 means no limit
326 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxSchemaNameLength( )
328 return 0; // 0 means no limit
331 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsTransactions( )
333 return false;
336 sal_Bool SAL_CALL MacabDatabaseMetaData::allProceduresAreCallable( )
338 return false;
341 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsStoredProcedures( )
343 return false;
346 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSelectForUpdate( )
348 return false;
351 sal_Bool SAL_CALL MacabDatabaseMetaData::allTablesAreSelectable( )
353 return false;
356 sal_Bool SAL_CALL MacabDatabaseMetaData::isReadOnly( )
358 // for the moment, we have read-only addresses, but this might change in the future
359 return true;
362 sal_Bool SAL_CALL MacabDatabaseMetaData::usesLocalFiles( )
364 return false;
367 sal_Bool SAL_CALL MacabDatabaseMetaData::usesLocalFilePerTable( )
369 return false;
372 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsTypeConversion( )
374 return false;
377 sal_Bool SAL_CALL MacabDatabaseMetaData::nullPlusNonNullIsNull( )
379 return false;
382 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsColumnAliasing( )
384 return false;
387 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsTableCorrelationNames( )
389 return false;
392 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsConvert( sal_Int32, sal_Int32 )
394 return false;
397 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsExpressionsInOrderBy( )
399 return false;
402 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsGroupBy( )
404 return false;
407 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsGroupByBeyondSelect( )
409 return false;
412 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsGroupByUnrelated( )
414 return false;
417 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsMultipleTransactions( )
419 return false;
422 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsMultipleResultSets( )
424 return false;
427 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsLikeEscapeClause( )
429 return false;
432 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsOrderByUnrelated( )
434 return false;
437 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsUnion( )
439 return false;
442 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsUnionAll( )
444 return false;
447 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsMixedCaseIdentifiers( )
449 return false;
452 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsMixedCaseQuotedIdentifiers( )
454 return false;
457 sal_Bool SAL_CALL MacabDatabaseMetaData::nullsAreSortedAtEnd( )
459 return false;
462 sal_Bool SAL_CALL MacabDatabaseMetaData::nullsAreSortedAtStart( )
464 return false;
467 sal_Bool SAL_CALL MacabDatabaseMetaData::nullsAreSortedHigh( )
469 return false;
472 sal_Bool SAL_CALL MacabDatabaseMetaData::nullsAreSortedLow( )
474 return false;
477 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSchemasInProcedureCalls( )
479 return false;
482 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSchemasInPrivilegeDefinitions( )
484 return false;
487 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCatalogsInProcedureCalls( )
489 return false;
492 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCatalogsInPrivilegeDefinitions( )
494 return false;
497 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCorrelatedSubqueries( )
499 return false;
502 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSubqueriesInComparisons( )
504 return false;
507 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSubqueriesInExists( )
509 return false;
512 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSubqueriesInIns( )
514 return false;
517 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsSubqueriesInQuantifieds( )
519 return false;
522 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsANSI92IntermediateSQL( )
524 return false;
527 OUString SAL_CALL MacabDatabaseMetaData::getURL( )
529 // if someday we support more than the default address book,
530 // this method should return the URL which was used to create it
531 return "sdbc:address:macab:";
534 OUString SAL_CALL MacabDatabaseMetaData::getUserName( )
536 return OUString();
539 OUString SAL_CALL MacabDatabaseMetaData::getDriverName( )
541 return "macab";
544 OUString SAL_CALL MacabDatabaseMetaData::getDriverVersion()
546 return MACAB_DRIVER_VERSION;
549 OUString SAL_CALL MacabDatabaseMetaData::getDatabaseProductVersion( )
551 return OUString();
554 OUString SAL_CALL MacabDatabaseMetaData::getDatabaseProductName( )
556 return OUString();
559 OUString SAL_CALL MacabDatabaseMetaData::getProcedureTerm( )
561 return OUString();
564 OUString SAL_CALL MacabDatabaseMetaData::getSchemaTerm( )
566 return OUString();
569 sal_Int32 SAL_CALL MacabDatabaseMetaData::getDriverMajorVersion( )
571 return MACAB_DRIVER_VERSION_MAJOR;
574 sal_Int32 SAL_CALL MacabDatabaseMetaData::getDefaultTransactionIsolation( )
576 return TransactionIsolation::NONE;
579 sal_Int32 SAL_CALL MacabDatabaseMetaData::getDriverMinorVersion( )
581 return MACAB_DRIVER_VERSION_MINOR;
584 OUString SAL_CALL MacabDatabaseMetaData::getSQLKeywords( )
586 return OUString();
589 OUString SAL_CALL MacabDatabaseMetaData::getSearchStringEscape( )
591 return OUString();
594 OUString SAL_CALL MacabDatabaseMetaData::getStringFunctions( )
596 return OUString();
599 OUString SAL_CALL MacabDatabaseMetaData::getTimeDateFunctions( )
601 return OUString();
604 OUString SAL_CALL MacabDatabaseMetaData::getSystemFunctions( )
606 return OUString();
609 OUString SAL_CALL MacabDatabaseMetaData::getNumericFunctions( )
611 return OUString();
614 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsExtendedSQLGrammar( )
616 return false;
619 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsCoreSQLGrammar( )
621 return false;
624 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsMinimumSQLGrammar( )
626 return true;
629 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsFullOuterJoins( )
631 return false;
634 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsLimitedOuterJoins( )
636 return false;
639 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnsInGroupBy( )
641 return 0; // 0 means no limit
644 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnsInOrderBy( )
646 return 0; // 0 means no limit
649 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxColumnsInSelect( )
651 return 0; // 0 means no limit
654 sal_Int32 SAL_CALL MacabDatabaseMetaData::getMaxUserNameLength( )
656 return 0; // 0 means no limit
659 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsResultSetType( sal_Int32 setType )
661 switch (setType)
663 case ResultSetType::FORWARD_ONLY:
664 case ResultSetType::SCROLL_INSENSITIVE:
665 return true;
667 return false;
670 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 )
672 switch (setType)
674 case ResultSetType::FORWARD_ONLY:
675 case ResultSetType::SCROLL_INSENSITIVE:
676 return true;
678 return false;
681 sal_Bool SAL_CALL MacabDatabaseMetaData::ownUpdatesAreVisible( sal_Int32 )
683 return false;
686 sal_Bool SAL_CALL MacabDatabaseMetaData::ownDeletesAreVisible( sal_Int32 )
688 return false;
691 sal_Bool SAL_CALL MacabDatabaseMetaData::ownInsertsAreVisible( sal_Int32 )
693 return false;
696 sal_Bool SAL_CALL MacabDatabaseMetaData::othersUpdatesAreVisible( sal_Int32 )
698 return false;
701 sal_Bool SAL_CALL MacabDatabaseMetaData::othersDeletesAreVisible( sal_Int32 )
703 return false;
706 sal_Bool SAL_CALL MacabDatabaseMetaData::othersInsertsAreVisible( sal_Int32 )
708 return false;
711 sal_Bool SAL_CALL MacabDatabaseMetaData::updatesAreDetected( sal_Int32 )
713 return false;
716 sal_Bool SAL_CALL MacabDatabaseMetaData::deletesAreDetected( sal_Int32 )
718 return false;
721 sal_Bool SAL_CALL MacabDatabaseMetaData::insertsAreDetected( sal_Int32 )
723 return false;
726 sal_Bool SAL_CALL MacabDatabaseMetaData::supportsBatchUpdates( )
728 return false;
731 Reference< XConnection > SAL_CALL MacabDatabaseMetaData::getConnection( )
733 return m_xConnection;
736 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTableTypes( )
738 rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes);
740 static ODatabaseMetaDataResultSet::ORows aRows = [&]
742 static constexpr OUStringLiteral aTable = u"TABLE";
743 ODatabaseMetaDataResultSet::ORows tmp;
744 ODatabaseMetaDataResultSet::ORow aRow(2);
745 aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue();
746 aRow[1] = new ORowSetValueDecorator(OUString(aTable));
747 tmp.push_back(aRow);
748 return tmp;
749 }();
750 pResult->setRows(aRows);
751 return pResult;
754 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTypeInfo( )
756 rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo);
758 static ODatabaseMetaDataResultSet::ORows aRows = [&]()
760 ODatabaseMetaDataResultSet::ORows tmp;
761 ODatabaseMetaDataResultSet::ORow aRow(19);
763 // We support four types: char, timestamp, integer, float
764 aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue();
765 aRow[1] = new ORowSetValueDecorator(OUString("CHAR"));
766 aRow[2] = new ORowSetValueDecorator(DataType::CHAR);
767 aRow[3] = new ORowSetValueDecorator(sal_Int32(254));
768 aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
769 aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
770 aRow[6] = ODatabaseMetaDataResultSet::getEmptyValue();
771 aRow[7] = new ORowSetValueDecorator(sal_Int32(ColumnValue::NULLABLE));
772 aRow[8] = ODatabaseMetaDataResultSet::get1Value();
773 aRow[9] = new ORowSetValueDecorator(sal_Int32(ColumnSearch::CHAR));
774 aRow[10] = ODatabaseMetaDataResultSet::get1Value();
775 aRow[11] = ODatabaseMetaDataResultSet::get0Value();
776 aRow[12] = ODatabaseMetaDataResultSet::get0Value();
777 aRow[13] = ODatabaseMetaDataResultSet::getEmptyValue();
778 aRow[14] = ODatabaseMetaDataResultSet::get0Value();
779 aRow[15] = ODatabaseMetaDataResultSet::get0Value();
780 aRow[16] = ODatabaseMetaDataResultSet::getEmptyValue();
781 aRow[17] = ODatabaseMetaDataResultSet::getEmptyValue();
782 aRow[18] = new ORowSetValueDecorator(sal_Int32(10));
784 tmp.push_back(aRow);
786 aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
787 aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP);
788 aRow[3] = new ORowSetValueDecorator(sal_Int32(19));
789 aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue();
790 aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue();
791 tmp.push_back(aRow);
793 aRow[1] = new ORowSetValueDecorator(OUString("INTEGER"));
794 aRow[2] = new ORowSetValueDecorator(DataType::INTEGER);
795 aRow[3] = new ORowSetValueDecorator(sal_Int32(20));
796 aRow[15] = new ORowSetValueDecorator(sal_Int32(20));
797 tmp.push_back(aRow);
799 aRow[1] = new ORowSetValueDecorator(OUString("FLOAT"));
800 aRow[2] = new ORowSetValueDecorator(DataType::FLOAT);
801 aRow[3] = new ORowSetValueDecorator(sal_Int32(20));
802 aRow[15] = new ORowSetValueDecorator(sal_Int32(15));
803 tmp.push_back(aRow);
805 return tmp;
806 }();
807 pResult->setRows(aRows);
808 return pResult;
811 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getCatalogs( )
813 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCatalogs );
816 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getSchemas( )
818 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eSchemas );
821 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getColumnPrivileges(
822 const Any&, const OUString&, const OUString&,
823 const OUString& )
825 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumnPrivileges );
828 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getColumns(
829 const Any&,
830 const OUString&,
831 const OUString& tableNamePattern,
832 const OUString& columnNamePattern)
834 rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns);
835 MacabRecords *aRecords;
836 OUString sTableName;
838 aRecords = m_xConnection->getAddressBook()->getMacabRecordsMatch(tableNamePattern);
840 ODatabaseMetaDataResultSet::ORows aRows;
841 if(aRecords != nullptr)
843 MacabHeader *aHeader = aRecords->getHeader();
844 sTableName = aRecords->getName();
846 ODatabaseMetaDataResultSet::ORow aRow(19);
848 aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue();
849 aRow[1] = ODatabaseMetaDataResultSet::getEmptyValue();
850 aRow[2] = ODatabaseMetaDataResultSet::getEmptyValue();
851 aRow[3] = new ORowSetValueDecorator(sTableName);
852 aRow[8] = ODatabaseMetaDataResultSet::getEmptyValue();
853 aRow[9] = ODatabaseMetaDataResultSet::get0Value();
854 aRow[10] = new ORowSetValueDecorator(sal_Int32(10));
855 aRow[11] = ODatabaseMetaDataResultSet::get1Value();
856 aRow[12] = ODatabaseMetaDataResultSet::getEmptyValue();
857 aRow[13] = ODatabaseMetaDataResultSet::getEmptyValue();
858 aRow[14] = ODatabaseMetaDataResultSet::getEmptyValue();
859 aRow[15] = ODatabaseMetaDataResultSet::getEmptyValue();
860 aRow[16] = new ORowSetValueDecorator(sal_Int32(254));
861 aRow[18] = new ORowSetValueDecorator(OUString("YES"));
863 sal_Int32 nPosition = 1;
864 OUString sName;
866 MacabHeader::iterator aField;
868 for ( aField = aHeader->begin();
869 aField != aHeader->end();
870 ++aField, ++nPosition)
873 sName = CFStringToOUString(static_cast<CFStringRef>((*aField)->value));
874 if (match(columnNamePattern, sName, '\0'))
876 aRow[4] = new ORowSetValueDecorator(sName);
877 aRow[17] = new ORowSetValueDecorator(nPosition);
878 switch((*aField)->type)
880 case kABStringProperty:
881 aRow[5] = new ORowSetValueDecorator(DataType::CHAR);
882 aRow[6] = new ORowSetValueDecorator(OUString("CHAR"));
883 aRow[7] = new ORowSetValueDecorator(sal_Int32(256));
884 aRows.push_back(aRow);
885 break;
886 case kABDateProperty:
887 aRow[5] = new ORowSetValueDecorator(DataType::TIMESTAMP);
888 aRow[6] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
889 aRows.push_back(aRow);
890 break;
891 case kABIntegerProperty:
892 aRow[5] = new ORowSetValueDecorator(DataType::INTEGER);
893 aRow[6] = new ORowSetValueDecorator(OUString("INTEGER"));
894 aRow[7] = new ORowSetValueDecorator(sal_Int32(20));
895 aRows.push_back(aRow);
896 break;
897 case kABRealProperty:
898 aRow[5] = new ORowSetValueDecorator(DataType::FLOAT);
899 aRow[6] = new ORowSetValueDecorator(OUString("FLOAT"));
900 aRow[7] = new ORowSetValueDecorator(sal_Int32(15));
901 aRows.push_back(aRow);
902 break;
903 default:
905 // shouldn't happen -- throw an error...?
910 pResult->setRows(aRows);
911 return pResult;
914 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTables(
915 const Any&,
916 const OUString&,
917 const OUString&,
918 const Sequence< OUString >& types)
920 rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTables);
922 // check whether we have tables in the requested types
923 // for the moment, we answer only the "TABLE" table type
924 // when no types are given at all, we return all the tables
925 static constexpr OUStringLiteral aTable = u"TABLE";
926 bool bTableFound = false;
927 const OUString* p = types.getConstArray(),
928 * pEnd = p + types.getLength();
930 if (p == pEnd)
932 bTableFound = true;
934 else while (p < pEnd)
936 if (match(*p, aTable, '\0'))
938 bTableFound = true;
939 break;
941 p++;
943 if (!bTableFound)
944 return pResult;
946 static ODatabaseMetaDataResultSet::ORows aRows = [&]()
948 ODatabaseMetaDataResultSet::ORows tmp;
949 ODatabaseMetaDataResultSet::ORow aRow(6);
951 MacabRecords *xRecords = m_xConnection->getAddressBook()->getMacabRecords();
952 std::vector<MacabGroup *> xGroups = m_xConnection->getAddressBook()->getMacabGroups();
953 sal_Int32 i, nGroups;
954 nGroups = xGroups.size();
956 aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue();
957 aRow[1] = ODatabaseMetaDataResultSet::getEmptyValue();
958 aRow[2] = ODatabaseMetaDataResultSet::getEmptyValue();
959 aRow[3] = new ORowSetValueDecorator(xRecords->getName());
960 aRow[4] = new ORowSetValueDecorator(OUString(aTable));
961 aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue();
962 tmp.push_back(aRow);
964 for(i = 0; i < nGroups; i++)
966 aRow[3] = new ORowSetValueDecorator(xGroups[i]->getName());
967 tmp.push_back(aRow);
969 return tmp;
970 }();
971 pResult->setRows(aRows);
972 return pResult;
975 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getProcedureColumns(
976 const Any&, const OUString&,
977 const OUString&, const OUString& )
979 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedureColumns );
982 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getProcedures(
983 const Any&, const OUString&,
984 const OUString& )
986 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eProcedures );
989 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getVersionColumns(
990 const Any&, const OUString&, const OUString& table )
992 rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eVersionColumns);
994 ODatabaseMetaDataResultSet::ORows aRows;
996 if (m_xConnection->getAddressBook()->getMacabRecords(table) != nullptr)
998 ODatabaseMetaDataResultSet::ORow aRow( 9 );
1000 OUString sName = CFStringToOUString(kABModificationDateProperty);
1002 aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue();
1003 aRow[1] = ODatabaseMetaDataResultSet::getEmptyValue();
1004 aRow[2] = new ORowSetValueDecorator(sName);
1005 aRow[3] = new ORowSetValueDecorator(DataType::TIMESTAMP);
1006 aRow[4] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
1008 aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue();
1009 aRow[6] = ODatabaseMetaDataResultSet::getEmptyValue();
1010 aRow[7] = ODatabaseMetaDataResultSet::getEmptyValue();
1011 aRow[8] = ODatabaseMetaDataResultSet::getEmptyValue();
1013 aRows.push_back(aRow);
1015 pResult->setRows(aRows);
1016 return pResult;
1019 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getExportedKeys(
1020 const Any&, const OUString&, const OUString& )
1022 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eExportedKeys );
1025 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getImportedKeys(
1026 const Any&, const OUString&, const OUString& )
1028 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eImportedKeys );
1031 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getPrimaryKeys(
1032 const Any&, const OUString&, const OUString& )
1034 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::ePrimaryKeys );
1037 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getIndexInfo(
1038 const Any&, const OUString&, const OUString&,
1039 sal_Bool, sal_Bool )
1041 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eIndexInfo );
1044 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getBestRowIdentifier(
1045 const Any&, const OUString&, const OUString&, sal_Int32,
1046 sal_Bool )
1048 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eBestRowIdentifier );
1051 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTablePrivileges(
1052 const Any&, const OUString&, const OUString& )
1054 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eTablePrivileges );
1057 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getCrossReference(
1058 const Any&, const OUString&,
1059 const OUString&, const Any&,
1060 const OUString&, const OUString& )
1062 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eCrossReference );
1065 Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getUDTs( const Any&, const OUString&, const OUString&, const Sequence< sal_Int32 >& )
1067 OSL_FAIL("Not implemented yet!");
1068 throw SQLException();
1072 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */