1.Dd December 19, 2018 2.Dt SQLITE3_BLOB_OPEN 3 3.Os 4.Sh NAME 5.Nm sqlite3_blob_open 6.Nd Open A BLOB For Incremental I/O 7.Sh SYNOPSIS 8.Ft int 9.Fo sqlite3_blob_open 10.Fa "sqlite3*" 11.Fa "const char *zDb" 12.Fa "const char *zTable" 13.Fa "const char *zColumn" 14.Fa "sqlite3_int64 iRow" 15.Fa "int flags" 16.Fa "sqlite3_blob **ppBlob " 17.Fc 18.Sh DESCRIPTION 19This interfaces opens a handle to the BLOB located in row iRow, 20column zColumn, table zTable in database zDb; in other words, the same 21BLOB that would be selected by: 22.Bd -literal 23SELECT zColumn FROM zDb.zTable WHERE rowid = iRow; 24.Ed 25.Pp 26Parameter zDb is not the filename that contains the database, but rather 27the symbolic name of the database. 28For attached databases, this is the name that appears after the AS 29keyword in the ATTACH statement. 30For the main database file, the database name is "main". 31For TEMP tables, the database name is "temp". 32.Pp 33If the flags parameter is non-zero, then the BLOB is opened for read 34and write access. 35If the flags parameter is zero, the BLOB is opened for read-only access. 36.Pp 37On success, SQLITE_OK is returned and the new BLOB handle 38is stored in *ppBlob. 39Otherwise an error code is returned and, unless the error 40code is SQLITE_MISUSE, *ppBlob is set to NULL. 41This means that, provided the API is not misused, it is always safe 42to call sqlite3_blob_close() on *ppBlob after this 43function it returns. 44.Pp 45This function fails with SQLITE_ERROR if any of the following are true: 46.Bl -bullet 47.It 48Database zDb does not exist , 49.It 50Table zTable does not exist within database zDb , 51.It 52Table zTable is a WITHOUT ROWID table , 53.It 54Column zColumn does not exist , 55.It 56Row iRow is not present in the table , 57.It 58The specified column of row iRow contains a value that is not a TEXT 59or BLOB value , 60.It 61Column zColumn is part of an index, PRIMARY KEY or UNIQUE constraint 62and the blob is being opened for read/write access , 63.It 64 Foreign key constraints are enabled, column 65zColumn is part of a child key definition and the blob is 66being opened for read/write access . 67.El 68.Pp 69Unless it returns SQLITE_MISUSE, this function sets the database connection 70error code and message accessible via sqlite3_errcode() 71and sqlite3_errmsg() and related functions. 72.Pp 73A BLOB referenced by sqlite3_blob_open() may be read using the sqlite3_blob_read() 74interface and modified by using sqlite3_blob_write(). 75The BLOB handle can be moved to a different row of the same 76table using the sqlite3_blob_reopen() interface. 77However, the column, table, or database of a BLOB handle 78cannot be changed after the BLOB handle is opened. 79.Pp 80If the row that a BLOB handle points to is modified by an UPDATE, 81DELETE, or by ON CONFLICT side-effects then the BLOB 82handle is marked as "expired". 83This is true if any column of the row is changed, even a column other 84than the one the BLOB handle is open on. 85Calls to sqlite3_blob_read() and sqlite3_blob_write() 86for an expired BLOB handle fail with a return code of SQLITE_ABORT. 87Changes written into a BLOB prior to the BLOB expiring are not rolled 88back by the expiration of the BLOB. 89Such changes will eventually commit if the transaction continues to 90completion. 91.Pp 92Use the sqlite3_blob_bytes() interface to determine 93the size of the opened blob. 94The size of a blob may not be changed by this interface. 95Use the UPDATE SQL command to change the size of a blob. 96.Pp 97The sqlite3_bind_zeroblob() and sqlite3_result_zeroblob() 98interfaces and the built-in zeroblob SQL function may be used 99to create a zero-filled blob to read or write using the incremental-blob 100interface. 101.Pp 102To avoid a resource leak, every open BLOB handle should 103eventually be released by a call to sqlite3_blob_close(). 104.Pp 105.Sh SEE ALSO 106.Xr sqlite3_blob 3 , 107.Xr sqlite3 3 , 108.Xr sqlite3_bind_blob 3 , 109.Xr sqlite3_blob_bytes 3 , 110.Xr sqlite3_blob_close 3 , 111.Xr sqlite3_blob_read 3 , 112.Xr sqlite3_blob_reopen 3 , 113.Xr sqlite3_blob_write 3 , 114.Xr sqlite3_errcode 3 , 115.Xr sqlite3_result_blob 3 , 116.Xr SQLITE_OK 3 117