diff --git a/en/application-dev/database/database-relational-guidelines.md b/en/application-dev/database/database-relational-guidelines.md index a4acbd9a7b47dca4332c7f6a881939b1928abd78..bd38925cbe8a17e5cb6319ffc9729ef263945e9c 100644 --- a/en/application-dev/database/database-relational-guidelines.md +++ b/en/application-dev/database/database-relational-guidelines.md @@ -196,17 +196,41 @@ Table 15 Transaction APIs (3) Create an RDB store. - The sample code is as follows: + FA model: ```js - import data_rdb from '@ohos.data.rdb' + import data_rdb from '@ohos.data.rdb' + // Obtain the context. + import featureAbility from '@ohos.ability.featureAbility' + let context = featureAbility.getContext() + + 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)"; - const STORE_CONFIG = { name: "rdbstore.db" } - data_rdb.getRdbStore(this.context, STORE_CONFIG, 1, function (err, rdbStore) { + const STORE_CONFIG = { name: "RdbTest.db" } + data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) { rdbStore.executeSql(CREATE_TABLE_TEST) console.info('create table done.') - }) + }) + ``` + Stage model: + ```ts + import data_rdb from '@ohos.data.rdb' + // Obtain the context. + import Ability from '@ohos.application.Ability' + let context = null + class MainAbility extends Ability { + onWindowStageCreate(windowStage) { + context = this.context + } + } + + 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 STORE_CONFIG = { name: "rdbstore.db" } + data_rdb.getRdbStore(context, STORE_CONFIG, 1, function (err, rdbStore) { + rdbStore.executeSql(CREATE_TABLE_TEST) + console.info('create table done.') + }) ``` 2. Insert data.