If i want to run a GqlQuery with a variable i've set is that possible?

for example:

myNumber = 4

myResult = db.GqlQuery("SELECT * from myData WHERE filter = myNumber")

this results in:

Parse Error: Invalid WHERE condition at symbol

Am i going about this all wrong? Thanks for your time.

有帮助吗?

解决方案

According to The Google Appengine Documentation, your code might look like this:

myNumber = 4
myResult = db.GqlQuery("SELECT * FROM myData WHERE filter = :num", num=myNumber)

or

myNumber = 4
myResult = db.GqlQuery("SELECT * FROM myData WHERE filter = :1", myNumber)

depending on whether you want to use a named or positional variable.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top