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