提交 07ce031c 编写于 作者: O openharmony_ci 提交者: Gitee

!839 add parameter context to getRdbstore and deleteRdbstore

Merge pull request !839 from smagicyun/master
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import ohos_data_rdb from '@ohos.data.rdb'; import ohos_data_rdb from '@ohos.data.rdb';
import data_dataability from '@ohos.data.dataability'; import data_dataability from '@ohos.data.dataability';
import ability_featureAbility from '@ohos.ability.featureAbility';
const TAG = "[RDB_JSKITS _TEST]" const TAG = "[RDB_JSKITS _TEST]"
const CREATE_TABLE_ALL_DATA_TYPE_SQL = "CREATE TABLE IF NOT EXISTS AllDataType " const CREATE_TABLE_ALL_DATA_TYPE_SQL = "CREATE TABLE IF NOT EXISTS AllDataType "
...@@ -30,11 +31,13 @@ const STORE_CONFIG = { ...@@ -30,11 +31,13 @@ const STORE_CONFIG = {
name: "Predicates.db", name: "Predicates.db",
} }
var rdbStore = undefined; var rdbStore = undefined;
var context = undefined;
describe('dataAbilityPredicatesTest', function () { describe('dataAbilityPredicatesTest', function () {
beforeAll(async function () { beforeAll(async function () {
console.info(TAG + 'beforeAll') console.info(TAG + 'beforeAll')
rdbStore = await ohos_data_rdb.getRdbStore(STORE_CONFIG, 1); context = await ability_featureAbility.getContext();
rdbStore = await ohos_data_rdb.getRdbStore(context, STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_ALL_DATA_TYPE_SQL, null); await rdbStore.executeSql(CREATE_TABLE_ALL_DATA_TYPE_SQL, null);
await buildAllDataType1(); await buildAllDataType1();
await buildAllDataType2(); await buildAllDataType2();
...@@ -52,7 +55,7 @@ describe('dataAbilityPredicatesTest', function () { ...@@ -52,7 +55,7 @@ describe('dataAbilityPredicatesTest', function () {
afterAll(async function () { afterAll(async function () {
console.info(TAG + 'afterAll') console.info(TAG + 'afterAll')
rdbStore = null rdbStore = null
await ohos_data_rdb.deleteRdbStore("Predicates.db"); await ohos_data_rdb.deleteRdbStore(context, "Predicates.db");
}) })
function resultSize(resultSet) { function resultSize(resultSet) {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import data_rdb from '@ohos.data.rdb' import data_rdb from '@ohos.data.rdb'
import ability_featureAbility from '@ohos.ability.featureAbility';
const TAG = "[RDB_JSKITS_TEST]" const TAG = "[RDB_JSKITS_TEST]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "data1 text," + "data2 long, " + "data3 double," + "data4 blob)"; const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "data1 text," + "data2 long, " + "data3 double," + "data4 blob)";
...@@ -22,11 +23,13 @@ const STORE_CONFIG = { ...@@ -22,11 +23,13 @@ const STORE_CONFIG = {
name: "Resultset.db", name: "Resultset.db",
} }
var rdbStore = undefined; var rdbStore = undefined;
var context = undefined;
describe('rdbResultSetTest', function () { describe('rdbResultSetTest', function () {
beforeAll(async function () { beforeAll(async function () {
console.info(TAG + 'beforeAll') console.info(TAG + 'beforeAll')
rdbStore = await data_rdb.getRdbStore(STORE_CONFIG, 1); context = await ability_featureAbility.getContext();
rdbStore = await data_rdb.getRdbStore(context, STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null); await rdbStore.executeSql(CREATE_TABLE_TEST, null);
await createTest(); await createTest();
}) })
...@@ -42,7 +45,7 @@ describe('rdbResultSetTest', function () { ...@@ -42,7 +45,7 @@ describe('rdbResultSetTest', function () {
afterAll(async function () { afterAll(async function () {
console.info(TAG + 'afterAll') console.info(TAG + 'afterAll')
rdbStore = null rdbStore = null
await data_rdb.deleteRdbStore("Resultset.db"); await data_rdb.deleteRdbStore(context, "Resultset.db");
}) })
//插入数据 //插入数据
async function createTest() { async function createTest() {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import ohos_data_rdb from '@ohos.data.rdb'; import ohos_data_rdb from '@ohos.data.rdb';
import ability_featureAbility from '@ohos.ability.featureAbility';
const TAG = "[RDB_JSKITS_TEST]" 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_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
...@@ -22,6 +23,7 @@ const STORE_CONFIG = { ...@@ -22,6 +23,7 @@ const STORE_CONFIG = {
name: "Delete.db", name: "Delete.db",
} }
var rdbStore = undefined; var rdbStore = undefined;
var context = undefined;
describe('rdbStoreDeleteTest', function () { describe('rdbStoreDeleteTest', function () {
beforeAll(function () { beforeAll(function () {
...@@ -30,7 +32,8 @@ describe('rdbStoreDeleteTest', function () { ...@@ -30,7 +32,8 @@ describe('rdbStoreDeleteTest', function () {
beforeEach(async function () { beforeEach(async function () {
console.info(TAG + 'beforeEach') console.info(TAG + 'beforeEach')
rdbStore = await ohos_data_rdb.getRdbStore(STORE_CONFIG, 1); context = await ability_featureAbility.getContext();
rdbStore = await ohos_data_rdb.getRdbStore(context, STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null); await rdbStore.executeSql(CREATE_TABLE_TEST, null);
}) })
...@@ -38,7 +41,7 @@ describe('rdbStoreDeleteTest', function () { ...@@ -38,7 +41,7 @@ describe('rdbStoreDeleteTest', function () {
console.info(TAG + 'afterEach') console.info(TAG + 'afterEach')
await rdbStore.executeSql("DELETE FROM test"); await rdbStore.executeSql("DELETE FROM test");
rdbStore = null rdbStore = null
await ohos_data_rdb.deleteRdbStore("Delete.db"); await ohos_data_rdb.deleteRdbStore(context, "Delete.db");
}) })
afterAll(async function () { afterAll(async function () {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import ohos_data_rdb from '@ohos.data.rdb'; import ohos_data_rdb from '@ohos.data.rdb';
import ability_featureAbility from '@ohos.ability.featureAbility';
const TAG = "[RDB_JSKITS_TEST]" 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_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
...@@ -24,11 +25,13 @@ const STORE_CONFIG = { ...@@ -24,11 +25,13 @@ const STORE_CONFIG = {
} }
var rdbStore = undefined; var rdbStore = undefined;
var context = undefined;
describe('rdbStoreInsertTest', function () { describe('rdbStoreInsertTest', function () {
beforeAll(async function () { beforeAll(async function () {
console.info(TAG + 'beforeAll') console.info(TAG + 'beforeAll')
rdbStore = await ohos_data_rdb.getRdbStore(STORE_CONFIG, 1); context = await ability_featureAbility.getContext();
rdbStore = await ohos_data_rdb.getRdbStore(context, STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null); await rdbStore.executeSql(CREATE_TABLE_TEST, null);
}) })
...@@ -44,7 +47,7 @@ describe('rdbStoreInsertTest', function () { ...@@ -44,7 +47,7 @@ describe('rdbStoreInsertTest', function () {
afterAll(async function () { afterAll(async function () {
console.info(TAG + 'afterAll') console.info(TAG + 'afterAll')
rdbStore = null rdbStore = null
await ohos_data_rdb.deleteRdbStore("InsertTest.db"); await ohos_data_rdb.deleteRdbStore(context, "InsertTest.db");
}) })
console.log(TAG + "*************Unit Test Begin*************"); console.log(TAG + "*************Unit Test Begin*************");
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import ohos_data_rdb from '@ohos.data.rdb'; import ohos_data_rdb from '@ohos.data.rdb';
import ability_featureAbility from '@ohos.ability.featureAbility';
const TAG = "[RDB_JSKITS _TEST]" const TAG = "[RDB_JSKITS _TEST]"
const CREATE_TABLE_ALL_DATA_TYPE_SQL = "CREATE TABLE IF NOT EXISTS AllDataType " const CREATE_TABLE_ALL_DATA_TYPE_SQL = "CREATE TABLE IF NOT EXISTS AllDataType "
...@@ -29,11 +30,13 @@ const STORE_CONFIG = { ...@@ -29,11 +30,13 @@ const STORE_CONFIG = {
name: "Predicates.db", name: "Predicates.db",
} }
var rdbStore = undefined; var rdbStore = undefined;
var context = undefined;
describe('rdbPredicatesTest', function () { describe('rdbPredicatesTest', function () {
beforeAll(async function () { beforeAll(async function () {
console.info(TAG + 'beforeAll') console.info(TAG + 'beforeAll')
rdbStore = await ohos_data_rdb.getRdbStore(STORE_CONFIG, 1); context = await ability_featureAbility.getContext();
rdbStore = await ohos_data_rdb.getRdbStore(context, STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_ALL_DATA_TYPE_SQL, null); await rdbStore.executeSql(CREATE_TABLE_ALL_DATA_TYPE_SQL, null);
await buildAllDataType1(); await buildAllDataType1();
await buildAllDataType2(); await buildAllDataType2();
...@@ -51,7 +54,7 @@ describe('rdbPredicatesTest', function () { ...@@ -51,7 +54,7 @@ describe('rdbPredicatesTest', function () {
afterAll(async function () { afterAll(async function () {
console.info(TAG + 'afterAll') console.info(TAG + 'afterAll')
rdbStore = null rdbStore = null
await ohos_data_rdb.deleteRdbStore("Predicates.db"); await ohos_data_rdb.deleteRdbStore(context, "Predicates.db");
}) })
function resultSize(resultSet) { function resultSize(resultSet) {
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import ohos_data_rdb from '@ohos.data.rdb'; import ohos_data_rdb from '@ohos.data.rdb';
import ability_featureAbility from '@ohos.ability.featureAbility';
const TAG = "[RDB_JSKITS_TEST]" 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_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
...@@ -22,10 +23,11 @@ const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIM ...@@ -22,10 +23,11 @@ const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIM
const STORE_CONFIG = { const STORE_CONFIG = {
name: "rdbstore.db", name: "rdbstore.db",
} }
var context = undefined;
describe('rdbStoreTest', function () { describe('rdbStoreTest', function () {
beforeAll(async function () { beforeAll(async function () {
console.info(TAG + 'beforeAll') console.info(TAG + 'beforeAll')
context = await ability_featureAbility.getContext();
}) })
beforeEach(function () { beforeEach(function () {
...@@ -49,7 +51,7 @@ describe('rdbStoreTest', function () { ...@@ -49,7 +51,7 @@ describe('rdbStoreTest', function () {
*/ */
it('testRdbStore0001', 0, async function (done) { it('testRdbStore0001', 0, async function (done) {
console.log(TAG + "************* testRdbStore0001 start *************"); console.log(TAG + "************* testRdbStore0001 start *************");
let storePromise = ohos_data_rdb.getRdbStore(STORE_CONFIG, 1); let storePromise = ohos_data_rdb.getRdbStore(context, STORE_CONFIG, 1);
storePromise.then(async (store) => { storePromise.then(async (store) => {
try { try {
await console.log(TAG + "getRdbStore done: " + store); await console.log(TAG + "getRdbStore done: " + store);
...@@ -61,7 +63,7 @@ describe('rdbStoreTest', function () { ...@@ -61,7 +63,7 @@ describe('rdbStoreTest', function () {
}) })
await storePromise await storePromise
storePromise = null storePromise = null
await ohos_data_rdb.deleteRdbStore("rdbstore.db"); await ohos_data_rdb.deleteRdbStore(context, "rdbstore.db");
done(); done();
console.log(TAG + "************* testRdbStore0001 end *************"); console.log(TAG + "************* testRdbStore0001 end *************");
}) })
...@@ -73,7 +75,7 @@ describe('rdbStoreTest', function () { ...@@ -73,7 +75,7 @@ describe('rdbStoreTest', function () {
*/ */
it('testRdbStore0002', 0, async function (done) { it('testRdbStore0002', 0, async function (done) {
console.log(TAG + "************* testRdbStore0002 start *************"); console.log(TAG + "************* testRdbStore0002 start *************");
let storePromise = ohos_data_rdb.getRdbStore(STORE_CONFIG, 2); let storePromise = ohos_data_rdb.getRdbStore(context, STORE_CONFIG, 2);
storePromise.then(async (store) => { storePromise.then(async (store) => {
try { try {
await console.log(TAG + "getRdbStore done: " + store); await console.log(TAG + "getRdbStore done: " + store);
...@@ -86,7 +88,7 @@ describe('rdbStoreTest', function () { ...@@ -86,7 +88,7 @@ describe('rdbStoreTest', function () {
}) })
await storePromise await storePromise
storePromise = null storePromise = null
await ohos_data_rdb.deleteRdbStore("rdbstore.db"); await ohos_data_rdb.deleteRdbStore(context, "rdbstore.db");
done(); done();
console.log(TAG + "************* testRdbStore0002 end *************"); console.log(TAG + "************* testRdbStore0002 end *************");
}) })
...@@ -102,7 +104,7 @@ describe('rdbStoreTest', function () { ...@@ -102,7 +104,7 @@ describe('rdbStoreTest', function () {
let storeConfig = { let storeConfig = {
name: "/wrong/rdbstore.db", name: "/wrong/rdbstore.db",
} }
let storePromise = ohos_data_rdb.getRdbStore(storeConfig, 4); let storePromise = ohos_data_rdb.getRdbStore(context, storeConfig, 4);
storePromise.then(async (ret) => { storePromise.then(async (ret) => {
await console.log(TAG + "getRdbStore done" + ret); await console.log(TAG + "getRdbStore done" + ret);
expect(null).assertFail(); expect(null).assertFail();
...@@ -122,7 +124,7 @@ describe('rdbStoreTest', function () { ...@@ -122,7 +124,7 @@ describe('rdbStoreTest', function () {
it('testRdbStore0004', 0, async function (done) { it('testRdbStore0004', 0, async function (done) {
console.log(TAG + "************* testRdbStore0004 start *************"); console.log(TAG + "************* testRdbStore0004 start *************");
let storePromise = ohos_data_rdb.getRdbStore(STORE_CONFIG, 6); let storePromise = ohos_data_rdb.getRdbStore(context, STORE_CONFIG, 6);
storePromise.then(async (store) => { storePromise.then(async (store) => {
try { try {
await store.executeSql(CREATE_TABLE_TEST); await store.executeSql(CREATE_TABLE_TEST);
...@@ -134,7 +136,7 @@ describe('rdbStoreTest', function () { ...@@ -134,7 +136,7 @@ describe('rdbStoreTest', function () {
}) })
await storePromise await storePromise
storePromise = null storePromise = null
await ohos_data_rdb.deleteRdbStore("rdbstore.db"); await ohos_data_rdb.deleteRdbStore(context, "rdbstore.db");
done(); done();
console.log(TAG + "************* testRdbStore0004 end *************"); console.log(TAG + "************* testRdbStore0004 end *************");
}) })
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import ohos_data_rdb from '@ohos.data.rdb'; import ohos_data_rdb from '@ohos.data.rdb';
import ability_featureAbility from '@ohos.ability.featureAbility';
const TAG = "[RDB_JSKITS_TEST]" const TAG = "[RDB_JSKITS_TEST]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name NOT NULL, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
...@@ -22,11 +23,13 @@ const STORE_CONFIG = { ...@@ -22,11 +23,13 @@ const STORE_CONFIG = {
name: "ExcuteSqlTest.db", name: "ExcuteSqlTest.db",
} }
var rdbStore = undefined; var rdbStore = undefined;
var context = undefined;
describe('rdbStoreInsertTest', function () { describe('rdbStoreInsertTest', function () {
beforeAll(async function () { beforeAll(async function () {
console.info(TAG + 'beforeAll') console.info(TAG + 'beforeAll')
rdbStore = await ohos_data_rdb.getRdbStore(STORE_CONFIG, 1); context = await ability_featureAbility.getContext();
rdbStore = await ohos_data_rdb.getRdbStore(context, STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null); await rdbStore.executeSql(CREATE_TABLE_TEST, null);
}) })
...@@ -42,7 +45,7 @@ describe('rdbStoreInsertTest', function () { ...@@ -42,7 +45,7 @@ describe('rdbStoreInsertTest', function () {
afterAll(async function () { afterAll(async function () {
console.info(TAG + 'afterAll') console.info(TAG + 'afterAll')
rdbStore = null rdbStore = null
await ohos_data_rdb.deleteRdbStore("ExcuteSqlTest.db"); await ohos_data_rdb.deleteRdbStore(context, "ExcuteSqlTest.db");
}) })
/** /**
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index'
import ohos_data_rdb from '@ohos.data.rdb'; import ohos_data_rdb from '@ohos.data.rdb';
import ability_featureAbility from '@ohos.ability.featureAbility';
const TAG = "[RDB_JSKITS_TEST]" const TAG = "[RDB_JSKITS_TEST]"
const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT UNIQUE, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)"; const CREATE_TABLE_TEST = "CREATE TABLE IF NOT EXISTS test (" + "id INTEGER PRIMARY KEY AUTOINCREMENT, " + "name TEXT UNIQUE, " + "age INTEGER, " + "salary REAL, " + "blobType BLOB)";
...@@ -21,11 +22,13 @@ const STORE_CONFIG = { ...@@ -21,11 +22,13 @@ const STORE_CONFIG = {
name: "UpdataTest.db", name: "UpdataTest.db",
} }
var rdbStore = undefined; var rdbStore = undefined;
var context = undefined;
describe('rdbStoreUpdateTest', function () { describe('rdbStoreUpdateTest', function () {
beforeAll(async function () { beforeAll(async function () {
console.info(TAG + 'beforeAll') console.info(TAG + 'beforeAll')
rdbStore = await ohos_data_rdb.getRdbStore(STORE_CONFIG, 1); context = await ability_featureAbility.getContext();
rdbStore = await ohos_data_rdb.getRdbStore(context, STORE_CONFIG, 1);
await rdbStore.executeSql(CREATE_TABLE_TEST, null); await rdbStore.executeSql(CREATE_TABLE_TEST, null);
}) })
...@@ -41,7 +44,7 @@ describe('rdbStoreUpdateTest', function () { ...@@ -41,7 +44,7 @@ describe('rdbStoreUpdateTest', function () {
afterAll(async function () { afterAll(async function () {
console.info(TAG + 'afterAll') console.info(TAG + 'afterAll')
rdbStore = null rdbStore = null
await ohos_data_rdb.deleteRdbStore("UpdataTest.db"); await ohos_data_rdb.deleteRdbStore(context, "UpdataTest.db");
}) })
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册