From f7fd84db3da385e7e874682f2f9c47cdb56a3082 Mon Sep 17 00:00:00 2001 From: Jef Geskens Date: Tue, 11 Jul 2023 16:36:37 +0200 Subject: [PATCH 1/3] Allow enforcing autocommit on the query level --- src/django_iseries/compiler.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/django_iseries/compiler.py b/src/django_iseries/compiler.py index 9f8d933..e066570 100644 --- a/src/django_iseries/compiler.py +++ b/src/django_iseries/compiler.py @@ -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 @@ -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)] @@ -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): From 51031ac0215838d292facb84743e548c66d6ea3b Mon Sep 17 00:00:00 2001 From: Jef Geskens Date: Tue, 1 Aug 2023 10:46:49 +0200 Subject: [PATCH 2/3] Fix bug when calling sqlmigrate --- src/django_iseries/schemaEditor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/django_iseries/schemaEditor.py b/src/django_iseries/schemaEditor.py index 2e44fed..fcc9e08 100644 --- a/src/django_iseries/schemaEditor.py +++ b/src/django_iseries/schemaEditor.py @@ -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), From ad50405f61f6183c76f54fe7be8dbd949fac588e Mon Sep 17 00:00:00 2001 From: Jef Geskens Date: Tue, 22 Aug 2023 16:39:01 +0200 Subject: [PATCH 3/3] Fix boolean lookups --- src/django_iseries/operations.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/django_iseries/operations.py b/src/django_iseries/operations.py index 1d7d9bf..fc3287e 100644 --- a/src/django_iseries/operations.py +++ b/src/django_iseries/operations.py @@ -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 @@ -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