1*9b5730f6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9b5730f6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9b5730f6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9b5730f6SAndrew Rist  * distributed with this work for additional information
6*9b5730f6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9b5730f6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9b5730f6SAndrew Rist  * "License"); you may not use this file except in compliance
9*9b5730f6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9b5730f6SAndrew Rist  *
11*9b5730f6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9b5730f6SAndrew Rist  *
13*9b5730f6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9b5730f6SAndrew Rist  * software distributed under the License is distributed on an
15*9b5730f6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9b5730f6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9b5730f6SAndrew Rist  * specific language governing permissions and limitations
18*9b5730f6SAndrew Rist  * under the License.
19*9b5730f6SAndrew Rist  *
20*9b5730f6SAndrew Rist  *************************************************************/
21*9b5730f6SAndrew Rist 
22*9b5730f6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
26cdf0e10cSrcweir #include "adabas/BResultSet.hxx"
27cdf0e10cSrcweir #include "adabas/BResultSetMetaData.hxx"
28cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
29cdf0e10cSrcweir #include "odbc/OTools.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using namespace connectivity::adabas;
32cdf0e10cSrcweir using namespace connectivity::odbc;
33cdf0e10cSrcweir using namespace cppu;
34cdf0e10cSrcweir using namespace com::sun::star::uno;
35cdf0e10cSrcweir using namespace com::sun::star::lang;
36cdf0e10cSrcweir using namespace com::sun::star::beans;
37cdf0e10cSrcweir using namespace com::sun::star::sdbc;
38cdf0e10cSrcweir using namespace com::sun::star::sdbcx;
39cdf0e10cSrcweir using namespace com::sun::star::container;
40cdf0e10cSrcweir using namespace com::sun::star::io;
41cdf0e10cSrcweir using namespace com::sun::star::util;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir // comment: all this movement methods are needed because adabas doesn't support a SQLGetData call when
44cdf0e10cSrcweir // the cursor was moved with a call of SQLFetchScroll. So when this is fixed by adabas we can remove this damn thing.
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 
next()47cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::next(  ) throw(SQLException, RuntimeException)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
50cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 	m_nLastColumnPos = 0;
54cdf0e10cSrcweir 	//	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0);
55cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	if(m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO)
58cdf0e10cSrcweir 		++m_nRowPos;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
61cdf0e10cSrcweir 	return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir // -----------------------------------------------------------------------------
first()64cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::first(  ) throw(SQLException, RuntimeException)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
67cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	m_nLastColumnPos = 0;
71cdf0e10cSrcweir 	// don't ask why !
72cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
73cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_FIRST,0);
74cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
75cdf0e10cSrcweir 	if(bRet)
76cdf0e10cSrcweir 	{
77cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
78cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
79cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
80cdf0e10cSrcweir 	}
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO );
85cdf0e10cSrcweir 	if ( bRet )
86cdf0e10cSrcweir 		m_nRowPos = 1;
87cdf0e10cSrcweir 	return bRet;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir // -------------------------------------------------------------------------
90cdf0e10cSrcweir 
last()91cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::last(  ) throw(SQLException, RuntimeException)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
94cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 	m_nLastColumnPos = 0;
98cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
99cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_LAST,0);
100cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
101cdf0e10cSrcweir 	if(bRet)
102cdf0e10cSrcweir 	{
103cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
104cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
105cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
106cdf0e10cSrcweir 	}
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 	m_bEOF = sal_True;
109cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
110cdf0e10cSrcweir 	// here I know definitely that I stand on the last record
111cdf0e10cSrcweir 	return m_bLastRecord = (m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO);
112cdf0e10cSrcweir }
113cdf0e10cSrcweir // -------------------------------------------------------------------------
absolute(sal_Int32 row)114cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
117cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	m_nLastColumnPos = 0;
121cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_ABSOLUTE,row);
124cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
125cdf0e10cSrcweir 	if(bRet)
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
128cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
129cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
130cdf0e10cSrcweir 	}
131cdf0e10cSrcweir 
132cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
133cdf0e10cSrcweir 	if(bRet)
134cdf0e10cSrcweir 		m_nRowPos = row;
135cdf0e10cSrcweir 	return bRet;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir // -------------------------------------------------------------------------
relative(sal_Int32 row)138cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
141cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	m_nLastColumnPos = 0;
145cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
146cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,row);
147cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
148cdf0e10cSrcweir 	if(bRet)
149cdf0e10cSrcweir 	{
150cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
151cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
152cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
153cdf0e10cSrcweir 	}
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
156cdf0e10cSrcweir 	if(bRet)
157cdf0e10cSrcweir 		m_nRowPos += row;
158cdf0e10cSrcweir 	return bRet;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir // -------------------------------------------------------------------------
previous()161cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::previous(  ) throw(SQLException, RuntimeException)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
164cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 	m_nLastColumnPos = 0;
168cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
169cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
170cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
171cdf0e10cSrcweir 	if(bRet)
172cdf0e10cSrcweir 	{
173cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
174cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
175cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
176cdf0e10cSrcweir 	}
177cdf0e10cSrcweir 
178cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
179cdf0e10cSrcweir 	if(bRet || m_nCurrentFetchState == SQL_NO_DATA)
180cdf0e10cSrcweir 		--m_nRowPos;
181cdf0e10cSrcweir 	return bRet;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir // -----------------------------------------------------------------------------
refreshRow()184cdf0e10cSrcweir void SAL_CALL OAdabasResultSet::refreshRow(  ) throw(SQLException, RuntimeException)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
187cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	//	SQLRETURN nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_REFRESH,SQL_LOCK_NO_CHANGE);
191cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
192cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,0);
193cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
194cdf0e10cSrcweir 	if(bRet)
195cdf0e10cSrcweir 	{
196cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
197cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
198cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
199cdf0e10cSrcweir 	}
200cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
201cdf0e10cSrcweir }
202cdf0e10cSrcweir // -----------------------------------------------------------------------------
getMetaData()203cdf0e10cSrcweir Reference< XResultSetMetaData > SAL_CALL OAdabasResultSet::getMetaData(  ) throw(SQLException, RuntimeException)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
206cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 	if(!m_xMetaData.is())
210cdf0e10cSrcweir 		m_xMetaData = new OAdabasResultSetMetaData(m_pStatement->getOwnConnection(),m_aStatementHandle,m_aSelectColumns);
211cdf0e10cSrcweir 	return m_xMetaData;
212cdf0e10cSrcweir }
213cdf0e10cSrcweir // -----------------------------------------------------------------------------
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 
220