Audacity  3.0.3
Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
DBConnection Class Reference

#include <DBConnection.h>

Collaboration diagram for DBConnection:
[legend]

Public Types

enum  StatementID {
  GetSamples, GetSummary256, GetSummary64k, LoadSampleBlock,
  InsertSampleBlock, DeleteSampleBlock, GetRootPage, GetDBPage
}
 
using CheckpointFailureCallback = std::function< void()>
 

Public Member Functions

 DBConnection (const std::weak_ptr< AudacityProject > &pProject, const std::shared_ptr< DBConnectionErrors > &pErrors, CheckpointFailureCallback callback)
 
 ~DBConnection ()
 
int Open (const FilePath fileName)
 
bool Close ()
 
void ThrowException (bool write) const
 throw and show appropriate message box More...
 
int SafeMode (const char *schema="main")
 
int FastMode (const char *schema="main")
 
bool Assign (sqlite3 *handle)
 
sqlite3 * Detach ()
 
sqlite3 * DB ()
 
int GetLastRC () const
 
const wxString GetLastMessage () const
 
sqlite3_stmt * Prepare (enum StatementID id, const char *sql)
 
void SetBypass (bool bypass)
 
bool ShouldBypass ()
 
void SetError (const TranslatableString &msg, const TranslatableString &libraryError={}, int errorCode={})
 Just set stored errors. More...
 
void SetDBError (const TranslatableString &msg, const TranslatableString &libraryError={}, int errorCode=-1)
 Set stored errors and write to log; and default libraryError to what database library reports. More...
 

Private Types

using StatementIndex = std::pair< enum StatementID, std::thread::id >
 

Private Member Functions

int OpenStepByStep (const FilePath fileName)
 
int ModeConfig (sqlite3 *db, const char *schema, const char *config)
 
void CheckpointThread (sqlite3 *db, const FilePath &fileName)
 

Static Private Member Functions

static int CheckpointHook (void *data, sqlite3 *db, const char *schema, int pages)
 

Private Attributes

std::weak_ptr< AudacityProjectmpProject
 
sqlite3 * mDB
 
sqlite3 * mCheckpointDB
 
std::thread mCheckpointThread
 
std::condition_variable mCheckpointCondition
 
std::mutex mCheckpointMutex
 
std::atomic_bool mCheckpointStop { false }
 
std::atomic_bool mCheckpointPending { false }
 
std::atomic_bool mCheckpointActive { false }
 
std::mutex mStatementMutex
 
std::map< StatementIndex, sqlite3_stmt * > mStatements
 
std::shared_ptr< DBConnectionErrorsmpErrors
 
CheckpointFailureCallback mCallback
 
bool mBypass
 

Detailed Description

Definition at line 39 of file DBConnection.h.

Member Typedef Documentation

◆ CheckpointFailureCallback

using DBConnection::CheckpointFailureCallback = std::function<void()>

Definition at line 44 of file DBConnection.h.

◆ StatementIndex

using DBConnection::StatementIndex = std::pair<enum StatementID, std::thread::id>
private

Definition at line 119 of file DBConnection.h.

Member Enumeration Documentation

◆ StatementID

Enumerator
GetSamples 
GetSummary256 
GetSummary64k 
LoadSampleBlock 
InsertSampleBlock 
DeleteSampleBlock 
GetRootPage 
GetDBPage 

Definition at line 71 of file DBConnection.h.

72  {
73  GetSamples,
80  GetDBPage
81  };

Constructor & Destructor Documentation

◆ DBConnection()

DBConnection::DBConnection ( const std::weak_ptr< AudacityProject > &  pProject,
const std::shared_ptr< DBConnectionErrors > &  pErrors,
CheckpointFailureCallback  callback 
)

Definition at line 42 of file DBConnection.cpp.

46 : mpProject{ pProject }
47 , mpErrors{ pErrors }
48 , mCallback{ std::move(callback) }
49 {
50  mDB = nullptr;
51  mCheckpointDB = nullptr;
52  mBypass = false;
53 }

◆ ~DBConnection()

DBConnection::~DBConnection ( )

Definition at line 55 of file DBConnection.cpp.

56 {
57  wxASSERT(mDB == nullptr);
58  if (mDB)
59  {
60  wxLogMessage("Database left open at connection destruction %s\n",
61  sqlite3_db_filename(mDB, nullptr));
62  }
63 }

