public SetValue(SqliteWordList owner, int index, EntryProperty property, T oldValue, T newValue) : base(owner) { this.index = index; this.oldValue = oldValue; this.newValue = newValue; this.property = property; }
public SortCommand(SqliteWordList owner, Comparison <WordListEntry> comparison) : base(owner) { if (comparison == null) { throw new ArgumentNullException("comparison"); } this.comparison = comparison; }
public static SqliteWordList FromSetID(SqliteDataStore store, long setID) { var list = new SqliteWordList(store, setID); if (!list.worker.Exists()) { list.Dispose(); return(null); } return(list); }
public Worker(SqliteObject store, SqliteWordList list) : base(store) { this.list = list; existsCommand = Connection.CreateCommand(); existsCommand.CommandText = @"SELECT Count(*) FROM Sets WHERE Sets.id = ?"; existsCommandID = existsCommand.CreateParameter(); existsCommand.Parameters.Add(existsCommandID); existsCommandID.Value = list.ID; insertCommand = Connection.CreateCommand(); insertCommand.CommandText = @" UPDATE VocabItems SET ListPosition = ListPosition + 1 WHERE SetID = $SetID AND ListPosition >= $ListPosition; INSERT INTO VocabItems (Phrase, Translation, SetID, ListPosition) VALUES ($Phrase, $Translation, $SetID, $ListPosition);" ; insertCommandSetID = insertCommand.CreateParameter(); insertCommandSetID.ParameterName = "SetID"; insertCommandSetID.Value = list.ID; insertCommand.Parameters.Add(insertCommandSetID); insertCommandListPosition = insertCommand.CreateParameter(); insertCommandListPosition.ParameterName = "ListPosition"; insertCommand.Parameters.Add(insertCommandListPosition); insertCommandPhrase = insertCommand.CreateParameter(); insertCommandPhrase.ParameterName = "Phrase"; insertCommand.Parameters.Add(insertCommandPhrase); insertCommandTranslation = insertCommand.CreateParameter(); insertCommandTranslation.ParameterName = "Translation"; insertCommand.Parameters.Add(insertCommandTranslation); deleteCommand = Connection.CreateCommand(); deleteCommand.CommandText = @" DELETE From VocabItems WHERE SetID = $SetID AND ListPosition = $ListPosition; UPDATE VocabItems SET ListPosition = ListPosition - 1 WHERE SetId = $SetID AND ListPosition > $ListPosition" ; deleteCommandSetID = deleteCommand.CreateParameter(); deleteCommandSetID.ParameterName = "SetID"; deleteCommand.Parameters.Add(deleteCommandSetID); deleteCommandListPosition = deleteCommand.CreateParameter(); deleteCommandListPosition.ParameterName = "ListPosition"; deleteCommand.Parameters.Add(deleteCommandListPosition); }
public Deletion(SqliteWordList owner, IEnumerable <int> indices) : base(owner) { foreach (int i in indices) { items.Add(new KeyValuePair <int, WordListEntry>(i, new WordListEntry(owner, list[i].Phrase, list[i].Translation) )); } // The indices must be in order for the deletion to proceed correctly. // Deleting lower indices before higher indices would result in shifting, and // subsequent deletions may delete the wrong entry. items.Sort((k1, k2) => k1.Key.CompareTo(k2.Key)); this.indices = items.ConvertAll(kvp => kvp.Key); }
public SqliteWordList CreateSet(string name, string author, string language, string url, DateTime?date) { long setID; using (var txn = Connection.BeginTransaction()) { ExecuteSQL("INSERT INTO Sets (Name, Author, Language, Url, Created) VALUES (?, ?, ?, ?, ?)", name, author, language, url, date.HasValue ? (object)date.Value : (object)DBNull.Value); setID = GetLastInsertRowID(); txn.Commit(); } var wl = SqliteWordList.FromSetID(this, setID); if (wl == null) { return(null); } wordLists[setID] = new NullWeakReference <SqliteWordList>(wl); return(wl); }
public MoveRowsCommand(SqliteWordList owner, IList <int> rows, int destination) : base(owner) { foreach (int i in rows) { if (i < 0 || i >= list.Count) { throw new ArgumentException("rows"); } } if (destination < 0 || destination > list.Count) { throw new ArgumentException("destination"); } // We require that the list of rows is in ascending order. this.rows = new List <int>(rows); this.rows.Sort(); this.destination = destination; // An optimisation: check if the operation would do nothing. bool contiguous = true; for (int i = 0; i < rows.Count - 1; ++i) { if (rows[i] + 1 != rows[i + 1]) { contiguous = false; break; } } idempotent = rows.Count == 0 || (contiguous && destination >= rows[0] && destination <= rows[0] + rows.Count); }
/// <param name="setID">The SetID of the word list</param> /// <returns>An existing SqliteWordList instance, if one exists, otherwise a newly-created SqliteWordList.</returns> public SqliteWordList GetWordList(long setID) { SqliteWordList wl = null; NullWeakReference <SqliteWordList> list; if (wordLists.TryGetValue(setID, out list)) { wl = list.Target; } if (wl != null) { return(wl); } wl = SqliteWordList.FromSetID(this, setID); if (wl == null) { return(null); } wordLists[setID] = new NullWeakReference <SqliteWordList>(wl); return(wl); }
public MultipleInsertion(SqliteWordList owner, int index, IList <WordListEntry> items) : base(owner) { this.index = index; this.items = items; }
public Insertion(SqliteWordList owner, int index, WordListEntry item) : base(owner) { this.index = index; this.item = item; }
public SetItem(SqliteWordList owner, int index, WordListEntry item) : base(owner) { this.index = index; this.item = item; }
protected Command(SqliteWordList owner) { worker = owner.worker; list = owner.list; this.owner = owner; }
public SwapRowsCommand(SqliteWordList owner, IList <int> indices) : base(owner) { this.indices = indices; }
public Deletion(SqliteWordList owner, params int[] indices) : this(owner, (IEnumerable <int>)indices) { }