| 289 | |
| 290 | # Fetch connection pool settings |
| 291 | opts = self.settings_dict['DATABASE_OPTIONS'] |
| 292 | if not isinstance(opts, dict): |
| 293 | # Insurance against foolish users... |
| 294 | opts = {} |
| 295 | if opts.get('SESSION_POOL', False): |
| 296 | self._use_pool = True |
| 297 | self._pool_settings = dict(self._pool_defaults) |
| 298 | self._pool_settings.update(opts) |
| 299 | else: |
| 300 | self._use_pool = False |
| 301 | |
| 302 | def _get_pool (self): |
| 303 | if not hasattr (self.__class__, '_pool'): |
| 304 | settings_dict = self.settings_dict |
| 305 | Database.OPT_Threading = 1 |
| 306 | if len(settings_dict['DATABASE_HOST'].strip()) == 0: |
| 307 | settings_dict['DATABASE_HOST'] = 'localhost' |
| 308 | if len(settings_dict['DATABASE_PORT'].strip()) != 0: |
| 309 | dsn = Database.makedsn(settings_dict['DATABASE_HOST'], |
| 310 | int(settings_dict['DATABASE_PORT']), |
| 311 | settings_dict['DATABASE_NAME']) |
| 312 | p = Database.SessionPool(settings_dict['DATABASE_USER'], |
| 313 | settings_dict['DATABASE_PASSWORD'], |
| 314 | dsn, |
| 315 | self._pool_settings['SESSION_POOL_MIN'], |
| 316 | self._pool_settings['SESSION_POOL_MAX'], |
| 317 | self._pool_settings['SESSION_POOL_INCREMENT'], |
| 318 | threaded = True) |
| 319 | else: |
| 320 | p = Database.SessionPool(settings_dict['DATABASE_USER'], |
| 321 | settings_dict['DATABASE_PASSWORD'], |
| 322 | settings_dict['DATABASE_NAME'], |
| 323 | self._pool_settings['SESSION_POOL_MIN'], |
| 324 | self._pool_settings['SESSION_POOL_MAX'], |
| 325 | self._pool_settings['SESSION_POOL_INCREMENT'], |
| 326 | threaded = True) |
| 327 | setattr(self.__class__, '_pool', p) |
| 328 | # TODO I think the init stuff only needs to happen once per pool, |
| 329 | # but it may be once per connection... |
| 330 | conn = p.acquire() |
| 331 | self._init_oracle_settings(conn) |
| 332 | p.release(conn) |
| 333 | return getattr(self.__class__, '_pool') |
| 353 | def _init_oracle_settings(self, connection): |
| 354 | cursor = FormatStylePlaceholderCursor(connection) |
| 355 | # Set oracle date to ansi date format. This only needs to execute |
| 356 | # once when we create a new connection. We also set the Territory |
| 357 | # to 'AMERICA' which forces Sunday to evaluate to a '1' in TO_CHAR(). |
| 358 | cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS' " |
| 359 | "NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF' " |
| 360 | "NLS_TERRITORY = 'AMERICA'") |
| 361 | try: |
| 362 | self.oracle_version = int(connection.version.split('.')[0]) |
| 363 | # There's no way for the DatabaseOperations class to know the |
| 364 | # currently active Oracle version, so we do some setups here. |
| 365 | # TODO: Multi-db support will need a better solution (a way to |
| 366 | # communicate the current version). |
| 367 | if self.oracle_version <= 9: |
| 368 | self.ops.regex_lookup = self.ops.regex_lookup_9 |
| 369 | else: |
| 370 | self.ops.regex_lookup = self.ops.regex_lookup_10 |
| 371 | except ValueError: |
| 372 | pass |
| 373 | return cursor |
| 374 | |
306 | | conn_string = self._connect_string() |
307 | | self.connection = Database.connect(conn_string, **self.settings_dict['DATABASE_OPTIONS']) |
308 | | cursor = FormatStylePlaceholderCursor(self.connection) |
309 | | # Set oracle date to ansi date format. This only needs to execute |
310 | | # once when we create a new connection. We also set the Territory |
311 | | # to 'AMERICA' which forces Sunday to evaluate to a '1' in TO_CHAR(). |
312 | | cursor.execute("ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS' " |
313 | | "NLS_TIMESTAMP_FORMAT = 'YYYY-MM-DD HH24:MI:SS.FF' " |
314 | | "NLS_TERRITORY = 'AMERICA'") |
| 378 | if self._use_pool and self.pool is not None: |
| 379 | self.connection = self.pool.acquire() |
| 380 | else: |
| 381 | self.connection = Database.connect(self._connect_string() |
| 382 | **self.settings_dict['DATABASE_OPTIONS']) |
| 383 | cursor = self._init_oracle_settings(self.connection) |
316 | | self.oracle_version = int(self.connection.version.split('.')[0]) |
317 | | # There's no way for the DatabaseOperations class to know the |
318 | | # currently active Oracle version, so we do some setups here. |
319 | | # TODO: Multi-db support will need a better solution (a way to |
320 | | # communicate the current version). |
321 | | if self.oracle_version <= 9: |
322 | | self.ops.regex_lookup = self.ops.regex_lookup_9 |
323 | | else: |
324 | | self.ops.regex_lookup = self.ops.regex_lookup_10 |
325 | | except ValueError: |
326 | | pass |
327 | | try: |