|
|
|
@ -47,40 +47,40 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
/* 以下都是一些SQL语句,辅助我们来对数据库进行操作 */
|
|
|
|
|
//创建note表的语句,这里的NoteColumns就是我们刚刚在Notes中定义的一个接口,里面定义了一系列静态的数据库表中的列名
|
|
|
|
|
private static final String CREATE_NOTE_TABLE_SQL =
|
|
|
|
|
"CREATE TABLE " + TABLE.NOTE + "(" +
|
|
|
|
|
NoteColumns.ID + " INTEGER PRIMARY KEY," +
|
|
|
|
|
NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
|
|
|
|
NoteColumns.HAS_ATTACHMENT + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
|
|
|
|
NoteColumns.NOTES_COUNT + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.SNIPPET + " TEXT NOT NULL DEFAULT ''," +
|
|
|
|
|
NoteColumns.TYPE + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.WIDGET_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," +
|
|
|
|
|
NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +
|
|
|
|
|
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
|
|
|
|
|
")";
|
|
|
|
|
"CREATE TABLE " + TABLE.NOTE + "(" +
|
|
|
|
|
NoteColumns.ID + " INTEGER PRIMARY KEY," +
|
|
|
|
|
NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.BG_COLOR_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
|
|
|
|
NoteColumns.HAS_ATTACHMENT + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
|
|
|
|
NoteColumns.NOTES_COUNT + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.SNIPPET + " TEXT NOT NULL DEFAULT ''," +
|
|
|
|
|
NoteColumns.TYPE + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.WIDGET_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.WIDGET_TYPE + " INTEGER NOT NULL DEFAULT -1," +
|
|
|
|
|
NoteColumns.SYNC_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.LOCAL_MODIFIED + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +
|
|
|
|
|
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
|
|
|
|
|
")";
|
|
|
|
|
//同上,创建data表的语句,这里的DataColumns就是我们刚刚在Notes中定义的一个接口,里面定义了一系列静态的数据库表中的列名
|
|
|
|
|
private static final String CREATE_DATA_TABLE_SQL =
|
|
|
|
|
"CREATE TABLE " + TABLE.DATA + "(" +
|
|
|
|
|
DataColumns.ID + " INTEGER PRIMARY KEY," +
|
|
|
|
|
DataColumns.MIME_TYPE + " TEXT NOT NULL," +
|
|
|
|
|
DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
|
|
|
|
NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
|
|
|
|
DataColumns.CONTENT + " TEXT NOT NULL DEFAULT ''," +
|
|
|
|
|
DataColumns.DATA1 + " INTEGER," +
|
|
|
|
|
DataColumns.DATA2 + " INTEGER," +
|
|
|
|
|
DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +
|
|
|
|
|
DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +
|
|
|
|
|
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
|
|
|
|
|
")";
|
|
|
|
|
"CREATE TABLE " + TABLE.DATA + "(" +
|
|
|
|
|
DataColumns.ID + " INTEGER PRIMARY KEY," +
|
|
|
|
|
DataColumns.MIME_TYPE + " TEXT NOT NULL," +
|
|
|
|
|
DataColumns.NOTE_ID + " INTEGER NOT NULL DEFAULT 0," +
|
|
|
|
|
NoteColumns.CREATED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
|
|
|
|
NoteColumns.MODIFIED_DATE + " INTEGER NOT NULL DEFAULT (strftime('%s','now') * 1000)," +
|
|
|
|
|
DataColumns.CONTENT + " TEXT NOT NULL DEFAULT ''," +
|
|
|
|
|
DataColumns.DATA1 + " INTEGER," +
|
|
|
|
|
DataColumns.DATA2 + " INTEGER," +
|
|
|
|
|
DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +
|
|
|
|
|
DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +
|
|
|
|
|
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
|
|
|
|
|
")";
|
|
|
|
|
// 功能简介:
|
|
|
|
|
// 创建一个以note的ID为索引
|
|
|
|
|
// 解读:
|
|
|
|
@ -89,8 +89,8 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
// 索引通常用于提高查询性能,特别是在对某个字段进行频繁查询时。
|
|
|
|
|
|
|
|
|
|
private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
|
|
|
|
|
"CREATE INDEX IF NOT EXISTS note_id_index ON " +
|
|
|
|
|
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
|
|
|
|
|
"CREATE INDEX IF NOT EXISTS note_id_index ON " +
|
|
|
|
|
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 以下是一些对便签增删改定义的触发器 */
|
|
|
|
@ -110,13 +110,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
// 触发器的逻辑是:当某个笔记的PARENT_ID(即父文件夹ID)被更新时,它会找到对应的文件夹(通过新的PARENT_ID),并将该文件夹的NOTES_COUNT(即笔记数)增加1。
|
|
|
|
|
|
|
|
|
|
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
|
|
|
|
|
"CREATE TRIGGER increase_folder_count_on_update "+
|
|
|
|
|
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN " +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
"CREATE TRIGGER increase_folder_count_on_update "+
|
|
|
|
|
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN " +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decrease folder's note count when move note from folder
|
|
|
|
@ -125,14 +125,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
// 添加触发器:减少文件夹的便签个数记录(因为我们会移动便签移出文件夹,这时候文件夹的计数要进行更新)
|
|
|
|
|
|
|
|
|
|
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
|
|
|
|
|
"CREATE TRIGGER decrease_folder_count_on_update " +
|
|
|
|
|
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN " +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
|
|
|
|
|
" AND " + NoteColumns.NOTES_COUNT + ">0" + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
"CREATE TRIGGER decrease_folder_count_on_update " +
|
|
|
|
|
" AFTER UPDATE OF " + NoteColumns.PARENT_ID + " ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN " +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
|
|
|
|
|
" AND " + NoteColumns.NOTES_COUNT + ">0" + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Increase folder's note count when insert new note to the folder
|
|
|
|
@ -140,13 +140,13 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
// 功能简介:(触发器原理和上面的 “增加文件夹的便签个数记录” 同理,就不细节解读了)
|
|
|
|
|
// 添加触发器:当我们在文件夹插入便签时,增加文件夹的便签个数记录
|
|
|
|
|
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
|
|
|
|
|
"CREATE TRIGGER increase_folder_count_on_insert " +
|
|
|
|
|
" AFTER INSERT ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN " +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
"CREATE TRIGGER increase_folder_count_on_insert " +
|
|
|
|
|
" AFTER INSERT ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN " +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + " + 1" +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=new." + NoteColumns.PARENT_ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Decrease folder's note count when delete note from the folder
|
|
|
|
@ -154,14 +154,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
// 功能简介:(触发器原理和上面的 “增加文件夹的便签个数记录” 同理,就不细节解读了)
|
|
|
|
|
// 添加触发器:当我们在文件夹删除便签时,减少文件夹的便签个数记录
|
|
|
|
|
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
|
|
|
|
|
"CREATE TRIGGER decrease_folder_count_on_delete " +
|
|
|
|
|
" AFTER DELETE ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN " +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
|
|
|
|
|
" AND " + NoteColumns.NOTES_COUNT + ">0;" +
|
|
|
|
|
" END";
|
|
|
|
|
"CREATE TRIGGER decrease_folder_count_on_delete " +
|
|
|
|
|
" AFTER DELETE ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN " +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.NOTES_COUNT + "=" + NoteColumns.NOTES_COUNT + "-1" +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=old." + NoteColumns.PARENT_ID +
|
|
|
|
|
" AND " + NoteColumns.NOTES_COUNT + ">0;" +
|
|
|
|
|
" END";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update note's content when insert data with type {@link DataConstants#NOTE}
|
|
|
|
@ -173,14 +173,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
// 它会更新NOTE表,将与新插入数据相关联的标签的SNIPPET(摘要)字段设置为新插入数据的CONTENT字段的值
|
|
|
|
|
|
|
|
|
|
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
|
|
|
|
|
"CREATE TRIGGER update_note_content_on_insert " +
|
|
|
|
|
" AFTER INSERT ON " + TABLE.DATA +
|
|
|
|
|
" WHEN new." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
"CREATE TRIGGER update_note_content_on_insert " +
|
|
|
|
|
" AFTER INSERT ON " + TABLE.DATA +
|
|
|
|
|
" WHEN new." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update note's content when data with {@link DataConstants#NOTE} type has changed
|
|
|
|
@ -192,14 +192,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
// 它会更新NOTE表,将与更新后的数据相关联的笔记的SNIPPET字段设置为新数据的CONTENT字段的值
|
|
|
|
|
|
|
|
|
|
private static final String DATA_UPDATE_NOTE_CONTENT_ON_UPDATE_TRIGGER =
|
|
|
|
|
"CREATE TRIGGER update_note_content_on_update " +
|
|
|
|
|
" AFTER UPDATE ON " + TABLE.DATA +
|
|
|
|
|
" WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
"CREATE TRIGGER update_note_content_on_update " +
|
|
|
|
|
" AFTER UPDATE ON " + TABLE.DATA +
|
|
|
|
|
" WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.SNIPPET + "=new." + DataColumns.CONTENT +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=new." + DataColumns.NOTE_ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update note's content when data with {@link DataConstants#NOTE} type has deleted
|
|
|
|
@ -211,14 +211,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
// 它会更新NOTE表,将与删除的数据相关联的笔记的SNIPPET字段设置为空字符串。
|
|
|
|
|
|
|
|
|
|
private static final String DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER =
|
|
|
|
|
"CREATE TRIGGER update_note_content_on_delete " +
|
|
|
|
|
" AFTER delete ON " + TABLE.DATA +
|
|
|
|
|
" WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.SNIPPET + "=''" +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
"CREATE TRIGGER update_note_content_on_delete " +
|
|
|
|
|
" AFTER delete ON " + TABLE.DATA +
|
|
|
|
|
" WHEN old." + DataColumns.MIME_TYPE + "='" + DataConstants.NOTE + "'" +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.SNIPPET + "=''" +
|
|
|
|
|
" WHERE " + NoteColumns.ID + "=old." + DataColumns.NOTE_ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete datas belong to note which has been deleted
|
|
|
|
@ -230,12 +230,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
// 它会从DATA表中删除所有与已删除的笔记(由old.ID表示)相关联的数据行(通过比较DATA表中的NOTE_ID字段与已删除笔记的ID来实现)
|
|
|
|
|
|
|
|
|
|
private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
|
|
|
|
|
"CREATE TRIGGER delete_data_on_delete " +
|
|
|
|
|
" AFTER DELETE ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" DELETE FROM " + TABLE.DATA +
|
|
|
|
|
" WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
"CREATE TRIGGER delete_data_on_delete " +
|
|
|
|
|
" AFTER DELETE ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" DELETE FROM " + TABLE.DATA +
|
|
|
|
|
" WHERE " + DataColumns.NOTE_ID + "=old." + NoteColumns.ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete notes belong to folder which has been deleted
|
|
|
|
@ -247,12 +247,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
// 触发器会删除所有以该文件夹为父级(PARENT_ID)的笔记(通过比较NOTE表中的PARENT_ID字段与已删除文件夹的ID来实现)
|
|
|
|
|
|
|
|
|
|
private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
|
|
|
|
|
"CREATE TRIGGER folder_delete_notes_on_delete " +
|
|
|
|
|
" AFTER DELETE ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" DELETE FROM " + TABLE.NOTE +
|
|
|
|
|
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
"CREATE TRIGGER folder_delete_notes_on_delete " +
|
|
|
|
|
" AFTER DELETE ON " + TABLE.NOTE +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" DELETE FROM " + TABLE.NOTE +
|
|
|
|
|
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Move notes belong to folder which has been moved to trash folder
|
|
|
|
@ -264,14 +264,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
|
|
|
|
|
// 触发器会更新所有以该文件夹为父级(PARENT_ID)的笔记,将它们也移动到回收站。
|
|
|
|
|
|
|
|
|
|
private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER =
|
|
|
|
|
"CREATE TRIGGER folder_move_notes_on_trash " +
|
|
|
|
|
" AFTER UPDATE ON " + TABLE.NOTE +
|
|
|
|
|
" WHEN new." + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER +
|
|
|
|
|
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
"CREATE TRIGGER folder_move_notes_on_trash " +
|
|
|
|
|
" AFTER UPDATE ON " + TABLE.NOTE +
|
|
|
|
|
" WHEN new." + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER +
|
|
|
|
|
" BEGIN" +
|
|
|
|
|
" UPDATE " + TABLE.NOTE +
|
|
|
|
|
" SET " + NoteColumns.PARENT_ID + "=" + Notes.ID_TRASH_FOLER +
|
|
|
|
|
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
|
|
|
|
|
" END";
|
|
|
|
|
// 构造器
|
|
|
|
|
public NotesDatabaseHelper(Context context) {
|
|
|
|
|
super(context, DB_NAME, null, DB_VERSION);
|