0

I need to know the way of getting the SQLAlchemy query printed with values.

I can be able to print the query which is getting processed, But it is not showing the values instead it just showing the field name itself.

SELECT recordsets.id AS recordsets_id, recordsets.version AS recordsets_version
FROM recordsets 
WHERE recordsets.domain_id = :domain_id_1 
AND recordsets.tenant_id IN (:tenant_id_1, :tenant_id_2) 
AND recordsets.name IN (:name_1, :name_2)

So instead of :name_1, :name_2 or :tenant_id_1, :tenant_id_2 I need to see the values itself.

asked Nov 16, 2015 at 14:33
0

1 Answer 1

0

When you're creating your engine you have the possibility to turn on logging, by setting echo on True. That will print all queries with their parameters.

Example:

engine = create_engine("mysql://scott:tiger@hostname/dbname",
 encoding='latin1', echo=True)

See: http://docs.sqlalchemy.org/en/rel_1_0/core/engines.html#engine-creation-api

For your example the output will look like:

2015年11月16日 15:50:25,137 INFO sqlalchemy.engine.base.Engine SELECT recordsets.id AS recordsets_id, recordsets.version AS recordsets_version
FROM recordsets 
WHERE recordsets.domain_id = :domain_id_1 
AND recordsets.tenant_id IN (:tenant_id_1, :tenant_id_2) 
AND recordsets.name IN (:name_1, :name_2)
2015年11月16日 15:50:25,137 INFO sqlalchemy.engine.base.Engine {'domain_id_1': 'THE actual domain id', 'tenant_id_1': 234, 'tenant_id_2': 456, 'name_1': 'your first name', 'name_2': 'your second example name'}
answered Nov 16, 2015 at 14:49
Sign up to request clarification or add additional context in comments.

3 Comments

I am in middle of development phase , I can't be able to go back to engine creation as you specified.What can I do now?
you're probably calling sqlalchemy.create_engine(...) somewhere in you're code. You could just adjust the parameters. Do you use a logger? Then you could try to use this: stackoverflow.com/questions/2950385/… (Look at the accepted answer.)
just enable logging using standard python logging module: logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) to enable logging any later time in your code after engine has been created. Here I assume that you configured logging at the start of your application already.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.