How in the world do I pass a string variable into GQL with python?? I can do it fine in SQL but it just isn't working. here is what I have:
personalposts = db.GqlQuery("select * from PersonalPost where user_id = %s order by created desc limit 30" % user_id)
This has been killing me but should be really simple I feel.
Thanks!
This should work:
personalposts = db.GqlQuery("select * from PersonalPost where user_id =:1 order by created desc limit 30",user_id)
GqlQuery
syntax examples:
q = GqlQuery("SELECT * FROM Song WHERE composer = 'Lennon, John'")
q = GqlQuery("SELECT __key__ FROM Song WHERE composer = :1", "Lennon, John")
q = GqlQuery("SELECT * FROM Song WHERE composer = :composer", composer="Lennon, John")
source: https://developers.google.com/appengine/docs/python/datastore/gqlqueryclass
parameters can be bound by position or name, look at the GqlQuery class documentation for more info.
So you could do
personalposts = db.GqlQuery("select * from PersonalPost where user_id = :1 order by created desc limit 30", user_id)
or
personalposts = db.GqlQuery("select * from PersonalPost where user_id = :id order by created desc limit 30", id = user_id)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With