#23 entering data into character field

closed-fixed
7
2002-08-28
2002-08-14
No

Let's try this again since the code wasn't uploaded the
last time I tried this. The following is an abbreviated
code snippet that I am using to test entering data into a
character field and retrieving through a search on that
character field. The table "test" has one column "test1"
defined as char[40]

I am using this with python 2.2.1 and Firebird release
1.0.

-- beginning code snippet--

import kinterbasdb

con = kinterbasdb.connect
(dsn="localhost:c:/nntptest1.gdb",
user="####",
password="####"
)
cur = con.cursor()

foo = ["foo"]
cur.execute("insert into test (test1) values (?)", foo)

con.commit()

cur.execute("select * from test where test1 = 'foo'")
print cur.fetchall()

#this searches for a record entered through ibconsole
cur.execute("select * from test where test1 = 'bar'")
print cur.fetchall()
cur.close()
con.close()

--end code snippet--

Running the script produces the following results:
--begin results--
[]
[('bar ',)]
--end results--

Basically, I am unable to use the expression "select ...
where field = ' text' " on data entered using kinterbasdb.
I can use "select... where field like 'text%'" but this has
disadvantages.

Discussion

  • Kirk Job-Sluder

    Kirk Job-Sluder - 2002-08-14

    Logged In: YES
    user_id=594741

    This is interesting. It looks like that manually constructed
    insert statements add trailing whitespace to fill the buffer
    while using the parameterized version does not.

    #this creates a record without padding
    foo = ["foo4"]
    cur.execute("insert into test (test1) values (?)",foo)

    #this creates a record with padding
    cur.execute("insert into test (test1) values ('foo4')")

    con.commit()

    #no padding
    cur.execute("select * from test where test1 = ?", foo)
    print cur.fetchall()

    #padding
    cur.execute("select * from test where test1 = 'foo4'")
    print cur.fetchall()

    --output--
    [('foo4',)]
    [('foo4 ',)]

    I hope this additional information helps.

     
  • David S. Rushby

    David S. Rushby - 2002-08-14
    • labels: --> General problems
    • priority: 5 --> 7
    • assigned_to: nobody --> woodsplitter
     
  • David S. Rushby

    David S. Rushby - 2002-08-14

    Logged In: YES
    user_id=414645

    Thanks for reporting this bug, Kirk.

    I've attached a version of _kinterbasdb.c that I believe fixes
    the problem. How does it work for you?

    You didn't mention what OS you're using; if you need a
    compiled .pyd (for Windows), I can attach it also.

     
  • Kirk Job-Sluder

    Kirk Job-Sluder - 2002-08-14

    Logged In: YES
    user_id=594741

    A compiled binary for windows would be helpful but I don't see
    the attachment either.

     
  • David S. Rushby

    David S. Rushby - 2002-08-14

    Logged In: YES
    user_id=414645

    I'll try the attachment again (as a zipped .pyd).

    Note that kinterbasdb is known to have some problems with
    multi-byte character sets (though this bug wasn't related to
    that). Because I don't use multi-byte character sets, I haven't
    taken the time to fix the issues yet. (see
    http://sourceforge.net/tracker/index.php?
    func=detail&aid=462244&group_id=9913&atid=209913 )

     
  • Kirk Job-Sluder

    Kirk Job-Sluder - 2002-08-15

    Logged In: YES
    user_id=594741

    That did the trick, thanks.

     
  • David S. Rushby

    David S. Rushby - 2002-08-28
    • status: open --> closed-fixed
     
  • David S. Rushby

    David S. Rushby - 2002-08-28

    Logged In: YES
    user_id=414645

    Fixed in version 3.0.2.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks