From 671d0fdcc71b21b80a7d3253ea542ace1a67f168 Mon Sep 17 00:00:00 2001 From: Tom Willemsen Date: Fri, 22 Mar 2013 02:23:42 +0100 Subject: [PATCH] Add search command --- clark.lisp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/clark.lisp b/clark.lisp index cbb0ec5..197b208 100644 --- a/clark.lisp +++ b/clark.lisp @@ -11,7 +11,9 @@ ("help" "Display this help and exit" "help") ("version" "Output version information and exit" - "version")) + "version") + ("search" "Search for a name or tag" + "search ")) "Help texts for commands.") (defconstant *version* "0.1.0" @@ -110,6 +112,23 @@ BM should be a list containing the url and name of the bookmark." (destructuring-bind (url name) bm (format t "~A~%~A~%~%" url name))) +(defun search-command (args) + "Search the database for a match." + (map + nil (lambda (bm) + (destructuring-bind (url name description) bm + (format t "~A~% ~A~% ~A~%~%" url name description))) + (execute-to-list + *db* (concatenate 'string + "SELECT url, name, description " + "FROM bookmark " + "WHERE name LIKE ? " + "OR ? IN (SELECT name " + "FROM tag " + "JOIN bookmark_tag ON (tag_id = tag.rowid) " + "WHERE bookmark_id = bookmark.rowid)") + (format nil "%~A%" (car args)) (car args)))) + (defun version-command (args) "Display clark's version number." (declare (ignore args))