Merge pull request #18 from nyalldawson/fix_limit

Fix LIMIT clause is ignored when executing SQL via ODBC, incorrect behavior with LIMIT 0
This commit is contained in:
Evan Miller 2020-08-18 07:02:00 -04:00 committed by GitHub
commit 1e983c70f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -1081,6 +1081,9 @@ SQLRETURN SQL_API SQLFetch(
//}
//cur = cur->next;
//}
if ( stmt->sql->limit >= 0 && stmt->rows_affected == stmt->sql->limit ) {
return SQL_NO_DATA_FOUND;
}
if (mdb_fetch_row(stmt->sql->cur_table)) {
stmt->rows_affected++;

View File

@ -590,7 +590,7 @@ void mdb_sql_reset(MdbSQL *sql)
sql->sel_count = 0;
sql->max_rows = -1;
sql->row_count = 0;
sql->limit = 0;
sql->limit = -1;
}
static void print_break(int sz, int first)
{
@ -886,7 +886,7 @@ mdb_sql_fetch_row(MdbSQL *sql, MdbTableDef *table)
{
int rc = mdb_fetch_row(table);
if (rc) {
if (sql->row_count + 1 > sql->limit) {
if (sql->limit >= 0 && sql->row_count + 1 > sql->limit) {
return 0;
}
sql->row_count++;