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

refsetMapは、マップではなくベクトルをラップします。このkeys関数は、ベクトルではなく、マップから一連のキーを返します。マップをラップするには、setMapを変更する必要があります。

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