• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Data Management Development
2
3
4## How do I encrypt an RDB store?
5
6Applicable to: OpenHarmony 3.1 Beta 5 (API version 9)
7
8**Solution**
9
10To encrypt an RDB store, set **encrypt** in **StoreConfig** to **true** when creating the RDB store.
11
12**Reference**
13
14[RDB Store](../reference/apis/js-apis-data-relationalStore.md#storeconfig)
15
16## What if I failed to clear a table in an RDB store using TRUNCATE TABLE?
17
18Applicable to: OpenHarmony SDK 3.2.9.2 (API version 9)
19
20**Symptom**
21
22An error is reported when the **TRUNCATE TABLE** statement is used to clear table data.
23
24**Solution**
25
26The RDB store uses SQLite and does not support the **TRUNCATE TABLE** statement. To clear a table in an RDB store, use the **DELETE** statement, for example, **DELETE FROM sqlite\_sequence WHERE name = 'table\_name'**.
27
28## What data types does an RDB store support?
29
30Applicable to: OpenHarmony SDK 3.0 or later, API version 9 stage model
31
32**Solution**
33
34An RDB store supports data of the number, string, and Boolean types. The number type supports data of the Double, Long, Float, Int, or Int64 type, with a maximum precision of 17 decimal digits.
35
36## How do I persist application data?
37
38Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
39
40**Solution**
41
42You can use the **PersistentStorage** class to implement application data persistence. You can link the persistent data with specific tags to **AppStorage**, and invoke **AppStorage** APIs to access the persistent data. Persistent data is stored in a local XML file in **/data/app/el2/100/base/<bundleName\>/haps/<hapName\>/files/persistent\_storage**.
43
44Example:
45
46```
47AppStorage.Link('varA')
48PersistentStorage.PersistProp("varA", "111");
49@Entry
50@Component
51struct Index {
52  @StorageLink('varA') varA: string = ''
53  build() {
54    Column() {
55      Text('varA: ' + this.varA).fontSize(20)
56      Button('Set').width(100).height(100).onClick(() => {
57        this.varA += '333'
58      })
59    }
60    .width('100%')
61    .height('100%')
62  }
63}
64```
65
66**Reference**
67
68[Persistent Data Management\(OpenHarmony\)](../quick-start/arkts-persiststorage.md)
69
70## How do I save pixel map data to a database?
71
72Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
73
74**Solution**
75
76Convert the pixel map data into an **ArrayBuffer** and save the **ArrayBuffer** to your database.
77
78**Reference**
79
80[readPixelsToBuffer](../reference/apis/js-apis-image.md#readpixelstobuffer7-1)
81
82## How do I obtain RDB store files?
83
84Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
85
86**Symptom**
87
88Problem of obtaining RDB store files.
89
90**Solution**
91
92The RDB store files are stored in **/data/app/el2/100/database/*Bundle_name*/entry/rdb/**. You can use the hdc command to copy the file from the directory and use a SQLite tool to open the file.
93
94Example:
95
96```
97 hdc file recv /data/app/el2/100/database/<bundleName>/entry/db/<tableName>  ./<path>
98```
99
100## Do the OpenHarmony databases have a lock mechanism?
101
102Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
103
104**Symptom**
105
106I do not know whether I need to design a lock mechanism for databases in development.
107
108**Solution**
109
110The distributed data service (DDS), RDB store, and preferences provided OpenHarmony have a lock mechanism. You do not need to bother with the lock mechanism during the development.
111
112## What if I failed to use get() to obtain the data saved by @ohos.data.storage put()?
113
114Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
115
116**Symptom**
117
118After @ohos.data.storage **put()** is called to save data, **get()** is called to obtain the data. However, the data fails to be obtained.
119
120**Solution**
121
122The **put()** method provided by **@ohos.data.storage** saves data in the memory. When the application exits, the data in the memory will be cleared. If you want to persist the data, you need to call **flush()** or **flushSync()** after **put()**. After data is persisted, you can use **get()** to obtain the data after the application is restarted.
123
124
125## What if a large text file fails to be saved in an RDB store?
126
127Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
128
129**Symptom**
130
131In API version 8, large text files cannot be saved in RDB stores.
132
133**Solution**
134
135In versions earlier than API version 9, the maximum length of a text file is 1024 bytes. If the text file exceeds 1024 bytes, it cannot be saved.
136The limit on the text file size has been removed since API9 version.
137
138## What if **undefined** is returned by **Preferences.get** after **Preferences.put()** is successfully called?
139
140Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
141
142**Symptom**
143
144Data is successfully saved using **preferences**, but fails to be obtained.
145
146**Solution**
147
1481. After **put()** is performed, use **flush()** to persist the data.
149
1502. Wait until the **flush()** asynchronous operation is complete, and call **get()**.
151
152## Can I specify the in-memory database mode when using an RDB store?
153
154Applicable to: OpenHarmony 3.2 Beta 5 (API version 9)
155
156**Solution**
157
158RDB stores use SQLite. The default in-memory database mode is file, which cannot be modified.
159