Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
audacity::sqlite::Row Class Referencefinal

A class representing a row in a result set. More...

#include <Statement.h>

Collaboration diagram for audacity::sqlite::Row:
[legend]

Public Member Functions

bool Get (int columnIndex, bool &value) const
 
bool Get (int columnIndex, int &value) const
 
bool Get (int columnIndex, long &value) const
 
bool Get (int columnIndex, long long &value) const
 
bool Get (int columnIndex, float &value) const
 
bool Get (int columnIndex, double &value) const
 
bool Get (int columnIndex, std::string &value) const
 
template<typename T >
GetOr (int columnIndex, T defaultValue=T()) const
 
int GetColumnCount () const
 
int64_t GetColumnBytes (int columnIndex) const
 
int64_t ReadData (int columnIndex, void *buffer, int64_t maxSize) const
 

Private Member Functions

 Row (StatementHandlePtr statement, std::vector< Error > &errors) noexcept
 
 Row ()=default
 
template<typename Reader >
bool DoGet (Reader reader, int columnIndex) const
 

Private Attributes

StatementHandlePtr mStatement {}
 
std::vector< Error > * mErrors {}
 
int mColumnsCount { 0 }
 

Friends

class RowIterator
 

Detailed Description

A class representing a row in a result set.

Indices are 0-based

Definition at line 31 of file Statement.h.

Constructor & Destructor Documentation

◆ Row() [1/2]

audacity::sqlite::Row::Row ( StatementHandlePtr  statement,
std::vector< Error > &  errors 
)
explicitprivatenoexcept

Definition at line 340 of file Statement.cpp.

341 : mStatement { std::move(statement) }
342 , mErrors { &errors }
343{
344 if (mStatement != nullptr)
345 mColumnsCount = sqlite3_column_count(*mStatement);
346}
StatementHandlePtr mStatement
Definition: Statement.h:62
std::vector< Error > * mErrors
Definition: Statement.h:63

◆ Row() [2/2]

audacity::sqlite::Row::Row ( )
privatedefault

Member Function Documentation

◆ DoGet()

template<typename Reader >
bool audacity::sqlite::Row::DoGet ( Reader  reader,
int  columnIndex 
) const
private

Definition at line 349 of file Statement.cpp.

350{
351 if (mStatement == nullptr)
352 {
353 if (mErrors != nullptr)
354 mErrors->emplace_back(Error(SQLITE_MISUSE));
355 return false;
356 }
357
358 if (columnIndex < 0 || columnIndex >= mColumnsCount)
359 {
360 if (mErrors != nullptr)
361 mErrors->emplace_back(Error(SQLITE_RANGE));
362 return false;
363 }
364
365 if constexpr (std::is_void_v<decltype(reader())>)
366 {
367 reader();
368 return true;
369 }
370 else
371 return reader();
372}

References mColumnsCount, mErrors, and mStatement.

Referenced by Get().

Here is the caller graph for this function:

◆ Get() [1/7]

bool audacity::sqlite::Row::Get ( int  columnIndex,
bool &  value 
) const

Definition at line 374 of file Statement.cpp.

375{
376 return DoGet([&] { value = sqlite3_column_int(*mStatement, columnIndex) != 0; }, columnIndex);
377}
bool DoGet(Reader reader, int columnIndex) const
Definition: Statement.cpp:349

References DoGet(), and mStatement.

Referenced by audacity::cloud::audiocom::sync::CloudProjectsDatabase::DoGetProjectData().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [2/7]

bool audacity::sqlite::Row::Get ( int  columnIndex,
double &  value 
) const

Definition at line 408 of file Statement.cpp.

409{
410 return DoGet([&] { value = sqlite3_column_double(*mStatement, columnIndex); },
411 columnIndex);
412}

References DoGet(), and mStatement.

Here is the call graph for this function:

◆ Get() [3/7]

bool audacity::sqlite::Row::Get ( int  columnIndex,
float &  value 
) const

Definition at line 397 of file Statement.cpp.

398{
399 return DoGet(
400 [&]
401 {
402 value =
403 static_cast<float>(sqlite3_column_double(*mStatement, columnIndex));
404 },
405 columnIndex);
406}

References DoGet(), and mStatement.

Here is the call graph for this function:

