可用于学习HarmonyOS中使用C-API进行关系型数据库操作,展示商品增删改查及筛选功能,核心为NDK封装RDB数据库与ArkUI界面交互。
Access rate limit exceeded. Please log in to continue.
Using C APIs to Read/Write a Relational Store
Overview
This sample shows how to use C APIs to add, delete, modify, and query a relational store.
Preview
| Home Page | Adding/Editing Offerings | Filtering Offerings |
|---|---|---|
![]() |
![]() |
![]() |
How to Use
- Tap Add to add an offering. After you tap Submit, the added offering information is displayed on the home page.
- Tap the edit icon to modify the information of an offering in the current list. After you tap Submit, the modified offering information is displayed on the home page.
- Tap the delete icon to delete an offering from the current list. After the deletion, the remaining offering information is displayed on the home page.
- Tap Offering to filter offerings by category. Mate 60/Mate 40 series offerings can be filtered and displayed in the offering list.
- Tap Price to filter offerings by price and display them on the home page.
- Tap the refresh icon to clear the filters. All offerings are displayed.
How to Implement
This sample consists of the following two parts:
-
Encapsulate an RDB store using the NDK:
(1) Encapsulate an RDB store using the NDK.
(2) Code files: RDB.h and RDB.cpp.
(3) For details, see RelationalStore Development (C/C++), Getting Started with the NDK.
-
Implement data interaction between ArkUI and C/C++:
(1) Implement data interaction between ArkUI and C/C++.
(2) Code files: napi_init.cpp, index.ets, and oh_modules/libentry.so/index.d.ts.
(3) For details, see Getting Started with the NDK.
Project Directory
├───entry/src/main/ets
│ ├───constant
│ │ └───FileConstants.ets // Encapsulation constants
│ ├───entryability
│ │ └───EntryAbility.ets // Ability lifecycle callbacks
│ ├───entrybackupability
│ │ └───EntryBackupAbility.ets // Backup ability lifecycle callbacks
│ ├───model
│ │ └───GoodModel.ets // Encapsulation offering class
│ └───pages
│ ├───Index.ets // Home page
│ └───GoodsList.ets // Offering list page
├───entry/src/main/cpp
│ ├───types/libentry/Index.d.ts // Function and type declarations
│ ├───RDB.h // Encapsulated RDB
│ ├───RDB.cpp // Encapsulated RDB
│ └───napi_init.cpp // Custom NDK functions encapsulated to ArkUI.
└───entry/src/main/resources // Static resources of the app
Permissions
N/A
Dependencies
N/A
Constraints
- The sample is only supported on bar phones with standard systems.
- The HarmonyOS version must be HarmonyOS 5.0.5 Release or later.
- The DevEco Studio version must be DevEco Studio 5.0.5 Release or later.
- The HarmonyOS SDK version must be HarmonyOS 5.0.5 Release SDK or later.
Introduction
可用于学习HarmonyOS中使用C-API进行关系型数据库操作,展示商品增删改查及筛选功能,核心为NDK封装RDB数据库与ArkUI界面交互。
Customize your domain

