1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
),
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( )
63 { // do some special here for you database
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
131 sal_Bool SAL_CALL
MacabDatabaseMetaData::doesMaxRowSizeIncludeBlobs( )
136 sal_Bool SAL_CALL
MacabDatabaseMetaData::storesLowerCaseQuotedIdentifiers( )
141 sal_Bool SAL_CALL
MacabDatabaseMetaData::storesLowerCaseIdentifiers( )
146 sal_Bool SAL_CALL
MacabDatabaseMetaData::storesMixedCaseQuotedIdentifiers( )
151 sal_Bool SAL_CALL
MacabDatabaseMetaData::storesMixedCaseIdentifiers( )
156 sal_Bool SAL_CALL
MacabDatabaseMetaData::storesUpperCaseQuotedIdentifiers( )
161 sal_Bool SAL_CALL
MacabDatabaseMetaData::storesUpperCaseIdentifiers( )
166 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsAlterTableWithAddColumn( )
171 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsAlterTableWithDropColumn( )
176 sal_Int32 SAL_CALL
MacabDatabaseMetaData::getMaxIndexLength( )
178 return 0; // 0 means no limit
181 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsNonNullableColumns( )
186 OUString SAL_CALL
MacabDatabaseMetaData::getCatalogTerm( )
191 OUString SAL_CALL
MacabDatabaseMetaData::getIdentifierQuoteString( )
193 // normally this is "
197 OUString SAL_CALL
MacabDatabaseMetaData::getExtraNameCharacters( )
202 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsDifferentTableCorrelationNames( )
207 sal_Bool SAL_CALL
MacabDatabaseMetaData::isCatalogAtStart( )
212 sal_Bool SAL_CALL
MacabDatabaseMetaData::dataDefinitionIgnoredInTransactions( )
217 sal_Bool SAL_CALL
MacabDatabaseMetaData::dataDefinitionCausesTransactionCommit( )
222 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsDataManipulationTransactionsOnly( )
227 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsDataDefinitionAndDataManipulationTransactions( )
232 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsPositionedDelete( )
237 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsPositionedUpdate( )
242 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsOpenStatementsAcrossRollback( )
247 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsOpenStatementsAcrossCommit( )
252 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsOpenCursorsAcrossCommit( )
257 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsOpenCursorsAcrossRollback( )
262 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsTransactionIsolationLevel( sal_Int32
)
267 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsSchemasInDataManipulation( )
272 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsANSI92FullSQL( )
277 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsANSI92EntryLevelSQL( )
279 return true; // should be supported at least
282 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsIntegrityEnhancementFacility( )
287 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsSchemasInIndexDefinitions( )
292 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsSchemasInTableDefinitions( )
297 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsCatalogsInTableDefinitions( )
302 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsCatalogsInIndexDefinitions( )
307 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsCatalogsInDataManipulation( )
312 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsOuterJoins( )
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( )
337 sal_Bool SAL_CALL
MacabDatabaseMetaData::allProceduresAreCallable( )
342 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsStoredProcedures( )
347 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsSelectForUpdate( )
352 sal_Bool SAL_CALL
MacabDatabaseMetaData::allTablesAreSelectable( )
357 sal_Bool SAL_CALL
MacabDatabaseMetaData::isReadOnly( )
359 // for the moment, we have read-only addresses, but this might change in the future
363 sal_Bool SAL_CALL
MacabDatabaseMetaData::usesLocalFiles( )
368 sal_Bool SAL_CALL
MacabDatabaseMetaData::usesLocalFilePerTable( )
373 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsTypeConversion( )
378 sal_Bool SAL_CALL
MacabDatabaseMetaData::nullPlusNonNullIsNull( )
383 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsColumnAliasing( )
388 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsTableCorrelationNames( )
393 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsConvert( sal_Int32
, sal_Int32
)
398 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsExpressionsInOrderBy( )
403 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsGroupBy( )
408 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsGroupByBeyondSelect( )
413 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsGroupByUnrelated( )
418 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsMultipleTransactions( )
423 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsMultipleResultSets( )
428 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsLikeEscapeClause( )
433 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsOrderByUnrelated( )
438 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsUnion( )
443 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsUnionAll( )
448 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsMixedCaseIdentifiers( )
453 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsMixedCaseQuotedIdentifiers( )
458 sal_Bool SAL_CALL
MacabDatabaseMetaData::nullsAreSortedAtEnd( )
463 sal_Bool SAL_CALL
MacabDatabaseMetaData::nullsAreSortedAtStart( )
468 sal_Bool SAL_CALL
MacabDatabaseMetaData::nullsAreSortedHigh( )
473 sal_Bool SAL_CALL
MacabDatabaseMetaData::nullsAreSortedLow( )
478 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsSchemasInProcedureCalls( )
483 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsSchemasInPrivilegeDefinitions( )
488 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsCatalogsInProcedureCalls( )
493 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsCatalogsInPrivilegeDefinitions( )
498 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsCorrelatedSubqueries( )
503 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsSubqueriesInComparisons( )
508 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsSubqueriesInExists( )
513 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsSubqueriesInIns( )
518 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsSubqueriesInQuantifieds( )
523 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsANSI92IntermediateSQL( )
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( )
540 OUString SAL_CALL
MacabDatabaseMetaData::getDriverName( )
545 OUString SAL_CALL
MacabDatabaseMetaData::getDriverVersion()
547 return MACAB_DRIVER_VERSION
;
550 OUString SAL_CALL
MacabDatabaseMetaData::getDatabaseProductVersion( )
555 OUString SAL_CALL
MacabDatabaseMetaData::getDatabaseProductName( )
560 OUString SAL_CALL
MacabDatabaseMetaData::getProcedureTerm( )
565 OUString SAL_CALL
MacabDatabaseMetaData::getSchemaTerm( )
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( )
590 OUString SAL_CALL
MacabDatabaseMetaData::getSearchStringEscape( )
595 OUString SAL_CALL
MacabDatabaseMetaData::getStringFunctions( )
600 OUString SAL_CALL
MacabDatabaseMetaData::getTimeDateFunctions( )
605 OUString SAL_CALL
MacabDatabaseMetaData::getSystemFunctions( )
610 OUString SAL_CALL
MacabDatabaseMetaData::getNumericFunctions( )
615 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsExtendedSQLGrammar( )
620 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsCoreSQLGrammar( )
625 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsMinimumSQLGrammar( )
630 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsFullOuterJoins( )
635 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsLimitedOuterJoins( )
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
)
664 case ResultSetType::FORWARD_ONLY
:
665 case ResultSetType::SCROLL_INSENSITIVE
:
671 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsResultSetConcurrency( sal_Int32 setType
, sal_Int32
)
675 case ResultSetType::FORWARD_ONLY
:
676 case ResultSetType::SCROLL_INSENSITIVE
:
682 sal_Bool SAL_CALL
MacabDatabaseMetaData::ownUpdatesAreVisible( sal_Int32
)
687 sal_Bool SAL_CALL
MacabDatabaseMetaData::ownDeletesAreVisible( sal_Int32
)
692 sal_Bool SAL_CALL
MacabDatabaseMetaData::ownInsertsAreVisible( sal_Int32
)
697 sal_Bool SAL_CALL
MacabDatabaseMetaData::othersUpdatesAreVisible( sal_Int32
)
702 sal_Bool SAL_CALL
MacabDatabaseMetaData::othersDeletesAreVisible( sal_Int32
)
707 sal_Bool SAL_CALL
MacabDatabaseMetaData::othersInsertsAreVisible( sal_Int32
)
712 sal_Bool SAL_CALL
MacabDatabaseMetaData::updatesAreDetected( sal_Int32
)
717 sal_Bool SAL_CALL
MacabDatabaseMetaData::deletesAreDetected( sal_Int32
)
722 sal_Bool SAL_CALL
MacabDatabaseMetaData::insertsAreDetected( sal_Int32
)
727 sal_Bool SAL_CALL
MacabDatabaseMetaData::supportsBatchUpdates( )
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
));
751 pResult
->setRows(std::vector(aRows
));
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));
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();
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));
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));
808 pResult
->setRows(std::vector(aRows
));
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
&,
826 return new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumnPrivileges
);
829 Reference
< XResultSet
> SAL_CALL
MacabDatabaseMetaData::getColumns(
832 const OUString
& tableNamePattern
,
833 const OUString
& columnNamePattern
)
835 rtl::Reference
<::connectivity::ODatabaseMetaDataResultSet
> pResult
= new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eColumns
);
836 MacabRecords
*aRecords
;
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;
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
);
887 case kABDateProperty
:
888 aRow
[5] = new ORowSetValueDecorator(DataType::TIMESTAMP
);
889 aRow
[6] = new ORowSetValueDecorator(OUString("TIMESTAMP"));
890 aRows
.push_back(aRow
);
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
);
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
);
906 // shouldn't happen -- throw an error...?
911 pResult
->setRows(std::move(aRows
));
915 Reference
< XResultSet
> SAL_CALL
MacabDatabaseMetaData::getTables(
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();
935 else while (p
< pEnd
)
937 if (match(*p
, aTable
, '\0'))
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();
965 for(i
= 0; i
< nGroups
; i
++)
967 aRow
[3] = new ORowSetValueDecorator(xGroups
[i
]->getName());
972 pResult
->setRows(std::vector(aRows
));
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
&,
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
));
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
,
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: */