Skip to content

Commit

Permalink
fix: Remove internal use of transactions (added in 0.6.0), because cs…
Browse files Browse the repository at this point in the history
…vkit's csvsql already starts a transaction
  • Loading branch information
jpmckinney committed Jan 9, 2024
1 parent 4f8ad30 commit 1415547
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.7.2 - Jan 9, 2024
--------------------

* fix: Remove internal use of transactions (added in 0.6.0), because csvkit's csvsql already starts a transaction.

0.7.1 - Jan 9, 2024
--------------------

Expand Down
34 changes: 16 additions & 18 deletions agatesql/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,27 +282,25 @@ def to_sql(self, connection_or_string, table_name, overwrite=False,
min_col_len=min_col_len, col_len_multiplier=col_len_multiplier)

if create:
with connection.begin():
if overwrite:
sql_table.drop(bind=connection, checkfirst=True)
if overwrite:
sql_table.drop(bind=connection, checkfirst=True)

sql_table.create(bind=connection, checkfirst=create_if_not_exists)
sql_table.create(bind=connection, checkfirst=create_if_not_exists)

if insert:
with connection.begin():
insert = sql_table.insert()
for prefix in prefixes:
insert = insert.prefix_with(prefix)
if chunk_size is None:
connection.execute(insert, [dict(zip(self.column_names, row)) for row in self.rows])
else:
number_of_rows = len(self.rows)
for index in range((number_of_rows - 1) // chunk_size + 1):
end_index = (index + 1) * chunk_size
if end_index > number_of_rows:
end_index = number_of_rows
connection.execute(insert, [dict(zip(self.column_names, row)) for row in
self.rows[index * chunk_size:end_index]])
insert = sql_table.insert()
for prefix in prefixes:
insert = insert.prefix_with(prefix)
if chunk_size is None:
connection.execute(insert, [dict(zip(self.column_names, row)) for row in self.rows])
else:
number_of_rows = len(self.rows)
for index in range((number_of_rows - 1) // chunk_size + 1):
end_index = (index + 1) * chunk_size
if end_index > number_of_rows:
end_index = number_of_rows
connection.execute(insert, [dict(zip(self.column_names, row)) for row in
self.rows[index * chunk_size:end_index]])

try:
return sql_table
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

project = 'agate-sql'
copyright = '2017, Christopher Groskopf'
version = '0.7.1'
version = '0.7.2'
release = version

# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='agate-sql',
version='0.7.1',
version='0.7.2',
description='agate-sql adds SQL read/write support to agate.',
long_description=long_description,
long_description_content_type='text/x-rst',
Expand Down

0 comments on commit 1415547

Please sign in to comment.