Exception: Supplied statement object parameter is invalid

1,366 views
Skip to first unread message

Alexander Shmugliakov

unread,
Mar 15, 2016, 12:00:15 AM3/15/16
to ibm_db
I'm trying to build my first python-django environment. I have installed on my box (Windows 7 Professional) the following:
  • Python 3.4.4
  • Django 1.9.4
  • IBM DB2 ODBC Driver 10.05.500.107
I'm connecting to the DB2 database LADDER via ODBC system DSN (with the same name) which I have tested and which works properly. After installing ibm_db and ibm_db_dbi packages I have the following short script to test the environment (following the article in the IBM Knowledge Base "Verifying the Python driver, SQLAlchemy adapter, and Django adapter installation"

import ibm_db
import ibm_db_dbi

ibm_db_conn = ibm_db.connect('LADDER','*****', '*****')
conn = ibm_db_dbi.Connection(ibm_db_conn)
conn.tables('LADDER', 'PLAYERS')

Running this script results in the following error:

================== RESTART: D:/Python/testDB2Connection.py ==================
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\ibm_db-2.0.6-py3.4.egg\ibm_db_dbi.py", line 815, in tables
    row = ibm_db.fetch_assoc(stmt)
Exception: Supplied statement object parameter is invalid

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/Python/testDB2Connection.py", line 6, in <module>
    conn.tables('LADDER', 'PLAYERS')
  File "C:\Python34\lib\site-packages\ibm_db-2.0.6-py3.4.egg\ibm_db_dbi.py", line 823, in tables
    raise _get_exception(inst)
ibm_db_dbi.Error: ibm_db_dbi::Error: Supplied statement object parameter is invalid

My knowledge of Python is insufficient to understand what and why happens and this is one of the rare case when Google was of no use. Can somebody, please, help me out of this? Thank you.

Best,
Alexander.

amarredd

unread,
Mar 15, 2016, 10:06:22 AM3/15/16
to ibm_db

Hello Alexander,

Your sample is just making use of python ibm_db and it is not using ibm_db_django.
Having said that, your example works fine for me. I am using python 3.4.4

I used sample :

import ibm_db
import ibm_db_dbi

db2conn = ibm_db.connect("database=SAMPLE";",'','')
conn = ibm_db_dbi.Connection(db2conn)


conn.tables('SYSADM', 'T1')


You could omit ibm_db_dbi calls unless you want to use Python Database API Specification v2.0 API.
Example:
import ibm_db
conn=ibm_db.connect('SAMPLE','','')
result = ibm_db.tables(conn, None, '%', "EMP")

i = 0
row = ibm_db.fetch_tuple(result)
while ( row ):
  ibm_db.num_fields(result)
  if (i < 4):
    print(", " + row[1] + ", " + row[2] + ", " + row[3] + ", , \n")
  i = i + 1
  row = ibm_db.fetch_tuple(result)

OutPUT:

, AMARREDD, EMP, TABLE, ,
Auto Generated Inline Image 1
Reply all
Reply to author
Forward
0 new messages