go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

Blob I/O

Open smhmw opened this issue 10 years ago • 9 comments

Would it be possible to implement the blob i/o API just as the backup API ?

mxk/go-sqlite has it but is a little out of date. gwenn/gosqlite has it too.

smhmw avatar Sep 16 '15 08:09 smhmw

database/sql doesn't provide Blob APIs. they provide Blob APIs for native driver (not database/sql).

mattn avatar Sep 16 '15 09:09 mattn

Yes, but we can provide it aside from database/sql, like backup (backup.go) ? I may try to make it work locally, if it works i'll submit the patch - if that's interesting enough.

smhmw avatar Sep 16 '15 09:09 smhmw

No way to pass the Blob type into database.sql.

mattn avatar Sep 16 '15 09:09 mattn

To make it work, you need access from sql.DB to the underlying/wrapped sqlite3.SQLiteConn...

gwenn avatar Sep 18 '15 17:09 gwenn

I don't want to access it from sql.DB, rather add an API to the lib in a similar way to sqlite3.SQLiteBackup, such as sqlite3.SQLiteBlob; and corresponding method in sqlite3.SQLiteConn such as Blob(db, table, column, rowid) (similar to SQLiteConn.Backup(...))

You would need to get the rowid from a query first, but it's also intended this way in SQLite C API : int sqlite3_blob_open( sqlite3*, const char *zDb, const char *zTable, const char *zColumn, sqlite3_int64 iRow, int flags, sqlite3_blob **ppBlob );.

I'll give it a try ...

smhmw avatar Sep 21 '15 09:09 smhmw

:+1:

anacrolix avatar Jan 13 '16 16:01 anacrolix

Any progress on this @smhmw ?

anacrolix avatar Feb 16 '16 12:02 anacrolix

@smhmw Any update ?

gjrtimmer avatar May 30 '18 13:05 gjrtimmer

I think I came up with a nice API for this in my SQLite driver, which could be implemented for this driver as well: https://github.com/ncruces/go-sqlite3/blob/main/ext/blobio/blob_test.go

This would require wrapping the pointer passing APIs, on top of blob IO.

PS: the example shows writing/reading a single blob, but it easily supports reading/writing multiple blobs in one go (callback gets called repeatedly for each blob).

ncruces avatar Nov 11 '23 09:11 ncruces

Blob API reference in SQLite documentation: https://sqlite.org/c3ref/blob.html

dolmen avatar Oct 17 '25 09:10 dolmen