Download our e-book of Introduction To Python
Shashank Shanu
2 years ago
engine = create_engine('sqlite:///testdb.db')
metadata = MetaData(bind=engine)
test = Table('test', metadata, autoload=true)
# Select all from pending_data
sel = select([test])
res = engine.execute(sel)
print(res)
# do an insert into pending_data
test.insert().values(info='blah').execute()
Code Error: Python sqlalchemy.exc.ResourceClosedError
engine = create_engine('sqlite:///testdb.db')
metadata = MetaData(bind=engine)
test = Table('test', metadata, autoload=true)
with engine.connect() as connection:
# Select all from pending_data
sel = select([test])
res = connection.execute(sel)
# do an insert into pending_data
connection.execute(test.insert().values(info='blah'))