!52 fix add note bug

Merge pull request !52 from zhanghongchuan33/master
This commit is contained in:
openharmony_ci 2022-05-23 09:11:17 +00:00 committed by Gitee
commit fb89ca7014
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 26 additions and 27 deletions

View File

@ -30,7 +30,6 @@ const FileMaxSize: number = 20 * 1024 * 1024
/** /**
* db instance * db instance
*/ */
var rdbStore = undefined
export default { export default {
/** /**
@ -40,27 +39,27 @@ export default {
ohosDataRdb.getRdbStore(context, SysDefData.dbInfo.db_name, SysDefData.dbInfo.db_verison) ohosDataRdb.getRdbStore(context, SysDefData.dbInfo.db_name, SysDefData.dbInfo.db_verison)
.then(async (store) => { .then(async (store) => {
LogUtil.info(TAG, "createRdbStore, store is " + store) LogUtil.info(TAG, "createRdbStore, store is " + store)
rdbStore = store globalThis.rdbStore = store
// create table // create table
await rdbStore.executeSql(TableSql.FolderTableSQL, null) await globalThis.rdbStore.executeSql(TableSql.FolderTableSQL, null)
await rdbStore.executeSql(TableSql.NoteTableSQL, null) await globalThis.rdbStore.executeSql(TableSql.NoteTableSQL, null)
await rdbStore.executeSql(TableSql.AttachmentTableSQL, null) await globalThis.rdbStore.executeSql(TableSql.AttachmentTableSQL, null)
await rdbStore.executeSql(TableSql.FormTableSQL, null) await globalThis.rdbStore.executeSql(TableSql.FormTableSQL, null)
LogUtil.info(TAG, "create table success") LogUtil.info(TAG, "create table success")
// insert system defined folder // insert system defined folder
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_allNotes) await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_allNotes)
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_unClassified) await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_unClassified)
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_myFavorites) await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_myFavorites)
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_recentDeletes) await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_recentDeletes)
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_personal) await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_personal)
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_life) await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_life)
await rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_work) await globalThis.rdbStore.insert(TableName.FolderTable, SysDefData.sys_def_work)
LogUtil.info(TAG, "insert system defined folder success") LogUtil.info(TAG, "insert system defined folder success")
// insert system defined note and attachment // insert system defined note and attachment
await rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note1) await globalThis.rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note1)
await rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note2) await globalThis.rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note2)
await rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note3) await globalThis.rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note3)
await rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note4) await globalThis.rdbStore.insert(TableName.NoteTable, SysDefData.sys_def_note4)
LogUtil.info(TAG, "insert system defined note and attachment success") LogUtil.info(TAG, "insert system defined note and attachment success")
// add sys-def folder and note to AppStorage // add sys-def folder and note to AppStorage
@ -172,11 +171,11 @@ export default {
ohosDataRdb.getRdbStore(context, SysDefData.dbInfo.db_name, SysDefData.dbInfo.db_verison) ohosDataRdb.getRdbStore(context, SysDefData.dbInfo.db_name, SysDefData.dbInfo.db_verison)
.then(async (store) => { .then(async (store) => {
LogUtil.info(TAG, "initAppStorage, store is " + store) LogUtil.info(TAG, "initAppStorage, store is " + store)
rdbStore = store globalThis.rdbStore = store
// query folder // query folder
let columns_folder = [] let columns_folder = []
let predicates_folder = new ohosDataRdb.RdbPredicates(TableName.FolderTable) let predicates_folder = new ohosDataRdb.RdbPredicates(TableName.FolderTable)
let resultSet_folder = await rdbStore.query(predicates_folder, columns_folder) let resultSet_folder = await globalThis.rdbStore.query(predicates_folder, columns_folder)
while (resultSet_folder.goToNextRow()) { while (resultSet_folder.goToNextRow()) {
let id = resultSet_folder.getLong(resultSet_folder.getColumnIndex(FolderTableColumn.Id)) let id = resultSet_folder.getLong(resultSet_folder.getColumnIndex(FolderTableColumn.Id))
let name = resultSet_folder.getString(resultSet_folder.getColumnIndex(FolderTableColumn.Name)) let name = resultSet_folder.getString(resultSet_folder.getColumnIndex(FolderTableColumn.Name))
@ -193,7 +192,7 @@ export default {
// query note // query note
let columns_note = [] let columns_note = []
let predicates_note = new ohosDataRdb.RdbPredicates(TableName.NoteTable) let predicates_note = new ohosDataRdb.RdbPredicates(TableName.NoteTable)
let resultSet_note = await rdbStore.query(predicates_note, columns_note) let resultSet_note = await globalThis.rdbStore.query(predicates_note, columns_note)
while (resultSet_note.goToNextRow()) { while (resultSet_note.goToNextRow()) {
let id = resultSet_note.getLong(resultSet_note.getColumnIndex(NoteTableColumn.Id)) let id = resultSet_note.getLong(resultSet_note.getColumnIndex(NoteTableColumn.Id))
let title = resultSet_note.getString(resultSet_note.getColumnIndex(NoteTableColumn.Title)) let title = resultSet_note.getString(resultSet_note.getColumnIndex(NoteTableColumn.Title))
@ -381,7 +380,7 @@ export default {
* @param callback * @param callback
*/ */
insert(tableName, valueBucket, callback) { insert(tableName, valueBucket, callback) {
rdbStore.insert(tableName, valueBucket).then((rowId) => { globalThis.rdbStore.insert(tableName, valueBucket).then((rowId) => {
LogUtil.info(TAG, "insert success, rowId is " + rowId) LogUtil.info(TAG, "insert success, rowId is " + rowId)
if (callback != null) { if (callback != null) {
callback(rowId) callback(rowId)
@ -397,7 +396,7 @@ export default {
* @param callback * @param callback
*/ */
delete(predicates, callback) { delete(predicates, callback) {
rdbStore.delete(predicates).then((affectedRowCount) => { globalThis.rdbStore.delete(predicates).then((affectedRowCount) => {
LogUtil.info(TAG, "delete success, affectedRowCount is " + affectedRowCount) LogUtil.info(TAG, "delete success, affectedRowCount is " + affectedRowCount)
if (callback != null) { if (callback != null) {
callback(affectedRowCount) callback(affectedRowCount)
@ -414,10 +413,10 @@ export default {
* @param callback * @param callback
*/ */
update(valueBucket, predicates, callback) { update(valueBucket, predicates, callback) {
if (!rdbStore) { if (!globalThis.rdbStore) {
return; return;
} }
rdbStore.update(valueBucket, predicates).then((affectedRowCount) => { globalThis.rdbStore.update(valueBucket, predicates).then((affectedRowCount) => {
LogUtil.info(TAG, "update success, affectedRowCount is " + affectedRowCount) LogUtil.info(TAG, "update success, affectedRowCount is " + affectedRowCount)
if (callback != null) { if (callback != null) {
callback(affectedRowCount) callback(affectedRowCount)
@ -434,7 +433,7 @@ export default {
* @param callback * @param callback
*/ */
query(columns, predicates, callback) { query(columns, predicates, callback) {
rdbStore.query(predicates, columns).then((resultSet) => { globalThis.rdbStore.query(predicates, columns).then((resultSet) => {
LogUtil.info(TAG, "query success, row count : " + resultSet.rowCount) LogUtil.info(TAG, "query success, row count : " + resultSet.rowCount)
if (callback != null) { if (callback != null) {
callback(resultSet) callback(resultSet)

View File

@ -17,7 +17,7 @@ import Ability from '@ohos.application.Ability'
import AbilityConstant from '@ohos.application.AbilityConstant' import AbilityConstant from '@ohos.application.AbilityConstant'
import fileio from '@ohos.fileio' import fileio from '@ohos.fileio'
import inputMethod from '@ohos.inputmethod' import inputMethod from '@ohos.inputmethod'
globalThis.rdbStore = undefined
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
private Tag = "MainAbility_Phone" private Tag = "MainAbility_Phone"

View File

@ -17,7 +17,7 @@ import Ability from '@ohos.application.Ability'
import AbilityConstant from '@ohos.application.AbilityConstant' import AbilityConstant from '@ohos.application.AbilityConstant'
import fileio from '@ohos.fileio' import fileio from '@ohos.fileio'
import inputMethod from '@ohos.inputmethod'; import inputMethod from '@ohos.inputmethod';
globalThis.rdbStore = undefined
export default class MainAbility extends Ability { export default class MainAbility extends Ability {
private Tag = "MainAbility_Tablet" private Tag = "MainAbility_Tablet"