References mDB.

Member Function Documentation

◆ Assign()

bool DBConnection::Assign ( sqlite3 *  handle)

◆ CheckpointHook()

int DBConnection::CheckpointHook ( void *  data,
sqlite3 *  db,
const char *  schema,
int  pages 
)
staticprivate

Definition at line 541 of file DBConnection.cpp.

542 {
543  // Get access to our object
544  DBConnection *that = static_cast<DBConnection *>(data);
545 
546  // Queue the database pointer for our checkpoint thread to process
547  std::lock_guard<std::mutex> guard(that->mCheckpointMutex);
548  that->mCheckpointPending = true;
549  that->mCheckpointCondition.notify_one();
550 
551  return SQLITE_OK;
552 }

References mCheckpointCondition, mCheckpointMutex, and mCheckpointPending.

Referenced by OpenStepByStep().

Here is the caller graph for this function:

◆ CheckpointThread()

void DBConnection::CheckpointThread ( sqlite3 *  db,
const FilePath fileName 
)
private

Definition at line 446 of file DBConnection.cpp.

447 {
448  int rc = SQLITE_OK;
449  bool giveUp = false;
450 
451  while (true)
452  {
453  {
454  // Wait for work or the stop signal
455  std::unique_lock<std::mutex> lock(mCheckpointMutex);
456  mCheckpointCondition.wait(lock,
457  [&]
458  {
460  });
461 
462  // Requested to stop, so bail
463  if (mCheckpointStop)
464  {
465  break;
466  }
467 
468  // Capture the number of pages that need checkpointing and reset
469  mCheckpointActive = true;
470  mCheckpointPending = false;
471  }
472 
473  // And kick off the checkpoint. This may not checkpoint ALL frames
474  // in the WAL. They'll be gotten the next time around.
475  using namespace std::chrono;
476  do {
477  rc = giveUp ? SQLITE_OK :
478  sqlite3_wal_checkpoint_v2(
479  db, nullptr, SQLITE_CHECKPOINT_PASSIVE, nullptr, nullptr);
480  }
481  // Contentions for an exclusive lock on the database are possible,
482  // even while the main thread is merely drawing the tracks, which
483  // may perform reads
484  while (rc == SQLITE_BUSY && (std::this_thread::sleep_for(1ms), true));
485 
486  // Reset
487  mCheckpointActive = false;
488 
489  if (rc != SQLITE_OK)
490  {
491  ADD_EXCEPTION_CONTEXT("sqlite3.rc", std::to_string(rc));
492  ADD_EXCEPTION_CONTEXT("sqlite3.context", "DBConnection::CheckpointThread");
493 
494  wxLogMessage("Failed to perform checkpoint on %s\n"
495  "\tErrCode: %d\n"
496  "\tErrMsg: %s",
497  fileName,
498  sqlite3_errcode(db),
499  sqlite3_errmsg(db));
500 
501  // Can't checkpoint -- maybe the device has too little space
502  wxFileNameWrapper fName{ fileName };
503  auto path = FileNames::AbbreviatePath(fName);
504  auto name = fName.GetFullName();
505  auto longname = name + "-wal";
506 
507  // TODO: Should we return the actual error message if it's not a
508  // disk full condition?
509  auto message1 = rc == SQLITE_FULL
510  ? XO("Could not write to %s.\n").Format(path)
511  : TranslatableString{};
512  auto message = XO(
513  "Disk is full.\n"
514  "%s\n"
515  "For tips on freeing up space, click the help button."
516  ).Format(message1);
517 
518  // Stop trying to checkpoint
519  giveUp = true;
520 
521  // Stop the audio.
522  GuardedCall(
523  [&message, rc] {
525  message, XO("Warning"), "Error:_Disk_full_or_not_writable" }; },
527  [this](AudacityException * e) {
528  // This executes in the main thread.
529  if (mCallback)
530  mCallback();
531  if (e)
532  e->DelayedHandlerAction();
533  }
534  );
535  }
536  }
537 
538  return;
539 }

References FileNames::AbbreviatePath(), ADD_EXCEPTION_CONTEXT, BadEnvironment, GuardedCall(), Internal, mCallback, mCheckpointActive, mCheckpointCondition, mCheckpointMutex, mCheckpointPending, mCheckpointStop, name, and XO.

