3

这是我的代码:

(defn tbl_email_data
  {:new-acc  1
   :email "test_get_account_3@mode-test.co"
   :token "pa55P0rt"})

(defn create-online-test-data[data_values]
   (with-connection
      (with-transaction []
         ;Insert tbl_email
         (execute-sql (format "Insert into tbl_email (email, acc_no, pass) values          ('%s', %d, '%s')" data_values :email data_values :new-acc data_values :token))
  )))

尝试运行它时,我收到以下错误:

com.mode.test.core.testOnline=> (create-online-test-data tbl_email_data)
java.lang.Exception: 事务回滚: d != clojure.lang.Keyword (NO_SOURCE_FILE:0)

4

1 回答 1

1

你的电话format没有做你认为它正在做的事情。您将地图和关键字作为参数传递,这将导致format将地图的字符串表示形式插入 SQL 字符串(并忽略最后三个参数)。

试试这个:

(format "Insert into tbl_email (email, acc_no, pass) values
         ('%s', %d, '%s')"
        (data_values :email)
        (data_values :new-acc)
        (data_values :token))

或者,更惯用一点:

(apply format
       "Insert into tbl_email (email, acc_no, pass) values
        ('%s', %d, '%s')"
      (map data_values [:email :new-acc :token]))
于 2013-03-21T15:54:59.767 回答