|
|
|
|
@ -35,35 +35,65 @@ import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 小米便签内容提供者
|
|
|
|
|
* 实现了ContentProvider接口,提供便签数据的增删改查功能
|
|
|
|
|
* 支持便签和文件夹的管理,以及搜索和搜索建议功能
|
|
|
|
|
*/
|
|
|
|
|
public class NotesProvider extends ContentProvider {
|
|
|
|
|
/**
|
|
|
|
|
* URI匹配器,用于将请求的URI映射到对应的处理逻辑
|
|
|
|
|
*/
|
|
|
|
|
private static final UriMatcher mMatcher;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据库帮助类实例,用于获取数据库连接
|
|
|
|
|
*/
|
|
|
|
|
private NotesDatabaseHelper mHelper;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 日志标签,用于在日志系统中标识本类的日志信息
|
|
|
|
|
*/
|
|
|
|
|
private static final String TAG = "NotesProvider";
|
|
|
|
|
|
|
|
|
|
private static final int URI_NOTE = 1;
|
|
|
|
|
private static final int URI_NOTE_ITEM = 2;
|
|
|
|
|
private static final int URI_DATA = 3;
|
|
|
|
|
private static final int URI_DATA_ITEM = 4;
|
|
|
|
|
|
|
|
|
|
private static final int URI_SEARCH = 5;
|
|
|
|
|
private static final int URI_SEARCH_SUGGEST = 6;
|
|
|
|
|
/**
|
|
|
|
|
* URI类型常量,用于标识不同的请求类型
|
|
|
|
|
* - URI_NOTE:查询所有便签和文件夹
|
|
|
|
|
* - URI_NOTE_ITEM:查询单个便签或文件夹
|
|
|
|
|
* - URI_DATA:查询所有便签数据
|
|
|
|
|
* - URI_DATA_ITEM:查询单个便签数据
|
|
|
|
|
* - URI_SEARCH:搜索便签
|
|
|
|
|
* - URI_SEARCH_SUGGEST:搜索建议
|
|
|
|
|
*/
|
|
|
|
|
private static final int URI_NOTE = 1; // 所有便签和文件夹
|
|
|
|
|
private static final int URI_NOTE_ITEM = 2; // 单个便签或文件夹
|
|
|
|
|
private static final int URI_DATA = 3; // 所有便签数据
|
|
|
|
|
private static final int URI_DATA_ITEM = 4; // 单个便签数据
|
|
|
|
|
private static final int URI_SEARCH = 5; // 搜索便签
|
|
|
|
|
private static final int URI_SEARCH_SUGGEST = 6; // 搜索建议
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
// 初始化URI匹配器,设置各种URI模式对应的处理类型
|
|
|
|
|
mMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST);
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note", URI_NOTE); // 匹配所有便签和文件夹
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "note/#", URI_NOTE_ITEM); // 匹配单个便签或文件夹
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "data", URI_DATA); // 匹配所有便签数据
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "data/#", URI_DATA_ITEM); // 匹配单个便签数据
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, "search", URI_SEARCH); // 匹配搜索请求
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, URI_SEARCH_SUGGEST); // 匹配搜索建议
|
|
|
|
|
mMatcher.addURI(Notes.AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", URI_SEARCH_SUGGEST); // 匹配带参数的搜索建议
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* x'0A' represents the '\n' character in sqlite. For title and content in the search result,
|
|
|
|
|
* we will trim '\n' and white space in order to show more information.
|
|
|
|
|
* 搜索结果的投影列定义
|
|
|
|
|
* x'0A'代表SQLite中的'\n'字符。在搜索结果中,我们会去除'\n'和空白字符以显示更多信息
|
|
|
|
|
* 定义了搜索建议需要的列:
|
|
|
|
|
* - ID:便签ID
|
|
|
|
|
* - SUGGEST_COLUMN_INTENT_EXTRA_DATA:用于传递便签ID
|
|
|
|
|
* - SUGGEST_COLUMN_TEXT_1和TEXT_2:搜索建议显示的文本
|
|
|
|
|
* - SUGGEST_COLUMN_ICON_1:搜索建议显示的图标
|
|
|
|
|
* - SUGGEST_COLUMN_INTENT_ACTION:点击搜索建议时的动作
|
|
|
|
|
* - SUGGEST_COLUMN_INTENT_DATA:点击搜索建议时的数据类型
|
|
|
|
|
*/
|
|
|
|
|
private static final String NOTES_SEARCH_PROJECTION = NoteColumns.ID + ","
|
|
|
|
|
+ NoteColumns.ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA + ","
|
|
|
|
|
@ -73,65 +103,94 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
+ "'" + Intent.ACTION_VIEW + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_ACTION + ","
|
|
|
|
|
+ "'" + Notes.TextNote.CONTENT_TYPE + "' AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 便签搜索查询语句
|
|
|
|
|
* 用于根据关键词搜索便签,只搜索未删除的普通便签
|
|
|
|
|
*/
|
|
|
|
|
private static String NOTES_SNIPPET_SEARCH_QUERY = "SELECT " + NOTES_SEARCH_PROJECTION
|
|
|
|
|
+ " FROM " + TABLE.NOTE
|
|
|
|
|
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?"
|
|
|
|
|
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
|
|
|
|
|
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
|
|
|
|
|
+ " WHERE " + NoteColumns.SNIPPET + " LIKE ?" // 模糊匹配关键词
|
|
|
|
|
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER // 排除回收站中的便签
|
|
|
|
|
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE; // 只搜索普通便签
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 内容提供者创建时调用,初始化数据库帮助类实例
|
|
|
|
|
* @return 初始化是否成功,始终返回true
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onCreate() {
|
|
|
|
|
// 获取数据库帮助类的单例实例
|
|
|
|
|
mHelper = NotesDatabaseHelper.getInstance(getContext());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询便签数据
|
|
|
|
|
* @param uri 请求的URI
|
|
|
|
|
* @param projection 返回的列
|
|
|
|
|
* @param selection 查询条件
|
|
|
|
|
* @param selectionArgs 查询条件参数
|
|
|
|
|
* @param sortOrder 排序方式
|
|
|
|
|
* @return 查询结果游标
|
|
|
|
|
* @throws IllegalArgumentException 当请求的URI无效或参数不符合要求时抛出
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
|
|
|
|
String sortOrder) {
|
|
|
|
|
Cursor c = null;
|
|
|
|
|
// 获取只读数据库连接
|
|
|
|
|
SQLiteDatabase db = mHelper.getReadableDatabase();
|
|
|
|
|
String id = null;
|
|
|
|
|
|
|
|
|
|
// 根据URI类型执行不同的查询逻辑
|
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
|
case URI_NOTE:
|
|
|
|
|
case URI_NOTE: // 查询所有便签和文件夹
|
|
|
|
|
c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null,
|
|
|
|
|
sortOrder);
|
|
|
|
|
break;
|
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
case URI_NOTE_ITEM: // 查询单个便签或文件夹
|
|
|
|
|
id = uri.getPathSegments().get(1); // 从URI中获取ID
|
|
|
|
|
c = db.query(TABLE.NOTE, projection, NoteColumns.ID + "=" + id
|
|
|
|
|
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA:
|
|
|
|
|
case URI_DATA: // 查询所有便签数据
|
|
|
|
|
c = db.query(TABLE.DATA, projection, selection, selectionArgs, null, null,
|
|
|
|
|
sortOrder);
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
case URI_DATA_ITEM: // 查询单个便签数据
|
|
|
|
|
id = uri.getPathSegments().get(1); // 从URI中获取ID
|
|
|
|
|
c = db.query(TABLE.DATA, projection, DataColumns.ID + "=" + id
|
|
|
|
|
+ parseSelection(selection), selectionArgs, null, null, sortOrder);
|
|
|
|
|
break;
|
|
|
|
|
case URI_SEARCH:
|
|
|
|
|
case URI_SEARCH_SUGGEST:
|
|
|
|
|
case URI_SEARCH: // 搜索便签
|
|
|
|
|
case URI_SEARCH_SUGGEST: // 搜索建议
|
|
|
|
|
// 搜索请求不允许指定排序方式和投影列
|
|
|
|
|
if (sortOrder != null || projection != null) {
|
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
|
"do not specify sortOrder, selection, selectionArgs, or projection" + "with this query");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取搜索关键词
|
|
|
|
|
String searchString = null;
|
|
|
|
|
if (mMatcher.match(uri) == URI_SEARCH_SUGGEST) {
|
|
|
|
|
// 从URI路径中获取搜索关键词
|
|
|
|
|
if (uri.getPathSegments().size() > 1) {
|
|
|
|
|
searchString = uri.getPathSegments().get(1);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 从URI查询参数中获取搜索关键词
|
|
|
|
|
searchString = uri.getQueryParameter("pattern");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果搜索关键词为空,返回null
|
|
|
|
|
if (TextUtils.isEmpty(searchString)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 构建模糊查询字符串
|
|
|
|
|
searchString = String.format("%%%s%%", searchString);
|
|
|
|
|
// 执行搜索查询
|
|
|
|
|
c = db.rawQuery(NOTES_SNIPPET_SEARCH_QUERY,
|
|
|
|
|
new String[] { searchString });
|
|
|
|
|
} catch (IllegalStateException ex) {
|
|
|
|
|
@ -141,21 +200,33 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
default:
|
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置内容变更通知URI,当数据发生变化时通知观察者
|
|
|
|
|
if (c != null) {
|
|
|
|
|
c.setNotificationUri(getContext().getContentResolver(), uri);
|
|
|
|
|
}
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 插入便签数据
|
|
|
|
|
* @param uri 请求的URI
|
|
|
|
|
* @param values 要插入的数据
|
|
|
|
|
* @return 插入数据的URI,包含新插入数据的ID
|
|
|
|
|
* @throws IllegalArgumentException 当请求的URI无效时抛出
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Uri insert(Uri uri, ContentValues values) {
|
|
|
|
|
// 获取可写数据库连接
|
|
|
|
|
SQLiteDatabase db = mHelper.getWritableDatabase();
|
|
|
|
|
long dataId = 0, noteId = 0, insertedId = 0;
|
|
|
|
|
|
|
|
|
|
// 根据URI类型执行不同的插入逻辑
|
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
|
case URI_NOTE:
|
|
|
|
|
case URI_NOTE: // 插入便签或文件夹
|
|
|
|
|
insertedId = noteId = db.insert(TABLE.NOTE, null, values);
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA:
|
|
|
|
|
case URI_DATA: // 插入便签数据
|
|
|
|
|
if (values.containsKey(DataColumns.NOTE_ID)) {
|
|
|
|
|
noteId = values.getAsLong(DataColumns.NOTE_ID);
|
|
|
|
|
} else {
|
|
|
|
|
@ -166,37 +237,49 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
default:
|
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
|
}
|
|
|
|
|
// Notify the note uri
|
|
|
|
|
|
|
|
|
|
// 通知便签URI数据变更
|
|
|
|
|
if (noteId > 0) {
|
|
|
|
|
getContext().getContentResolver().notifyChange(
|
|
|
|
|
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Notify the data uri
|
|
|
|
|
// 通知数据URI数据变更
|
|
|
|
|
if (dataId > 0) {
|
|
|
|
|
getContext().getContentResolver().notifyChange(
|
|
|
|
|
ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 返回包含新插入数据ID的URI
|
|
|
|
|
return ContentUris.withAppendedId(uri, insertedId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除便签数据
|
|
|
|
|
* @param uri 请求的URI
|
|
|
|
|
* @param selection 删除条件
|
|
|
|
|
* @param selectionArgs 删除条件参数
|
|
|
|
|
* @return 删除的行数
|
|
|
|
|
* @throws IllegalArgumentException 当请求的URI无效时抛出
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
|
|
|
|
int count = 0;
|
|
|
|
|
String id = null;
|
|
|
|
|
// 获取可写数据库连接
|
|
|
|
|
SQLiteDatabase db = mHelper.getWritableDatabase();
|
|
|
|
|
boolean deleteData = false;
|
|
|
|
|
|
|
|
|
|
// 根据URI类型执行不同的删除逻辑
|
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
|
case URI_NOTE:
|
|
|
|
|
selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 ";
|
|
|
|
|
case URI_NOTE: // 删除便签或文件夹
|
|
|
|
|
selection = "(" + selection + ") AND " + NoteColumns.ID + ">0 "; // 排除系统文件夹
|
|
|
|
|
count = db.delete(TABLE.NOTE, selection, selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
|
case URI_NOTE_ITEM: // 删除单个便签或文件夹
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
/**
|
|
|
|
|
* ID that smaller than 0 is system folder which is not allowed to
|
|
|
|
|
* trash
|
|
|
|
|
* ID小于0的是系统文件夹,不允许删除
|
|
|
|
|
*/
|
|
|
|
|
long noteId = Long.valueOf(id);
|
|
|
|
|
if (noteId <= 0) {
|
|
|
|
|
@ -205,11 +288,11 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
count = db.delete(TABLE.NOTE,
|
|
|
|
|
NoteColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA:
|
|
|
|
|
case URI_DATA: // 删除便签数据
|
|
|
|
|
count = db.delete(TABLE.DATA, selection, selectionArgs);
|
|
|
|
|
deleteData = true;
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
|
case URI_DATA_ITEM: // 删除单个便签数据
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
count = db.delete(TABLE.DATA,
|
|
|
|
|
DataColumns.ID + "=" + id + parseSelection(selection), selectionArgs);
|
|
|
|
|
@ -218,6 +301,8 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
default:
|
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 通知数据变更
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
if (deleteData) {
|
|
|
|
|
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
|
|
|
|
|
@ -227,28 +312,40 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新便签数据
|
|
|
|
|
* @param uri 请求的URI
|
|
|
|
|
* @param values 要更新的数据
|
|
|
|
|
* @param selection 更新条件
|
|
|
|
|
* @param selectionArgs 更新条件参数
|
|
|
|
|
* @return 更新的行数
|
|
|
|
|
* @throws IllegalArgumentException 当请求的URI无效时抛出
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
|
|
|
|
int count = 0;
|
|
|
|
|
String id = null;
|
|
|
|
|
// 获取可写数据库连接
|
|
|
|
|
SQLiteDatabase db = mHelper.getWritableDatabase();
|
|
|
|
|
boolean updateData = false;
|
|
|
|
|
|
|
|
|
|
// 根据URI类型执行不同的更新逻辑
|
|
|
|
|
switch (mMatcher.match(uri)) {
|
|
|
|
|
case URI_NOTE:
|
|
|
|
|
increaseNoteVersion(-1, selection, selectionArgs);
|
|
|
|
|
case URI_NOTE: // 更新便签或文件夹
|
|
|
|
|
increaseNoteVersion(-1, selection, selectionArgs); // 增加便签版本号
|
|
|
|
|
count = db.update(TABLE.NOTE, values, selection, selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_NOTE_ITEM:
|
|
|
|
|
case URI_NOTE_ITEM: // 更新单个便签或文件夹
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
increaseNoteVersion(Long.valueOf(id), selection, selectionArgs);
|
|
|
|
|
increaseNoteVersion(Long.valueOf(id), selection, selectionArgs); // 增加便签版本号
|
|
|
|
|
count = db.update(TABLE.NOTE, values, NoteColumns.ID + "=" + id
|
|
|
|
|
+ parseSelection(selection), selectionArgs);
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA:
|
|
|
|
|
case URI_DATA: // 更新便签数据
|
|
|
|
|
count = db.update(TABLE.DATA, values, selection, selectionArgs);
|
|
|
|
|
updateData = true;
|
|
|
|
|
break;
|
|
|
|
|
case URI_DATA_ITEM:
|
|
|
|
|
case URI_DATA_ITEM: // 更新单个便签数据
|
|
|
|
|
id = uri.getPathSegments().get(1);
|
|
|
|
|
count = db.update(TABLE.DATA, values, DataColumns.ID + "=" + id
|
|
|
|
|
+ parseSelection(selection), selectionArgs);
|
|
|
|
|
@ -258,6 +355,7 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 通知数据变更
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
if (updateData) {
|
|
|
|
|
getContext().getContentResolver().notifyChange(Notes.CONTENT_NOTE_URI, null);
|
|
|
|
|
@ -267,17 +365,28 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 解析选择条件,将额外的条件添加到现有条件中
|
|
|
|
|
* @param selection 原选择条件
|
|
|
|
|
* @return 解析后的选择条件
|
|
|
|
|
*/
|
|
|
|
|
private String parseSelection(String selection) {
|
|
|
|
|
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 增加便签版本号
|
|
|
|
|
* @param id 便签ID,如果为-1则更新所有符合条件的便签
|
|
|
|
|
* @param selection 更新条件
|
|
|
|
|
* @param selectionArgs 更新条件参数
|
|
|
|
|
*/
|
|
|
|
|
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
|
|
|
|
|
StringBuilder sql = new StringBuilder(120);
|
|
|
|
|
sql.append("UPDATE ");
|
|
|
|
|
sql.append(TABLE.NOTE);
|
|
|
|
|
sql.append(" SET ");
|
|
|
|
|
sql.append(NoteColumns.VERSION);
|
|
|
|
|
sql.append("=" + NoteColumns.VERSION + "+1 ");
|
|
|
|
|
sql.append("=" + NoteColumns.VERSION + "+1 "); // 版本号自增1
|
|
|
|
|
|
|
|
|
|
if (id > 0 || !TextUtils.isEmpty(selection)) {
|
|
|
|
|
sql.append(" WHERE ");
|
|
|
|
|
@ -293,9 +402,15 @@ public class NotesProvider extends ContentProvider {
|
|
|
|
|
sql.append(selectString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 执行SQL语句
|
|
|
|
|
mHelper.getWritableDatabase().execSQL(sql.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取URI对应的MIME类型
|
|
|
|
|
* @param uri 请求的URI
|
|
|
|
|
* @return MIME类型,目前未实现,返回null
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public String getType(Uri uri) {
|
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|