xref: /trunk/main/connectivity/source/drivers/adabas/BResultSet.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include "adabas/BResultSet.hxx"
31 #include "adabas/BResultSetMetaData.hxx"
32 #include <com/sun/star/lang/DisposedException.hpp>
33 #include "odbc/OTools.hxx"
34 
35 using namespace connectivity::adabas;
36 using namespace connectivity::odbc;
37 using namespace cppu;
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::lang;
40 using namespace com::sun::star::beans;
41 using namespace com::sun::star::sdbc;
42 using namespace com::sun::star::sdbcx;
43 using namespace com::sun::star::container;
44 using namespace com::sun::star::io;
45 using namespace com::sun::star::util;
46 
47 // comment: all this movement methods are needed because adabas doesn't support a SQLGetData call when
48 // the cursor was moved with a call of SQLFetchScroll. So when this is fixed by adabas we can remove this damn thing.
49 
50 
51 sal_Bool SAL_CALL OAdabasResultSet::next(  ) throw(SQLException, RuntimeException)
52 {
53     ::osl::MutexGuard aGuard( m_aMutex );
54     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
55 
56 
57     m_nLastColumnPos = 0;
58     //  m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_NEXT,0);
59     m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
60 
61     if(m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO)
62         ++m_nRowPos;
63 
64     OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
65     return m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
66 }
67 // -----------------------------------------------------------------------------
68 sal_Bool SAL_CALL OAdabasResultSet::first(  ) throw(SQLException, RuntimeException)
69 {
70     ::osl::MutexGuard aGuard( m_aMutex );
71     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
72 
73 
74     m_nLastColumnPos = 0;
75     // don't ask why !
76     N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
77     m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_FIRST,0);
78     sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
79     if(bRet)
80     {
81         m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
82         N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
83         m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
84     }
85 
86     OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
87 
88     bRet = ( m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO );
89     if ( bRet )
90         m_nRowPos = 1;
91     return bRet;
92 }
93 // -------------------------------------------------------------------------
94 
95 sal_Bool SAL_CALL OAdabasResultSet::last(  ) throw(SQLException, RuntimeException)
96 {
97     ::osl::MutexGuard aGuard( m_aMutex );
98     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
99 
100 
101     m_nLastColumnPos = 0;
102     N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
103     m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_LAST,0);
104     sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
105     if(bRet)
106     {
107         m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
108         N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
109         m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
110     }
111 
112     m_bEOF = sal_True;
113     OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
114     // here I know definitely that I stand on the last record
115     return m_bLastRecord = (m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO);
116 }
117 // -------------------------------------------------------------------------
118 sal_Bool SAL_CALL OAdabasResultSet::absolute( sal_Int32 row ) throw(SQLException, RuntimeException)
119 {
120     ::osl::MutexGuard aGuard( m_aMutex );
121     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
122 
123 
124     m_nLastColumnPos = 0;
125     N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
126 
127     m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_ABSOLUTE,row);
128     sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
129     if(bRet)
130     {
131         m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
132         N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
133         m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
134     }
135 
136     OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
137     if(bRet)
138         m_nRowPos = row;
139     return bRet;
140 }
141 // -------------------------------------------------------------------------
142 sal_Bool SAL_CALL OAdabasResultSet::relative( sal_Int32 row ) throw(SQLException, RuntimeException)
143 {
144     ::osl::MutexGuard aGuard( m_aMutex );
145     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
146 
147 
148     m_nLastColumnPos = 0;
149     N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
150     m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,row);
151     sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
152     if(bRet)
153     {
154         m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
155         N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
156         m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
157     }
158 
159     OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
160     if(bRet)
161         m_nRowPos += row;
162     return bRet;
163 }
164 // -------------------------------------------------------------------------
165 sal_Bool SAL_CALL OAdabasResultSet::previous(  ) throw(SQLException, RuntimeException)
166 {
167     ::osl::MutexGuard aGuard( m_aMutex );
168     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
169 
170 
171     m_nLastColumnPos = 0;
172     N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
173     m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
174     sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
175     if(bRet)
176     {
177         m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
178         N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
179         m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
180     }
181 
182     OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
183     if(bRet || m_nCurrentFetchState == SQL_NO_DATA)
184         --m_nRowPos;
185     return bRet;
186 }
187 // -----------------------------------------------------------------------------
188 void SAL_CALL OAdabasResultSet::refreshRow(  ) throw(SQLException, RuntimeException)
189 {
190     ::osl::MutexGuard aGuard( m_aMutex );
191     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
192 
193 
194     //  SQLRETURN nRet = N3SQLSetPos(m_aStatementHandle,1,SQL_REFRESH,SQL_LOCK_NO_CHANGE);
195     N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_OFF,SQL_IS_UINTEGER);
196     m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_RELATIVE,0);
197     sal_Bool bRet = m_nCurrentFetchState == SQL_SUCCESS || m_nCurrentFetchState == SQL_SUCCESS_WITH_INFO;
198     if(bRet)
199     {
200         m_nCurrentFetchState = N3SQLFetchScroll(m_aStatementHandle,SQL_FETCH_PRIOR,0);
201         N3SQLSetStmtAttr(m_aStatementHandle,SQL_ATTR_RETRIEVE_DATA,(SQLPOINTER)SQL_RD_ON,SQL_IS_UINTEGER);
202         m_nCurrentFetchState = N3SQLFetch(m_aStatementHandle);
203     }
204     OTools::ThrowException(m_pStatement->getOwnConnection(),m_nCurrentFetchState,m_aStatementHandle,SQL_HANDLE_STMT,*this);
205 }
206 // -----------------------------------------------------------------------------
207 Reference< XResultSetMetaData > SAL_CALL OAdabasResultSet::getMetaData(  ) throw(SQLException, RuntimeException)
208 {
209     ::osl::MutexGuard aGuard( m_aMutex );
210     checkDisposed(OResultSet_BASE::rBHelper.bDisposed);
211 
212 
213     if(!m_xMetaData.is())
214         m_xMetaData = new OAdabasResultSetMetaData(m_pStatement->getOwnConnection(),m_aStatementHandle,m_aSelectColumns);
215     return m_xMetaData;
216 }
217 // -----------------------------------------------------------------------------
218 
219 
220 
221 
222 
223 
224