bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / evoab2 / NDatabaseMetaData.cxx
blob3f6e00aa43bb06303c4fea6bf682bdcdaa29ddb3
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 .
20 #include "NDatabaseMetaData.hxx"
21 #include <com/sun/star/sdbc/DataType.hpp>
22 #include <com/sun/star/sdbc/TransactionIsolation.hpp>
23 #include <connectivity/dbexception.hxx>
24 #include <connectivity/FValue.hxx>
25 #include <com/sun/star/sdbc/ColumnSearch.hpp>
26 #include <rtl/ref.hxx>
28 #include <cstddef>
29 #include <string.h>
30 #include <string_view>
32 #include "EApi.h"
34 using namespace connectivity::evoab;
35 using namespace connectivity;
36 using namespace com::sun::star::uno;
37 using namespace com::sun::star::lang;
38 using namespace com::sun::star::beans;
39 using namespace com::sun::star::sdbc;
40 using namespace com::sun::star::sdbcx;
42 namespace
44 bool equal(const char *str1, const char *str2)
46 return str1 == nullptr || str2 == nullptr ? str1 == str2 : strcmp(str1, str2) == 0;
50 namespace connectivity::evoab
52 sal_Int32 const s_nCOLUMN_SIZE = 256;
53 sal_Int32 const s_nDECIMAL_DIGITS = 0;
54 sal_Int32 const s_nNULLABLE = 1;
55 sal_Int32 const s_nCHAR_OCTET_LENGTH = 65535;
57 static ColumnProperty **pFields=nullptr;
58 static guint nFields = 0;
60 static const char *pDenyList[] =
62 "id",
63 "list-show-addresses",
64 "address-label-home",
65 "address-label-work",
66 "address-label-other"
69 const SplitEvoColumns* get_evo_addr()
71 static const SplitEvoColumns evo_addr[] = {
72 {"addr-line1",DEFAULT_ADDR_LINE1},{"addr-line2",DEFAULT_ADDR_LINE2},{"city",DEFAULT_CITY},{"state",DEFAULT_STATE},{"country",DEFAULT_COUNTRY},{"zip",DEFAULT_ZIP},
73 {"work-addr-line1",WORK_ADDR_LINE1},{"work-addr-line2",WORK_ADDR_LINE2},{"work-city",WORK_CITY},{"work-state",WORK_STATE},{"work-country",WORK_COUNTRY},{"work-zip",WORK_ZIP},
74 {"home-addr-line1",HOME_ADDR_LINE1},{"home-addr-line2",HOME_ADDR_LINE2},{"home-addr-City",HOME_CITY},{"home-state",HOME_STATE},{"home-country",HOME_COUNTRY},{"home-zip",HOME_ZIP},
75 {"other-addr-line1",OTHER_ADDR_LINE1},{"other-addr-line2",OTHER_ADDR_LINE2},{"other-addr-city",OTHER_CITY},{"other-addr-state",OTHER_STATE},{"other-addr-country",OTHER_COUNTRY},{"other-addr-zip",OTHER_ZIP}
77 return evo_addr;
80 static void
81 splitColumn (ColumnProperty **pToBeFields)
83 const SplitEvoColumns* evo_addr( get_evo_addr() );
84 for (int i = 0; i < OTHER_ZIP; i++)
86 pToBeFields[nFields] = g_new0(ColumnProperty,1);
87 pToBeFields[nFields]->bIsSplittedValue = true;
88 pToBeFields[nFields]->pField = g_param_spec_ref(g_param_spec_string (evo_addr[i].pColumnName,evo_addr[i].pColumnName,"",nullptr,G_PARAM_WRITABLE));
89 nFields++;
93 static void
94 initFields()
96 if( pFields )
97 return;
99 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
100 if( pFields )
101 return;
103 guint nProps;
104 ColumnProperty **pToBeFields;
105 GParamSpec **pProps;
106 nFields = 0;
107 pProps = g_object_class_list_properties
108 ( static_cast<GObjectClass *>(g_type_class_ref( E_TYPE_CONTACT )),
109 &nProps );
110 pToBeFields = g_new0(ColumnProperty *, (nProps + OTHER_ZIP)/* new column(s)*/ );
111 for ( guint i = 0; i < nProps; i++ )
113 switch (pProps[i]->value_type)
115 case G_TYPE_STRING:
116 case G_TYPE_BOOLEAN:
118 bool bAdd = true;
119 const char *pName = g_param_spec_get_name( pProps[i] );
120 for (unsigned int j = 0; j < G_N_ELEMENTS( pDenyList ); j++ )
122 if( !strcmp( pDenyList[j], pName ) )
124 bAdd = false;
125 break;
128 if( bAdd )
130 pToBeFields[nFields]= g_new0(ColumnProperty,1);
131 pToBeFields[nFields]->bIsSplittedValue=false;
132 pToBeFields[ nFields++ ]->pField = g_param_spec_ref( pProps[i] );
134 break;
136 default:
137 break;
141 splitColumn(pToBeFields);
142 pFields = pToBeFields;
146 const ColumnProperty *
147 getField(guint n)
149 initFields();
150 if( n < nFields )
151 return pFields[n];
152 else
153 return nullptr;
156 GType
157 getGFieldType( guint nCol )
159 initFields();
161 if ( nCol < nFields )
162 return pFields[nCol]->pField->value_type;
163 return G_TYPE_STRING;
166 sal_Int32
167 getFieldType( guint nCol )
169 sal_Int32 nType = getGFieldType( nCol );
170 return nType == G_TYPE_STRING ? DataType::VARCHAR : DataType::BIT;
173 guint findEvoabField(std::u16string_view aColName)
175 guint nRet = guint(-1);
176 bool bFound = false;
177 initFields();
178 for (guint i=0;(i < nFields) && !bFound;i++)
180 OUString aName = getFieldName(i);
181 if (aName == aColName)
183 nRet = i;
184 bFound = true;
187 return nRet;
190 OUString
191 getFieldTypeName( guint nCol )
193 switch( getFieldType( nCol ) )
195 case DataType::BIT:
196 return "BIT";
197 case DataType::VARCHAR:
198 return "VARCHAR";
199 default:
200 break;
202 return OUString();
205 OUString
206 getFieldName( guint nCol )
208 const GParamSpec *pSpec = getField( nCol )->pField;
209 OUString aName;
210 initFields();
212 if( pSpec )
214 aName = OStringToOUString( g_param_spec_get_name( const_cast<GParamSpec *>(pSpec) ),
215 RTL_TEXTENCODING_UTF8 );
216 aName = aName.replace( '-', '_' );
218 return aName;
221 void
222 free_column_resources()
224 for (int i=nFields-1;i > 0;i--)
226 if (pFields && pFields[i] )
228 if (pFields[i]->pField)
229 g_param_spec_unref(pFields[i]->pField);
230 g_free(pFields[i]);
233 if(pFields)
235 g_free(pFields);
236 pFields=nullptr;
245 OEvoabDatabaseMetaData::OEvoabDatabaseMetaData(OEvoabConnection* _pCon)
246 : ::connectivity::ODatabaseMetaDataBase(_pCon, _pCon->getConnectionInfo())
247 ,m_pConnection(_pCon)
249 OSL_ENSURE(m_pConnection,"OEvoabDatabaseMetaData::OEvoabDatabaseMetaData: No connection set!");
251 OEvoabDatabaseMetaData::~OEvoabDatabaseMetaData()
256 ODatabaseMetaDataResultSet::ORows OEvoabDatabaseMetaData::getColumnRows( const OUString& columnNamePattern )
258 ODatabaseMetaDataResultSet::ORows aRows;
259 ODatabaseMetaDataResultSet::ORow aRow(19);
261 // ****************************************************
262 // Some entries in a row never change, so set them now
263 // ****************************************************
265 // Catalog
266 aRow[1] = new ORowSetValueDecorator(OUString());
267 // Schema
268 aRow[2] = new ORowSetValueDecorator(OUString());
269 // COLUMN_SIZE
270 aRow[7] = new ORowSetValueDecorator(s_nCOLUMN_SIZE);
271 // BUFFER_LENGTH, not used
272 aRow[8] = ODatabaseMetaDataResultSet::getEmptyValue();
273 // DECIMAL_DIGITS.
274 aRow[9] = new ORowSetValueDecorator(s_nDECIMAL_DIGITS);
275 // NUM_PREC_RADIX
276 aRow[10] = new ORowSetValueDecorator(sal_Int32(10));
277 // NULLABLE
278 aRow[11] = new ORowSetValueDecorator(s_nNULLABLE);
279 // REMARKS
280 aRow[12] = ODatabaseMetaDataResultSet::getEmptyValue();
281 // COLUMN_DEF, not used
282 aRow[13] = ODatabaseMetaDataResultSet::getEmptyValue();
283 // SQL_DATA_TYPE, not used
284 aRow[14] = ODatabaseMetaDataResultSet::getEmptyValue();
285 // SQL_DATETIME_SUB, not used
286 aRow[15] = ODatabaseMetaDataResultSet::getEmptyValue();
287 // CHAR_OCTET_LENGTH, refer to [5]
288 aRow[16] = new ORowSetValueDecorator(s_nCHAR_OCTET_LENGTH);
289 // IS_NULLABLE
290 aRow[18] = new ORowSetValueDecorator(OUString("YES"));
293 aRow[3] = new ORowSetValueDecorator(OUString("TABLE"));
294 ::osl::MutexGuard aGuard( m_aMutex );
296 initFields();
297 for (sal_Int32 i = 0; i < static_cast<sal_Int32>(nFields); i++)
299 if( match( columnNamePattern, getFieldName( i ), '\0' ) )
301 aRow[5] = new ORowSetValueDecorator( static_cast<sal_Int16>( getFieldType( i ) ) );
302 aRow[6] = new ORowSetValueDecorator( getFieldTypeName( i ) );
304 // COLUMN_NAME
305 aRow[4] = new ORowSetValueDecorator( getFieldName( i ) );
306 // ORDINAL_POSITION
307 aRow[17] = new ORowSetValueDecorator( i );
308 aRows.push_back( aRow );
312 return aRows ;
315 OUString OEvoabDatabaseMetaData::impl_getCatalogSeparator_throw( )
317 return OUString();
320 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxBinaryLiteralLength( )
322 return 0;// 0 means no limit
325 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxRowSize( )
327 return 0;// 0 means no limit
330 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxCatalogNameLength( )
332 return 0;// 0 means no limit
335 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxCharLiteralLength( )
337 return 0;// 0 means no limit
340 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxColumnNameLength( )
342 return 0;// 0 means no limit
345 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxColumnsInIndex( )
347 return 0;// 0 means no limit
350 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxCursorNameLength( )
352 return 0;// 0 means no limit
355 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxConnections( )
357 return 0;// 0 means no limit
360 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxColumnsInTable( )
362 return 0;// 0 means no limit
365 sal_Int32 OEvoabDatabaseMetaData::impl_getMaxStatements_throw( )
367 return 0;// 0 means no limit
370 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxTableNameLength( )
372 return 0;// 0 means no limit
375 sal_Int32 OEvoabDatabaseMetaData::impl_getMaxTablesInSelect_throw( )
377 // We only support a single table
378 return 1;
382 sal_Bool SAL_CALL OEvoabDatabaseMetaData::doesMaxRowSizeIncludeBlobs( )
384 return false;
387 sal_Bool SAL_CALL OEvoabDatabaseMetaData::storesLowerCaseQuotedIdentifiers( )
389 return false;
392 sal_Bool SAL_CALL OEvoabDatabaseMetaData::storesLowerCaseIdentifiers( )
394 return false;
397 bool OEvoabDatabaseMetaData::impl_storesMixedCaseQuotedIdentifiers_throw( )
399 return false;
402 sal_Bool SAL_CALL OEvoabDatabaseMetaData::storesMixedCaseIdentifiers( )
404 return false;
407 sal_Bool SAL_CALL OEvoabDatabaseMetaData::storesUpperCaseQuotedIdentifiers( )
409 return false;
412 sal_Bool SAL_CALL OEvoabDatabaseMetaData::storesUpperCaseIdentifiers( )
414 return false;
417 bool OEvoabDatabaseMetaData::impl_supportsAlterTableWithAddColumn_throw( )
419 return false;
422 bool OEvoabDatabaseMetaData::impl_supportsAlterTableWithDropColumn_throw( )
424 return false;
427 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxIndexLength( )
429 return 0;// 0 means no limit
432 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsNonNullableColumns( )
434 return false;
437 OUString SAL_CALL OEvoabDatabaseMetaData::getCatalogTerm( )
439 return OUString();
442 OUString OEvoabDatabaseMetaData::impl_getIdentifierQuoteString_throw( )
444 // normally this is "
445 return "\"";
448 OUString SAL_CALL OEvoabDatabaseMetaData::getExtraNameCharacters( )
450 return OUString();
453 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsDifferentTableCorrelationNames( )
455 return false;
458 bool OEvoabDatabaseMetaData::impl_isCatalogAtStart_throw( )
460 return false;
463 sal_Bool SAL_CALL OEvoabDatabaseMetaData::dataDefinitionIgnoredInTransactions( )
465 return true;
468 sal_Bool SAL_CALL OEvoabDatabaseMetaData::dataDefinitionCausesTransactionCommit( )
470 return true;
473 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsDataManipulationTransactionsOnly( )
475 return true;
478 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsDataDefinitionAndDataManipulationTransactions( )
480 return true;
483 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsPositionedDelete( )
485 return false;
488 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsPositionedUpdate( )
490 return false;
493 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsOpenStatementsAcrossRollback( )
495 return false;
498 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsOpenStatementsAcrossCommit( )
500 return false;
503 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsOpenCursorsAcrossCommit( )
505 return false;
508 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsOpenCursorsAcrossRollback( )
510 return false;
513 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsTransactionIsolationLevel( sal_Int32 /*level*/ )
515 return false;
518 bool OEvoabDatabaseMetaData::impl_supportsSchemasInDataManipulation_throw( )
520 return false;
523 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsANSI92FullSQL( )
525 return false;
528 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsANSI92EntryLevelSQL( )
530 return true; // should be supported at least
533 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsIntegrityEnhancementFacility( )
535 return false;
538 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsSchemasInIndexDefinitions( )
540 return false;
543 bool OEvoabDatabaseMetaData::impl_supportsSchemasInTableDefinitions_throw( )
545 return false;
548 bool OEvoabDatabaseMetaData::impl_supportsCatalogsInTableDefinitions_throw( )
550 return false;
553 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsCatalogsInIndexDefinitions( )
555 return false;
558 bool OEvoabDatabaseMetaData::impl_supportsCatalogsInDataManipulation_throw( )
560 return false;
563 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsOuterJoins( )
565 return false;
568 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxStatementLength( )
570 return 0;// 0 means no limit
573 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxProcedureNameLength( )
575 return 0;// 0 means no limit
578 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxSchemaNameLength( )
580 return 0;// 0 means no limit
583 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsTransactions( )
585 return false;
588 sal_Bool SAL_CALL OEvoabDatabaseMetaData::allProceduresAreCallable( )
590 return false;
593 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsStoredProcedures( )
595 return false;
598 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsSelectForUpdate( )
600 return false;
603 sal_Bool SAL_CALL OEvoabDatabaseMetaData::allTablesAreSelectable( )
605 // We allow you to select from any table.
606 return true;
609 sal_Bool SAL_CALL OEvoabDatabaseMetaData::isReadOnly( )
611 // For now definitely read-only, no support for update/delete
612 return true;
615 sal_Bool SAL_CALL OEvoabDatabaseMetaData::usesLocalFiles( )
617 return false;
620 sal_Bool SAL_CALL OEvoabDatabaseMetaData::usesLocalFilePerTable( )
622 return false;
625 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsTypeConversion( )
627 return false;
630 sal_Bool SAL_CALL OEvoabDatabaseMetaData::nullPlusNonNullIsNull( )
632 return false;
635 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsColumnAliasing( )
637 // todo add Support for this.
638 return false;
641 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsTableCorrelationNames( )
643 return false;
646 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsConvert( sal_Int32 /*fromType*/, sal_Int32 /*toType*/ )
648 return false;
651 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsExpressionsInOrderBy( )
653 return false;
656 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsGroupBy( )
658 return false;
661 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsGroupByBeyondSelect( )
663 return false;
666 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsGroupByUnrelated( )
668 return false;
671 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsMultipleTransactions( )
673 return false;
676 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsMultipleResultSets( )
678 return false;
681 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsLikeEscapeClause( )
683 return false;
686 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsOrderByUnrelated( )
688 return false;
691 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsUnion( )
693 return false;
696 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsUnionAll( )
698 return false;
701 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsMixedCaseIdentifiers( )
703 return false;
706 bool OEvoabDatabaseMetaData::impl_supportsMixedCaseQuotedIdentifiers_throw( )
708 // Any case may be used
709 return true;
712 sal_Bool SAL_CALL OEvoabDatabaseMetaData::nullsAreSortedAtEnd( )
714 return false;
717 sal_Bool SAL_CALL OEvoabDatabaseMetaData::nullsAreSortedAtStart( )
719 return true;
722 sal_Bool SAL_CALL OEvoabDatabaseMetaData::nullsAreSortedHigh( )
724 return false;
727 sal_Bool SAL_CALL OEvoabDatabaseMetaData::nullsAreSortedLow( )
729 return true;
732 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsSchemasInProcedureCalls( )
734 return false;
737 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsSchemasInPrivilegeDefinitions( )
739 return false;
742 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsCatalogsInProcedureCalls( )
744 return false;
747 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsCatalogsInPrivilegeDefinitions( )
749 return false;
752 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsCorrelatedSubqueries( )
754 return false;
757 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsSubqueriesInComparisons( )
759 return false;
762 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsSubqueriesInExists( )
764 return false;
767 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsSubqueriesInIns( )
769 return false;
772 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsSubqueriesInQuantifieds( )
774 return false;
777 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsANSI92IntermediateSQL( )
779 return false;
782 OUString SAL_CALL OEvoabDatabaseMetaData::getURL( )
784 ::osl::MutexGuard aGuard( m_aMutex );
786 return m_pConnection->getURL();
789 OUString SAL_CALL OEvoabDatabaseMetaData::getUserName( )
791 return OUString();
794 OUString SAL_CALL OEvoabDatabaseMetaData::getDriverName( )
796 return OUString();
799 OUString SAL_CALL OEvoabDatabaseMetaData::getDriverVersion()
801 return "1";
804 OUString SAL_CALL OEvoabDatabaseMetaData::getDatabaseProductVersion( )
806 return "0";
809 OUString SAL_CALL OEvoabDatabaseMetaData::getDatabaseProductName( )
811 return OUString();
814 OUString SAL_CALL OEvoabDatabaseMetaData::getProcedureTerm( )
816 return OUString();
819 OUString SAL_CALL OEvoabDatabaseMetaData::getSchemaTerm( )
821 return OUString();
824 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getDriverMajorVersion( )
826 return 1;
829 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getDefaultTransactionIsolation( )
831 return TransactionIsolation::NONE;
834 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getDriverMinorVersion( )
836 return 0;
839 OUString SAL_CALL OEvoabDatabaseMetaData::getSQLKeywords( )
841 return OUString();
844 OUString SAL_CALL OEvoabDatabaseMetaData::getSearchStringEscape( )
846 return OUString();
849 OUString SAL_CALL OEvoabDatabaseMetaData::getStringFunctions( )
851 return OUString();
854 OUString SAL_CALL OEvoabDatabaseMetaData::getTimeDateFunctions( )
856 return OUString();
859 OUString SAL_CALL OEvoabDatabaseMetaData::getSystemFunctions( )
861 return OUString();
864 OUString SAL_CALL OEvoabDatabaseMetaData::getNumericFunctions( )
866 return OUString();
869 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsExtendedSQLGrammar( )
871 return false;
874 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsCoreSQLGrammar( )
876 return false;
879 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsMinimumSQLGrammar( )
881 return true;
884 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsFullOuterJoins( )
886 return false;
889 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsLimitedOuterJoins( )
891 return false;
894 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxColumnsInGroupBy( )
896 return 0;// 0 means no limit
899 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxColumnsInOrderBy( )
901 return 0;// 0 means no limit
904 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxColumnsInSelect( )
906 return 0;// 0 means no limit
909 sal_Int32 SAL_CALL OEvoabDatabaseMetaData::getMaxUserNameLength( )
911 return 0;// 0 means no limit
914 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsResultSetType( sal_Int32 /*setType*/ )
916 return false;
919 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsResultSetConcurrency( sal_Int32 /*setType*/, sal_Int32 /*concurrency*/ )
921 return false;
924 sal_Bool SAL_CALL OEvoabDatabaseMetaData::ownUpdatesAreVisible( sal_Int32 /*setType*/ )
926 return false;
929 sal_Bool SAL_CALL OEvoabDatabaseMetaData::ownDeletesAreVisible( sal_Int32 /*setType*/ )
931 return false;
934 sal_Bool SAL_CALL OEvoabDatabaseMetaData::ownInsertsAreVisible( sal_Int32 /*setType*/ )
936 return false;
939 sal_Bool SAL_CALL OEvoabDatabaseMetaData::othersUpdatesAreVisible( sal_Int32 /*setType*/ )
941 return false;
944 sal_Bool SAL_CALL OEvoabDatabaseMetaData::othersDeletesAreVisible( sal_Int32 /*setType*/ )
946 return false;
949 sal_Bool SAL_CALL OEvoabDatabaseMetaData::othersInsertsAreVisible( sal_Int32 /*setType*/ )
951 return false;
954 sal_Bool SAL_CALL OEvoabDatabaseMetaData::updatesAreDetected( sal_Int32 /*setType*/ )
956 return false;
959 sal_Bool SAL_CALL OEvoabDatabaseMetaData::deletesAreDetected( sal_Int32 /*setType*/ )
961 return false;
964 sal_Bool SAL_CALL OEvoabDatabaseMetaData::insertsAreDetected( sal_Int32 /*setType*/ )
966 return false;
969 sal_Bool SAL_CALL OEvoabDatabaseMetaData::supportsBatchUpdates( )
971 return false;
974 // here follow all methods which return a resultset
975 // the first methods is an example implementation how to use this resultset
976 // of course you could implement it on your and you should do this because
977 // the general way is more memory expensive
979 Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getTableTypes( )
981 /* Don't need to change as evoab driver supports only table */
983 // there exists no possibility to get table types so we have to check
984 static const std::u16string_view sTableTypes[] =
986 u"TABLE" // Currently we only support a 'TABLE' nothing more complex
988 rtl::Reference<::connectivity::ODatabaseMetaDataResultSet> pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTableTypes);
990 // here we fill the rows which should be visible when ask for data from the resultset returned here
991 auto nNbTypes = SAL_N_ELEMENTS(sTableTypes);
992 ODatabaseMetaDataResultSet::ORows aRows;
993 for(std::size_t i=0;i < nNbTypes;++i)
995 // bound row
996 aRows.push_back( { ODatabaseMetaDataResultSet::getEmptyValue(), new ORowSetValueDecorator(OUString(sTableTypes[i])) });
998 // here we set the rows at the resultset
999 pResult->setRows(aRows);
1000 return pResult;
1003 Reference< XResultSet > OEvoabDatabaseMetaData::impl_getTypeInfo_throw( )
1006 * Return the proper type information required by evo driver
1009 rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo);
1011 static ODatabaseMetaDataResultSet::ORows aRows = []()
1013 ODatabaseMetaDataResultSet::ORows tmp;
1014 ODatabaseMetaDataResultSet::ORow aRow
1016 ODatabaseMetaDataResultSet::getEmptyValue() ,
1017 new ORowSetValueDecorator(OUString("VARCHAR")) ,
1018 new ORowSetValueDecorator(DataType::VARCHAR) ,
1019 new ORowSetValueDecorator(sal_Int32(s_nCHAR_OCTET_LENGTH)) ,
1020 ODatabaseMetaDataResultSet::getQuoteValue() ,
1021 ODatabaseMetaDataResultSet::getQuoteValue() ,
1022 ODatabaseMetaDataResultSet::getEmptyValue() ,
1023 ODatabaseMetaDataResultSet::get1Value() ,
1024 ODatabaseMetaDataResultSet::get1Value() ,
1025 new ORowSetValueDecorator(sal_Int32(ColumnSearch::FULL)) ,
1026 ODatabaseMetaDataResultSet::get1Value() ,
1027 ODatabaseMetaDataResultSet::get0Value() ,
1028 ODatabaseMetaDataResultSet::get0Value() ,
1029 ODatabaseMetaDataResultSet::getEmptyValue() ,
1030 ODatabaseMetaDataResultSet::get0Value() ,
1031 ODatabaseMetaDataResultSet::get0Value() ,
1032 ODatabaseMetaDataResultSet::getEmptyValue() ,
1033 ODatabaseMetaDataResultSet::getEmptyValue() ,
1034 new ORowSetValueDecorator(sal_Int32(10))
1037 tmp.push_back(aRow);
1039 aRow[1] = new ORowSetValueDecorator(OUString("VARCHAR"));
1040 aRow[2] = new ORowSetValueDecorator(DataType::VARCHAR);
1041 aRow[3] = new ORowSetValueDecorator(sal_Int32(65535));
1042 tmp.push_back(aRow);
1043 return tmp;
1044 }();
1045 pResultSet->setRows(aRows);
1046 return pResultSet;
1049 Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getColumns(
1050 const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& /*tableNamePattern*/,
1051 const OUString& columnNamePattern )
1053 // this returns an empty resultset where the column-names are already set
1054 // in special the metadata of the resultset already returns the right columns
1055 rtl::Reference<ODatabaseMetaDataResultSet> pResultSet = new ODatabaseMetaDataResultSet( ODatabaseMetaDataResultSet::eColumns );
1056 pResultSet->setRows( getColumnRows( columnNamePattern ) );
1057 return pResultSet;
1061 bool isSourceBackend(ESource *pSource, const char *backendname)
1063 if (!pSource || !e_source_has_extension (pSource, E_SOURCE_EXTENSION_ADDRESS_BOOK))
1064 return false;
1066 gpointer extension = e_source_get_extension (pSource, E_SOURCE_EXTENSION_ADDRESS_BOOK);
1067 return extension && equal(e_source_backend_get_backend_name (extension), backendname);
1070 Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getTables(
1071 const Any& /*catalog*/, const OUString& /*schemaPattern*/,
1072 const OUString& /*tableNamePattern*/, const Sequence< OUString >& types )
1074 ::osl::MutexGuard aGuard( m_aMutex );
1076 rtl::Reference<ODatabaseMetaDataResultSet> pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes);
1078 // check if any type is given
1079 // when no types are given then we have to return all tables e.g. TABLE
1081 static const OUStringLiteral aTable(u"TABLE");
1083 bool bTableFound = true;
1084 sal_Int32 nLength = types.getLength();
1085 if(nLength)
1087 bTableFound = false;
1089 const OUString* pBegin = types.getConstArray();
1090 const OUString* pEnd = pBegin + nLength;
1091 for(;pBegin != pEnd;++pBegin)
1093 if(*pBegin == aTable)
1095 bTableFound = true;
1096 break;
1100 if(!bTableFound)
1101 return pResult;
1103 ODatabaseMetaDataResultSet::ORows aRows;
1105 if (eds_check_version(3, 6, 0) == nullptr)
1107 GList *pSources = e_source_registry_list_sources(get_e_source_registry(), E_SOURCE_EXTENSION_ADDRESS_BOOK);
1109 for (GList* liter = pSources; liter; liter = liter->next)
1111 ESource *pSource = E_SOURCE (liter->data);
1112 bool can = false;
1113 switch (m_pConnection->getSDBCAddressType())
1115 case SDBCAddress::EVO_GWISE:
1116 can = isSourceBackend( pSource, "groupwise"); // not supported in evo/eds 3.6.x+, somehow
1117 break;
1118 case SDBCAddress::EVO_LOCAL:
1119 can = isSourceBackend( pSource, "local");
1120 break;
1121 case SDBCAddress::EVO_LDAP:
1122 can = isSourceBackend( pSource, "ldap");
1123 break;
1124 case SDBCAddress::Unknown:
1125 can = true;
1126 break;
1128 if (!can)
1129 continue;
1131 OUString aHumanName = OStringToOUString( e_source_get_display_name( pSource ),
1132 RTL_TEXTENCODING_UTF8 );
1133 OUString aUID = OStringToOUString( e_source_get_uid( pSource ),
1134 RTL_TEXTENCODING_UTF8 );
1135 ODatabaseMetaDataResultSet::ORow aRow{
1136 ORowSetValueDecoratorRef(),
1137 ORowSetValueDecoratorRef(),
1138 ORowSetValueDecoratorRef(),
1139 new ORowSetValueDecorator(aHumanName), //tablename
1140 new ORowSetValueDecorator(ORowSetValue(aTable)),
1141 new ORowSetValueDecorator(aUID)}; //comment
1142 //I'd prefer to swap the comment and the human name and
1143 //just use e_source_registry_ref_source(get_e_source_registry(), aUID);
1144 //in open book rather than search for the name again
1145 aRows.push_back(aRow);
1148 g_list_foreach (pSources, reinterpret_cast<GFunc>(g_object_unref), nullptr);
1149 g_list_free (pSources);
1151 else
1153 ESourceList *pSourceList;
1154 if( !e_book_get_addressbooks (&pSourceList, nullptr) )
1155 pSourceList = nullptr;
1157 GSList *g;
1158 for( g = e_source_list_peek_groups( pSourceList ); g; g = g->next)
1160 GSList *s;
1161 const char *p = e_source_group_peek_base_uri(E_SOURCE_GROUP(g->data));
1163 switch (m_pConnection->getSDBCAddressType()) {
1164 case SDBCAddress::EVO_GWISE:
1165 if ( !strncmp( "groupwise://", p, 11 ))
1166 break;
1167 else
1168 continue;
1169 case SDBCAddress::EVO_LOCAL:
1170 if ( !strncmp( "file://", p, 6 ) ||
1171 !strncmp( "local://", p, 6 ) )
1172 break;
1173 else
1174 continue;
1175 case SDBCAddress::EVO_LDAP:
1176 if ( !strncmp( "ldap://", p, 6 ))
1177 break;
1178 else
1179 continue;
1180 case SDBCAddress::Unknown:
1181 break;
1183 for (s = e_source_group_peek_sources (E_SOURCE_GROUP (g->data)); s; s = s->next)
1185 ESource *pSource = E_SOURCE (s->data);
1187 OUString aName = OStringToOUString( e_source_peek_name( pSource ),
1188 RTL_TEXTENCODING_UTF8 );
1190 aRows.push_back(
1192 ORowSetValueDecoratorRef(),
1193 ORowSetValueDecoratorRef(),
1194 ORowSetValueDecoratorRef(),
1195 new ORowSetValueDecorator(aName),
1196 new ORowSetValueDecorator(ORowSetValue(aTable)),
1197 ODatabaseMetaDataResultSet::getEmptyValue()
1204 pResult->setRows(aRows);
1206 return pResult;
1209 Reference< XResultSet > SAL_CALL OEvoabDatabaseMetaData::getUDTs( const Any& /*catalog*/, const OUString& /*schemaPattern*/, const OUString& /*typeNamePattern*/, const Sequence< sal_Int32 >& /*types*/ )
1211 ::dbtools::throwFeatureNotImplementedSQLException( "XDatabaseMetaDaza::getUDTs", *this );
1212 return nullptr;
1216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */