@@ -157,30 +157,25 @@ def __init__(self, *args, **kwargs):
157
157
158
158
159
159
def get_connection_params (self ):
160
+ params = {}
161
+
162
+ params ["connection_string" ] = self ._get_connection_string ()
160
163
settings_dict = self .settings_dict
161
- if not settings_dict ['NAME' ]:
162
- from django .core .exceptions import ImproperlyConfigured
163
- raise ImproperlyConfigured (
164
- "settings.DATABASES is improperly configured. "
165
- "Please supply the NAME value." )
166
- conn_params = {
167
- 'database' : settings_dict ['NAME' ],
168
- }
169
- conn_params .update (settings_dict ['OPTIONS' ])
170
- if 'autocommit' in conn_params :
171
- del conn_params ['autocommit' ]
172
- if settings_dict ['USER' ]:
173
- conn_params ['user' ] = settings_dict ['USER' ]
174
- if settings_dict ['PASSWORD' ]:
175
- conn_params ['password' ] = settings_dict ['PASSWORD' ]
176
- if settings_dict ['HOST' ]:
177
- conn_params ['host' ] = settings_dict ['HOST' ]
178
- if settings_dict ['PORT' ]:
179
- conn_params ['port' ] = settings_dict ['PORT' ]
180
- return conn_params
164
+ options = settings_dict ['OPTIONS' ]
165
+ autocommit = options .get ('autocommit' , False )
166
+ params ["autocommit" ] = autocommit
167
+
168
+ return params
181
169
182
170
def get_new_connection (self , conn_params ):
183
- return Database .connect (** conn_params )
171
+ connstr = conn_params ["connection_string" ]
172
+ autocommit = conn_params .get ('autocommit' , False )
173
+
174
+ if self .unicode_results :
175
+ return Database .connect (connstr , autocommit = autocommit ,
176
+ unicode_results = 'True' )
177
+ else :
178
+ return Database .connect (connstr , autocommit = autocommit )
184
179
185
180
def init_connection_state (self ):
186
181
pass
@@ -271,16 +266,9 @@ def _cursor(self):
271
266
272
267
if self .connection is None :
273
268
new_conn = True
274
- connstr = self ._get_connection_string ()#';'.join(cstr_parts)
275
- options = settings_dict ['OPTIONS' ]
276
- autocommit = options .get ('autocommit' , False )
277
- if self .unicode_results :
278
- self .connection = Database .connect (connstr , \
279
- autocommit = autocommit , \
280
- unicode_results = 'True' )
281
- else :
282
- self .connection = Database .connect (connstr , \
283
- autocommit = autocommit )
269
+ params = self .get_connection_params ()
270
+
271
+ self .connection = self .get_new_connection (params )
284
272
connection_created .send (sender = self .__class__ , connection = self )
285
273
286
274
cursor = self .connection .cursor ()
0 commit comments