Hello.
First of all I'd like to apologize if this is not the right group to
post this.
I have a portion of the code that gives me an error, while I think it
shouldn't. I'm trying to construct string for eval function that will
return a variable with value of or_ sqlalchemy parameter. I'm not really
sure if what I'm trying to achieve should be done differently. I have a
friends_list which is basically list of Friend records. I want to select
Posts like it's shown below.
Unfortunately eval(evalstr) gives me syntax error. The error is on
eval(evalstr) function which states *<type 'exceptions.SyntaxError'>:
invalid syntax (<string>, line 1)*. I think this is because of
model.Post.account.id, so or_() cannot follow the relation Post.account.
I couldn't think of a better idea for this and quite frankly I'm not an
sql expert, so please forgive if I'm asking stupid questions.
Is it a bug in elixir or am I doing something wrong? If there's a way
for doing this in pure sql, could someone please tell me how can this be
achieved? I'd greatly appreciate it.
Thanks a lot.
Karol Tomala
--- cut ---
evalstr = 'or_clause = or_('
for i in (0, friends_count - 1):
friend = friends_list[i]
if i < friends_count - 1:
sep = ', '
else:
sep = ''
evalstr += 'model.Post.account.id == %d%s' %
(friend.friend.id, sep)
evalstr += ')'
eval(evalstr)
post_obj_list = model.Post.query().filter(
or_(
and_(model.Post.account == account_obj,
model.Post.parent == None),
and_(or_clause, model.Post.visibility == 0)
)
).order_by(model.Post.postdate.desc()).limit(10).all()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---