public OpenResult Open() { if (_connection.State == ConnectionState.Connecting || _connection.State == ConnectionState.Open) { return(OpenResult.AlreadyOpen); } try { _connection.Open(); return(OpenResult.Open); } #if UNITY_EDITOR catch (Exception ex) { SQLiteLogger.LogError( new SQLiteLogger.LogPart("Error trying to open database with connection string:", Color.white), SQLiteLogger.LogPart.newLine, new SQLiteLogger.LogPart(_connection.ConnectionString, Constants.Colors.lightBlue), SQLiteLogger.LogPart.newLine, new SQLiteLogger.LogPart(ex, Color.red)); #else catch { #endif return(OpenResult.Failure); } }
public CloseResult Close() { if (_connection.State == ConnectionState.Broken || _connection.State == ConnectionState.Closed) { return(CloseResult.AlreadyClose); } try { _connection.Close(); return(CloseResult.Close); } #if UNITY_EDITOR catch (Exception ex) { SQLiteLogger.LogError( new SQLiteLogger.LogPart("Error trying to close database:", Color.white), SQLiteLogger.LogPart.newLine, new SQLiteLogger.LogPart(ex, Color.red)); #else catch { #endif return(CloseResult.Failure); } }
public static CreateResult Create(string databaseFilePath) { if (File.Exists(databaseFilePath)) { return(CreateResult.AlreadyExists); } string parentDirectory = Directory.GetParent(databaseFilePath).ToString(); if (!Directory.Exists(parentDirectory)) { Directory.CreateDirectory(parentDirectory); } try { SqliteConnection.CreateFile(databaseFilePath); return(CreateResult.Create); } #if UNITY_EDITOR catch (SqliteException ex) { SQLiteLogger.LogError( new SQLiteLogger.LogPart("Error trying to create database file at path:", Color.white), SQLiteLogger.LogPart.newLine, new SQLiteLogger.LogPart(databaseFilePath, Constants.Colors.lightBlue), SQLiteLogger.LogPart.newLine, new SQLiteLogger.LogPart(ex, Color.red)); #else catch { #endif return(CreateResult.Failure); } }