2

I have this code (using sqlalchemy):

 session = self._new_session(database_id=dbname)
 with session.begin():
    result_proxy = session.execute(sql_query, sql_params)

where

sql_query = 'select * from t_client where id = :id'
sql_params = {'id': 5131}

How may I see the actual query before executing without using regular expression? I mean something like this:

select * from t_client where id = 5131
insomniaqq
  • 61
  • 1
  • 5
  • Output the two variables. Or mail them to yourself. You'll have to do some minor editing to get a useable sql command but it might be good enough. – Dan Bracuk Feb 16 '16 at 15:50
  • thanks, I understand it. But how to get the useable sql query with params already in? I mean if there is the easier way to get this 'select * from t_client where id = 5131' from that 'query = 'select * from t_client where id = :id' query_params = {'id': 5131}' rather than use regex? – insomniaqq Feb 16 '16 at 15:55
  • :\w+ i may use this, but maybe I can get result query from sa? – insomniaqq Feb 16 '16 at 20:13
  • 1
    An important thing to note is that the query `select * from t_client where id = :id` is at no point converted to `select * from t_client where id = 5131`. Instead, the parameters are sent separately as part of the underlying RDBMS-specific protocol in order to mitigate SQL injection attacks. – univerio Feb 16 '16 at 20:36
  • oh, thanks for answer! 'the parameters are sent separately' was the main thing I was interested in. – insomniaqq Feb 17 '16 at 10:55

0 Answers0