@@ -14,6 +14,8 @@ internal class InMemoryFingerprintDatabase : IFingerprintDatabase
14
14
InMemoryModelService modelService = null ;
15
15
SQLiteConnection sqlite_conn = null ;
16
16
17
+ string databasePath = "" ;
18
+
17
19
18
20
public DateTime lastPlexIntroAdded
19
21
{
@@ -66,6 +68,8 @@ public void LoadDatabase(string path)
66
68
67
69
SetupNewScan ( ) ;
68
70
71
+ databasePath = path ;
72
+
69
73
SQLiteConnectionStringBuilder sb = new SQLiteConnectionStringBuilder ( ) ;
70
74
sb . DataSource = Program . PathCombine ( path , "fingerprintMedia.db" ) ;
71
75
sb . Version = 3 ;
@@ -239,14 +243,25 @@ public int ExecuteDBCommand(string cmd, Dictionary<string, object> p = null)
239
243
}
240
244
}
241
245
246
+ int count = 0 ;
247
+
242
248
while ( true )
243
249
{
244
250
try
245
251
{
252
+ count ++ ;
246
253
return sqlite_cmd . ExecuteNonQuery ( ) ;
247
254
}
248
255
catch ( SQLiteException ex )
249
256
{
257
+ if ( count >= 2 )
258
+ {
259
+ Console . WriteLine ( $ "PlexDB ExecuteDBCommand Database has been locked for a long time. Attempting to re-connect.") ;
260
+ CloseDatabase ( ) ;
261
+ LoadDatabase ( databasePath ) ;
262
+ count = 0 ;
263
+ }
264
+
250
265
if ( ( SQLiteErrorCode ) ex . ErrorCode != SQLiteErrorCode . Busy )
251
266
{
252
267
Console . WriteLine ( "InMemoryFingerprintDatabase.ExecuteDBCommand exception: " + ex . Message + "" +
@@ -260,6 +275,7 @@ public int ExecuteDBCommand(string cmd, Dictionary<string, object> p = null)
260
275
Console . WriteLine ( $ "{ x . Key } = { x . Value } ") ;
261
276
}
262
277
}
278
+ Program . Exit ( ) ;
263
279
return - 1 ;
264
280
}
265
281
Thread . Sleep ( 10 ) ;
@@ -283,10 +299,13 @@ public SQLResultInfo ExecuteDBQuery(string cmd, Dictionary<string, object> p = n
283
299
}
284
300
}
285
301
302
+ int count = 0 ;
303
+
286
304
while ( true )
287
305
{
288
306
try
289
307
{
308
+ count ++ ;
290
309
//var reader = sqlite_cmd.ExecuteReader(System.Data.CommandBehavior.KeyInfo);
291
310
ret . reader = sqlite_cmd . ExecuteReader ( ) ;
292
311
@@ -299,6 +318,14 @@ public SQLResultInfo ExecuteDBQuery(string cmd, Dictionary<string, object> p = n
299
318
}
300
319
catch ( SQLiteException ex )
301
320
{
321
+ if ( count >= 2 )
322
+ {
323
+ Console . WriteLine ( $ "PlexDB ExecuteDBCommand Database has been locked for a long time. Attempting to re-connect.") ;
324
+ CloseDatabase ( ) ;
325
+ LoadDatabase ( databasePath ) ;
326
+ count = 0 ;
327
+ }
328
+
302
329
if ( ( SQLiteErrorCode ) ex . ErrorCode != SQLiteErrorCode . Busy )
303
330
{
304
331
Console . WriteLine ( "InMemoryFingerprintDatabase.ExecuteDBCommand exception: " + ex . Message + "" +
@@ -312,6 +339,7 @@ public SQLResultInfo ExecuteDBQuery(string cmd, Dictionary<string, object> p = n
312
339
Console . WriteLine ( $ "{ x . Key } = { x . Value } ") ;
313
340
}
314
341
}
342
+ Program . Exit ( ) ;
315
343
return null ;
316
344
}
317
345
Thread . Sleep ( 10 ) ;
0 commit comments