Referenced by OpenStepByStep().

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

◆ Close()

bool DBConnection::Close ( )

Definition at line 215 of file DBConnection.cpp.

216 {
217  wxASSERT(mDB != nullptr);
218  int rc;
219 
220  // Protect...
221  if (mDB == nullptr)
222  {
223  return true;
224  }
225 
226  // Uninstall our checkpoint hook so that no additional checkpoints
227  // are sent our way. (Though this shouldn't really happen.)
228  sqlite3_wal_hook(mDB, nullptr, nullptr);
229 
230  // Display a progress dialog if there's active or pending checkpoints
232  {
233  TranslatableString title = XO("Checkpointing project");
234 
235  // Get access to the active project
236  auto project = mpProject.lock();
237  if (project)
238  {
239  title = XO("Checkpointing %s").Format(project->GetProjectName());
240  }
241 
242  // Provides a progress dialog with indeterminate mode
243  using namespace BasicUI;
244  auto pd = MakeGenericProgress({},
245  title, XO("This may take several seconds"));
246  wxASSERT(pd);
247 
248  // Wait for the checkpoints to end
250  {
251  wxMilliSleep(50);
252  pd->Pulse();
253  }
254  }
255 
256  // Tell the checkpoint thread to shutdown
257  {
258  std::lock_guard<std::mutex> guard(mCheckpointMutex);
259  mCheckpointStop = true;
260  mCheckpointCondition.notify_one();
261  }
262 
263  // And wait for it to do so
264  if (mCheckpointThread.joinable())
265  {
266  mCheckpointThread.join();
267  }
268 
269  // We're done with the prepared statements
270  {
271  std::lock_guard<std::mutex> guard(mStatementMutex);
272  for (auto stmt : mStatements)
273  {
274  // No need to process return code, but log it for diagnosis
275  rc = sqlite3_finalize(stmt.second);
276  if (rc != SQLITE_OK)
277  {
278  wxLogMessage("Failed to finalize statement on %s\n"
279  "\tErrMsg: %s\n"
280  "\tSQL: %s",
281  sqlite3_db_filename(mDB, nullptr),
282  sqlite3_errmsg(mDB),
283  stmt.second);
284  }
285  }
286  mStatements.clear();
287  }
288 
289  // Not much we can do if the closes fail, so just report the error
290 
291  // Close the checkpoint connection
292  rc = sqlite3_close(mCheckpointDB);
293  if (rc != SQLITE_OK)
294  {
295  ADD_EXCEPTION_CONTEXT("sqlite3.rc", std::to_string(rc));
296  ADD_EXCEPTION_CONTEXT("sqlite3.context", "DBConnection::Close::close_checkpoint");
297 
298  wxLogMessage("Failed to close checkpoint connection for %s\n"
299  "\tError: %s\n",
300  sqlite3_db_filename(mCheckpointDB, nullptr),
301  sqlite3_errmsg(mCheckpointDB));
302  }
303  mCheckpointDB = nullptr;
304 
305  // Close the primary connection
306  rc = sqlite3_close(mDB);
307  if (rc != SQLITE_OK)
308  {
309  ADD_EXCEPTION_CONTEXT("sqlite3.rc", std::to_string(rc));
310  ADD_EXCEPTION_CONTEXT("sqlite3.context", "DBConnection::OpenStepByStep::close");
311 
312  wxLogMessage("Failed to close %s\n"
313  "\tError: %s\n",
314  sqlite3_db_filename(mDB, nullptr),
315  sqlite3_errmsg(mDB));
316  }
317  mDB = nullptr;
318 
319  return true;
320 }

References ADD_EXCEPTION_CONTEXT, BasicUI::MakeGenericProgress(), mCheckpointActive, mCheckpointCondition, mCheckpointDB, mCheckpointMutex, mCheckpointPending, mCheckpointStop, mCheckpointThread, mDB, mpProject, mStatementMutex, mStatements, title, and XO.

Here is the call graph for this function:

◆ DB()

sqlite3 * DBConnection::DB ( )

Definition at line 375 of file DBConnection.cpp.

376 {
377  wxASSERT(mDB != nullptr);
378 
379  return mDB;
380 }

References mDB.

Referenced by ProjectFileIO::DB(), SqliteSampleBlock::DB(), ProjectFileIO::GetDiskUsage(), and SetDBError().

Here is the caller graph for this function:

◆ Detach()

sqlite3* DBConnection::Detach ( )

◆ FastMode()

int DBConnection::FastMode ( const char *  schema = "main")

Definition at line 341 of file DBConnection.cpp.

342 {
343  return ModeConfig(mDB, schema, FastConfig);
344 }

References FastConfig, mDB, and ModeConfig().

Here is the call graph for this function:

◆ GetLastMessage()

const wxString DBConnection::GetLastMessage ( ) const

Definition at line 387 of file DBConnection.cpp.

388 {
389  return sqlite3_errmsg(mDB);
390 }

References mDB.

◆ GetLastRC()

int DBConnection::GetLastRC ( ) const

Definition at line 382 of file DBConnection.cpp.

383 {
384  return sqlite3_errcode(mDB);
385 }

References mDB.

◆ ModeConfig()

int DBConnection::ModeConfig ( sqlite3 *  db,
const char *  schema,
const char *  config 
)
private

Definition at line 346 of file DBConnection.cpp.

347 {
348  // Ensure attached DB connection gets configured
349  int rc;
350 
351  // Replace all schema "keywords" with the schema name
352  wxString sql = config;
353  sql.Replace(wxT("<schema>"), schema);
354 
355  // Set the configuration
356  rc = sqlite3_exec(db, sql, nullptr, nullptr, nullptr);
357  if (rc != SQLITE_OK)
358  {
359  ADD_EXCEPTION_CONTEXT("sqlite3.rc", std::to_string(rc));
360  ADD_EXCEPTION_CONTEXT("sqlite3.context", "DBConnection::ModeConfig");
361  ADD_EXCEPTION_CONTEXT("sqlite3.mode", config);
362 
363  // Don't store in connection, just report it
364  wxLogMessage("Failed to set mode on %s\n"
365  "\tError: %s\n"
366  "\tSQL: %s",
367  sqlite3_db_filename(mDB, nullptr),
368  sqlite3_errmsg(mDB),
369  sql);
370  }
371 
372  return rc;
373 }

References ADD_EXCEPTION_CONTEXT, and mDB.

Referenced by FastMode(), OpenStepByStep(), and SafeMode().

Here is the caller graph for this function:

◆ Open()

int DBConnection::Open ( const FilePath  fileName)

Definition at line 133 of file DBConnection.cpp.

134 {
135  wxASSERT(mDB == nullptr);
136  int rc;
137 
138  // Initialize checkpoint controls
139  mCheckpointStop = false;
140  mCheckpointPending = false;
141  mCheckpointActive = false;
142  rc = OpenStepByStep( fileName );
143  if ( rc != SQLITE_OK)
144  {
145  if (mCheckpointDB)
146  {
147  sqlite3_close(mCheckpointDB);
148  mCheckpointDB = nullptr;
149  }
150 
151  if (mDB)
152  {
153  sqlite3_close(mDB);
154  mDB = nullptr;
155  }
156  }
157  return rc;
158 }

References mCheckpointActive, mCheckpointDB, mCheckpointPending, mCheckpointStop, mDB, and OpenStepByStep().

Here is the call graph for this function:

◆ OpenStepByStep()

int DBConnection::OpenStepByStep ( const FilePath  fileName)
private

Definition at line 160 of file DBConnection.cpp.

