gpt4 book ai didi

grails - 使用MYSQL时Grails条件查询失败并出现语法错误

转载 作者:行者123 更新时间:2023-12-02 15:55:24 27 4
gpt4 key购买 nike

当应用程序连接到MYSQL实例时,我有一个查询失败。使用H2内存数据库时,查询工作正常。所有其他查询都可以使用MYSQL正常工作。

错误消息:您的SQL语法有错误;检查与MySQL服务器版本相对应的手册,以在第1行的')'附近使用正确的语法

Controller Action :

def index() {
def currentUser = currentUser()
def peopleFollowing = currentUser.following
def c = Post.createCriteria()
def postList = c.list {
'in' ("user", peopleFollowing)
'order' "dateCreated", "desc"
}
[postList:postList, user : currentUser, peopleFollowing:peopleFollowing]
}

当我删除in子句时,查询针对MYSQL运行。因此,似乎是:“in”(“用户”,peopleFollowing)引起了问题。我认为问题在于,这是MYSQL保留字。我试过在周围使用反引号,但一直收到语法错误...?
class Post {


String content
Date dateCreated
User user


static belongsTo = [user : User]

static hasMany = [postComments: PostComment]

static constraints = {
content (blank: false)
}

static mapping = {
sort dateCreated:"desc"
content type:"text"
postComments sort:"dateCreated", order:"desc"
}

}

类Post {
字符串内容
日期dateCreated
用户用户
静态归属于= [用户:用户]
静态hasMany = [postComments:PostComment]
静态约束= {
内容(空白:false)
}
静态映射= {
排序dateCreated:“desc”
内容类型:“文本”
postComments排序:“dateCreated”,顺序:“desc”
}
}
类Post {
字符串内容
日期dateCreated
用户用户
静态归属于= [用户:用户]
静态hasMany = [postComments:PostComment]
静态约束= {
内容(空白:false)
}
静态映射= {
排序dateCreated:“desc”
内容类型:“文本”
postComments排序:“dateCreated”,顺序:“desc”
}
}

最佳答案

我通过这样做来解决了这个问题:

def postList = Post.findAllByUserInList( peopleFollowing )

关于grails - 使用MYSQL时Grails条件查询失败并出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34168699/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com