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 542 of file DBConnection.cpp.

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

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 447 of file DBConnection.cpp.

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

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  wxGenericProgressDialog pd(title.Translation(),
244  XO("This may take several seconds").Translation(),
245  300000, // range
246  nullptr, // parent
247  wxPD_APP_MODAL | wxPD_ELAPSED_TIME | wxPD_SMOOTH);
248 
249  // Wait for the checkpoints to end
251  {
252  wxMilliSleep(50);
253  pd.Pulse();
254  }
255  }
256 
257  // Tell the checkpoint thread to shutdown
258  {
259  std::lock_guard<std::mutex> guard(mCheckpointMutex);
260  mCheckpointStop = true;
261  mCheckpointCondition.notify_one();
262  }
263 
264  // And wait for it to do so
265  if (mCheckpointThread.joinable())
266  {
267  mCheckpointThread.join();
268  }
269 
270  // We're done with the prepared statements
271  {
272  std::lock_guard<std::mutex> guard(mStatementMutex);
273  for (auto stmt : mStatements)
274  {
275  // No need to process return code, but log it for diagnosis
276  rc = sqlite3_finalize(stmt.second);
277  if (rc != SQLITE_OK)
278  {
279  wxLogMessage("Failed to finalize statement on %s\n"
280  "\tErrMsg: %s\n"
281  "\tSQL: %s",
282  sqlite3_db_filename(mDB, nullptr),
283  sqlite3_errmsg(mDB),
284  stmt.second);
285  }
286  }
287  mStatements.clear();
288  }
289 
290  // Not much we can do if the closes fail, so just report the error
291 
292  // Close the checkpoint connection
293  rc = sqlite3_close(mCheckpointDB);
294  if (rc != SQLITE_OK)
295  {
296  ADD_EXCEPTION_CONTEXT("sqlite3.rc", std::to_string(rc));
297  ADD_EXCEPTION_CONTEXT("sqlite3.context", "DBConnection::Close::close_checkpoint");
298 
299  wxLogMessage("Failed to close checkpoint connection for %s\n"
300  "\tError: %s\n",
301  sqlite3_db_filename(mCheckpointDB, nullptr),
302  sqlite3_errmsg(mCheckpointDB));
303  }
304  mCheckpointDB = nullptr;
305 
306  // Close the primary connection
307  rc = sqlite3_close(mDB);
308  if (rc != SQLITE_OK)
309  {
310  ADD_EXCEPTION_CONTEXT("sqlite3.rc", std::to_string(rc));
311  ADD_EXCEPTION_CONTEXT("sqlite3.context", "DBConnection::OpenStepByStep::close");
312 
313  wxLogMessage("Failed to close %s\n"
314  "\tError: %s\n",
315  sqlite3_db_filename(mDB, nullptr),
316  sqlite3_errmsg(mDB));
317  }
318  mDB = nullptr;
319 
320  return true;
321 }

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

Here is the call graph for this function:

◆ DB()

sqlite3 * DBConnection::DB ( )

Definition at line 376 of file DBConnection.cpp.

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

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 342 of file DBConnection.cpp.

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

References FastConfig, mDB, and ModeConfig().

Here is the call graph for this function:

◆ GetLastMessage()

const wxString DBConnection::GetLastMessage ( ) const

Definition at line 388 of file DBConnection.cpp.

389 {
390  return sqlite3_errmsg(mDB);
391 }

References mDB.

◆ GetLastRC()

int DBConnection::GetLastRC ( ) const

Definition at line 383 of file DBConnection.cpp.

384 {
385  return sqlite3_errcode(mDB);
386 }

References mDB.

◆ ModeConfig()

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

Definition at line 347 of file DBConnection.cpp.

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

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 393 of file DBConnection.cpp.

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

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 337 of file DBConnection.cpp.

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

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 323 of file DBConnection.cpp.

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

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
wxFileNameWrapper
Definition: wxFileNameWrapper.h:21
DBConnection::mDB
sqlite3 * mDB
Definition: DBConnection.h:108
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:376
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
FileNames::AbbreviatePath
AUDACITY_DLL_API wxString AbbreviatePath(const wxFileName &fileName)
Give enough of the path to identify the device. (On Windows, drive letter plus ':')
name
const TranslatableString name
Definition: Distortion.cpp:98
AudacityLogger::Get
static AudacityLogger * Get()
Definition: AudacityLogger.cpp:58
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:542
DBConnection::GetSummary256
@ GetSummary256
Definition: DBConnection.h:74
DBConnection::mCheckpointThread
std::thread mCheckpointThread
Definition: DBConnection.h:111
DBConnection::GetSummary64k
@ GetSummary64k
Definition: DBConnection.h:75
SimpleGuard< void >
Specialization of SimpleGuard, also defining a default value.
Definition: AudacityException.h:155
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
GuardedCall
R GuardedCall(const F1 &body, const F2 &handler=F2::Default(), const F3 &delayedHandler={})
Execute some code on any thread; catch any AudacityException; enqueue error report on the main thread...
Definition: AudacityException.h:201
DBConnection::LoadSampleBlock
@ LoadSampleBlock
Definition: DBConnection.h:76
DBConnection::SafeMode
int SafeMode(const char *schema="main")
Definition: DBConnection.cpp:337
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:347
DBConnection::CheckpointThread
void CheckpointThread(sqlite3 *db, const FilePath &fileName)
Definition: DBConnection.cpp:447
TranslatableString::Translation
wxString Translation() const
Definition: TranslatableString.h:79
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:91
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