-3

I'm using SQLAlchemy and MSSQL 2019 with triggers (insert/update) can't remove .

engine_new = create_engine('mssql+pymssql://***:***@***/***', implicit_returning=False)
Session_new = sessionmaker(bind=engine_new)
session_new = Session_new()
metadata_new = MetaData()
metadata_new.reflect(bind=engine_new)

partsTable = metadata_new.tables['parts']

def addPart(dataArt, manId)
# rowInsertStmt = insert(partsTable).values(
rowInsertStmt = partsTable.insert().values(
                part_kod = dataArt.get('kod'),                
                part_description = dataArt.get('title'),
                part_kod_supplier = dataArt.get('supplier'),
                part_manufacturer = manId
            )

        session_new.execute(rowInsertStmt)

        session_new.commit()


dataArt - list with parts descriptions
manId - is of manufactures

Error message:

The target table 'parts' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.DB-Lib error message 20018

Now, I think that SQLalchemy can't work with MSSQL triggers. Because no working solution was found on the web for my situation, but in official documents this problem is not highlighted.

Any advice, please? It possible use SQLalchemy without OUTPUT? Drop SQLalchemy and use direct SQL requests?

9

1 Answer 1

0

Thanks for @ThomA!

The solution is using method add with Session like:

with Session(autoflush=False, bind=engine_new) as db:

                new_part = Parts(                    
                    part_kod=dataArt.get('kod'),
                    part_description=dataArt.get('title'),
                    part_kod_supplier=dataArt.get('supplier'),
                    part_manufacturer=manId
                )

                db.add(new_part)
                db.commit()

While using

rowInsertStmt = insert(partsTable).values(...)
#or this rowInsertStmt = partsTable.insert().values(...)
session_new.execute(rowInsertStmt)
session_new.commit()

You will see an error in the topic.

I use the same solution with 'insert' for processing 'manufactures' and it works well, but with one sql trigger.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.