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 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); }