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