LibreOffice Module dbaccess (master) 1
dsmeta.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <dsmeta.hxx>
22#include <dsntypes.hxx>
24
25#include <map>
26#include <utility>
27
28namespace dbaui
29{
30
31 using namespace dbaccess;
32 using namespace ::com::sun::star;
33
34 namespace {
35
36 struct FeatureSupport
37 {
38 // authentication mode of the data source
40
41 FeatureSupport()
43 {
44 }
45
46 explicit FeatureSupport(AuthenticationMode Auth)
47 :eAuthentication( Auth )
48 {
49 }
50 };
51
52 struct FeatureMapping
53 {
57 };
58
59 // global tables
60 const FeatureMapping s_aMappings[] = {
61 { DSID_AUTORETRIEVEENABLED, "GeneratedValues" },
62 { DSID_AUTOINCREMENTVALUE, "GeneratedValues" },
63 { DSID_AUTORETRIEVEVALUE, "GeneratedValues" },
64 { DSID_SQL92CHECK, "UseSQL92NamingConstraints" },
65 { DSID_APPEND_TABLE_ALIAS, "AppendTableAliasInSelect" },
66 { DSID_AS_BEFORE_CORRNAME, "UseKeywordAsBeforeAlias" },
67 { DSID_ENABLEOUTERJOIN, "UseBracketedOuterJoinSyntax" },
68 { DSID_IGNOREDRIVER_PRIV, "IgnoreDriverPrivileges" },
69 { DSID_PARAMETERNAMESUBST, "ParameterNameSubstitution" },
70 { DSID_SUPPRESSVERSIONCL, "DisplayVersionColumns" },
71 { DSID_CATALOG, "UseCatalogInSelect" },
72 { DSID_SCHEMA, "UseSchemaInSelect" },
73 { DSID_INDEXAPPENDIX, "UseIndexDirectionKeyword" },
74 { DSID_DOSLINEENDS, "UseDOSLineEnds" },
75 { DSID_BOOLEANCOMPARISON, "BooleanComparisonMode" },
76 { DSID_CHECK_REQUIRED_FIELDS, "FormsCheckRequiredFields" },
77 { DSID_IGNORECURRENCY, "IgnoreCurrency" },
78 { DSID_ESCAPE_DATETIME, "EscapeDateTime" },
79 { DSID_PRIMARY_KEY_SUPPORT, "PrimaryKeySupport" },
80 { DSID_RESPECTRESULTSETTYPE, "RespectDriverResultSetType" },
81 { DSID_MAX_ROW_SCAN, "MaxRowScan" },
82 };
83 }
84
85 static const FeatureSet& lcl_getFeatureSet( const OUString& _rURL )
86 {
87 typedef std::map< OUString, FeatureSet > FeatureSets;
88 static FeatureSets s_aFeatureSets = []()
89 {
90 FeatureSets tmp;
91 ::connectivity::DriversConfig aDriverConfig( ::comphelper::getProcessComponentContext() );
92 const uno::Sequence< OUString > aPatterns = aDriverConfig.getURLs();
93 for ( auto const & pattern : aPatterns )
94 {
95 FeatureSet aCurrentSet;
96 const ::comphelper::NamedValueCollection aCurrentFeatures( aDriverConfig.getFeatures( pattern ).getNamedValues() );
97
98 for ( const FeatureMapping& rFeatureMapping : s_aMappings )
99 {
100 if ( aCurrentFeatures.has( rFeatureMapping.pAsciiFeatureName ) )
101 aCurrentSet.put( rFeatureMapping.nItemID );
102 }
103
104 tmp[ pattern ] = aCurrentSet;
105 }
106 return tmp;
107 }();
108
109 OSL_ENSURE( s_aFeatureSets.find( _rURL ) != s_aFeatureSets.end(), "invalid URL/pattern!" );
110 return s_aFeatureSets[ _rURL ];
111 }
112
113 static AuthenticationMode getAuthenticationMode( const OUString& _sURL )
114 {
115 static std::map< OUString, FeatureSupport > s_aSupport = []()
116 {
117 std::map< OUString, FeatureSupport > tmp;
118 ::connectivity::DriversConfig aDriverConfig(::comphelper::getProcessComponentContext());
119 const uno::Sequence< OUString > aURLs = aDriverConfig.getURLs();
120 const OUString* pIter = aURLs.getConstArray();
121 const OUString* pEnd = pIter + aURLs.getLength();
122 for(;pIter != pEnd;++pIter)
123 {
124 FeatureSupport aInit( AuthNone );
125 const ::comphelper::NamedValueCollection& aMetaData = aDriverConfig.getMetaData(*pIter);
126 if ( aMetaData.has("Authentication") )
127 {
128 OUString sAuth;
129 aMetaData.get("Authentication") >>= sAuth;
130 if ( sAuth == "UserPassword" )
131 aInit = FeatureSupport(AuthUserPwd);
132 else if ( sAuth == "Password" )
133 aInit = FeatureSupport(AuthPwd);
134 }
135 tmp.insert(std::make_pair(*pIter,aInit));
136 }
137 return tmp;
138 }();
139 OSL_ENSURE(s_aSupport.find(_sURL) != s_aSupport.end(),"Illegal URL!");
140 return s_aSupport[ _sURL ].eAuthentication;
141 }
142
143 // DataSourceMetaData
145 :m_sURL( _sURL )
146 {
147 }
148
150 {
151 }
152
154 {
155 return lcl_getFeatureSet( m_sURL );
156 }
157
159 {
160 return getAuthenticationMode( _sURL );
161 }
162
163} // namespace dbaui
164
165/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::uno::Any & get(const OUString &_rValueName) const
css::uno::Sequence< css::beans::NamedValue > getNamedValues() const
const ::comphelper::NamedValueCollection & getFeatures(std::u16string_view _sURL) const
css::uno::Sequence< OUString > getURLs() const
const ::comphelper::NamedValueCollection & getMetaData(std::u16string_view _sURL) const
static AuthenticationMode getAuthentication(const OUString &_sURL)
determines whether or not the data source requires authentication
Definition: dsmeta.cxx:158
DataSourceMetaData(const OUString &_sURL)
Definition: dsmeta.cxx:144
const FeatureSet & getFeatureSet() const
returns a struct describing this data source type's support for our known advanced settings
Definition: dsmeta.cxx:153
can be used to ask for (UI) support for certain advanced features
Definition: dsmeta.hxx:74
void put(const ItemID _id)
Definition: dsmeta.hxx:81
OUString m_sURL
Definition: dbwizsetup.cxx:870
#define DSID_RESPECTRESULTSETTYPE
Definition: dsitems.hxx:93
#define DSID_SCHEMA
Definition: dsitems.hxx:79
#define DSID_ESCAPE_DATETIME
Definition: dsitems.hxx:89
#define DSID_ENABLEOUTERJOIN
Definition: dsitems.hxx:77
#define DSID_AS_BEFORE_CORRNAME
Definition: dsitems.hxx:85
#define DSID_INDEXAPPENDIX
Definition: dsitems.hxx:80
#define DSID_MAX_ROW_SCAN
Definition: dsitems.hxx:92
#define DSID_BOOLEANCOMPARISON
Definition: dsitems.hxx:75
sal_Int32 ItemID
Definition: dsitems.hxx:28
#define DSID_DOSLINEENDS
Definition: dsitems.hxx:83
#define DSID_PARAMETERNAMESUBST
Definition: dsitems.hxx:55
#define DSID_CHECK_REQUIRED_FIELDS
Definition: dsitems.hxx:86
#define DSID_AUTOINCREMENTVALUE
Definition: dsitems.hxx:69
#define DSID_PRIMARY_KEY_SUPPORT
Definition: dsitems.hxx:91
#define DSID_IGNOREDRIVER_PRIV
Definition: dsitems.hxx:74
#define DSID_AUTORETRIEVEENABLED
Definition: dsitems.hxx:71
#define DSID_CATALOG
Definition: dsitems.hxx:78
#define DSID_IGNORECURRENCY
Definition: dsitems.hxx:87
#define DSID_SUPPRESSVERSIONCL
Definition: dsitems.hxx:57
#define DSID_APPEND_TABLE_ALIAS
Definition: dsitems.hxx:72
#define DSID_SQL92CHECK
Definition: dsitems.hxx:68
#define DSID_AUTORETRIEVEVALUE
Definition: dsitems.hxx:70
ItemID nItemID
one of the items from dsitems.hxx
Definition: dsmeta.cxx:55
OUString pAsciiFeatureName
Definition: dsmeta.cxx:56
AuthenticationMode eAuthentication
Definition: dsmeta.cxx:39
AuthenticationMode
Definition: dsmeta.hxx:37
@ AuthPwd
Definition: dsmeta.hxx:40
@ AuthNone
Definition: dsmeta.hxx:38
@ AuthUserPwd
Definition: dsmeta.hxx:39
static const FeatureSet & lcl_getFeatureSet(const OUString &_rURL)
Definition: dsmeta.cxx:85
static AuthenticationMode getAuthenticationMode(const OUString &_sURL)
Definition: dsmeta.cxx:113