Skip to content

Commit

Permalink
Added interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Mar 1, 2024
1 parent 0917e3c commit b8116c3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion COVERAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
| `sqlite3_changes64` | |
| `sqlite3_clear_bindings` ||
| `sqlite3_close` ||
| `sqlite3_close_v2` | |
| `sqlite3_close_v2` | |
| `sqlite3_collation_needed` | |
| `sqlite3_collation_needed16` | |
| `sqlite3_column_blob` | |
Expand Down
18 changes: 18 additions & 0 deletions src/sqlite3.F90
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ module sqlite3
public :: sqlite3_clear_bindings
public :: sqlite3_close
public :: sqlite3_close_
public :: sqlite3_close_v2
public :: sqlite3_close_v2_
public :: sqlite3_column_count
public :: sqlite3_column_double
public :: sqlite3_column_int
Expand Down Expand Up @@ -421,6 +423,14 @@ function sqlite3_close_(db) bind(c, name='sqlite3_close')
integer(kind=c_int) :: sqlite3_close_
end function sqlite3_close_

! int sqlite3_close_v2(sqlite3 *db)
function sqlite3_close_v2_(db) bind(c, name='sqlite3_close_v2')
import :: c_int, c_ptr
implicit none
type(c_ptr), intent(in), value :: db
integer(kind=c_int) :: sqlite3_close_v2_
end function sqlite3_close_v2_

! int sqlite3_column_count(sqlite3_stmt *stmt)
function sqlite3_column_count(stmt) bind(c, name='sqlite3_column_count')
import :: c_int, c_ptr
Expand Down Expand Up @@ -957,6 +967,14 @@ function sqlite3_close(db)
if (sqlite3_close == SQLITE_OK) db = c_null_ptr
end function sqlite3_close

function sqlite3_close_v2(db)
type(c_ptr), intent(inout) :: db
integer :: sqlite3_close_v2

sqlite3_close_v2 = sqlite3_close_v2_(db)
if (sqlite3_close_v2 == SQLITE_OK) db = c_null_ptr
end function sqlite3_close_v2

function sqlite3_column_name(stmt, idx)
type(c_ptr), intent(inout) :: stmt
integer, intent(in) :: idx
Expand Down
10 changes: 7 additions & 3 deletions test/test_sqlite3.f90
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ program test_sqlite3
print '("SQLite source ID: ", a)', sqlite3_sourceid()

! Open SQLite database.
rc = sqlite3_open(DB_FILE, db)
if (rc /= SQLITE_OK) stop 'sqlite3_open(): failed'
rc = sqlite3_open_v2(DB_FILE, db, ior(SQLITE_OPEN_READWRITE, SQLITE_OPEN_CREATE))

if (rc /= SQLITE_OK) then
print '("Error ", i0, ": ", a)', sqlite3_errcode(db), sqlite3_errmsg(db)
stop 'sqlite3_open_v2(): failed'
end if

db_name = sqlite3_db_name(db, 0)
if (len(db_name) == 0) stop 'sqlite3_db_name(): failed'
Expand Down Expand Up @@ -210,7 +214,7 @@ program test_sqlite3
call print_error(rc, 'sqlite3_exec', errmsg)

! Close SQLite handle.
rc = sqlite3_close(db)
rc = sqlite3_close_v2(db)
if (rc /= SQLITE_OK) stop 'sqlite3_close(): failed'
contains
integer function journal_mode_wal(db) result(rc)
Expand Down

0 comments on commit b8116c3

Please sign in to comment.