Skip to content

Commit 432e297

Browse files
authored
Merge pull request #42 from s-t-e-v-e-n-k/use-begin-nested
Use Connection.begin_nested() instead
2 parents 059b687 + 91276ae commit 432e297

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

agatesql/table.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,15 @@ def to_sql(self, connection_or_string, table_name, overwrite=False,
273273
min_col_len=min_col_len, col_len_multiplier=col_len_multiplier)
274274

275275
if create:
276-
with connection.begin():
276+
with connection.begin_nested() as conn:
277277
if overwrite:
278278
sql_table.drop(bind=connection, checkfirst=True)
279279

280280
sql_table.create(bind=connection, checkfirst=create_if_not_exists)
281+
conn.commit()
281282

282283
if insert:
283-
with connection.begin():
284+
with connection.begin_nested() as conn:
284285
insert = sql_table.insert()
285286
for prefix in prefixes:
286287
insert = insert.prefix_with(prefix)
@@ -295,6 +296,8 @@ def to_sql(self, connection_or_string, table_name, overwrite=False,
295296
connection.execute(insert, [dict(zip(self.column_names, row)) for row in
296297
self.rows[index * chunk_size:end_index]])
297298

299+
conn.commit()
300+
298301
try:
299302
return sql_table
300303
finally:

0 commit comments

Comments
 (0)