It is currently Wed May 23, 2012 2:46 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: select with string placeholders
PostPosted: Thu Jul 21, 2011 12:02 pm 
Offline

Joined: Tue Dec 21, 2010 7:14 pm
Posts: 22
One silly question..

Hi I'm trying to write a select function with two string placeholders and I'm not able to write it..

I'm able to get a good result for the select with:

ids = self.pool.get('payment.type').search(cr,uid,[('name','ilike',value)], context=context)
if ids:
cr.execute('SELECT l.id ' \
'FROM account_move_line l, account_invoice i, account_voucher j ' \
'WHERE (l.move_id = j.move_id AND j.payment_type = ' + str(ids[0]) + ') OR (l.move_id = i.move_id AND i.payment_type in (%s))' % (','.join(map(str, ids))))
res = cr.fetchall()

But it's not a good code...

I want to write something as:

ids = self.pool.get('payment.type').search(cr,uid,[('name','ilike',value)], context=context)
if ids:
cr.execute('SELECT l.id ' \
'FROM account_move_line l, account_invoice i, account_voucher j ' \
'WHERE (l.move_id = j.move_id AND j.payment_type in (%s)) ') OR (l.move_id = i.move_id AND i.payment_type in (%s))' % (','.join(map(str, ids))))
res = cr.fetchall()

But, of course, I get: TypeError: not enough arguments for format string

How can I pass the value for both placeholders?. I'm not able to find the correct syntax..

Thanks in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP