Check-in [73c6d80c36]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:added sqlite3-config-log and sqlite3-busy-timeout
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:73c6d80c360f605d16515908ca8619dfd80469c8
User & Date: aldo 2018-12-09 15:17:02
Context
2018-12-09
15:17
added scgi-before-fork-hook check-in: 04a3625e95 user: aldo tags: trunk
15:17
added sqlite3-config-log and sqlite3-busy-timeout check-in: 73c6d80c36 user: aldo tags: trunk
2018-04-16
15:02
small fixes check-in: bd1b679435 user: aldo tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to sqlite3.sls.

8
9
10
11
12
13
14

15
16
17
18
19
20
21
..
43
44
45
46
47
48
49
50

51
52
53
54
55
56
57
...
121
122
123
124
125
126
127


128
129
130
131
132
133
134
...
233
234
235
236
237
238
239




240
241
242
243
244
245
246
...
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
...
806
807
808
809
810
811
812
813


814

815
816
817
818
819
820
821
822
823
824
825
826
 (export
  ;; procedures
  open-database
                                        ;define-collation
                                        ;define-function
  set-busy-handler!
                                        ;make-busy-timeout

  interrupt!
  auto-committing?
  change-count
  last-insert-rowid
  finalize!
  prepare
  source-sql
................................................................................
  sql-complete?
  database-version
  database-memory-used
  database-memory-highwater
  enable-shared-cache!
  enable-load-extension!

  sqlite3-trace)


 (import
  (chezscheme)
  (srfi s0 cond-expand)
  (srfi s2 and-let)
  (matchable)
  (only (srfi s13 strings) string-contains-ci)
................................................................................
   (let ([x (find (lambda (a) (equal? (cdr a) status)) sqlite3:status)])
     (if (pair? x) (car x) #f)))

 (define sqlite3:type-enum (make-enumeration '(undefined integer float text blob null)))
 (define sqlite3:type-index (enum-set-indexer sqlite3:type-enum))
 (define (sqlite3:type-ref index)
   (list-ref (enum-set->list sqlite3:type-enum) index))



 ;; Auxiliary types

 (define-ftype sqlite3:context void*)

 (define-ftype sqlite3:value void*)

................................................................................
 ;; Set application busy handler.  Does not use a callback, so it is safe
 ;; to yield.  Handler is called with DB, COUNT and LAST (the last value
 ;; it returned).  Return true value to continue trying, or #f to stop.
 (define (set-busy-handler! db handler)
   (check-database 'set-busy-handler! db)
   (database-busy-handler-set! db handler))





 (define (database-addr db)
   (ftype-pointer-address (database-ptr db)))

 (define (statement-addr stmt)
   (ftype-pointer-address (statement-ptr stmt)))

 ;; Cancel any running database operation as soon as possible
................................................................................
            [zSql (string->utf8 sql)]
            [nByte (bytevector-length zSql)]
            [e (sqlite3_prepare_v2 (database-addr db) zSql nByte (ftype-pointer-address ptr) #f)])
       (cond [(equal? e 0)
              (make-statement (ftype-&ref sqlite3:statement** (*) ptr) db)]
             [else
              (case (number->sqlite3:status e)
                [(busy)
                 (let ([h (database-busy-handler db)])
                   (cond
                    [(and h (h db retries))
                     (retry (fx+ retries 1))]
                    [else
                     ((abort-sqlite3-error 'prepare db db sql) e)]))]
                [else
................................................................................
      [else
       enable?])]))

 (define (sqlite3-trace db func data)
   (check-database 'sqlite3-trace db)
   (let ([f (foreign-procedure "sqlite3_trace" (sqlite3:database* void* void*) void)])
     (f (database-addr db) func data)))
 


 (foreign-procedure "sqlite3_trace" ( void* void*) void)


 (record-writer
  (type-descriptor database)
  (lambda (r p wr)
    (wr
     (if (database-ptr r)
         "#<sqlite3:database>"
         "#<sqlite3:database zombie>")
     p)))

 ) ; library sqlite3








>







 







|
>







 







>
>







 







>
>
>
>







 







|







 







|
>
>
|
>












8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
...
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
...
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
 (export
  ;; procedures
  open-database
                                        ;define-collation
                                        ;define-function
  set-busy-handler!
                                        ;make-busy-timeout
  sqlite3-busy-timeout
  interrupt!
  auto-committing?
  change-count
  last-insert-rowid
  finalize!
  prepare
  source-sql
................................................................................
  sql-complete?
  database-version
  database-memory-used
  database-memory-highwater
  enable-shared-cache!
  enable-load-extension!

  sqlite3-trace
  sqlite3-config-log)

 (import
  (chezscheme)
  (srfi s0 cond-expand)
  (srfi s2 and-let)
  (matchable)
  (only (srfi s13 strings) string-contains-ci)
................................................................................
   (let ([x (find (lambda (a) (equal? (cdr a) status)) sqlite3:status)])
     (if (pair? x) (car x) #f)))

 (define sqlite3:type-enum (make-enumeration '(undefined integer float text blob null)))
 (define sqlite3:type-index (enum-set-indexer sqlite3:type-enum))
 (define (sqlite3:type-ref index)
   (list-ref (enum-set->list sqlite3:type-enum) index))

 

 ;; Auxiliary types

 (define-ftype sqlite3:context void*)

 (define-ftype sqlite3:value void*)

................................................................................
 ;; Set application busy handler.  Does not use a callback, so it is safe
 ;; to yield.  Handler is called with DB, COUNT and LAST (the last value
 ;; it returned).  Return true value to continue trying, or #f to stop.
 (define (set-busy-handler! db handler)
   (check-database 'set-busy-handler! db)
   (database-busy-handler-set! db handler))

 (define (sqlite3-busy-timeout db ms)
   (let ([f (foreign-procedure "sqlite3_busy_timeout" (sqlite3:database* int) int)])
     (f (database-addr db) ms)))
 
 (define (database-addr db)
   (ftype-pointer-address (database-ptr db)))

 (define (statement-addr stmt)
   (ftype-pointer-address (statement-ptr stmt)))

 ;; Cancel any running database operation as soon as possible
................................................................................
            [zSql (string->utf8 sql)]
            [nByte (bytevector-length zSql)]
            [e (sqlite3_prepare_v2 (database-addr db) zSql nByte (ftype-pointer-address ptr) #f)])
       (cond [(equal? e 0)
              (make-statement (ftype-&ref sqlite3:statement** (*) ptr) db)]
             [else
              (case (number->sqlite3:status e)
                #;[(busy)
                 (let ([h (database-busy-handler db)])
                   (cond
                    [(and h (h db retries))
                     (retry (fx+ retries 1))]
                    [else
                     ((abort-sqlite3-error 'prepare db db sql) e)]))]
                [else
................................................................................
      [else
       enable?])]))

 (define (sqlite3-trace db func data)
   (check-database 'sqlite3-trace db)
   (let ([f (foreign-procedure "sqlite3_trace" (sqlite3:database* void* void*) void)])
     (f (database-addr db) func data)))

 (define (sqlite3-config-log func data)
   ;(check-database 'sqlite3-config-log db)
   (let ([f (foreign-procedure "sqlite3_config" (int void* void*) void)])
     (f 16 func data)))

 (record-writer
  (type-descriptor database)
  (lambda (r p wr)
    (wr
     (if (database-ptr r)
         "#<sqlite3:database>"
         "#<sqlite3:database zombie>")
     p)))

 ) ; library sqlite3