Hello all,

I am in the process of writing a program using sqlite3 whose purpose
is to "convert" a custom type of 2-dimensional array into an sqlite
table. My progress has been rather good, but I've run into a stumbling
block. This type of array - a NumPy recarray - can take any type of
data object as an entry. To get around this, I decided for the
purposes of not halting the conversion process because of something
the user will likely not be using in any sort of query, I would have
Pickle turn any objects I am not explicitly providing support for into
strings, which should then be able to be inserted into the table, even
if nothing meaningful can be done with them. I want to do this rather
than just, say, kick the elements out, because I want to be able to
reverse the process as well and thus simply Pickle.loads to get back
what is supposed to be there. Of course, the troublesome part lies in
this working for a not-defined set of classes.

I decided that a decent way to implement this would be to create a
dummy class in which I first wrap any objects that are not NumPy
datatypes or datetime. Then, I wrote an adapter function that I could
register the dummy class with, with the adapter simply returning the
output Pickle string. I also wrote an analogous converter function
that returns the result of loading the string with Pickle. The reason
for going to all this trouble to preserve the data is I want to be
able to convert back as well.

My problem now is that when I try to use this dummy class, even though
my adapter function should be passing a string into sqlite, I get the
dreaded sqlite3 interface error:

sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

I think my adapter function is written more or less correctly and am
at a loss. Attached is a test example of my code, where I try to do it
with a list as the object being pickled (note the list just stands
alone here, it is not part of a recarray; this is just to get it
working on the individual element level). Note that this is basically
the exact example from the python.org page on sqlite, with my class
and adapter/converter functions being used instead.

Can I get any feedback on what I might be doing wrong? I'm perplexed,
as I don't see why this shouldn't work. Maybe there's some really
simple syntax mistake I'm making. Full error text below:

$ python dclasstest.py
Traceback (most recent call last):
  File "dclasstest.py", line 31, in <module>
    cur.execute("insert into test(p) values (?)", (p,))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

Thanks in advance for any feedback.

Regards,
Josh
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to