3

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?

A J Brockberg
  • 563
  • 2
  • 5
  • 18
  • 1
    check this out https://stackoverflow.com/a/23835766/7853322 – brddawg Oct 27 '17 at 18:49
  • 1
    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' – A J Brockberg Oct 28 '17 at 05:34

0 Answers0