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 171 of file ProjectFileIO.cpp.

Constructor & Destructor Documentation

◆ SQLiteBlobStream() [1/2]

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

Definition at line 192 of file ProjectFileIO.cpp.

193 : mBlob(blob)
194 , mIsReadOnly(readOnly)
195 {
196 mBlobSize = sqlite3_blob_bytes(blob);
197 }
sqlite3_blob * mBlob

References mBlobSize.

◆ SQLiteBlobStream() [2/2]

SQLiteBlobStream::SQLiteBlobStream ( SQLiteBlobStream &&  rhs)
inlinenoexcept

Definition at line 199 of file ProjectFileIO.cpp.

200 {
201 *this = std::move(rhs);
202 }

◆ ~SQLiteBlobStream()

SQLiteBlobStream::~SQLiteBlobStream ( )
inlinenoexcept

Definition at line 214 of file ProjectFileIO.cpp.

215 {
216 // Destructor should not throw and there is no
217 // way to handle the error otherwise
218 (void) Close();
219 }
int Close() noexcept

References Close().

Here is the call graph for this function:

Member Function Documentation

◆ Close()

int SQLiteBlobStream::Close ( )
inlinenoexcept

Definition at line 226 of file ProjectFileIO.cpp.

227 {
228 if (mBlob == nullptr)
229 return SQLITE_OK;
230
231 const int rc = sqlite3_blob_close(mBlob);
232
233 mBlob = nullptr;
234
235 return rc;
236 }

References mBlob.

Referenced by ~SQLiteBlobStream().

Here is the caller graph for this function:

◆ IsEof()

bool SQLiteBlobStream::IsEof ( ) const
inlinenoexcept

Definition at line 279 of file ProjectFileIO.cpp.

280 {
281 return mOffset == mBlobSize;
282 }

References mBlobSize, and mOffset.

◆ IsOpen()

bool SQLiteBlobStream::IsOpen ( ) const
inlinenoexcept

Definition at line 221 of file ProjectFileIO.cpp.

222 {
223 return mBlob != nullptr;
224 }

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 174 of file ProjectFileIO.cpp.

177 {
178 if (db == nullptr)
179 return {};
180
181 sqlite3_blob* blob = nullptr;
182
183 const int rc = sqlite3_blob_open(
184 db, schema, table, column, rowID, readOnly ? 0 : 1, &blob);
185
186 if (rc != SQLITE_OK)
187 return {};
188
189 return std::make_optional<SQLiteBlobStream>(blob, readOnly);
190 }

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 204 of file ProjectFileIO.cpp.

205 {
206 std::swap(mBlob, rhs.mBlob);
210
211 return *this;
212 }
void swap(std::unique_ptr< Alg_seq > &a, std::unique_ptr< Alg_seq > &b)
Definition: NoteTrack.cpp:634

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 254 of file ProjectFileIO.cpp.

255 {
256 if (!IsOpen() || ptr == nullptr)
257 return SQLITE_MISUSE;
258
259 const int availableBytes = mBlobSize - mOffset;
260
261 if (availableBytes == 0)
262 {
263 size = 0;
264 return SQLITE_OK;
265 }
266 else if (availableBytes < size)
267 {
268 size = availableBytes;
269 }
270
271 const int rc = sqlite3_blob_read(mBlob, ptr, size, mOffset);
272
273 if (rc == SQLITE_OK)
274 mOffset += size;
275
276 return rc;
277 }
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 238 of file ProjectFileIO.cpp.

239 {
240 // Stream APIs usually return the number of bytes written.
241 // sqlite3_blob_write is all-or-nothing function,
242 // so Write will return the result of the call
243 if (!IsOpen() || mIsReadOnly || ptr == nullptr)
244 return SQLITE_MISUSE;
245
246 const int rc = sqlite3_blob_write(mBlob, ptr, size, mOffset);
247
248 if (rc == SQLITE_OK)
249 mOffset += size;
250
251 return rc;
252 }

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 285 of file ProjectFileIO.cpp.

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

◆ mBlobSize

size_t SQLiteBlobStream::mBlobSize { 0 }
private

Definition at line 286 of file ProjectFileIO.cpp.

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

◆ mIsReadOnly

bool SQLiteBlobStream::mIsReadOnly { false }
private

Definition at line 290 of file ProjectFileIO.cpp.

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

◆ mOffset

int SQLiteBlobStream::mOffset { 0 }
private

Definition at line 288 of file ProjectFileIO.cpp.

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


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