1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef CONNECTIVITY_INC_CONNECTIVITY_DBMETADATA_HXX
25 #define CONNECTIVITY_INC_CONNECTIVITY_DBMETADATA_HXX
26 
27 /** === begin UNO includes === **/
28 #include <com/sun/star/sdbc/XConnection.hpp>
29 /** === end UNO includes === **/
30 
31 #include <memory>
32 #include "connectivity/dbtoolsdllapi.hxx"
33 
34 namespace comphelper
35 {
36     class ComponentContext;
37 }
38 
39 //........................................................................
40 namespace dbtools
41 {
42 //........................................................................
43 
44 	//====================================================================
45 	//= DatabaseMetaData
46 	//====================================================================
47     struct DatabaseMetaData_Impl;
48     /** encapsulates meta data about a database/connection which cannot be obtained
49         from the usual XDatabaseMetaData result set.
50 
51         Meta data perhaps isn't really the right term ... Some of the methods
52         in this class involved heuristics, some are just a convenient wrapper
53         around more complex ways to obtain the same information.
54 
55         @todo
56             Once CWS dba30 is integrated, we could easily add all the meta data
57             which is part of the "Info" property of a data source.
58     */
59 	class OOO_DLLPUBLIC_DBTOOLS DatabaseMetaData
60 	{
61     private:
62         ::std::auto_ptr< DatabaseMetaData_Impl >    m_pImpl;
63 
64     public:
65         DatabaseMetaData();
66         /** constructs a DatabaseMetaData instance
67             @param  _rxConnection
68                 is the connection whose meta data you're interested in.
69                 Note that some of the information provided by this class can only be obtained
70                 if this connection denotes an application-level connection, i.e. supports
71                 the com.sun.star.sdb.Connection service.
72 
73             @throws ::com::sun::star::lang::IllegalArgumentException
74                 if the given connection is not <NULL/>, but the XDatabaseMetaData provided by it
75                 are <NULL/>
76             @throws ::com::sun::star::sdbc::SQLException
77                 if obtaining the meta data from the connection throws an SQLException
78             @throws ::com::sun::star::uno::RuntimeException
79                 if obtaining the meta data from the connection throws an RuntimeException
80         */
81         DatabaseMetaData(
82             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _connection );
83         DatabaseMetaData( const DatabaseMetaData& _copyFrom );
84         DatabaseMetaData& operator=( const DatabaseMetaData& _copyFrom );
85 
86         ~DatabaseMetaData();
87 
88     public:
89         /** determines whether or not the instances is based on a valid connection
90 
91             As long as this method returns true<TRUE/>, you should expect all other
92             methods throwing an SQLException when called.
93         */
94         bool    isConnected() const;
95 
96         /** resets the instance so that it's based on a new connection
97         */
reset(const::com::sun::star::uno::Reference<::com::sun::star::sdbc::XConnection> & _connection)98         inline  void    reset( const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _connection )
99         {
100             *this = DatabaseMetaData( _connection );
101         }
102 
103         /// wraps XDatabaseMetaData::getIdentifierQuoteString
104         const ::rtl::OUString&  getIdentifierQuoteString() const;
105 
106         /// wraps XDatabaseMetaData::getCatalogSeparator
107         const ::rtl::OUString&  getCatalogSeparator() const;
108 
109         /** determines whether the database supports sub queries in the FROM part
110             of a SELECT clause are supported.
111             @throws ::com::sun::star::sdbc::SQLException
112                 with SQLState 08003 (connection does not exist) if the instances was
113                 default-constructed and does not have a connection, yet.
114         */
115         bool supportsSubqueriesInFrom() const;
116 
117         /** checks whether the database supports primary keys
118 
119             Since there's no dedicated API to ask a database for this, a heuristics needs to be applied.
120             First, the <code>PrimaryKeySupport<code> settings of the data source is examined. If it is <TRUE/>
121             or <FALSE/>, then value is returned. If it is <NULL/>, then the database meta data are examined
122             for support of core SQL grammar, and the result is returned. The assumption is that a database/driver
123             which supports core SQL grammar usually also supports primary keys, and vice versa. At least, experience
124             shows this is true most of the time.
125         */
126         bool supportsPrimaryKeys() const;
127 
128         /** determines whether names in the database should be restricted to SQL-92 identifiers
129 
130             Effectively, this method checks the EnableSQL92Check property of the data source settings,
131             if present.
132         */
133         bool restrictIdentifiersToSQL92() const;
134 
135         /** determines whether when generating SQL statements, an AS keyword should be generated
136             before a correlation name.
137 
138             E.g., it determines whether <code>SELECT * FROM table AS correlation_name</code> or
139             <code>SELECT * FROM table correlation_name</code> is generated.
140         */
141         bool generateASBeforeCorrelationName() const;
142 
143         /** should date time be escaped like '2001-01-01' => #2001-01-01#
144         */
145         bool shouldEscapeDateTime() const;
146 
147         /** auto increment columns should be automaticly used as primary key.
148         */
149         bool isAutoIncrementPrimaryKey() const;
150 
151         /** determines the syntax to use for boolean comparison predicates
152 
153             @see ::com::sun::star::sdb::BooleanComparisonMode
154         */
155         sal_Int32
156             getBooleanComparisonMode() const;
157 
158         /** determines in relations are supported.
159         *
160         * \return <TRUE/> when relations are supported, otherwise <FALSE/>
161         */
162         bool supportsRelations() const;
163 
164         /** determines if column alias names can be used in the order by clause.
165         *
166         * \return <TRUE/> when relations are supported, otherwise <FALSE/>
167         */
168         bool supportsColumnAliasInOrderBy() const;
169 
170         /** determines whether user administration is supported for the database
171 
172             User administration support is controlled by the availability of the XUsersSupplier
173             interface, and it returning a non-NULL users container.
174 
175             @param _rContext
176                 the component context we operate in. Might be needed to create the
177                 css.sdbc.DriverManager instance.
178         */
179         bool    supportsUserAdministration( const ::comphelper::ComponentContext& _rContext ) const;
180 
181         /** determines whether in the application UI, empty table folders (aka catalogs/schemas) should be displayed
182         */
183         bool displayEmptyTableFolders() const;
184 
185         /** determines that threads are supported.
186         *
187         * \return <TRUE/> when threads are supported, otherwise <FALSE/>
188         */
189         bool supportsThreads() const;
190 	};
191 
192 //........................................................................
193 } // namespace dbtools
194 //........................................................................
195 
196 #endif // CONNECTIVITY_INC_CONNECTIVITY_DBMETADATA_HXX
197