problems displaying results in ibm_db

D

digz

This simple db connectivity and select test program works in the
interactive mode
.... print r
....
13
ABC
4
2009-05-11

The same executed from a script using python testdb.py does not yield
anything , What am I doing wrong ?

import ibm_db
conn = ibm_db.connect( 'DATABASE', 'user', 'pwd')
result = ibm_db.exec_immediate( conn, 'SELECT * FROM TEST FETCH FIRST
1 ROWS ONLY')
row = ibm_db.fetch_tuple( result )
for r in row:
print r

==
python testdb.py
database value after unicode conversion is : N
database value sent to CLI is : N==
 
P

ptn

result = ibm_db.exec_immediate( conn, 'SELECT * FROM TEST FETCH FIRST
1 ROWS ONLY')

You have the same string split into two lines, which means that what
you actually have is this:

result = ibm_db.exec_immediate( conn, 'SELECT * FROM TEST FETCH
FIRST<NEWLINE CHARACTER HERE>
1 ROWS ONLY')

You need to escape that little '\n' with a backslash:

result = ibm_db.exec_immediate( conn, 'SELECT * FROM TEST FETCH FIRST\
1 ROWS ONLY')

Better yet, use implicit string concatenation:

result = ibm_db.exec_immediate( conn, 'SELECT * FROM TEST FETCH FIRST'
'1 ROWS ONLY')

Note that now you have two strings: 'SELECT * FROM TEST FETCH FIRST'
and '1 ROWS ONLY'


Pablo Torres N.
 
D

Dennis Lee Bieber

This simple db connectivity and select test program works in the
interactive mode

... print r
...
13
ABC
4
2009-05-11

The same executed from a script using python testdb.py does not yield
anything , What am I doing wrong ?

import ibm_db
conn = ibm_db.connect( 'DATABASE', 'user', 'pwd')
result = ibm_db.exec_immediate( conn, 'SELECT * FROM TEST FETCH FIRST
1 ROWS ONLY')
row = ibm_db.fetch_tuple( result )
for r in row:
print r

==
database value after unicode conversion is : N
database value sent to CLI is : N
And where are THOSE output lines coming from... I'd suspect you
aren't running the same file you think you are...
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,201
Messages
2,571,049
Members
47,655
Latest member
eizareri

Latest Threads

Top