Call on('sqliteErrorOccurred') to obtain the error logs that occur during SQL execution.
Call relationalStore.getInsertSqlInfo to obtain the SQL statement used to insert data.
Call relationalStore.getUpdateSqlInfo to obtain the SQL statement used to update data.
Call relationalStore.getDeleteSqlInfo to obtain the SQL statement used to delete data.
Call relationalStore.getQuerySqlInfo to obtain the SQL statement used to query data.
When an RDB store is used, different file artifacts may be generated. The purpose of each file is described in the following table.
| File Type | Description |
|---|---|
| .db | Database persistent file, used to store database data. |
| .db-wal | Used to save operation logs, allowing changes to be rolled back upon transaction failure to ensure data consistency. This file exists only when the database uses WAL mode (the system default logging mode is WAL (Write Ahead Log) mode). |
| .db-shm | Shared memory file, used to coordinate changes to the same db file by multiple database connections to prevent data conflicts. This file exists only when the database uses WAL mode (the system default logging mode is WAL (Write Ahead Log) mode). |
| .key_lock | Used to save file lock information. |
| .pub_key | Used to save database key information. This file exists only when database encryption is configured and custom encryption parameters are not configured (that is, when encrypt is set to true via StoreConfig and cryptoParam is not configured). |
| .db-dwr | Used to save file header information. |
| .db-compare | Used to save all DDL statements. |
In an RDB store, when you call getRdbStore() to open an encrypted database with a raw key, configure the CryptoParam.encryptionKey parameter as follows:
import { relationalStore } from '@kit.ArkData'
import { buffer } from '@kit.ArkTS';
let password: string = "x'3605d7de19311edba4d3c88143c61cdd79dd5a58bc829c8b1234567891234567'"; // Replace with the actual database raw key (a 64-character hexadecimal string, corresponding to a 32-byte raw key).
let key = new Uint8Array(buffer.from(password, 'utf8').buffer); // Returns a Uint8Array.
// Configure encryption parameters.
const cryptoParam: relationalStore.CryptoParam = {
encryptionKey: key, // Mandatory. Specifies the key.
};