From 1e91836bddacff500da4ab511828e5898ccde327 Mon Sep 17 00:00:00 2001 From: LeVon Smoker Date: Mon, 17 Jun 2024 08:47:03 -0400 Subject: [PATCH 1/5] Django 4.1 fix replace django.utils.timezone.utc with datetime.timezone.utc --- ibm_db_django/pybase.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ibm_db_django/pybase.py b/ibm_db_django/pybase.py index 6456c39..8fec208 100644 --- a/ibm_db_django/pybase.py +++ b/ibm_db_django/pybase.py @@ -407,7 +407,10 @@ def _fix_return_data( self, row ): index = index + 1 if ( desc[1] == Database.DATETIME ): if settings.USE_TZ and value is not None and timezone.is_naive( value ): - value = value.replace( tzinfo=timezone.utc ) + if ( djangoVersion[0:2] >= (4, 1 ) ): + value = value.replace( tzinfo=datetime.timezone.utc ) + else: + value = value.replace( tzinfo=timezone.utc ) row[index] = value elif ( djangoVersion[0:2] >= (1, 5 ) ): if isinstance(value, six.string_types): From 1c821221c160220c0a4421a14cc62c553414d49a Mon Sep 17 00:00:00 2001 From: LeVon Smoker Date: Fri, 21 Jun 2024 10:34:10 -0400 Subject: [PATCH 2/5] Check for django v 5.x --- ibm_db_django/pybase.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ibm_db_django/pybase.py b/ibm_db_django/pybase.py index 8fec208..03bf2bc 100644 --- a/ibm_db_django/pybase.py +++ b/ibm_db_django/pybase.py @@ -407,7 +407,7 @@ def _fix_return_data( self, row ): index = index + 1 if ( desc[1] == Database.DATETIME ): if settings.USE_TZ and value is not None and timezone.is_naive( value ): - if ( djangoVersion[0:2] >= (4, 1 ) ): + if ( djangoVersion[0:2] >= (5, 0 ) ): value = value.replace( tzinfo=datetime.timezone.utc ) else: value = value.replace( tzinfo=timezone.utc ) From 3bccb0cdbad869a800537cd398eaad22d97fe956 Mon Sep 17 00:00:00 2001 From: LeVon Smoker Date: Thu, 27 Jun 2024 09:19:17 -0400 Subject: [PATCH 3/5] Fix to allow more db functions in columns - handle db functions where a comma is used to delimit parameters - handle db functions (ie, CAST) that use "AS xxxx" (ie, varchar) where it is not an alias --- ibm_db_django/compiler.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/ibm_db_django/compiler.py b/ibm_db_django/compiler.py index 51ecfe9..b949788 100644 --- a/ibm_db_django/compiler.py +++ b/ibm_db_django/compiler.py @@ -146,6 +146,24 @@ def as_sql( self, with_limits=True, with_col_aliases=False, subquery=False ): sql_sel = "SELECT DISTINCT" sql_select_token = sql_split[0].split( "," ) + # rejoin items that use comma in a db function + new_sql_select_token = [] + paren_count = 0 + column_fragment = None + for column in sql_select_token: + paren_count += column.count('(') - column.count(')') + if paren_count > 0: + if column_fragment: + column_fragment = ', '.join([column_fragment, column]) + else: + column_fragment = column + elif paren_count == 0 and column_fragment: + new_sql_select_token.append(', '.join([column_fragment, column])) + column_fragment = None + else: + new_sql_select_token.append(column) + sql_select_token = new_sql_select_token + i = 0 first_field_no = 0 while ( i < len( sql_select_token ) ): @@ -161,10 +179,11 @@ def as_sql( self, with_limits=True, with_col_aliases=False, subquery=False ): i = i + 4 continue - if sql_select_token[i].count( " AS " ) == 1: - temp_col_alias = sql_select_token[i].split( " AS " ) + if sql_select_token[i].count( ' AS "' ) == 1: + # split only on column aliases not "AS varchar" for instance + temp_col_alias = sql_select_token[i].split( ' AS "' ) sql_pri = '%s %s,' % ( sql_pri, sql_select_token[i] ) - sql_sel = "%s %s," % ( sql_sel, temp_col_alias[1] ) + sql_sel = '%s "%s,' % ( sql_sel, temp_col_alias[1] ) i = i + 1 continue From 4ab034f99a03259bf4da0a9c4abf5e472cfcfc4e Mon Sep 17 00:00:00 2001 From: LeVon Smoker Date: Thu, 27 Jun 2024 09:21:39 -0400 Subject: [PATCH 4/5] Fix to allow more db functions in columns - handle db functions where a comma is used to delimit parameters - handle db functions (ie, CAST) that use "AS xxxx" (ie, varchar) where it is not an alias --- ibm_db_django/query.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/ibm_db_django/query.py b/ibm_db_django/query.py index 22ddf16..c9788d5 100755 --- a/ibm_db_django/query.py +++ b/ibm_db_django/query.py @@ -52,6 +52,24 @@ def as_sql( self, with_limits = True, with_col_aliases = False ): sql_sel = "SELECT DISTINCT" sql_select_token = sql_split[0].split( "," ) + # rejoin items that use comma in a db function + new_sql_select_token = [] + paren_count = 0 + column_fragment = None + for column in sql_select_token: + paren_count += column.count('(') - column.count(')') + if paren_count > 0: + if column_fragment: + column_fragment = ', '.join([column_fragment, column]) + else: + column_fragment = column + elif paren_count == 0 and column_fragment: + new_sql_select_token.append(', '.join([column_fragment, column])) + column_fragment = None + else: + new_sql_select_token.append(column) + sql_select_token = new_sql_select_token + i = 0 while ( i < len( sql_select_token ) ): if sql_select_token[i].count( "TIMESTAMP(DATE(SUBSTR(CHAR(" ) == 1: @@ -66,10 +84,11 @@ def as_sql( self, with_limits = True, with_col_aliases = False ): i = i + 4 continue - if sql_select_token[i].count( " AS " ) == 1: - temp_col_alias = sql_select_token[i].split( " AS " ) + if sql_select_token[i].count( ' AS "' ) == 1: + # split only on column aliases not "AS varchar" for instance + temp_col_alias = sql_select_token[i].split( ' AS "' ) sql_pri = '%s %s,' % ( sql_pri, sql_select_token[i] ) - sql_sel = "%s %s," % ( sql_sel, temp_col_alias[1] ) + sql_sel = '%s "%s,' % ( sql_sel, temp_col_alias[1] ) i = i + 1 continue From 64aad116bf92109b07dec21a1fddfe691422356c Mon Sep 17 00:00:00 2001 From: LeVon Smoker Date: Tue, 2 Jul 2024 16:06:22 -0400 Subject: [PATCH 5/5] import os module --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 13c35ea..cd5d31e 100644 --- a/setup.py +++ b/setup.py @@ -15,6 +15,7 @@ # | Authors: Ambrish Bhargava, Tarun Pasrija, Rahul Priyadarshi | # +--------------------------------------------------------------------------+ +import os import sys _IS_JYTHON = sys.platform.startswith('java')