Loading...
Searching...
No Matches
odbc.f90
1#include <c_interop.inc>
2module odbc
3 use, intrinsic :: iso_c_binding
4 use sqltypes
5 use sql
6 use sqlext
7 use odbc_constants
8
9 implicit none
10
11 private :: extract_error
12
13contains
14
15 subroutine check_error(code, msg, handle, htype)
16 integer(SQLRETURN), intent(in) :: code
17 character(*), intent(in) :: msg
18 type(SQLHANDLE), intent(in) :: handle
19 integer(SQLSMALLINT), intent(in) :: htype
20
21 if (code /= sql_success .and. code /= sql_success_with_info) then
22 call extract_error(msg, handle, htype)
23 end if
24 end subroutine
25
26 subroutine extract_error(msg, handle, htype)
27 character(*), intent(in) :: msg
28 type(SQLHANDLE), intent(in) :: handle
29 integer(c_short), intent(in) :: htype
30 !private
31 integer(c_short) :: err, lmsg
32 integer(c_int) :: native_error
33 character(6, c_char) :: state
34 character(256, c_char) :: text
35 integer(SQLRETURN) :: ret
36
37 write(*, *) "The driver reported the following error ", trim(msg)
38 err = 1
39 ret = sqlgetdiagrec(htype, handle, err, state, native_error, &
40 text, len(text, c_short), lmsg)
41 do while (ret == sql_success .or. ret == sql_success_with_info)
42 err = err + _short(1)
43 write(*, '(A,":",i0,":",i0,":",A)') trim(state), err, native_error, trim(text)
44 ret = sqlgetdiagrec(htype, handle, err, state, native_error, &
45 text, len(text, c_short), lmsg)
46 end do
47 end subroutine
48
49end module
Triming of c-string returning fortran allocatable characters.