diff --git a/AppScope/app.json5 b/AppScope/app.json5 index ca89e435793d9525a42995addd89a795d1eae7be..f0acc59d12ee09562b57f5aaa2a0870c22bb6b17 100644 --- a/AppScope/app.json5 +++ b/AppScope/app.json5 @@ -3,7 +3,7 @@ "bundleName": "cn.openharmony.dataorm", "vendor": "example", "versionCode": 1000000, - "versionName": "2.2.1-rc.2", + "versionName": "2.2.1", "icon": "$media:app_icon", "label": "$string:app_name", "distributedNotificationEnabled": true diff --git a/CHANGELOG.md b/CHANGELOG.md index 81ec669a17a10fd981d39c93447d44c589c16745..ddb7336c195ac09876391c7f8343e4d61d52541a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.2.1 +- 修复将条件语句作为条件时查询失败的问题 + ## 2.2.1-rc.2 - 修复in、notIn、between条件查询失败的问题 diff --git a/entry/oh-package.json5 b/entry/oh-package.json5 index 6a6b76d45a323ae2c2b36b35eb7ea72c219fd1c9..cfc349d56129f95c9e1142d4e893bd1f6172caf8 100644 --- a/entry/oh-package.json5 +++ b/entry/oh-package.json5 @@ -10,7 +10,7 @@ }, "description": "example description", "repository": {}, - "version": "2.2.1-rc.2", + "version": "2.2.1", "dependencies": { "@ohos/dataorm": "file:../library" } diff --git a/library/oh-package.json5 b/library/oh-package.json5 index aae3b05458e0de20be7c062ba034f211e98d3882..05c662f55abfa1b67c764cad078e414cc9291bca 100644 --- a/library/oh-package.json5 +++ b/library/oh-package.json5 @@ -14,7 +14,7 @@ "main": "index.ts", "repository": "https://gitee.com/openharmony-sig/dataORM", "type": "module", - "version": "2.2.1-rc.2", + "version": "2.2.1", "dependencies": { "reflect-metadata": "^0.1.13" }, diff --git a/library/src/main/ets/core/query/PropertyCondition.ts b/library/src/main/ets/core/query/PropertyCondition.ts index 2da61f12b062aa54dfc8965795feb936f098e91d..c6df092d78396f76da584bc047941f58b99970a7 100644 --- a/library/src/main/ets/core/query/PropertyCondition.ts +++ b/library/src/main/ets/core/query/PropertyCondition.ts @@ -92,7 +92,7 @@ export class PropertyCondition extends AbstractCondition { } public appendTo(builder: StringBuilder, tableAlias: string) { - let s = SqlUtils.appendProperty("", tableAlias, this.property).concat(this.op); + let s = SqlUtils.appendProperty("", tableAlias, this.property).concat(" " + this.op + " "); builder.append(s); } } diff --git a/library/src/main/ets/core/query/QueryBuilder.ts b/library/src/main/ets/core/query/QueryBuilder.ts index 98405282b8f89bd91f5d92f73250fe58762b3177..d2db724445bc63b7c862d92e70caa9eb9ceaf9de 100644 --- a/library/src/main/ets/core/query/QueryBuilder.ts +++ b/library/src/main/ets/core/query/QueryBuilder.ts @@ -27,6 +27,7 @@ import { PropertyCondition } from './PropertyCondition'; import dataRdb from '@ohos.data.relationalStore' import { StringBuilder } from '../StringBuilder' import { SqlUtils } from '../internal/SqlUtils' +import { StringCondition } from './StringCondition' export class QueryBuilder { @@ -44,7 +45,7 @@ export class QueryBuilder { private limits: number; private offsets: number; private isDistinct: boolean; - private predicates: dataRdb.RdbPredicates; + predicates: dataRdb.RdbPredicates; /** stored with a leading space */ private stringOrderCollations: string; @@ -245,7 +246,6 @@ export class QueryBuilder { let value: any = ( whereCondition).value; let values: any[] = ( whereCondition).values; switch (op) { - case "eq": this.predicates.equalTo(property.columnName, value) break; @@ -283,6 +283,82 @@ export class QueryBuilder { this.predicates.isNotNull(property.columnName) break; } + } else if (whereCondition.constructor.name == "StringCondition"){ + let str = ( whereCondition).getStr(); + let values = ( whereCondition).values; + let valueArray = str.split(" "); + let index = 0; + let columnName = ""; + for (let i = 0; i < valueArray.length; i++) { + let op = valueArray[i]; + if (!!!op) { + continue; + } + if (op.includes(".") && op.includes(this.tablePrefix)) { + columnName = valueArray[i].split(".")[1]; + continue; + } + switch (op) { + case "eq": + this.predicates.equalTo(columnName, values[index]) + index++; + break; + case "notEq": + this.predicates.notEqualTo(columnName, values[index]) + index++; + break; + case "like": + this.predicates.like(columnName, values[index]) + index++; + break; + case "between": + this.predicates.between(columnName, values[index], values[index + 1]) + index += 2; + break; + case "in": + this.predicates.in(columnName, values[index]) + index++; + break; + case "notIn": + this.predicates.notIn(columnName, values[index]) + index++; + break; + case "gt": + this.predicates.greaterThan(columnName, values[index]) + index++; + break; + case "lt": + this.predicates.lessThan(columnName, values[index]) + index++; + break; + case "ge": + this.predicates.greaterThanOrEqualTo(columnName, values[index]) + index++; + break; + case "le": + this.predicates.lessThanOrEqualTo(columnName, values[index]) + index++; + break; + case "isNull": + this.predicates.isNull(columnName) + break; + case "isNotNull": + this.predicates.isNotNull(columnName) + break; + case "AND": + this.predicates.and() + break; + case "OR": + this.predicates.or() + break; + case "(": + this.predicates.beginWrap() + break; + case ")": + this.predicates.endWrap() + break; + } + } } } diff --git a/library/src/main/ets/core/query/StringCondition.ts b/library/src/main/ets/core/query/StringCondition.ts index 9075b6f561d97cda6728bc8a9e08eaba79149fad..960551cb482b94e590ee4f0864c6191172fa5c55 100644 --- a/library/src/main/ets/core/query/StringCondition.ts +++ b/library/src/main/ets/core/query/StringCondition.ts @@ -25,6 +25,10 @@ export class StringCondition extends AbstractCondition { this.str = str; } + public getStr(): string { + return this.str; + } + public appendTo(builder: StringBuilder, tableAlias: string) { builder.append(tableAlias) } diff --git a/library/src/main/ets/core/query/WhereCollector.ts b/library/src/main/ets/core/query/WhereCollector.ts index 8f4e7e52dbc2ed07aadadcdb4eafb3ca3d19ce6b..7facd13ca24a032bc92470e39d12b973a816fa35 100644 --- a/library/src/main/ets/core/query/WhereCollector.ts +++ b/library/src/main/ets/core/query/WhereCollector.ts @@ -73,8 +73,9 @@ export class WhereCollector { combineWhereConditions(combineOp: string, cond1: WhereCondition, cond2: WhereCondition, condMore: Array): WhereCondition { - let builder = new StringBuilder("("); + let builder = new StringBuilder("( "); let combinedValues = new Array(); + if (combineOp === "OR") { this.predicates.beginWrap(); this.whereCase(cond1); @@ -94,15 +95,42 @@ export class WhereCollector { this.whereCase(condMore[j]); } } - this.addCondition(builder, combinedValues, cond1); - builder.append(combineOp); - this.addCondition(builder, combinedValues, cond2); + + if (cond1.constructor.name == "StringCondition") { + let str = ( cond1).getStr(); + let values = ( cond1).values; + builder.append(str); + combinedValues.push(values); + } else if (cond1.constructor.name == "PropertyCondition") { + this.addCondition(builder, combinedValues, cond1); + } + + builder.append(combineOp + " "); + + if (cond2.constructor.name == "StringCondition") { + let str = ( cond2).getStr(); + let values = ( cond2).values; + builder.append(str); + combinedValues.push(values); + } else if (cond2.constructor.name == "PropertyCondition") { + this.addCondition(builder, combinedValues, cond2); + } for (let i = 0;i < condMore.length; i++) { - builder.append(combineOp); - this.addCondition(builder, combinedValues, condMore[i]); + builder.append(combineOp + " "); + + if (condMore[i].constructor.name == "StringCondition") { + let str = ( condMore[i]).getStr(); + let values = ( condMore[i]).values; + builder.append(str); + combinedValues.push(values); + } else if (condMore[i].constructor.name == "PropertyCondition") { + this.addCondition(builder, combinedValues, condMore[i]); + } } - builder.append(')'); + + builder.append(') '); + combinedValues = combinedValues.flat(Infinity); return new StringCondition(builder.toString(), null, combinedValues); } diff --git a/oh-package.json5 b/oh-package.json5 index 7436c07ea9c75a86800adfb66ae5cdb9d4acc015..0feab287b6e7b26a50cdc8d4fad3beed338f50cc 100644 --- a/oh-package.json5 +++ b/oh-package.json5 @@ -11,6 +11,6 @@ }, "description": "example description", "repository": {}, - "version": "2.2.1-rc.2", + "version": "2.2.1", "dependencies": {} }