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