Skip to content

Fix #196: CLI0109E String data right truncation in has_table() with pd.read_sql()#197

Merged
bimalkjha merged 1 commit intoibmdb:masterfrom
bchoudhary6415:ibmdbsa_issue
Apr 22, 2026
Merged

Fix #196: CLI0109E String data right truncation in has_table() with pd.read_sql()#197
bimalkjha merged 1 commit intoibmdb:masterfrom
bchoudhary6415:ibmdbsa_issue

Conversation

@bchoudhary6415
Copy link
Copy Markdown
Collaborator

Problem
When using pd.read_sql(sql=query, con=conn) with SQLAlchemy 2.0.47+,
pandas internally calls dialect.has_table() passing the entire SQL query
string as the table_name parameter. Since the SQL string exceeds the
maximum Db2 identifier length (128 bytes), the CLI driver raises:
CLI0109E String data right truncation. SQLSTATE=22001

Additionally, when pd.read_sql(sql=text(query), con=conn) is used,
a TextClause object is passed as table_name, causing:
AttributeError: 'TextClause' object has no attribute 'startswith'

Root Cause
has_table() did not validate the table_name input before querying
SYSCAT.TABLES. Any non-string or oversized input was passed directly
to the database, causing the CLI driver to fail on parameter binding.

Fix
Added input validation guard in has_table() across all reflectors
(DB2Reflector, AS400Reflector, OS390Reflector) and the dialect entry
point (DB2Dialect). If table_name is not a string or exceeds 128
characters (max Db2 table name length on all platforms), return False
immediately without querying the database.

Fixes #196

…r length

Signed-off-by: Balram Choudhary <bchoudhary@rocketsoftware.com>
@bchoudhary6415 bchoudhary6415 self-assigned this Apr 22, 2026
@bimalkjha bimalkjha merged commit ee3e2b9 into ibmdb:master Apr 22, 2026
3 checks passed
@bchoudhary6415 bchoudhary6415 deleted the ibmdbsa_issue branch April 23, 2026 05:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants