Corrects forward-only fetching for MDBTools.

This commit is contained in:
zxMarce 2021-04-09 19:45:57 -03:00
parent e078f54480
commit 0047bdf9c0
2 changed files with 20 additions and 30 deletions

1
.gitignore vendored
View file

@ -45,4 +45,3 @@ DISABLED*
**/.gitignore **/.gitignore
app/other/MakeWebSite/gambas.sourceforge.net/*/ app/other/MakeWebSite/gambas.sourceforge.net/*/
*~ *~
.vscode/c_cpp_properties.json

View file

@ -221,7 +221,7 @@ int GetRecordCount(SQLHANDLE stmtHandle, SQLINTEGER cursorScrollable)
//Make sure the statement has a cursor //Make sure the statement has a cursor
if (!(stmtHandle && (cursorScrollable == SQL_TRUE))) if (!(stmtHandle && (cursorScrollable == SQL_TRUE)))
{ {
DB.Debug("gb.db.odbc", "cannot do GetRecordCount()!"); DB.Debug("gb.db.odbc", "GetRecordCount(): Cannot count records!");
return ((int) myRecCnt); return ((int) myRecCnt);
} }
@ -1133,47 +1133,38 @@ fflush(stderr);
{ {
if(res->Cursor_Scrollable == SQL_TRUE) //Does the query support scrolling? if(res->Cursor_Scrollable == SQL_TRUE) //Does the query support scrolling?
{ {
retcode2 = SQLFetchScroll(res->odbcStatHandle, SQL_FETCH_ABSOLUTE, pos + 1); retcode2 = SQLFetchScroll(
DB.Debug( res->odbcStatHandle,
"gb.db.odbc", SQL_FETCH_ABSOLUTE,
"query_fill.SQLFetchScroll(SQL_FETCH_ABSOLUTE): retcode2=%d", pos + 1
(int)retcode2
); );
} }
else else
{ {
retcode2 = SQLFetchScroll(res->odbcStatHandle, SQL_FETCH_NEXT, pos + 1); retcode2 = SQLFetchScroll(
if(!SQL_SUCCEEDED(retcode2))
{
reportODBCError(
"SQLFetchScroll(SQL_FETCH_NEXT)",
res->odbcStatHandle, res->odbcStatHandle,
SQL_HANDLE_STMT SQL_FETCH_NEXT,
); pos + 1
}
DB.Debug(
"gb.db.odbc",
"query_fill.SQLFetchScroll(SQL_FETCH_NEXT): retcode2=%d",
(int)retcode2
); );
} }
} }
else else
{ {
/** /**
* zxMarce, 20210405: This next IF seems to be unnecessary * 20210409 zxMarce: The next IF makes sure the query is not
* (and even bad) for MDBTools (and maybe any other driver that * forced to fetch-back, as the first fetch is issued with:
* not support cursors). Disabling until a new problem arises. * (next == false) && (pos == 0)
* Actually, come to think of it, I do not understand what the * Subsequent valid (forward) fetches are issued with:
* purpose of this "next" parameter can be. * (next == true) && (pos != 0)
* Any invalid fetch is detected by comparing against:
* (!next) && (pos != 0)
* which will trigger a descriptive error message.
*/ */
/* if ((!next) && (pos != 0))
if (!next)
{ {
GB.Error("Unable to fetch row (!next)"); GB.Error("Forward-only result cannot fetch backwards");
return DB_ERROR; return DB_ERROR;
} }
*/
retcode2 = SQLFetch(res->odbcStatHandle); retcode2 = SQLFetch(res->odbcStatHandle);
} }