Skip to content

Commit d41a08e

Browse files
Fixed bug in identifying bind variables in SQL statements containing a
single line comment at the end of the statement.
1 parent fbafc1d commit d41a08e

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Thin Mode Changes
2020
#) Fixed regression when using IAM token authentication
2121
(`issue 288 <https://github.com/oracle/python-oracledb/issues/288>`__).
2222
#) Fixed bug when using DRCP with :ref:`asyncio <asyncio>`.
23+
#) Fixed bug in identifying bind variables in SQL statements containing a
24+
single line comment at the end of the statement.
2325

2426
Thick Mode Changes
2527
++++++++++++++++++

src/oracledb/impl/thin/statement.pyx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ cdef class Parser:
200200
cdef int _parse_single_line_comment(self) except -1:
201201
"""
202202
Single line comments consist of two dashes and all characters up to the
203-
next line break. This method is called when the first dash is detected
204-
and checks for the subsequent dash. If found, the single line comment
205-
is traversed and the current position is updated; otherwise, the
206-
current position is left untouched.
203+
next line break (or the end of the data). This method is called when
204+
the first dash is detected and checks for the subsequent dash. If
205+
found, the single line comment is traversed and the current position is
206+
updated; otherwise, the current position is left untouched.
207207
"""
208208
cdef:
209209
ssize_t pos = self.pos + 1
@@ -213,12 +213,12 @@ cdef class Parser:
213213
ch = cpython.PyUnicode_READ(self.sql_kind, self.sql_data, pos)
214214
if not in_comment:
215215
if ch != '-':
216-
break
216+
return 0
217217
in_comment = True
218218
elif cpython.Py_UNICODE_ISLINEBREAK(ch):
219-
self.pos = pos
220219
break
221220
pos += 1
221+
self.pos = pos
222222

223223
cdef int parse(self, Statement stmt) except -1:
224224
"""

tests/test_5200_sql_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_5200(self):
3636
"5200 - single line comment"
3737
self.cursor.prepare(
3838
"--begin :value2 := :a + :b + :c +:a +3; end;\n"
39-
"begin :value2 := :a + :c +3; end;"
39+
"begin :value2 := :a + :c +3; end; -- not a :bind_variable"
4040
)
4141
self.assertEqual(self.cursor.bindnames(), ["VALUE2", "A", "C"])
4242

0 commit comments

Comments
 (0)