(快速參考)

executeUpdate

目的

使用 DML 風格操作 更新資料庫

範例

Account.executeUpdate("delete Book b where b.pages > 100")

Account.executeUpdate("delete Book b where b.title like ?",
                      ['Groovy In Action'])

Account.executeUpdate("delete Book b where b.author=?",
                      [Author.load(1)])

Account.executeUpdate("update Book b set b.title='Groovy In Action'" +
                      "where b.title='GINA'")

Account.executeUpdate("update Book b set b.title=:newTitle " +
                      "where b.title=:oldTitle",
                      [newTitle: 'Groovy In Action', oldTitle: 'GINA'])

說明

GORM 沒有提供 deleteAll 方法,因為刪除資料必須小心執行。若要刪除資料,您可以使用 executeUpdate。基本語法為

Book.executeUpdate(String query)
Book.executeUpdate(String query, List positionalParams)
Book.executeUpdate(String query, Map namedParams)

參數

  • query - 包含 DML 風格操作的 HQL 查詢

  • positionalParams - 位置參數化 HQL 查詢的 List

  • namedParams - 命名參數化 HQL 查詢的 Map