diff --git a/common/src/main/ets/broadcast/BroadcastHelper.ets b/common/src/main/ets/broadcast/BroadcastHelper.ets index 686eb21bea363662c7372325523f348a9b8958b2..b4b8b58c56c2f34bea931f0553fd51895f7948ef 100644 --- a/common/src/main/ets/broadcast/BroadcastHelper.ets +++ b/common/src/main/ets/broadcast/BroadcastHelper.ets @@ -27,16 +27,21 @@ const TAG = 'BroadcastHelper'; * @param data 广播携带数据,数据结构参考系统api:CommonEventPublishData */ export function sendBroadcast(action: string, data?: commonEventManager.CommonEventPublishData): void { - const callback = (err: BusinessError): void => { - if (err?.code) { - Log.error(TAG, `sendBroadcast [${action}] get err:${err?.code}, msg=${err?.message}`); + try{ + const callback = (err: BusinessError): void => { + if (err?.code) { + Log.error(TAG, `sendBroadcast [${action}] get err:${err?.code}, msg=${err?.message}`); + } else { + Log.info(TAG, `sendBroadcast [${action}] successful`); + } + }; + if (data) { + commonEventManager.publish(action, data, callback); } else { - Log.info(TAG, `sendBroadcast [${action}] successful`); + commonEventManager.publish(action, callback); } - }; - if (data) { - commonEventManager.publish(action, data, callback); - } else { - commonEventManager.publish(action, callback); + } catch (err) { + Log.error(TAG, `sendBroadcast err:${err?.message}`); } + } \ No newline at end of file diff --git a/datamanager/src/main/ets/processor/DefaultProcessor.ets b/datamanager/src/main/ets/processor/DefaultProcessor.ets index 6c6dbe6bef1b07c9ec5eff5b866d47d129547f2e..71f3b586b24f6779daaff3a91d8cab87c01fe4e0 100644 --- a/datamanager/src/main/ets/processor/DefaultProcessor.ets +++ b/datamanager/src/main/ets/processor/DefaultProcessor.ets @@ -235,7 +235,12 @@ export class DefaultProcessor implements DatabaseProcessor, Observable { Log.warn(this.logTag, `query get err:${err?.code}, ${err?.message}`); } } - rdbStore.query(table, predicates, columns, queryInnerFun); + try{ + rdbStore.query(table, predicates, columns, queryInnerFun); + } catch (err) { + Log.error(TAG, `doQuery get err:${err?.message}`); + } + } /** diff --git a/datamanager/src/main/ets/processor/instances/InstanceExpandHelper.ets b/datamanager/src/main/ets/processor/instances/InstanceExpandHelper.ets index b8a2d1d28aee5ef918aba514488c2ec25eb05de9..f8afbef4ae37a52c97d8c1b639baed3c9e3c4252 100644 --- a/datamanager/src/main/ets/processor/instances/InstanceExpandHelper.ets +++ b/datamanager/src/main/ets/processor/instances/InstanceExpandHelper.ets @@ -33,7 +33,11 @@ const TAG = "InstanceExpandHelper" */ export async function deleteAllInstances(rdbStore: data_rdb.RdbStore): Promise { const predicate = new data_rdb.RdbPredicates(InstancesColumns.TABLE_NAME); - const result = await rdbStore.delete(predicate); + try { + const result = await rdbStore.delete(predicate); + } catch (err) { + Log.error(TAG, `deleteAllInstances delete err:${err?.message}`); + } return result >= 0; } diff --git a/datamanager/src/main/ets/processor/instances/InstancesProcessor.ets b/datamanager/src/main/ets/processor/instances/InstancesProcessor.ets index 9d31859748ef515de966a104ee79aa610af5beaa..808fb7ea763ac03e24b7b627fcb4aa3da78a9e99 100644 --- a/datamanager/src/main/ets/processor/instances/InstancesProcessor.ets +++ b/datamanager/src/main/ets/processor/instances/InstancesProcessor.ets @@ -240,7 +240,12 @@ export async function expandOne(rdbStore: data_rdb.RdbStore, rowId: number, valu export async function acquireUpdateOne(rdbStore: data_rdb.RdbStore, eventId: number, event: Events | undefined) { const predicate = new dataSharePredicates.DataSharePredicates(); predicate.equalTo(InstancesColumns.EVENT_ID, eventId); - await rdbStore.delete(InstancesColumns.TABLE_NAME, predicate); + try { + await rdbStore.delete(InstancesColumns.TABLE_NAME, predicate); + } catch (err) { + Log.error(TAG, `acquireUpdateOne delete err:${err?.message}`); + } + acquireExpandOne(rdbStore, eventId, event); } @@ -280,13 +285,13 @@ function doInstancesQuery(rdbStore: data_rdb.RdbStore, columns: Array, p Log.error(TAG, `generate empty sql, the params maybe invalid`); return; } - Log.info(TAG, `instances query sql=${sql}`); + try { let instancesQueryFun = (err: BusinessError, resultSet: data_rdb.ResultSet) => { callback(err, resultSet); } rdbStore.querySql(sql, [], instancesQueryFun); } catch (err) { - Log.error(TAG, `doInstancesQuery querySql get err:${err?.message}, SQL:${sql}`); + Log.error(TAG, `doInstancesQuery querySql get err:${err?.message}`); } } \ No newline at end of file diff --git a/datamanager/src/main/ets/utils/CalendarDataHelper.ets b/datamanager/src/main/ets/utils/CalendarDataHelper.ets index ee5d53615b635a7b71a05446bff25c5c2f1602d3..69ddfc363fcd868f7bc6aca48632829d19607370 100644 --- a/datamanager/src/main/ets/utils/CalendarDataHelper.ets +++ b/datamanager/src/main/ets/utils/CalendarDataHelper.ets @@ -248,9 +248,9 @@ let CREATE_EVENTS_RAW_TIMES_TABLE_SQL = `CREATE TABLE IF NOT EXISTS ` + `${EventsRawTimesColumns.EVENT_ID} INTEGER NOT NULL, ` + `${EventsRawTimesColumns.DT_START_2445} TEXT, ` + `${EventsRawTimesColumns.DT_END_2445} TEXT, ` -+ `${EventsRawTimesColumns.ORIGINAL_INSTANCE_TIME2445} TEXT, ` -+ `${EventsRawTimesColumns.LAST_DATE2445} TEXT, ` -+ `UNIQUE (${EventsRawTimesColumns.EVENT_ID}))`; + + `${EventsRawTimesColumns.ORIGINAL_INSTANCE_TIME2445} TEXT, ` + + `${EventsRawTimesColumns.LAST_DATE2445} TEXT, ` + + `UNIQUE (${EventsRawTimesColumns.EVENT_ID}))`; /** * the create map_address_history table sql @@ -359,47 +359,52 @@ class CalendarDataHelper { await this.createEventsTable(); Log.log(TAG, "initRdbStore createEventsTable succeed"); } catch (err) { - Log.error(TAG, `initRdbStore createEventsTable get err:${err}`); + Log.error(TAG, `initRdbStore createEventsTable get err:${err.message}`); } Log.log(TAG, "initRdbStore executeSql start"); - await this.rdbStore?.executeSql(CREATE_CALENDARS_TABLE_SQL, []); - Log.log(TAG, "initRdbStore createCalendarsTable succeed"); - await this.rdbStore?.executeSql(CREATE_REMINDERS_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_REMINDERS_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_INSTANCES_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_INSTANCES_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_COLORS_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_COLORS_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_ATTENDEES_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_ATTENDEES_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_CALENDAR_ALERTS_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_CALENDAR_ALERTS_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_CALENDAR_CACHE_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_CALENDAR_CACHE_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_CALENDAR_METADATA_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_CALENDAR_METADATA_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_EVENTS_RAW_TIMES_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_EVENTS_RAW_TIMES_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_MAP_ADDRESS_HISTORY_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_MAP_ADDRESS_HISTORY_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_EXTENDED_PROPERTIES_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_EXTENDED_PROPERTIES_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_SYNC_STATE_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_SYNC_STATE_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_SYNC_STATE_METADATA_TABLE_SQL, []); - Log.log(TAG, "initRdbStore CREATE_SYNC_STATE_METADATA_TABLE_SQL succeed"); - await this.rdbStore?.executeSql(CREATE_EXTEND_CALENDAR_EVENT_TABLE_NAME_SQL, []); - Log.log(TAG, "initRdbStore CREATE_EXTEND_CALENDAR_EVENT_TABLE_NAME_SQL succeed"); - - this.createSyncIdUpdateTrigger(); - Log.log(TAG, "initRdbStore createSyncIdUpdateTrigger succeed"); - this.createDeleteEventTriggers(); - Log.log(TAG, "initRdbStore createDeleteEventTriggers succeed"); - this.createColorsTriggers(); - Log.log(TAG, "initRdbStore createColorsTriggers succeed"); - this.createCalendarCleanupTrigger(); - Log.log(TAG, "initRdbStore createCalendarCleanupTrigger succeed"); - Log.log(TAG, "initRdbStore executeSql end"); + try { + await this.rdbStore?.executeSql(CREATE_CALENDARS_TABLE_SQL, []); + Log.log(TAG, "initRdbStore createCalendarsTable succeed"); + await this.rdbStore?.executeSql(CREATE_REMINDERS_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_REMINDERS_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_INSTANCES_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_INSTANCES_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_COLORS_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_COLORS_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_ATTENDEES_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_ATTENDEES_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_CALENDAR_ALERTS_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_CALENDAR_ALERTS_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_CALENDAR_CACHE_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_CALENDAR_CACHE_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_CALENDAR_METADATA_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_CALENDAR_METADATA_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_EVENTS_RAW_TIMES_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_EVENTS_RAW_TIMES_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_MAP_ADDRESS_HISTORY_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_MAP_ADDRESS_HISTORY_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_EXTENDED_PROPERTIES_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_EXTENDED_PROPERTIES_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_SYNC_STATE_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_SYNC_STATE_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_SYNC_STATE_METADATA_TABLE_SQL, []); + Log.log(TAG, "initRdbStore CREATE_SYNC_STATE_METADATA_TABLE_SQL succeed"); + await this.rdbStore?.executeSql(CREATE_EXTEND_CALENDAR_EVENT_TABLE_NAME_SQL, []); + Log.log(TAG, "initRdbStore CREATE_EXTEND_CALENDAR_EVENT_TABLE_NAME_SQL succeed"); + + this.createSyncIdUpdateTrigger(); + Log.log(TAG, "initRdbStore createSyncIdUpdateTrigger succeed"); + this.createDeleteEventTriggers(); + Log.log(TAG, "initRdbStore createDeleteEventTriggers succeed"); + this.createColorsTriggers(); + Log.log(TAG, "initRdbStore createColorsTriggers succeed"); + this.createCalendarCleanupTrigger(); + Log.log(TAG, "initRdbStore createCalendarCleanupTrigger succeed"); + Log.log(TAG, "initRdbStore executeSql end"); + } catch (err) { + Log.error(TAG, `initRdbStore err:${err.message}`); + } + } private async createEventsTable() { @@ -563,9 +568,13 @@ class CalendarDataHelper { ` WHERE ${ExtendedPropertiesColumns.EVENT_ID} = old.${EventColumns.ID};` let EVENTS_CLEANUP_TRIGGER = `CREATE TRIGGER events_cleanup_delete DELETE ON ` + - `${EventColumns.TABLE_NAME} BEGIN ${EVENTS_CLEANUP_TRIGGER_SQL} END` - await this.rdbStore?.executeSql(EVENTS_CLEANUP_TRIGGER, []); - Log.log(TAG, 'call createDeleteEventTriggers end'); + `${EventColumns.TABLE_NAME} BEGIN ${EVENTS_CLEANUP_TRIGGER_SQL} END` + try { + await this.rdbStore?.executeSql(EVENTS_CLEANUP_TRIGGER, []); + Log.log(TAG, 'call createDeleteEventTriggers end'); + } catch (err) { + Log.error(TAG, `createDeleteEventTriggers err:${err?.message}`); + } } private async createColorsTriggers() { @@ -606,38 +615,51 @@ class CalendarDataHelper { ` new.${CalendarsColumns.CALENDAR_COLOR_INDEX} NOT NULL` + ` BEGIN ${CALENDAR_UPDATE_COLOR_TRIGGER_SQL} END` - Log.log(TAG, 'call CREATE_EVENT_COLOR_UPDATE_TRIGGER'); - await this.rdbStore?.executeSql(CREATE_EVENT_COLOR_UPDATE_TRIGGER, []) - Log.log(TAG, 'call CREATE_CALENDAR_COLOR_UPDATE_TRIGGER'); - await this.rdbStore?.executeSql(CREATE_CALENDAR_COLOR_UPDATE_TRIGGER, []) - Log.log(TAG, 'call createColorsTriggers end'); + try { + Log.log(TAG, 'call CREATE_EVENT_COLOR_UPDATE_TRIGGER'); + await this.rdbStore?.executeSql(CREATE_EVENT_COLOR_UPDATE_TRIGGER, []) + Log.log(TAG, 'call CREATE_CALENDAR_COLOR_UPDATE_TRIGGER'); + await this.rdbStore?.executeSql(CREATE_CALENDAR_COLOR_UPDATE_TRIGGER, []) + Log.log(TAG, 'call createColorsTriggers end'); + } catch (err) { + Log.error(TAG, `createColorsTriggers err:${err?.message}`); + } + } private async createCalendarCleanupTrigger() { Log.log(TAG, 'call createCalendarCleanupTrigger start') let CALENDAR_CLEANUP_TRIGGER_SQL = `DELETE FROM ` + - `${EventColumns.TABLE_NAME} WHERE ` + - `${EventColumns.CALENDAR_ID} = old.${EventColumns.ID};` + `${EventColumns.TABLE_NAME} WHERE ` + + `${EventColumns.CALENDAR_ID} = old.${EventColumns.ID};` let CALENDAR_CLEANUP_TRIGGER = `CREATE TRIGGER calendar_cleanup DELETE ON ` + - `${CalendarsColumns.TABLE_NAME} ` + - `BEGIN ${CALENDAR_CLEANUP_TRIGGER_SQL} END` - await this.rdbStore?.executeSql(CALENDAR_CLEANUP_TRIGGER, []); - Log.log(TAG, 'call createCalendarCleanupTrigger end'); + `${CalendarsColumns.TABLE_NAME} ` + + `BEGIN ${CALENDAR_CLEANUP_TRIGGER_SQL} END` + try { + await this.rdbStore?.executeSql(CALENDAR_CLEANUP_TRIGGER, []); + Log.log(TAG, 'call createCalendarCleanupTrigger end'); + } catch (err) { + Log.error(TAG, `createCalendarCleanupTrigger err:${err?.message}`); + } } private async createSyncIdUpdateTrigger() { - Log.log(TAG, 'call createSyncIdUpdateTrigger start'); - let EVENTS_ORIGINAL_SYNC_TRIGGER_SQL = `UPDATE ${EventColumns.TABLE_NAME}` + - ` SET ${EventColumns.ORIGINAL_SYNC_ID} = ` + - `new.${EventColumns.SYNC_ID}` + - ` WHERE ${EventColumns.ORIGINAL_ID} =old.${EventColumns.ID};` - let CREATE_SYNC_ID_UPDATE_TRIGGER = `CREATE TRIGGER original_sync_update` + - ` UPDATE OF ${EventColumns.SYNC_ID}` + - ` ON ${EventColumns.TABLE_NAME}` + - ` BEGIN ${EVENTS_ORIGINAL_SYNC_TRIGGER_SQL} END` - - await this.rdbStore?.executeSql(CREATE_SYNC_ID_UPDATE_TRIGGER, []); - Log.log(TAG, 'call createSyncIdUpdateTrigger end'); + try { + Log.log(TAG, 'call createSyncIdUpdateTrigger start'); + let EVENTS_ORIGINAL_SYNC_TRIGGER_SQL = `UPDATE ${EventColumns.TABLE_NAME}` + + ` SET ${EventColumns.ORIGINAL_SYNC_ID} = ` + + `new.${EventColumns.SYNC_ID}` + + ` WHERE ${EventColumns.ORIGINAL_ID} =old.${EventColumns.ID};` + let CREATE_SYNC_ID_UPDATE_TRIGGER = `CREATE TRIGGER original_sync_update` + + ` UPDATE OF ${EventColumns.SYNC_ID}` + + ` ON ${EventColumns.TABLE_NAME}` + + ` BEGIN ${EVENTS_ORIGINAL_SYNC_TRIGGER_SQL} END` + + await this.rdbStore?.executeSql(CREATE_SYNC_ID_UPDATE_TRIGGER, []); + Log.log(TAG, 'call createSyncIdUpdateTrigger end'); + } catch (err) { + Log.error(TAG, `createSyncIdUpdateTrigger err:${err?.message}`); + } } }