/// <summary> /// Adds a single new entry to the dictionary. /// </summary> public void NewEntry(CedictEntry entry, string note) { tr = conn.BeginTransaction(); string head, trg; entry.GetCedict(out head, out trg); // Check restrictions - can end up dropped entry checkRestrictions(entry.ChSimpl, trg); // Check for duplicate if (SqlDict.DoesHeadExist(head)) { throw new Exception("Headword already exists: " + head); } // Serialize, store in DB, index int binId = indexEntry(entry); // Populate entries table int entryId = storeEntry(entry.ChSimpl, head, trg, binId); // Record change cmdInsModifNew.Parameters["@timestamp"].Value = DateTime.UtcNow; cmdInsModifNew.Parameters["@user_id"].Value = userId; cmdInsModifNew.Parameters["@note"].Value = note; cmdInsModifNew.Parameters["@entry_id"].Value = entryId; cmdInsModifNew.ExecuteNonQuery(); int modifId = (int)cmdInsModifNew.LastInsertedId; // Also link from entry cmdUpdLastModif.Parameters["@entry_id"].Value = entryId; cmdUpdLastModif.Parameters["@last_modif_id"].Value = modifId; cmdUpdLastModif.ExecuteNonQuery(); // Commit. Otherwise, dispose will roll all this back if it finds non-null transaction. tr.Commit(); tr.Dispose(); tr = null; }
/// <summary> /// Process one line in the CEDICT format: parse, and store/index in dictionary. /// !! Does not check against dupes; cannot be used to update. /// </summary> public void AddEntry(string line) { ++lineNum; // Cycle through transactions if (lineNum % 3000 == 0) { tr.Commit(); tr.Dispose(); tr = null; tr = conn.BeginTransaction(); } // Parse line from CEDICT format CedictEntry entry = CedictCompiler.ParseEntry(line, lineNum, swLog, swDropped); if (entry == null) { return; } string head, trg; entry.GetCedict(out head, out trg); // Check restrictions - can end up dropped entry try { checkRestrictions(entry.ChSimpl, trg); } catch { return; } // Serialize, store in DB, index int binId = indexEntry(entry); // Populate entries table int entryId = storeEntry(entry.ChSimpl, head, trg, binId); // Folding history: mark new entry as affected by this bulk operation if (foldHistory) { cmdInsBulkModif.Parameters["@modif_id"].Value = modifId; cmdInsBulkModif.Parameters["@entry_id"].Value = entryId; cmdInsBulkModif.ExecuteNonQuery(); } // Verbose (per-entry) history else { // Record change cmdInsModifNew.Parameters["@timestamp"].Value = DateTime.UtcNow; cmdInsModifNew.Parameters["@user_id"].Value = userId; cmdInsModifNew.Parameters["@note"].Value = note; cmdInsModifNew.Parameters["@entry_id"].Value = entryId; cmdInsModifNew.ExecuteNonQuery(); int modifId = (int)cmdInsModifNew.LastInsertedId; // Also link from entry cmdUpdLastModif.Parameters["@entry_id"].Value = entryId; cmdUpdLastModif.Parameters["@last_modif_id"].Value = modifId; cmdUpdLastModif.ExecuteNonQuery(); } }