Skip to content

Commit

Permalink
Add a return code check when we're fetching results. Previously, ther… (
Browse files Browse the repository at this point in the history
#246)

* Add a return code check when we're fetching results. Previously, there might have been an error when calling SQLFetchScroll and ODBC.jl ignored it

* Fix travis hopefully

* Fix basic querying
  • Loading branch information
quinnj committed Aug 7, 2019
1 parent 2fd9417 commit d2f2f4e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist: trusty
language: julia

sudo: false
Expand Down
4 changes: 2 additions & 2 deletions src/ODBC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ macro CHECK(handle, handletype, func)
str = string(func)
esc(quote
ret = $func
ret != ODBC.API.SQL_SUCCESS && ret != ODBC.API.SQL_SUCCESS_WITH_INFO && ODBCError($handle, $handletype) &&
ret != ODBC.API.SQL_SUCCESS && ret != ODBC.API.SQL_SUCCESS_WITH_INFO && ret != API.SQL_NO_DATA && ODBCError($handle, $handletype) &&
throw(ODBCError("$($str) failed; return code: $ret => $(ODBC.API.RETURN_VALUES[ret])"))
nothing
ret
end)
end

Expand Down
4 changes: 2 additions & 2 deletions src/Query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Base.iterate(q::Query{rows, NT}, st=1) where {rows, NT}
((st > q.rowsfetched[] && q.status[] != API.SQL_SUCCESS && q.status[] != API.SQL_SUCCESS_WITH_INFO) || q.status[] == API.SQL_NO_DATA) && return nothing
nt = generate_namedtuple(NT, q, st)
if st == q.rowsfetched[]
q.status[] = API.SQLFetchScroll(q.stmt, API.SQL_FETCH_NEXT, 0)
q.status[] = @CHECK q.stmt API.SQL_HANDLE_STMT API.SQLFetchScroll(q.stmt, API.SQL_FETCH_NEXT, 0)
q.rowsfetched[] > 0 && foreach(i->cast!(q.jltypes[i], q, i), 1:length(q.jltypes))
st = 0
end
Expand Down Expand Up @@ -118,7 +118,7 @@ function Query(dsn::DSN, query::AbstractString)
q = Query{rows >= 0 ? rows : missing, NT, typeof(columns)}(
stmt, Ref(0), columns, rowsfetched, boundcols, indcols, csizes, types, jltypes, boundcount)
if rows != 0
q.status[] = Int(API.SQLFetchScroll(q.stmt, API.SQL_FETCH_NEXT, 0))
q.status[] = @CHECK q.stmt API.SQL_HANDLE_STMT API.SQLFetchScroll(q.stmt, API.SQL_FETCH_NEXT, 0)
q.rowsfetched[] > 0 && foreach(i->cast!(jltypes[i], q, i), 1:length(jltypes))
else
q.status[] = 100
Expand Down

0 comments on commit d2f2f4e

Please sign in to comment.