161 {
162  const char *name = fileName.ToUTF8();
163 
164  bool success = false;
165  int rc = sqlite3_open(name, &mDB);
166  if (rc != SQLITE_OK)
167  {
168  ADD_EXCEPTION_CONTEXT("sqlite3.rc", std::to_string(rc));
169  ADD_EXCEPTION_CONTEXT("sqlite3.context", "DBConnection::OpenStepByStep::open");
170 
171  wxLogMessage("Failed to open primary connection to %s: %d, %s\n",
172  fileName,
173  rc,
174  sqlite3_errstr(rc));
175  return rc;
176  }
177 
178  // Set default mode
179  // (See comments in ProjectFileIO::SaveProject() about threading
180  rc = SafeMode();
181  if (rc != SQLITE_OK)
182  {
183  SetDBError(XO("Failed to set safe mode on primary connection to %s").Format(fileName));
184  return rc;
185  }
186 
187  rc = sqlite3_open(name, &mCheckpointDB);
188  if (rc != SQLITE_OK)
189  {
190  ADD_EXCEPTION_CONTEXT("sqlite3.rc", std::to_string(rc));
191  ADD_EXCEPTION_CONTEXT("sqlite3.context", "DBConnection::OpenStepByStep::open_checkpoint");
192 
193  wxLogMessage("Failed to open checkpoint connection to %s: %d, %s\n",
194  fileName,
195  rc,
196  sqlite3_errstr(rc));
197  return rc;
198  }
199 
200  rc = ModeConfig(mCheckpointDB, "main", SafeConfig);
201  if (rc != SQLITE_OK) {
202  SetDBError(XO("Failed to set safe mode on checkpoint connection to %s").Format(fileName));
203  return rc;
204  }
205 
206  auto db = mCheckpointDB;
207  mCheckpointThread = std::thread(
208  [this, db, fileName]{ CheckpointThread(db, fileName); });
209 
210  // Install our checkpoint hook
211  sqlite3_wal_hook(mDB, CheckpointHook, this);
212  return rc;
213 }

References ADD_EXCEPTION_CONTEXT, CheckpointHook(), CheckpointThread(), mCheckpointDB, mCheckpointThread, mDB, ModeConfig(), name, SafeConfig, SafeMode(), SetDBError(), and XO.

Referenced by Open().

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

◆ Prepare()

sqlite3_stmt * DBConnection::Prepare ( enum StatementID  id,
const char *  sql 
)

Definition at line 392 of file DBConnection.cpp.

393 {
394  std::lock_guard<std::mutex> guard(mStatementMutex);
395 
396  int rc;
397  // See bug 2673
398  // We must not use the same prepared statement from two different threads.
399  // Therefore, in the cache, use the thread id too.
400  StatementIndex ndx(id, std::this_thread::get_id());
401 
402  // Return an existing statement if it's already been prepared
403  auto iter = mStatements.find(ndx);
404  if (iter != mStatements.end())
405  {
406  return iter->second;
407  }
408 
409  // Prepare the statement
410  sqlite3_stmt *stmt = nullptr;
411  rc = sqlite3_prepare_v3(mDB, sql, -1, SQLITE_PREPARE_PERSISTENT, &stmt, 0);
412  if (rc != SQLITE_OK)
413  {
414  ADD_EXCEPTION_CONTEXT("sqlite3.query", sql);
415  ADD_EXCEPTION_CONTEXT("sqlite3.rc", std::to_string(rc));
416  ADD_EXCEPTION_CONTEXT("sqlite3.context", "DBConnection::Prepare");
417 
418  wxLogMessage("Failed to prepare statement for %s\n"
419  "\tError: %s\n"
420  "\tSQL: %s",
421  sqlite3_db_filename(mDB, nullptr),
422  sqlite3_errmsg(mDB),
423  sql);
424 
425  // TODO: Look into why this causes an access violation
427  }
428 
429  // There are a small number (10 or so) of different id's corresponding
430  // to different SQL statements, see enum StatementID
431  // We have relatively few threads running at any one time,
432  // e.g. main gui thread, a playback thread, a thread for compacting.
433  // However the cache might keep growing, as we start/stop audio,
434  // perhaps, if we chose to use a new thread each time.
435  // For 3.0.0 I think that's OK. If it's a data leak it's a slow
436  // enough one. wxLogDebugs seem to show that the audio play thread
437  // is being reused, not recreated with a new ID, i.e. no leak at all.
438  // ANSWER-ME Just how serious is the data leak? How best to fix?
439 
440  // Remember the cached statement.
441  mStatements.insert({ndx, stmt});
442 
443  return stmt;
444 }

References ADD_EXCEPTION_CONTEXT, mDB, mStatementMutex, mStatements, and THROW_INCONSISTENCY_EXCEPTION.

Referenced by SqliteSampleBlock::Commit(), SqliteSampleBlock::Delete(), SqliteSampleBlock::DoGetSamples(), ProjectFileIO::GetDiskUsage(), SqliteSampleBlock::GetSummary(), and SqliteSampleBlock::Load().

Here is the caller graph for this function:

◆ SafeMode()

int DBConnection::SafeMode ( const char *  schema = "main")

