5

I want to print the SQL statements generated on INSERT, UPDATE, DELTE queries send by sqlalchemy db session. I am using sqlalchemy as ORM and sqlite3 database. I know I can print the SQL of a query using this.

Like it is shown below

INSERT INTO Table (id) VALUES (?)
(1)

But I want to print the query and parameter in one line like this

INSERT INTO Table (id) VALUES (1);

I only want to print the INSERT, UPDATE and DELETE queries.

How can I do this?

2
  • 1
    check this out stackoverflow.com/a/23835766/7853322 Commented Oct 27, 2017 at 18:49
  • 3
    hi @brddawg I tried this. It requires the db_session.query object. But for insert/update queries I am using db_session.add(object_to_be_saved) and for delete queries I am using db_session.delete(object_to_be_saved). Also when I tried to do db_session.query.statement I was getting error as object has no attribute 'statement' Commented Oct 28, 2017 at 5:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.