Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/boolean lookup #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/django_iseries/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
import sys

from django.db.models.sql import compiler
from django.conf import settings

from itertools import zip_longest


ENFORCE_AUTOCOMMIT = getattr(settings, 'DJANGO_ISERIES_ENFORCE_AUTOCOMMIT', False)


class SQLCompiler(compiler.SQLCompiler):
pass

Expand All @@ -34,6 +38,8 @@ def as_sql(self):
qn = self.connection.ops.quote_name
opts = self.query.get_meta()
sql = f'SELECT {qn(opts.pk.column)} FROM FINAL TABLE ({sql})'
if ENFORCE_AUTOCOMMIT:
sql = f'{sql} WITH NONE'
return [(sql, params)]


Expand All @@ -42,7 +48,11 @@ class SQLDeleteCompiler(compiler.SQLDeleteCompiler, SQLCompiler):


class SQLUpdateCompiler(compiler.SQLUpdateCompiler, SQLCompiler):
pass
def as_sql(self):
sql, params = super().as_sql()
if ENFORCE_AUTOCOMMIT:
sql = f'{sql} WITH NONE'
return sql, params


class SQLAggregateCompiler(compiler.SQLAggregateCompiler, SQLCompiler):
Expand Down
11 changes: 7 additions & 4 deletions src/django_iseries/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ def datetime_cast_date_sql(self, field_name, tzname):
field_name = self._convert_field_to_tz(field_name, tzname)
return "DATE(%s)" % field_name

def field_cast_sql(self, db_type, internal_type):
if db_type == 'SMALLINT' and internal_type == 'BooleanField':
return 'coalesce((select 1 from sysibm.sysdummy1 where %s), 0)'
return super().field_cast_sql(db_type, internal_type)
# def field_cast_sql(self, db_type, internal_type):
# if db_type == 'SMALLINT' and internal_type == 'BooleanField':
# return 'coalesce((select 1 from sysibm.sysdummy1 where %s), 0)'
# return super().field_cast_sql(db_type, internal_type)

# Function to extract day, month or year from the date.
# Reference: http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0023457.html
Expand Down Expand Up @@ -507,3 +507,6 @@ def _convert_field_to_tz(self, field_name, tzname):

def check_expression_support(self, expression):
super().check_expression_support(expression)

def conditional_expression_supported_in_where_clause(self, expression):
return False
2 changes: 1 addition & 1 deletion src/django_iseries/schemaEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def alter_field(self, model, old_field, new_field, strict=False):
self.execute(
self.sql_create_fk % {
'table': self.quote_name(model._meta.db_table),
'name': self._create_index_name(model, [new_field.column], suffix="_fk"),
'name': self._create_index_name(self.quote_name(model._meta.db_table), [new_field.column], suffix="_fk"),
'column': self.quote_name(new_field.column),
'to_table': self.quote_name(new_field.remote_field.model._meta.db_table),
'to_column': self.quote_name(new_field.remote_field.get_related_field().column),
Expand Down