Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
SQLiteBlobStream Class Referencefinal

Public Member Functions

 SQLiteBlobStream (sqlite3_blob *blob, bool readOnly) noexcept
 
 SQLiteBlobStream (SQLiteBlobStream &&rhs) noexcept
 
SQLiteBlobStreamoperator= (SQLiteBlobStream &&rhs) noexcept
 
 ~SQLiteBlobStream () noexcept
 
bool IsOpen () const noexcept
 
int Close () noexcept
 
int Write (const void *ptr, int size) noexcept
 
int Read (void *ptr, int &size) noexcept
 
bool IsEof () const noexcept
 

Static Public Member Functions

static std::optional< SQLiteBlobStreamOpen (sqlite3 *db, const char *schema, const char *table, const char *column, int64_t rowID, bool readOnly) noexcept
 

Private Attributes

sqlite3_blob * mBlob { nullptr }
 
size_t mBlobSize { 0 }
 
int mOffset { 0 }
 
bool mIsReadOnly { false }
 

Detailed Description

Definition at line 216 of file ProjectFileIO.cpp.

Constructor & Destructor Documentation

◆ SQLiteBlobStream() [1/2]

SQLiteBlobStream::SQLiteBlobStream ( sqlite3_blob *  blob,
bool  readOnly 
)
inlinenoexcept

Definition at line 237 of file ProjectFileIO.cpp.

238 : mBlob(blob)
239 , mIsReadOnly(readOnly)
240 {
241 mBlobSize = sqlite3_blob_bytes(blob);
242 }
sqlite3_blob * mBlob

References mBlobSize.

◆ SQLiteBlobStream() [2/2]

SQLiteBlobStream::SQLiteBlobStream ( SQLiteBlobStream &&  rhs)
inlinenoexcept

Definition at line 244 of file ProjectFileIO.cpp.

245 {
246 *this = std::move(rhs);
247 }

◆ ~SQLiteBlobStream()

SQLiteBlobStream::~SQLiteBlobStream ( )
inlinenoexcept

Definition at line 259 of file ProjectFileIO.cpp.

260 {
261 // Destructor should not throw and there is no
262 // way to handle the error otherwise
263 (void) Close();
264 }
int Close() noexcept

References Close().

Here is the call graph for this function:

Member Function Documentation

◆ Close()

int SQLiteBlobStream::Close ( )
inlinenoexcept

Definition at line 271 of file ProjectFileIO.cpp.

272 {
273 if (mBlob == nullptr)
274 return SQLITE_OK;
275
276 const int rc = sqlite3_blob_close(mBlob);
277
278 mBlob = nullptr;
279
280 return rc;
281 }

References mBlob.

Referenced by ~SQLiteBlobStream().

Here is the caller graph for this function:

◆ IsEof()

bool SQLiteBlobStream::IsEof ( ) const
inlinenoexcept

Definition at line 324 of file ProjectFileIO.cpp.

325 {
326 return mOffset == mBlobSize;
327 }

References mBlobSize, and mOffset.

◆ IsOpen()

bool SQLiteBlobStream::IsOpen ( ) const
inlinenoexcept

Definition at line 266 of file ProjectFileIO.cpp.

267 {
268 return mBlob != nullptr;
269 }

References mBlob.

Referenced by Read(), and Write().

Here is the caller graph for this function:

◆ Open()

static std::optional< SQLiteBlobStream > SQLiteBlobStream::Open ( sqlite3 *  db,
const char *  schema,
const char *  table,
const char *  column,
int64_t  rowID,
bool  readOnly 
)
inlinestaticnoexcept

Definition at line 219 of file ProjectFileIO.cpp.

222 {
223 if (db == nullptr)
224 return {};
225
226 sqlite3_blob* blob = nullptr;
227
228 const int rc = sqlite3_blob_open(
229 db, schema, table, column, rowID, readOnly ? 0 : 1, &blob);
230
231 if (rc != SQLITE_OK)
232 return {};
233
234 return std::make_optional<SQLiteBlobStream>(blob, readOnly);
235 }

Referenced by BufferedProjectBlobStream::OpenBlob(), and ProjectFileIO::WriteDoc().

Here is the caller graph for this function:

◆ operator=()

SQLiteBlobStream & SQLiteBlobStream::operator= ( SQLiteBlobStream &&  rhs)
inlinenoexcept

Definition at line 249 of file ProjectFileIO.cpp.

250 {
251 std::swap(mBlob, rhs.mBlob);
255
256 return *this;
257 }
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:752

References mBlob, mBlobSize, mIsReadOnly, mOffset, and anonymous_namespace{NoteTrack.cpp}::swap().

Here is the call graph for this function:

◆ Read()

int SQLiteBlobStream::Read ( void *  ptr,
int &  size 
)
inlinenoexcept

Definition at line 299 of file ProjectFileIO.cpp.

300 {
301 if (!IsOpen() || ptr == nullptr)
302 return SQLITE_MISUSE;
303
304 const int availableBytes = mBlobSize - mOffset;
305
306 if (availableBytes == 0)
307 {
308 size = 0;
309 return SQLITE_OK;
310 }
311 else if (availableBytes < size)
312 {
313 size = availableBytes;
314 }
315
316 const int rc = sqlite3_blob_read(mBlob, ptr, size, mOffset);
317
318 if (rc == SQLITE_OK)
319 mOffset += size;
320
321 return rc;
322 }
bool IsOpen() const noexcept

References IsOpen(), mBlob, mBlobSize, mOffset, and size.

Here is the call graph for this function:

◆ Write()

int SQLiteBlobStream::Write ( const void *  ptr,
int  size 
)
inlinenoexcept

Definition at line 283 of file ProjectFileIO.cpp.

284 {
285 // Stream APIs usually return the number of bytes written.
286 // sqlite3_blob_write is all-or-nothing function,
287 // so Write will return the result of the call
288 if (!IsOpen() || mIsReadOnly || ptr == nullptr)
289 return SQLITE_MISUSE;
290
291 const int rc = sqlite3_blob_write(mBlob, ptr, size, mOffset);
292
293 if (rc == SQLITE_OK)
294 mOffset += size;
295
296 return rc;
297 }

References IsOpen(), mBlob, mIsReadOnly, mOffset, and size.

Here is the call graph for this function:

Member Data Documentation

◆ mBlob

sqlite3_blob* SQLiteBlobStream::mBlob { nullptr }
private

Definition at line 330 of file ProjectFileIO.cpp.

Referenced by Close(), IsOpen(), operator=(), Read(), and Write().

◆ mBlobSize

size_t SQLiteBlobStream::mBlobSize { 0 }
private

Definition at line 331 of file ProjectFileIO.cpp.

Referenced by IsEof(), operator=(), Read(), and SQLiteBlobStream().

◆ mIsReadOnly

bool SQLiteBlobStream::mIsReadOnly { false }
private

Definition at line 335 of file ProjectFileIO.cpp.

Referenced by operator=(), and Write().

◆ mOffset

int SQLiteBlobStream::mOffset { 0 }
private

Definition at line 333 of file ProjectFileIO.cpp.

Referenced by IsEof(), operator=(), Read(), and Write().


The documentation for this class was generated from the following file: