From d69fbac881f61600b949dbc92292ffa4ff22c744 Mon Sep 17 00:00:00 2001 From: yanglifeng1217 Date: Thu, 31 Aug 2023 17:29:55 +0800 Subject: [PATCH] Signed-off-by: yanglifeng1217 --- .../main/js/test/RdbstoreInsertJsunit.test.js | 1823 ++++++------ .../js/test/RdbstoreTransactionJsunit.test.js | 798 +++--- .../main/js/test/RdbstoreUpdateJsunit.test.js | 426 ++- .../test/RelationalStoreInsertJsunit.test.js | 2464 ++++++++--------- .../RelationalStoreTransactionJsunit.test.js | 799 +++--- .../test/RelationalStoreUpdateJsunit.test.js | 291 +- 6 files changed, 3289 insertions(+), 3312 deletions(-) diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js index 89744abc8..8f4264cdd 100644 --- a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreInsertJsunit.test.js @@ -13,423 +13,404 @@ * limitations under the License. */ -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import dataRdb from '@ohos.data.rdb'; const TAG = "[RDB_JSKITS_TEST]" const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; -const CREATE_TABLE_NAME = "CREATE TABLE IF NOT EXISTS test" +const CREATE_TABLE_NAME = "CREATE TABLE IF NOT EXISTS test" const CREATE_TABLE = " (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; const STORE_CONFIG = { name: "InsertTest.db", } -var rdbStore = undefined; -var resultSet = undefined; - +let rdbStore = undefined; +let resultSet = undefined; function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } + export default function rdbstoreInsertTest() { -describe('rdbstoreInsertTest', function () { - beforeAll(async function () { - console.info(TAG + 'beforeAll') - rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); - await rdbStore.executeSql(CREATE_TABLE_TEST, null) - - }) + describe('rdbstoreInsertTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll') - beforeEach(async function () { - console.info(TAG + 'beforeEach') - await rdbStore.executeSql("DELETE FROM test"); - }) - afterEach(async function () { - console.info(TAG + 'afterEach') - }) + }) - afterAll(async function () { - console.info(TAG + 'afterAll') - rdbStore = null - await dataRdb.deleteRdbStore("InsertTest.db").then(() => { - sleep(2) - }); - }) + beforeEach(async function () { + console.info(TAG + 'beforeEach') + rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); + await rdbStore.executeSql(CREATE_TABLE_TEST, null) + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + rdbStore = null + await dataRdb.deleteRdbStore("InsertTest.db") + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + }) + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.name rdb insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0010 + * @tc.desc rdb insert test + */ + it('testRdbStoreInsert0001', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + } + { + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + } + { + const valueBucket = { + "name": "lisi", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + } + + let predicates = new dataRdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + await rdbStore.query(predicates).then((resultSet) => { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + expect(false).assertEqual(resultSet.goToNextRow()) + done(); + console.info(TAG + "************* testRdbStoreInsert0001 end *************"); + resultSet.close(); + resultSet = null; + }).catch((err) => { + console.error(`Query failed, code is ${err.code},message is ${err.message}`); + expect().assertFail(); + done(); + }) + }) - console.info(TAG + "*************Unit Test Begin*************"); + /** + * @tc.name rdb insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0020 + * @tc.desc rdb insert test + */ + it('testRdbStoreInsert0002', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0002 start *************"); + let u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("wrong", valueBucket).then(async (ret) => { + expect(1).assertEqual(ret); + console.info(TAG + "insert first done: " + ret); + done(); + console.info(TAG + "************* testRdbStoreInsert0002 end *************"); + }).catch((err) => { + console.info(TAG + "insert with wrong table" + err) + done(); + }) + } + }) - /** - * @tc.name rdb insert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0010 - * @tc.desc rdb insert test - */ - it('testRdbStoreInsert0001', 0, async function (done) { - console.info(TAG + "************* testRdbStoreInsert0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - { + /** + * @tc.name rdb insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0030 + * @tc.desc rdb insert test + */ + it('testRdbStoreInsert0003', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0003 start *************"); + let u8 = new Uint8Array([1, 2, 3]) const valueBucket = { "name": "zhangsan", "age": 18, "salary": 100.5, "blobType": u8, } - await rdbStore.insert("test", valueBucket) - } - { + try { + await rdbStore.insert(null, valueBucket).then(() => { + console.log("insert done"); + expect().assertFail(); + done(); + }).catch((error) => { + console.log("insert error" + error); + expect().assertFail(); + done(); + }) + } catch (err) { + console.log(`insert failed, code is ${err.code},message is ${err.message}`); + expect(err.code).assertEqual('401'); + done(); + console.info(TAG + "************* testRdbStoreInsert0003 end *************"); + } + }) + + /** + * @tc.name rdb insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0040 + * @tc.desc rdb insert test + */ + it('testRdbStoreInsert0004', 0, async function (done) { + console.log(TAG + "************* testRdbStoreInsert0004 start *************"); + let u8 = new Uint8Array([1, 2, 3]) const valueBucket = { - "name": "lisi", + "name": "zhangsan", + "age": 18, + "salary": null, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket).then(async (ret) => { + expect(1).assertEqual(ret); + console.log(TAG + "insert first done: " + ret); + done(); + console.log(TAG + "************* testRdbStoreInsert0004 end *************"); + }).catch((err) => { + console.log(TAG + "insert with null table" + err); + expect().assertFail(); + done(); + }) + }) + + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0010 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertPromise0001', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0001 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "1" + CREATE_TABLE) + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", "age": 18, "salary": 100.5, "blobType": u8, } - await rdbStore.insert("test", valueBucket) - } - { - const valueBucket = { + const valueBucket2 = { "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", "age": 20, "salary": 100.5, "blobType": u8, } - await rdbStore.insert("test", valueBucket) - } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.batchInsert("test1", valueBuckets).then((number) => { + expect(3).assertEqual(number) + }).catch((err) => { + expect().assertFail(); + }) - let predicates = new dataRdb.RdbPredicates("test"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(1).assertEqual(id); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("insert1 error " + e); - } - resultSet = null - done() - console.info(TAG + "************* testRdbStoreInsert0001 end *************"); - }) + let predicates = new dataRdb.RdbPredicates("test1"); + predicates.equalTo("name", "zhangsan") + await rdbStore.query(predicates).then((resultSet) => { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + expect(false).assertEqual(resultSet.goToNextRow()) + done(); + console.info(TAG + "************* testRdbStorebatchInsertPromise0001 end *************"); + resultSet.close(); + resultSet = null; + }).catch((err) => { + console.error(`Updated failed, err is ${err}`); + expect().assertFail(); + done(); + }) + }) - /** - * @tc.name rdb insert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0020 - * @tc.desc rdb insert test - */ - it('testRdbStoreInsert0002', 0, async function (done) { - console.info(TAG + "************* testRdbStoreInsert0002 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - { - const valueBucket = { + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0020 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertPromise0002', 0, async function (done) { + await rdbStore.executeSql(CREATE_TABLE_NAME + "2" + CREATE_TABLE) + console.info(TAG + "************* testRdbStorebatchInsertPromise0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { "name": "zhangsan", "age": 18, "salary": 100.5, "blobType": u8, } - let insertPromise = rdbStore.insert("wrong", valueBucket) - insertPromise.then(async (ret) => { - expect(1).assertEqual(ret) - console.info(TAG + "insert first done: " + ret) - expect(null).assertFail() + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.batchInsert("test2", valueBuckets).then((number) => { + expect(3).assertEqual(number) }).catch((err) => { - console.info(TAG + "insert with wrong table") + expect().assertFail(); + }) + let predicates = new dataRdb.RdbPredicates("test2"); + predicates.equalTo("name", "lisi") + await rdbStore.query(predicates).then(async (resultSet) => { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + }).catch((err) => { + console.error(TAG +`Query failed, code is ${err.code},message is ${err.message}`); + expect().assertFail(); }) - } - done() - console.info(TAG + "************* testRdbStoreInsert0002 end *************"); - }) - /** - * @tc.name rdb insert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0030 - * @tc.desc rdb insert test - */ - it('testRdbStoreInsert0003', 0, async function (done) { - console.info(TAG + "************* testRdbStoreInsert0003 start *************"); - let errInfo = undefined; - var u8 = new Uint8Array([1, 2, 3]) - { - const valueBucket = { + try { + await rdbStore.delete(predicates).then(async (number) => { + console.log(TAG +`delete done = ` + number); + expect(1).assertEqual(number) + }).catch((err) => { + console.error(TAG +`delete failed, code is ${err.code},message is ${err.message}`); + expect().assertFail(); + }) + + await rdbStore.query(predicates).then(async (resultSet) => { + console.log(TAG +`Query done = ` + resultSet.rowCount); + expect(resultSet.rowCount).assertEqual(0); + done(); + console.info(TAG + "************* testRdbStorebatchInsertPromise0002 end *************"); + resultSet.close(); + resultSet = null; + }).catch((error) => { + console.error(TAG +`Query failed, code is ${error.code},message is ${error.message}`); + expect().assertFail(); + done(); + }) + } catch (e) { + console.info(TAG +" error " + e); + expect().assertFail(); + done(); + } + }) + + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0030 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertPromise0003', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0003 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "3" + CREATE_TABLE) + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { "name": "zhangsan", "age": 18, "salary": 100.5, "blobType": u8, } - try{ - rdbStore.insert(null, valueBucket) - }catch(err){ - errInfo = err + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, } - expect(errInfo.code).assertEqual("401") - } - done() - console.info(TAG + "************* testRdbStoreInsert0003 end *************"); - }) - - /** - * @tc.name rdb insert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0040 - * @tc.desc rdb insert test - */ - it('testRdbStoreInsert0004', 0, async function (done) { - console.log(TAG + "************* testRdbStoreInsert0004 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket = { - "name": "zhangsan", - "age": 18, - "salary": null, - "blobType": u8, - } - let insertPromise = rdbStore.insert("test", valueBucket) - insertPromise.then(async (ret) => { - expect(1).assertEqual(ret) - console.log(TAG + "insert first done: " + ret) - }).catch((err) => { - console.log(TAG + "insert with null table") - expect(null).assertFail() - }) - done(); - console.log(TAG + "************* testRdbStoreInsert0004 end *************"); - }) - - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0010 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertPromise0001', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertPromise0001 start *************"); - await rdbStore.executeSql(CREATE_TABLE_NAME + "1" + CREATE_TABLE) - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.batchInsert("test1", valueBuckets).then((number) => { - expect(3).assertEqual(number) - }).catch((err) =>{ - expect(false).assertTrue(); - }) - - let predicates = new dataRdb.RdbPredicates("test1"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(1).assertEqual(id); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - predicates = new dataRdb.RdbPredicates("test1"); - predicates.equalTo("name", "lisi") - resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - resultSet = null - done() - console.info(TAG + "************* testRdbStorebatchInsertPromise0001 end *************"); - }) - - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0020 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertPromise0002', 0, async function (done) { - await rdbStore.executeSql(CREATE_TABLE_NAME + "2" + CREATE_TABLE) - console.info(TAG + "************* testRdbStorebatchInsertPromise0002 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.batchInsert("test2", valueBuckets).then((number) => { - expect(3).assertEqual(number) - }).catch((err) =>{ - expect(false).assertTrue(); - }) - let predicates = new dataRdb.RdbPredicates("test2"); - predicates.equalTo("name", "lisi") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - await rdbStore.delete(predicates).then((number) => { - expect(1).assertEqual(number) - }).then(async () => { - resultSet = await rdbStore.query(predicates).catch((err) =>{ - expect(err != null).assertTrue(); - }) + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.batchInsert("test3", valueBuckets).then((number) => { + expect(3).assertEqual(number) + }).catch((err) => { + expect(false).assertTrue(); }) - } catch (e) { - console.info("BatchInsert2 error " + e); - } - resultSet = null - done() - console.info(TAG + "************* testRdbStorebatchInsertPromise0002 end *************"); - }) - - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0030 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertPromise0003', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertPromise0003 start *************"); - await rdbStore.executeSql(CREATE_TABLE_NAME + "3" + CREATE_TABLE) - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.batchInsert("test3", valueBuckets).then((number) => { - expect(3).assertEqual(number) - }).catch((err) =>{ - expect(false).assertTrue(); - }) - let predicates = new dataRdb.RdbPredicates("test3"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(1).assertEqual(id); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - predicates = new dataRdb.RdbPredicates("test3"); - predicates.equalTo("name", "lisi") - resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - const valueBucket4 = { - "name": "zhangmaowen", - "age": 25, - "salary": 500, - "blobType": u8, + let predicates = new dataRdb.RdbPredicates("test3"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + resultSet.close(); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + } catch (e) { + console.info("BatchInsert1 error " + e); } - await rdbStore.insert("test3",valueBucket4) predicates = new dataRdb.RdbPredicates("test3"); - predicates.equalTo("name", "zhangmaowen") + predicates.equalTo("name", "lisi") resultSet = await rdbStore.query(predicates) try { console.info(TAG + "resultSet query done"); @@ -438,81 +419,105 @@ describe('rdbstoreInsertTest', function () { const name = resultSet.getString(resultSet.getColumnIndex("name")) const age = resultSet.getLong(resultSet.getColumnIndex("age")) const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + resultSet.close(); console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(4).assertEqual(id); - expect("zhangmaowen").assertEqual(name) - expect(25).assertEqual(age) - expect(500).assertEqual(salary) + expect(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + const valueBucket4 = { + "name": "zhangmaowen", + "age": 25, + "salary": 500, + "blobType": u8, + } + await rdbStore.insert("test3", valueBucket4) + predicates = new dataRdb.RdbPredicates("test3"); + predicates.equalTo("name", "zhangmaowen") + resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + resultSet.close(); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(4).assertEqual(id); + expect("zhangmaowen").assertEqual(name) + expect(25).assertEqual(age) + expect(500).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); + } } catch (e) { console.info("BatchInsert1 error " + e); } - } catch (e) { - console.info("BatchInsert1 error " + e); - } - resultSet = null - done(); - console.info(TAG + "************* testRdbStorebatchInsertPromise0003 end *************"); - }) - - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0040 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertPromise0004', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertPromise0004 start *************"); - await rdbStore.executeSql(CREATE_TABLE_NAME + "4" + CREATE_TABLE) - var u8 = new Uint8Array([1, 2, 3]) - var valueBuckets = new Array(100); - for(var i=0;i { - console.info(TAG + "Batch insert data end") - expect(100).assertEqual(number) - }).catch((err) =>{ - expect(false).assertTrue(); + done(); + console.info(TAG + "************* testRdbStorebatchInsertPromise0003 end *************"); }) - let predicates = new dataRdb.RdbPredicates("test4"); - predicates.equalTo("name", "zhangsan55") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(56).assertEqual(id); - expect("zhangsan55").assertEqual(name) - expect(55).assertEqual(age) - expect(56).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - resultSet = null; - done() - console.info(TAG + "************* testRdbStorebatchInsertPromise0004 end *************"); - }) + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0040 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertPromise0004', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0004 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "4" + CREATE_TABLE) + var u8 = new Uint8Array([1, 2, 3]) + var valueBuckets = new Array(100); + for (var i = 0;i < valueBuckets.length; i++) { + valueBuckets[i] = { + "name": "zhangsan" + i, + "age": i, + "salary": 1 + i, + "blobType": u8, + }; + } + console.info(TAG + "Batch insert data start") + await rdbStore.batchInsert("test4", valueBuckets).then((number) => { + console.info(TAG + "Batch insert data end") + expect(100).assertEqual(number) + }).catch((err) => { + expect(false).assertTrue(); + }) + + let predicates = new dataRdb.RdbPredicates("test4"); + predicates.equalTo("name", "zhangsan55") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(56).assertEqual(id); + expect("zhangsan55").assertEqual(name) + expect(55).assertEqual(age) + expect(56).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + resultSet = null; + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0004 end *************"); + }) - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0050 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertPromise0005', 0, async function (done) { + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0050 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertPromise0005', 0, async function (done) { console.info(TAG + "************* testRdbStorebatchInsertPromise0005 start *************"); await rdbStore.executeSql(CREATE_TABLE_NAME + "5" + CREATE_TABLE) var u8 = new Uint8Array([1, 2, 3]) @@ -537,10 +542,10 @@ describe('rdbstoreInsertTest', function () { const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] await rdbStore.batchInsert("test5", valueBuckets).then((number) => { expect(3).assertEqual(number) - }).catch((err) =>{ + }).catch((err) => { expect(false).assertTrue(); }) - + let predicates = new dataRdb.RdbPredicates("test5"); predicates.equalTo("name", "zhangsan") let resultSet = await rdbStore.query(predicates) @@ -567,300 +572,278 @@ describe('rdbstoreInsertTest', function () { console.info(TAG + "************* testRdbStorebatchInsertPromise0005 end *************"); }) - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0060 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertPromise0006', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertPromise0006 start *************"); - await rdbStore.executeSql(CREATE_TABLE_NAME + "6" + CREATE_TABLE) - let errInfo = undefined; - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - try{ - await rdbStore.batchInsert("test6","valueBuckets") - }catch(err){ - console.info(TAG + "Batch insert data error: " + err) - errInfo = err - } - expect(errInfo.code).assertEqual("401") - done() - console.info(TAG + "************* testRdbStorebatchInsertPromise0006 end *************"); - }) + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0060 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertPromise0006', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0006 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "6" + CREATE_TABLE) + let errInfo = undefined; + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + try { + await rdbStore.batchInsert("test6", "valueBuckets") + } catch (err) { + console.info(TAG + "Batch insert data error: " + err) + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0006 end *************"); + }) - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0070 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertPromise0007', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertPromise0007 start *************"); - let errInfo = undefined; - await rdbStore.executeSql(CREATE_TABLE_NAME + "7" + CREATE_TABLE) - try{ - await rdbStore.batchInsert("test7") - }catch(err){ - console.info(TAG + "Batch insert data error: " + err) - errInfo = err - } - expect(errInfo.code).assertEqual("401") - done() - console.info(TAG + "************* testRdbStorebatchInsertPromise0007 end *************"); - }) + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Promise_0070 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertPromise0007', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0007 start *************"); + let errInfo = undefined; + await rdbStore.executeSql(CREATE_TABLE_NAME + "7" + CREATE_TABLE) + try { + await rdbStore.batchInsert("test7") + } catch (err) { + console.info(TAG + "Batch insert data error: " + err) + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0007 end *************"); + }) - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0100 - * @tc.desc rdb insert test - * zheg s - */ - it('testRdbStorebatchInsertCallback0001', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.executeSql(CREATE_TABLE_NAME + "callback1" + CREATE_TABLE).then(async () => { - console.info(TAG + "Batch insert data start") - await rdbStore.batchInsert("testcallback1", valueBuckets, async (err, data) => { - if(err != null){ - expect(false).assertTrue(); - }else{ - console.info(TAG + "Batch insert data end") - expect(3).assertEqual(data) - let predicates = new dataRdb.RdbPredicates("testcallback1"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(1).assertEqual(id); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - predicates = new dataRdb.RdbPredicates("testcallback1"); - predicates.equalTo("name", "lisi") - resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("BatchInsert1 error " + e); + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0100 + * @tc.desc rdb insert test + * zheg s + */ + it('testRdbStorebatchInsertCallback0001', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "callback1" + CREATE_TABLE).then(async () => { + console.info(TAG + "Batch insert data start") + await rdbStore.batchInsert("testcallback1", valueBuckets, async (err, data) => { + if (err != null) { + expect(false).assertTrue(); + } else { + console.info(TAG + "Batch insert data end") + expect(3).assertEqual(data) + let predicates = new dataRdb.RdbPredicates("testcallback1"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + expect(false).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + predicates = new dataRdb.RdbPredicates("testcallback1"); + predicates.equalTo("name", "lisi") + resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + expect(false).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); + } } - } - done(); + done(); + }) + resultSet = null }) - resultSet = null + await sleep(2000) + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0001 end *************"); }) - await sleep(2000) - done() - console.info(TAG + "************* testRdbStorebatchInsertCallback0001 end *************"); - }) - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0200 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertCallback0002', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0002 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback2" + CREATE_TABLE).then(async () => { - await rdbStore.batchInsert("testCallback2", valueBuckets, async (err, data) => { - if(err != null){ - expect(false).assertTrue(); - }else{ - expect(3).assertEqual(data) - let predicates = new dataRdb.RdbPredicates("testCallback2"); - predicates.equalTo("name", "lisi") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - await rdbStore.delete(predicates).then((number) => { - expect(1).assertEqual(number) - }).then(async () => { - resultSet = await rdbStore.query(predicates).catch((err) =>{ - expect(err != null).assertTrue(); + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0200 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertCallback0002', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback2" + CREATE_TABLE).then(async () => { + await rdbStore.batchInsert("testCallback2", valueBuckets, async (err, data) => { + if (err != null) { + expect(false).assertTrue(); + } else { + expect(3).assertEqual(data) + let predicates = new dataRdb.RdbPredicates("testCallback2"); + predicates.equalTo("name", "lisi") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + await rdbStore.delete(predicates).then((number) => { + expect(1).assertEqual(number) + }).then(async () => { + resultSet = await rdbStore.query(predicates).catch((err) => { + expect(err != null).assertTrue(); + }) }) - }) - } catch (e) { - console.info("BatchInsert2 error " + e); + } catch (e) { + console.info("BatchInsert2 error " + e); + } } - } - done(); + done(); + }) }) + await sleep(2000) + resultSet = null + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0002 end *************"); }) - await sleep(2000) - resultSet = null - done() - console.info(TAG + "************* testRdbStorebatchInsertCallback0002 end *************"); - }) - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0300 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertCallback0003', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0003 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback3" + CREATE_TABLE).then(async () =>{ - await rdbStore.batchInsert("testCallback3", valueBuckets, async (err, data) => { - if(err != null){ - expect(false).assertTrue() - }else{ - expect(3).assertEqual(data) - let predicates = new dataRdb.RdbPredicates("testCallback3"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); - expect(1).assertEqual(id); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - predicates = new dataRdb.RdbPredicates("testCallback3"); - predicates.equalTo("name", "lisi") - resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - const valueBucket4 = { - "name": "zhangmaowen", - "age": 25, - "salary": 500, - "blobType": u8, + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0300 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertCallback0003', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0003 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback3" + CREATE_TABLE).then(async () => { + await rdbStore.batchInsert("testCallback3", valueBuckets, async (err, data) => { + if (err != null) { + expect(false).assertTrue() + } else { + expect(3).assertEqual(data) + let predicates = new dataRdb.RdbPredicates("testCallback3"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); } - await rdbStore.insert("testCallback3",valueBucket4) predicates = new dataRdb.RdbPredicates("testCallback3"); - predicates.equalTo("name", "zhangmaowen") + predicates.equalTo("name", "lisi") resultSet = await rdbStore.query(predicates) try { console.info(TAG + "resultSet query done"); @@ -870,221 +853,243 @@ describe('rdbstoreInsertTest', function () { const age = resultSet.getLong(resultSet.getColumnIndex("age")) const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); - expect(4).assertEqual(id); - expect("zhangmaowen").assertEqual(name) - expect(25).assertEqual(age) - expect(500).assertEqual(salary) + expect(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + const valueBucket4 = { + "name": "zhangmaowen", + "age": 25, + "salary": 500, + "blobType": u8, + } + await rdbStore.insert("testCallback3", valueBucket4) + predicates = new dataRdb.RdbPredicates("testCallback3"); + predicates.equalTo("name", "zhangmaowen") + resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); + expect(4).assertEqual(id); + expect("zhangmaowen").assertEqual(name) + expect(25).assertEqual(age) + expect(500).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); + } } catch (e) { console.info("BatchInsert1 error " + e); } - } catch (e) { - console.info("BatchInsert1 error " + e); } - } - done(); + done(); + }) }) + await sleep(2000) + resultSet = null + done(); + console.info(TAG + "************* testRdbStorebatchInsertCallback0003 end *************"); }) - await sleep(2000) - resultSet = null - done(); - console.info(TAG + "************* testRdbStorebatchInsertCallback0003 end *************"); - }) - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0400 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertCallback0004', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0004 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - var valueBuckets = new Array(100); - for(var i=0;i { - await rdbStore.batchInsert("testCallbak4", valueBuckets, async (err, data) => { - if(err != null){ - expect(false).assertTrue(); - }else{ - console.info(TAG + "Batch insert data end") - expect(100).assertEqual(data) - let predicates = new dataRdb.RdbPredicates("testCallbak4"); - predicates.equalTo("name", "zhangsan55") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); - expect(56).assertEqual(id); - expect("zhangsan55").assertEqual(name) - expect(55).assertEqual(age) - expect(56).assertEqual(salary) - } catch (e) { - console.info("BatchInsert1 error " + e); + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0400 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertCallback0004', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0004 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + var valueBuckets = new Array(100); + for (var i = 0;i < valueBuckets.length; i++) { + valueBuckets[i] = { + "name": "zhangsan" + i, + "age": i, + "salary": 1 + i, + "blobType": u8, + }; + } + console.info(TAG + "Batch insert data start") + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callbak4" + CREATE_TABLE).then(async () => { + await rdbStore.batchInsert("testCallbak4", valueBuckets, async (err, data) => { + if (err != null) { + expect(false).assertTrue(); + } else { + console.info(TAG + "Batch insert data end") + expect(100).assertEqual(data) + let predicates = new dataRdb.RdbPredicates("testCallbak4"); + predicates.equalTo("name", "zhangsan55") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); + expect(56).assertEqual(id); + expect("zhangsan55").assertEqual(name) + expect(55).assertEqual(age) + expect(56).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); + } } - } - done(); + done(); + }) }) + await sleep(2000) + resultSet = null; + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0004 end *************"); }) - await sleep(2000) - resultSet = null; - done() - console.info(TAG + "************* testRdbStorebatchInsertCallback0004 end *************"); - }) - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0500 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertCallback0005', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0005 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket3 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback5" + CREATE_TABLE).then(async () => { - await rdbStore.batchInsert("testCallback5", valueBuckets, async (err, number) => { - if(err != null){ - expect(false).assertTrue(); - }else{ - expect(3).assertEqual(number) - let predicates = new dataRdb.RdbPredicates("testCallback5"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + " name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - expect(true).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("BatchInsert1 error " + e); + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0500 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertCallback0005', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0005 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket3 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback5" + CREATE_TABLE).then(async () => { + await rdbStore.batchInsert("testCallback5", valueBuckets, async (err, number) => { + if (err != null) { + expect(false).assertTrue(); + } else { + expect(3).assertEqual(number) + let predicates = new dataRdb.RdbPredicates("testCallback5"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + " name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + expect(true).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); + } } - } - done(); + done(); + }) }) + await sleep(2000) + resultSet = null; + done(); + console.info(TAG + "************* testRdbStorebatchInsertCallback0005 end *************"); }) - await sleep(2000) - resultSet = null; - done(); - console.info(TAG + "************* testRdbStorebatchInsertCallback0005 end *************"); - }) - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0600 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertCallback0006', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0006 start *************"); - let errInfo = undefined; - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback6" + CREATE_TABLE).then(async () => { - try{ - rdbStore.batchInsert("testCallback6", "valueBuckets", (err, data) => { - console.info(TAG + "Affect row is " + data) - if(err != null){ - expect(null).assertFail(); - }else{ - expect(data).assertEqual(-1) - } - }) - }catch(err){ - console.info(TAG + "Batch insert data error: " + err) - errInfo = err + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0600 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertCallback0006', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0006 start *************"); + let errInfo = undefined; + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback6" + CREATE_TABLE).then(async () => { + try { + rdbStore.batchInsert("testCallback6", "valueBuckets", (err, data) => { + console.info(TAG + "Affect row is " + data) + if (err != null) { + expect(null).assertFail(); + } else { + expect(data).assertEqual(-1) + } + }) + } catch (err) { + console.info(TAG + "Batch insert data error: " + err) + errInfo = err + } + }) + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0006 end *************"); }) - expect(errInfo.code).assertEqual("401") - done() - console.info(TAG + "************* testRdbStorebatchInsertCallback0006 end *************"); - }) - /** - * @tc.name rdb batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0700 - * @tc.desc rdb insert test - */ - it('testRdbStorebatchInsertCallback0007', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0007 start *************"); - let errInfo = undefined; - await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback7" + CREATE_TABLE).then(async () => { - try{ - await rdbStore.batchInsert("testCallback7", (err,data) => { - console.info(TAG + "Affect row is " + data) - if(err != null){ - expect(null).assertFail(); - }else{ - expect(data).assertEqual(-1) - } - }) - }catch(err){ - errInfo = err - } - }).catch((err) => { - expect(null).assertFail(); + /** + * @tc.name rdb batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_BatchInsert_Callback_0700 + * @tc.desc rdb insert test + */ + it('testRdbStorebatchInsertCallback0007', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0007 start *************"); + let errInfo = undefined; + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback7" + CREATE_TABLE).then(async () => { + try { + await rdbStore.batchInsert("testCallback7", (err, data) => { + console.info(TAG + "Affect row is " + data) + if (err != null) { + expect(null).assertFail(); + } else { + expect(data).assertEqual(-1) + } + }) + } catch (err) { + errInfo = err + } + }).catch((err) => { + expect(null).assertFail(); + }) + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0007 end *************"); }) - expect(errInfo.code).assertEqual("401") - done() - console.info(TAG + "************* testRdbStorebatchInsertCallback0007 end *************"); - }) - console.info(TAG + "*************Unit Test End*************"); -}) + console.info(TAG + "*************Unit Test End*************"); + }) } diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js index 0b67bd78d..48a2b3c3e 100644 --- a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreTransactionJsunit.test.js @@ -26,414 +26,414 @@ const STORE_CONFIG = { var rdbStore = undefined; export default function rdbstoreTransactionTest() { -describe('rdbstoreTransactionTest', function () { - beforeAll(function () { - console.info(TAG + 'beforeAll') - }) - - beforeEach(async function () { - console.info(TAG + 'beforeEach') - rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); - await rdbStore.executeSql(CREATE_TABLE_TEST, null); - }) - - afterEach(async function () { - console.info(TAG + 'afterEach') - await rdbStore.executeSql("DELETE FROM test"); - rdbStore = null - await dataRdb.deleteRdbStore("rdbstoreTransactionTest.db"); - }) - - afterAll(async function () { - console.info(TAG + 'afterAll') - }) - - console.info(TAG + "*************Unit Test Begin*************"); - - /** - * @tc.name rdb transaction insert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_testRdbTransactionInsert0001 - * @tc.desc rdb transaction insert & commit, the result comes out is 3 items; - */ - it('testRdbTransactionInsert0001', 0, async function (done) { - console.info(TAG + "************* testRdbStoreInsert0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - rdbStore.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket) - - await rdbStore.commit() - - let predicates = new dataRdb.RdbPredicates("test"); - let resultSet = await rdbStore.query(predicates) - console.info(TAG + "testRdbTransactionInsert0001 result count " + resultSet.rowCount) - expect(1).assertEqual(resultSet.rowCount) - resultSet.close() -// resultSet == null; - } catch (e) { - console.info(TAG + e); - expect(null).assertFail() - console.info(TAG + "testRdbTransactionInsert0001 failed"); - } - done() - console.info(TAG + "************* testRdbTransactionInsert0001 end *************"); - }) - - /** - * @tc.name rdb transaction insert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_testRdbTransactionInsert0002 - * @tc.desc rdb transaction insert & commit, the result comes out is 3 items; - */ - it('testRdbTransactionInsert0002', 0, async function (done) { - console.info(TAG + "************* testRdbStoreInsert0002 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket) - - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 9.5, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket1) - - - const valueBucket2 = { - "name": "wangwu", - "age": 16, - "salary": 99, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket2) - - await rdbStore.commit() - - let predicates = new dataRdb.RdbPredicates("test"); - let resultSet = await rdbStore.query(predicates) - expect(3).assertEqual(resultSet.rowCount) - resultSet.close() -// resultSet == null; - } catch (e) { - expect(null).assertFail() - console.info(TAG + "testRdbTransactionInsert0002 failed"); - } - done() - console.info(TAG + "************* testRdbTransactionInsert0002 end *************"); - }) - - - /** - * @tc.name rdb transaction insert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_testRdbTransactionInsert0003 - * @tc.desc while using transaction to insert values, querying the db, - * the result comes out is 0; - */ - it('testRdbTransactionInsert0003', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionInsert0003 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, + describe('rdbstoreTransactionTest', function () { + beforeAll(function () { + console.info(TAG + 'beforeAll') + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + await rdbStore.executeSql("DELETE FROM test"); + rdbStore = null + await dataRdb.deleteRdbStore("rdbstoreTransactionTest.db"); + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + }) + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.name rdb transaction insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_testRdbTransactionInsert0001 + * @tc.desc rdb transaction insert & commit, the result comes out is 3 items; + */ + it('testRdbTransactionInsert0001', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + await rdbStore.commit() + + let predicates = new dataRdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + console.info(TAG + "testRdbTransactionInsert0001 result count " + resultSet.rowCount) + expect(1).assertEqual(resultSet.rowCount) + resultSet.close() + // resultSet == null; + } catch (e) { + console.info(TAG + e); + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0001 failed"); } - await rdbStore.insert("test", valueBucket) - - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 9.5, - "blobType": u8, + done() + console.info(TAG + "************* testRdbTransactionInsert0001 end *************"); + }) + + /** + * @tc.name rdb transaction insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_testRdbTransactionInsert0002 + * @tc.desc rdb transaction insert & commit, the result comes out is 3 items; + */ + it('testRdbTransactionInsert0002', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 9.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1) + + + const valueBucket2 = { + "name": "wangwu", + "age": 16, + "salary": 99, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket2) + + await rdbStore.commit() + + let predicates = new dataRdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + expect(3).assertEqual(resultSet.rowCount) + resultSet.close() + // resultSet == null; + } catch (e) { + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0002 failed"); } - await rdbStore.insert("test", valueBucket1) - - let predicates = new dataRdb.RdbPredicates("test"); - let resultSet = await rdbStore.query(predicates) - expect(0).assertEqual(resultSet.rowCount) - resultSet.close() -// resultSet == null; - const valueBucket2 = { - "name": "wangwu", - "age": 16, - "salary": 99, - "blobType": u8, + done() + console.info(TAG + "************* testRdbTransactionInsert0002 end *************"); + }) + + + /** + * @tc.name rdb transaction insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_testRdbTransactionInsert0003 + * @tc.desc while using transaction to insert values, querying the db, + * the result comes out is 0; + */ + it('testRdbTransactionInsert0003', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionInsert0003 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 9.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1) + + let predicates = new dataRdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + expect(0).assertEqual(resultSet.rowCount) + resultSet.close() + // resultSet == null; + const valueBucket2 = { + "name": "wangwu", + "age": 16, + "salary": 99, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket2) + + await rdbStore.commit() + } catch (e) { + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0003 failed"); } - await rdbStore.insert("test", valueBucket2) - - await rdbStore.commit() - } catch (e) { - expect(null).assertFail() - console.info(TAG + "testRdbTransactionInsert0003 failed"); - } - done() - console.info(TAG + "************* testRdbTransactionInsert0003 end *************"); - }) - - /** - * @tc.name rdb insert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_RollBack_0001 - * @tc.desc the classical transaction scenario, when we insert or commit the value, - * db returns an exception, we need to catch exception and rollback. - */ - it('testRdbTransactionRollBack0001', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionRollBack0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "id": 1, - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, + done() + console.info(TAG + "************* testRdbTransactionInsert0003 end *************"); + }) + + /** + * @tc.name rdb insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_RollBack_0001 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionRollBack0001', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionRollBack0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + await rdbStore.insert("test", valueBucket) + + await rdbStore.commit() + } catch (e) { + await rdbStore.rollBack() + let predicates = new dataRdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + console.info(TAG + "testRdbTransactionRollBack0001 result count " + resultSet.rowCount); + expect(0).assertEqual(resultSet.rowCount) + resultSet.close() + // resultSet == null; } - await rdbStore.insert("test", valueBucket) - await rdbStore.insert("test", valueBucket) - - await rdbStore.commit() - } catch (e) { - await rdbStore.rollBack() - let predicates = new dataRdb.RdbPredicates("test"); - let resultSet = await rdbStore.query(predicates) - console.info(TAG + "testRdbTransactionRollBack0001 result count " + resultSet.rowCount); - expect(0).assertEqual(resultSet.rowCount) - resultSet.close() -// resultSet == null; - } - done() - console.info(TAG + "************* testRdbTransactionRollBack0001 end *************"); - }) - - /** - * @tc.name rdb insert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Multi_0001 - * @tc.desc the classical transaction scenario, when we insert or commit the value, - * db returns an exception, we need to catch exception and rollback. - */ - it('testRdbTransactionMulti0001', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionMulti0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "id": 1, - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, + done() + console.info(TAG + "************* testRdbTransactionRollBack0001 end *************"); + }) + + /** + * @tc.name rdb insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Multi_0001 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionMulti0001', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionMulti0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + await rdbStore.beginTransaction() + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 220.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1).then(async (ret) => { + console.info(TAG + "testRdbTransactionMulti0001 * insert result " + ret); + expect(2).assertEqual(ret) + }) + + await rdbStore.commit() + await rdbStore.commit() + + let predicates = new dataRdb.RdbPredicates("test"); + await rdbStore.query(predicates).then(async (ret) => { + expect(2).assertEqual(ret.rowCount) + done() + console.info(TAG + "************* testRdbTransactionMulti0001 end *************"); + ret.close() + }) + } catch (e) { + console.info(TAG + "testRdbTransactionMulti0001 fail ***** "); } - await rdbStore.insert("test", valueBucket) - - await rdbStore.beginTransaction() - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 220.5, - "blobType": u8, + }) + + /** + * @tc.name rdb insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Multi_0002 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionMulti0002', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionMulti0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket); + + await rdbStore.beginTransaction() + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 220.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1, async function (err, ret1){ + console.info(TAG + "testRdbTransactionMulti0002 * insert result " + ret1); + expect(2).assertEqual(ret1) + + await rdbStore.rollBack() + + await rdbStore.commit() + + let predicates = new dataRdb.RdbPredicates("test"); + await rdbStore.query(predicates).then(async (ret2) => { + console.info(TAG + "testRdbTransactionMulti0002 * final query " + ret2.rowCount); + expect(1).assertEqual(ret2.rowCount) + done() + console.info(TAG + "************* testRdbTransactionMulti0002 end *************"); + ret2.close() + }) + }) + + } catch (e) { + console.info(TAG + "testRdbTransactionMulti0002 fail ***** "); + expect().assertFail(); + done(); } - let num = rdbStore.insert("test", valueBucket1) - num.then(async (ret) => { - console.info(TAG + "testRdbTransactionMulti0001 * insert result " + ret); - expect(2).assertEqual(ret) - }) - - await rdbStore.commit() - await rdbStore.commit() - - let predicates = new dataRdb.RdbPredicates("test"); - num = rdbStore.query(predicates) - num.then(async (ret) => { - expect(2).assertEqual(ret.rowCount) - ret.close() - }) - } catch (e) { - console.info(TAG + "testRdbTransactionMulti0001 fail ***** "); - } - done() - console.info(TAG + "************* testRdbTransactionMulti0001 end *************"); - }) - - /** - * @tc.name rdb insert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Multi_0002 - * @tc.desc the classical transaction scenario, when we insert or commit the value, - * db returns an exception, we need to catch exception and rollback. - */ - it('testRdbTransactionMulti0002', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionMulti0002 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "id": 1, - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, + }) + + /** + * @tc.name rdb insert test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Multi_0003 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionMulti0003', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionMulti0003 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket); + + await rdbStore.beginTransaction(); + const valueBucket2 = { + "name": "zhangsan", + "age": 20, + "salary": 220.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket2); + + await rdbStore.rollBack(); + + const valueBucket3 = { + "name": "wangwu", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket3); + await rdbStore.commit(); + + let predicates = new dataRdb.RdbPredicates("test"); + await rdbStore.query(predicates).then(async (ret) => { + console.info(TAG + "testRdbTransactionMulti0003 * final query " + ret.rowCount); + expect(2).assertEqual(ret.rowCount); + done(); + console.info(TAG + "************* testRdbTransactionMulti0003 end *************"); + ret.close(); + }) + } catch (e) { + await rdbStore.rollBack() + console.info(TAG + "testRdbTransactionMulti0003 rollback ***** "); } - await rdbStore.insert("test", valueBucket, function (err, ret){ - - }); - await rdbStore.beginTransaction() - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 220.5, - "blobType": u8, + }) + + /** + * @tc.name rdb delete test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Transaction_Delete_0010 + * @tc.desc the classical transaction scenario, when we delete or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionDelete0001', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionDelete0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 9.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1) + + let predicates = new dataRdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + expect(0).assertEqual(resultSet.rowCount) + resultSet.close() + // resultSet == null; + const valueBucket2 = { + "name": "wangwu", + "age": 16, + "salary": 99, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket2) + + await rdbStore.commit() + } catch (e) { + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0003 failed"); } - let num = rdbStore.insert("test", valueBucket1) - num.then(async (ret) => { - console.info(TAG + "testRdbTransactionMulti0002 * insert result " + ret); - expect(2).assertEqual(ret) - ret.close() - }) - - await rdbStore.rollBack() - - await rdbStore.commit() - - let predicates = new dataRdb.RdbPredicates("test"); - num = rdbStore.query(predicates) - num.then(async (ret) => { - console.info(TAG + "testRdbTransactionMulti0002 * final query " + ret.rowCount); - expect(1).assertEqual(ret.rowCount) - ret.close() - }) - } catch (e) { - console.info(TAG + "testRdbTransactionMulti0002 fail ***** "); - } - done() - console.info(TAG + "************* testRdbTransactionMulti0002 end *************"); - }) - - /** - * @tc.name rdb insert test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Multi_0003 - * @tc.desc the classical transaction scenario, when we insert or commit the value, - * db returns an exception, we need to catch exception and rollback. - */ - it('testRdbTransactionMulti0003', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionMulti0003 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "id": 1, - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, + //删除 + { + let predicates = await new dataRdb.RdbPredicates("test") + await rdbStore.delete(predicates).then(async (ret) => { + expect(3).assertEqual(ret); + done() + console.info(TAG + "************* testRdbTransactionDelete0001 end *************"); + console.info(TAG + "Delete done: " + ret) + }).catch((err) => { + expect(null).assertFail(); + done(); + }) } - await rdbStore.insert("test", valueBucket, function (err, ret){ - }); + }) - await rdbStore.beginTransaction() - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 220.5, - "blobType": u8, - } - let num = await rdbStore.insert("test", valueBucket1) - - await rdbStore.rollBack() - - await rdbStore.insert("test", valueBucket) - await rdbStore.commit() - - let predicates = new dataRdb.RdbPredicates("test"); - num = rdbStore.query(predicates) - num.then(async (ret) => { - console.info(TAG + "testRdbTransactionMulti0003 * final query " + ret.rowCount); - expect(1).assertEqual(ret.rowCount) - ret.close() - }) - } catch (e) { - await rdbStore.rollBack() - console.info(TAG + "testRdbTransactionMulti0003 rollback ***** "); - } - done() - console.info(TAG + "************* testRdbTransactionMulti0003 end *************"); - }) - - /** - * @tc.name rdb delete test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Transaction_Delete_0010 - * @tc.desc the classical transaction scenario, when we delete or commit the value, - * db returns an exception, we need to catch exception and rollback. - */ - it('testRdbTransactionDelete0001', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionDelete0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket) - - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 9.5, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket1) - - let predicates = new dataRdb.RdbPredicates("test"); - let resultSet = await rdbStore.query(predicates) - expect(0).assertEqual(resultSet.rowCount) - resultSet.close() -// resultSet == null; - const valueBucket2 = { - "name": "wangwu", - "age": 16, - "salary": 99, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket2) - - await rdbStore.commit() - } catch (e) { - expect(null).assertFail() - console.info(TAG + "testRdbTransactionInsert0003 failed"); - } - //删除 - { - let predicates = await new dataRdb.RdbPredicates("test") - let deletePromise = rdbStore.delete(predicates) - deletePromise.then(async (ret) => { - expect(3).assertEqual(ret) - console.info(TAG + "Delete done: " + ret) - }).catch((err) => { - expect(null).assertFail() - }) - await deletePromise - } - done() - console.info(TAG + "************* testRdbTransactionDelete0001 end *************"); - }) - - console.info(TAG + "*************Unit Test End*************"); -})} + console.info(TAG + "*************Unit Test End*************"); + })} diff --git a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js index 79d0383a4..39fab7e72 100644 --- a/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/RdbJstest/hap/src/main/js/test/RdbstoreUpdateJsunit.test.js @@ -23,245 +23,243 @@ const STORE_CONFIG = { var rdbStore = undefined; export default function rdbStoreUpdateTest() { -describe('rdbStoreUpdateTest', function () { - beforeAll(function () { - console.info(TAG + 'beforeAll') - }) - - beforeEach(async function () { - console.info(TAG + 'beforeEach') - rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); - await rdbStore.executeSql(CREATE_TABLE_TEST, null); - }) - - afterEach(async function () { - console.info(TAG + 'afterEach') - await rdbStore.executeSql("DELETE FROM test"); - rdbStore = null - await dataRdb.deleteRdbStore("UpdataTest.db"); - }) + describe('rdbStoreUpdateTest', function () { + beforeAll(function () { + console.info(TAG + 'beforeAll') + }) - afterAll(async function () { - console.info(TAG + 'afterAll') - }) + beforeEach(async function () { + console.info(TAG + 'beforeEach') + rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + }) - /** - * @tc.name resultSet Update test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0010 - * @tc.desc resultSet Update test - */ - it('testRdbStoreUpdate0001', 0, async function (done) { - console.info(TAG + "************* testRdbStoreUpdate0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - //插入 - { - const valueBucket = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - let insertPromise = rdbStore.insert("test", valueBucket) - insertPromise.then(async (ret) => { - expect(1).assertEqual(ret); - console.info(TAG + "update done: " + ret); - }).catch((err) => { - expect(null).assertFail(); - }) - await insertPromise - } - //更新 - { - var u8 = new Uint8Array([4, 5, 6]) - const valueBucket = { - "name": "lisi", - "age": 20, - "salary": 200.5, - "blobType": u8, - } - let predicates = await new dataRdb.RdbPredicates("test") - predicates.equalTo("id", "1") - let updatePromise = rdbStore.update(valueBucket, predicates) - await updatePromise.then(async (ret) => { - expect(1).assertEqual(ret); - console.info(TAG + "update done: " + ret); - let resultSet = await rdbStore.query(predicates) + afterEach(async function () { + console.info(TAG + 'afterEach') + await rdbStore.executeSql("DELETE FROM test"); + rdbStore = null + await dataRdb.deleteRdbStore("UpdataTest.db"); + }) - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = await resultSet.getLong(resultSet.getColumnIndex("id")) - const name = await resultSet.getString(resultSet.getColumnIndex("name")) - const age = await resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) + afterAll(async function () { + console.info(TAG + 'afterAll') + }) - expect(1).assertEqual(id); - expect("lisi").assertEqual(name); - expect(20).assertEqual(age); - expect(200.5).assertEqual(salary); - expect(4).assertEqual(blobType[0]); - expect(5).assertEqual(blobType[1]); - expect(6).assertEqual(blobType[2]); - console.info(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(false).assertEqual(resultSet.goToNextRow()) - resultSet = null - }).catch((err) => { - console.info(TAG + "update error"); - expect(null).assertFail(); - }) - //await updatePromise - } - done(); - console.info(TAG + "************* testRdbStoreUpdate0001 end *************"); - }) - - /** - * @tc.name resultSet Update test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0020 - * @tc.desc resultSet Update test - */ - it('testRdbStoreUpdate0002', 0, async function (done) { - console.info(TAG + "************* testRdbStoreUpdate0002 start *************"); - //更新 - { - let errInfo = undefined; + /** + * @tc.name resultSet Update test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0010 + * @tc.desc resultSet Update test + */ + it('testRdbStoreUpdate0001', 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate0001 start *************"); var u8 = new Uint8Array([1, 2, 3]) - const valueBucket = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - try{ - let predicates = new dataRdb.RdbPredicates("") - let updatePromise = rdbStore.update(valueBucket, predicates) - updatePromise.then(async (ret) => { - console.info(TAG + "update done: " + ret); - expect(null).assertFail(); - }).catch((err) => { - console.info(TAG + "update with null table name"); - }) - }catch(err){ - errInfo = err - } + //插入 { - const emptyBucket = {}; - let predicates = await new dataRdb.RdbPredicates("test") - let updatePromise = rdbStore.update(emptyBucket, predicates) - updatePromise.then(async (ret) => { + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + let insertPromise = rdbStore.insert("test", valueBucket) + insertPromise.then(async (ret) => { + expect(1).assertEqual(ret); console.info(TAG + "update done: " + ret); - expect(null).assertFail(); }).catch((err) => { - console.info(TAG + "update with wrong valueBucket"); + expect(null).assertFail(); }) + await insertPromise } + //更新 { + var u8 = new Uint8Array([4, 5, 6]) + const valueBucket = { + "name": "lisi", + "age": 20, + "salary": 200.5, + "blobType": u8, + } let predicates = await new dataRdb.RdbPredicates("test") - await predicates.equalTo("aaa", "null") + predicates.equalTo("id", "1") let updatePromise = rdbStore.update(valueBucket, predicates) - updatePromise.then(async (ret) => { + await updatePromise.then(async (ret) => { + expect(1).assertEqual(ret); console.info(TAG + "update done: " + ret); - expect(null).assertFail(); - }).catch((err) => { - console.info(TAG + "update with wrong condition"); - }) - } - expect(errInfo.code).assertEqual("401") - } - done(); - console.info(TAG + "************* testRdbStoreUpdate0002 end *************"); - }) + let resultSet = await rdbStore.query(predicates) - /** - * @tc.name resultSet Update test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0030 - * @tc.desc resultSet Update test - */ - it('testRdbStoreUpdate0003', 0, async function (done) { - console.info(TAG + "************* testRdbStoreUpdate0003 start *************"); - //更新 - { - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - "wrongColumn": 100.5, - } - { - let predicates = new dataRdb.RdbPredicates("wrongTable") - let updatePromise = rdbStore.update(valueBucket, predicates) - updatePromise.then(async (ret) => { - console.info(TAG + "update done: " + ret); - expect(null).assertFail(); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = await resultSet.getLong(resultSet.getColumnIndex("id")) + const name = await resultSet.getString(resultSet.getColumnIndex("name")) + const age = await resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) + + expect(1).assertEqual(id); + expect("lisi").assertEqual(name); + expect(20).assertEqual(age); + expect(200.5).assertEqual(salary); + expect(4).assertEqual(blobType[0]); + expect(5).assertEqual(blobType[1]); + expect(6).assertEqual(blobType[2]); + console.info(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(false).assertEqual(resultSet.goToNextRow()) + resultSet = null }).catch((err) => { - console.info(TAG + "update with wrong table name"); - }) - //await updatePromise - } - { - let predicates = await new dataRdb.RdbPredicates("test") - let updatePromise = rdbStore.update(valueBucket, predicates) - updatePromise.then(async (ret) => { - console.info(TAG + "update done: " + ret); + console.info(TAG + "update error"); expect(null).assertFail(); - }).catch((err) => { - console.info(TAG + "update with wrong column name"); }) //await updatePromise } - } - done(); - console.info(TAG + "************* testRdbStoreUpdate0003 end *************"); - }) + done(); + console.info(TAG + "************* testRdbStoreUpdate0001 end *************"); + }) - /** - * @tc.name resultSet Update test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0040 - * @tc.desc resultSet Update test - */ - it('testRdbStoreUpdate0004', 0, async function (done) { - console.info(TAG + "************* testRdbStoreUpdate0004 start *************"); - //更新 - { - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, + /** + * @tc.name resultSet Update test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0020 + * @tc.desc resultSet Update test + */ + it('testRdbStoreUpdate0002', 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate0002 start *************"); + //更新 + { + let errInfo = undefined; + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + try{ + let predicates = new dataRdb.RdbPredicates("") + let updatePromise = rdbStore.update(valueBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with null table name"); + }) + }catch(err){ + errInfo = err + } + { + const emptyBucket = {}; + let predicates = await new dataRdb.RdbPredicates("test") + let updatePromise = rdbStore.update(emptyBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with wrong valueBucket"); + }) + } + { + let predicates = await new dataRdb.RdbPredicates("test") + await predicates.equalTo("aaa", "null") + let updatePromise = rdbStore.update(valueBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with wrong condition"); + }) + } + expect(errInfo.code).assertEqual("401") } + done(); + console.info(TAG + "************* testRdbStoreUpdate0002 end *************"); + }) + + /** + * @tc.name resultSet Update test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0030 + * @tc.desc resultSet Update test + */ + it('testRdbStoreUpdate0003', 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate0003 start *************"); + //更新 { - let predicates = await new dataRdb.RdbPredicates("test") - await predicates.equalTo("aaa", "null") - let updatePromise = rdbStore.update(valueBucket, predicates) - updatePromise.then(async (ret) => { - console.info(TAG + "update done: " + ret); - expect(null).assertFail(); - }).catch((err) => { - console.info(TAG + "update with wrong condition"); - }) - //await updatePromise + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + "wrongColumn": 100.5, + } + { + let predicates = new dataRdb.RdbPredicates("wrongTable") + let updatePromise = rdbStore.update(valueBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with wrong table name"); + }) + //await updatePromise + } + { + let predicates = await new dataRdb.RdbPredicates("test") + let updatePromise = rdbStore.update(valueBucket, predicates) + updatePromise.then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with wrong column name"); + }) + //await updatePromise + } } + done(); + console.info(TAG + "************* testRdbStoreUpdate0003 end *************"); + }) + + /** + * @tc.name resultSet Update test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_Update_0040 + * @tc.desc resultSet Update test + */ + it('testRdbStoreUpdate0004', 0, async function (done) { + console.info(TAG + "************* testRdbStoreUpdate0004 start *************"); + //更新 { - const emptyBucket = {}; - let predicates = await new dataRdb.RdbPredicates("test") - await predicates.equalTo("name", "zhangsan") - await predicates.equalTo("age", 18) - await predicates.equalTo("null", 100.5) - let updatePromise = rdbStore.update(valueBucket, predicates) - updatePromise.then(async (ret) => { - console.info(TAG + "update done: " + ret); - expect(null).assertFail(); - }).catch((err) => { - console.info(TAG + "update with wrong condition"); - }) + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + { + let predicates = await new dataRdb.RdbPredicates("test") + await predicates.equalTo("aaa", "null") + await rdbStore.update(valueBucket, predicates).then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.info(TAG + "update with wrong condition"); + expect(err !== null).assertTrue(); + }) + } + { + let predicates = await new dataRdb.RdbPredicates("test") + await predicates.equalTo("name", "zhangsan") + await predicates.equalTo("age", 18) + await predicates.equalTo("null", 100.5) + await rdbStore.update(valueBucket, predicates).then(async (ret) => { + console.info(TAG + "update done: " + ret); + expect(ret).assertEqual(0); + }).catch((err) => { + console.info(TAG + "update with wrong condition"); + expect(null).assertFail(); + }) + } } - } - done(); - console.info(TAG + "************* testRdbStoreUpdate0004 end *************"); + done(); + console.info(TAG + "************* testRdbStoreUpdate0004 end *************"); + }) + console.info(TAG + "*************Unit Test End*************"); }) - console.info(TAG + "*************Unit Test End*************"); -}) - + } diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreInsertJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreInsertJsunit.test.js index 6ec5d1959..759493d3a 100644 --- a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreInsertJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreInsertJsunit.test.js @@ -13,431 +13,307 @@ * limitations under the License. */ -import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' +import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' import data_Rdb from '@ohos.data.relationalStore'; import ability_featureAbility from '@ohos.ability.featureAbility' + var context = ability_featureAbility.getContext(); const TAG = "[RelationalStore_JSKITS_TEST]" const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; -const CREATE_TABLE_NAME = "CREATE TABLE IF NOT EXISTS test" +const CREATE_TABLE_NAME = "CREATE TABLE IF NOT EXISTS test" const CREATE_TABLE = " (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; const STORE_CONFIG = { name: "InsertTest.db", securityLevel: data_Rdb.SecurityLevel.S1 } -var rdbStore = undefined; -var resultSet = undefined; +let rdbStore = undefined; function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } + export default function relationalStoreInsertTest() { -describe('relationalStoreInsertTest', function () { - beforeAll(async function () { - console.info(TAG + 'beforeAll') - rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); - await rdbStore.executeSql(CREATE_TABLE_TEST, null) + describe('relationalStoreInsertTest', function () { + beforeAll(async function () { + console.info(TAG + 'beforeAll') + }) - }) + beforeEach(async function () { + console.info(TAG + 'beforeEach') + rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null) + }) - beforeEach(async function () { - console.info(TAG + 'beforeEach') - await rdbStore.executeSql("DELETE FROM test"); - }) + afterEach(async function () { + console.info(TAG + 'afterEach') + rdbStore = null + await data_Rdb.deleteRdbStore(context, "InsertTest.db") + }) - afterEach(async function () { - console.info(TAG + 'afterEach') - }) + afterAll(async function () { + console.info(TAG + 'afterAll') + }) - afterAll(async function () { - console.info(TAG + 'afterAll') - rdbStore = null - await data_Rdb.deleteRdbStore(context, "InsertTest.db").then(() => { - sleep(2) - }); - }) + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0010 + * @tc.desc RelationalStore insert test + */ + it('testRdbStoreInsert0001', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + } + { + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + } + { + const valueBucket = { + "name": "lisi", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + } + + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + await rdbStore.query(predicates).then(async (resultSet) => { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + expect(false).assertEqual(resultSet.goToNextRow()) + done(); + console.info(TAG + "************* testRdbStoreInsert0001 end *************"); + resultSet.close(); + resultSet = null; + }).catch((err) => { + console.info("insert1 error " + err); + expect().assertFail(); + done(); + }) + }) + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0020 + * @tc.desc RelationalStore insert test + */ + it('testRdbStoreInsert0002', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0002 start *************"); + let u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("wrong", valueBucket).then(async (ret) => { + console.info(TAG + "insert first done: " + ret) + expect().assertFail(); + done(); + }).catch((err) => { + console.info(TAG + "insert with wrong table") + expect(err !== null).assertTrue(); + done(); + console.info(TAG + "************* testRdbStoreInsert0002 end *************"); + }) + } + }) - console.info(TAG + "*************Unit Test Begin*************"); + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0030 + * @tc.desc RelationalStore insert test + */ + it('testRdbStoreInsert0003', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0003 start *************"); + let u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + try { + await rdbStore.insert(null, valueBucket).then(()=>{ + console.log("insert done"); + expect().assertFail(); + done(); + }).catch((error) => { + console.log("insert error" + error); + expect().assertFail(); + done(); + }) + } catch (err) { + console.log(`insert failed, code is ${err.code},message is ${err.message}`); + expect(err.code).assertEqual('401'); + done(); + console.info(TAG + "************* testRdbStoreInsert0003 end *************"); + } + } + }) - /** - * @tc.name RelationalStore insert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0010 - * @tc.desc RelationalStore insert test - */ - it('testRdbStoreInsert0001', 0, async function (done) { - console.info(TAG + "************* testRdbStoreInsert0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - { + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0040 + * @tc.desc RelationalStore insert test + */ + it('testRdbStoreInsert0004', 0, async function (done) { + console.log(TAG + "************* testRdbStoreInsert0004 start *************"); + let u8 = new Uint8Array([1, 2, 3]) const valueBucket = { "name": "zhangsan", "age": 18, - "salary": 100.5, + "salary": null, "blobType": u8, } - await rdbStore.insert("test", valueBucket) - } - { - const valueBucket = { - "name": "lisi", + await rdbStore.insert("test", valueBucket).then(async (ret) => { + expect(1).assertEqual(ret); + console.log(TAG + "insert first done: " + ret); + done(); + console.log(TAG + "************* testRdbStoreInsert0004 end *************"); + }).catch((err) => { + console.log(TAG + "insert with null table" + err); + expect().assertFail(); + done(); + }) + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0010 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0001', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0001 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "1" + CREATE_TABLE) + let u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", "age": 18, "salary": 100.5, "blobType": u8, } - await rdbStore.insert("test", valueBucket) - } - { - const valueBucket = { + const valueBucket2 = { "name": "lisi", - "age": 20, - "salary": 100.5, + "age": 23, + "salary": 200, "blobType": u8, } - await rdbStore.insert("test", valueBucket) - } - - let predicates = new data_Rdb.RdbPredicates("test"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(1).assertEqual(id); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("insert1 error " + e); - } - resultSet.close(); - done() - console.info(TAG + "************* testRdbStoreInsert0001 end *************"); - }) - - /** - * @tc.name RelationalStore insert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0020 - * @tc.desc RelationalStore insert test - */ - it('testRdbStoreInsert0002', 0, async function (done) { - console.info(TAG + "************* testRdbStoreInsert0002 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - { - const valueBucket = { - "name": "zhangsan", - "age": 18, + const valueBucket3 = { + "name": "wangwu", + "age": 20, "salary": 100.5, "blobType": u8, } - let insertPromise = rdbStore.insert("wrong", valueBucket) - insertPromise.then(async (ret) => { - expect(1).assertEqual(ret) - console.info(TAG + "insert first done: " + ret) - expect(null).assertFail() + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.batchInsert("test1", valueBuckets).then((number) => { + console.info(TAG + "batchInsert number = " + number); + expect(3).assertEqual(number); }).catch((err) => { - console.info(TAG + "insert with wrong table") + console.info(TAG + "batchInsert fail = " + err); + expect().assertFail(); }) - } - done() - console.info(TAG + "************* testRdbStoreInsert0002 end *************"); - }) - /** - * @tc.name RelationalStore insert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0030 - * @tc.desc RelationalStore insert test - */ - it('testRdbStoreInsert0003', 0, async function (done) { - console.info(TAG + "************* testRdbStoreInsert0003 start *************"); - let errInfo = undefined; - var u8 = new Uint8Array([1, 2, 3]) - { - const valueBucket = { + let predicates = new data_Rdb.RdbPredicates("test1"); + predicates.equalTo("name", "zhangsan") + await rdbStore.query(predicates).then((resultSet) => { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + expect(false).assertEqual(resultSet.goToNextRow()) + done(); + console.info(TAG + "************* testRdbStorebatchInsertPromise0001 end *************"); + resultSet.close(); + resultSet = null; + }).catch((err) => { + console.error(`Updated failed, err is ${err}`); + expect().assertFail(); + done(); + }) + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0020 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0002', 0, async function (done) { + await rdbStore.executeSql(CREATE_TABLE_NAME + "2" + CREATE_TABLE) + console.info(TAG + "************* testRdbStorebatchInsertPromise0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { "name": "zhangsan", "age": 18, "salary": 100.5, "blobType": u8, } - try{ - rdbStore.insert(null, valueBucket) - }catch(err){ - errInfo = err + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, } - expect(errInfo.code).assertEqual("401") - } - done() - console.info(TAG + "************* testRdbStoreInsert0003 end *************"); - }) - - /** - * @tc.name RelationalStore insert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Insert_0040 - * @tc.desc RelationalStore insert test - */ - it('testRdbStoreInsert0004', 0, async function (done) { - console.log(TAG + "************* testRdbStoreInsert0004 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket = { - "name": "zhangsan", - "age": 18, - "salary": null, - "blobType": u8, - } - let insertPromise = rdbStore.insert("test", valueBucket) - insertPromise.then(async (ret) => { - expect(1).assertEqual(ret) - console.log(TAG + "insert first done: " + ret) - }).catch((err) => { - console.log(TAG + "insert with null table") - expect(null).assertFail() - }) - done(); - console.log(TAG + "************* testRdbStoreInsert0004 end *************"); - }) - - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0010 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertPromise0001', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertPromise0001 start *************"); - await rdbStore.executeSql(CREATE_TABLE_NAME + "1" + CREATE_TABLE) - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.batchInsert("test1", valueBuckets).then((number) => { - expect(3).assertEqual(number) - }).catch((err) =>{ - expect(false).assertTrue(); - }) - - let predicates = new data_Rdb.RdbPredicates("test1"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(1).assertEqual(id); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - resultSet.close(); - predicates = new data_Rdb.RdbPredicates("test1"); - predicates.equalTo("name", "lisi") - resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - resultSet.close(); - done() - console.info(TAG + "************* testRdbStorebatchInsertPromise0001 end *************"); - }) - - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0020 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertPromise0002', 0, async function (done) { - await rdbStore.executeSql(CREATE_TABLE_NAME + "2" + CREATE_TABLE) - console.info(TAG + "************* testRdbStorebatchInsertPromise0002 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.batchInsert("test2", valueBuckets).then((number) => { - expect(3).assertEqual(number) - }).catch((err) =>{ - expect(false).assertTrue(); - }) - let predicates = new data_Rdb.RdbPredicates("test2"); - predicates.equalTo("name", "lisi") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - resultSet.close(); - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - await rdbStore.delete(predicates).then((number) => { - expect(1).assertEqual(number) - }).then(async () => { - resultSet = await rdbStore.query(predicates).catch((err) =>{ - expect(err != null).assertTrue(); - }) - resultSet.close(); - }) - } catch (e) { - console.info("BatchInsert2 error " + e); - } - done() - console.info(TAG + "************* testRdbStorebatchInsertPromise0002 end *************"); - }) - - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0030 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertPromise0003', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertPromise0003 start *************"); - await rdbStore.executeSql(CREATE_TABLE_NAME + "3" + CREATE_TABLE) - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.batchInsert("test3", valueBuckets).then((number) => { - expect(3).assertEqual(number) - }).catch((err) =>{ - expect(false).assertTrue(); - }) - - let predicates = new data_Rdb.RdbPredicates("test3"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - resultSet.close(); - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(1).assertEqual(id); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - predicates = new data_Rdb.RdbPredicates("test3"); - predicates.equalTo("name", "lisi") - resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - resultSet.close(); - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - const valueBucket4 = { - "name": "zhangmaowen", - "age": 25, - "salary": 500, + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, "blobType": u8, } - await rdbStore.insert("test3",valueBucket4) - predicates = new data_Rdb.RdbPredicates("test3"); - predicates.equalTo("name", "zhangmaowen") - resultSet = await rdbStore.query(predicates) + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.batchInsert("test2", valueBuckets).then((number) => { + expect(3).assertEqual(number) + }).catch((err) => { + expect(false).assertTrue(); + }) + let predicates = new data_Rdb.RdbPredicates("test2"); + predicates.equalTo("name", "lisi") + let resultSet = await rdbStore.query(predicates) try { console.info(TAG + "resultSet query done"); expect(true).assertEqual(resultSet.goToFirstRow()) @@ -445,83 +321,36 @@ describe('relationalStoreInsertTest', function () { const name = resultSet.getString(resultSet.getColumnIndex("name")) const age = resultSet.getLong(resultSet.getColumnIndex("age")) const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) resultSet.close(); console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(4).assertEqual(id); - expect("zhangmaowen").assertEqual(name) - expect(25).assertEqual(age) - expect(500).assertEqual(salary) + expect(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + await rdbStore.delete(predicates).then((number) => { + expect(1).assertEqual(number) + }).then(async () => { + resultSet = await rdbStore.query(predicates).catch((err) => { + expect(err != null).assertTrue(); + }) + resultSet.close(); + }) } catch (e) { - console.info("BatchInsert1 error " + e); + console.info("BatchInsert2 error " + e); } - } catch (e) { - console.info("BatchInsert1 error " + e); - } - done(); - console.info(TAG + "************* testRdbStorebatchInsertPromise0003 end *************"); - }) - - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0040 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertPromise0004', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertPromise0004 start *************"); - await rdbStore.executeSql(CREATE_TABLE_NAME + "4" + CREATE_TABLE) - var u8 = new Uint8Array([1, 2, 3]) - var valueBuckets = new Array(100); - for(var i=0;i { - console.info(TAG + "Batch insert data end") - expect(100).assertEqual(number) - }).catch((err) =>{ - expect(false).assertTrue(); + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0002 end *************"); }) - let predicates = new data_Rdb.RdbPredicates("test4"); - predicates.equalTo("name", "zhangsan55") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - resultSet.close(); - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(56).assertEqual(id); - expect("zhangsan55").assertEqual(name) - expect(55).assertEqual(age) - expect(56).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - done() - console.info(TAG + "************* testRdbStorebatchInsertPromise0004 end *************"); - }) - - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0050 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertPromise0005', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertPromise0005 start *************"); - await rdbStore.executeSql(CREATE_TABLE_NAME + "5" + CREATE_TABLE) + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0030 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0003', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0003 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "3" + CREATE_TABLE) var u8 = new Uint8Array([1, 2, 3]) const valueBucket1 = { "name": "zhangsan", @@ -530,348 +359,333 @@ describe('relationalStoreInsertTest', function () { "blobType": u8, } const valueBucket2 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, + "name": "lisi", + "age": 23, + "salary": 200, "blobType": u8, } const valueBucket3 = { - "name": "zhangsan", - "age": 18, + "name": "wangwu", + "age": 20, "salary": 100.5, "blobType": u8, } const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.batchInsert("test5", valueBuckets).then((number) => { + await rdbStore.batchInsert("test3", valueBuckets).then((number) => { expect(3).assertEqual(number) - }).catch((err) =>{ + }).catch((err) => { expect(false).assertTrue(); }) - - let predicates = new data_Rdb.RdbPredicates("test5"); + + let predicates = new data_Rdb.RdbPredicates("test3"); predicates.equalTo("name", "zhangsan") let resultSet = await rdbStore.query(predicates) try { console.info(TAG + "resultSet query done"); expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) const name = resultSet.getString(resultSet.getColumnIndex("name")) const age = resultSet.getLong(resultSet.getColumnIndex("age")) const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + " name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + resultSet.close(); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); expect("zhangsan").assertEqual(name) expect(18).assertEqual(age) expect(100.5).assertEqual(salary) expect(1).assertEqual(blobType[0]) expect(2).assertEqual(blobType[1]) expect(3).assertEqual(blobType[2]) - expect(true).assertEqual(resultSet.goToNextRow()) } catch (e) { console.info("BatchInsert1 error " + e); } - resultSet.close(); - done(); - console.info(TAG + "************* testRdbStorebatchInsertPromise0005 end *************"); - }) - - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0060 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertPromise0006', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertPromise0006 start *************"); - await rdbStore.executeSql(CREATE_TABLE_NAME + "6" + CREATE_TABLE) - let errInfo = undefined; - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - try{ - await rdbStore.batchInsert("test6","valueBuckets") - }catch(err){ - console.info(TAG + "Batch insert data error: " + err) - errInfo = err - } - expect(errInfo.code).assertEqual("401") - done() - console.info(TAG + "************* testRdbStorebatchInsertPromise0006 end *************"); - }) - - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0070 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertPromise0007', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertPromise0007 start *************"); - let errInfo = undefined; - await rdbStore.executeSql(CREATE_TABLE_NAME + "7" + CREATE_TABLE) - try{ - await rdbStore.batchInsert("test7") - }catch(err){ - console.info(TAG + "Batch insert data error: " + err) - errInfo = err - } - expect(errInfo.code).assertEqual("401") - done() - console.info(TAG + "************* testRdbStorebatchInsertPromise0007 end *************"); - }) - - - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0100 - * @tc.desc RelationalStore insert test - * zheg s - */ - it('testRdbStorebatchInsertCallback0001', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.executeSql(CREATE_TABLE_NAME + "callback1" + CREATE_TABLE).then(async () => { - console.info(TAG + "Batch insert data start") - await rdbStore.batchInsert("testcallback1", valueBuckets, async (err, data) => { - if(err != null){ - expect(false).assertTrue(); - }else{ - console.info(TAG + "Batch insert data end") - expect(3).assertEqual(data) - let predicates = new data_Rdb.RdbPredicates("testcallback1"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(1).assertEqual(id); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - resultSet.close(); - predicates = new data_Rdb.RdbPredicates("testcallback1"); - predicates.equalTo("name", "lisi") - resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("BatchInsert1 error " + e); - } + predicates = new data_Rdb.RdbPredicates("test3"); + predicates.equalTo("name", "lisi") + resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + resultSet.close(); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + const valueBucket4 = { + "name": "zhangmaowen", + "age": 25, + "salary": 500, + "blobType": u8, + } + await rdbStore.insert("test3", valueBucket4) + predicates = new data_Rdb.RdbPredicates("test3"); + predicates.equalTo("name", "zhangmaowen") + resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) resultSet.close(); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(4).assertEqual(id); + expect("zhangmaowen").assertEqual(name) + expect(25).assertEqual(age) + expect(500).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); } - done(); - }) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + done(); + console.info(TAG + "************* testRdbStorebatchInsertPromise0003 end *************"); }) - await sleep(2000) - done() - console.info(TAG + "************* testRdbStorebatchInsertCallback0001 end *************"); - }) - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0200 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertCallback0002', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0002 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback2" + CREATE_TABLE).then(async () => { - await rdbStore.batchInsert("testCallback2", valueBuckets, async (err, data) => { - if(err != null){ - expect(false).assertTrue(); - }else{ - expect(3).assertEqual(data) - let predicates = new data_Rdb.RdbPredicates("testCallback2"); - predicates.equalTo("name", "lisi") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - resultSet.close(); - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - await rdbStore.delete(predicates).then((number) => { - expect(1).assertEqual(number) - }).then(async () => { - resultSet = await rdbStore.query(predicates).catch((err) =>{ - expect(err != null).assertTrue(); - }) - resultSet.close(); - }) - } catch (e) { - console.info("BatchInsert2 error " + e); - } - } - done(); + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0040 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0004', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0004 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "4" + CREATE_TABLE) + var u8 = new Uint8Array([1, 2, 3]) + var valueBuckets = new Array(100); + for (var i = 0;i < valueBuckets.length; i++) { + valueBuckets[i] = { + "name": "zhangsan" + i, + "age": i, + "salary": 1 + i, + "blobType": u8, + }; + } + console.info(TAG + "Batch insert data start") + await rdbStore.batchInsert("test4", valueBuckets).then((number) => { + console.info(TAG + "Batch insert data end") + expect(100).assertEqual(number) + }).catch((err) => { + expect(false).assertTrue(); }) + + let predicates = new data_Rdb.RdbPredicates("test4"); + predicates.equalTo("name", "zhangsan55") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + resultSet.close(); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(56).assertEqual(id); + expect("zhangsan55").assertEqual(name) + expect(55).assertEqual(age) + expect(56).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0004 end *************"); }) - await sleep(2000) - done() - console.info(TAG + "************* testRdbStorebatchInsertCallback0002 end *************"); - }) - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0300 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertCallback0003', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0003 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback3" + CREATE_TABLE).then(async () =>{ - await rdbStore.batchInsert("testCallback3", valueBuckets, async (err, data) => { - if(err != null){ - expect(false).assertTrue() - }else{ - expect(3).assertEqual(data) - let predicates = new data_Rdb.RdbPredicates("testCallback3"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - resultSet.close(); - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); - expect(1).assertEqual(id); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - } catch (e) { - console.info("BatchInsert1 error " + e); - } - predicates = new data_Rdb.RdbPredicates("testCallback3"); - predicates.equalTo("name", "lisi") - resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - resultSet.close(); - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); - expect(2).assertEqual(id); - expect("lisi").assertEqual(name) - expect(23).assertEqual(age) - expect(200).assertEqual(salary) - const valueBucket4 = { - "name": "zhangmaowen", - "age": 25, - "salary": 500, - "blobType": u8, + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0050 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0005', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0005 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "5" + CREATE_TABLE) + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket3 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.batchInsert("test5", valueBuckets).then((number) => { + expect(3).assertEqual(number) + }).catch((err) => { + expect(false).assertTrue(); + }) + + let predicates = new data_Rdb.RdbPredicates("test5"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + " name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + expect(true).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + resultSet.close(); + done(); + console.info(TAG + "************* testRdbStorebatchInsertPromise0005 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0060 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0006', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0006 start *************"); + await rdbStore.executeSql(CREATE_TABLE_NAME + "6" + CREATE_TABLE) + let errInfo = undefined; + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + try { + await rdbStore.batchInsert("test6", "valueBuckets") + } catch (err) { + console.info(TAG + "Batch insert data error: " + err) + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0006 end *************"); + }) + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Promise_0070 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertPromise0007', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertPromise0007 start *************"); + let errInfo = undefined; + await rdbStore.executeSql(CREATE_TABLE_NAME + "7" + CREATE_TABLE) + try { + await rdbStore.batchInsert("test7") + } catch (err) { + console.info(TAG + "Batch insert data error: " + err) + errInfo = err + } + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertPromise0007 end *************"); + }) + + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0100 + * @tc.desc RelationalStore insert test + * zheg s + */ + it('testRdbStorebatchInsertCallback0001', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "callback1" + CREATE_TABLE).then(async () => { + console.info(TAG + "Batch insert data start") + await rdbStore.batchInsert("testcallback1", valueBuckets, async (err, data) => { + if (err != null) { + expect(false).assertTrue(); + } else { + console.info(TAG + "Batch insert data end") + expect(3).assertEqual(data) + let predicates = new data_Rdb.RdbPredicates("testcallback1"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + expect(false).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); } - await rdbStore.insert("testCallback3",valueBucket4) - predicates = new data_Rdb.RdbPredicates("testCallback3"); - predicates.equalTo("name", "zhangmaowen") + resultSet.close(); + predicates = new data_Rdb.RdbPredicates("testcallback1"); + predicates.equalTo("name", "lisi") resultSet = await rdbStore.query(predicates) try { console.info(TAG + "resultSet query done"); @@ -880,469 +694,644 @@ describe('relationalStoreInsertTest', function () { const name = resultSet.getString(resultSet.getColumnIndex("name")) const age = resultSet.getLong(resultSet.getColumnIndex("age")) const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - resultSet.close(); - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); - expect(4).assertEqual(id); - expect("zhangmaowen").assertEqual(name) - expect(25).assertEqual(age) - expect(500).assertEqual(salary) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + expect(false).assertEqual(resultSet.goToNextRow()) } catch (e) { console.info("BatchInsert1 error " + e); } - } catch (e) { - console.info("BatchInsert1 error " + e); + resultSet.close(); } - } - done(); + done(); + }) }) + await sleep(2000) + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0001 end *************"); }) - await sleep(2000) - done(); - console.info(TAG + "************* testRdbStorebatchInsertCallback0003 end *************"); - }) - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0400 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertCallback0004', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0004 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - var valueBuckets = new Array(100); - for(var i=0;i { - await rdbStore.batchInsert("testCallbak4", valueBuckets, async (err, data) => { - if(err != null){ - expect(false).assertTrue(); - }else{ - console.info(TAG + "Batch insert data end") - expect(100).assertEqual(data) - let predicates = new data_Rdb.RdbPredicates("testCallbak4"); - predicates.equalTo("name", "zhangsan55") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - resultSet.close(); - console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); - expect(56).assertEqual(id); - expect("zhangsan55").assertEqual(name) - expect(55).assertEqual(age) - expect(56).assertEqual(salary) - } catch (e) { - console.info("BatchInsert1 error " + e); + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback2" + CREATE_TABLE).then(async () => { + await rdbStore.batchInsert("testCallback2", valueBuckets, async (err, data) => { + if (err != null) { + expect(false).assertTrue(); + } else { + expect(3).assertEqual(data) + let predicates = new data_Rdb.RdbPredicates("testCallback2"); + predicates.equalTo("name", "lisi") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + resultSet.close(); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + await rdbStore.delete(predicates).then((number) => { + expect(1).assertEqual(number) + }).then(async () => { + resultSet = await rdbStore.query(predicates).catch((err) => { + expect(err != null).assertTrue(); + }) + resultSet.close(); + }) + } catch (e) { + console.info("BatchInsert2 error " + e); + } } - } - done(); + done(); + }) }) + await sleep(2000) + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0002 end *************"); }) - await sleep(2000) - done() - console.info(TAG + "************* testRdbStorebatchInsertCallback0004 end *************"); - }) - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0500 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertCallback0005', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0005 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket3 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback5" + CREATE_TABLE).then(async () => { - await rdbStore.batchInsert("testCallback5", valueBuckets, async (err, number) => { - if(err != null){ - expect(false).assertTrue(); - }else{ - expect(3).assertEqual(number) - let predicates = new data_Rdb.RdbPredicates("testCallback5"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.info(TAG + "resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.info(TAG + " name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(100.5).assertEqual(salary) - expect(1).assertEqual(blobType[0]) - expect(2).assertEqual(blobType[1]) - expect(3).assertEqual(blobType[2]) - expect(true).assertEqual(resultSet.goToNextRow()) - } catch (e) { - console.info("BatchInsert1 error " + e); + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0300 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertCallback0003', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0003 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback3" + CREATE_TABLE).then(async () => { + await rdbStore.batchInsert("testCallback3", valueBuckets, async (err, data) => { + if (err != null) { + expect(false).assertTrue() + } else { + expect(3).assertEqual(data) + let predicates = new data_Rdb.RdbPredicates("testCallback3"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + resultSet.close(); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + predicates = new data_Rdb.RdbPredicates("testCallback3"); + predicates.equalTo("name", "lisi") + resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + resultSet.close(); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); + expect(2).assertEqual(id); + expect("lisi").assertEqual(name) + expect(23).assertEqual(age) + expect(200).assertEqual(salary) + const valueBucket4 = { + "name": "zhangmaowen", + "age": 25, + "salary": 500, + "blobType": u8, + } + await rdbStore.insert("testCallback3", valueBucket4) + predicates = new data_Rdb.RdbPredicates("testCallback3"); + predicates.equalTo("name", "zhangmaowen") + resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + resultSet.close(); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); + expect(4).assertEqual(id); + expect("zhangmaowen").assertEqual(name) + expect(25).assertEqual(age) + expect(500).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + } catch (e) { + console.info("BatchInsert1 error " + e); + } } - resultSet.close(); - } - done(); + done(); + }) }) + await sleep(2000) + done(); + console.info(TAG + "************* testRdbStorebatchInsertCallback0003 end *************"); }) - await sleep(2000) - done(); - console.info(TAG + "************* testRdbStorebatchInsertCallback0005 end *************"); - }) - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0600 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertCallback0006', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0006 start *************"); - let errInfo = undefined; - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket1 = { - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - const valueBucket2 = { - "name": "lisi", - "age": 23, - "salary": 200, - "blobType": u8, - } - const valueBucket3 = { - "name": "wangwu", - "age": 20, - "salary": 100.5, - "blobType": u8, - } - const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] - await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback6" + CREATE_TABLE).then(async () => { - try{ - rdbStore.batchInsert("testCallback6", "valueBuckets", (err, data) => { - console.info(TAG + "Affect row is " + data) - if(err != null){ - expect(null).assertFail(); - }else{ - expect(data).assertEqual(-1) - } - }) - }catch(err){ - console.info(TAG + "Batch insert data error: " + err) - errInfo = err + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0400 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertCallback0004', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0004 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + var valueBuckets = new Array(100); + for (var i = 0;i < valueBuckets.length; i++) { + valueBuckets[i] = { + "name": "zhangsan" + i, + "age": i, + "salary": 1 + i, + "blobType": u8, + }; } - }) - expect(errInfo.code).assertEqual("401") - done() - console.info(TAG + "************* testRdbStorebatchInsertCallback0006 end *************"); - }) - - - /** - * @tc.name RelationalStore batchInsert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0700 - * @tc.desc RelationalStore insert test - */ - it('testRdbStorebatchInsertCallback0007', 0, async function (done) { - console.info(TAG + "************* testRdbStorebatchInsertCallback0007 start *************"); - let errInfo = undefined; - await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback7" + CREATE_TABLE).then(async () => { - try{ - await rdbStore.batchInsert("testCallback7", (err,data) => { - console.info(TAG + "Affect row is " + data) - if(err != null){ - expect(null).assertFail(); - }else{ - expect(data).assertEqual(-1) + console.info(TAG + "Batch insert data start") + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callbak4" + CREATE_TABLE).then(async () => { + await rdbStore.batchInsert("testCallbak4", valueBuckets, async (err, data) => { + if (err != null) { + expect(false).assertTrue(); + } else { + console.info(TAG + "Batch insert data end") + expect(100).assertEqual(data) + let predicates = new data_Rdb.RdbPredicates("testCallbak4"); + predicates.equalTo("name", "zhangsan55") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + resultSet.close(); + console.info(TAG + "id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary); + expect(56).assertEqual(id); + expect("zhangsan55").assertEqual(name) + expect(55).assertEqual(age) + expect(56).assertEqual(salary) + } catch (e) { + console.info("BatchInsert1 error " + e); + } } + done(); }) - }catch(err){ - errInfo = err - } - }).catch((err) => { - expect(null).assertFail(); + }) + await sleep(2000) + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0004 end *************"); }) - expect(errInfo.code).assertEqual("401") - done() - console.info(TAG + "************* testRdbStorebatchInsertCallback0007 end *************"); - }) - /** - * @tc.name rdb inserttWithConflictResolution test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0001 - * @tc.desc rdb insertWithConflictResolution test - */ - it('InsertWithConflictResolution0001', 0, async function (done) { - console.log(TAG + " ************* InsertWithConflictResolution0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - { - const valueBucket = { - "id": 1, + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0500 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertCallback0005', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0005 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket2 = { + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + const valueBucket3 = { "name": "zhangsan", "age": 18, "salary": 100.5, "blobType": u8, } - await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_NONE); - } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback5" + CREATE_TABLE).then(async () => { + await rdbStore.batchInsert("testCallback5", valueBuckets, async (err, number) => { + if (err != null) { + expect(false).assertTrue(); + } else { + expect(3).assertEqual(number) + let predicates = new data_Rdb.RdbPredicates("testCallback5"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.info(TAG + "resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.info(TAG + " name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(100.5).assertEqual(salary) + expect(1).assertEqual(blobType[0]) + expect(2).assertEqual(blobType[1]) + expect(3).assertEqual(blobType[2]) + expect(true).assertEqual(resultSet.goToNextRow()) + } catch (e) { + console.info("BatchInsert1 error " + e); + } + resultSet.close(); + } + done(); + }) + }) + await sleep(2000) + done(); + console.info(TAG + "************* testRdbStorebatchInsertCallback0005 end *************"); + }) - { - const valueBucket = { - "id": 1, + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0600 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertCallback0006', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0006 start *************"); + let errInfo = undefined; + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { "name": "zhangsan", "age": 18, - "salary": 200.5, + "salary": 100.5, "blobType": u8, } - try { - let insertPromise = rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_NONE); - insertPromise.then(async (ret) => { - expect(1).assertEqual(ret); - console.log(TAG + " InsertWithConflictResolution0001 insert first done: " + ret); + const valueBucket2 = { + "name": "lisi", + "age": 23, + "salary": 200, + "blobType": u8, + } + const valueBucket3 = { + "name": "wangwu", + "age": 20, + "salary": 100.5, + "blobType": u8, + } + const valueBuckets = [valueBucket1, valueBucket2, valueBucket3] + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback6" + CREATE_TABLE).then(async () => { + try { + rdbStore.batchInsert("testCallback6", "valueBuckets", (err, data) => { + console.info(TAG + "Affect row is " + data) + if (err != null) { + expect(null).assertFail(); + } else { + expect(data).assertEqual(-1) + } + }) + } catch (err) { + console.info(TAG + "Batch insert data error: " + err) + errInfo = err + } + }) + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0006 end *************"); + }) + + + /** + * @tc.name RelationalStore batchInsert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_BatchInsert_Callback_0700 + * @tc.desc RelationalStore insert test + */ + it('testRdbStorebatchInsertCallback0007', 0, async function (done) { + console.info(TAG + "************* testRdbStorebatchInsertCallback0007 start *************"); + let errInfo = undefined; + await rdbStore.executeSql(CREATE_TABLE_NAME + "Callback7" + CREATE_TABLE).then(async () => { + try { + await rdbStore.batchInsert("testCallback7", (err, data) => { + console.info(TAG + "Affect row is " + data) + if (err != null) { + expect(null).assertFail(); + } else { + expect(data).assertEqual(-1) + } + }) + } catch (err) { + errInfo = err + } + }).catch((err) => { + expect(null).assertFail(); + }) + expect(errInfo.code).assertEqual("401") + done() + console.info(TAG + "************* testRdbStorebatchInsertCallback0007 end *************"); + }) + + /** + * @tc.name rdb inserttWithConflictResolution test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0001 + * @tc.desc rdb insertWithConflictResolution test + */ + it('InsertWithConflictResolution0001', 0, async function (done) { + console.log(TAG + " ************* InsertWithConflictResolution0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "id": 1, + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_NONE); + } + + { + const valueBucket = { + "id": 1, + "name": "zhangsan", + "age": 18, + "salary": 200.5, + "blobType": u8, + } + try { + let insertPromise = rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_NONE); + insertPromise.then(async (ret) => { + expect(1).assertEqual(ret); + console.log(TAG + " InsertWithConflictResolution0001 insert first done: " + ret); + expect(null).assertFail(); + }).catch((err) => { + console.log(TAG + " InsertWithConflictResolution0001 insert with wrong valuebucket and ConflictResolution is default") + done(); + }) + } catch (err) { + console.log(TAG + " InsertWithConflictResolution0001 catch err: failed, err: code=" + err.code + " message=" + err.message) + expect("401").assertEqual(err.code); expect(null).assertFail(); - }).catch((err) => { - console.log(TAG + " InsertWithConflictResolution0001 insert with wrong valuebucket and ConflictResolution is default") - done(); - }) - } catch(err) { - console.log(TAG + " InsertWithConflictResolution0001 catch err: failed, err: code=" + err.code + " message=" + err.message) - expect("401").assertEqual(err.code); - expect(null).assertFail(); + } } - } - console.log(TAG + " ************* InsertWithConflictResolution_0001 end *************"); - }) + console.log(TAG + " ************* InsertWithConflictResolution_0001 end *************"); + }) - /** - * @tc.name rdb inserttWithConflictResolution test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0002 - * @tc.desc rdb insertWithConflictResolution test - */ - it('InsertWithConflictResolution0002', 0, async function (done) { - console.log(TAG + " ************* InsertWithConflictResolution0002 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - { - const valueBucket = { - "id": 1, - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, + /** + * @tc.name rdb inserttWithConflictResolution test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0002 + * @tc.desc rdb insertWithConflictResolution test + */ + it('InsertWithConflictResolution0002', 0, async function (done) { + console.log(TAG + " ************* InsertWithConflictResolution0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "id": 1, + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK); } - await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK); - } - { - const valueBucket = { - "id": 1, - "name": "zhangsan", - "age": 18, - "salary": 200.5, - "blobType": u8, - } - try { - let insertPromise = rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK); - insertPromise.then(async (ret) => { - expect(1).assertEqual(ret) - console.log(TAG + " InsertWithConflictResolution0002 insert first done: " + ret) + { + const valueBucket = { + "id": 1, + "name": "zhangsan", + "age": 18, + "salary": 200.5, + "blobType": u8, + } + try { + let insertPromise = rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK); + insertPromise.then(async (ret) => { + expect(1).assertEqual(ret) + console.log(TAG + " InsertWithConflictResolution0002 insert first done: " + ret) + expect(null).assertFail() + }).catch((err) => { + console.log(TAG + " InsertWithConflictResolution0002 insert with wrong valuebucket and ConflictResolution is ON_CONFLICT_ROLLBACK") + done() + }) + } catch (err) { + console.log(TAG + " InsertWithConflictResolution0002 catch err: failed, err: code=" + err.code + " message=" + err.message) + expect("401").assertEqual(err.code) expect(null).assertFail() - }).catch((err) => { - console.log(TAG + " InsertWithConflictResolution0002 insert with wrong valuebucket and ConflictResolution is ON_CONFLICT_ROLLBACK") - done() - }) - } catch(err) { - console.log(TAG + " InsertWithConflictResolution0002 catch err: failed, err: code=" + err.code + " message=" + err.message) - expect("401").assertEqual(err.code) - expect(null).assertFail() + } } - } - console.log(TAG + " ************* InsertWithConflictResolution_0002 end *************"); - }) + console.log(TAG + " ************* InsertWithConflictResolution_0002 end *************"); + }) - /** - * @tc.name rdb inserttWithConflictResolution test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0003 - * @tc.desc rdb insertWithConflictResolution test - */ - it('InsertWithConflictResolution0003', 0, async function (done) { - console.log(TAG + " ************* InsertWithConflictResolution0003 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - { - const valueBucket = { - "id": 1, - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, + /** + * @tc.name rdb inserttWithConflictResolution test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0003 + * @tc.desc rdb insertWithConflictResolution test + */ + it('InsertWithConflictResolution0003', 0, async function (done) { + console.log(TAG + " ************* InsertWithConflictResolution0003 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + { + const valueBucket = { + "id": 1, + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_IGNORE); } - await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_IGNORE); - } - { - const valueBucket = { - "id": 1, - "name": "zhangsan", - "age": 18, - "salary": 200.5, - "blobType": u8, + { + const valueBucket = { + "id": 1, + "name": "zhangsan", + "age": 18, + "salary": 200.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_IGNORE); } - await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_IGNORE); - } - let predicates = new data_Rdb.RdbPredicates("test"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.log(TAG + " InsertWithConflictResolution0003 resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - console.log(TAG + " InsertWithConflictResolution0004 id=" + id + ", salary=" + salary ); - expect(1).assertEqual(id); - expect(100.5).assertEqual(salary) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (err) { - console.log(TAG + " InsertWithConflictResolution0003 insert error" + err); - } - resultSet.close(); - done() - console.log(TAG + " ************* InsertWithConflictResolution_0003 end *************"); - }) - - /** - * @tc.name rdb inserttWithConflictResolution test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0004 - * @tc.desc rdb insertWithConflictResolution test - */ - it('InsertWithConflictResolution0004', 0, async function (done) { - console.log(TAG + " ************* InsertWithConflictResolution0004 start *************"); - { - var u8 = new Uint8Array([1, 2, 3]) - const valueBucket = { - "id": 1, - "name": "zhangsan", - "age": 18, - "salary": 100.5, - "blobType": u8, + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.log(TAG + " InsertWithConflictResolution0003 resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + console.log(TAG + " InsertWithConflictResolution0004 id=" + id + ", salary=" + salary); + expect(1).assertEqual(id); + expect(100.5).assertEqual(salary) + expect(false).assertEqual(resultSet.goToNextRow()) + } catch (err) { + console.log(TAG + " InsertWithConflictResolution0003 insert error" + err); } - await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_REPLACE); - } - let predicates = new data_Rdb.RdbPredicates("test"); - predicates.equalTo("name", "zhangsan") - let resultSet = await rdbStore.query(predicates) - try { - console.log(TAG + " InsertWithConflictResolution0004 resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - expect(1).assertEqual(id); - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (err) { - console.log(TAG + " InsertWithConflictResolution0004 insert error" + err); - } - resultSet.close(); + resultSet.close(); + done() + console.log(TAG + " ************* InsertWithConflictResolution_0003 end *************"); + }) - { - var u8 = new Uint8Array([4, 5, 6]) - const valueBucket = { - "id": 1, - "name": "zhangsan", - "age": 18, - "salary": 200.5, - "blobType": u8, + /** + * @tc.name rdb inserttWithConflictResolution test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0004 + * @tc.desc rdb insertWithConflictResolution test + */ + it('InsertWithConflictResolution0004', 0, async function (done) { + console.log(TAG + " ************* InsertWithConflictResolution0004 start *************"); + { + var u8 = new Uint8Array([1, 2, 3]) + const valueBucket = { + "id": 1, + "name": "zhangsan", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_REPLACE); } - await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_REPLACE); - } - resultSet = await rdbStore.query(predicates) - try { - console.log(TAG + " InsertWithConflictResolution0004 resultSet query done"); - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = resultSet.getLong(resultSet.getColumnIndex("id")) - const name = resultSet.getString(resultSet.getColumnIndex("name")) - const age = resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) - console.log(TAG + " InsertWithConflictResolution0004 id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - expect(1).assertEqual(id); - expect("zhangsan").assertEqual(name) - expect(18).assertEqual(age) - expect(200.5).assertEqual(salary) - expect(4).assertEqual(blobType[0]) - expect(5).assertEqual(blobType[1]) - expect(6).assertEqual(blobType[2]) - expect(false).assertEqual(resultSet.goToNextRow()) - } catch (err) { - console.log(TAG + " InsertWithConflictResolution0004 resultSet query error " + err); - } - resultSet.close(); - done() - console.log(TAG + " ************* InsertWithConflictResolution_0004 end *************"); - }) + let predicates = new data_Rdb.RdbPredicates("test"); + predicates.equalTo("name", "zhangsan") + let resultSet = await rdbStore.query(predicates) + try { + console.log(TAG + " InsertWithConflictResolution0004 resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + expect(1).assertEqual(id); + expect(false).assertEqual(resultSet.goToNextRow()) + } catch (err) { + console.log(TAG + " InsertWithConflictResolution0004 insert error" + err); + } + resultSet.close(); - /** - * @tc.name rdb inserttWithConflictResolution test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0005 - * @tc.desc rdb insertWithConflictResolution test - */ - it('InsertWithConflictResolution0005', 0, async function (done) { - console.log(TAG + " ************* InsertWithConflictResolution0005 start *************"); - { - var u8 = new Uint8Array([4, 5, 6]) - const valueBucket = { - "id": 1, - "name": "zhangsan", - "age": 18, - "salary": 200.5, - "blobType": u8, + { + var u8 = new Uint8Array([4, 5, 6]) + const valueBucket = { + "id": 1, + "name": "zhangsan", + "age": 18, + "salary": 200.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_REPLACE); } + resultSet = await rdbStore.query(predicates) try { - rdbStore.insert("test", valueBucket, 6); - expect(null).assertFail() - } catch(err) { - console.log(TAG + " InsertWithConflictResolution0005 catch err: failed, err: code=" + err.code + " message=" + err.message) - expect("401").assertEqual(err.code) - done() + console.log(TAG + " InsertWithConflictResolution0004 resultSet query done"); + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = resultSet.getLong(resultSet.getColumnIndex("id")) + const name = resultSet.getString(resultSet.getColumnIndex("name")) + const age = resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = resultSet.getBlob(resultSet.getColumnIndex("blobType")) + console.log(TAG + " InsertWithConflictResolution0004 id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name) + expect(18).assertEqual(age) + expect(200.5).assertEqual(salary) + expect(4).assertEqual(blobType[0]) + expect(5).assertEqual(blobType[1]) + expect(6).assertEqual(blobType[2]) + expect(false).assertEqual(resultSet.goToNextRow()) + } catch (err) { + console.log(TAG + " InsertWithConflictResolution0004 resultSet query error " + err); } - } + resultSet.close(); + done() + console.log(TAG + " ************* InsertWithConflictResolution_0004 end *************"); + }) - console.log(TAG + " ************* InsertWithConflictResolution_0005 end *************"); - }) + /** + * @tc.name rdb inserttWithConflictResolution test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0005 + * @tc.desc rdb insertWithConflictResolution test + */ + it('InsertWithConflictResolution0005', 0, async function (done) { + console.log(TAG + " ************* InsertWithConflictResolution0005 start *************"); + { + var u8 = new Uint8Array([4, 5, 6]) + const valueBucket = { + "id": 1, + "name": "zhangsan", + "age": 18, + "salary": 200.5, + "blobType": u8, + } + try { + rdbStore.insert("test", valueBucket, 6); + expect(null).assertFail() + } catch (err) { + console.log(TAG + " InsertWithConflictResolution0005 catch err: failed, err: code=" + err.code + " message=" + err.message) + expect("401").assertEqual(err.code) + done() + } + } + + console.log(TAG + " ************* InsertWithConflictResolution_0005 end *************"); + }) - /** - * @tc.name rdb inserttWithConflictResolution test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0006 - * @tc.desc rdb insertWithConflictResolution test - */ - it('InsertWithConflictResolution0006', 0, async function (done) { + /** + * @tc.name rdb inserttWithConflictResolution test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0006 + * @tc.desc rdb insertWithConflictResolution test + */ + it('InsertWithConflictResolution0006', 0, async function (done) { console.log(TAG + " ************* InsertWithConflictResolution0006 start *************"); var u8 = new Uint8Array([1, 2, 3]) { @@ -1355,7 +1344,7 @@ describe('relationalStoreInsertTest', function () { } await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_ABORT); } - + { const valueBucket = { "id": 1, @@ -1374,38 +1363,35 @@ describe('relationalStoreInsertTest', function () { console.log(TAG + " InsertWithConflictResolution0006 insert with wrong valuebucket and ConflictResolution is ON_CONFLICT_ABORT") done() }) - } catch(err) { + } catch (err) { console.log(TAG + " InsertWithConflictResolution0006 catch err: failed, err: code=" + err.code + " message=" + err.message) expect("401").assertEqual(err.code) expect(null).assertFail() } } - + console.log(TAG + " ************* InsertWithConflictResolution0006 end *************"); }) - + /** - * @tc.name rdb inserttWithConflictResolution test - * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0007 - * @tc.desc rdb insertWithConflictResolution test - */ - it('InsertWithConflictResolution0007', 0, async function (done) { + * @tc.name rdb inserttWithConflictResolution test + * @tc.number SUB_DDM_AppDataFWK_JSRDB_InsertWithConflictResolution_0007 + * @tc.desc rdb insertWithConflictResolution test + */ + it('InsertWithConflictResolution0007', 0, async function (done) { console.log(TAG + " ************* InsertWithConflictResolution0007 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - { - const valueBucket = { + let u8 = new Uint8Array([1, 2, 3]) + const valueBucket1 = { "id": 1, "name": "zhangsan", "age": 18, "salary": 100.5, "blobType": u8, } - await rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_FAIL); - } - - { - const valueBucket = { + await rdbStore.insert("test", valueBucket1, data_Rdb.ConflictResolution.ON_CONFLICT_FAIL); + + const valueBucket2 = { "id": 1, "name": "zhangsan", "age": 18, @@ -1413,26 +1399,26 @@ describe('relationalStoreInsertTest', function () { "blobType": u8, } try { - let insertPromise = rdbStore.insert("test", valueBucket, data_Rdb.ConflictResolution.ON_CONFLICT_FAIL); + let insertPromise = rdbStore.insert("test", valueBucket2, data_Rdb.ConflictResolution.ON_CONFLICT_FAIL); insertPromise.then(async (ret) => { - expect(1).assertEqual(ret) +// expect(1).assertEqual(ret) console.log(TAG + " InsertWithConflictResolution0007 insert first done: " + ret) - expect(null).assertFail() - }).catch((err) => { - console.log(TAG + " InsertWithConflictResolution0007 insert with wrong valuebucket and ConflictResolution is ON_CONFLICT_FAIL") + expect().assertFail(); done() + }).catch((err) => { + console.error(`insert failed, code is ${err.code},message is ${err.message}`); + expect(err !== null).assertTrue(); + done(); }) - } catch(err) { - console.log(TAG + " InsertWithConflictResolution0007 catch err: failed, err: code=" + err.code + " message=" + err.message) - expect("401").assertEqual(err.code) - expect(null).assertFail() + } catch (err) { + console.log(TAG + " catch err: failed, err: code=" + err.code + " message=" + err.message) + expect().assertFail(); + done(); } - } - console.log(TAG + " ************* InsertWithConflictResolution0007 end *************"); - }) + }) - /** + /** * @tc.name rdb insert test * @tc.number SUB_DDM_AppDataFWK_JSRDB_Insert_0100 * @tc.desc rdb insert test @@ -1440,64 +1426,59 @@ describe('relationalStoreInsertTest', function () { it('SUB_DDM_AppDataFWK_JSRDB_Insert_0100', 0, async function (done) { console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0100 start *************"); var u8 = new Uint8Array([1, 2, 3]) - { - const valueBucket = { - "id": 1, - "name": "zhangsan", - "age": null, - "salary": undefined, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket); + + const valueBucket1 = { + "id": 1, + "name": "zhangsan", + "age": null, + "salary": undefined, + "blobType": u8, } + await rdbStore.insert("test", valueBucket1); - { - const valueBucket = { - "id": 2, - "name": "lisi", - "age": 19, - "salary": 200.5, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket); + const valueBucket2 = { + "id": 2, + "name": "lisi", + "age": 19, + "salary": 200.5, + "blobType": u8, } + await rdbStore.insert("test", valueBucket2); + let predicates = new data_Rdb.RdbPredicates("test"); - let resultSet = await rdbStore.query(predicates); - try { - done() + await rdbStore.query(predicates).then((resultSet) => { expect(true).assertEqual(resultSet.goToFirstRow()); expect(true).assertEqual(resultSet.isColumnNull(resultSet.getColumnIndex("age"))); expect(true).assertEqual(resultSet.isColumnNull(resultSet.getColumnIndex("salary"))); - } catch (err) { - console.log("query error" + err); + resultSet.close(); + resultSet = null; + }).catch((err) => { + console.log("query1 error" + err); expect().assertFail() - } + }) - { - const valueBucket = { - "age": null, - "salary": undefined, - } - predicates.equalTo("name", "lisi") - await rdbStore.update(valueBucket, predicates) + const valueBucket3 = { + "age": null, + "salary": undefined, } + predicates.equalTo("name", "lisi"); + await rdbStore.update(valueBucket3, predicates); predicates.clear(); - resultSet = await rdbStore.query(predicates); - try { - done(); + await rdbStore.query(predicates).then((resultSet) => { expect(true).assertEqual(resultSet.goToFirstRow()); expect(true).assertEqual(resultSet.goToNextRow()); expect(true).assertEqual(resultSet.isColumnNull(resultSet.getColumnIndex("age"))); expect(200.5).assertEqual(resultSet.getDouble(resultSet.getColumnIndex("salary"))); - } catch (err) { - console.log("query error" + err); - expect().assertFail() - } - - resultSet.close() - resultSet = null - console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0100 end *************"); + done(); + console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0100 end *************"); + resultSet.close(); + resultSet = null; + }).catch((err) => { + console.log("query2 error" + err); + expect().assertFail(); + done(); + }) }) /** @@ -1516,8 +1497,7 @@ describe('relationalStoreInsertTest', function () { "blobType": u8, } try { - let insertPromise = rdbStore.insert("test", valueBucket) - insertPromise.then(async (ret) => { + await rdbStore.insert("test", valueBucket).then(async (ret) => { done(); expect().assertFail() }).catch((err) => { @@ -1526,13 +1506,13 @@ describe('relationalStoreInsertTest', function () { }) } catch (err) { done(); - console.log("catch err: failed, err: code=" + err.code + " message=" + err.message) - expect('401').assertEqual(err.code) + console.log("catch err: failed, err: code=" + err.code + " message=" + err.message + typeof (err.code)) + expect(err.code).assertEqual('401'); } } console.log(TAG + "************* SUB_DDM_AppDataFWK_JSRDB_Insert_0200 end *************"); }) - - console.info(TAG + " *************Unit Test End*************"); -}) + + console.info(TAG + " *************Unit Test End*************"); + }) } diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreTransactionJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreTransactionJsunit.test.js index fe98c636c..c772a3070 100644 --- a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreTransactionJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreTransactionJsunit.test.js @@ -29,414 +29,415 @@ const STORE_CONFIG = { var rdbStore = undefined; export default function relationalStoreTransactionTest() { -describe('relationalStoreTransactionTest', function () { - beforeAll(function () { - console.info(TAG + 'beforeAll') - }) - - beforeEach(async function () { - console.info(TAG + 'beforeEach') - rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); - await rdbStore.executeSql(CREATE_TABLE_TEST, null); - }) - - afterEach(async function () { - console.info(TAG + 'afterEach') - await rdbStore.executeSql("DELETE FROM test"); - rdbStore = null - await data_Rdb.deleteRdbStore(context, "rdbstoreTransactionTest.db"); - }) - - afterAll(async function () { - console.info(TAG + 'afterAll') - }) - - console.info(TAG + "*************Unit Test Begin*************"); - - /** - * @tc.name RelationalStore transaction insert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_testRdbTransactionInsert0001 - * @tc.desc RelationalStore transaction insert & commit, the result comes out is 3 items; - */ - it('testRdbTransactionInsert0001', 0, async function (done) { - console.info(TAG + "************* testRdbStoreInsert0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - rdbStore.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket) - - await rdbStore.commit() - - let predicates = new data_Rdb.RdbPredicates("test"); - let resultSet = await rdbStore.query(predicates) - console.info(TAG + "testRdbTransactionInsert0001 result count " + resultSet.rowCount) - expect(1).assertEqual(resultSet.rowCount) - resultSet.close() -// resultSet == null; - } catch (e) { - console.info(TAG + e); - expect(null).assertFail() - console.info(TAG + "testRdbTransactionInsert0001 failed"); - } - done() - console.info(TAG + "************* testRdbTransactionInsert0001 end *************"); - }) - - /** - * @tc.name RelationalStore transaction insert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_testRdbTransactionInsert0002 - * @tc.desc RelationalStore transaction insert & commit, the result comes out is 3 items; - */ - it('testRdbTransactionInsert0002', 0, async function (done) { - console.info(TAG + "************* testRdbStoreInsert0002 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket) - - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 9.5, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket1) - - - const valueBucket2 = { - "name": "wangwu", - "age": 16, - "salary": 99, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket2) - - await rdbStore.commit() - - let predicates = new data_Rdb.RdbPredicates("test"); - let resultSet = await rdbStore.query(predicates) - expect(3).assertEqual(resultSet.rowCount) - resultSet.close() -// resultSet == null; - } catch (e) { - expect(null).assertFail() - console.info(TAG + "testRdbTransactionInsert0002 failed"); - } - done() - console.info(TAG + "************* testRdbTransactionInsert0002 end *************"); - }) - - - /** - * @tc.name RelationalStore transaction insert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_testRdbTransactionInsert0003 - * @tc.desc while using transaction to insert values, querying the db, - * the result comes out is 0; - */ - it('testRdbTransactionInsert0003', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionInsert0003 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, + describe('relationalStoreTransactionTest', function () { + beforeAll(function () { + console.info(TAG + 'beforeAll') + }) + + beforeEach(async function () { + console.info(TAG + 'beforeEach') + rdbStore = await data_Rdb.getRdbStore(context, STORE_CONFIG); + await rdbStore.executeSql(CREATE_TABLE_TEST, null); + }) + + afterEach(async function () { + console.info(TAG + 'afterEach') + await rdbStore.executeSql("DELETE FROM test"); + rdbStore = null + await data_Rdb.deleteRdbStore(context, "rdbstoreTransactionTest.db"); + }) + + afterAll(async function () { + console.info(TAG + 'afterAll') + }) + + console.info(TAG + "*************Unit Test Begin*************"); + + /** + * @tc.name RelationalStore transaction insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_testRdbTransactionInsert0001 + * @tc.desc RelationalStore transaction insert & commit, the result comes out is 3 items; + */ + it('testRdbTransactionInsert0001', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + await rdbStore.commit() + + let predicates = new data_Rdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + console.info(TAG + "testRdbTransactionInsert0001 result count " + resultSet.rowCount) + expect(1).assertEqual(resultSet.rowCount) + resultSet.close() + // resultSet == null; + } catch (e) { + console.info(TAG + e); + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0001 failed"); } - await rdbStore.insert("test", valueBucket) - - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 9.5, - "blobType": u8, + done() + console.info(TAG + "************* testRdbTransactionInsert0001 end *************"); + }) + + /** + * @tc.name RelationalStore transaction insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_testRdbTransactionInsert0002 + * @tc.desc RelationalStore transaction insert & commit, the result comes out is 3 items; + */ + it('testRdbTransactionInsert0002', 0, async function (done) { + console.info(TAG + "************* testRdbStoreInsert0002 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 9.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1) + + + const valueBucket2 = { + "name": "wangwu", + "age": 16, + "salary": 99, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket2) + + await rdbStore.commit() + + let predicates = new data_Rdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + expect(3).assertEqual(resultSet.rowCount) + resultSet.close() + // resultSet == null; + } catch (e) { + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0002 failed"); } - await rdbStore.insert("test", valueBucket1) - - let predicates = new data_Rdb.RdbPredicates("test"); - let resultSet = await rdbStore.query(predicates) - expect(0).assertEqual(resultSet.rowCount) - resultSet.close() -// resultSet == null; - const valueBucket2 = { - "name": "wangwu", - "age": 16, - "salary": 99, - "blobType": u8, + done() + console.info(TAG + "************* testRdbTransactionInsert0002 end *************"); + }) + + + /** + * @tc.name RelationalStore transaction insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_testRdbTransactionInsert0003 + * @tc.desc while using transaction to insert values, querying the db, + * the result comes out is 0; + */ + it('testRdbTransactionInsert0003', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionInsert0003 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 9.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1) + + let predicates = new data_Rdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + expect(0).assertEqual(resultSet.rowCount) + resultSet.close() + // resultSet == null; + const valueBucket2 = { + "name": "wangwu", + "age": 16, + "salary": 99, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket2) + + await rdbStore.commit() + } catch (e) { + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0003 failed"); } - await rdbStore.insert("test", valueBucket2) - - await rdbStore.commit() - } catch (e) { - expect(null).assertFail() - console.info(TAG + "testRdbTransactionInsert0003 failed"); - } - done() - console.info(TAG + "************* testRdbTransactionInsert0003 end *************"); - }) - - /** - * @tc.name RelationalStore insert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RollBack_0001 - * @tc.desc the classical transaction scenario, when we insert or commit the value, - * db returns an exception, we need to catch exception and rollback. - */ - it('testRdbTransactionRollBack0001', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionRollBack0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "id": 1, - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, + done() + console.info(TAG + "************* testRdbTransactionInsert0003 end *************"); + }) + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_RollBack_0001 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionRollBack0001', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionRollBack0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + await rdbStore.insert("test", valueBucket) + + await rdbStore.commit() + } catch (e) { + await rdbStore.rollBack() + let predicates = new data_Rdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + console.info(TAG + "testRdbTransactionRollBack0001 result count " + resultSet.rowCount); + expect(0).assertEqual(resultSet.rowCount) + resultSet.close() + // resultSet == null; } - await rdbStore.insert("test", valueBucket) - await rdbStore.insert("test", valueBucket) - - await rdbStore.commit() - } catch (e) { - await rdbStore.rollBack() - let predicates = new data_Rdb.RdbPredicates("test"); - let resultSet = await rdbStore.query(predicates) - console.info(TAG + "testRdbTransactionRollBack0001 result count " + resultSet.rowCount); - expect(0).assertEqual(resultSet.rowCount) - resultSet.close() -// resultSet == null; - } - done() - console.info(TAG + "************* testRdbTransactionRollBack0001 end *************"); - }) - - /** - * @tc.name RelationalStore insert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Multi_0001 - * @tc.desc the classical transaction scenario, when we insert or commit the value, - * db returns an exception, we need to catch exception and rollback. - */ - it('testRdbTransactionMulti0001', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionMulti0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "id": 1, - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, + done() + console.info(TAG + "************* testRdbTransactionRollBack0001 end *************"); + }) + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Multi_0001 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionMulti0001', 0, async function (done) { + console.info('ttt' + "************* testRdbTransactionMulti0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + await rdbStore.beginTransaction() + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 220.5, + "blobType": u8, + } + let num = rdbStore.insert("test", valueBucket1) + num.then(async (ret1) => { + console.info('ttt' + "testRdbTransactionMulti0001 * insert result " + ret1); + expect(2).assertEqual(ret1) + }) + + await rdbStore.commit() + await rdbStore.commit() + + let predicates = new data_Rdb.RdbPredicates("test"); + await rdbStore.query(predicates).then(async (ret2) => { + console.info('ttt' + "testRdbTransactionMulti0001 ret.rowCount = " + ret2.rowCount); + expect(2).assertEqual(ret2.rowCount) + done() + console.info('ttt' + "************* testRdbTransactionMulti0001 end *************"); + ret2.close() + }) + } catch (e) { + console.info('ttt' + "testRdbTransactionMulti0001 fail ***** "); } - await rdbStore.insert("test", valueBucket) - - await rdbStore.beginTransaction() - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 220.5, - "blobType": u8, + }) + + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Multi_0002 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionMulti0002', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionMulti0002 start *************"); + let u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + await rdbStore.beginTransaction() + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 220.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1, async function (err, ret1){ + console.info(TAG + "testRdbTransactionMulti0002 * insert result " + ret1); + expect(2).assertEqual(ret1); + + await rdbStore.rollBack() + + await rdbStore.commit() + + let predicates = new data_Rdb.RdbPredicates("test"); + await rdbStore.query(predicates).then(async (ret2) => { + console.info(TAG + "testRdbTransactionMulti0002 * final query " + ret2.rowCount); + expect(1).assertEqual(ret2.rowCount) + done() + console.info(TAG + "************* testRdbTransactionMulti0002 end *************"); + ret2.close() + }) + }) + + } catch (e) { + console.info(TAG + "testRdbTransactionMulti0002 fail ***** "); + expect().assertFail(); + done(); } - let num = rdbStore.insert("test", valueBucket1) - num.then(async (ret) => { - console.info(TAG + "testRdbTransactionMulti0001 * insert result " + ret); - expect(2).assertEqual(ret) - }) - - await rdbStore.commit() - await rdbStore.commit() - - let predicates = new data_Rdb.RdbPredicates("test"); - num = rdbStore.query(predicates) - num.then(async (ret) => { - expect(2).assertEqual(ret.rowCount) - ret.close() - }) - } catch (e) { - console.info(TAG + "testRdbTransactionMulti0001 fail ***** "); - } - done() - console.info(TAG + "************* testRdbTransactionMulti0001 end *************"); - }) - - /** - * @tc.name RelationalStore insert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Multi_0002 - * @tc.desc the classical transaction scenario, when we insert or commit the value, - * db returns an exception, we need to catch exception and rollback. - */ - it('testRdbTransactionMulti0002', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionMulti0002 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "id": 1, - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, + }) + /** + * @tc.name RelationalStore insert test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Multi_0003 + * @tc.desc the classical transaction scenario, when we insert or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionMulti0003', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionMulti0003 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "id": 1, + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket); + + await rdbStore.beginTransaction(); + const valueBucket2 = { + "name": "zhangsan", + "age": 20, + "salary": 220.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket2); + + await rdbStore.rollBack(); + + const valueBucket3 = { + "name": "wangwu", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket3); + await rdbStore.commit(); + + let predicates = new data_Rdb.RdbPredicates("test"); + await rdbStore.query(predicates).then(async (ret) => { + console.info(TAG + "testRdbTransactionMulti0003 * final query " + ret.rowCount); + expect(2).assertEqual(ret.rowCount); + done(); + console.info(TAG + "************* testRdbTransactionMulti0003 end *************"); + ret.close(); + }) + } catch (e) { + await rdbStore.rollBack() + console.info(TAG + "testRdbTransactionMulti0003 rollback ***** "); } - await rdbStore.insert("test", valueBucket, function (err, ret){ - - }); - await rdbStore.beginTransaction() - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 220.5, - "blobType": u8, + }) + + /** + * @tc.name RelationalStore delete test + * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Transaction_Delete_0010 + * @tc.desc the classical transaction scenario, when we delete or commit the value, + * db returns an exception, we need to catch exception and rollback. + */ + it('testRdbTransactionDelete0001', 0, async function (done) { + console.info(TAG + "************* testRdbTransactionDelete0001 start *************"); + var u8 = new Uint8Array([1, 2, 3]) + try { + await rdbStore.beginTransaction() + const valueBucket = { + "name": "lisi", + "age": 18, + "salary": 100.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket) + + const valueBucket1 = { + "name": "zhangsan", + "age": 20, + "salary": 9.5, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket1) + + let predicates = new data_Rdb.RdbPredicates("test"); + let resultSet = await rdbStore.query(predicates) + expect(0).assertEqual(resultSet.rowCount) + resultSet.close() + // resultSet == null; + const valueBucket2 = { + "name": "wangwu", + "age": 16, + "salary": 99, + "blobType": u8, + } + await rdbStore.insert("test", valueBucket2) + + await rdbStore.commit() + } catch (e) { + expect(null).assertFail() + console.info(TAG + "testRdbTransactionInsert0003 failed"); } - let num = rdbStore.insert("test", valueBucket1) - num.then(async (ret) => { - console.info(TAG + "testRdbTransactionMulti0002 * insert result " + ret); - expect(2).assertEqual(ret) - ret.close() - }) - - await rdbStore.rollBack() - - await rdbStore.commit() - - let predicates = new data_Rdb.RdbPredicates("test"); - num = rdbStore.query(predicates) - num.then(async (ret) => { - console.info(TAG + "testRdbTransactionMulti0002 * final query " + ret.rowCount); - expect(1).assertEqual(ret.rowCount) - ret.close() - }) - } catch (e) { - console.info(TAG + "testRdbTransactionMulti0002 fail ***** "); - } - done() - console.info(TAG + "************* testRdbTransactionMulti0002 end *************"); - }) - - /** - * @tc.name RelationalStore insert test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Multi_0003 - * @tc.desc the classical transaction scenario, when we insert or commit the value, - * db returns an exception, we need to catch exception and rollback. - */ - it('testRdbTransactionMulti0003', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionMulti0003 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "id": 1, - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, + //删除 + { + let predicates = await new data_Rdb.RdbPredicates("test") + await rdbStore.delete(predicates).then(async (ret) => { + expect(3).assertEqual(ret); + done() + console.info(TAG + "************* testRdbTransactionDelete0001 end *************"); + console.info(TAG + "Delete done: " + ret) + }).catch((err) => { + expect(null).assertFail(); + done(); + }) } - await rdbStore.insert("test", valueBucket, function (err, ret){ - }); + }) - await rdbStore.beginTransaction() - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 220.5, - "blobType": u8, - } - let num = await rdbStore.insert("test", valueBucket1) - - await rdbStore.rollBack() - - await rdbStore.insert("test", valueBucket) - await rdbStore.commit() - - let predicates = new data_Rdb.RdbPredicates("test"); - num = rdbStore.query(predicates) - num.then(async (ret) => { - console.info(TAG + "testRdbTransactionMulti0003 * final query " + ret.rowCount); - expect(1).assertEqual(ret.rowCount) - ret.close() - }) - } catch (e) { - await rdbStore.rollBack() - console.info(TAG + "testRdbTransactionMulti0003 rollback ***** "); - } - done() - console.info(TAG + "************* testRdbTransactionMulti0003 end *************"); - }) - - /** - * @tc.name RelationalStore delete test - * @tc.number SUB_DDM_AppDataFWK_JSRelationalStore_Transaction_Delete_0010 - * @tc.desc the classical transaction scenario, when we delete or commit the value, - * db returns an exception, we need to catch exception and rollback. - */ - it('testRdbTransactionDelete0001', 0, async function (done) { - console.info(TAG + "************* testRdbTransactionDelete0001 start *************"); - var u8 = new Uint8Array([1, 2, 3]) - try { - await rdbStore.beginTransaction() - const valueBucket = { - "name": "lisi", - "age": 18, - "salary": 100.5, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket) - - const valueBucket1 = { - "name": "zhangsan", - "age": 20, - "salary": 9.5, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket1) - - let predicates = new data_Rdb.RdbPredicates("test"); - let resultSet = await rdbStore.query(predicates) - expect(0).assertEqual(resultSet.rowCount) - resultSet.close() -// resultSet == null; - const valueBucket2 = { - "name": "wangwu", - "age": 16, - "salary": 99, - "blobType": u8, - } - await rdbStore.insert("test", valueBucket2) - - await rdbStore.commit() - } catch (e) { - expect(null).assertFail() - console.info(TAG + "testRdbTransactionInsert0003 failed"); - } - //删除 - { - let predicates = await new data_Rdb.RdbPredicates("test") - let deletePromise = rdbStore.delete(predicates) - deletePromise.then(async (ret) => { - expect(3).assertEqual(ret) - console.info(TAG + "Delete done: " + ret) - }).catch((err) => { - expect(null).assertFail() - }) - await deletePromise - } - done() - console.info(TAG + "************* testRdbTransactionDelete0001 end *************"); - }) - - console.info(TAG + "*************Unit Test End*************"); -})} + console.info(TAG + "*************Unit Test End*************"); + })} diff --git a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreUpdateJsunit.test.js b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreUpdateJsunit.test.js index 4ce38615b..910d3d1fa 100644 --- a/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreUpdateJsunit.test.js +++ b/distributeddatamgr/relationalStoretest/relationalStoreJstest/hap/src/main/js/test/RelationalStoreUpdateJsunit.test.js @@ -237,32 +237,29 @@ export default function relationalStoreUpdateTest() { { let predicates = await new data_Rdb.RdbPredicates("test") await predicates.equalTo("aaa", "null") - let updatePromise = rdbStore.update(valueBucket, predicates) - updatePromise.then(async (ret) => { + await rdbStore.update(valueBucket, predicates).then(async (ret) => { console.info(TAG + "update done: " + ret); expect(null).assertFail(); }).catch((err) => { + expect(err !== null).assertTrue(); console.info(TAG + "update with wrong condition"); }) - //await updatePromise } { - const emptyBucket = {}; let predicates = await new data_Rdb.RdbPredicates("test") await predicates.equalTo("name", "zhangsan") await predicates.equalTo("age", 18) await predicates.equalTo("null", 100.5) - let updatePromise = rdbStore.update(valueBucket, predicates) - updatePromise.then(async (ret) => { + await rdbStore.update(valueBucket, predicates).then(async (ret) => { console.info(TAG + "update done: " + ret); - expect(null).assertFail(); + expect(ret).assertEqual(0); + done(); + console.info(TAG + "************* testRdbStoreUpdate0004 end *************"); }).catch((err) => { console.info(TAG + "update with wrong condition"); }) } } - done(); - console.info(TAG + "************* testRdbStoreUpdate0004 end *************"); }) /** @@ -329,7 +326,7 @@ export default function relationalStoreUpdateTest() { await expect(2).assertEqual(blobType[1]); await expect(3).assertEqual(blobType[2]); console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" - + salary + ", blobType=" + blobType); + + salary + ", blobType=" + blobType); await expect(true).assertEqual(resultSet.goToNextRow()) const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id")) @@ -346,7 +343,7 @@ export default function relationalStoreUpdateTest() { await expect(8).assertEqual(blobType_1[1]); await expect(9).assertEqual(blobType_1[2]); console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary=" - + salary_1 + ", blobType=" + blobType_1); + + salary_1 + ", blobType=" + blobType_1); await expect(false).assertEqual(resultSet.goToNextRow()) resultSet.close() @@ -401,59 +398,58 @@ export default function relationalStoreUpdateTest() { } let predicates = await new data_Rdb.RdbPredicates("test") await predicates.equalTo("age", "19") - let updatePromise = rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_NONE); - updatePromise.then(async (ret) => { - await console.log(TAG + "testRdbStoreUpdateWithConflictResolution0002 done: " + ret); - expect(null).assertFail(); + await rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_NONE).then(async (ret) => { + console.log(TAG + "testRdbStoreUpdateWithConflictResolution0002 done: " + ret); + expect().assertFail(); }).catch((err) => { - console.log(TAG + "testRdbStoreUpdateWithConflictResolution0002 error"); - expect(null).assertFail(); + console.log(TAG + "testRdbStoreUpdateWithConflictResolution0002 error" + err); + expect(err !== null).assertTrue(); }) - done() } { let predicates = await new data_Rdb.RdbPredicates("test") - let resultSet = await rdbStore.query(predicates) - - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = await resultSet.getLong(resultSet.getColumnIndex("id")) - const name = await resultSet.getString(resultSet.getColumnIndex("name")) - const age = await resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) - - await expect(1).assertEqual(id); - await expect("zhangsan").assertEqual(name); - await expect(18).assertEqual(age); - await expect(100.5).assertEqual(salary); - await expect(1).assertEqual(blobType[0]); - await expect(2).assertEqual(blobType[1]); - await expect(3).assertEqual(blobType[2]); - console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" + await rdbStore.query(predicates).then(async (resultSet)=>{ + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = await resultSet.getLong(resultSet.getColumnIndex("id")) + const name = await resultSet.getString(resultSet.getColumnIndex("name")) + const age = await resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) + + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name); + expect(18).assertEqual(age); + expect(100.5).assertEqual(salary); + expect(1).assertEqual(blobType[0]); + expect(2).assertEqual(blobType[1]); + expect(3).assertEqual(blobType[2]); + console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - await expect(true).assertEqual(resultSet.goToNextRow()) - const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id")) - const name_1 = await resultSet.getString(resultSet.getColumnIndex("name")) - const age_1 = await resultSet.getLong(resultSet.getColumnIndex("age")) - const salary_1 = await resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType_1 = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) - - await expect(2).assertEqual(id_1); - await expect("lisi").assertEqual(name_1); - await expect(19).assertEqual(age_1); - await expect(200.5).assertEqual(salary_1); - await expect(4).assertEqual(blobType_1[0]); - await expect(5).assertEqual(blobType_1[1]); - await expect(6).assertEqual(blobType_1[2]); - console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary=" + expect(true).assertEqual(resultSet.goToNextRow()) + const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id")) + const name_1 = await resultSet.getString(resultSet.getColumnIndex("name")) + const age_1 = await resultSet.getLong(resultSet.getColumnIndex("age")) + const salary_1 = await resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType_1 = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) + + expect(2).assertEqual(id_1); + expect("lisi").assertEqual(name_1); + expect(19).assertEqual(age_1); + expect(200.5).assertEqual(salary_1); + expect(4).assertEqual(blobType_1[0]); + expect(5).assertEqual(blobType_1[1]); + expect(6).assertEqual(blobType_1[2]); + console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary=" + salary_1 + ", blobType=" + blobType_1); - await expect(false).assertEqual(resultSet.goToNextRow()) + expect(false).assertEqual(resultSet.goToNextRow()) - resultSet.close() - done() - console.log(TAG + "************* testRdbStoreUpdateWithConflictResolution0002 end *************"); + resultSet.close(); + resultSet = null; + done() + console.log(TAG + "************* testRdbStoreUpdateWithConflictResolution0002 end *************"); + }) } }) @@ -497,10 +493,9 @@ export default function relationalStoreUpdateTest() { } let predicates = await new data_Rdb.RdbPredicates("test") await predicates.equalTo("age", "19") - let updatePromise = rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK); - updatePromise.then(async (ret) => { - await expect(1).assertEqual(ret); - await console.log(TAG + "testRdbStoreUpdateWithConflictResolution0003 done: " + ret); + await rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK).then(async (ret) => { + expect(1).assertEqual(ret); + console.log(TAG + "testRdbStoreUpdateWithConflictResolution0003 done: " + ret); { let predicates = await new data_Rdb.RdbPredicates("test") let resultSet = await rdbStore.query(predicates) @@ -512,33 +507,33 @@ export default function relationalStoreUpdateTest() { const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) - await expect(1).assertEqual(id); - await expect("zhangsan").assertEqual(name); - await expect(18).assertEqual(age); - await expect(100.5).assertEqual(salary); - await expect(1).assertEqual(blobType[0]); - await expect(2).assertEqual(blobType[1]); - await expect(3).assertEqual(blobType[2]); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name); + expect(18).assertEqual(age); + expect(100.5).assertEqual(salary); + expect(1).assertEqual(blobType[0]); + expect(2).assertEqual(blobType[1]); + expect(3).assertEqual(blobType[2]); console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" - + salary + ", blobType=" + blobType); + + salary + ", blobType=" + blobType); - await expect(true).assertEqual(resultSet.goToNextRow()) + expect(true).assertEqual(resultSet.goToNextRow()) const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id")) const name_1 = await resultSet.getString(resultSet.getColumnIndex("name")) const age_1 = await resultSet.getLong(resultSet.getColumnIndex("age")) const salary_1 = await resultSet.getDouble(resultSet.getColumnIndex("salary")) const blobType_1 = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) - await expect(3).assertEqual(id_1); - await expect("wangjing").assertEqual(name_1); - await expect(20).assertEqual(age_1); - await expect(300.5).assertEqual(salary_1); - await expect(7).assertEqual(blobType_1[0]); - await expect(8).assertEqual(blobType_1[1]); - await expect(9).assertEqual(blobType_1[2]); + expect(3).assertEqual(id_1); + expect("wangjing").assertEqual(name_1); + expect(20).assertEqual(age_1); + expect(300.5).assertEqual(salary_1); + expect(7).assertEqual(blobType_1[0]); + expect(8).assertEqual(blobType_1[1]); + expect(9).assertEqual(blobType_1[2]); console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary=" - + salary_1 + ", blobType=" + blobType_1); - await expect(false).assertEqual(resultSet.goToNextRow()) + + salary_1 + ", blobType=" + blobType_1); + expect(false).assertEqual(resultSet.goToNextRow()) resultSet.close() done(); @@ -593,59 +588,58 @@ export default function relationalStoreUpdateTest() { } let predicates = await new data_Rdb.RdbPredicates("test") await predicates.equalTo("age", "19") - let updatePromise = rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK); - updatePromise.then(async (ret) => { - aexpect(null).assertFail(); + await rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_ROLLBACK).then(async (ret) => { + expect(null).assertFail(); await console.log(TAG + "testRdbStoreUpdateWithConflictResolution0004 done: " + ret); }).catch((err) => { - expect(null).assertFail(); + expect(err !== null).assertTrue(); console.log(TAG + "testRdbStoreUpdateWithConflictResolution0004 error"); }) - done() +// done() } { let predicates = await new data_Rdb.RdbPredicates("test") - let resultSet = await rdbStore.query(predicates) - - expect(true).assertEqual(resultSet.goToFirstRow()) - const id = await resultSet.getLong(resultSet.getColumnIndex("id")) - const name = await resultSet.getString(resultSet.getColumnIndex("name")) - const age = await resultSet.getLong(resultSet.getColumnIndex("age")) - const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) - - await expect(1).assertEqual(id); - await expect("zhangsan").assertEqual(name); - await expect(18).assertEqual(age); - await expect(100.5).assertEqual(salary); - await expect(1).assertEqual(blobType[0]); - await expect(2).assertEqual(blobType[1]); - await expect(3).assertEqual(blobType[2]); - console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" + await rdbStore.query(predicates).then(async (resultSet)=>{ + expect(true).assertEqual(resultSet.goToFirstRow()) + const id = await resultSet.getLong(resultSet.getColumnIndex("id")) + const name = await resultSet.getString(resultSet.getColumnIndex("name")) + const age = await resultSet.getLong(resultSet.getColumnIndex("age")) + const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) + + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name); + expect(18).assertEqual(age); + expect(100.5).assertEqual(salary); + expect(1).assertEqual(blobType[0]); + expect(2).assertEqual(blobType[1]); + expect(3).assertEqual(blobType[2]); + console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" + salary + ", blobType=" + blobType); - await expect(true).assertEqual(resultSet.goToNextRow()) - const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id")) - const name_1 = await resultSet.getString(resultSet.getColumnIndex("name")) - const age_1 = await resultSet.getLong(resultSet.getColumnIndex("age")) - const salary_1 = await resultSet.getDouble(resultSet.getColumnIndex("salary")) - const blobType_1 = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) - - await expect(2).assertEqual(id_1); - await expect("lisi").assertEqual(name_1); - await expect(19).assertEqual(age_1); - await expect(200.5).assertEqual(salary_1); - await expect(4).assertEqual(blobType_1[0]); - await expect(5).assertEqual(blobType_1[1]); - await expect(6).assertEqual(blobType_1[2]); - console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary=" + expect(true).assertEqual(resultSet.goToNextRow()) + const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id")) + const name_1 = await resultSet.getString(resultSet.getColumnIndex("name")) + const age_1 = await resultSet.getLong(resultSet.getColumnIndex("age")) + const salary_1 = await resultSet.getDouble(resultSet.getColumnIndex("salary")) + const blobType_1 = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) + + expect(2).assertEqual(id_1); + expect("lisi").assertEqual(name_1); + expect(19).assertEqual(age_1); + expect(200.5).assertEqual(salary_1); + expect(4).assertEqual(blobType_1[0]); + expect(5).assertEqual(blobType_1[1]); + expect(6).assertEqual(blobType_1[2]); + console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary=" + salary_1 + ", blobType=" + blobType_1); - await expect(false).assertEqual(resultSet.goToNextRow()) + expect(false).assertEqual(resultSet.goToNextRow()) - resultSet.close() - done() - console.log(TAG + "************* testRdbStoreUpdateWithConflictResolution0004 end *************"); + resultSet.close() + done() + console.log(TAG + "************* testRdbStoreUpdateWithConflictResolution0004 end *************"); + }) } }) @@ -689,10 +683,9 @@ export default function relationalStoreUpdateTest() { } let predicates = await new data_Rdb.RdbPredicates("test") await predicates.equalTo("age", "19") - let updatePromise = rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_REPLACE); - updatePromise.then(async (ret) => { - await expect(1).assertEqual(ret); - await console.log(TAG + "testRdbStoreUpdateWithConflictResolution0005 done: " + ret); + await rdbStore.update(valueBucket, predicates, data_Rdb.ConflictResolution.ON_CONFLICT_REPLACE).then(async (ret) => { + expect(1).assertEqual(ret); + console.log(TAG + "testRdbStoreUpdateWithConflictResolution0005 done: " + ret); { let predicates = await new data_Rdb.RdbPredicates("test") let resultSet = await rdbStore.query(predicates) @@ -704,33 +697,33 @@ export default function relationalStoreUpdateTest() { const salary = await resultSet.getDouble(resultSet.getColumnIndex("salary")) const blobType = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) - await expect(1).assertEqual(id); - await expect("zhangsan").assertEqual(name); - await expect(18).assertEqual(age); - await expect(100.5).assertEqual(salary); - await expect(1).assertEqual(blobType[0]); - await expect(2).assertEqual(blobType[1]); - await expect(3).assertEqual(blobType[2]); + expect(1).assertEqual(id); + expect("zhangsan").assertEqual(name); + expect(18).assertEqual(age); + expect(100.5).assertEqual(salary); + expect(1).assertEqual(blobType[0]); + expect(2).assertEqual(blobType[1]); + expect(3).assertEqual(blobType[2]); console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" - + salary + ", blobType=" + blobType); + + salary + ", blobType=" + blobType); - await expect(true).assertEqual(resultSet.goToNextRow()) + expect(true).assertEqual(resultSet.goToNextRow()) const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id")) const name_1 = await resultSet.getString(resultSet.getColumnIndex("name")) const age_1 = await resultSet.getLong(resultSet.getColumnIndex("age")) const salary_1 = await resultSet.getDouble(resultSet.getColumnIndex("salary")) const blobType_1 = await resultSet.getBlob(resultSet.getColumnIndex("blobType")) - await expect(3).assertEqual(id_1); - await expect("wangjing").assertEqual(name_1); - await expect(20).assertEqual(age_1); - await expect(300.5).assertEqual(salary_1); - await expect(7).assertEqual(blobType_1[0]); - await expect(8).assertEqual(blobType_1[1]); - await expect(9).assertEqual(blobType_1[2]); + expect(3).assertEqual(id_1); + expect("wangjing").assertEqual(name_1); + expect(20).assertEqual(age_1); + expect(300.5).assertEqual(salary_1); + expect(7).assertEqual(blobType_1[0]); + expect(8).assertEqual(blobType_1[1]); + expect(9).assertEqual(blobType_1[2]); console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary=" - + salary_1 + ", blobType=" + blobType_1); - await expect(false).assertEqual(resultSet.goToNextRow()) + + salary_1 + ", blobType=" + blobType_1); + expect(false).assertEqual(resultSet.goToNextRow()) resultSet.close() done() @@ -801,7 +794,7 @@ export default function relationalStoreUpdateTest() { await expect(5).assertEqual(blobType[1]); await expect(6).assertEqual(blobType[2]); console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" - + salary + ", blobType=" + blobType); + + salary + ", blobType=" + blobType); await expect(false).assertEqual(resultSet.goToNextRow()) resultSet.close() @@ -881,7 +874,7 @@ export default function relationalStoreUpdateTest() { await expect(2).assertEqual(blobType[1]); await expect(3).assertEqual(blobType[2]); console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" - + salary + ", blobType=" + blobType); + + salary + ", blobType=" + blobType); await expect(true).assertEqual(resultSet.goToNextRow()) const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id")) @@ -898,7 +891,7 @@ export default function relationalStoreUpdateTest() { await expect(8).assertEqual(blobType_1[1]); await expect(9).assertEqual(blobType_1[2]); console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary=" - + salary_1 + ", blobType=" + blobType_1); + + salary_1 + ", blobType=" + blobType_1); await expect(false).assertEqual(resultSet.goToNextRow()) resultSet.close() @@ -970,7 +963,7 @@ export default function relationalStoreUpdateTest() { await expect(5).assertEqual(blobType[1]); await expect(6).assertEqual(blobType[2]); console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" - + salary + ", blobType=" + blobType); + + salary + ", blobType=" + blobType); await expect(false).assertEqual(resultSet.goToNextRow()) resultSet.close() @@ -1049,7 +1042,7 @@ export default function relationalStoreUpdateTest() { await expect(2).assertEqual(blobType[1]); await expect(3).assertEqual(blobType[2]); console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" - + salary + ", blobType=" + blobType); + + salary + ", blobType=" + blobType); await expect(true).assertEqual(resultSet.goToNextRow()) const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id")) @@ -1066,7 +1059,7 @@ export default function relationalStoreUpdateTest() { await expect(8).assertEqual(blobType_1[1]); await expect(9).assertEqual(blobType_1[2]); console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary=" - + salary_1 + ", blobType=" + blobType_1); + + salary_1 + ", blobType=" + blobType_1); await expect(false).assertEqual(resultSet.goToNextRow()) resultSet.close() @@ -1138,7 +1131,7 @@ export default function relationalStoreUpdateTest() { await expect(2).assertEqual(blobType[1]); await expect(3).assertEqual(blobType[2]); console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" - + salary + ", blobType=" + blobType); + + salary + ", blobType=" + blobType); await expect(true).assertEqual(resultSet.goToNextRow()) resultSet.close() @@ -1217,7 +1210,7 @@ export default function relationalStoreUpdateTest() { await expect(2).assertEqual(blobType[1]); await expect(3).assertEqual(blobType[2]); console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" - + salary + ", blobType=" + blobType); + + salary + ", blobType=" + blobType); await expect(true).assertEqual(resultSet.goToNextRow()) const id_1 = await resultSet.getLong(resultSet.getColumnIndex("id")) @@ -1234,7 +1227,7 @@ export default function relationalStoreUpdateTest() { await expect(8).assertEqual(blobType_1[1]); await expect(9).assertEqual(blobType_1[2]); console.log(TAG + "{id=" + id_1 + ", name=" + name_1 + ", age=" + age_1 + ", salary=" - + salary_1 + ", blobType=" + blobType_1); + + salary_1 + ", blobType=" + blobType_1); await expect(false).assertEqual(resultSet.goToNextRow()) resultSet.close() @@ -1306,7 +1299,7 @@ export default function relationalStoreUpdateTest() { await expect(5).assertEqual(blobType[1]); await expect(6).assertEqual(blobType[2]); console.log(TAG + "{id=" + id + ", name=" + name + ", age=" + age + ", salary=" - + salary + ", blobType=" + blobType); + + salary + ", blobType=" + blobType); await expect(false).assertEqual(resultSet.goToNextRow()) resultSet.close() -- GitLab