Add simple searching

This commit is contained in:
Tom Willemsen 2013-02-02 16:53:16 +01:00
parent 1d51bacd51
commit d5dbe8ed27

View file

@ -74,6 +74,18 @@
bookmark-id tag-id)))
tags)))
(define (search-bookmarks db str)
(for-each-row print-row db #<<END
SELECT *
FROM bookmark
WHERE name LIKE ?
OR ? IN (SELECT name
FROM tag
JOIN bookmark_tag ON (tag_id = tag.rowid)
WHERE bookmark_id = bookmark.rowid)
END
(string-append "%" str "%") str))
;; Is STR a URL? Very naïve, assumes all URLs begin with either
;; `http://' or `https://', should be improved.
(define (url-string? str)
@ -92,7 +104,7 @@
"--help, -h Display this help and exit~%"
"--version, -v Output version information and exit~%")))
;; Parse command-line arguments
;; Parse "other" command-line arguments
(define (handle-regular-args args)
(do ((arg (car args) (and (not (null? args))
(car args))))
@ -120,6 +132,8 @@
db (lambda ()
(add-bookmark
db (car args) (cadr args) (caddr args) (cdddr args)) #t)))
((string= (car args) "search")
(search-bookmarks db (cadr args)))
(else
(handle-regular-args args)))
(finalize! db #t)))