I'm trying to store binary data in a sqlite database and call into the
db using pysqlite 3.
What I've got so far is this:
import sqlite
con = sqlite.connect( DB_PATH)
cur = con.cursor()
query = """create table t1(
ID INTEGER PRIMARY KEY,
data BLOB );"""
cur.execute(que ry)
con.commit()
b = buffer('/path/to/binary/file')
query = 'insert into table (ID,data) values (1,?);'
result = cur.execute(que ry,(b))
con.commit()
The error message I get is :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/sqlite/main.py", line 255, in
execute
self.rs = self.con.db.exe cute(SQL % parms)
TypeError: not all arguments converted during string formatting
I also read about using adapters, but I haven't found any clear info
on how to use them.
Does anyone have an example of storing binary data (image) in sqlite
using pysqlite? 3 7552
On Tue, 2007-07-31 at 00:25 +0000, ru*********@gma il.com wrote:
I'm trying to store binary data in a sqlite database and call into the
db using pysqlite 3.
What I've got so far is this:
import sqlite
con = sqlite.connect( DB_PATH)
cur = con.cursor()mea n
query = """create table t1(
ID INTEGER PRIMARY KEY,
data BLOB );"""
cur.execute(que ry)
con.commit()
b = buffer('/path/to/binary/file')
query = 'insert into table (ID,data) values (1,?);'
result = cur.execute(que ry,(b))
The second argument to execute() must be a sequence of parameter values.
You have one parameter value, the string b. To make a one-tuple, you
need a comma, as in "(b,)".
con.commit()
The error message I get is :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/sqlite/main.py", line 255, in
execute
self.rs = self.con.db.exe cute(SQL % parms)
This traceback line worries me. I'm almost certain that you're not using
the latest version of the sqlite module. The module that is included
with Python2.5 is called sqlite3, and it lives
in .../python/site-packages/sqlite3/*
and .../python/lib-dynload/_sqlite3.so.
HTH,
--
Carsten Haese http://informixdb.sourceforge.net
On Jul 30, 6:25 pm, rustyhow...@gma il.com wrote:
I'm trying to store binary data in a sqlite database and call into the
db using pysqlite 3.
What I've got so far is this:
import sqlite
con = sqlite.connect( DB_PATH)
cur = con.cursor()
query = """create table t1(
ID INTEGER PRIMARY KEY,
data BLOB );"""
cur.execute(que ry)
con.commit()
b = buffer('/path/to/binary/file')
buffer() ?
>From the docs:
----
There are several built-in functions that are no longer essential to
learn, know or use in modern Python programming. They have been kept
here to maintain backwards compatibility with programs written for
older versions of Python.
....
buffer(object[, offset[, size]])
----
On Tue, 2007-07-31 at 00:13 -0700, 7stud wrote:
On Jul 30, 6:25 pm, rustyhow...@gma il.com wrote:
I'm trying to store binary data in a sqlite database and call into the
db using pysqlite 3.
What I've got so far is this:
import sqlite
con = sqlite.connect( DB_PATH)
cur = con.cursor()
query = """create table t1(
ID INTEGER PRIMARY KEY,
data BLOB );"""
cur.execute(que ry)
con.commit()
b = buffer('/path/to/binary/file')
buffer() ?
Using buffer is not in itself wrong, as some DB-API modules, including
sqlite3, do use buffer objects to encapsulate binary data. However, the
encapsulation should be called in a portable way by using the standard
Binary factory function: b = sqlite3.Binary( contents).
What is wrong, though, is passing the filename into it instead of the
contents. This is in addition to the wrong execute call and using the
wrong version of the sqlite module, as I pointed out in my previous
reply.
--
Carsten Haese http://informixdb.sourceforge.net This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tony |
last post by:
Hi,
I have dynamically created a PDF document in memory as a FileOutputStream
Now I have to get it into a DB2 table, storing it as a BLOB. The table has a
document id,
document name, some date fields and this BLOB column that stores PDF Files.
Until now, the PDF files were read off of a disk drive. The code used was:
byte fileAsBytes = (byte) adminDocEvent.getFile();
which returns an object.
|
by: Juergen Gerner |
last post by:
Hello Python fans,
I'm trying and searching for many days for an acceptable solution...
without success. I want to store files in a database using BLOB
fields. The database table has an ID field (INT, auto_increment), an
ORDER field (INT, for knowing the right order) and a "normal" BLOB
field. It is planned to split large files in 64k-parts and sort these
parts by the ORDER field.
Here's some pseudo code how I wanted to implement this...
|
by: David Horowitz |
last post by:
Hi folks,
I want to be able to store and retrieve UNSAVED Word documents as BLOBs. I
got all the info for storing them if they're already saved on the file
system. But what if they're not already saved? I could save them to a temp
file first and then make it a blob, but I'd rather not put them on the file
system at all. I could use Document.Contents to get the Range object for the
whole doc and then BLOB that, but I'm not sure that would...
|
by: aldonnelley |
last post by:
Hi there.
I'm a long-time lurker and (I think) first time poster.
Only relatively new to python, and I'm trying to get pysqlite to work
with binary data, and having a tough time of it.
I want to set up a table with:
- a URL,
- some filenames related to that URL,
- and some simple generated HTML.
|
by: Nader Emami |
last post by:
I have installed "TurboGears" and I would install 'pysqlite' also. I am
a user on a Linux machine. If I try to install the 'pysqlite' with
'easy_install' tool I get the next error message. The error message is
longer than what I send here.
% easy_install pysqlite
Searching for pysqlite
Reading http://cheeseshop.python.org/pypi/pysqlite/
Reading http://pysqlite.org/
| |
by: lorirobn |
last post by:
Hi,
I need to add photos to my database. Back End is on MS SQL Server (I
believe 2000), and Front End is on MS Access.
I have read about storing the photos as BLOBS, but I am not sure how
to do this with SQL Server. Does this mean store the photo as OLE
image, but do something else to it to make it a "Blob"?
I have also read about linking to the photo rather than storing it on
|
by: Annonymous Coward |
last post by:
I remember readng that BLOBs can be stored externally (with reference to
the BLOB file stored in tables instead).
Does anyone have any experience doing this ? I have a few questions:
1).what are the things to watch out for (apart from obvious ones like
'file not found' type errors).
2). How may a stored proc be written to fetch the BLOB data ? (An
example would be very helpful)
3). How are errors handled in the stored proc that...
|
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
pysqlite 2.5.0 released
=======================
I'm pleased to announce the availability of pysqlite 2.5.0. This is
a release with major new features.
Go to http://pysqlite.org/ for downloads, online documentation and
|
by: Astley Le Jasper |
last post by:
I've been getting errors recently when using pysqlite. I've declared
the table columns as real numbers to 2 decimal places (I'm dealing
with money), but when doing division on two numbers that happen to
have no decimal fractions, the results through pysqlite are coming
through as integers. The funny thing is that when looking at the
database using SQLite Manager or SQLite Pro the results there are
displayed correctly. As a temporary fix...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |