简体   繁体   English

如何在密码查询中引入参数?

[英]How to introduce parameters in a cypher query?

I have this cypher query in a Python program: 我在Python程序中有以下密码查询:

prevNode = graph_db.data("OPTIONAL MATCH (n:Node) WHERE n.property = {param} RETURN n")

The line of code above gives this error: 上面的代码行给出了此错误:

'py2neo.database.status.ClientError: Expected a parameter named param' 'py2neo.database.status.ClientError:需要一个名为param的参数'

param is well defined at this point of the program because I print it a line before executing the query. 在程序的这一点上,param定义得很好,因为我在执行查询之前将其打印了一行。

I have tried to put the value in the query instead of the parameter, like this: 我试图将值而不是参数放在查询中,如下所示:

prevNode = graph_db.data("OPTIONAL MATCH (n:Node) WHERE n.property = '1234' RETURN n")

And worked well. 并运作良好。

Does anyone knows where is the mistake? 谁知道错误在哪里?

Thanks in advance. 提前致谢。

You didn't pass any substitution variables into the function. 您没有将任何替代变量传递给函数。

graph_db.data("OPTIONAL MATCH (n:Node) WHERE n.property = {param} RETURN n", param='1234')

You can also explicitly pass in the locals() dictionary; 您也可以显式传递locals()字典; this will use any local variables you have defined of the appropriate names: 这将使用您定义的具有适当名称的任何局部变量:

graph_db.data("OPTIONAL MATCH (n:Node) WHERE n.property = {param} RETURN n", **locals())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM