1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_connectivity.hxx"
30*cdf0e10cSrcweir #include "adabas/BResultSet.hxx"
31*cdf0e10cSrcweir #include "adabas/BResultSetMetaData.hxx"
32*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
33*cdf0e10cSrcweir #include "odbc/OTools.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir using namespace connectivity::adabas;
36*cdf0e10cSrcweir using namespace connectivity::odbc;
37*cdf0e10cSrcweir using namespace cppu;
38*cdf0e10cSrcweir using namespace com::sun::star::uno;
39*cdf0e10cSrcweir using namespace com::sun::star::lang;
40*cdf0e10cSrcweir using namespace com::sun::star::beans;
41*cdf0e10cSrcweir using namespace com::sun::star::sdbc;
42*cdf0e10cSrcweir using namespace com::sun::star::sdbcx;
43*cdf0e10cSrcweir using namespace com::sun::star::container;
44*cdf0e10cSrcweir using namespace com::sun::star::io;
45*cdf0e10cSrcweir using namespace com::sun::star::util;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir // comment: all this movement methods are needed because adabas doesn't support a SQLGetData call when
48*cdf0e10cSrcweir // the cursor was moved with a call of SQLFetchScroll. So when this is fixed by adabas we can remove this damn thing.
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::next(  ) throw(SQLException, RuntimeException)
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
54*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir 	m_nLastColumnPos = 0;
58*cdf0e10cSrcweir 	//	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0);
59*cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 	if(m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO)
62*cdf0e10cSrcweir 		++m_nRowPos;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
65*cdf0e10cSrcweir 	return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
66*cdf0e10cSrcweir }
67*cdf0e10cSrcweir // -----------------------------------------------------------------------------
68*cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::first(  ) throw(SQLException, RuntimeException)
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
71*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 	m_nLastColumnPos = 0;
75*cdf0e10cSrcweir 	// don't ask why !
76*cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
77*cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_FIRST,0);
78*cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
79*cdf0e10cSrcweir 	if(bRet)
80*cdf0e10cSrcweir 	{
81*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
82*cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
83*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
84*cdf0e10cSrcweir 	}
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir     bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO );
89*cdf0e10cSrcweir 	if ( bRet )
90*cdf0e10cSrcweir 		m_nRowPos = 1;
91*cdf0e10cSrcweir 	return bRet;
92*cdf0e10cSrcweir }
93*cdf0e10cSrcweir // -------------------------------------------------------------------------
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::last(  ) throw(SQLException, RuntimeException)
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
98*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	m_nLastColumnPos = 0;
102*cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
103*cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_LAST,0);
104*cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
105*cdf0e10cSrcweir 	if(bRet)
106*cdf0e10cSrcweir 	{
107*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
108*cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
109*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
110*cdf0e10cSrcweir 	}
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	m_bEOF = sal_True;
113*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
114*cdf0e10cSrcweir 	// here I know definitely that I stand on the last record
115*cdf0e10cSrcweir 	return m_bLastRecord = (m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO);
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir // -------------------------------------------------------------------------
118*cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
119*cdf0e10cSrcweir {
120*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
121*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	m_nLastColumnPos = 0;
125*cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_ABSOLUTE,row);
128*cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
129*cdf0e10cSrcweir 	if(bRet)
130*cdf0e10cSrcweir 	{
131*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
132*cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
133*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
134*cdf0e10cSrcweir 	}
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
137*cdf0e10cSrcweir 	if(bRet)
138*cdf0e10cSrcweir 		m_nRowPos = row;
139*cdf0e10cSrcweir 	return bRet;
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir // -------------------------------------------------------------------------
142*cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
145*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	m_nLastColumnPos = 0;
149*cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
150*cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,row);
151*cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
152*cdf0e10cSrcweir 	if(bRet)
153*cdf0e10cSrcweir 	{
154*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
155*cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
156*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
157*cdf0e10cSrcweir 	}
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
160*cdf0e10cSrcweir 	if(bRet)
161*cdf0e10cSrcweir 		m_nRowPos += row;
162*cdf0e10cSrcweir 	return bRet;
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir // -------------------------------------------------------------------------
165*cdf0e10cSrcweir sal_Bool SAL_CALL OAdabasResultSet::previous(  ) throw(SQLException, RuntimeException)
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
168*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 	m_nLastColumnPos = 0;
172*cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
173*cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
174*cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
175*cdf0e10cSrcweir 	if(bRet)
176*cdf0e10cSrcweir 	{
177*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
178*cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
179*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
180*cdf0e10cSrcweir 	}
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
183*cdf0e10cSrcweir 	if(bRet || m_nCurrentFetchState == SQL_NO_DATA)
184*cdf0e10cSrcweir 		--m_nRowPos;
185*cdf0e10cSrcweir 	return bRet;
186*cdf0e10cSrcweir }
187*cdf0e10cSrcweir // -----------------------------------------------------------------------------
188*cdf0e10cSrcweir void SAL_CALL OAdabasResultSet::refreshRow(  ) throw(SQLException, RuntimeException)
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
191*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	//	SQLRETURN nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_REFRESH,SQL_LOCK_NO_CHANGE);
195*cdf0e10cSrcweir 	N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
196*cdf0e10cSrcweir 	m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,0);
197*cdf0e10cSrcweir 	sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
198*cdf0e10cSrcweir 	if(bRet)
199*cdf0e10cSrcweir 	{
200*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
201*cdf0e10cSrcweir 		N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
202*cdf0e10cSrcweir 		m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
203*cdf0e10cSrcweir 	}
204*cdf0e10cSrcweir 	OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
205*cdf0e10cSrcweir }
206*cdf0e10cSrcweir // -----------------------------------------------------------------------------
207*cdf0e10cSrcweir Reference< XResultSetMetaData > SAL_CALL OAdabasResultSet::getMetaData(  ) throw(SQLException, RuntimeException)
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
210*cdf0e10cSrcweir 	checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 	if(!m_xMetaData.is())
214*cdf0e10cSrcweir 		m_xMetaData = new OAdabasResultSetMetaData(m_pStatement->getOwnConnection(),m_aStatementHandle,m_aSelectColumns);
215*cdf0e10cSrcweir 	return m_xMetaData;
216*cdf0e10cSrcweir }
217*cdf0e10cSrcweir // -----------------------------------------------------------------------------
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 
224