Skip to content

Commit 284d4db

Browse files
committed
Added interfaces to backup functions.
1 parent 498016c commit 284d4db

File tree

1 file changed

+74
-8
lines changed

1 file changed

+74
-8
lines changed

src/sqlite.f90

Lines changed: 74 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ module sqlite
143143
integer(kind=c_size_t), parameter, public :: SQLITE_STATIC = 0
144144
integer(kind=c_size_t), parameter, public :: SQLITE_TRANSIENT = -1
145145

146+
public :: sqlite3_backup_finish
147+
public :: sqlite3_backup_init
148+
public :: sqlite3_backup_pagecount
149+
public :: sqlite3_backup_remaining
150+
public :: sqlite3_backup_step
146151
public :: sqlite3_bind_double
147152
public :: sqlite3_bind_int
148153
public :: sqlite3_bind_int64
@@ -201,6 +206,50 @@ module sqlite
201206
public :: sqlite3_update_hook
202207

203208
interface
209+
! int sqlite3_backup_finish(sqlite3_backup *p)
210+
function sqlite3_backup_finish(p) bind(c, name='sqlite3_backup_finish')
211+
import :: c_int, c_ptr
212+
implicit none
213+
type(c_ptr), intent(in), value :: p
214+
integer(kind=c_int) :: sqlite3_backup_finish
215+
end function sqlite3_backup_finish
216+
217+
! sqlite3_backup *sqlite3_backup_init(sqlite3 *pDest, const char *zDestName, sqlite3 *pSource, const char *zSourceName)
218+
function sqlite3_backup_init_(p_dest, z_dest_name, p_source, z_source_name) bind(c, name='sqlite3_backup_init')
219+
import :: c_char, c_ptr
220+
implicit none
221+
type(c_ptr), intent(in), value :: p_dest
222+
character(kind=c_char), intent(in) :: z_dest_name
223+
type(c_ptr), intent(in), value :: p_source
224+
character(kind=c_char), intent(in) :: z_source_name
225+
type(c_ptr) :: sqlite3_backup_init_
226+
end function sqlite3_backup_init_
227+
228+
! int sqlite3_backup_pagecount(sqlite3_backup *p)
229+
function sqlite3_backup_pagecount(p) bind(c, name='sqlite3_backup_pagecount')
230+
import :: c_int, c_ptr
231+
implicit none
232+
type(c_ptr), intent(in), value :: p
233+
integer(kind=c_int) :: sqlite3_backup_pagecount
234+
end function sqlite3_backup_pagecount
235+
236+
! int sqlite3_backup_remaining(sqlite3_backup *p)
237+
function sqlite3_backup_remaining(p) bind(c, name='sqlite3_backup_remaining')
238+
import :: c_int, c_ptr
239+
implicit none
240+
type(c_ptr), intent(in), value :: p
241+
integer(kind=c_int) :: sqlite3_backup_remaining
242+
end function sqlite3_backup_remaining
243+
244+
! int sqlite3_backup_step(sqlite3_backup *p, int nPage)
245+
function sqlite3_backup_step(p, npage) bind(c, name='sqlite3_backup_step')
246+
import :: c_int, c_ptr
247+
implicit none
248+
type(c_ptr), intent(in), value :: p
249+
integer(kind=c_int), intent(in), value :: npage
250+
integer(kind=c_int) :: sqlite3_backup_step
251+
end function sqlite3_backup_step
252+
204253
! int sqlite3_bind_double(sqlite3_stmt *stmt, int idx, double val)
205254
function sqlite3_bind_double(stmt, idx, val) bind(c, name='sqlite3_bind_double')
206255
import :: c_double, c_int, c_ptr
@@ -271,12 +320,12 @@ function sqlite3_clear_bindings(stmt) bind(c, name='sqlite3_clear_bindings')
271320
end function sqlite3_clear_bindings
272321

273322
! int sqlite3_close(sqlite3 *db)
274-
function sqlite3_close(db) bind(c, name='sqlite3_close')
323+
function sqlite3_close_(db) bind(c, name='sqlite3_close')
275324
import :: c_int, c_ptr
276325
implicit none
277326
type(c_ptr), intent(in), value :: db
278-
integer(kind=c_int) :: sqlite3_close
279-
end function sqlite3_close
327+
integer(kind=c_int) :: sqlite3_close_
328+
end function sqlite3_close_
280329

281330
! double sqlite3_column_double(sqlite3_stmt *stmt, int icol)
282331
function sqlite3_column_double(stmt, icol) bind(c, name='sqlite3_column_double')
@@ -645,6 +694,19 @@ end subroutine sqlite3_str_reset
645694
module procedure :: sqlite3_config_null
646695
end interface
647696
contains
697+
function sqlite3_backup_init(p_dest, z_dest_name, p_source, z_source_name)
698+
type(c_ptr), intent(in) :: p_dest
699+
character(len=*), intent(in) :: z_dest_name
700+
type(c_ptr), intent(in) :: p_source
701+
character(len=*), intent(in) :: z_source_name
702+
type(c_ptr) :: sqlite3_backup_init
703+
704+
sqlite3_backup_init = sqlite3_backup_init_(p_dest, &
705+
z_dest_name // c_null_char, &
706+
p_source, &
707+
z_source_name // c_null_char)
708+
end function sqlite3_backup_init
709+
648710
function sqlite3_bind_text(stmt, idx, val, destructor)
649711
!! Binds text to column. This wrapper passes destructor
650712
!! `SQLITE_TRANSIENT` by default!
@@ -662,6 +724,14 @@ function sqlite3_bind_text(stmt, idx, val, destructor)
662724
sqlite3_bind_text = sqlite3_bind_text_(stmt, idx, val, len(val), SQLITE_TRANSIENT)
663725
end function sqlite3_bind_text
664726

727+
function sqlite3_close(db)
728+
type(c_ptr), intent(inout) :: db
729+
integer :: sqlite3_close
730+
731+
sqlite3_close = sqlite3_close_(db)
732+
if (sqlite3_close == SQLITE_OK) db = c_null_ptr
733+
end function sqlite3_close
734+
665735
function sqlite3_column_text(stmt, icol)
666736
type(c_ptr), intent(inout) :: stmt
667737
integer, intent(in) :: icol
@@ -703,10 +773,7 @@ function sqlite3_errmsg(db)
703773
type(c_ptr) :: ptr
704774

705775
ptr = sqlite3_errmsg_(db)
706-
707-
if (c_associated(ptr)) then
708-
call c_f_str_ptr(ptr, sqlite3_errmsg)
709-
end if
776+
if (c_associated(ptr)) call c_f_str_ptr(ptr, sqlite3_errmsg)
710777
end function sqlite3_errmsg
711778

712779
function sqlite3_exec(db, sql, callback, client_data, errmsg)
@@ -720,7 +787,6 @@ function sqlite3_exec(db, sql, callback, client_data, errmsg)
720787

721788
sqlite3_exec = sqlite3_exec_(db, sql // c_null_char, callback, client_data, ptr)
722789
if (.not. c_associated(ptr)) return
723-
724790
if (present(errmsg)) call c_f_str_ptr(ptr, errmsg)
725791
end function sqlite3_exec
726792

0 commit comments

Comments
 (0)