[sqlite] Blob Data Assignments

4 views
Skip to first unread message

Nigel Verity

unread,
Mar 23, 2012, 12:29:14 PM3/23/12
to sqlite...@sqlite.org

Hi
I'm new to SQLite, coming from an Access/VB background. Having moved over to Linux I'm now developing an application using Gambas. One of the requirements is to store a scanned document (PDF) in a record as a blob, along with its metadata. I've no problem selecting the document, but I'm struggling to work out how to assign it to the blob field. Does anybody have any tips or, possibly, the URL of a site that could assist?
Thanks
Nige
_______________________________________________
sqlite-users mailing list
sqlite...@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Simon Slavin

unread,
Mar 23, 2012, 12:34:01 PM3/23/12
to General Discussion of SQLite Database

On 23 Mar 2012, at 4:29pm, Nigel Verity <nigel...@hotmail.com> wrote:

> I'm new to SQLite, coming from an Access/VB background. Having moved over to Linux I'm now developing an application using Gambas. One of the requirements is to store a scanned document (PDF) in a record as a blob, along with its metadata. I've no problem selecting the document, but I'm struggling to work out how to assign it to the blob field. Does anybody have any tips or, possibly, the URL of a site that could assist?

A blob stores a sequence of bytes. The bytes can represent anything you like. So you could, for example, read in a PDF file and store the bytes of that file in a BLOB. You'll probably want to store the file's name in another column, too.

Simon.

Igor Tandetnik

unread,
Mar 23, 2012, 12:42:37 PM3/23/12
to sqlite...@sqlite.org
Nigel Verity <nigel...@hotmail.com> wrote:
> I'm new to SQLite, coming from an Access/VB background. Having moved over to Linux I'm now developing an application using
> Gambas. One of the requirements is to store a scanned document (PDF) in a record as a blob, along with its metadata. I've no
> problem selecting the document, but I'm struggling to work out how to assign it to the blob field.

There are two ways. If you have the whole document in a single memory buffer, then just prepare a statement like

insert into mytable(document) values (?);

use sqlite3_bind_blob to bind your memory buffer as a parameter, and run the statement.

Alternatively, you can use sqlite3_blob_open, sqlite3_blob_write et al. This way you don't need to have all the data in memory at once (useful for very large blobs), but you still have to know the size up front.
--
Igor Tandetnik

Reply all
Reply to author
Forward
0 new messages