Skip to content

Commit

Permalink
fixes for Boolean type
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Nov 14, 2022
1 parent ca4d652 commit 946a3bb
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
17 changes: 16 additions & 1 deletion sqlalchemy_iris/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@ def _get_limit_or_fetch(self, select):
else:
return select._fetch_clause

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

def visit_false(self, expr, **kw):
return "0"

def visit_is_true_unary_operator(self, element, operator, **kw):
return "%s = 1" % self.process(element.element, **kw)

def visit_is_false_unary_operator(self, element, operator, **kw):
return "%s = 0" % self.process(element.element, **kw)

def get_select_precolumns(self, select, **kw):

text = ""
Expand Down Expand Up @@ -556,6 +568,7 @@ def create_cursor(self):


colspecs = {
sqltypes.Boolean: types.IRISBoolean,
sqltypes.Date: types.IRISDate,
sqltypes.DateTime: types.IRISDateTime,
sqltypes.TIMESTAMP: types.IRISTimeStamp,
Expand All @@ -580,10 +593,12 @@ class IRISDialect(default.DefaultDialect):
supports_views = True
supports_default_values = True

supports_native_boolean = True
non_native_boolean_check_constraint = False

supports_sequences = False

postfetch_lastrowid = True
non_native_boolean_check_constraint = False
supports_simple_order_by_label = False
supports_empty_insert = False
supports_is_distinct_from = False
Expand Down
21 changes: 21 additions & 0 deletions sqlalchemy_iris/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
HOROLOG_ORDINAL = datetime.date(1840, 12, 31).toordinal()


class IRISBoolean(sqltypes.Boolean):
def _should_create_constraint(self, compiler, **kw):
return False

def bind_processor(self, dialect):
def process(value):
if isinstance(value, int):
return 1 if value > 0 else 0
elif isinstance(value, bool):
return 1 if value is True else 0
return None
return process

def result_processor(self, dialect, coltype):
def process(value):
if isinstance(value, int):
return value > 0
return value
return process


class IRISDate(sqltypes.Date):
def bind_processor(self, dialect):
def process(value):
Expand Down

0 comments on commit 946a3bb

Please sign in to comment.