sqlite3 adaptors mystery



Hi,

I am in the process of creating a small script for filling the
sqlite3 database with data from rather large XML-RPC query (list
of many bugs from the Red Hat Bugzilla) and I would love to use
adaptors and converters for some data types which I am missing.

I have this test script (made hopefully pretty faithfully from the
documentation):

#!/usr/bin/python
import sqlite3
def adapt_boolean(bol):
if bol:
return "True"
else:
return "False"

def convert_boolean(bolStr):
if str(bolStr) == "True":
return bool(True)
elif str(bolStr) == "False":
return bool(False)
else:
raise ValueError, "Unknown value of bool attribute '%s'" \
% bolStr

sqlite3.register_adapter(bool,adapt_boolean)
sqlite3.register_converter("boolean",convert_boolean)

db = sqlite3.connect("test.db")
cur=db.cursor()
cur.execute("create table test(p boolean)")
p=False
cur.execute("insert into test(p) values (?)", (p,))
p=True
cur.execute("insert into test(p) values (?)", (p,))
cur.execute("select p from test")
print cur.fetchall()

And I would expect to print on output representation of bool values, i.e.,
something like

[False,True]

However, when running this program it seems converter doesn’t seem to work,
because I get:

[matej@viklef dumpBugzilla]$ rm test.db ; python testAdaptors.py
[(u'False',), (u'True',)]
[matej@viklef dumpBugzilla]$

There is probably something quite obvious what I do incorrectly, but I just
don't see it. Could somebody kick me in the right direction, please?

Thanks a lot,

Matěj Cepl
.



Relevant Pages

  • Re: Dragonfly macro/script recorder
    ... and sending the script to the clipboard... ... no movement at start of script records correctly. ... bool AfterFirstUpstroke=false; ... {//UNUSEABLE KEYBOARD MESSAGE ...
    (comp.lang.beta)
  • Dragonfly macro/script recorder
    ... Script is copied ... from file at end of recording. ... bool AllowMore=false; ... virtual int ExitInstance; ...
    (comp.lang.beta)
  • Re: Memory leak with filling an sqlite3 database...
    ... I have a small script that queries an MS sql server, and stores the ... results locally, inside an sqlite3 database. ...
    (comp.lang.tcl)
  • [SLE] Re: mounting a usb dvd disk
    ... but i found an entry in the german suse list with a possible solution.. ... as you said you have the problem in a script.. ... volume.policy.should_mount = true (bool) ... > with the dvd label within a few seconds of a dvd being inserted (this ...
    (SuSE)
  • Re: script-shutdown when process ended
    ... Bool = false ... > Hey, I was wondering if any of you knew how to write a script for XP, ... > that would probably run in system start-up, ... > shutdown -s automatically when a person ends a particular task. ...
    (microsoft.public.windowsxp.help_and_support)