【问题标题】:OrientDB SQL function parameter values are not accessible inside the function bodyOrientDB SQL 函数参数值在函数体内不可访问
【发布时间】:2016-02-03 14:24:25
【问题描述】:

我尝试在 OrientDB 中编写一个 SQL 函数来插入表 Feature。函数体如下所示,它接受两个参数w 和t。

insert into Feature (weight, title) values (w, t) return @rid

当我使用指定为12 和some title 的参数执行此函数时,我得到的响应是这样的。

[ { "@type": "d", "@rid": "#21:24135", "@version": 1, "@class": "Feature", "weight": null, "title": null } ]

看起来好像没有设置参数,因此值12 和some title 在函数中不可见。我还尝试在函数体中的参数名称前使用$ 之类的特殊字符(将参数值称为$t,而不是t),但仍然没有走运。

【问题讨论】:

  • 嗨 Raajerc,你能发布整个函数吗?你是如何声明 wieght 和 title 的?
  • 嗨 LucaS,这是完整的功能。我没有特别声明任何变量。我们必须这样做吗?

标签: sql function orientdb


【解决方案1】:

你可以使用这个查询

insert into Feature (weight, title) values (:w, :t) return @rid

【讨论】:

  • 发挥了魅力。但不幸的是,我已经放弃并手动进行了添加。添加所有数据后才看到这个答案。
【解决方案2】:

你能看到:“titile”:null 不是“title”,所以这个插入到 Feature (weight, title) 值 (w, t) 返回@rid,它找不到我认为要分配的属性

【讨论】:

    【解决方案3】:

    我认为你执行了命令

    insert into Feature (weight, title) values (w, t) return @rid

    但是您在传递参数 w 和 t 时忘记插入引号。 试试这个代码:

    var g=orient.getGraph();
    var ins = g.command('sql','insert into Feature (weight, title) values ('+w+', "'+t+'")');
    return ins;
    

    输出:

    [
        {
            "@type": "d",
            "@rid": "#12:-2",
            "@version": 0,
            "@class": "Feature",
            "weight": 14,
            "title": "sometitle",
            "@fieldTypes": "weight=d"
        }
    ]
    

    希望对你有帮助

    【讨论】:

    • 我尝试在浏览器本身上运行它,看到这个答案后,我也尝试在引号中包含传递的参数。但我仍然没有在字段weight 或title 上获得任何值
    • 我发了截图here
    猜你喜欢
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多