waliwali / ibm-db

Automatically exported from code.google.com/p/ibm-db
0 stars 0 forks source link

ibm_db.execute raises an exception if I try to debug with pdb after using bind_param with date #18

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I used the following code:
--- CODE BEGIN ---
import os
import ibm_db
import datetime

query = """
SELECT
    CAL_DATE,
    CAL_YEAR
FROM
    DAR.TD_CALENDAR
WHERE
    CAL_DATE > ?
FETCH FIRST 5 ROWS ONLY;
"""

creds_file = os.path.join(os.getenv("HOME"), '.db2w.credentials')
user, passwd = open(creds_file).read().splitlines()[:2]
conn = ibm_db.connect('db2w', user, passwd)
stmt = ibm_db.prepare(conn, query)
how_far = datetime.datetime.now() - datetime.timedelta(hours=200)
print ibm_db.bind_param(stmt, 1, str(how_far.date()),
ibm_db.SQL_PARAM_INPUT, ibm_db.SQL_TYPE_DATE)
print ibm_db.execute(stmt)
row = ibm_db.fetch_tuple(stmt)
while row:
    print row
    row = ibm_db.fetch_tuple(stmt)
--- CODE END ---

2. If I execute the code normally, everything works:
$ python test_query.py 
True
True
('2008-09-23', 2008)
('2008-09-24', 2008)
('2008-09-25', 2008)
('2008-09-26', 2008)
('2008-09-27', 2008)

3. If I try to debug the code, there is an exception:
Sample IPython debugging session:
In [1]: run -d test_query.py
Breakpoint 1 at /home/user/Work/sample_query/test_query.py:1
NOTE: Enter 'c' at the ipdb>  prompt to start your script.
> <string>(1)<module>()

ipdb> c
> /home/user/Work/sample_query/test_query.py(1)<module>()
1---> 1 import os
      2 import ibm_db
      3 import datetime

ipdb> b 23
Breakpoint 2 at /home/user/Work/sample_query/test_query.py:23
ipdb> c
True
> /home/user/Work/sample_query/test_query.py(23)<module>()
     22 print ibm_db.bind_param(stmt, 1, str(how_far.date()),
ibm_db.SQL_PARAM_INPUT, ibm_db.SQL_TYPE_DATE)
2--> 23 print ibm_db.execute(stmt)
     24 row = ibm_db.fetch_tuple(stmt)

ipdb> n
Exception: 'Statement Execute Failed: [IBM][CLI Driver] CLI0113E  SQLSTATE
22007: An invalid datetime format ...d; that is, an invalid string
representation or value was specified. SQLSTATE=22007 SQLCODE=-99999'
> /home/user/Work/sample_query/test_query.py(23)<module>()
     22 print ibm_db.bind_param(stmt, 1, str(how_far.date()),
ibm_db.SQL_PARAM_INPUT, ibm_db.SQL_TYPE_DATE)
2--> 23 print ibm_db.execute(stmt)
     24 row = ibm_db.fetch_tuple(stmt)

ipdb> 

What is the expected output? What do you see instead?
I expect to be able to debug without having an exception.

What version of the product are you using? On what operating system?
Python 2.5, ibm_db 0.3.0, db2level returns:
DB21085I  Instance "user" uses "32" bits and DB2 code release "SQL08028" 
with level identifier "03090106".
Informational tokens are "DB2 v8.1.2.136", "s070720", "MI00189", and FixPak 
"15".
Product is installed at "/opt/IBM/db2/V8.1".

Please provide any additional information below.
I'm on Ubuntu Hardy Heron 8.04.1. The program also raises an exception if I
use plain old pdb.

Original issue reported on code.google.com by fred.dub...@gmail.com on 30 Sep 2008 at 9:06

Attachments:

GoogleCodeExporter commented 9 years ago
Hi Fred,
      I am not able to reproduce this issue. In my case, program is working fine (on 
ubuntu 7.10) for both normal run and in debugging (pdb). I am very surprised 
that 
the code is running fine on normal run and not working while debugging... 

Thanks,
Abhigyan

Original comment by abhigyan...@in.ibm.com on 6 Oct 2008 at 12:18

GoogleCodeExporter commented 9 years ago
After more testing, I noticed that the culprit is this line:

print ibm_db.bind_param(stmt, 1, str(how_far.date()), ibm_db.SQL_PARAM_INPUT,
ibm_db.SQL_TYPE_DATE)

If I replace the above line with this:
param = str(how_far.date())
print ibm_db.bind_param(stmt, 1, param, ibm_db.SQL_PARAM_INPUT, 
ibm_db.SQL_TYPE_DATE)

The execute works in debug mode. Weird.

Original comment by fred.dub...@gmail.com on 6 Oct 2008 at 2:33

GoogleCodeExporter commented 9 years ago
Very strange indeed. But atleast you have a solution now. ;)

Original comment by abhigyan...@in.ibm.com on 7 Oct 2008 at 6:56