From 80c715d2c9cf27c9249b22cc87e88a6c20615537 Mon Sep 17 00:00:00 2001 From: wangzhongjie Date: Wed, 25 Jun 2025 14:10:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20dConsole.log=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/config/LogEnum.ets | 5 +-- entry/src/main/ets/utils/DbSql.ets | 41 ++++++++++---------- entry/src/main/ets/utils/table/Operation.ets | 17 ++++---- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/entry/src/main/ets/config/LogEnum.ets b/entry/src/main/ets/config/LogEnum.ets index 934cd37..9bdc88b 100644 --- a/entry/src/main/ets/config/LogEnum.ets +++ b/entry/src/main/ets/config/LogEnum.ets @@ -49,7 +49,4 @@ export const HomeTag = '[Home]'; export const JudgeTag = '[Judge]'; //初始化表 -export const InitTableTag = '[InitTable]'; - -//数据库操作 -export const DbOperationTag = '[DbOperation]'; \ No newline at end of file +export const InitTableTag = '[InitTable]'; \ No newline at end of file diff --git a/entry/src/main/ets/utils/DbSql.ets b/entry/src/main/ets/utils/DbSql.ets index b3d6de2..2b02caa 100644 --- a/entry/src/main/ets/utils/DbSql.ets +++ b/entry/src/main/ets/utils/DbSql.ets @@ -2,7 +2,6 @@ import relationalStore from '@ohos.data.relationalStore' import common from '@ohos.app.ability.common' import { BusinessError } from '@ohos.base' import { DbTag } from '../config' -import { dConsole } from './LogWorker' export interface ColumnInfo { name: string, @@ -28,11 +27,11 @@ class DbUtils { relationalStore.getRdbStore(context, config) .then(rdbStore => { this.rdbStore = rdbStore - dConsole.log(DbTag, "db rdbStore init success") + console.log(DbTag, "db rdbStore init success") resolve() }) .catch((err: BusinessError) => { - dConsole.error(DbTag, `db rdbStore init fail reason:${err}`); + console.error(DbTag, `db rdbStore init fail reason:${err}`); reject(err) }) @@ -45,11 +44,11 @@ class DbUtils { if (this.rdbStore) { this.rdbStore?.executeSql(createSql) .then(() => { - dConsole.log(DbTag, "sql createTable success") + console.log(DbTag, "sql createTable success") resolve() }) .catch((err: BusinessError) => { - dConsole.error(DbTag, `sql createTable fail err:${JSON.stringify(err)}`); + console.error(DbTag, `sql createTable fail err:${JSON.stringify(err)}`); reject(err) }) } else { @@ -64,11 +63,11 @@ class DbUtils { return new Promise((resolve, reject) => { if (this.rdbStore) { this.rdbStore?.executeSql(sql).then(() => { - dConsole.log(DbTag, "sql clearTable success", sql) + console.log(DbTag, "sql clearTable success", sql) resolve() }) } else { - dConsole.error(DbTag, "sql clearTable fail", sql) + console.error(DbTag, "sql clearTable fail", sql) reject('rdbStore is null') } }) @@ -79,14 +78,14 @@ class DbUtils { return new Promise((resolve, reject) => { if (this.rdbStore) { this.rdbStore?.executeSql(sql).then(() => { - dConsole.log(DbTag, "sql executeSql success", sql) + console.log(DbTag, "sql executeSql success", sql) resolve("") }).catch((err: BusinessError) => { - dConsole.error(DbTag, `sql executeSql fail err:${JSON.stringify(err)}`); + console.error(DbTag, `sql executeSql fail err:${JSON.stringify(err)}`); reject(err) }) } else { - dConsole.error(DbTag, "sql executeSql fail", sql) + console.error(DbTag, "sql executeSql fail", sql) reject('rdbStore is null') } }) @@ -98,10 +97,10 @@ class DbUtils { if (this.rdbStore) { this.rdbStore?.insert(tableName, obj, (err, res) => { if (err) { - dConsole.error(DbTag, `sql insertData fail err:${JSON.stringify(err)}`); + console.error(DbTag, `sql insertData fail err:${JSON.stringify(err)}`); reject(err) } else { - dConsole.log(DbTag, `sql insertData success res:${res}`); + console.log(DbTag, `sql insertData success res:${res}`); resolve(res) } }) @@ -116,10 +115,10 @@ class DbUtils { return new Promise((resolve, reject) => { const SQL = `DELETE FROM ${tableName};` this.executeSql(SQL).then(res => { - dConsole.log(DbTag, "删除表成功!表名:", tableName) + console.log(DbTag, "删除表成功!表名:", tableName) resolve(true) }).catch((err: BusinessError) => { - dConsole.error(DbTag, "删除表失败!表名:", tableName, "错误信息:", JSON.stringify(err)) + console.error(DbTag, "删除表失败!表名:", tableName, "错误信息:", JSON.stringify(err)) reject(false) }) }) @@ -138,7 +137,7 @@ class DbUtils { return new Promise((resolve, reject) => { if (this.rdbStore) { this.rdbStore.querySql(sql, []).then((res: relationalStore.ResultSet) => { - dConsole.log(DbTag, "sql query", JSON.stringify(res)) + console.log(DbTag, "sql query", JSON.stringify(res)) if (res.rowCount <= 0) { resolve(0 as T) } else { @@ -146,7 +145,7 @@ class DbUtils { resolve(res.getLong(0) as T) } }).catch((err: BusinessError) => { - dConsole.error(DbTag, `sql queryCount fail err:${JSON.stringify(err)}`); + console.error(DbTag, `sql queryCount fail err:${JSON.stringify(err)}`); reject(err) }) } else { @@ -161,10 +160,10 @@ class DbUtils { if (this.rdbStore) { this.rdbStore?.query(predicates, columns.map(info => info.columnName), (err, result) => { if (err) { - dConsole.error(DbTag, `sql queryForList fail err:${JSON.stringify(err)}`); + console.error(DbTag, `sql queryForList fail err:${JSON.stringify(err)}`); reject(err) } else { - dConsole.log(DbTag, `sql queryForList success rows: ${result.rowCount.toString()}`) + console.log(DbTag, `sql queryForList success rows: ${result.rowCount.toString()}`) resolve(this.parseResultSet(result, columns)) } }) @@ -180,7 +179,7 @@ class DbUtils { if (this.rdbStore) { this.rdbStore?.querySql(sql, [], (err, result) => { if (err) { - dConsole.error(DbTag, `sql queryForListBySql fail err:${JSON.stringify(err)}`); + console.error(DbTag, `sql queryForListBySql fail err:${JSON.stringify(err)}`); reject(err) } else { resolve(this.parseResultSet(result, columns)) @@ -230,11 +229,11 @@ class DbUtils { if (this.rdbStore) { this.rdbStore?.delete(predicates) .then(rows => { - dConsole.log(DbTag, `DbUtil delete success rows: ${rows.toString()}`) + console.log(DbTag, `DbUtil delete success rows: ${rows.toString()}`) resolve(rows) }) .catch((err: BusinessError) => { - dConsole.error(DbTag, `DbUtil delete fail err:${JSON.stringify(err)}`); + console.error(DbTag, `DbUtil delete fail err:${JSON.stringify(err)}`); reject(err) }) } else { diff --git a/entry/src/main/ets/utils/table/Operation.ets b/entry/src/main/ets/utils/table/Operation.ets index 0e5e492..1244837 100644 --- a/entry/src/main/ets/utils/table/Operation.ets +++ b/entry/src/main/ets/utils/table/Operation.ets @@ -5,19 +5,19 @@ import { BusinessError } from '@ohos.base'; import Prompt from '@system.prompt'; import { initialization } from '../../api'; -import { DbOperationTag, GlobalConfig, InitTableTag } from '../../config'; +import { GlobalConfig, InitTableTag } from '../../config'; import FileUtils from '../FileUtils'; import { dConsole } from '../LogWorker'; // 建表操作 export async function InitTable() { ParameterPlatform.forEach(item => { - dConsole.log(DbOperationTag, "表名", item.sqlCreate) + console.log("表名", item.sqlCreate) if (item) { DB.executeSql(item.sqlCreate).then(() => { - dConsole.log(DbOperationTag, "表创建成功", item.tableName) + console.log("表创建成功", item.tableName) }).catch((err: BusinessError) => { - dConsole.error(DbOperationTag, "表创建失败", item.tableName, err) + console.log("表创建失败", item.tableName, err) }) } }) @@ -40,12 +40,12 @@ export function SqlInsertTable(tableName: string, data: Array, delFl }).join(",") let INSERT_SQL = "INSERT INTO " + tableName + " (" + columns + ") VALUES " + values - dConsole.log(DbOperationTag, '表插入语句,', INSERT_SQL, 'tableName', tableName) + console.log('表插入语句,', INSERT_SQL, 'tableName', tableName) DB.executeSql(INSERT_SQL).then(() => { - dConsole.log(DbOperationTag, '插入表成功', 'tableName', tableName) + console.log('插入表成功', 'tableName', tableName) resolve(true) }).catch((err: BusinessError) => { - dConsole.error(DbOperationTag, '插入表失败,', JSON.stringify(err), 'tableName', tableName) + console.log('插入表失败,', JSON.stringify(err), 'tableName', tableName) reject(err) }) }) @@ -67,7 +67,6 @@ export async function GetSyncData(tableName: string): Promise { return new Promise((resolve, reject) => { const platform = ParameterPlatform.get(tableName); if (!platform || !platform.columns) { - dConsole.error(DbOperationTag, `Invalid tableName or columns not found for table: ${tableName}`); throw new Error(`Invalid tableName or columns not found for table: ${tableName}`); } const columns: ColumnInfo[] = platform.columns.map((res: string) => { @@ -78,10 +77,8 @@ export async function GetSyncData(tableName: string): Promise { } as ColumnInfo; }); DB.queryListBySql(`select * from ${tableName}`, columns).then((res: T[]) => { - dConsole.log(DbOperationTag, `获取表 ${tableName} 数据成功`, res); resolve(res); }).catch((err: BusinessError) => { - dConsole.error(DbOperationTag, `获取表 ${tableName} 数据失败`, JSON.stringify(err)); reject(err); }); });