Skip to content

Commit

Permalink
some small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Nov 16, 2022
1 parent 4a1f299 commit f54e821
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 11 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
intersystems_iris>=3.3.0b8
intersystems_iris>=3.3.0b9
SQLAlchemy>=1.4
50 changes: 47 additions & 3 deletions sqlalchemy_iris/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ def visit_delete(self, delete_stmt, **kw):
text = super().visit_delete(delete_stmt, **kw)
return text

def for_update_clause(self, select, **kw):
return ""

def visit_true(self, expr, **kw):
return "1"

Expand Down Expand Up @@ -425,7 +428,7 @@ def _add_exact(column):

_order_by_clauses = [
sql_util.unwrap_label_reference(elem)
for elem in select._order_by_clause.clauses
for elem in select._order_by_clause.clauses if isinstance(elem, schema.Column)
]
if _order_by_clauses:
select._raw_columns = [
Expand Down Expand Up @@ -508,6 +511,19 @@ def visit_column(self, column, within_columns_clause=False, **kwargs):
text = 'CONVERT(VARCHAR, %s)' % (text, )
return text

def visit_concat_op_binary(self, binary, operator, **kw):
return "STRING(%s, %s)" % (
self.process(binary.left, **kw),
self.process(binary.right, **kw),
)

def visit_mod_binary(self, binary, operator, **kw):
return (
self.process(binary.left, **kw)
+ " # "
+ self.process(binary.right, **kw)
)


class IRISDDLCompiler(sql.compiler.DDLCompiler):
"""IRIS syntactic idiosyncrasies"""
Expand All @@ -519,8 +535,12 @@ def visit_drop_schema(self, drop, **kw):
return ""

def visit_check_constraint(self, constraint, **kw):
raise exc.CompileError("Check CONSTRAINT not supported")
# pass
pass

def visit_add_constraint(self, create, **kw):
if isinstance(create.element, schema.CheckConstraint):
raise exc.CompileError("Can't add CHECK constraint")
return super().visit_add_constraint(create, **kw)

def visit_computed_column(self, generated, **kwargs):
text = self.sql_compiler.process(
Expand Down Expand Up @@ -706,6 +726,9 @@ def __init__(self, **kwargs):
]
)

def _get_default_schema_name(self, connection):
return IRISDialect.default_schema_name

def _get_option(self, connection, option):
cursor = connection.cursor()
# cursor = connection.cursor()
Expand Down Expand Up @@ -751,6 +774,27 @@ def dbapi(cls):
# dbapi.paramstyle = "format"
return dbapi

def is_disconnect(self, e, connection, cursor):
if isinstance(e, self.dbapi.InterfaceError):
return "Connection is closed" in str(e)
return False

def do_ping(self, dbapi_connection):
cursor = None
try:
cursor = dbapi_connection.cursor()
try:
cursor.execute(self._dialect_specific_select_one)
finally:
cursor.close()
except self.dbapi.Error as err:
if self.is_disconnect(err, dbapi_connection, cursor):
return False
else:
raise
else:
return True

def create_connect_args(self, url):
opts = {}
opts["hostname"] = url.host
Expand Down
47 changes: 47 additions & 0 deletions sqlalchemy_iris/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,50 @@ def precision_numerics_many_significant_digits(self):
def symbol_names_w_double_quote(self):
"""Target driver can create tables with a name like 'some " table'"""
return exclusions.closed()

@property
def unique_constraint_reflection(self):
return exclusions.open()

@property
def index_reflects_included_columns(self):
return exclusions.open()

@property
def intersect(self):
"""Target database must support INTERSECT or equivalent."""
return exclusions.closed()

@property
def except_(self):
"""Target database must support EXCEPT or equivalent (i.e. MINUS)."""
return exclusions.closed()

@property
def boolean_col_expressions(self):
"""Target database must support boolean expressions as columns"""

return exclusions.closed()

@property
def order_by_label_with_expression(self):
"""target backend supports ORDER BY a column label within an
expression.
Basically this::
select data as foo from test order by foo || 'bar'
Lots of databases including PostgreSQL don't support this,
so this is off by default.
"""
return exclusions.closed()

@property
def memory_process_intensive(self):
"""Driver is able to handle the memory tests which run in a subprocess
and iterate through hundreds of connections
"""
return exclusions.closed()
7 changes: 0 additions & 7 deletions test/test_suite.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from sqlalchemy.testing.suite import QuotedNameArgumentTest as _QuotedNameArgumentTest
from sqlalchemy.testing.suite import FetchLimitOffsetTest as _FetchLimitOffsetTest
from sqlalchemy.testing.suite import CompoundSelectTest as _CompoundSelectTest
from sqlalchemy.testing import fixtures
# from sqlalchemy.testing import AssertsExecutionResults, AssertsCompiledSQL
from sqlalchemy import testing
from sqlalchemy import Table, Column, Integer, String, select
import pytest
Expand All @@ -16,11 +14,6 @@ def test_limit_offset_aliased_selectable_in_unions(self):
return


@pytest.mark.skip()
class QuotedNameArgumentTest(_QuotedNameArgumentTest):
pass


class FetchLimitOffsetTest(_FetchLimitOffsetTest):

def test_simple_offset_no_order(self, connection):
Expand Down

0 comments on commit f54e821

Please sign in to comment.