@@ -25,7 +25,8 @@ using namespace facebook;
25
25
std::map<std::string, ConnectionPool *> dbMap =
26
26
std::map<std::string, ConnectionPool *>();
27
27
28
- SQLiteOPResult generateNotOpenResult (std::string const &dbName) {
28
+ SQLiteOPResult generateNotOpenResult (std::string const &dbName)
29
+ {
29
30
return SQLiteOPResult{
30
31
.type = SQLiteError,
31
32
.errorMessage = dbName + " is not open" ,
@@ -42,8 +43,10 @@ sqliteOpenDb(string const dbName, string const docPath,
42
43
const char *, sqlite3_int64),
43
44
void (*onTransactionFinalizedCallback)(
44
45
const TransactionCallbackPayload *event),
45
- uint32_t numReadConnections) {
46
- if (dbMap.count (dbName) == 1 ) {
46
+ uint32_t numReadConnections)
47
+ {
48
+ if (dbMap.count (dbName) == 1 )
49
+ {
47
50
return SQLiteOPResult{
48
51
.type = SQLiteError,
49
52
.errorMessage = dbName + " is already open" ,
@@ -60,8 +63,10 @@ sqliteOpenDb(string const dbName, string const docPath,
60
63
};
61
64
}
62
65
63
- SQLiteOPResult sqliteCloseDb (string const dbName) {
64
- if (dbMap.count (dbName) == 0 ) {
66
+ SQLiteOPResult sqliteCloseDb (string const dbName)
67
+ {
68
+ if (dbMap.count (dbName) == 0 )
69
+ {
65
70
return generateNotOpenResult (dbName);
66
71
}
67
72
@@ -76,8 +81,10 @@ SQLiteOPResult sqliteCloseDb(string const dbName) {
76
81
};
77
82
}
78
83
79
- void sqliteCloseAll () {
80
- for (auto const &x : dbMap) {
84
+ void sqliteCloseAll ()
85
+ {
86
+ for (auto const &x : dbMap)
87
+ {
81
88
x.second ->closeAll ();
82
89
delete x.second ;
83
90
}
@@ -86,8 +93,10 @@ void sqliteCloseAll() {
86
93
87
94
SQLiteOPResult sqliteQueueInContext (std::string dbName,
88
95
ConnectionLockId const contextId,
89
- std::function<void (sqlite3 *)> task) {
90
- if (dbMap.count (dbName) == 0 ) {
96
+ std::function<void (sqlite3 *)> task)
97
+ {
98
+ if (dbMap.count (dbName) == 0 )
99
+ {
91
100
return generateNotOpenResult (dbName);
92
101
}
93
102
@@ -96,33 +105,41 @@ SQLiteOPResult sqliteQueueInContext(std::string dbName,
96
105
}
97
106
98
107
void sqliteReleaseLock (std::string const dbName,
99
- ConnectionLockId const contextId) {
100
- if (dbMap.count (dbName) == 0 ) {
108
+ ConnectionLockId const contextId)
109
+ {
110
+ LOGSIMPLE (" [sqliteReleaseLock] start %lld" , timestamp);
111
+ if (dbMap.count (dbName) == 0 )
112
+ {
101
113
// Do nothing if the lock does not actually exist
102
114
return ;
103
115
}
104
116
105
117
ConnectionPool *connection = dbMap[dbName];
106
118
connection->closeContext (contextId);
119
+ LOGSIMPLE (" [sqliteReleaseLock] end %lld" , timestamp);
107
120
}
108
121
109
122
SQLiteOPResult sqliteRequestLock (std::string const dbName,
110
123
ConnectionLockId const contextId,
111
- ConcurrentLockType lockType) {
112
- if (dbMap.count (dbName) == 0 ) {
124
+ ConcurrentLockType lockType)
125
+ {
126
+ if (dbMap.count (dbName) == 0 )
127
+ {
113
128
return generateNotOpenResult (dbName);
114
129
}
115
130
116
131
ConnectionPool *connection = dbMap[dbName];
117
132
118
- if (connection == nullptr ) {
133
+ if (connection == nullptr )
134
+ {
119
135
return SQLiteOPResult{
120
136
.type = SQLiteOk,
121
137
122
138
};
123
139
}
124
140
125
- switch (lockType) {
141
+ switch (lockType)
142
+ {
126
143
case ConcurrentLockType::ReadLock:
127
144
connection->readLock (contextId);
128
145
break ;
@@ -141,35 +158,43 @@ SQLiteOPResult sqliteRequestLock(std::string const dbName,
141
158
142
159
SQLiteOPResult sqliteAttachDb (string const mainDBName, string const docPath,
143
160
string const databaseToAttach,
144
- string const alias) {
145
- if (dbMap.count (mainDBName) == 0 ) {
161
+ string const alias)
162
+ {
163
+ if (dbMap.count (mainDBName) == 0 )
164
+ {
146
165
return generateNotOpenResult (mainDBName);
147
166
}
148
167
149
168
ConnectionPool *connection = dbMap[mainDBName];
150
169
return connection->attachDatabase (databaseToAttach, docPath, alias);
151
170
}
152
171
153
- SQLiteOPResult sqliteDetachDb (string const mainDBName, string const alias) {
154
- if (dbMap.count (mainDBName) == 0 ) {
172
+ SQLiteOPResult sqliteDetachDb (string const mainDBName, string const alias)
173
+ {
174
+ if (dbMap.count (mainDBName) == 0 )
175
+ {
155
176
return generateNotOpenResult (mainDBName);
156
177
}
157
178
158
179
ConnectionPool *connection = dbMap[mainDBName];
159
180
return connection->detachDatabase (alias);
160
181
}
161
182
162
- SQLiteOPResult sqliteRemoveDb (string const dbName, string const docPath) {
163
- if (dbMap.count (dbName) == 1 ) {
183
+ SQLiteOPResult sqliteRemoveDb (string const dbName, string const docPath)
184
+ {
185
+ if (dbMap.count (dbName) == 1 )
186
+ {
164
187
SQLiteOPResult closeResult = sqliteCloseDb (dbName);
165
- if (closeResult.type == SQLiteError) {
188
+ if (closeResult.type == SQLiteError)
189
+ {
166
190
return closeResult;
167
191
}
168
192
}
169
193
170
194
string dbPath = get_db_path (dbName, docPath);
171
195
172
- if (!file_exists (dbPath)) {
196
+ if (!file_exists (dbPath))
197
+ {
173
198
return SQLiteOPResult{
174
199
.type = SQLiteOk,
175
200
.errorMessage =
0 commit comments