Raise cx_Oracle.DatabaseError, not IndexError for a scroll operation that

would position the cursor outside of the result set.
This commit is contained in:
Anthony Tuininga 2017-02-03 09:01:47 -07:00
parent 0bcbd072a8
commit 73f61d8a07
3 changed files with 9 additions and 7 deletions

View File

@ -418,8 +418,8 @@ Cursor Object
positioned at the first row and if set to "last", the cursor is set to the positioned at the first row and if set to "last", the cursor is set to the
last row in the result set. last row in the result set.
An IndexError is raised if the mode is "relative" or "absolute" and the An error is raised if the mode is "relative" or "absolute" and the scroll
scroll operation would position the cursor outside of the result set. operation would position the cursor outside of the result set.
.. versionadded:: development .. versionadded:: development

View File

@ -2197,7 +2197,7 @@ static PyObject *Cursor_Scroll(
// handle the case when no rows have been retrieved // handle the case when no rows have been retrieved
if (self->bufferRowCount == 0) { if (self->bufferRowCount == 0) {
if (fetchMode != OCI_FETCH_FIRST && fetchMode != OCI_FETCH_LAST) { if (fetchMode != OCI_FETCH_FIRST && fetchMode != OCI_FETCH_LAST) {
PyErr_SetString(PyExc_IndexError, PyErr_SetString(g_DatabaseErrorException,
"requested scroll operation would leave result set"); "requested scroll operation would leave result set");
return NULL; return NULL;
} }

View File

@ -254,7 +254,8 @@ class TestCursor(BaseTestCase):
select NumberCol select NumberCol
from TestNumbers from TestNumbers
order by IntCol""") order by IntCol""")
self.assertRaises(IndexError, cursor.scroll, 12, "absolute") self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 12,
"absolute")
def testScrollAbsoluteInBuffer(self): def testScrollAbsoluteInBuffer(self):
"""test scrolling absolute (when in buffers)""" """test scrolling absolute (when in buffers)"""
@ -335,7 +336,7 @@ class TestCursor(BaseTestCase):
select NumberCol select NumberCol
from TestNumbers from TestNumbers
order by IntCol""") order by IntCol""")
self.assertRaises(IndexError, cursor.scroll, 15) self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 15)
def testScrollRelativeExceptionBefore(self): def testScrollRelativeExceptionBefore(self):
"""test scrolling relative yields an exception (before result set)""" """test scrolling relative yields an exception (before result set)"""
@ -345,7 +346,7 @@ class TestCursor(BaseTestCase):
select NumberCol select NumberCol
from TestNumbers from TestNumbers
order by IntCol""") order by IntCol""")
self.assertRaises(IndexError, cursor.scroll, -5) self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, -5)
def testScrollRelativeInBuffer(self): def testScrollRelativeInBuffer(self):
"""test scrolling relative (when in buffers)""" """test scrolling relative (when in buffers)"""
@ -389,7 +390,8 @@ class TestCursor(BaseTestCase):
self.assertEqual(cursor.fetchall(), []) self.assertEqual(cursor.fetchall(), [])
cursor.scroll(mode = "first") cursor.scroll(mode = "first")
self.assertEqual(cursor.fetchall(), []) self.assertEqual(cursor.fetchall(), [])
self.assertRaises(IndexError, cursor.scroll, 1, mode = "absolute") self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 1,
mode = "absolute")
def testScrollDifferingArrayAndFetchSizes(self): def testScrollDifferingArrayAndFetchSizes(self):
"""test scrolling with differing array sizes and fetch array sizes""" """test scrolling with differing array sizes and fetch array sizes"""