Skip to content

Commit 055014c

Browse files
committed
Document for sys_guid function.
1 parent 40dc36c commit 055014c

File tree

6 files changed

+118
-0
lines changed

6 files changed

+118
-0
lines changed

CN/modules/ROOT/nav.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
**** xref:master/6.3.7.adoc[嵌套子函数]
3131
**** xref:master/6.3.8.adoc[Force View]
3232
**** xref:master/6.3.9.adoc[大小写转换]
33+
**** xref:master/6.3.10.adoc[sys_guid 函数]
3334
*** xref:master/6.4.adoc[国标GB18030]
3435
*** 内置函数
3536
**** xref:master/6.4.1.adoc[sys_context]
@@ -55,6 +56,7 @@
5556
*** xref:master/7.17.adoc[17、NLS 参数]
5657
*** xref:master/7.18.adoc[18、Force View]
5758
*** xref:master/7.19.adoc[19、嵌套子函数]
59+
*** xref:master/7.20.adoc[20、sys_guid 函数]
5860
** IvorySQL贡献指南
5961
*** xref:master/8.1.adoc[社区贡献指南]
6062
*** xref:master/8.2.adoc[asciidoc语法快速参考]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
:sectnums:
2+
:sectnumlevels: 5
3+
4+
:imagesdir: ./_images
5+
6+
= sys_guid() 函数
7+
8+
== 目的
9+
10+
IvorySQL的sys_guid() 是一个强大的随机数产生函数,它产生并返回一个由16个字节组成的数据库级别唯一的标识符(原始值)。
11+
12+
== 实现说明
13+
14+
IvorySQL的sys_guid()函数通过修改插件uuid-ossp的代码实现。为了充分利用uuid的多种基础库,采用如下逻辑:
15+
16+
1. 如果系统有uuid-ossp,就使用uuid_make();
17+
2. 如果系统有uuid-e2fs,就使用 uuid_generate_random();
18+
3. 否则就调用 arc4random();
19+
20+
同时修改代码使得IvorySQL能够自动载入uuid-ossp插件。
21+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
:sectnums:
2+
:sectnumlevels: 5
3+
4+
:imagesdir: ./_images
5+
6+
= sys_guid() 函数
7+
8+
== 目的
9+
10+
IvorySQL的sys_guid() 是一个强大的随机数产生函数,它产生并返回一个由16个字节组成的数据库级别唯一的标识符(原始值)。
11+
12+
== 使用示例
13+
14+
```
15+
highgo=# select sys_guid() from dual;
16+
sys_guid
17+
------------------------------------
18+
\x3ed9426c8a093442a38bea09a74f44a1
19+
(1 row)
20+
```
21+
22+
== sys_guid函数在建表时可以作为主键
23+
24+
```
25+
create table student
26+
(
27+
student_id raw(16) default sys_guid() primary key,
28+
student_name varchar2(100) not null
29+
);
30+
```
31+
32+
== 新增数据时自动填充主键
33+
34+
```
35+
insert into student(student_name) values ('Steven');
36+
```

EN/modules/ROOT/nav.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*** xref:master/6.3.7.adoc[Nested Subfunctions]
3030
*** xref:master/6.3.8.adoc[Force View]
3131
*** xref:master/6.3.9.adoc[Case Conversion]
32+
*** xref:master/6.3.10.adoc[sys_guid Function]
3233
** xref:master/6.4.adoc[GB18030 Character Set]
3334
** Built-in Functions
3435
*** xref:master/6.4.1.adoc[sys_context]
@@ -54,6 +55,7 @@
5455
** xref:master/7.17.adoc[17、NLS Parameters]
5556
** xref:master/7.18.adoc[18、Force View]
5657
** xref:master/7.19.adoc[19、Nested Subfunctions]
58+
** xref:master/7.20.adoc[20、sys_guid Function]
5759
* xref:master/8.adoc[Community contribution]
5860
* xref:master/9.adoc[Tool Reference]
5961
* xref:master/10.adoc[FAQ]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
:sectnums:
2+
:sectnumlevels: 5
3+
4+
:imagesdir: ./_images
5+
6+
= sys_guid() function
7+
8+
== Purpose
9+
10+
IvorySQL's sys_guid() is a powerful random number generation function that generates and returns a 16-byte database-level unique identifier (raw value).
11+
12+
== Implementation Description
13+
14+
The sys_guid() function of IvorySQL is implemented by modifying the code of the uuid-ossp plugin. To make full use of various underlying libraries of uuid, the following logic is adopted:
15+
16+
1. If the uuid-ossp exists in the system, uuid_make() will be used;
17+
2. If the uuid-e2fs exists in the system, uuid_generate_random() will be used;
18+
3. Otherwise use arc4random();
19+
20+
Meanwhile modify the code so that IvorySQL can load uuid-ossp extension automatically.
21+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
:sectnums:
2+
:sectnumlevels: 5
3+
4+
:imagesdir: ./_images
5+
6+
= sys_guid() function
7+
8+
== Purpose
9+
10+
IvorySQL's sys_guid() is a powerful random number generation function that generates and returns a 16-byte database-level unique identifier (raw value).
11+
12+
== Usage example
13+
14+
```
15+
highgo=# select sys_guid() from dual;
16+
sys_guid
17+
------------------------------------
18+
\x3ed9426c8a093442a38bea09a74f44a1
19+
(1 row)
20+
```
21+
22+
== The sys_guid function can generate default values for primary keys when creating a table
23+
24+
```
25+
create table student
26+
(
27+
student_id raw(16) default sys_guid() primary key,
28+
student_name varchar2(100) not null
29+
);
30+
```
31+
32+
== The primary key is automatically populated when new data is added
33+
34+
```
35+
insert into student(student_name) values ('Steven');
36+
```

0 commit comments

Comments
 (0)