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

Fixes - Django 5.0 django.utils.timezone.utc removal, handle comma in function in column, import os #100

Open
wants to merge 6 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
25 changes: 22 additions & 3 deletions ibm_db_django/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ):
Expand All @@ -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

Expand Down
5 changes: 4 additions & 1 deletion ibm_db_django/pybase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] >= (5, 0 ) ):
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):
Expand Down
25 changes: 22 additions & 3 deletions ibm_db_django/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# | Authors: Ambrish Bhargava, Tarun Pasrija, Rahul Priyadarshi |
# +--------------------------------------------------------------------------+

import os
import sys

_IS_JYTHON = sys.platform.startswith('java')
Expand Down