Skip to content

Commit 25d5468

Browse files
The complete connect string is now sent to the server instead of just
the actual components being used. This is important for some configurations.
1 parent 62d7800 commit 25d5468

File tree

7 files changed

+20
-18
lines changed

7 files changed

+20
-18
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Thin Mode Changes
3131
:data:`~oracledb.DB_TYPE_UROWID` that exceed 3950 bytes in length.
3232
#) Fixed bug preventing correct parsing of connect descriptors with both
3333
ADDRESS and ADDRESS_LIST components at the same level.
34+
#) The complete connect string is now sent to the server instead of just the
35+
actual components being used. This is important for some configurations.
3436

3537
Thick Mode Changes
3638
++++++++++++++++++

src/oracledb/base_impl.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ cdef class Description:
136136
public str wallet_location
137137

138138
cdef str _build_duration_str(self, double value)
139-
cdef str build_connect_string(self)
139+
cdef str build_connect_string(self, str cid=*)
140140

141141

142142
cdef class DescriptionList:

src/oracledb/impl/base/connect_params.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ cdef class Description:
707707
return f"{value_minutes}min"
708708
return f"{value_int}"
709709

710-
cdef str build_connect_string(self):
710+
cdef str build_connect_string(self, str cid=None):
711711
"""
712712
Build a connect string from the components.
713713
"""
@@ -728,10 +728,14 @@ cdef class Description:
728728
parts.append(f"(POOL_CONNECTION_CLASS={self.cclass})")
729729
if self.purity != 0:
730730
parts.append(f"(POOL_PURITY={self.purity})")
731+
if cid is not None:
732+
parts.append(f"(CID={cid})")
731733
connect_data = f'(CONNECT_DATA={"".join(parts)})'
732734

733735
# build security segment, if applicable
734-
parts = [f"(SSL_SERVER_DN_MATCH={self.ssl_server_dn_match})"]
736+
parts = []
737+
if self.ssl_server_dn_match:
738+
parts.append("(SSL_SERVER_DN_MATCH=ON)")
735739
if self.ssl_server_cert_dn is not None:
736740
parts.append(f"(SSL_SERVER_CERT_DN={self.ssl_server_cert_dn})")
737741
if self.wallet_location is not None:

src/oracledb/impl/thin/connection.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ cdef class ThinConnImpl(BaseConnImpl):
9191
cdef int _connect_with_address(self, Address address,
9292
Description description,
9393
ConnectParamsImpl params,
94+
str connect_string,
9495
bint raise_exception) except -1:
9596
"""
9697
Internal method used for connecting with the given description and
9798
address.
9899
"""
99100
try:
100101
self._protocol._connect_phase_one(self, params, description,
101-
address)
102+
address, connect_string)
102103
except exceptions.DatabaseError:
103104
if raise_exception:
104105
raise
@@ -130,10 +131,12 @@ cdef class ThinConnImpl(BaseConnImpl):
130131
uint32_t num_attempts = description.retry_count + 1
131132
uint32_t num_lists = len(address_lists)
132133
AddressList address_list
134+
str connect_string
133135
Address address
134136
# Retry connecting to the socket if an attempt fails and retry_count
135137
# is specified in the connect string. If an attempt succeeds, return
136138
# the socket and the valid address object.
139+
connect_string = _get_connect_data(description)
137140
for i in range(num_attempts):
138141
# Iterate through each address_list in the description. If the
139142
# description level load_balance is on, keep track of the least
@@ -161,7 +164,7 @@ cdef class ThinConnImpl(BaseConnImpl):
161164
and j == num_lists - 1 \
162165
and k == num_addresses - 1
163166
self._connect_with_address(address, description, params,
164-
raise_exc)
167+
connect_string, raise_exc)
165168
if self._protocol._in_connect:
166169
continue
167170
address_list.lru_index = (idx1 + 1) % num_addresses

src/oracledb/impl/thin/protocol.pyx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,18 @@ cdef class Protocol:
120120
ThinConnImpl conn_impl,
121121
ConnectParamsImpl params,
122122
Description description,
123-
Address address) except -1:
123+
Address address,
124+
str connect_string) except -1:
124125
"""
125126
Method for performing the required steps for establishing a connection
126127
within the scope of a retry. If the listener refuses the connection, a
127128
retry will be performed, if retry_count is set.
128129
"""
129130
cdef:
130-
str connect_string, host, redirect_data
131131
ConnectMessage connect_message = None
132132
object ssl_context, connect_info
133133
ConnectParamsImpl temp_params
134+
str host, redirect_data
134135
Address temp_address
135136
uint8_t packet_type
136137
int port, pos
@@ -143,7 +144,6 @@ cdef class Protocol:
143144
host = address.host
144145
port = address.port
145146
self._connect_tcp(params, description, address, host, port)
146-
connect_string = _get_connect_data(address, description)
147147

148148
# send connect message and process response; this may request the
149149
# message to be resent multiple times; if a redirect packet is

src/oracledb/impl/thin/utils.pyx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,15 @@ cdef object _encode_rowid(Rowid *rowid):
8888
return buf[:TNS_MAX_ROWID_LENGTH].decode()
8989

9090

91-
def _get_connect_data(address, description):
91+
cdef str _get_connect_data(Description description):
9292
"""
9393
Return the connect data required by the listener in order to connect.
9494
"""
9595
constants = _connect_constants
96-
server_type = f"(SERVER={description.server_type})" \
97-
if description.server_type is not None else ""
98-
identity = f"(SERVICE_NAME={description.service_name})" \
99-
if description.service_name is not None or \
100-
description.sid is None else f"(SID={description.sid})"
10196
cid = f"(PROGRAM={constants.sanitized_program_name})" + \
10297
f"(HOST={constants.sanitized_machine_name})" + \
10398
f"(USER={constants.sanitized_user_name})"
104-
return f"(DESCRIPTION=(ADDRESS=(PROTOCOL={address.protocol.upper()})" + \
105-
f"(HOST={address.host})(PORT={address.port}))" + \
106-
f"(CONNECT_DATA={identity}{server_type}(CID={cid})))"
99+
return description.build_connect_string(cid)
107100

108101

109102
def _print_packet(operation, socket_fileno, data):

tests/test_4500_connect_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def test_4531_build_connect_string_with_tcp_connect_timeout(self):
481481
f"(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)" + \
482482
f"(HOST={host})(PORT=1521)))(CONNECT_DATA=" + \
483483
f"(SERVICE_NAME={service_name}))" + \
484-
f"(SECURITY=(SSL_SERVER_DN_MATCH=True)))"
484+
f"(SECURITY=(SSL_SERVER_DN_MATCH=ON)))"
485485
self.assertEqual(params.get_connect_string(), connect_string)
486486

487487
def test_4532_multiple_alias_entry_tnsnames(self):

0 commit comments

Comments
 (0)