MCPcopy Create free account
hub / github.com/audacity/audacity / Open

Method Open

libraries/lib-sqlite-helpers/sqlite/Connection.cpp:20–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18namespace audacity::sqlite
19{
20Result<Connection>
21Connection::Open(std::string_view path, OpenMode mode, ThreadMode threadMode)
22{
23 auto error = Initialize();
24
25 if (error.IsError())
26 return error;
27
28 int flags = 0;
29
30 switch (mode)
31 {
32 case OpenMode::ReadWrite:
33 flags = SQLITE_OPEN_READWRITE;
34 break;
35 case OpenMode::ReadOnly:
36 flags = SQLITE_OPEN_READONLY;
37 break;
38 case OpenMode::ReadWriteCreate:
39 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
40 break;
41 case OpenMode::Memory:
42 flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY;
43 break;
44 }
45
46 switch (threadMode)
47 {
48 case ThreadMode::MultiThread:
49 flags |= SQLITE_OPEN_NOMUTEX;
50 break;
51 case ThreadMode::Serialized:
52 flags |= SQLITE_OPEN_FULLMUTEX;
53 break;
54 }
55
56 sqlite3* connection = nullptr;
57
58 // If the path is not null-terminated, copy it to a temporary string.
59 std::string temp;
60 if (*(path.data() + path.size()) != '\0')
61 {
62 temp = std::string(path);
63 path = temp;
64 }
65
66 error = Error(sqlite3_open_v2(path.data(), &connection, flags, nullptr));
67
68 if (error.IsError())
69 return error;
70
71 return Connection(connection, true);
72}
73
74Result<Connection> Connection::Wrap(sqlite3* connection)
75{

Callers

nothing calls this directly

Calls 6

IsErrorMethod · 0.80
InitializeFunction · 0.70
ErrorFunction · 0.70
ConnectionFunction · 0.70
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected