public void AddTables(string[] asTableNames) { int i = 0; string[] asSqlCommands; if (((_eState == nState.OK) || (_eState == nState.FileNotFound)) && (_DatabaseConnection != null) && (asTableNames != null) && (asTableNames.Length > 0)) { _eState = nState.OK; asSqlCommands = new string[asTableNames.Length]; foreach (string sTableName in asTableNames) { asSqlCommands[i++] = "CREATE TABLE IF NOT EXISTS " + sTableName + " ( id INT PRIMARY KEY NOT NULL, data BLOB )"; } CommandsNonQuery(asSqlCommands); Close(); if (File.Exists(_sPath)) { _eState = nState.OK; } else { _eState = nState.FileNotFound; } } else { _eState = nState.CouldNotCreate; } }
public bool Open() { if (_eState == nState.OK) { if (!_isOpen) { try { _DatabaseConnection.Open(); _isOpen = true; _eState = nState.OK; } catch { _isOpen = false; _eState = nState.CouldNotOpen; } } } else { _isOpen = false; _eState = nState.CouldNotOpen; if (_DatabaseConnection != null) { _DatabaseConnection.Close(); _DatabaseConnection = null; } } return(_isOpen); }
protected SQLiteDatabase() { _isOpen = false; _abMemoryBuffer = new byte[ciMemoryBufferLength]; _eState = nState.Undefined; _sPath = _sConnectionString = string.Empty; _DatabaseConnection = null; }
/// <summary></summary> public bool Start() { if ((_eState != nState.Idle) || _quCommand.IsEmpty) { return(false); } else { eState = nState.Working; _AsyncThread = new Thread(() => AsynchronousThreadMethod()); _AsyncThread.Start(); return(true); } }
/// <summary></summary> public bool Start() { if ((_eState != nState.Idle) || _quCommands.IsEmpty) { return(false); } else { // Task t = new Task(() => { _Cryptography.FillKey(new CryptoKey("", CryptoKey.nKeyFormat.KeePass, CryptoKey.nKeyType.Symmetric, 32)); }); // t.Start(); eState = nState.Working; _AsyncThread = new Thread(() => AsynchronousThreadMethod()); _AsyncThread.Start(); return(true); } }
/// <summary></summary> private void AsynchronousThreadMethod() { while (_quCommand.TryDequeue(out BackgroundMessage UserInterfaceMessage)) { switch (UserInterfaceMessage.eType) { case BackgroundMessage.nType.PasswordToKey: ExecutePasswordToKey(UserInterfaceMessage); break; default: throw new NotImplementedException("command not implemented: " + UserInterfaceMessage.eType.ToString()); } if (_eState == nState.CancelRequested) { Reset(); } } _quReturn.Enqueue(new BackgroundMessage(BackgroundMessage.nType.Stop)); eState = nState.Idle; _AsyncThread = null; }
/// <summary>Reset all variables.</summary> private void Reset() { #pragma warning disable IDE0059 // Suppres warnings that the value assigned to variable is never used if (!_quCommands.IsEmpty) { while (_quCommands.TryDequeue(out BackgroundMessage MessageToDiscard)) { ; } } if (!_quReturn.IsEmpty) { while (_quReturn.TryDequeue(out BackgroundMessage MessageToDiscard)) { ; } } #pragma warning restore IDE0059 // Value assigned to variable is never used eState = nState.Idle; _AsyncThread = null; }
public SQLiteDatabase(string sPath) : this() { string sDirectoryName = Path.GetDirectoryName(sPath); if (string.IsNullOrEmpty(sPath)) { _eState = nState.DirectoryNotFound; } else { if (!Directory.Exists(sDirectoryName)) { try { Directory.CreateDirectory(sDirectoryName); } catch { }; } if (Directory.Exists(sDirectoryName)) { _sPath = sPath; _sConnectionString = "Data Source=" + _sPath; _DatabaseConnection = new SQLiteConnection(_sConnectionString); if (File.Exists(sPath)) { _eState = nState.OK; } else { _eState = nState.FileNotFound; } } else { _eState = nState.DirectoryNotFound; } } }
/// <summary></summary> public void RequestCancel() { eState = nState.CancelRequested; }