arrays - 在Groovy脚本上查看SQL保存

标签 arrays json grails groovy

我有一个由于某些错误而无法插入的 Controller 。我想查看SQL或什至错误,但我的SSTS IDE中的控制台均未显示。有没有办法让我看到它正在创建的SQL并强制它向控制台吐出错误?我的Database.groovy配置中有loggingSql = true

class OrdersController {
    def save = {
        def input = request.JSON

        def order = new Orders(input)
        // I want to see the SQL output of this save
        order.save(flush:true)

    }   

}

最佳答案

很可能您还没有达到任何SQL的阶段。可能发生的情况是您的Orders没有通过验证,因此在数据库运行之前就失败了。

您永远不应有一个简单的foo.save()-它应该永远是

if(foo.save()) {
    // save successful
} else {
    // save failed
}


foo.save(failOnError: true)

(如果验证失败,flush: true无效。)

documentation goes into further detail,包括有关如何查看哪些字段失败的示例。

关于arrays - 在Groovy脚本上查看SQL保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9781979/

相关文章:

jquery - 将 "this"添加到 jQuery 中 "each"的父堆栈

javascript - Angular.forEach 和 .find

grails - 在 Grails 中使用刻录图像插件时如何居中对齐水印

Python - 通过json解析在Cloud Storage中创建Json文件

json - 在Go中将类似JSON的字符串转换为struct

tomcat - 将 Grails 部署到子上下文路径

tomcat - Grails 3.1.4 应用程序部署错误

arrays - Dart :无法将新列表添加到2D列表中

c - 初始化结构数组 - {NULL} 与 {}

javascript - AngularJS 的 .config()