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 .
22 #include <sal/config.h>
24 #include <string_view>
27 #include <dbadllapi.hxx>
28 #include <connectivity/DriversConfig.hxx>
34 /// known datasource types
54 DST_EVOLUTION_GROUPWISE
= 18,
55 DST_EVOLUTION_LDAP
= 19,
58 DST_MSACCESS_2007
= 22,
59 DST_EMBEDDED_HSQLDB
= 23,
60 DST_MYSQL_NATIVE
= 24,
61 DST_MYSQL_NATIVE_DIRECT
= 25,
63 DST_EMBEDDED_FIREBIRD
= 27,
67 DST_USERDEFINE1
, /// first user defined driver
78 DST_UNKNOWN
/// unrecognized type
81 #define PAGE_DBSETUPWIZARD_INTRO 0
82 #define PAGE_DBSETUPWIZARD_DBASE 1
83 #define PAGE_DBSETUPWIZARD_TEXT 2
84 #define PAGE_DBSETUPWIZARD_MSACCESS 3
85 #define PAGE_DBSETUPWIZARD_LDAP 4
86 //5 was PAGE_DBSETUPWIZARD_ADABAS
87 #define PAGE_DBSETUPWIZARD_MYSQL_INTRO 6
88 #define PAGE_DBSETUPWIZARD_MYSQL_JDBC 7
89 #define PAGE_DBSETUPWIZARD_MYSQL_ODBC 8
90 #define PAGE_DBSETUPWIZARD_ORACLE 9
91 #define PAGE_DBSETUPWIZARD_JDBC 10
92 #define PAGE_DBSETUPWIZARD_ADO 11
93 #define PAGE_DBSETUPWIZARD_ODBC 12
94 #define PAGE_DBSETUPWIZARD_DOCUMENT_OR_SPREADSHEET 13
95 #define PAGE_DBSETUPWIZARD_AUTHENTIFICATION 14
96 #define PAGE_DBSETUPWIZARD_FINAL 16
97 #define PAGE_DBSETUPWIZARD_USERDEFINED 17
98 #define PAGE_DBSETUPWIZARD_MYSQL_NATIVE 18
99 #define PAGE_DBSETUPWIZARD_POSTGRES 19
101 // ODsnTypeCollection
102 class OOO_DLLPUBLIC_DBA ODsnTypeCollection final
105 std::vector
<OUString
> m_aDsnTypesDisplayNames
; /// user readable names for the datasource types
106 std::vector
<OUString
> m_aDsnPrefixes
; /// DSN prefixes which determine the type of a datasource
107 ::connectivity::DriversConfig m_aDriverConfig
;
109 #if OSL_DEBUG_LEVEL > 0
110 sal_Int32 m_nLivingIterators
; /// just for debugging reasons, counts the living iterators
115 friend class ODsnTypeCollection::TypeIterator
;
117 ODsnTypeCollection(const css::uno::Reference
< css::uno::XComponentContext
>& _xContext
);
118 ~ODsnTypeCollection();
120 /// get the datasource type display name from a DSN string
121 OUString
getTypeDisplayName(std::u16string_view _sURL
) const;
123 /// on a given string, cut the type prefix and return the result
124 OUString
cutPrefix(std::u16string_view _sURL
) const;
126 /// on a given string, return the type prefix
127 OUString
getPrefix(std::u16string_view _sURL
) const;
129 /// determines whether there is a driver for the given URL prefix/pattern
130 bool hasDriver( const char* _pAsciiPattern
) const;
132 /// on a given string, return the Java Driver Class
133 OUString
getJavaDriverClass(std::u16string_view _sURL
) const;
135 /// returns the media type of a file based database
136 OUString
getMediaType(std::u16string_view _sURL
) const;
138 /// returns the dsn prefix for a given media type
139 OUString
getDatasourcePrefixFromMediaType(std::u16string_view _sMediaType
, std::u16string_view _sExtension
);
141 void extractHostNamePort(const OUString
& _rDsn
,OUString
& _sDatabaseName
,OUString
& _rHostname
,sal_Int32
& _nPortNumber
) const;
143 /// check if the given data source allows creation of tables
144 bool supportsTableCreation(std::u16string_view _sURL
) const;
146 /// check if the given data source allows to show column description.
147 bool supportsColumnDescription(std::u16string_view _sURL
) const;
149 // check if a Browse button may be shown to insert connection url
150 bool supportsBrowsing(std::u16string_view _sURL
) const;
152 // check if a Create New Database button may be shown to insert connection url
153 bool supportsDBCreation(std::u16string_view _sURL
) const;
155 /// check if the given data source type is based on the file system - i.e. the URL is a prefix plus a file URL
156 bool isFileSystemBased(std::u16string_view _sURL
) const;
158 bool isConnectionUrlRequired(std::u16string_view _sURL
) const;
160 /// checks if the given data source type embeds its data into the database document
161 static bool isEmbeddedDatabase( std::u16string_view _sURL
);
163 static OUString
getEmbeddedDatabase();
165 // returns true when the properties dialog can be shown, otherwise false.
166 static bool isShowPropertiesEnabled( const OUString
& _sURL
);
168 /** returns default settings for newly created databases of the given type.
170 css::uno::Sequence
< css::beans::PropertyValue
>
171 getDefaultDBSettings( std::u16string_view _sURL
) const;
173 /// get access to the first element of the types collection
174 inline TypeIterator
begin() const;
175 /// get access to the (last + 1st) element of the types collection
176 inline TypeIterator
end() const;
178 void fillPageIds(std::u16string_view _sURL
,std::vector
<sal_Int16
>& _rOutPathIds
) const;
180 DATASOURCE_TYPE
determineType(std::u16string_view _rDsn
) const;
182 sal_Int32
getIndexOf(std::u16string_view _sURL
) const;
183 sal_Int32
size() const;
184 OUString
getType(std::u16string_view _sURL
) const;
187 //- ODsnTypeCollection::TypeIterator
188 class OOO_DLLPUBLIC_DBA
ODsnTypeCollection::TypeIterator
190 friend class ODsnTypeCollection
;
192 friend bool OOO_DLLPUBLIC_DBA
operator==(const TypeIterator
& lhs
, const TypeIterator
& rhs
);
193 friend bool OOO_DLLPUBLIC_DBA
operator!=(const TypeIterator
& lhs
, const TypeIterator
& rhs
) { return !(lhs
== rhs
); }
196 const ODsnTypeCollection
* m_pContainer
;
197 sal_Int32 m_nPosition
;
200 TypeIterator(const TypeIterator
& _rSource
);
203 OUString
const & getURLPrefix() const;
204 OUString
const & getDisplayName() const;
207 const TypeIterator
& operator++();
210 TypeIterator(const ODsnTypeCollection
* _pContainer
, sal_Int32 _nInitialPos
);
214 inline ODsnTypeCollection::TypeIterator
ODsnTypeCollection::begin() const { return ODsnTypeCollection::TypeIterator(this, 0);}
215 inline ODsnTypeCollection::TypeIterator
ODsnTypeCollection::end() const { return ODsnTypeCollection::TypeIterator(this, m_aDsnTypesDisplayNames
.size());}
217 } // namespace dbaccess
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */