susja
susja

Reputation: 321

SQL statement does not have effect using pyodbc

I am running python script on the server that should update existing table 'loading_log' using ODBC connection.

The issue is that my script does not have any effect on the table in Database i.e. it does not delete records and does not insert new records.

At the same time I don't see any errors thrown after the execution. If I run the same SQL query from Desktop using the same credentials it works fine.

My question: Why it does not work inside python script?

Here's an excerpt from my code:

curs.execute('''
        delete from loading_log
    ''')

    #
    #record loaded record ids into loading_log table
    #

    #logging.info('insert laoded record id data into loading_log table')
    curs.execute('''
    insert into loading_log (catalog_sample_events_id,ShippingId)
    select top 500
    cs.catalog_sample_events_id,
    cs.shipping_id ShippingId
    from catalog_sample_events cs
    join event_type et on et.event_type_id = cs.event_type_id
    join event_source es on es.event_source_id = cs.event_source_id
    join etl_status esi on esi.etl_status_id = cs.etl_status_id
    where cs.catalog_sample_events_id > ?
    order by cs.catalog_sample_events_id
    ''', max_id)

Upvotes: 0

Views: 97

Answers (1)

Chris
Chris

Reputation: 23179

You need to commit the transaction:

curs.commit()  

or tell pyodbc to use autocommit mode. See pyodbc wiki for more details.

Upvotes: 2

Related Questions