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