Definition at line 336 of file DBConnection.cpp.

337 {
338  return ModeConfig(mDB, schema, SafeConfig);
339 }

References mDB, ModeConfig(), and SafeConfig.

Referenced by OpenStepByStep().

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

◆ SetBypass()

void DBConnection::SetBypass ( bool  bypass)

Definition at line 65 of file DBConnection.cpp.

66 {
67  mBypass = bypass;
68 }

References mBypass.

◆ SetDBError()

void DBConnection::SetDBError ( const TranslatableString msg,
const TranslatableString libraryError = {},
int  errorCode = -1 
)

Set stored errors and write to log; and default libraryError to what database library reports.

Definition at line 101 of file DBConnection.cpp.

103 {
104  auto db = DB();
105 
106  mpErrors->mErrorCode = errorCode < 0 && db
107  ? sqlite3_errcode(db)
108  : errorCode;
109 
110  mpErrors->mLastError = msg.empty()
111  ? XO("(%d): %s").Format(mpErrors->mErrorCode, sqlite3_errstr(mpErrors->mErrorCode))
112  : msg;
113 
114  mpErrors->mLibraryError = libraryError.empty() && db
115  ? Verbatim(sqlite3_errmsg(db))
116  : libraryError;
117 
118  wxLogMessage("DBConnection SetDBError\n"
119  "\tErrorCode: %d\n"
120  "\tLastError: %s\n"
121  "\tLibraryError: %s",
122  mpErrors->mErrorCode,
123  mpErrors->mLastError.Debug(),
124  mpErrors->mLibraryError.Debug());
125 
126  auto logger = AudacityLogger::Get();
127  if (logger)
128  {
129  mpErrors->mLog = logger->GetLog(10);
130  }
131 }

References DB(), TranslatableString::empty(), AudacityLogger::Get(), mpErrors, Verbatim(), and XO.

Referenced by OpenStepByStep().

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

◆ SetError()

void DBConnection::SetError ( const TranslatableString msg,
const TranslatableString libraryError = {},
int  errorCode = {} 
)

Just set stored errors.

Definition at line 75 of file DBConnection.cpp.

77 {
78  mpErrors->mErrorCode = errorCode;
79 
80  mpErrors->mLastError = msg;
81 
82  mpErrors->mLibraryError = errorCode && libraryError.empty()
83  ? XO("(%d): %s").Format(errorCode, sqlite3_errstr(errorCode))
84  : libraryError;
85 
86  wxLogMessage("DBConnection SetError\n"
87  "\tErrorCode: %d\n"
88  "\tLastError: %s\n"
89  "\tLibraryError: %s",
90  mpErrors->mErrorCode,
91  mpErrors->mLastError.Debug(),
92  mpErrors->mLibraryError.Debug());
93 
94  auto logger = AudacityLogger::Get();
95  if (logger)
96  {
97  mpErrors->mLog = logger->GetLog(10);
98  }
99 }

References TranslatableString::empty(), AudacityLogger::Get(), mpErrors, and XO.

Here is the call graph for this function:

◆ ShouldBypass()

bool DBConnection::ShouldBypass ( )

Definition at line 70 of file DBConnection.cpp.

71 {
72  return mBypass;
73 }

References mBypass.

◆ ThrowException()

void DBConnection::ThrowException ( bool  write) const

throw and show appropriate message box

Parameters
writeIf true, a database update failed; if false, only a SELECT failed

Definition at line 322 of file DBConnection.cpp.

323 {
324  // Sqlite3 documentation says returned character string
325  // does NOT require freeing by us.
326  wxString dbName{ sqlite3_db_filename(mDB, "main") };
327  // Now we have an absolute path. Throw a message box exception that
328  // formats a helpful message just as used to be done before sqlite3
329  // was used for projects.
330  throw FileException{
332  dbName
333  };
334 }

References mDB, FileException::Read, and FileException::Write.

Referenced by SqliteSampleBlock::Commit(), SqliteSampleBlock::Delete(), SqliteSampleBlock::GetBlob(), and SqliteSampleBlock::Load().

Here is the caller graph for this function:

Member Data Documentation

◆ mBypass

bool DBConnection::mBypass
private

Definition at line 126 of file DBConnection.h.

Referenced by SetBypass(), and ShouldBypass().

◆ mCallback

