目录

vector-store数据库调试工具指导

当前开发者在使用vector-store数据库进行开发调试和定位问题时,无法查看数据库文件中的内容信息,如元数据和用户数据等。

为了提升开发者的工作效率,数据库调试工具支持开发者查看设备中的vector-store数据库内容。

从HarmonyOS 6.0.0版本开始,支持使用vector-store数据库调试工具。

环境要求

操作准备

命令参考

vector-store调试工具支持的命令如下表所示:

命令格式 命令描述
.help 显示帮助信息。
.q | .quit 退出数据库交互模式。
.mode <table|print> 设置输出模式, 默认是table。
.table 列出所有表名。
.index 列出所有索引名称。
.schema 列出表的schemas。
.count 列出所有表的记录总数。

vector-store调试工具操作用例如下表所示:

快捷操作 命令
创建表 create table
查询表 .table或者.schema
重命名表名 alter table t1 rename to new_t1;
增加表字段 alter table t1 add column c text;
重命名表字段 alter table t1 rename b to new_b;
删除表字段 alter table t1 drop column c;
删除表 drop table t1;
添加表索引 create index idx_1 on t3(a);
插入数据 insert into t2 values(1,'xx'),(2,'yy');
查询数据 select * from t1;
更新数据 update t1 set b = 'z' where a =3;
删除数据 delete from t1 where b = 'z';

约束限制

命令的具体使用及示例

[h2]帮助命令(.help)

打开vector-store数据库后,使用帮助命令可以查看其支持的命令。

vector>>> .help

[h2]创建或打开已有的数据库

  1. 执行hdc shell命令进入shell交互模式。

  2. 必须要先切换至目标调试应用路径下, 再进入已有db文件层级,执行"arkdata -t vector"新建一个数据库。

    C:\Users\*****>hdc shell
    $ cd /data/app/el1/100/database/com.test.myapplication   // 进入到目标调试应用路径下(当前路径为示例,开发者需自己获取调试应用路径)
    $ cd entry/rdb/                                          // 需要进入到有db文件的路径下,保证有读写权限,才能有权限创建新数据库.
    $ arkdata -t vector
    Enter ".help" for usage hints.
    vector>>>
  3. 创建新的数据库时,系统会自动生成以下类型的文件, 标签debug_hap_data_file代表属于调试应用。

    $ ls -lZ ./data/vector/
    total 176
    -rw------- 1 shell shell u:object_r:debug_hap_data_file:s0  77824 2025-08-12 20:12 arkdata
    -rw------- 1 shell shell u:object_r:debug_hap_data_file:s0   8208 2025-08-12 20:13 arkdata.ctrl
    -rw------- 1 shell shell u:object_r:debug_hap_data_file:s0  24592 2025-08-12 20:13 arkdata.ctrl.dwr
    -rw------- 1 shell shell u:object_r:debug_hap_data_file:s0    512 2025-08-12 20:13 arkdata.redo
    -rw------- 1 shell shell u:object_r:debug_hap_data_file:s0      8 2025-08-12 20:13 arkdata.safe
    -rw------- 1 shell shell u:object_r:debug_hap_data_file:s0  28672 2025-08-12 20:12 arkdata.undo
  4. 打开已有数据库。

    $ arkdata -t vector -f ./data/vector/arkdata
    Enter ".help" for usage hints.
    vector>>>

[h2]创建表

[h2]查询表

[h2]重命名表名

在vector>>>提示符下,通过"alter table t1 rename to new_t1;"命令重命名对应的表名,显示结果如下:

vector>>> .schema
+-------+------+----------+--------------------------------------+
| type  | name | tbl_name | sql                                  |
+-------+------+----------+--------------------------------------+
| TABLE | T1   | T1       | create table t1( a int, new_b text); |
+-------+------+----------+--------------------------------------+
vector>>> alter table t1 rename to new_t1;  // 更改t1的表名为new_t1
vector>>> .schema
+-------+--------+----------+------------------------------------------+
| type  | name   | tbl_name | sql                                      |
+-------+--------+----------+------------------------------------------+
| TABLE | NEW_T1 | NEW_T1   | create table NEW_T1( a int, new_b text); |
+-------+--------+----------+------------------------------------------+

[h2]增加表字段

在vector>>>提示符下,通过"alter table t1 add column c text;"命令进行增加表字段,显示结果如下:

vector>>> create table t1( a int, b text);
vector>>> .schema
+-------+------+----------+----------------------------------+
| type  | name | tbl_name | sql                              |
+-------+------+----------+----------------------------------+
| TABLE | T1   | T1       | create table t1( a int, b text); |
+-------+------+----------+----------------------------------+
vector>>> alter table t1 add column c text;  // 在t1的表中,增加一个名为c,内容类型为text的字段
vector>>> .schema
+-------+------+----------+------------------------------------------+
| type  | name | tbl_name | sql                                      |
+-------+------+----------+------------------------------------------+
| TABLE | T1   | T1       | create table t1( a int, b text, c text); |
+-------+------+----------+------------------------------------------+

