mirror of
https://github.com/sqlalchemy/sqlalchemy.git
synced 2026-05-31 04:48:02 -04:00
- cx_Oracle.makedsn can now be passed service_name; squash
commit of pr152
This commit is contained in:
committed by
Mike Bayer
parent
a14729266a
commit
3db84b174a
Vendored
+8
@@ -23,6 +23,14 @@
|
||||
series as well. For changes that are specific to 1.0 with an emphasis
|
||||
on compatibility concerns, see :doc:`/changelog/migration_10`.
|
||||
|
||||
.. change::
|
||||
:tags: feature, oracle
|
||||
:pullreq: github:152
|
||||
|
||||
Added support for cx_oracle connections to a specific service
|
||||
name, as opposed to a tns name, by passing ``?service_name=<name>``
|
||||
to the URL. Pull request courtesy Sławomir Ehlert.
|
||||
|
||||
.. change::
|
||||
:tags: feature, mysql
|
||||
:tickets: 3155
|
||||
|
||||
@@ -61,6 +61,12 @@ on the URL, or as keyword arguments to :func:`.create_engine()` are:
|
||||
Defaults to ``True``. Note that this is the opposite default of the
|
||||
cx_Oracle DBAPI itself.
|
||||
|
||||
* ``service_name`` - An option to use connection string (DSN) with
|
||||
``SERVICE_NAME`` instead of ``SID``. It can't be passed when a ``database``
|
||||
part is given.
|
||||
E.g. ``oracle+cx_oracle://scott:tiger@host:1521/?service_name=hr``
|
||||
is a valid url. This value is only available as a URL query string argument.
|
||||
|
||||
.. _cx_oracle_unicode:
|
||||
|
||||
Unicode
|
||||
@@ -862,14 +868,26 @@ class OracleDialect_cx_oracle(OracleDialect):
|
||||
util.coerce_kw_type(dialect_opts, opt, bool)
|
||||
setattr(self, opt, dialect_opts[opt])
|
||||
|
||||
if url.database:
|
||||
database = url.database
|
||||
service_name = dialect_opts.get('service_name', None)
|
||||
if database or service_name:
|
||||
# if we have a database, then we have a remote host
|
||||
port = url.port
|
||||
if port:
|
||||
port = int(port)
|
||||
else:
|
||||
port = 1521
|
||||
dsn = self.dbapi.makedsn(url.host, port, url.database)
|
||||
|
||||
if database and service_name:
|
||||
raise exc.InvalidRequestError(
|
||||
'"service_name" option shouldn\'t '
|
||||
'be used with a "database" part of the url')
|
||||
if database:
|
||||
makedsn_kwargs = {'sid': database}
|
||||
if service_name:
|
||||
makedsn_kwargs = {'service_name': service_name}
|
||||
|
||||
dsn = self.dbapi.makedsn(url.host, port, **makedsn_kwargs)
|
||||
else:
|
||||
# we have a local tnsname
|
||||
dsn = url.host
|
||||
|
||||
@@ -2074,3 +2074,23 @@ class DBLinkReflectionTest(fixtures.TestBase):
|
||||
autoload_with=testing.db, oracle_resolve_synonyms=True)
|
||||
eq_(list(t.c.keys()), ['id', 'data'])
|
||||
eq_(list(t.primary_key), [t.c.id])
|
||||
|
||||
|
||||
class ServiceNameTest(fixtures.TestBase):
|
||||
__only_on__ = 'oracle+cx_oracle'
|
||||
|
||||
def test_cx_oracle_service_name(self):
|
||||
url_string = 'oracle+cx_oracle://scott:tiger@host/?service_name=hr'
|
||||
eng = create_engine(url_string, _initialize=False)
|
||||
cargs, cparams = eng.dialect.create_connect_args(eng.url)
|
||||
|
||||
assert 'SERVICE_NAME=hr' in cparams['dsn']
|
||||
assert 'SID=hr' not in cparams['dsn']
|
||||
|
||||
def test_cx_oracle_service_name_bad(self):
|
||||
url_string = 'oracle+cx_oracle://scott:tiger@host/hr1?service_name=hr2'
|
||||
assert_raises(
|
||||
exc.InvalidRequestError,
|
||||
create_engine, url_string,
|
||||
_initialize=False
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user