public void UpdateRecord(IBaseWindow baseWin, GDMRecord record) { if (baseWin == null) { throw new ArgumentNullException("baseWin"); } if (record == null || !IsIndexedRecord(record)) { return; } try { lock (fLock) { using (WritableDatabase database = new WritableDatabase(GetXDBFolder(), Xapian.Xapian.DB_CREATE_OR_OPEN)) using (TermGenerator indexer = new TermGenerator()) using (Stem stemmer = new Stem("russian")) { indexer.SetStemmer(stemmer); ReindexRecord(baseWin, database, indexer, record); SetDBLastChange(baseWin, database); } } } catch (Exception ex) { Logger.LogWrite("SearchManager.UpdateRecord(): " + ex.Message); } }
public void DeleteRecord(IBaseWindow baseWin, string xref) { if (baseWin == null) { throw new ArgumentNullException("baseWin"); } try { lock (fLock) { using (WritableDatabase database = new WritableDatabase(GetXDBFolder(), Xapian.Xapian.DB_CREATE_OR_OPEN)) { uint docid = FindDocId(baseWin, database, xref); if (docid != 0) { database.DeleteDocument(docid); SetDBLastChange(baseWin, database); } } } } catch (Exception ex) { Logger.LogWrite("SearchManager.DeleteRecord(): " + ex.Message); } }
public void AddData(Template template) { ContentValues c = new ContentValues(); c.Put(KEY_NAME, template.Name); c.Put(KEY_VALUE, template.Value); WritableDatabase.InsertOrThrow(TABLE_NAME, null, c); }
public void Savemarker(double lat, double lng) { ContentValues values = new ContentValues(); values.Put(MapMarkerContract.MarkerTable.COLUMN_NAME_LAT, lat); values.Put(MapMarkerContract.MarkerTable.COLUMN_NAME_LONG, lng); WritableDatabase.Insert(MapMarkerContract.MarkerTable.TABLE_NAME, null, values); }
/// <summary> /// Remove the flavor from the database. /// </summary> /// <param name="flavor"></param> public void RemoveFlavor(Flavor flavor) { string cmd = $"DELETE FROM {FLAVOR_TABLE_NAME} WHERE {FLAVOR_ID_COL}={flavor.ID};"; try { WritableDatabase.ExecSQL(cmd); } catch (SQLiteAbortException e) { Console.WriteLine(e.Message); } }
/// <summary> /// Remove a nicotine from the database. /// </summary> /// <param name="nicotine">The nicotine to remove.</param> public void RemoveNicotine(Nicotine nicotine) { string cmd = $"DELETE FROM {NIC_TABLE_NAME} WHERE {NIC_ID_COL}={nicotine.ID};"; try { WritableDatabase.ExecSQL(cmd); } catch (SQLiteAbortException e) { Console.WriteLine(e.Message); } }
/// <summary> /// Update a recipe item in its table. /// </summary> /// <param name="recipeItem">The recipe item to update.</param> public void UpdateRecipeItem(RecipeItem recipeItem) { string cmd = $"UPDATE {RI_TABLE_NAME} SET {RI_FLAVOR_COL}={recipeItem.Flavor.ID}, {RI_PERCENTAGE_COL}={recipeItem.Percentage} " + $"WHERE {RI_ID_COL}={recipeItem.ID};"; try { WritableDatabase.ExecSQL(cmd); } catch (SQLiteAbortException e) { Console.WriteLine(e.Message); } }
public Bitmap ReturnDrawableBase(long id, string path) { string[] col = { "ColumnBitmap" }; string[] param = { path }; cursor = WritableDatabase.Query("ContentTable", col, "ColumnPath = ?", param, null, null, null); cursor.MoveToFirst(); byte[] array = cursor.GetBlob(cursor.GetColumnIndex(COLUMN_BITMAP)); Bitmap b = Multitools.ConvertToBitmap(array); return(b); }
/// <summary> /// Update a nicotine in the database. /// </summary> /// <param name="nicotine">The nicotine to update.</param> public void UpdateNicotine(Nicotine nicotine) { string cmd = $"UPDATE {NIC_TABLE_NAME} SET {NIC_NAME_COL}=\"{nicotine.Name}\", {NIC_VG_COL}={nicotine.VG}, " + $" {NIC_CONC_COL}={nicotine.Concentration} WHERE {NIC_ID_COL}={nicotine.ID};"; try { WritableDatabase.ExecSQL(cmd); } catch (SQLiteAbortException e) { Console.WriteLine(e.Message); } }
/// <summary> /// Remove a recipe item from the database. /// </summary> /// <param name="recipeItem">The recipe item to remove.</param> public void RemoveRecipeItem(RecipeItem recipeItem) { string cmd = $"DELETE FROM {RI_TABLE_NAME} WHERE {RI_ID_COL}={recipeItem.ID};"; string joinCmd = $"DELETE FROM {RECIPE_RI_TABLE_NAME} WHERE {RECIPE_RI_RI_ID}={recipeItem.ID};"; try { WritableDatabase.ExecSQL(cmd); WritableDatabase.ExecSQL(joinCmd); } catch (SQLiteAbortException e) { Console.WriteLine(e.Message); } }
/// <summary> /// Update an existing flavor in the database. /// </summary> /// <param name="flavor">The flavor to be updated.</param> public void UpdateFlavor(Flavor flavor) { int pg = flavor.PG ? 1 : 0; string cmd = $"UPDATE {FLAVOR_TABLE_NAME} SET {FLAVOR_NAME_COL}=\"{flavor.Name}\", {FLAVOR_PG_COL}={pg}, " + $"{FLAVOR_RECPER_COL}={flavor.RecommendedPercentage} WHERE {FLAVOR_ID_COL} = {flavor.ID};"; try { WritableDatabase.ExecSQL(cmd); } catch (SQLiteAbortException e) { Console.WriteLine(e.Message); } }
public void SaveBitmapBase(long id, string path, int start, int end, Bitmap image) //SAVE IMAGE IN DB { byte[] bytearray = Multitools.ConvertoBLob(image); ContentValues cv = new ContentValues(); cv.Put(COLUMN_ID, id); cv.Put(COLUMN_IMGPATH, path); cv.Put(COLUMN_START, start); cv.Put(COLUMN_END, end); cv.Put(COLUMN_BITMAP, bytearray); WritableDatabase.Insert(CONTENTTABLE, null, cv); }
/// <summary> /// Add a new nicotine to the nicotine table. /// </summary> /// <param name="nicotine">The nicotine to add.</param> public void PutNicotine(Nicotine nicotine) { string cmd = $"INSERT INTO {NIC_TABLE_NAME} ({NIC_NAME_COL}, {NIC_VG_COL}, {NIC_CONC_COL}) " + $"VALUES (\"{nicotine.Name}\", {nicotine.VG}, {nicotine.Concentration});"; try { WritableDatabase.ExecSQL(cmd); nicotine.ID = GetLastInsertedID(); } catch (SQLiteAbortException e) { Console.WriteLine(e.Message); } }
/// <summary> /// Add a new flavor to the flavor table. /// </summary> /// <param name="flavor">The flavor being added.</param> public void PutFlavor(Flavor flavor) { int pg = flavor.PG ? 1 : 0; string cmd = $"INSERT INTO {FLAVOR_TABLE_NAME} ({FLAVOR_NAME_COL}, {FLAVOR_PG_COL}, {FLAVOR_RECPER_COL}) " + $"VALUES (\"{flavor.Name}\", {pg}, {flavor.RecommendedPercentage});"; try { WritableDatabase.ExecSQL(cmd); flavor.ID = GetLastInsertedID(); } catch (SQLiteAbortException e) { Console.WriteLine(e.Message); } }
public void cadastrar(Prato prat) { ContentValues values = new ContentValues(); values.Put("nome", prat.Nome); values.Put("valor", prat.Valor); WritableDatabase.Insert(TABELA, null, values); Log.Info(TAG, "Prato cadastradado: " + prat.Nome); }
/// <summary> /// Add the recipe item to its table. /// </summary> /// <param name="recipeItem">The recipe item to add.</param> public void PutRecipeItem(RecipeItem recipeItem, Recipe owner) { string cmd = $"INSERT INTO {RI_TABLE_NAME} ({RI_FLAVOR_COL}, {RI_PERCENTAGE_COL}) " + $"VALUES ({recipeItem.Flavor.ID}, {recipeItem.Percentage});"; string joinCmd = $"INSERT INTO {RECIPE_RI_TABLE_NAME} ({RECIPE_RI_RECIPE_ID}, " + $" {RECIPE_RI_RI_ID}) VALUES ({owner.ID}, {recipeItem.ID});"; try { WritableDatabase.ExecSQL(cmd); recipeItem.ID = GetLastInsertedID(); WritableDatabase.ExecSQL(cmd); } catch (SQLiteAbortException e) { Console.WriteLine(e.Message); } }
private static uint FindDocId(IBaseWindow baseWin, WritableDatabase database, string xref) { uint result; string key = "Q" + GetSign(baseWin) + "_" + xref; using (PostingIterator p = database.PostListBegin(key)) { if (p == database.PostListEnd(key)) { result = 0; // 0 - is invalid docid (see XapianManual) } else { result = p.GetDocId(); } } return(result); }
public void EmptyDb(string appId) { // query to obtain the names of all tables in your database ICursor c = WritableDatabase.RawQuery("SELECT name FROM sqlite_master WHERE type='table'", null); List <String> tables = new List <string>(); // iterate over the result set, adding every table name to a list while (c.MoveToNext()) { tables.Add(c.GetString(0)); } // call DROP TABLE on every table name foreach (String table in tables) { String dropQuery = "DELETE FROM " + table; WritableDatabase.ExecSQL(dropQuery); } }
public void ReindexBase(IBaseWindow baseWin) { if (baseWin == null) { return; } try { lock (fLock) { using (WritableDatabase database = new WritableDatabase(GetXDBFolder(), Xapian.Xapian.DB_CREATE_OR_OPEN)) using (TermGenerator indexer = new TermGenerator()) using (Stem stemmer = new Stem("russian")) { indexer.SetStemmer(stemmer); IProgressController progress = AppHost.Progress; progress.ProgressInit(fPlugin.LangMan.LS(TLS.LSID_SearchIndexRefreshing), baseWin.Context.Tree.RecordsCount); int num = baseWin.Context.Tree.RecordsCount; for (int i = 0; i < num; i++) { GDMRecord record = baseWin.Context.Tree[i]; if (IsIndexedRecord(record)) { ReindexRecord(baseWin, database, indexer, record); } progress.ProgressStep(); } progress.ProgressDone(); SetDBLastChange(baseWin, database); } } } catch (Exception ex) { Logger.LogWrite("SearchManager.ReindexBase(): " + ex.Message); } }
private static void ReindexRecord(IBaseWindow baseWin, WritableDatabase database, TermGenerator indexer, GDMRecord record) { uint docid = FindDocId(baseWin, database, record.XRef); if (docid != 0) { // checking for needed updates string recLastchange = record.ChangeDate.ToString(); string docLastchange; using (Document curDoc = database.GetDocument(docid)) { docLastchange = curDoc.GetValue(0); } // updating a record if (!string.Equals(recLastchange, docLastchange)) { using (Document doc = new Document()) { if (SetDocumentContext(baseWin, doc, indexer, record)) { database.ReplaceDocument(docid, doc); } } } } else { // only adding using (Document doc = new Document()) { if (SetDocumentContext(baseWin, doc, indexer, record)) { database.AddDocument(doc); } } } }
public void DeleteId(string tablename, string id) { WritableDatabase.Delete(tablename, $"id={id}", null); }
private static void SetDBLastChange(IBaseWindow baseWin, WritableDatabase database) { string dbLastchange = baseWin.Context.Tree.Header.TransmissionDateTime.ToString("yyyy.MM.dd HH:mm:ss", null); database.SetMetadata(GetSign(baseWin), dbLastchange); }
public void RemoveData(string name) { WritableDatabase.Delete(TABLE_NAME, KEY_NAME + " == ?", new string[] { name }); }
public void deletar(Prato prat) { String[] args = { prat.ID.ToString() }; WritableDatabase.Delete(TABELA, "id=?", args); }
public long SaveText(IEditable Text, Bundle args) { long NoteNumber = 0; string date = DateTime.Now.ToString("dd MMM yyyyг. HH:mm"); ContentValues cv = new ContentValues(); SpannableFactory a = new SpannableFactory(); ISpannable saveText = a.NewSpannable(Text); Java.Lang.Object[] span = saveText.GetSpans(0, saveText.Length(), Java.Lang.Class.FromType(typeof(ImageSpan))); if (span != null) { for (int i = 0; i < span.Length; i++) { saveText.RemoveSpan(span[i]); } } if (Build.VERSION.SdkInt >= BuildVersionCodes.N) { cv.Put(COLUMN_TEXT, Html.ToHtml(saveText, ToHtmlOptions.ParagraphLinesIndividual)); } else { cv.Put(COLUMN_TEXT, Html.ToHtml(saveText)); } cv.Put(COLUMN_EDITINGTIME, date); if (args != null) { WritableDatabase.Update(TEXTTABLE, cv, "_id == ?", new string[] { args.GetString(Databasehelper.COLUMN_ID) }); WritableDatabase.ExecSQL("DELETE from " + CONTENTTABLE + " Where _id == " + args.GetString(Databasehelper.COLUMN_ID)); //Delete old image NoteNumber = Convert.ToInt32(args.GetString(COLUMN_ID)); } else { long id = 1; cursor = WritableDatabase.RawQuery("Select _id from " + Databasehelper.TEXTTABLE + " ORDER BY _id DESC LIMIT 1", null); if (cursor.MoveToFirst()) { id = cursor.GetLong(cursor.GetColumnIndex("_id")); cursor.Close(); id++; } cv.Put(COLUMN_ID, id); WritableDatabase.Insert(TEXTTABLE, null, cv); NoteNumber = id; } Java.Lang.Object[] spans = Text.GetSpans(0, Text.Length(), Java.Lang.Class.FromType(typeof(ImageSpan))); //Insert Image in Database if (spans != null) { for (int i = 0; i < spans.Length; i++) { int start = Text.GetSpanStart(spans[i]); int end = Text.GetSpanEnd(spans[i]); string source; source = Text.ToString().Substring(start + 1, end - start - 2); SaveBitmapBase(NoteNumber, source, start, end, ((BitmapDrawable)((ImageSpan)spans[i]).Drawable).Bitmap); } } return(NoteNumber); }
public void DropTable(string tableName) { string sql = "drop table if exists " + tableName; WritableDatabase.ExecSQL(sql); }