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