Skip to content

refactor(mdb): use safe conn.execute() for fetch_table_row_count#92

Merged
lewiszlw merged 3 commits into
masterfrom
refactor/mdb-query-safe-exec
Jun 22, 2026
Merged

refactor(mdb): use safe conn.execute() for fetch_table_row_count#92
lewiszlw merged 3 commits into
masterfrom
refactor/mdb-query-safe-exec

Conversation

@lewiszlw

Copy link
Copy Markdown
Member

Summary

Replace preallocate + unsafe exec_direct + unsafe bind_col + unsafe fetch (3 unsafe blocks) in fetch_table_row_count with odbc-api's safe conn.execute() + cursor.next_row().

Before

let pre = conn.preallocate()?;
let mut stmt = pre.into_handle();
unsafe { stmt.exec_direct(&sql_text) }?;
unsafe { stmt.bind_col(1, &mut dummy) }?;
loop { match unsafe { stmt.fetch() } { ... } }

After

let mut cursor = conn.execute(&count_query, (), None)?...;
loop { match cursor.next_row() { ... } }

Zero unsafe blocks.

lewiszlw added 3 commits June 22, 2026 14:08
The dummy column bind was a workaround for mdbtools 1.0.x which required
SQLBindCol before SQLFetch. With odbc-api's safe conn.execute() wrapper
handling the statement lifecycle, try removing this workaround to see if
mdbtools no longer hangs on SQLFetch without prior SQLBindCol.
Replace the manual preallocate + unsafe exec_direct + unsafe bind_col +
unsafe fetch pattern with odbc-api's safe conn.execute() + cursor.next_row().
Counts rows by iterating the cursor — zero unsafe blocks.
@lewiszlw lewiszlw merged commit d6722b0 into master Jun 22, 2026
3 checks passed
@lewiszlw lewiszlw deleted the refactor/mdb-query-safe-exec branch June 22, 2026 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant