0

我正在尝试构建一个类似于 SQL 的函数:

UPDATE Persons SET Address=Martin20, City=Miami WHERE LastName=Darmon AND FirstName=Gilad

我已将 SET 和 Where 解析为地图和列表。
现在我想更新我拥有的表。但是我遇到了一个错误

Exception in thread "main" setMap #<Ref@6bad186f: [:Address Martin20 :City Miami]>
whereList #{0}
java.lang.ClassCastException: clojure.lang.Keyword cannot be cast to java.util.Map$Entry
    at clojure.lang.APersistentMap$KeySeq.first(APersistentMap.java:132)
    at clojure.lang.RT.first(RT.java:559)
    at clojure.core$first.invoke(core.clj:55)
    at ClojureSQL$UpdateRecord.invoke(project.clj:205)
    at ClojureSQL$UpdateTable.invoke(project.clj:253)
    at ClojureSQL$Execute.invoke(project.clj:285)
    at ClojureSQL$eval1340.invoke(project.clj:312)

这是为更新函数设置参数的函数:

;UpdateTable function
(defn UpdateTable [updateQuery]
  "The UPDATE statement is used to update existing records in a table"
  (println "UPDATE ")
  (let [SpecificGetTableName (CreateGetTableNameFunc #"UPDATE ([_0-9a-zA-Z]+)") 
        tableName (SpecificGetTableName updateQuery)
        whereList (ListRecordsMatchConditions updateQuery tableName)        ; return the row numbers in which we need to update 
        setMap    (GetValuesFromSetCommand updateQuery)]
    (UpdateRecord tableName whereList setMap)
  )
)

该错误在doseq函数中:

;update specific table records (from whereList) with new values (from setMap)
(defn UpdateRecord [tableName whereList setMap]
  "Insert values into table in order of keys / columns"
  (println "setMap" setMap)
  (println "whereList" whereList)
  (let [tableRef (get (deref dataBase) tableName)]        
    (doseq [curKey (keys @setMap) i whereList]         ; <-here is the BUG

       (dosync (alter (tableRef curKey) assoc i val))  ; perfrom thread safe insert of value to column
    )
    (println tableRef) 
  )
)
4

1 回答 1

1

您的setMapref 包装了一个矢量,而不是一个地图。该keys函数从映射返回一个键序列,而不是一个向量。您需要更改 setMap 以包装地图:

(ref {:Address "Martin20" :City "Miami"})
于 2013-02-24T14:24:28.830 回答