[h2]重命名表字段

在vector>>>提示符下,通过"alter table t1 rename b to new_b;"命令重命名对应的表字段,显示结果如下:

vector>>> .schema
+-------+------+----------+----------------------------------+
| type  | name | tbl_name | sql                              |
+-------+------+----------+----------------------------------+
| TABLE | T1   | T1       | create table t1( a int, b text); |
+-------+------+----------+----------------------------------+
vector>>> alter table t1 rename b to new_b; // 重命名t1表b字段为new_b
vector>>> .schema
+-------+------+----------+--------------------------------------+
| type  | name | tbl_name | sql                                  |
+-------+------+----------+--------------------------------------+
| TABLE | T1   | T1       | create table t1( a int, new_b text); |
+-------+------+----------+--------------------------------------+

[h2]删除表字段

在vector>>>提示符下,通过"alter table t1 drop column c;"命令删除指表中指定字段,显示结果如下:

vector>>> .schema
+-------+------+----------+------------------------------------------+
| type  | name | tbl_name | sql                                      |
+-------+------+----------+------------------------------------------+
| TABLE | T1   | T1       | create table t1( a int, b text, c text); |
+-------+------+----------+------------------------------------------+
vector>>> alter table t1 drop column c;  // 删除t1表中名为c的字段
vector>>> .schema
+-------+------+----------+----------------------------------+
| type  | name | tbl_name | sql                              |
+-------+------+----------+----------------------------------+
| TABLE | T1   | T1       | create table t1( a int, b text); |
+-------+------+----------+----------------------------------+

[h2]删除表

在vector>>>提示符下,通过"drop table t1;"命令,删除数据库中的名为t1的表,显示结果如下:

vector>>>drop table t1;  // 删除表t1
vector>>>.table
+------+
| name |
+------+
| T2   |
+------+

[h2]添加表索引

在vector>>>提示符下,通过"create index idx_1 on t3(a);"命令给该表对应字段,添加索引,显示结果如下:

vector>>> create table t3(a int, b text);  // 仅在表内未添加数据的情况下才能创建索引。
vector>>> create index idx_1 on t3(a);     // 给该表对应字段,添加索引为idx_1
vector>>> .index
+-------+
| name  |
+-------+
| idx_1 |
+-------+

[h2]插入数据

[h2]查询数据

  1. 全表查询。

    • 在vector>>>提示符下,通过".mode print"和"select * from 表名;"命令查询指定表所有内容,显示结果如下:

      vector>>> .mode print
      vector>>> select * from t1;
      [row-0]
      a            = 1
      b            = x
      [row-1]
      a            = 2
      b            = y
    • 通过".mode table"和"select * from 表名;"命令查询指定表所有内容,显示结果如下:

      vector>>> .mode table
      vector>>> select * from t1;
      +----+---+
      | a  | b |
      +----+---+
      | 1  | x |
      | 2  | y |
      +----+---+
  2. 在vector>>>提示符下,通过"select * from 表名 where 筛选条件"命令查询指定key的键值对,显示结果如下:

    vector>>> select * from t1 where a =1;
    +----+---+
    | a  | b |
    +----+---+
    | 1  | x |
    +----+---+
  3. 在vector>>>提示符下,通过.count命令列出所有表的记录总数,显示结果如下:

    vector>>> .count
    +------------+--------------+
    | table_name | record_count |
    +------------+--------------+
    | T1         | 2            |
    | T2         | 2            |
    | T3         | 0            |
    +------------+--------------+

[h2]更新数据

在vector>>>提示符下,通过"update t1 set b = 'z' where a =3;"命令更新键值对,显示结果如下:

vector>>> select * from t1;
+----+----+
| a  | b  |
+----+----+
| 1  | x  |
| 2  | y  |
| 3  | xx |
+----+----+
vector>>> update t1 set b = 'z' where a =3;
vector>>> select * from t1;
+----+---+
| a  | b |
+----+---+
| 1  | x |
| 2  | y |
| 3  | z |
+----+---+

[h2]删除数据

在vector>>>提示符下,通过"delete from t1 where b = 'z';"命令删除表中指定键值对,显示结果如下:

vector>>> select * from t1;
+----+---+
| a  | b |
+----+---+
| 1  | x |
| 2  | y |
| 3  | z |
+----+---+
vector>>> delete from t1 where b = 'z';// 删除t1表中的z
vector>>> select * from t1;
+----+---+
| a  | b |
+----+---+
| 1  | x |
| 2  | y |
+----+---+

在vector>>>提示符下,可以使用 .q或者.quit命令退出数据库交互模式,显示结果如下:

vector>>>.q
$

模拟器支持情况

当前工具支持模拟器。

常见问题

[h2]如何删除字符

使用Ctrl+BackSpace删除单个字符,使用Ctrl+U删除全部字符。