CheckpointFailureCallback DBConnection::mCallback
private

Definition at line 123 of file DBConnection.h.

Referenced by CheckpointThread().

◆ mCheckpointActive

std::atomic_bool DBConnection::mCheckpointActive { false }
private

Definition at line 116 of file DBConnection.h.

Referenced by CheckpointThread(), Close(), and Open().

◆ mCheckpointCondition

std::condition_variable DBConnection::mCheckpointCondition
private

Definition at line 112 of file DBConnection.h.

Referenced by CheckpointHook(), CheckpointThread(), and Close().

◆ mCheckpointDB

sqlite3* DBConnection::mCheckpointDB
private

Definition at line 109 of file DBConnection.h.

Referenced by Close(), Open(), and OpenStepByStep().

◆ mCheckpointMutex

std::mutex DBConnection::mCheckpointMutex
private

Definition at line 113 of file DBConnection.h.

Referenced by CheckpointHook(), CheckpointThread(), and Close().

◆ mCheckpointPending

std::atomic_bool DBConnection::mCheckpointPending { false }
private

Definition at line 115 of file DBConnection.h.

Referenced by CheckpointHook(), CheckpointThread(), Close(), and Open().

◆ mCheckpointStop

std::atomic_bool DBConnection::mCheckpointStop { false }
private

Definition at line 114 of file DBConnection.h.

Referenced by CheckpointThread(), Close(), and Open().

◆ mCheckpointThread

std::thread DBConnection::mCheckpointThread
private

Definition at line 111 of file DBConnection.h.

Referenced by Close(), and OpenStepByStep().

◆ mDB

sqlite3* DBConnection::mDB
private

◆ mpErrors

std::shared_ptr<DBConnectionErrors> DBConnection::mpErrors
private

Definition at line 122 of file DBConnection.h.

Referenced by SetDBError(), and SetError().

◆ mpProject

std::weak_ptr<AudacityProject> DBConnection::mpProject
private

Definition at line 107 of file DBConnection.h.

Referenced by Close().

◆ mStatementMutex

std::mutex DBConnection::mStatementMutex
private

Definition at line 118 of file DBConnection.h.

Referenced by Close(), and Prepare().

◆ mStatements

std::map<StatementIndex, sqlite3_stmt *> DBConnection::mStatements
private

Definition at line 120 of file DBConnection.h.

Referenced by Close(), and Prepare().


