mysql - ColdFusion/Railo 脚本中出现 SQL 错误 "new query()"

标签 mysql sql railo cfml

当我尝试插入时,我从 Railo 收到了一个非常无用的 SQL 错误。我认为这与我传递给它的 :param 值有关;当我把它们拿出来并用一个简单的字符串替换它们时,它就起作用了。

这是我的代码(位于 CFC 内):

local.registerUserQuery = new query();
            local.registerUserQuery.setDatasource("popwave");
            local.registerUserQuery.setSQL("

                INSERT INTO users (

                    userUUID,
                    userName,
                    userPassword,
                    userEmail,
                    userToken,
                    userCreated,
                    userBiography,
                    userCommentPoints,
                    userLinkPoints,
                    userImageID,
                    userRemoved,
                    userCategoriesOwner,
                    userCategoriesSubscribed

                )

                VALUES (

                    '#createUUID()#' , 
                    :userName , 
                    :userPassword , 
                    :userEmail , 
                    '#local.token#' , 
                    #createODBCDate(now())# , 
                    '' , 
                    0, 
                    0, 
                    0, 
                    0, 
                    0, 
                    0 

                )

            "); 

            local.registerUserQuery.setName("registerUser");

            local.registerUserQuery.addParam( name="userName", value="#arguments.userName#", cfsqltype="cf_sql_varchar" ); 
            local.registerUserQuery.addParam( name="userPassword", value="#arguments.userPassword#", cfsqltype="cf_sql_varchar" ); 
            local.registerUserQuery.addParam( name="userEmail", value="#arguments.userEmail#", cfsqltype="cf_sql_varchar" );

            local.registerUserQuery.execute();

我一生都无法理解为什么这会引发错误!我需要能够使用:param。

这是 Railo 错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 49

检查该行号似乎没有指向任何相关内容。该查询位于第 200 行!而且,如前所述...当我替换这些 :param 值时,SQL 似乎可以工作。

我在这里确实做错了什么吗?拔我的头发!

谢谢, 迈克尔。

编辑:

忘了说了,Railo 版本是:

Railo 3.3.1.000 Error (database)

最佳答案

听起来您遇到了问题 RAILO-1281应在 3.3.1.005 中修复。

"RAILO-1281: When doing a query INSERT with CFScript "new query()" and using a cfqueryparam with addParam(), the end ")" is removed"

顺便说一句,您应该对所有动态值使用 addParam

关于mysql - ColdFusion/Railo 脚本中出现 SQL 错误 "new query()",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9298032/

相关文章:

php - 导致大量输出的mysql查询使php页面变为空白

MySQL 意外返回 "WHERE integer_column = ' string_value' 的结果

coldfusion - Railo web.cfm 显示 IIS 404

php - 如何在 SQL 中使用 bool 值

mysql - hadoop集群中的MySQL安装过程

mysql - 具有相同多列的 SQL 搜索值

sql - 执行 SQL 语句时,可以在过滤之前应用标量函数吗?

Railo 服务器将加号 (+) 转换为空格

xml - 从 XSLT 中抛出异常

php - 如何对从 phpMyAdmin 获取数据的 ListView 进行排序