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