The documentation for this class was generated from the following files:
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
DBConnection::mCheckpointPending
std::atomic_bool mCheckpointPending
Definition: DBConnection.h:115
DBConnection::DeleteSampleBlock
@ DeleteSampleBlock
Definition: DBConnection.h:78
TranslatableString::empty
bool empty() const
Definition: TranslatableString.h:72
GuardedCall
R GuardedCall(const F1 &body, const F2 &handler=F2::Default(), std::function< void(AudacityException *)> delayedHandler=DefaultDelayedHandlerAction{})
Execute some code on any thread; catch any AudacityException; enqueue error report on the main thread...
Definition: AudacityException.h:202
wxFileNameWrapper
Definition: wxFileNameWrapper.h:21
DBConnection::mDB
sqlite3 * mDB
Definition: DBConnection.h:108
FileNames::AbbreviatePath
FILES_API wxString AbbreviatePath(const wxFileName &fileName)
Give enough of the path to identify the device. (On Windows, drive letter plus ':')
DBConnection::SetDBError
void SetDBError(const TranslatableString &msg, const TranslatableString &libraryError={}, int errorCode=-1)
Set stored errors and write to log; and default libraryError to what database library reports.
Definition: DBConnection.cpp:101
FileException::Cause::Write
@ Write
most important to detect when storage space is exhausted
FileException::Cause::Read
@ Read
Format
Abstract base class used in importing a file.
ExceptionType::BadEnvironment
@ BadEnvironment
Indicates problems with environment, such as a full disk.
FileException
Thrown for failure of file or database operations in deeply nested places.
Definition: FileException.h:19
XO
#define XO(s)
Definition: Internat.h:31
DBConnection::mCallback
CheckpointFailureCallback mCallback
Definition: DBConnection.h:123
DBConnection
Definition: DBConnection.h:40
DBConnection::GetSamples
@ GetSamples
Definition: DBConnection.h:73
DBConnection::DB
sqlite3 * DB()
Definition: DBConnection.cpp:375
SafeConfig
static const char * SafeConfig
Definition: DBConnection.cpp:28
DBConnection::mCheckpointDB
sqlite3 * mCheckpointDB
Definition: DBConnection.h:109
DBConnection::GetDBPage
@ GetDBPage
Definition: DBConnection.h:80
AudacityException
Base class for exceptions specially processed by the application.
Definition: AudacityException.h:33
DBConnection::OpenStepByStep
int OpenStepByStep(const FilePath fileName)
Definition: DBConnection.cpp:160
DBConnection::mCheckpointCondition
std::condition_variable mCheckpointCondition
Definition: DBConnection.h:112
FastConfig
static const char * FastConfig
Definition: DBConnection.cpp:36
name
const TranslatableString name
Definition: Distortion.cpp:98
AudacityLogger::Get
static AudacityLogger * Get()
Definition: AudacityLogger.cpp:35
DBConnection::GetRootPage
@ GetRootPage
Definition: DBConnection.h:79
THROW_INCONSISTENCY_EXCEPTION
#define THROW_INCONSISTENCY_EXCEPTION
Throw InconsistencyException, using C++ preprocessor to identify the source code location.
Definition: InconsistencyException.h:79
DBConnection::mpErrors
std::shared_ptr< DBConnectionErrors > mpErrors
Definition: DBConnection.h:122
DBConnection::CheckpointHook
static int CheckpointHook(void *data, sqlite3 *db, const char *schema, int pages)
Definition: DBConnection.cpp:541
DBConnection::GetSummary256
@ GetSummary256
Definition: DBConnection.h:74
DBConnection::mCheckpointThread
std::thread mCheckpointThread
Definition: DBConnection.h:111
DBConnection::GetSummary64k
@ GetSummary64k
Definition: DBConnection.h:75
BasicUI
Definition: Export.h:39
title
static const auto title
Definition: NoUpdatesAvailableDialog.cpp:22
SimpleGuard< void >
Specialization of SimpleGuard, also defining a default value.
Definition: AudacityException.h:159
BasicUI::MakeGenericProgress
std::unique_ptr< GenericProgressDialog > MakeGenericProgress(const WindowPlacement &placement, const TranslatableString &title, const TranslatableString &message)
Create and display a progress dialog (return nullptr if Services not installed)
Definition: BasicUI.h:281
DBConnection::InsertSampleBlock
@ InsertSampleBlock
Definition: DBConnection.h:77
DBConnection::mCheckpointActive
std::atomic_bool mCheckpointActive
Definition: DBConnection.h:116
DBConnection::mBypass
bool mBypass
Definition: DBConnection.h:126
DBConnection::LoadSampleBlock
@ LoadSampleBlock
Definition: DBConnection.h:76
DBConnection::SafeMode
int SafeMode(const char *schema="main")
Definition: DBConnection.cpp:336
DBConnection::mCheckpointMutex
std::mutex mCheckpointMutex
Definition: DBConnection.h:113
Verbatim
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
Definition: TranslatableString.h:321
ExceptionType::Internal
@ Internal
Indicates internal failure from Audacity.
DBConnection::ModeConfig
int ModeConfig(sqlite3 *db, const char *schema, const char *config)
Definition: DBConnection.cpp:346
DBConnection::CheckpointThread
void CheckpointThread(sqlite3 *db, const FilePath &fileName)
Definition: DBConnection.cpp:446
ADD_EXCEPTION_CONTEXT
#define ADD_EXCEPTION_CONTEXT(name, value)
Definition: SentryHelper.h:21
DBConnection::mpProject
std::weak_ptr< AudacityProject > mpProject
Definition: DBConnection.h:107
DBConnection::mStatementMutex
std::mutex mStatementMutex
Definition: DBConnection.h:118
SimpleMessageBoxException
A MessageBoxException that shows a given, unvarying string.
Definition: AudacityException.h:95
DBConnection::mCheckpointStop
std::atomic_bool mCheckpointStop
Definition: DBConnection.h:114
DBConnection::mStatements
std::map< StatementIndex, sqlite3_stmt * > mStatements
Definition: DBConnection.h:120
DBConnection::StatementIndex
std::pair< enum StatementID, std::thread::id > StatementIndex
Definition: DBConnection.h:119