fix: dConsole.log问题
This commit is contained in:
		
							parent
							
								
									9da3b0f856
								
							
						
					
					
						commit
						80c715d2c9
					
				| @ -49,7 +49,4 @@ export const HomeTag = '[Home]'; | ||||
| export const JudgeTag = '[Judge]'; | ||||
| 
 | ||||
| //初始化表 | ||||
| export const InitTableTag = '[InitTable]'; | ||||
| 
 | ||||
| //数据库操作 | ||||
| export const DbOperationTag = '[DbOperation]'; | ||||
| export const InitTableTag = '[InitTable]'; | ||||
| @ -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 { | ||||
|  | ||||
| @ -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<RecordType>, 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<T>(tableName: string): Promise<T[]> { | ||||
|   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<T>(tableName: string): Promise<T[]> { | ||||
|       } as ColumnInfo; | ||||
|     }); | ||||
|     DB.queryListBySql<T>(`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); | ||||
|     }); | ||||
|   }); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user