Skip to content

Commit

Permalink
Resolve fetchall() does not return error
Browse files Browse the repository at this point in the history
Signed-off-by: Balram Choudhary <[email protected]>
  • Loading branch information
bchoudhary6415 committed Jan 28, 2025
1 parent 1923813 commit f40ef6e
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ibm_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -15505,7 +15505,7 @@ static PyObject* ibm_db_fetchmany(PyObject *self, PyObject *args)
// Fetch all rows from the result set
static PyObject *ibm_db_fetchall(PyObject *self, PyObject *args)
{
LogMsg(INFO, "entry fetchmany()", fileName);
LogMsg(INFO, "entry fetchall()", fileName);
PyObject *argsStr = PyObject_Repr(args); // Get string representation of args
snprintf(messageStr, sizeof(messageStr), "Received arguments: %s", PyUnicode_AsUTF8(argsStr));
LogMsg(INFO, messageStr, fileName);
Expand Down
6 changes: 1 addition & 5 deletions ibm_db_dbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1792,15 +1792,11 @@ def _fetch_helper(self, fetch_size=-1):
error_msg = f"Statement error: {str(ibm_db.stmt_errormsg())}"
LogMsg(ERROR, error_msg)
self.messages.append(Error(str(ibm_db.stmt_errormsg())))
raise self.messages[len(self.messages) - 1]
else:
LogMsg(ERROR, f"Error occured : {_get_exception(inst)}")
self.messages.append(_get_exception(inst))
if len(row_list) == 0:
raise self.messages[len(self.messages) - 1]
else:
LogMsg(DEBUG, f"Returning {row_list} from _fetch_helper()")
LogMsg(INFO, "exit _fetch_helper()")
return row_list

if row != False:
if self.FIX_RETURN_TYPE == 1:
Expand Down
73 changes: 73 additions & 0 deletions ibm_db_tests/test_315_FetchAll_DBI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#
# Licensed Materials - Property of IBM
#
# (c) Copyright IBM Corp. 2007-2008
#

from __future__ import print_function
import sys
import unittest
import ibm_db
import ibm_db_dbi
import config
from testfunctions import IbmDbTestFunctions


class IbmDbTestCase(unittest.TestCase):

def test_315_FetchAll_DBI(self):
obj = IbmDbTestFunctions()
obj.assert_expect(self.run_test_315)

def run_test_315(self):
conn = ibm_db.connect(config.database, config.user, config.password)

ibm_db.autocommit(conn, ibm_db.SQL_AUTOCOMMIT_OFF)

# Drop the test table, in case it exists
drop = 'DROP TABLE varigraph'
try:
result = ibm_db.exec_immediate(conn, drop)
except:
pass

# Create the test table
create = 'CREATE TABLE varigraph( i INT, g VARGRAPHIC(10000))'
result = ibm_db.exec_immediate(conn, create)

vargraphic_string = "a" * 8192

insert_sql = "INSERT INTO varigraph (i, g) VALUES (?, ?)"
stmt = ibm_db.prepare(conn, insert_sql)

ibm_db.bind_param(stmt, 1, 0)
ibm_db.bind_param(stmt, 2, 'hogehoge')
ibm_db.execute(stmt)

ibm_db.bind_param(stmt, 1, 1)
ibm_db.bind_param(stmt, 2, vargraphic_string)
ibm_db.execute(stmt)

db2_conn = ibm_db_dbi.Connection(conn)
db2_cur = db2_conn.cursor()

sql = "SELECT i, length(g||g) FROM varigraph"

try:
db2_conn.cursor()
db2_cur.execute(sql)
for (i, len) in db2_cur.fetchall():
print("i: {} , len: {} ".format(i, len))
except:
err = ibm_db.stmt_errormsg()
print(err)

#__END__
#__LUW_EXPECTED__
#[IBM][CLI Driver][DB2/LINUXX8664] SQL0137N The length resulting from "CONCAT" is greater than "0000016350 ". SQLSTATE=54006 SQLCODE=-137
#__ZOS_EXPECTED__
#[IBM][CLI Driver][DB2/LINUXX8664] SQL0137N The length resulting from "CONCAT" is greater than "0000016350 ". SQLSTATE=54006 SQLCODE=-137
#__SYSTEMI_EXPECTED__
#[IBM][CLI Driver][AS] SQL0137N The length resulting from "CONCAT" is greater than "0000016350 ". SQLSTATE=54006 SQLCODE=-137
#__IDS_EXPECTED__
#[IBM][CLI Driver][IDS/LINUXX8664] SQL0137N The length resulting from "CONCAT" is greater than "0000016350 ". SQLSTATE=54006 SQLCODE=-137

0 comments on commit f40ef6e

Please sign in to comment.