• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# ArkData Changelog
2
3## cl.arkdata.1 Added Error Code 14800020 to getRdbStore() in @ohos.data.relationalStore.d.ts
4**Access Level**
5
6Public API
7
8**Reason for Change**
9
10No error code is reported when the root key does not match the working key. The error code 14800020 is added to trigger the database restore and rebuild on the service side.
11
12**Change Impact**
13
14This change is a non-compatible change.
15
16Before the change, no error code is reported when the root key does not match the working key. As a result, the database cannot be restored on the service side.
17
18After the change, error code 14800020 is reported when the root key does not match the working key. This error code will trigger the restore and rebuild of the database on the service side.
19
20**Start API Level**
21
22API 9
23
24**Change Since**
25
26OpenHarmony 5.0.1.1
27
28**Key API/Component Changes**
29
30The following APIs in [@ohos.data.relationalStore.d.ts](https://gitee.com/openharmony/interface_sdk-js/blob/master/api/@ohos.data.relationalStore.d.ts):
31
321. function getRdbStore(context: Context, config: StoreConfig, callback: AsyncCallback\<RdbStore\>): void;
33
342. function getRdbStore(context: Context, config: StoreConfig): Promise\<RdbStore\>;
35
36**Adaptation Guide**
37
38If the error code 14800020 is thrown after **getRdbStore** is called, the database root key does not match the working key. In this case, the database needs to be rebuilt.
39```ts
40import { relationalStore } from '@kit.ArkData';
41import { BusinessError } from '@kit.BasicServicesKit';
42import { UIAbility } from '@kit.AbilityKit';
43import { window } from '@kit.ArkUI';
44
45const STORE_CONFIG: relationalStore.StoreConfig = {
46  name: "RdbTest.db",
47  securityLevel: relationalStore.SecurityLevel.S3,
48  encrypt: true
49};
50const CREATE_TABLE_TEST =
51  "CREATE TABLE IF NOT EXISTS EMPLOYEE (id INTEGER PRIMARY KEY AUTOINCREMENT,name TEXT NOT NULL, age INTEGER, salary REAL, blobType BLOB)";
52
53let store: relationalStore.RdbStore | undefined = undefined;
54relationalStore.getRdbStore(this.context, STORE_CONFIG, (err: BusinessError, rdbStore: relationalStore.RdbStore) => {
55  store = rdbStore;
56  store.executeSql(CREATE_TABLE_TEST);
57  if (err) {
58    console.error(`Get RdbStore failed, code is ${err.code},message is ${err.message}`);
59    // If err.code is 14800020, the database needs to be restored on the service side.
60    return;
61  }
62  console.info('Get RdbStore successfully.');
63})
64```
65