PS: for postgresql, it's nasty ... placeholders are in "python" notation, so

db.executesql('select * from %s', placeholders=('example'))

or 

db.executesql('select * from %(tablename)s', placeholders={'tablename' : 
'example'})

works.

If payback types is passed as a string, you need to add a % to retain the 
quoted template, I guess

payback_types = ('s','p')
      query_string = """
            select sum(happen_amount) from cash_journal 
            where distributor_id = 1
            and transaction_type in %(types)s
            and extract(epoch from (%%s - happen_time)) < %%s;""" % {
                'types': str(payback_types)
            }
        
        lockAmount = self.db.executesql(query_string, placeholders=(now, 
seconds))
or

payback_types = ('s','p')
      query_string = """
            select sum(happen_amount) from cash_journal 
            where distributor_id = 1
            and transaction_type in %(types)s
            and extract(epoch from (%%(now)s - happen_time)) < 
%%(seconds)s;""" % {
                'types': str(payback_types)
            }
        
        lockAmount = self.db.executesql(query_string, 
placeholders=dict(now=now, seconds=seconds))

should work as intended.


Reply via email to