更新值未在hsqldb上生成实际更新

时间:2022-04-16 22:47:09

I'm new to clojure. Have been playing with jdbc using hsqldb.

我是clojure的新手。一直在使用hsqldb玩jdbc。

Did this function to update table "persona" where the field "cedula" is the primary key

这个功能是否更新了“cedula”字段是主键的表“persona”

(defn update [cedula x]
(sql/with-connection common/database
    (sql/update-values :persona
        ["cedula=?" cedula] x)))

Ran this in REPL

在REPL中这个

(per/update 111 {:cedula 122 :nombre "Raul" :cargo "mm"})

But after that if I go to the .log file in the DB I see that it does a delete and then an insert.

但之后,如果我转到DB中的.log文件,我会看到它执行删除然后插入。

/*C15*/SET SCHEMA PUBLIC
CONNECT USER SA
SET AUTOCOMMIT FALSE
DELETE FROM PERSONA WHERE CEDULA=111
INSERT INTO PERSONA VALUES(122,'Raul','mm')
COMMIT
SET AUTOCOMMIT TRUE
DISCONNECT

Is that normal?

这是正常的吗?

1 个解决方案

#1


2  

This is the code for update-values:

这是update-values的代码:

(defn update-values
  "Updates values on selected rows in a table. where-params is a vector
  containing a string providing the (optionally parameterized) selection
  criteria followed by values for any parameters. record is a map from
  strings or keywords (identifying columns) to updated values."
  [table where-params record]
  (let [[where & params] where-params
        column-strs (map as-identifier (keys record))
        columns (apply str (concat (interpose "=?, " column-strs) "=?"))]
    (do-prepared
      (format "UPDATE %s SET %s WHERE %s"
              (as-identifier table) columns where)
      (concat (vals record) params))))

As you can see, there's absolutely no way it will generate anything but a UPDATE, as it ought to. So what's actually happening?

正如你所看到的,除了应该更新之外,绝对没有办法产生任何东西。那真正发生了什么?

From the HSQLDB docs:

从HSQLDB文档:

As HyperSQL logs the DDL and DML statements in the .log file, this file can be used to check what is being sent to the database. Note that UPDATE statements are represented by a DELETE followed by an INSERT statement.

由于HyperSQL在.log文件中记录DDL和DML语句,因此该文件可用于检查发送到数据库的内容。请注意,UPDATE语句由DELETE后跟INSERT语句表示。

So the HSQLDB log is simply writing a DELETE and INSERT, even though the query being executed is really an UPDATE.

因此HSQLDB日志只是编写DELETE和INSERT,即使正在执行的查询实际上是UPDATE。

#1


2  

This is the code for update-values:

这是update-values的代码:

(defn update-values
  "Updates values on selected rows in a table. where-params is a vector
  containing a string providing the (optionally parameterized) selection
  criteria followed by values for any parameters. record is a map from
  strings or keywords (identifying columns) to updated values."
  [table where-params record]
  (let [[where & params] where-params
        column-strs (map as-identifier (keys record))
        columns (apply str (concat (interpose "=?, " column-strs) "=?"))]
    (do-prepared
      (format "UPDATE %s SET %s WHERE %s"
              (as-identifier table) columns where)
      (concat (vals record) params))))

As you can see, there's absolutely no way it will generate anything but a UPDATE, as it ought to. So what's actually happening?

正如你所看到的,除了应该更新之外,绝对没有办法产生任何东西。那真正发生了什么?

From the HSQLDB docs:

从HSQLDB文档:

As HyperSQL logs the DDL and DML statements in the .log file, this file can be used to check what is being sent to the database. Note that UPDATE statements are represented by a DELETE followed by an INSERT statement.

由于HyperSQL在.log文件中记录DDL和DML语句,因此该文件可用于检查发送到数据库的内容。请注意,UPDATE语句由DELETE后跟INSERT语句表示。

So the HSQLDB log is simply writing a DELETE and INSERT, even though the query being executed is really an UPDATE.

因此HSQLDB日志只是编写DELETE和INSERT,即使正在执行的查询实际上是UPDATE。