Skip to content

Commit 4f8ad30

Browse files
committed
feat: Add experimental support for Ingres
1 parent 8f120be commit 4f8ad30

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
0.7.1 - Jan 9, 2024
22
--------------------
33

4+
* feat: Add experimental support for Ingres.
45
* fix: Restore internal use of transactions instead of savepoints, because not all database engines support savepoints.
56

67
0.7.0 - Oct 18, 2023

agatesql/table.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -196,21 +196,27 @@ def make_sql_table(table, table_name, dialect=None, db_schema=None, constraints=
196196
sql_column_kwargs = {}
197197

198198
if constraints:
199-
if isinstance(column.data_type, agate.Text) and dialect == 'mysql':
199+
if isinstance(column.data_type, agate.Text) and dialect in ('ingres', 'mysql'):
200200
length = table.aggregate(agate.MaxLength(column_name)) * decimal.Decimal(col_len_multiplier)
201-
if length > 21844:
202-
# @see https://dev.mysql.com/doc/refman/5.7/en/string-type-overview.html
201+
if (
202+
# https://dev.mysql.com/doc/refman/8.2/en/string-type-syntax.html
203+
dialect == 'mysql' and length > 21844 # 65,535 bytes divided by 3
204+
# https://docs.actian.com/ingres/11.2/index.html#page/SQLRef/Character_Data_Types.htm
205+
or dialect == 'ingres' and length > 10666 # 32,000 bytes divided by 3
206+
):
203207
sql_column_type = TEXT
208+
# If length is zero, SQLAlchemy may raise "VARCHAR requires a length on dialect mysql".
204209
else:
205-
# If length is zero, SQLAlchemy may raise "VARCHAR requires a length on dialect mysql".
206210
sql_type_kwargs['length'] = length if length >= min_col_len else min_col_len
207211

208212
# PostgreSQL and SQLite don't have scale default 0.
209213
# @see https://www.postgresql.org/docs/9.2/static/datatype-numeric.html
210214
# @see https://www.sqlite.org/datatype3.html
211-
if isinstance(column.data_type, agate.Number) and dialect in ('mssql', 'mysql', 'oracle'):
215+
if isinstance(column.data_type, agate.Number) and dialect in ('ingres', 'mssql', 'mysql', 'oracle'):
216+
# Ingres has precision range 1-39 and default 5, scale default 0.
217+
# @see https://docs.actian.com/ingres/11.2/index.html#page/SQLRef/Storage_Formats_of_Data_Types.htm
212218
# MySQL has precision range 1-65 and default 10, scale default 0.
213-
# @see https://dev.mysql.com/doc/refman/5.7/en/fixed-point-types.html
219+
# @see https://dev.mysql.com/doc/refman/8.2/en/fixed-point-types.html
214220
# Oracle has precision range 1-38 and default 38, scale default 0.
215221
# @see https://docs.oracle.com/cd/B28359_01/server.111/b28318/datatype.htm#CNCPT1832
216222
# SQL Server has range 1-38 and default 18, scale default 0.
@@ -219,7 +225,7 @@ def make_sql_table(table, table_name, dialect=None, db_schema=None, constraints=
219225
sql_type_kwargs['scale'] = table.aggregate(agate.MaxPrecision(column_name))
220226

221227
# Avoid errors due to NO_ZERO_DATE.
222-
# @see https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_no_zero_date
228+
# @see https://dev.mysql.com/doc/refman/8.2/en/sql-mode.html#sqlmode_no_zero_date
223229
if not isinstance(column.data_type, agate.DateTime):
224230
sql_column_kwargs['nullable'] = table.aggregate(agate.HasNulls(column_name))
225231

@@ -276,14 +282,14 @@ def to_sql(self, connection_or_string, table_name, overwrite=False,
276282
min_col_len=min_col_len, col_len_multiplier=col_len_multiplier)
277283

278284
if create:
279-
with connection.begin() as conn:
285+
with connection.begin():
280286
if overwrite:
281287
sql_table.drop(bind=connection, checkfirst=True)
282288

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

285291
if insert:
286-
with connection.begin() as conn:
292+
with connection.begin():
287293
insert = sql_table.insert()
288294
for prefix in prefixes:
289295
insert = insert.prefix_with(prefix)

0 commit comments

Comments
 (0)