◆ Get() [4/7]

bool audacity::sqlite::Row::Get ( int  columnIndex,
int &  value 
) const

Definition at line 379 of file Statement.cpp.

380{
381 return DoGet([&] { value = sqlite3_column_int(*mStatement, columnIndex); }, columnIndex);
382}

References DoGet(), and mStatement.

Here is the call graph for this function:

◆ Get() [5/7]

bool audacity::sqlite::Row::Get ( int  columnIndex,
long &  value 
) const

Definition at line 384 of file Statement.cpp.

385{
386 if (sizeof(long) == 4)
387 return DoGet([&] { value = sqlite3_column_int(*mStatement, columnIndex); }, columnIndex);
388 else
389 return DoGet([&] { value = sqlite3_column_int64(*mStatement, columnIndex); }, columnIndex);
390}

References DoGet(), and mStatement.

Here is the call graph for this function:

◆ Get() [6/7]

bool audacity::sqlite::Row::Get ( int  columnIndex,
long long &  value 
) const

Definition at line 392 of file Statement.cpp.

393{
394 return DoGet([&] { value = sqlite3_column_int64(*mStatement, columnIndex); }, columnIndex);
395}

References DoGet(), and mStatement.

Here is the call graph for this function:

◆ Get() [7/7]

bool audacity::sqlite::Row::Get ( int  columnIndex,
std::string &  value 
) const

Definition at line 414 of file Statement.cpp.

415{
416 return DoGet(
417 [&]
418 {
419 const auto* text = reinterpret_cast<const char*>(
420 sqlite3_column_text(*mStatement, columnIndex));
421
422 if (text == nullptr)
423 return false;
424
425 // Per sqlite convention, text is never nullptr
426 value = text;
427 return true;
428 },
429 columnIndex);
430}

References DoGet(), and mStatement.

Here is the call graph for this function:

◆ GetColumnBytes()

int64_t audacity::sqlite::Row::GetColumnBytes ( int  columnIndex) const

Definition at line 437 of file Statement.cpp.

438{
439 return sqlite3_column_bytes(*mStatement, columnIndex);
440}

References mStatement.

Referenced by ReadData().

Here is the caller graph for this function:

◆ GetColumnCount()

int audacity::sqlite::Row::GetColumnCount ( ) const

Definition at line 432 of file Statement.cpp.

433{
434 return sqlite3_column_count(*mStatement);
435}

References mStatement.

◆ GetOr()

template<typename T >
T audacity::sqlite::Row::GetOr ( int  columnIndex,
defaultValue = T() 
) const
inline

Definition at line 47 of file Statement.h.

48 {
49 T value;
50 return Get(columnIndex, value) ? value : defaultValue;
51 }
bool Get(int columnIndex, bool &value) const
Definition: Statement.cpp:374

References BasicUI::Get().

Here is the call graph for this function:

◆ ReadData()

int64_t audacity::sqlite::Row::ReadData ( int  columnIndex,
void *  buffer,
int64_t  maxSize 
) const

Definition at line 442 of file Statement.cpp.

443{
444 const auto* data = sqlite3_column_blob(*mStatement, columnIndex);
445
446 if (data == nullptr)
447 return 0;
448
449 const auto size = std::min(maxSize, GetColumnBytes(columnIndex));
450
451 std::memcpy(buffer, data, size);
452
453 return size;
454}
int min(int a, int b)
int64_t GetColumnBytes(int columnIndex) const
Definition: Statement.cpp:437

References GetColumnBytes(), min(), mStatement, and size.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ RowIterator

friend class RowIterator
friend

Definition at line 33 of file Statement.h.

Member Data Documentation

◆ mColumnsCount

int audacity::sqlite::Row::mColumnsCount { 0 }
private

Definition at line 64 of file Statement.h.

Referenced by DoGet().

◆ mErrors

std::vector<Error>* audacity::sqlite::Row::mErrors {}
private

Definition at line 63 of file Statement.h.

Referenced by DoGet().

◆ mStatement

StatementHandlePtr audacity::sqlite::Row::mStatement {}
private

Definition at line 62 of file Statement.h.

Referenced by DoGet(), Get(), GetColumnBytes(), GetColumnCount(), and ReadData().


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