3
3
from django .db .backends .base .creation import BaseDatabaseCreation
4
4
from django .core .exceptions import ImproperlyConfigured
5
5
from django .utils .asyncio import async_unsafe
6
+ from django .utils .functional import cached_property
7
+ from django .db .utils import DatabaseErrorWrapper
6
8
7
9
from .introspection import DatabaseIntrospection
8
10
from .features import DatabaseFeatures
12
14
from .creation import DatabaseCreation
13
15
from .validation import DatabaseValidation
14
16
15
- import intersystems_iris as Database
16
-
17
-
18
- Database .Warning = type ("StandardError" , (object ,), {})
19
- Database .Error = type ("StandardError" , (object ,), {})
20
-
21
- Database .InterfaceError = type ("Error" , (object ,), {})
22
-
23
- Database .DatabaseError = type ("Error" , (object ,), {})
24
- Database .DataError = type ("DatabaseError" , (object ,), {})
25
- Database .OperationalError = type ("DatabaseError" , (object ,), {})
26
- Database .IntegrityError = type ("DatabaseError" , (object ,), {})
27
- Database .InternalError = type ("DatabaseError" , (object ,), {})
28
- Database .ProgrammingError = type ("DatabaseError" , (object ,), {})
29
- Database .NotSupportedError = type ("DatabaseError" , (object ,), {})
17
+ import intersystems_iris .dbapi ._DBAPI as Database
30
18
31
19
32
20
def ignore (* args , ** kwargs ):
@@ -41,8 +29,8 @@ class DatabaseWrapper(BaseDatabaseWrapper):
41
29
display_name = 'InterSystems IRIS'
42
30
43
31
data_types = {
44
- 'AutoField' : 'INTEGER AUTO_INCREMENT ' ,
45
- 'BigAutoField' : 'BIGINT AUTO_INCREMENT ' ,
32
+ 'AutoField' : 'IDENTITY ' ,
33
+ 'BigAutoField' : 'IDENTITY ' ,
46
34
'BinaryField' : 'LONG BINARY' ,
47
35
'BooleanField' : 'BIT' ,
48
36
'CharField' : 'VARCHAR(%(max_length)s)' ,
@@ -63,7 +51,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
63
51
'PositiveIntegerField' : 'INTEGER' ,
64
52
'PositiveSmallIntegerField' : 'SMALLINT' ,
65
53
'SlugField' : 'VARCHAR(%(max_length)s)' ,
66
- 'SmallAutoField' : 'SMALLINT AUTO_INCREMENT ' ,
54
+ 'SmallAutoField' : 'IDENTITY ' ,
67
55
'SmallIntegerField' : 'SMALLINT' ,
68
56
'TextField' : 'TEXT' ,
69
57
'TimeField' : 'TIME(6)' ,
@@ -81,20 +69,31 @@ class DatabaseWrapper(BaseDatabaseWrapper):
81
69
'gte' : '>= %s' ,
82
70
'lt' : '< %s' ,
83
71
'lte' : '<= %s' ,
84
- 'startswith' : "%%%%STARTSWITH %s" ,
72
+ 'startswith' : "LIKE %s ESCAPE ' \\ ' " ,
85
73
'endswith' : "LIKE %s ESCAPE '\\ '" ,
86
- 'istartswith' : "%%%%STARTSWITH %s" ,
74
+ 'istartswith' : "LIKE %s ESCAPE ' \\ ' " ,
87
75
'iendswith' : "LIKE %s ESCAPE '\\ '" ,
76
+ }
77
+
78
+ pattern_esc = r"REPLACE(REPLACE(REPLACE({}, '\', '\\'), '%%', '\%%'), '_', '\_')"
79
+ pattern_ops = {
80
+ "contains" : "LIKE '%%' || {} || '%%'" ,
81
+ "icontains" : "LIKE '%%' || UPPER({}) || '%%'" ,
82
+ "startswith" : "LIKE {} || '%%'" ,
83
+ "istartswith" : "LIKE UPPER({}) || '%%'" ,
84
+ "endswith" : "LIKE '%%' || {}" ,
85
+ "iendswith" : "LIKE '%%' || UPPER({})" ,
88
86
89
87
}
88
+
90
89
Database = Database
91
90
92
- _commit = ignore
93
- _rollback = ignore
94
- _savepoint = ignore
95
- _savepoint_commit = ignore
96
- _savepoint_rollback = ignore
97
- _set_autocommit = ignore
91
+ # _commit = ignore
92
+ # _rollback = ignore
93
+ # _savepoint = ignore
94
+ # _savepoint_commit = ignore
95
+ # _savepoint_rollback = ignore
96
+ # _set_autocommit = ignore
98
97
99
98
SchemaEditorClass = DatabaseSchemaEditor
100
99
@@ -105,6 +104,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
105
104
ops_class = DatabaseOperations
106
105
validation_class = DatabaseValidation
107
106
107
+ _disable_constraint_checking = False
108
108
109
109
def get_connection_params (self ):
110
110
settings_dict = self .settings_dict
@@ -134,10 +134,10 @@ def get_connection_params(self):
134
134
conn_params ['hostname' ] = settings_dict ['HOST' ]
135
135
if settings_dict ['PORT' ]:
136
136
conn_params ['port' ] = settings_dict ['PORT' ]
137
- if settings_dict ['NAME' ]:
138
- conn_params ['namespace' ] = settings_dict ['NAME' ]
139
137
if 'NAMESPACE' in settings_dict :
140
138
conn_params ['namespace' ] = settings_dict ['NAMESPACE' ]
139
+ if settings_dict ['NAME' ]:
140
+ conn_params ['namespace' ] = settings_dict ['NAME' ]
141
141
142
142
if (
143
143
not conn_params ['hostname' ] or
@@ -158,16 +158,24 @@ def get_connection_params(self):
158
158
"Please supply the USER and PASSWORD"
159
159
)
160
160
161
+ conn_params ['application_name' ] = 'django'
162
+ conn_params ["autoCommit" ] = self .autocommit
161
163
return conn_params
162
164
165
+ def init_connection_state (self ):
166
+ pass
167
+
163
168
@async_unsafe
164
169
def get_new_connection (self , conn_params ):
165
170
return Database .connect (** conn_params )
166
171
167
- def init_connection_state (self ):
168
- cursor = self .connection .cursor ()
169
- # cursor.callproc('%SYSTEM_SQL.Util_SetOption', ['SELECTMODE', 1])
170
- # cursor.callproc('%SYSTEM.SQL_SetSelectMode', [1])
172
+ def _close (self ):
173
+ if self .connection is not None :
174
+ # Automatically rollbacks anyway
175
+ # self.in_atomic_block = False
176
+ # self.needs_rollback = False
177
+ with self .wrap_database_errors :
178
+ return self .connection .close ()
171
179
172
180
@async_unsafe
173
181
def create_cursor (self , name = None ):
@@ -182,3 +190,29 @@ def is_usable(self):
182
190
return False
183
191
else :
184
192
return True
193
+
194
+ @cached_property
195
+ def wrap_database_errors (self ):
196
+ """
197
+ Context manager and decorator that re-throws backend-specific database
198
+ exceptions using Django's common wrappers.
199
+ """
200
+ return DatabaseErrorWrapper (self )
201
+
202
+ def _set_autocommit (self , autocommit ):
203
+ with self .wrap_database_errors :
204
+ self .connection .setAutoCommit (autocommit )
205
+
206
+ def disable_constraint_checking (self ):
207
+ self ._disable_constraint_checking = True
208
+ return True
209
+
210
+ def enable_constraint_checking (self ):
211
+ self ._disable_constraint_checking = False
212
+
213
+ @async_unsafe
214
+ def savepoint_commit (self , sid ):
215
+ """
216
+ IRIS does not have `RELEASE SAVEPOINT`
217
+ so, just ignore it
218
+ """
0 commit comments