public void Dispose() { if (m_db != null) { m_db.Close(); m_db.Dispose(); m_db = null; } }
public void Dispose() { if (sqlClient != null) { sqlClient.Close(); sqlClient.Dispose(); sqlClient = null; } }
private void Open() { try { // Maybe called by an exception if (m_db != null) { try { m_db.Close(); m_db.Dispose(); Log.Warn("PictureDatabaseSqlLite: Disposing current instance.."); } catch (Exception) {} } // Open database try { Directory.CreateDirectory(Config.GetFolder(Config.Dir.Database)); } catch (Exception) {} m_db = new SQLiteClient(Config.GetFile(Config.Dir.Database, "PictureDatabase.db3")); // Retry 10 times on busy (DB in use or system resources exhausted) m_db.BusyRetries = 10; // Wait 100 ms between each try (default 10) m_db.BusyRetryDelay = 100; _dbHealth = DatabaseUtility.IntegrityCheck(m_db); DatabaseUtility.SetPragmas(m_db); CreateTables(); InitSettings(); } catch (Exception ex) { Log.Error("picture database exception err:{0} stack:{1}", ex.Message, ex.StackTrace); Open(); } Log.Info("picture database opened"); }
public static void Close() { string databaseFile = Settings.GetPath(Settings.Path.database); try { m_db.Close(); m_db.Dispose(); m_db = null; MPTVSeriesLog.Write("Successfully closed database. Filename = '{0}'", databaseFile); } catch (Exception) { MPTVSeriesLog.Write("Failed to close database. Filename = '{0}'", databaseFile); } }
public void Close() { lock (lockObject) { if (!_connected) { return; } logger.Info("Closing database connection..."); try { sqliteClient.Close(); sqliteClient.Dispose(); logger.Info("Successfully closed Database: {0}", dbFilename); _connected = false; } catch (Exception e) { logger.ErrorException("Failed closing Database: " + dbFilename, e); } } }
void init() { lock (syncRoot) { if (isInit) { return; } string dbFile = Config.GetFile(Config.Dir.Database, DB_FILE_NAME); bool exists = File.Exists(dbFile); sqlClient = new SQLiteClient(dbFile); DatabaseUtility.AddTable(sqlClient, Emulator.TABLE_NAME, Emulator.DBTableString); DatabaseUtility.AddTable(sqlClient, EmulatorProfile.TABLE_NAME, EmulatorProfile.DBTableString); DatabaseUtility.AddTable(sqlClient, Game.TABLE_NAME, Game.DBTableString); DatabaseUtility.AddTable(sqlClient, GameDisc.TABLE_NAME, GameDisc.DBTableString); DatabaseUtility.AddTable(sqlClient, "Info", "CREATE TABLE Info(" + "name varchar(50)," + "value varchar(100)," + "PRIMARY KEY(name)" + ")" ); isInit = true; SQLiteResultSet result = sqlClient.Execute("SELECT value FROM Info WHERE name='version'"); if (result.Rows.Count == 0) { if (exists) { sqlClient.Execute("INSERT INTO Info VALUES('version','1.7')"); isInit = false; sqlClient.Dispose(); init(); } else { UpdateDBVersion(); } return; } double currentVersion = double.Parse(result.Rows[0].fields[0], System.Globalization.CultureInfo.InvariantCulture); if (currentVersion == DB_VERSION) { return; } if (!backupDBFile()) { isInit = false; return; } if (updateDatabase(currentVersion)) { UpdateDBVersion(); return; } isInit = false; sqlClient.Dispose(); Logger.LogInfo("Deleting incompatible database (backup has been created)"); try { File.Delete(dbFile); } catch (Exception ex) { Logger.LogError("Failed to delete database file, try deleting {0} manually - {1}", dbFile, ex.Message); return; } init(); } }