提交 35f4fcd0 编写于 作者: M Maowen

<zhangmaowen@huawei.com>

Signed-off-by: NMaowen <zhangmaowen@huawei.com>
上级 23f43bd0
......@@ -23,4 +23,6 @@ require('./RdbstorePredicatesJsunit.test.js')
require('./RdbstoreRdbstoreJsunit.test.js')
require('./RdbstoreStoreExcuteSqlJsunit.test.js')
require('./RdbstoreUpdateJsunit.test.js')
require('./DataAbilityPredicatesJsunit.test.js')
\ No newline at end of file
require('./DataAbilityPredicatesJsunit.test.js')
require('./RdbstoreTransactionJsunit.test.js')
require('./RdbstorePredicatesJoinJsunit.test.js')
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import dataRdb from '@ohos.data.rdb';
const USER_TABLE = "CREATE TABLE IF NOT EXISTS user "
+ "(userId INTEGER PRIMARY KEY AUTOINCREMENT, firstName TEXT , lastName TEXT ,"
+ "age INTEGER , balance REAL NOT NULL)";
const BOOK_TABLE = "CREATE TABLE IF NOT EXISTS Book (id INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "name TEXT, userId INTEGER , "
+ "FOREIGN KEY (userId) REFERENCES user (userId) ON UPDATE NO ACTION ON DELETE CASCADE)";
const USER_BULK_INSERT_STATEMENT = "INSERT INTO user"
+ "(userId, firstName, lastName, age, balance) VALUES "
+ "(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?)";
const BOOK_BULK_INSERT_STATEMENT = "INSERT INTO Book (id, name, userId) "
+ "VALUES (?,?,?),(?,?,?),(?,?,?)";
const STORE_CONFIG = { name: "RdbJoinTest.db" }
const CURRENT_STORE_VERSION = 1;
const TAG = 'RDB_TEST';
var rdbStore = undefined;
describe('rdbStorePredicatesJoinTest', function () {
beforeAll(async function () {
console.info(TAG + 'beforeAll end')
})
beforeEach(async function () {
console.info(TAG + 'beforeEach')
rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, CURRENT_STORE_VERSION);
await generateUserTable();
await generateBookTable();
console.info(TAG + 'beforeEach end')
})
afterEach(async function () {
console.info(TAG + 'afterEach')
await dataRdb.deleteRdbStore("InsertTest.db");
rdbStore = null
console.info(TAG + 'afterEach end')
})
afterAll(async function () {
console.info(TAG + 'afterAll end')
})
async function generateUserTable() {
console.info(TAG + 'generateUserTable')
await rdbStore.executeSql(USER_TABLE);
const users = [
{userId:1, firstName:"Zhang", lastName:"San", age:29, balance:100.51},
{userId:2, firstName:"Li", lastName:"Si", age:30, balance:200.51},
{userId:3, firstName:"wang", lastName:"wu", age:30, balance:300.51},
{userId:4, firstName:"sun", lastName:"liu", age:30, balance:400.51},
{userId:5, firstName:"ma", lastName:"qi", age:32, balance:500.51},
];
var objects = new Array();
users.forEach((user) => {
objects.push(user.userId);
objects.push(user.firstName);
objects.push(user.lastName);
objects.push(user.age);
objects.push(user.balance);
});
await rdbStore.executeSql(USER_BULK_INSERT_STATEMENT, objects);
console.info(TAG + 'generateUserTable end')
}
async function generateBookTable() {
console.info(TAG + 'generateBookTable')
await rdbStore.executeSql(BOOK_TABLE);
var books = [
{id:1, name:"sanguo", userId:1},
{id:2, name:"xiyouji", userId:2},
{id:3, name:"shuihuchuan", userId:3},
]
var objects = new Array();
books.forEach(book => {
objects.push(book.id);
objects.push(book.name);
objects.push(book.userId);
});
await rdbStore.executeSql(BOOK_BULK_INSERT_STATEMENT, objects);
console.info(TAG + 'generateBookTable end')
}
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.name: testRdbJoin001
* @tc.desc: SUB_DDM_AppDataFWK_Rdb_Inner_Join
* @tc.type: FUNC
* @tc.require: I4NZP6
*/
it('testRdbJoin001', 0, async function (done) {
console.log(TAG + "testRdbJoin001 begin.");
let resultSet = await rdbStore.querySql(
"SELECT * FROM user INNER JOIN Book ON user.userId = Book.id WHERE Book.name = 'sanguo'")
expect(1).assertEqual(resultSet.rowCount);
expect(true).assertEqual(resultSet.goToFirstRow());
expect(1).assertEqual(resultSet.getInt(0));
expect("Zhang").assertEqual(resultSet.getString(1));
expect("San").assertEqual(resultSet.getString(2));
expect(29).assertEqual(resultSet.getInt(3));
expect(100.51).assertEqual(resultSet.getDouble(4));
expect(1).assertEqual(resultSet.getInt(5));
expect("sanguo").assertEqual(resultSet.getString(6));
expect(1).assertEqual(resultSet.getInt(7));
done();
})
/**
* @tc.name: testRdbJoin002
* @tc.desc: SUB_DDM_AppDataFWK_Rdb_Cross_Join
* @tc.type: FUNC
* @tc.require: I4NZP6
*/
it('testRdbJoin002', 0, async function (done) {
console.log(TAG + "testRdbJoin002 begin.");
let resultSet = await rdbStore.querySql("" +
"SELECT * FROM user CROSS JOIN Book USING(userId) WHERE Book.name = 'sanguo'");
expect(1).assertEqual(resultSet.rowCount);
expect(true).assertEqual(resultSet.goToFirstRow());
expect(1).assertEqual(resultSet.getInt(0));
expect("Zhang").assertEqual(resultSet.getString(1));
expect("San").assertEqual(resultSet.getString(2));
expect(29).assertEqual(resultSet.getInt(3));
expect(100.51).assertEqual(resultSet.getDouble(4));
expect(1).assertEqual(resultSet.getInt(5));
expect("sanguo").assertEqual(resultSet.getString(6));
done();
done();
})
/**
* @tc.name: testRdbJoin003
* @tc.desc: SUB_DDM_AppDataFWK_Rdb_Left_Outer_Join
* @tc.type: FUNC
* @tc.require: I4NZP6
*/
it('testRdbJoin003', 0, async function (done) {
console.log(TAG + "testRdbJoin003 begin.");
let resultSet = await rdbStore.querySql("" +
"SELECT * FROM user LEFT OUTER JOIN Book USING(userId) WHERE Book.name = 'sanguo'");
expect(1).assertEqual(resultSet.rowCount);
expect(true).assertEqual(resultSet.goToFirstRow());
expect(1).assertEqual(resultSet.getInt(0));
expect("Zhang").assertEqual(resultSet.getString(1));
expect("San").assertEqual(resultSet.getString(2));
expect(29).assertEqual(resultSet.getInt(3));
expect(100.51).assertEqual(resultSet.getDouble(4));
expect(1).assertEqual(resultSet.getInt(5));
expect("sanguo").assertEqual(resultSet.getString(6));
done();
})
console.log(TAG + "*************Unit Test End*************");
})
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
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, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
const STORE_CONFIG = {
name: "InsertTest.db",
}
var rdbStore = undefined;
describe('rdbStoreInsertTest', 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("Delete.db");
})
afterAll(async function () {
console.info(TAG + 'afterAll')
})
console.log(TAG + "*************Unit Test Begin*************");
/**
* @tc.name rdb transaction insert test
* @tc.number SUB_DDM_AppDataFWK_testRdbTransactionInsert0001
* @tc.desc rdb transaction insert & commit, the result comes out is 3 items;
*/
it('testRdbTransactionInsert0001', 0, async function (done) {
console.log(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.log(TAG + "testRdbTransactionInsert0001 result count " + resultSet.rowCount)
expect(1).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
} catch (e) {
console.log(TAG + e);
expect(null).assertFail()
console.log(TAG + "testRdbTransactionInsert0001 failed");
}
done()
console.log(TAG + "************* testRdbTransactionInsert0001 end *************");
})
/**
* @tc.name rdb transaction insert test
* @tc.number SUB_DDM_AppDataFWK_testRdbTransactionInsert0002
* @tc.desc rdb transaction insert & commit, the result comes out is 3 items;
*/
it('testRdbTransactionInsert0002', 0, async function (done) {
console.log(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.log(TAG + "testRdbTransactionInsert0002 failed");
}
done()
console.log(TAG + "************* testRdbTransactionInsert0002 end *************");
})
/**
* @tc.name rdb transaction insert test
* @tc.number SUB_DDM_AppDataFWK_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.log(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.log(TAG + "testRdbTransactionInsert0003 failed");
}
done()
console.log(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.log(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.log(TAG + "testRdbTransactionRollBack0001 result count " + resultSet.rowCount);
expect(0).assertEqual(resultSet.rowCount)
resultSet.close()
// resultSet == null;
}
done()
console.log(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.log(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,
}
let num = rdbStore.insert("test", valueBucket1)
num.then(async (ret) => {
console.log(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.log(TAG + "testRdbTransactionMulti0001 fail ***** ");
}
done()
console.log(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.log(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, function (err, ret){
});
await rdbStore.beginTransaction()
const valueBucket1 = {
"name": "zhangsan",
"age": 20,
"salary": 220.5,
"blobType": u8,
}
let num = rdbStore.insert("test", valueBucket1)
num.then(async (ret) => {
console.log(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.log(TAG + "testRdbTransactionMulti0002 * final query " + ret.rowCount);
expect(1).assertEqual(ret.rowCount)
ret.close()
})
} catch (e) {
console.log(TAG + "testRdbTransactionMulti0002 fail ***** ");
}
done()
console.log(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.log(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, 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.log(TAG + "testRdbTransactionMulti0003 * final query " + ret.rowCount);
expect(1).assertEqual(ret.rowCount)
ret.close()
})
} catch (e) {
await rdbStore.rollBack()
console.log(TAG + "testRdbTransactionMulti0003 rollback ***** ");
}
done()
console.log(TAG + "************* testRdbTransactionMulti0003 end *************");
})
/**
* @tc.name rdb update test
* @tc.number SUB_DDM_AppDataFWK_JSRDB_Transaction_Update_0010
* @tc.desc the classical transaction scenario, when we update or commit the value,
* db returns an exception, we need to catch exception and rollback.
*/
it('testRdbTransactionUpdate0001', 0, async function (done) {
console.log(TAG + "************* testRdbTransactionUpdate0001 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.log(TAG + "testRdbTransactionUpdate0001 result count " + resultSet.rowCount)
expect(1).assertEqual(resultSet.rowCount)
// resultSet == null;
} catch (e) {
console.log(TAG + e);
expect(null).assertFail()
console.log(TAG + "testRdbTransactionUpdate0001 failed");
}
//更新
{
var u8 = new Uint8Array([4, 5, 6])
const valueBucket = {
"name": "zhangsan",
"age": 20,
"salary": 200.5,
"blobType": u8,
}
let predicates = await new dataRdb.RdbPredicates("test")
await predicates.equalTo("id", "1")
let updatePromise = rdbStore.update(valueBucket, predicates)
updatePromise.then(async (ret) => {
await expect(1).assertEqual(ret);
await console.log(TAG + "testRdbTransactionUpdate0001 update done: " + ret);
//查询
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(20).assertEqual(age);
await expect(200.5).assertEqual(salary);
await expect(4).assertEqual(blobType[0]);
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);
await expect(false).assertEqual(resultSet.goToNextRow())
resultSet = null
}).catch((err) => {
console.log(TAG + "testRdbTransactionUpdate0001 update error");
expect(null).assertFail();
})
//await updatePromise
}
done()
console.log(TAG + "************* testRdbTransactionUpdate0001 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.log(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.log(TAG + "testRdbTransactionInsert0003 failed");
}
//删除
{
let predicates = await new dataRdb.RdbPredicates("test")
let deletePromise = rdbStore.delete(predicates)
deletePromise.then(async (ret) => {
expect(3).assertEqual(ret)
console.log(TAG + "Delete done: " + ret)
}).catch((err) => {
expect(null).assertFail()
})
await deletePromise
}
done()
console.log(TAG + "************* testRdbTransactionDelete0001 end *************");
})
console.log(TAG + "*************Unit Test End*************");
})
\ No newline at end of file
......@@ -23,25 +23,25 @@ const STORE_CONFIG = {
var rdbStore = undefined;
describe('rdbStoreUpdateTest', function () {
beforeAll(async function () {
beforeAll(function () {
console.info(TAG + 'beforeAll')
rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null);
})
beforeEach(async function () {
await rdbStore.executeSql("DELETE FROM test");
console.info(TAG + 'beforeEach')
rdbStore = await dataRdb.getRdbStore(STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null);
})
afterEach(function () {
afterEach(async function () {
console.info(TAG + 'afterEach')
await rdbStore.executeSql("DELETE FROM test");
rdbStore = null
await dataRdb.deleteRdbStore("Delete.db");
})
afterAll(async function () {
console.info(TAG + 'afterAll')
rdbStore = null
await dataRdb.deleteRdbStore("UpdataTest.db");
})
/**
......@@ -84,35 +84,31 @@ describe('rdbStoreUpdateTest', function () {
updatePromise.then(async (ret) => {
await expect(1).assertEqual(ret);
await console.log(TAG + "update done: " + ret);
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("lisi").assertEqual(name);
await expect(20).assertEqual(age);
await expect(200.5).assertEqual(salary);
await expect(4).assertEqual(blobType[0]);
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);
await expect(false).assertEqual(resultSet.goToNextRow())
resultSet = null
}).catch((err) => {
console.log(TAG + "update error");
expect(null).assertFail();
})
//await updatePromise
}
//查询
{
let predicates = await new dataRdb.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("lisi").assertEqual(name);
await expect(20).assertEqual(age);
await expect(200.5).assertEqual(salary);
await expect(4).assertEqual(blobType[0]);
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);
await expect(false).assertEqual(resultSet.goToNextRow())
resultSet = null
}
done();
console.log(TAG + "************* testRdbStoreUpdate0001 end *************");
})
......@@ -262,4 +258,4 @@ describe('rdbStoreUpdateTest', function () {
})
console.log(TAG + "*************Unit Test End*************");
})
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册