1# Data Management Development 2 3 4## How do I encrypt an RDB store? (API version 9) 5 6**Solution** 7 8To encrypt an RDB store, set **encrypt** in **StoreConfig** to **true** when creating the RDB store. 9 10**Reference** 11 12[RDB Store](../reference/apis/js-apis-data-relationalStore.md#storeconfig) 13 14 15## What if I failed to clear a table in an RDB store by using TRUNCATE TABLE? (API version 9) 16 17**Symptom** 18 19An error is reported when the **TRUNCATE TABLE** statement is used to clear table data. 20 21**Solution** 22 23The RDB store uses SQLite, which 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'**. 24 25 26## What data types are supported by an RDB store? (API version 9) 27 28Applicable to: stage model 29 30**Solution** 31 32An 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. 33 34 35## How do I persistent application data? (API version 9) 36 37**Solution** 38 39You 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**. 40 41Example: 42 43``` 44AppStorage.Link('varA') 45PersistentStorage.PersistProp("varA", "111"); 46@Entry 47@Component 48struct Index { 49 @StorageLink('varA') varA: string = '' 50 build() { 51 Column() { 52 Text('varA: ' + this.varA).fontSize(20) 53 Button('Set').width(100).height(100).onClick(() => { 54 this.varA += '333' 55 }) 56 } 57 .width('100%') 58 .height('100%') 59 } 60} 61``` 62 63**Reference** 64 65[PersistentStorage](../quick-start/arkts-persiststorage.md) 66 67 68## How do I save pixel map data to a database? (API version 9) 69 70**Solution** 71 72Convert the pixel map data into an **ArrayBuffer** and save the **ArrayBuffer** to your database. 73 74**Reference** 75 76[readPixelsToBuffer](../reference/apis/js-apis-image.md#readpixelstobuffer7-1) 77 78 79## How do I obtain RDB store files? (API version 9) 80 81**Symptom** 82 83Problem of obtaining RDB store files. 84 85**Solution** 86 87The 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. 88 89Example: 90 91``` 92 hdc file recv /data/app/el2/100/database/<bundleName>/entry/db/<tableName> ./<path> 93``` 94 95 96## Should I design a lock mechanism for databases in development? (API version 9) 97 98**Symptom** 99 100I do not know whether I need to design a lock mechanism for databases in development. 101 102**Solution** 103 104The distributed data service (DDS), RDB store, and preferences provided by OpenHarmony come with a lock mechanism. You do not need to bother with the lock mechanism during the development. 105 106 107## What if I failed to use get() to obtain the data saved by @ohos.data.storage put()? (API version 9) 108 109**Symptom** 110 111After @ohos.data.storage **put()** is called to save data, **get()** is called to obtain the data. However, the data fails to be obtained. 112 113**Solution** 114 115The **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. 116 117 118## What if a large text file fails to be saved in an RDB store? (API version 9) 119 120**Symptom** 121 122In API version 8, large text files cannot be saved in RDB stores. 123 124**Solution** 125 126In 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. 127 128The limit on the text file size has been removed since API9 version. 129 130 131## What if "undefined" is returned by Preferences.get after Preferences.put is successful? (API version 9) 132 133**Symptom** 134 135Data is successfully saved using **preferences**, but fails to be obtained. 136 137**Solution** 138 1391. After **put()** is performed, use **flush()** to persist the data. 140 1412. Call **get()** after **flush()** is complete. 142 143 144## Can I specify the in-memory database mode when using an RDB store? (API version 9) 145 146**Solution** 147 148RDB stores use SQLite. The default in-memory database mode is file, which cannot be changed. 149