rlm@0: (ns coderloop.hello-sql rlm@0: (:refer-clojure :only []) rlm@0: (:require rlm.ns-rlm rlm.light-base)) rlm@0: (rlm.ns-rlm/ns-clone rlm.light-base) rlm@0: (use 'coderloop.utils) rlm@0: rlm@0: (use 'clojure.contrib.sql) ;;' satisfy prettify rlm@0: (import 'org.gjt.mm.mysql.Driver) rlm@0: rlm@0: (def *port* 3306) rlm@0: rlm@0: (def *host* "localhost") rlm@0: rlm@0: (defn doit [] rlm@0: (let [db-host "localhost" rlm@0: db-port *port* rlm@0: db-name "testdb"] rlm@0: (def db {:classname "com.mysql.jdbc.Driver" rlm@0: :subprotocol "mysql" rlm@0: :subname (str "//" db-host ":" db-port "/" db-name) rlm@0: :user "root" rlm@0: :password "sql1005025"}) rlm@0: (with-connection db rlm@0: (with-query-results rs ["select * from hello_data"] rlm@0: (println rs))))) rlm@0: rlm@0: rlm@0: (defn read-hello-data [[username password db-name]] rlm@0: (let [db-host *host* rlm@0: db-port *port*] rlm@0: (def db {:classname "com.mysql.jdbc.Driver" rlm@0: :subprotocol "mysql" rlm@0: :subname (str "//" db-host ":" db-port "/" db-name) rlm@0: :user username rlm@0: :password password}) rlm@0: (with-connection db rlm@0: (with-query-results rs ["select * from hello_data"] rlm@0: (vec rs))))) rlm@0: rlm@0: rlm@0: rlm@0: (defn print-result [args] rlm@0: (let [results (read-hello-data args)] rlm@0: (println rlm@0: (apply str (interpose " " (map :text results)))))) rlm@0: rlm@0: rlm@0: (defn slick-test [] (read-hello-data ["root" "sql1005025" "testdb"])) rlm@0: rlm@0: rlm@0: (if (command-line?) rlm@0: (print-result *command-line-args*)) rlm@0: rlm@0: ;; rs will be a sequence of maps, rlm@0: ;; one for each record in the result set. rlm@0: