Skip to content

Commit 252abea

Browse files
committed
fix CALL INTO feature typo
1 parent 08b7654 commit 252abea

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

CN/modules/ROOT/pages/master/6.3.12.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@
2121

2222
- 当 CALL 语句包含绑定变量(如 :x)时:
2323

24-
客户端将其重写为一个特殊的匿名 PL 块(DO $$ ... $$);
25-
使用扩展查询协议发送,以便传递参数类型和精度信息;
26-
服务端执行该匿名块,并将结果返回给客户端;
27-
客户端再将结果写入对应的绑定变量。
24+
客户端将其重写为一个特殊的匿名 PL 块(DO $$ ... $$);
25+
使用扩展查询协议发送,以便传递参数类型和精度信息;
26+
服务端执行该匿名块,并将结果返回给客户端;
27+
客户端再将结果写入对应的绑定变量。
2828

2929
- 当 CALL 语句不含绑定变量时:
3030

3131
行为与原生 PostgreSQL 完全一致,使用简单查询协议,不做任何重写。
3232

3333
== 实现原理
3434
=== 交互式终端
35-
为了在接口中兼容CALL [INTO]语句,需将其转换为匿名PL/SQL块,并借助匿名块对OUT参数的支持来实现功能等价。这就要求get_parameter_description函数能够正确识别CALL语句,并在遇到CALL INTO时,返回重写后的PL语句。
35+
为了在接口中兼容CALL [INTO]语句,需将其转换为匿名PL/iSQL块,并借助匿名块对OUT参数的支持来实现功能等价。这就要求get_parameter_description函数能够正确识别CALL语句,并在遇到CALL INTO时,返回重写后的PL语句。
3636
相应地,get_hostvariables例程需要将这些信息(如是否为 CALL 语句、是否包含INTO、重写后的语句等)保存到HostVariable结构中。HostVariable的定义如下:
3737
```
3838
typedef struct HostVariable
@@ -101,7 +101,7 @@ typedef struct DoStmt
101101
bool do_from_call; /* True if DoStmt is come from CallStmt */
102102
} DoStmt;
103103
```
104-
在IVY接口中,占位符信息是通过一个名为get_parameter_description的集合返回函数(SRF)获取的。该函数需要能够识别输入语句的类型,并在遇到CALL INTO语句时,返回重写后的PL/SQL赋值语句
104+
在IVY接口中,占位符信息是通过一个名为get_parameter_description的集合返回函数(SRF)获取的。该函数需要能够识别输入语句的类型,并在遇到CALL INTO语句时,返回重写后的PL/iSQL赋值语句
105105
为此,IvorySQL对该函数的返回结构(TupleDesc)进行了扩展:新增了一个hint 字段,专门用于返回CALL INTO语句重写后的PL代码;对于其他类型的语句,该字段保持为NULL。
106106
此外,原函数结果集的第一条元组的第一个字段原本仅用true/false来区分语句是否为匿名块。为了更准确地识别语句类型(尤其是CALL语句),现已将其修改为返回对应解析树的 CommandTag。
107107
所有这些元数据信息最终会被封装到一个用户上下文结构中,以便在 SRF 函数的多次调用之间高效传递和复用。
@@ -148,10 +148,10 @@ Ivyreplacenamebindtoposition3
148148

149149
在IvyexecPreparedStatement 和 IvyexecPreparedStatement2 这类接口中,用户需要显式提供每个参数的 paramvalues、paramlengths、paramformats 和 parammode。对于 CALL 语句,这些参数数组中的元素顺序必须根据重写后的匿名块结构进行位置调整,以确保绑定与执行逻辑一致。
150150

151-
其中,IvyexecPreparedStatement2 更为特殊:它要求用户额外提供一个 IvyBindOutInfo* 类型的输出绑定列表。该列表不仅用于绑定 OUT 参数,还被 IvyAssignPLISQLOutParameter 在获取 PL/SQL 过程返回结果时用来识别每个 OUT 参数的数据类型。因此,在处理 CALL语句时,接口会先对用户传入的 IvyBindOutInfo*列表进行位置重排(将INTO对应的输出变量移至首位),再将其写入IvyPreparedStatement语句句柄中,供后续赋值使用。
151+
其中,IvyexecPreparedStatement2 更为特殊:它要求用户额外提供一个 IvyBindOutInfo* 类型的输出绑定列表。该列表不仅用于绑定 OUT 参数,还被 IvyAssignPLISQLOutParameter 在获取 PL/iSQL 过程返回结果时用来识别每个 OUT 参数的数据类型。因此,在处理 CALL语句时,接口会先对用户传入的 IvyBindOutInfo*列表进行位置重排(将INTO对应的输出变量移至首位),再将其写入IvyPreparedStatement语句句柄中,供后续赋值使用。
152152

153153
关于输出参数的精度处理:当CALL语句中的输出绑定变量与实际返回值的精度不匹配时,系统可能报错,也可能自动截断——具体行为取决于绑定变量的数据类型是否与过程/函数声明的参数类型完全一致。
154-
在PL/SQL inline handler中,每个OUT参数的精确数据类型均可通过ParamListInfo在绑定阶段获取。如果当前执行的匿名块是由CALL语句转换而来的特殊DoStmt,那么在执行赋值时,系统会进行如下判断:
154+
在PL/iSQL inline handler中,每个OUT参数的精确数据类型均可通过ParamListInfo在绑定阶段获取。如果当前执行的匿名块是由CALL语句转换而来的特殊DoStmt,那么在执行赋值时,系统会进行如下判断:
155155

156156
若ParamListInfo中记录的类型与函数/存储过程形参的类型完全相同,则采用强制类型转换赋值;
157157
否则,采用隐式类型转换赋值。

EN/modules/ROOT/pages/master/6.3.12.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Since PostgreSQL/IvorySQL inherently does not support direct assignment to clien
3232

3333
== Implementation Details
3434
=== psql
35-
To ensure compatibility with the CALL [INTO] statement in the interface, it must be converted into an anonymous PL/SQL block, leveraging the support for OUT parameters in anonymous blocks to achieve functional equivalence.
35+
To ensure compatibility with the CALL [INTO] statement in the interface, it must be converted into an anonymous PL/iSQL block, leveraging the support for OUT parameters in anonymous blocks to achieve functional equivalence.
3636

3737
This requires the get_parameter_description function to correctly identify CALL statements and, when encountering CALL INTO, return the rewritten PL statement.
3838

@@ -103,7 +103,7 @@ typedef struct DoStmt
103103
bool do_from_call; /* True if DoStmt is come from CallStmt */
104104
} DoStmt;
105105
```
106-
In the IVY interface, placeholder information is obtained through a Set-Returning Function (SRF) called get_parameter_description. This function needs to identify the type of input statement and return the rewritten PL/SQL assignment statement when encountering CALL INTO statements.
106+
In the IVY interface, placeholder information is obtained through a Set-Returning Function (SRF) called get_parameter_description. This function needs to identify the type of input statement and return the rewritten PL/iSQL assignment statement when encountering CALL INTO statements.
107107

108108
To achieve this, IvorySQL has extended the return structure (TupleDesc) of this function: a new hint field has been added specifically to return the rewritten PL code for CALL INTO statements; for other types of statements, this field remains NULL.
109109

@@ -155,11 +155,11 @@ Ivyreplacenamebindtoposition3
155155

156156
In interfaces such as IvyexecPreparedStatement and IvyexecPreparedStatement2, users must explicitly provide paramvalues, paramlengths, paramformats, and parammode for each parameter. For CALL statements, the order of elements in these parameter arrays must be adjusted according to the rewritten anonymous block structure to ensure binding consistency with the execution logic.
157157

158-
Among them, IvyexecPreparedStatement2 is more specialized: it requires users to additionally provide an output binding list of type IvyBindOutInfo*. This list is not only used to bind OUT parameters but is also utilized by IvyAssignPLISQLOutParameter to identify the data type of each OUT parameter when retrieving PL/SQL procedure results. Therefore, when processing CALL statements, the interface first reorders the user-provided IvyBindOutInfo* list (moving the INTO-bound output variable to the first position) and then writes it into the IvyPreparedStatement statement handle for subsequent assignment.
158+
Among them, IvyexecPreparedStatement2 is more specialized: it requires users to additionally provide an output binding list of type IvyBindOutInfo*. This list is not only used to bind OUT parameters but is also utilized by IvyAssignPLISQLOutParameter to identify the data type of each OUT parameter when retrieving PL/iSQL procedure results. Therefore, when processing CALL statements, the interface first reorders the user-provided IvyBindOutInfo* list (moving the INTO-bound output variable to the first position) and then writes it into the IvyPreparedStatement statement handle for subsequent assignment.
159159

160160
Regarding precision handling for output parameters: When there is a mismatch between the precision of an output binding variable in a CALL statement and the actual returned value, the system may either raise an error or automatically truncate—the specific behavior depends on whether the data type of the binding variable exactly matches the parameter type declared in the procedure/function.
161161

162-
In the PL/SQL inline handler, the precise data type of each OUT parameter can be obtained through ParamListInfo during the binding phase. If the currently executed anonymous block is a special DoStmt converted from a CALL statement, the system performs the following checks during assignment:
162+
In the PL/iSQL inline handler, the precise data type of each OUT parameter can be obtained through ParamListInfo during the binding phase. If the currently executed anonymous block is a special DoStmt converted from a CALL statement, the system performs the following checks during assignment:
163163

164164
If the type recorded in ParamListInfo exactly matches the formal parameter type of the function/stored procedure, a forced type conversion is applied for assignment.
165165
Otherwise, an implicit type conversion is used for assignment.

0 commit comments

Comments
 (0)