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_ODBC_ORESULTSETMETADATA_HXX_
29 #define _CONNECTIVITY_ODBC_ORESULTSETMETADATA_HXX_
30 
31 #include <com/sun/star/sdbc/XResultSetMetaData.hpp>
32 #include <cppuhelper/implbase1.hxx>
33 #include "odbc/OFunctions.hxx"
34 #include "odbc/odbcbasedllapi.hxx"
35 #ifndef _VECTOR_
36 #include <vector>
37 #endif
38 #include "odbc/OConnection.hxx"
39 
40 namespace connectivity
41 {
42 	namespace odbc
43 	{
44 		//**************************************************************
45 		//************ Class: ResultSetMetaData
46 		//**************************************************************
47         typedef ::cppu::WeakImplHelper1<        ::com::sun::star::sdbc::XResultSetMetaData>   OResultSetMetaData_BASE;
48 
49 		class OOO_DLLPUBLIC_ODBCBASE OResultSetMetaData :
50             public 	OResultSetMetaData_BASE
51 		{
52 		protected:
53 			::std::vector<sal_Int32> m_vMapping; // when not every column is needed
54             ::std::map<sal_Int32,sal_Int32> m_aColumnTypes;
55 
56 			SQLHANDLE		m_aStatementHandle;
57 			OConnection*	m_pConnection;
58 			sal_Int32		m_nColCount;
59 			sal_Bool		m_bUseODBC2Types;
60 
61             ::rtl::OUString getCharColAttrib(sal_Int32 column,sal_Int32 ident) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
62             sal_Int32 getNumColAttrib(sal_Int32 column,sal_Int32 ident) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
63 		public:
64 			// ein Konstruktor, der fuer das Returnen des Objektes benoetigt wird:
65 			OResultSetMetaData(OConnection*	_pConnection, SQLHANDLE _pStmt )
66                 :m_aStatementHandle( _pStmt )
67 				,m_pConnection(_pConnection)
68 				,m_nColCount(-1)
69 				,m_bUseODBC2Types(sal_False)
70 			{}
71 			OResultSetMetaData(OConnection*	_pConnection, SQLHANDLE _pStmt ,const ::std::vector<sal_Int32> & _vMapping)
72                     :m_vMapping(_vMapping)
73                     ,m_aStatementHandle( _pStmt )
74                     ,m_pConnection(_pConnection)
75 					,m_nColCount(_vMapping.size()-1)
76 					,m_bUseODBC2Types(sal_False)
77 			{}
78 			virtual ~OResultSetMetaData();
79 
80 
81             static SQLLEN getNumColAttrib(OConnection* _pConnection
82                                               ,SQLHANDLE _aStatementHandle
83                                               ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface
84                                               ,sal_Int32 _column
85                                               ,sal_Int32 ident) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
86 
87             static SQLSMALLINT getColumnODBCType(OConnection* _pConnection
88                                               ,SQLHANDLE _aStatementHandle
89                                               ,const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface
90                                               ,sal_Int32 column)
91                                                throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
92 
93 			inline oslGenericFunction getOdbcFunction(sal_Int32 _nIndex)  const
94 			{
95 				return m_pConnection->getOdbcFunction(_nIndex);
96 			}
97 			/// Avoid ambigous cast error from the compiler.
98             inline operator ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > () throw()
99 			{ return this; }
100 
101             virtual sal_Int32 SAL_CALL getColumnCount(  ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
102             virtual sal_Bool SAL_CALL isAutoIncrement( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
103             virtual sal_Bool SAL_CALL isCaseSensitive( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
104             virtual sal_Bool SAL_CALL isSearchable( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
105             virtual sal_Bool SAL_CALL isCurrency( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
106             virtual sal_Int32 SAL_CALL isNullable( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
107             virtual sal_Bool SAL_CALL isSigned( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
108             virtual sal_Int32 SAL_CALL getColumnDisplaySize( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
109             virtual ::rtl::OUString SAL_CALL getColumnLabel( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
110             virtual ::rtl::OUString SAL_CALL getColumnName( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
111             virtual ::rtl::OUString SAL_CALL getSchemaName( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
112             virtual sal_Int32 SAL_CALL getPrecision( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
113 			virtual sal_Int32 SAL_CALL getScale( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
114             virtual ::rtl::OUString SAL_CALL getTableName( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
115             virtual ::rtl::OUString SAL_CALL getCatalogName( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
116             virtual sal_Int32 SAL_CALL getColumnType( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
117             virtual ::rtl::OUString SAL_CALL getColumnTypeName( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
118             virtual sal_Bool SAL_CALL isReadOnly( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
119             virtual sal_Bool SAL_CALL isWritable( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
120             virtual sal_Bool SAL_CALL isDefinitelyWritable( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
121             virtual ::rtl::OUString SAL_CALL getColumnServiceName( sal_Int32 column ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
122 		};
123 	}
124 }
125 #endif // _CONNECTIVITY_ODBC_ORESULTSETMETADATA_HXX_
126 
127