Skip to content

Commit 55e18d0

Browse files
committed
more fixes
1 parent 4c93f7e commit 55e18d0

File tree

4 files changed

+51
-24
lines changed

4 files changed

+51
-24
lines changed

django_iris/base.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class DatabaseClient(BaseDatabaseClient):
3838

3939

4040
class DatabaseWrapper(BaseDatabaseWrapper):
41-
vendor = 'interystems'
41+
vendor = 'intersystems'
4242
display_name = 'InterSystems IRIS'
4343

4444
data_types = {
@@ -75,19 +75,19 @@ class DatabaseWrapper(BaseDatabaseWrapper):
7575

7676
operators = {
7777
'exact': '= %s',
78-
# 'iexact': "LIKE %s ESCAPE '\\'",
79-
# 'contains': "LIKE %s ESCAPE '\\'",
80-
# 'icontains': "LIKE %s ESCAPE '\\'",
78+
'iexact': "LIKE %s ESCAPE '\\'",
79+
'contains': "LIKE %s ESCAPE '\\'",
80+
'icontains': "LIKE %s ESCAPE '\\'",
8181
# 'regex': 'REGEXP %s',
8282
# 'iregex': "REGEXP '(?i)' || %s",
8383
'gt': '> %s',
8484
'gte': '>= %s',
8585
'lt': '< %s',
8686
'lte': '<= %s',
8787
'startswith': "%STARTSWITH %s",
88-
# 'endswith': "LIKE %s ESCAPE '\\'",
88+
'endswith': "LIKE %s ESCAPE '\\'",
8989
'istartswith': "%STARTSWITH %s",
90-
# 'iendswith': "LIKE %s ESCAPE '\\'",
90+
'iendswith': "LIKE %s ESCAPE '\\'",
9191

9292
}
9393
Database = Database
@@ -165,7 +165,9 @@ def get_new_connection(self, conn_params):
165165
return Database.connect(**conn_params)
166166

167167
def init_connection_state(self):
168-
pass
168+
cursor = self.connection.cursor()
169+
# cursor.callproc('%SYSTEM_SQL.Util_SetOption', ['SELECTMODE', 1])
170+
# cursor.callproc('%SYSTEM.SQL_SetSelectMode', [1])
169171

170172
@async_unsafe
171173
def create_cursor(self, name=None):

django_iris/cursor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def _fix_for_params(self, query, params):
2020
def execute(self, query, params=None):
2121
self.times = 0
2222
query, params = self._fix_for_params(query, params)
23+
# print(query, params)
2324
return self.cursor.execute(query, params)
2425

2526
def executemany(self, query, params=None):

django_iris/features.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ class DatabaseFeatures(BaseDatabaseFeatures):
1515
supports_column_check_constraints = False
1616
supports_table_check_constraints = False
1717
can_introspect_check_constraints = False
18+
19+
interprets_empty_strings_as_nulls = True

django_iris/operations.py

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1+
import imp
12
from django.conf import settings
23
from django.db.backends.base.operations import BaseDatabaseOperations
34
from django.utils import timezone
45
from itertools import chain
6+
from datetime import datetime
57

8+
import traceback
69

710
class DatabaseOperations(BaseDatabaseOperations):
811
def quote_name(self, name):
912
if name.startswith('"') and name.endswith('"'):
1013
return name # Quoting once is enough.
1114
return '"%s"' % name
1215

13-
def adapt_datetimefield_value(self, value):
14-
if value is None:
15-
return None
16-
17-
# Expression values are adapted by the database.
18-
if hasattr(value, 'resolve_expression'):
19-
return value
20-
21-
# MySQL doesn't support tz-aware datetimes
22-
if timezone.is_aware(value):
23-
if settings.USE_TZ:
24-
value = timezone.make_naive(value, self.connection.timezone)
25-
else:
26-
raise ValueError(
27-
"IRIS backend does not support timezone-aware datetimes when USE_TZ is False.")
28-
return str(value).split("+")[0]
29-
3016
def last_insert_id(self, cursor, table_name, pk_name):
3117
cursor.execute("SELECT TOP 1 %(pk)s FROM %(table)s ORDER BY %(pk)s DESC" % {
3218
'table': table_name,
@@ -60,3 +46,39 @@ def limit_offset_sql(self, low_mark, high_mark):
6046
# ('LIMIT %d' % limit) if limit else None,
6147
# ('OFFSET %d' % offset) if offset else None,
6248
) if sql)
49+
50+
def adapt_datetimefield_value(self, value):
51+
# print('adapt_datetimefield_value', value)
52+
# print(*traceback.format_stack(), sep='\n')
53+
if value is None:
54+
return None
55+
# Expression values are adapted by the database.
56+
if hasattr(value, 'resolve_expression'):
57+
return value
58+
59+
value = int(value.timestamp() * 1000000)
60+
if value >= 0:
61+
value += 2 ** 60
62+
else:
63+
value += -(2 ** 61 * 3)
64+
65+
return str(value)
66+
# return str(value).split("+")[0]
67+
68+
def get_db_converters(self, expression):
69+
converters = super().get_db_converters(expression)
70+
internal_type = expression.output_field.get_internal_type()
71+
if internal_type == "DateTimeField":
72+
converters.append(self.convert_datetimefield_value)
73+
return converters
74+
75+
def convert_datetimefield_value(self, value, expression, connection):
76+
# print('convert_datetimefield_value', value, expression)
77+
if isinstance(value, int):
78+
if value > 0:
79+
value -= 2 ** 60
80+
else:
81+
value -= -(2 ** 61 * 3)
82+
value = value / 1000000
83+
value = datetime.fromtimestamp(value)
84+
return value

0 commit comments

Comments
 (0)