fix: dConsole.log问题
This commit is contained in:
		
							parent
							
								
									9da3b0f856
								
							
						
					
					
						commit
						80c715d2c9
					
				| @ -50,6 +50,3 @@ export const JudgeTag = '[Judge]'; | |||||||
| 
 | 
 | ||||||
| //初始化表 | //初始化表 | ||||||
| export const InitTableTag = '[InitTable]'; | export const InitTableTag = '[InitTable]'; | ||||||
| 
 |  | ||||||
| //数据库操作 |  | ||||||
| export const DbOperationTag = '[DbOperation]'; |  | ||||||
| @ -2,7 +2,6 @@ import relationalStore from '@ohos.data.relationalStore' | |||||||
| import common from '@ohos.app.ability.common' | import common from '@ohos.app.ability.common' | ||||||
| import { BusinessError } from '@ohos.base' | import { BusinessError } from '@ohos.base' | ||||||
| import { DbTag } from '../config' | import { DbTag } from '../config' | ||||||
| import { dConsole } from './LogWorker' |  | ||||||
| 
 | 
 | ||||||
| export interface ColumnInfo { | export interface ColumnInfo { | ||||||
|   name: string, |   name: string, | ||||||
| @ -28,11 +27,11 @@ class DbUtils { | |||||||
|       relationalStore.getRdbStore(context, config) |       relationalStore.getRdbStore(context, config) | ||||||
|         .then(rdbStore => { |         .then(rdbStore => { | ||||||
|           this.rdbStore = rdbStore |           this.rdbStore = rdbStore | ||||||
|           dConsole.log(DbTag, "db rdbStore init success") |           console.log(DbTag, "db rdbStore init success") | ||||||
|           resolve() |           resolve() | ||||||
|         }) |         }) | ||||||
|         .catch((err: BusinessError) => { |         .catch((err: BusinessError) => { | ||||||
|           dConsole.error(DbTag, `db rdbStore init fail reason:${err}`); |           console.error(DbTag, `db rdbStore init fail reason:${err}`); | ||||||
|           reject(err) |           reject(err) | ||||||
|         }) |         }) | ||||||
| 
 | 
 | ||||||
| @ -45,11 +44,11 @@ class DbUtils { | |||||||
|       if (this.rdbStore) { |       if (this.rdbStore) { | ||||||
|         this.rdbStore?.executeSql(createSql) |         this.rdbStore?.executeSql(createSql) | ||||||
|           .then(() => { |           .then(() => { | ||||||
|             dConsole.log(DbTag, "sql createTable success") |             console.log(DbTag, "sql createTable success") | ||||||
|             resolve() |             resolve() | ||||||
|           }) |           }) | ||||||
|           .catch((err: BusinessError) => { |           .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) |             reject(err) | ||||||
|           }) |           }) | ||||||
|       } else { |       } else { | ||||||
| @ -64,11 +63,11 @@ class DbUtils { | |||||||
|     return new Promise((resolve, reject) => { |     return new Promise((resolve, reject) => { | ||||||
|       if (this.rdbStore) { |       if (this.rdbStore) { | ||||||
|         this.rdbStore?.executeSql(sql).then(() => { |         this.rdbStore?.executeSql(sql).then(() => { | ||||||
|           dConsole.log(DbTag, "sql clearTable success", sql) |           console.log(DbTag, "sql clearTable success", sql) | ||||||
|           resolve() |           resolve() | ||||||
|         }) |         }) | ||||||
|       } else { |       } else { | ||||||
|         dConsole.error(DbTag, "sql clearTable fail", sql) |         console.error(DbTag, "sql clearTable fail", sql) | ||||||
|         reject('rdbStore is null') |         reject('rdbStore is null') | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
| @ -79,14 +78,14 @@ class DbUtils { | |||||||
|     return new Promise((resolve, reject) => { |     return new Promise((resolve, reject) => { | ||||||
|       if (this.rdbStore) { |       if (this.rdbStore) { | ||||||
|         this.rdbStore?.executeSql(sql).then(() => { |         this.rdbStore?.executeSql(sql).then(() => { | ||||||
|           dConsole.log(DbTag, "sql executeSql success", sql) |           console.log(DbTag, "sql executeSql success", sql) | ||||||
|           resolve("") |           resolve("") | ||||||
|         }).catch((err: BusinessError) => { |         }).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) |           reject(err) | ||||||
|         }) |         }) | ||||||
|       } else { |       } else { | ||||||
|         dConsole.error(DbTag, "sql executeSql fail", sql) |         console.error(DbTag, "sql executeSql fail", sql) | ||||||
|         reject('rdbStore is null') |         reject('rdbStore is null') | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
| @ -98,10 +97,10 @@ class DbUtils { | |||||||
|       if (this.rdbStore) { |       if (this.rdbStore) { | ||||||
|         this.rdbStore?.insert(tableName, obj, (err, res) => { |         this.rdbStore?.insert(tableName, obj, (err, res) => { | ||||||
|           if (err) { |           if (err) { | ||||||
|             dConsole.error(DbTag, `sql insertData fail err:${JSON.stringify(err)}`); |             console.error(DbTag, `sql insertData fail err:${JSON.stringify(err)}`); | ||||||
|             reject(err) |             reject(err) | ||||||
|           } else { |           } else { | ||||||
|             dConsole.log(DbTag, `sql insertData success res:${res}`); |             console.log(DbTag, `sql insertData success res:${res}`); | ||||||
|             resolve(res) |             resolve(res) | ||||||
|           } |           } | ||||||
|         }) |         }) | ||||||
| @ -116,10 +115,10 @@ class DbUtils { | |||||||
|     return new Promise((resolve, reject) => { |     return new Promise((resolve, reject) => { | ||||||
|       const SQL = `DELETE FROM ${tableName};` |       const SQL = `DELETE FROM ${tableName};` | ||||||
|       this.executeSql(SQL).then(res => { |       this.executeSql(SQL).then(res => { | ||||||
|         dConsole.log(DbTag, "删除表成功!表名:", tableName) |         console.log(DbTag, "删除表成功!表名:", tableName) | ||||||
|         resolve(true) |         resolve(true) | ||||||
|       }).catch((err: BusinessError) => { |       }).catch((err: BusinessError) => { | ||||||
|         dConsole.error(DbTag, "删除表失败!表名:", tableName, "错误信息:", JSON.stringify(err)) |         console.error(DbTag, "删除表失败!表名:", tableName, "错误信息:", JSON.stringify(err)) | ||||||
|         reject(false) |         reject(false) | ||||||
|       }) |       }) | ||||||
|     }) |     }) | ||||||
| @ -138,7 +137,7 @@ class DbUtils { | |||||||
|     return new Promise((resolve, reject) => { |     return new Promise((resolve, reject) => { | ||||||
|       if (this.rdbStore) { |       if (this.rdbStore) { | ||||||
|         this.rdbStore.querySql(sql, []).then((res: relationalStore.ResultSet) => { |         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) { |           if (res.rowCount <= 0) { | ||||||
|             resolve(0 as T) |             resolve(0 as T) | ||||||
|           } else { |           } else { | ||||||
| @ -146,7 +145,7 @@ class DbUtils { | |||||||
|             resolve(res.getLong(0) as T) |             resolve(res.getLong(0) as T) | ||||||
|           } |           } | ||||||
|         }).catch((err: BusinessError) => { |         }).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) |           reject(err) | ||||||
|         }) |         }) | ||||||
|       } else { |       } else { | ||||||
| @ -161,10 +160,10 @@ class DbUtils { | |||||||
|       if (this.rdbStore) { |       if (this.rdbStore) { | ||||||
|         this.rdbStore?.query(predicates, columns.map(info => info.columnName), (err, result) => { |         this.rdbStore?.query(predicates, columns.map(info => info.columnName), (err, result) => { | ||||||
|           if (err) { |           if (err) { | ||||||
|             dConsole.error(DbTag, `sql queryForList fail err:${JSON.stringify(err)}`); |             console.error(DbTag, `sql queryForList fail err:${JSON.stringify(err)}`); | ||||||
|             reject(err) |             reject(err) | ||||||
|           } else { |           } 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)) |             resolve(this.parseResultSet(result, columns)) | ||||||
|           } |           } | ||||||
|         }) |         }) | ||||||
| @ -180,7 +179,7 @@ class DbUtils { | |||||||
|       if (this.rdbStore) { |       if (this.rdbStore) { | ||||||
|         this.rdbStore?.querySql(sql, [], (err, result) => { |         this.rdbStore?.querySql(sql, [], (err, result) => { | ||||||
|           if (err) { |           if (err) { | ||||||
|             dConsole.error(DbTag, `sql queryForListBySql fail err:${JSON.stringify(err)}`); |             console.error(DbTag, `sql queryForListBySql fail err:${JSON.stringify(err)}`); | ||||||
|             reject(err) |             reject(err) | ||||||
|           } else { |           } else { | ||||||
|             resolve(this.parseResultSet(result, columns)) |             resolve(this.parseResultSet(result, columns)) | ||||||
| @ -230,11 +229,11 @@ class DbUtils { | |||||||
|       if (this.rdbStore) { |       if (this.rdbStore) { | ||||||
|         this.rdbStore?.delete(predicates) |         this.rdbStore?.delete(predicates) | ||||||
|           .then(rows => { |           .then(rows => { | ||||||
|             dConsole.log(DbTag, `DbUtil delete success rows: ${rows.toString()}`) |             console.log(DbTag, `DbUtil delete success rows: ${rows.toString()}`) | ||||||
|             resolve(rows) |             resolve(rows) | ||||||
|           }) |           }) | ||||||
|           .catch((err: BusinessError) => { |           .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) |             reject(err) | ||||||
|           }) |           }) | ||||||
|       } else { |       } else { | ||||||
|  | |||||||
| @ -5,19 +5,19 @@ import { BusinessError } from '@ohos.base'; | |||||||
| import Prompt from '@system.prompt'; | import Prompt from '@system.prompt'; | ||||||
| import { initialization } from '../../api'; | import { initialization } from '../../api'; | ||||||
| 
 | 
 | ||||||
| import { DbOperationTag, GlobalConfig, InitTableTag } from '../../config'; | import { GlobalConfig, InitTableTag } from '../../config'; | ||||||
| import FileUtils from '../FileUtils'; | import FileUtils from '../FileUtils'; | ||||||
| import { dConsole } from '../LogWorker'; | import { dConsole } from '../LogWorker'; | ||||||
| 
 | 
 | ||||||
| // 建表操作 | // 建表操作 | ||||||
| export async function InitTable() { | export async function InitTable() { | ||||||
|   ParameterPlatform.forEach(item => { |   ParameterPlatform.forEach(item => { | ||||||
|     dConsole.log(DbOperationTag, "表名", item.sqlCreate) |     console.log("表名", item.sqlCreate) | ||||||
|     if (item) { |     if (item) { | ||||||
|       DB.executeSql(item.sqlCreate).then(() => { |       DB.executeSql(item.sqlCreate).then(() => { | ||||||
|         dConsole.log(DbOperationTag, "表创建成功", item.tableName) |         console.log("表创建成功", item.tableName) | ||||||
|       }).catch((err: BusinessError) => { |       }).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<RecordType>, delFl | |||||||
|       }).join(",") |       }).join(",") | ||||||
|       let INSERT_SQL = "INSERT INTO " + tableName |       let INSERT_SQL = "INSERT INTO " + tableName | ||||||
|         + " (" + columns + ") VALUES " + values |         + " (" + columns + ") VALUES " + values | ||||||
|       dConsole.log(DbOperationTag, '表插入语句,', INSERT_SQL, 'tableName', tableName) |       console.log('表插入语句,', INSERT_SQL, 'tableName', tableName) | ||||||
|       DB.executeSql(INSERT_SQL).then(() => { |       DB.executeSql(INSERT_SQL).then(() => { | ||||||
|         dConsole.log(DbOperationTag, '插入表成功', 'tableName', tableName) |         console.log('插入表成功', 'tableName', tableName) | ||||||
|         resolve(true) |         resolve(true) | ||||||
|       }).catch((err: BusinessError) => { |       }).catch((err: BusinessError) => { | ||||||
|         dConsole.error(DbOperationTag, '插入表失败,', JSON.stringify(err), 'tableName', tableName) |         console.log('插入表失败,', JSON.stringify(err), 'tableName', tableName) | ||||||
|         reject(err) |         reject(err) | ||||||
|       }) |       }) | ||||||
|     }) |     }) | ||||||
| @ -67,7 +67,6 @@ export async function GetSyncData<T>(tableName: string): Promise<T[]> { | |||||||
|   return new Promise((resolve, reject) => { |   return new Promise((resolve, reject) => { | ||||||
|     const platform = ParameterPlatform.get(tableName); |     const platform = ParameterPlatform.get(tableName); | ||||||
|     if (!platform || !platform.columns) { |     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}`); |       throw new Error(`Invalid tableName or columns not found for table: ${tableName}`); | ||||||
|     } |     } | ||||||
|     const columns: ColumnInfo[] = platform.columns.map((res: string) => { |     const columns: ColumnInfo[] = platform.columns.map((res: string) => { | ||||||
| @ -78,10 +77,8 @@ export async function GetSyncData<T>(tableName: string): Promise<T[]> { | |||||||
|       } as ColumnInfo; |       } as ColumnInfo; | ||||||
|     }); |     }); | ||||||
|     DB.queryListBySql<T>(`select * from ${tableName}`, columns).then((res: T[]) => { |     DB.queryListBySql<T>(`select * from ${tableName}`, columns).then((res: T[]) => { | ||||||
|       dConsole.log(DbOperationTag, `获取表 ${tableName} 数据成功`, res); |  | ||||||
|       resolve(res); |       resolve(res); | ||||||
|     }).catch((err: BusinessError) => { |     }).catch((err: BusinessError) => { | ||||||
|       dConsole.error(DbOperationTag, `获取表 ${tableName} 数据失败`, JSON.stringify(err)); |  | ||||||
|       reject(err); |       reject(err); | ||||||
|     }); |     }); | ||||||
|   }); |   }); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user