Skip to content

Commit 946a3bb

Browse files
committed
fixes for Boolean type
1 parent ca4d652 commit 946a3bb

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

sqlalchemy_iris/base.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,18 @@ def _get_limit_or_fetch(self, select):
348348
else:
349349
return select._fetch_clause
350350

351+
def visit_true(self, expr, **kw):
352+
return "1"
353+
354+
def visit_false(self, expr, **kw):
355+
return "0"
356+
357+
def visit_is_true_unary_operator(self, element, operator, **kw):
358+
return "%s = 1" % self.process(element.element, **kw)
359+
360+
def visit_is_false_unary_operator(self, element, operator, **kw):
361+
return "%s = 0" % self.process(element.element, **kw)
362+
351363
def get_select_precolumns(self, select, **kw):
352364

353365
text = ""
@@ -556,6 +568,7 @@ def create_cursor(self):
556568

557569

558570
colspecs = {
571+
sqltypes.Boolean: types.IRISBoolean,
559572
sqltypes.Date: types.IRISDate,
560573
sqltypes.DateTime: types.IRISDateTime,
561574
sqltypes.TIMESTAMP: types.IRISTimeStamp,
@@ -580,10 +593,12 @@ class IRISDialect(default.DefaultDialect):
580593
supports_views = True
581594
supports_default_values = True
582595

596+
supports_native_boolean = True
597+
non_native_boolean_check_constraint = False
598+
583599
supports_sequences = False
584600

585601
postfetch_lastrowid = True
586-
non_native_boolean_check_constraint = False
587602
supports_simple_order_by_label = False
588603
supports_empty_insert = False
589604
supports_is_distinct_from = False

sqlalchemy_iris/types.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@
55
HOROLOG_ORDINAL = datetime.date(1840, 12, 31).toordinal()
66

77

8+
class IRISBoolean(sqltypes.Boolean):
9+
def _should_create_constraint(self, compiler, **kw):
10+
return False
11+
12+
def bind_processor(self, dialect):
13+
def process(value):
14+
if isinstance(value, int):
15+
return 1 if value > 0 else 0
16+
elif isinstance(value, bool):
17+
return 1 if value is True else 0
18+
return None
19+
return process
20+
21+
def result_processor(self, dialect, coltype):
22+
def process(value):
23+
if isinstance(value, int):
24+
return value > 0
25+
return value
26+
return process
27+
28+
829
class IRISDate(sqltypes.Date):
930
def bind_processor(self, dialect):
1031
def process(value):

0 commit comments

Comments
 (0)