Skip to content

Commit 73c83e9

Browse files
committed
various updates
1 parent 437eb7d commit 73c83e9

File tree

8 files changed

+131
-26
lines changed

8 files changed

+131
-26
lines changed

setup.cfg

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ addopts= --tb native -v -r fxX --maxfail=25 -p no:warnings
3636
python_files=test/*test_*.py
3737

3838
[db]
39-
default=iris+iris://_SYSTEM:SYS@localhost:1972/USER
39+
default=iris://_SYSTEM:SYS@localhost:1972/USER
4040
sqlite=sqlite:///:memory:
4141

4242
[sqla_testing]
4343
requirement_cls=sqlalchemy_iris.requirements:Requirements
4444
profile_file=test/profiles.txt
45+
46+
[flake8]
47+
max-line-length=120

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
dependency_links=dependency_links,
1919
entry_points={
2020
"sqlalchemy.dialects": [
21-
"iris = sqlalchemy_iris:IRISDialect",
21+
"iris = sqlalchemy_iris.iris:IRISDialect_iris",
2222
]
2323
},
2424
)

sqlalchemy_iris/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
from sqlalchemy.dialects import registry as _registry
2+
13
from . import base
24
from . import iris
3-
from .base import IRISDialect
4-
from .iris import IRISDialect_iris
55

66
base.dialect = dialect = iris.dialect
77

8+
_registry.register("iris.iris", "sqlalchemy_iris.iris", "IRISDialect_iris")
9+
810
__all__ = [
9-
IRISDialect,
10-
IRISDialect_iris,
1111
dialect,
1212
]

sqlalchemy_iris/base.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from sqlalchemy.sql import util as sql_util
1010
from sqlalchemy.sql import between
1111
from sqlalchemy.sql import func
12-
from sqlalchemy import sql
12+
from sqlalchemy import sql, text
1313
from sqlalchemy import util
1414
from sqlalchemy import types as sqltypes
1515

@@ -393,6 +393,9 @@ def translate_select_structure(self, select_stmt, **kwargs):
393393
for elem in select._order_by_clause.clauses
394394
]
395395

396+
if not _order_by_clauses:
397+
_order_by_clauses = [text('%id')]
398+
396399
limit_clause = self._get_limit_or_fetch(select)
397400
offset_clause = select._offset_clause
398401

@@ -440,6 +443,44 @@ def visit_drop_schema(self, drop, **kw):
440443
def visit_check_constraint(self, constraint, **kw):
441444
raise exc.CompileError("Check CONSTRAINT not supported")
442445

446+
def get_column_specification(self, column, **kwargs):
447+
448+
colspec = [
449+
self.preparer.format_column(column),
450+
]
451+
452+
if (
453+
column.primary_key
454+
and column is column.table._autoincrement_column
455+
):
456+
colspec.append("SERIAL")
457+
else:
458+
colspec.append(
459+
self.dialect.type_compiler.process(
460+
column.type,
461+
type_expression=column,
462+
identifier_preparer=self.preparer,
463+
)
464+
)
465+
466+
if column.computed is not None:
467+
colspec.append(self.process(column.computed))
468+
default = self.get_column_default_string(column)
469+
if default is not None:
470+
colspec.append("DEFAULT " + default)
471+
472+
if not column.nullable:
473+
colspec.append("NOT NULL")
474+
475+
comment = column.comment
476+
if comment is not None:
477+
literal = self.sql_compiler.render_literal_value(
478+
comment, sqltypes.String()
479+
)
480+
colspec.append("%%DESCRIPTION " + literal)
481+
482+
return " ".join(colspec)
483+
443484

444485
class IRISTypeCompiler(compiler.GenericTypeCompiler):
445486
def visit_boolean(self, type_, **kw):
@@ -536,11 +577,13 @@ def process(value):
536577

537578

538579
class IRISDialect(default.DefaultDialect):
539-
driver = 'iris'
580+
581+
name = 'iris'
540582

541583
default_schema_name = "SQLUser"
542584

543585
default_paramstyle = "format"
586+
supports_statement_cache = True
544587

545588
supports_native_decimal = True
546589
supports_sane_rowcount = True
@@ -551,7 +594,6 @@ class IRISDialect(default.DefaultDialect):
551594

552595
supports_sequences = False
553596

554-
supports_statement_cache = False
555597
postfetch_lastrowid = False
556598
non_native_boolean_check_constraint = False
557599
supports_simple_order_by_label = False
@@ -610,6 +652,7 @@ def _fix_for_params(self, query, params, many=False):
610652

611653
def do_execute(self, cursor, query, params, context=None):
612654
query, params = self._fix_for_params(query, params)
655+
# print('do_execute', query, params)
613656
cursor.execute(query, params)
614657

615658
def do_executemany(self, cursor, query, params, context=None):
@@ -903,7 +946,7 @@ def get_columns(self, connection, table_name, schema=None, **kw):
903946
):
904947
if charlen == -1:
905948
charlen = None
906-
kwargs["length"] = charlen
949+
kwargs["length"] = int(charlen)
907950
if collation:
908951
kwargs["collation"] = collation
909952
if coltype is None:
@@ -914,10 +957,10 @@ def get_columns(self, connection, table_name, schema=None, **kw):
914957
coltype = sqltypes.NULLTYPE
915958
else:
916959
if issubclass(coltype, sqltypes.Numeric):
917-
kwargs["precision"] = numericprec
960+
kwargs["precision"] = int(numericprec)
918961

919962
if not issubclass(coltype, sqltypes.Float):
920-
kwargs["scale"] = numericscale
963+
kwargs["scale"] = int(numericscale)
921964

922965
coltype = coltype(**kwargs)
923966

sqlalchemy_iris/iris.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
class IRISDialect_iris(IRISDialect):
55
driver = "iris"
66

7-
def create_connect_args(self, url):
8-
opts = dict(url.query)
9-
return ([], opts)
7+
supports_statement_cache = True
108

119

1210
dialect = IRISDialect_iris

sqlalchemy_iris/requirements.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def autoincrement_insert(self):
211211
"""target platform generates new surrogate integer primary key values
212212
when insert() is executed, excluding the pk column."""
213213

214-
return exclusions.closed()
214+
return exclusions.open()
215215

216216
@property
217217
def fetch_rows_post_commit(self):
@@ -367,8 +367,7 @@ def reflects_pk_names(self):
367367
@property
368368
def table_reflection(self):
369369
"""target database has general support for table reflection"""
370-
# return exclusions.open()
371-
return exclusions.closed()
370+
return exclusions.open()
372371

373372
@property
374373
def reflect_tables_no_columns(self):
@@ -1124,5 +1123,5 @@ def autoincrement_without_sequence(self):
11241123
"""If autoincrement=True on a column does not require an explicit
11251124
sequence. This should be false only for oracle.
11261125
"""
1127-
# return exclusions.open()
1128-
return exclusions.closed()
1126+
return exclusions.open()
1127+
# return exclusions.closed()

test/conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from sqlalchemy.dialects import registry
22
import pytest
33

4-
registry.register(
5-
"iris.iris", "sqlalchemy_iris", "IRISDialect"
6-
)
4+
registry.register("iris.iris", "sqlalchemy_iris.iris", "IRISDialect_iris")
75

86
pytest.register_assert_rewrite("sqlalchemy.testing.assertions")
97

10-
from sqlalchemy.testing.plugin.pytestplugin import *
8+
from sqlalchemy.testing.plugin.pytestplugin import * # noqa

test/test_suite.py

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
from sqlalchemy.testing.suite.test_reflection import QuotedNameArgumentTest as _QuotedNameArgumentTest
1+
from sqlalchemy.testing.suite import QuotedNameArgumentTest as _QuotedNameArgumentTest
2+
from sqlalchemy.testing.suite import FetchLimitOffsetTest as _FetchLimitOffsetTest
23
from sqlalchemy.testing.suite import CompoundSelectTest as _CompoundSelectTest
4+
from sqlalchemy.testing import fixtures, AssertsExecutionResults, AssertsCompiledSQL
5+
from sqlalchemy import testing
6+
from sqlalchemy import Table, Column, Integer, String, select
37
import pytest
48

5-
from sqlalchemy.testing.suite import * # noqa
9+
from sqlalchemy.testing.suite import * # noqa
610

711

812
class CompoundSelectTest(_CompoundSelectTest):
@@ -14,3 +18,63 @@ def test_limit_offset_aliased_selectable_in_unions(self):
1418
@pytest.mark.skip()
1519
class QuotedNameArgumentTest(_QuotedNameArgumentTest):
1620
pass
21+
22+
23+
class FetchLimitOffsetTest(_FetchLimitOffsetTest):
24+
25+
def test_simple_offset_no_order(self, connection):
26+
table = self.tables.some_table
27+
self._assert_result(
28+
connection,
29+
select(table).offset(2),
30+
[(3, 3, 4), (4, 4, 5), (5, 4, 6)],
31+
)
32+
self._assert_result(
33+
connection,
34+
select(table).offset(3),
35+
[(4, 4, 5), (5, 4, 6)],
36+
)
37+
38+
@testing.combinations(
39+
([(2, 0), (2, 1), (3, 2)]),
40+
([(2, 1), (2, 0), (3, 2)]),
41+
([(3, 1), (2, 1), (3, 1)]),
42+
argnames="cases",
43+
)
44+
def test_simple_limit_offset_no_order(self, connection, cases):
45+
table = self.tables.some_table
46+
connection = connection.execution_options(compiled_cache={})
47+
48+
assert_data = [(1, 1, 2), (2, 2, 3), (3, 3, 4), (4, 4, 5), (5, 4, 6)]
49+
50+
for limit, offset in cases:
51+
expected = assert_data[offset: offset + limit]
52+
self._assert_result(
53+
connection,
54+
select(table).limit(limit).offset(offset),
55+
expected,
56+
)
57+
58+
59+
class MiscTest(AssertsExecutionResults, AssertsCompiledSQL, fixtures.TablesTest):
60+
61+
__backend__ = True
62+
63+
__only_on__ = "iris"
64+
65+
@classmethod
66+
def define_tables(cls, metadata):
67+
Table(
68+
"some_table",
69+
metadata,
70+
Column("id", Integer, primary_key=True),
71+
Column("x", Integer),
72+
Column("y", Integer),
73+
Column("z", String(50)),
74+
)
75+
76+
# def test_compile(self):
77+
# table = self.tables.some_table
78+
79+
# stmt = select(table.c.id, table.c.x).offset(20).limit(10)
80+

0 commit comments

Comments
 (0)