From 73f61d8a07537baa838f1965c0fcd648e2ac4cbd Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Fri, 3 Feb 2017 09:01:47 -0700 Subject: [PATCH] Raise cx_Oracle.DatabaseError, not IndexError for a scroll operation that would position the cursor outside of the result set. --- doc/cursor.rst | 4 ++-- src/Cursor.c | 2 +- test/Cursor.py | 10 ++++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/doc/cursor.rst b/doc/cursor.rst index ae990ef..5b6b1df 100644 --- a/doc/cursor.rst +++ b/doc/cursor.rst @@ -418,8 +418,8 @@ Cursor Object positioned at the first row and if set to "last", the cursor is set to the last row in the result set. - An IndexError is raised if the mode is "relative" or "absolute" and the - scroll operation would position the cursor outside of the result set. + An error is raised if the mode is "relative" or "absolute" and the scroll + operation would position the cursor outside of the result set. .. versionadded:: development diff --git a/src/Cursor.c b/src/Cursor.c index d2c4ea2..e91b0f2 100644 --- a/src/Cursor.c +++ b/src/Cursor.c @@ -2197,7 +2197,7 @@ static PyObject *Cursor_Scroll( // handle the case when no rows have been retrieved if (self->bufferRowCount == 0) { if (fetchMode != OCI_FETCH_FIRST && fetchMode != OCI_FETCH_LAST) { - PyErr_SetString(PyExc_IndexError, + PyErr_SetString(g_DatabaseErrorException, "requested scroll operation would leave result set"); return NULL; } diff --git a/test/Cursor.py b/test/Cursor.py index 0f30fc7..dbe036e 100644 --- a/test/Cursor.py +++ b/test/Cursor.py @@ -254,7 +254,8 @@ class TestCursor(BaseTestCase): select NumberCol from TestNumbers order by IntCol""") - self.assertRaises(IndexError, cursor.scroll, 12, "absolute") + self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 12, + "absolute") def testScrollAbsoluteInBuffer(self): """test scrolling absolute (when in buffers)""" @@ -335,7 +336,7 @@ class TestCursor(BaseTestCase): select NumberCol from TestNumbers order by IntCol""") - self.assertRaises(IndexError, cursor.scroll, 15) + self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, 15) def testScrollRelativeExceptionBefore(self): """test scrolling relative yields an exception (before result set)""" @@ -345,7 +346,7 @@ class TestCursor(BaseTestCase): select NumberCol from TestNumbers order by IntCol""") - self.assertRaises(IndexError, cursor.scroll, -5) + self.assertRaises(cx_Oracle.DatabaseError, cursor.scroll, -5) def testScrollRelativeInBuffer(self): """test scrolling relative (when in buffers)""" @@ -389,7 +390,8 @@ class TestCursor(BaseTestCase): self.assertEqual(cursor.fetchall(), []) cursor.scroll(mode = "first") 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): """test scrolling with differing array sizes and fetch array sizes"""