Remove db as a global variable

There's no need for it to be a global variable.
This commit is contained in:
Tom Willemsen 2012-12-28 01:46:15 +01:00
parent f71c70ca7b
commit 57f06ec8c9

View file

@ -15,11 +15,11 @@
(format #t "~a~% ~a~% ~a~% ~a~%~%" (string-no-null name) (string-no-null description)
(string-no-null url) (seconds->string seconds)))
(define (add-tag name)
(define (add-tag db name)
(execute db "INSERT INTO tag VALUES (?)" name)
(last-insert-rowid db))
(define (add-bookmark url name description tags)
(define (add-bookmark db url name description tags)
(execute db "INSERT INTO bookmark VALUES (?, STRFTIME('%s'), ?, ?)"
url name description)
(let ((bookmark-id (last-insert-rowid db)))
@ -29,7 +29,7 @@
(set! tag-id (first-result db "SELECT rowid FROM tag WHERE name = ?" tag))
(exn (exn sqlite3)
(if (eq? (get-condition-property exn 'sqlite3 'status) 'done)
(set! tag-id (add-tag tag))
(set! tag-id (add-tag db tag))
(signal exn))))
(execute db "INSERT INTO bookmark_tag VALUES (?, ?)"
bookmark-id tag-id)))
@ -41,17 +41,16 @@
(string= (substring str 0 8) "https://"))))
(define (main args)
(if (null? args)
(for-each-row print-row db "select * from bookmark")
(cond
((url-string? (car args))
(with-transaction
db (lambda () (add-bookmark (car args) (cadr args) (caddr args) (cdddr args)) #t)))
(else
(format #t "Unrecognized option: ~a~%" (car args))))))
(let ((db (open-database (data-file "linkwave.db"))))
(if (null? args)
(for-each-row print-row db "select * from bookmark")
(cond
((url-string? (car args))
(with-transaction
db (lambda () (add-bookmark db (car args) (cadr args) (caddr args) (cdddr args)) #t)))
(else
(format #t "Unrecognized option: ~a~%" (car args)))))
(define db (open-database (data-file "linkwave.db")))
(finalize! db #t)))
(main (command-line-arguments))
(finalize! db #t)