Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IvorySQL PL/SQL 创建函数/存储过程存在问题 #477 #492

Merged
merged 2 commits into from Sep 11, 2023
Merged

IvorySQL PL/SQL 创建函数/存储过程存在问题 #477 #492

merged 2 commits into from Sep 11, 2023

Conversation

Leo-XM-Zeng
Copy link
Contributor

@Leo-XM-Zeng Leo-XM-Zeng commented Sep 8, 2023

a. 修复按上键不能正常创建function/procedure的异常情况

make clean
make && make install
psql -d postgres
set ivorysql.compatible_mode = oracle;
\parser

create or replace PROCEDURE xfunc (emp_id numeric) IS a int;
BEGIN
raise notice '%', 'numeric1';
END;
/

-- 按上键 重复操作
-- 按上键 修改部分内容 如添加变量
create or replace PROCEDURE xfunc (emp_id numeric) IS a int; b int;
BEGIN
raise notice '%', 'numeric1';
END;
/
-- 自行测试

Summary by CodeRabbit

  • New Feature: Enhanced handling of function/procedure endings in PL/SQL code. The lexer now properly identifies and manages the end of the creation process, improving the parsing accuracy.
  • Refactor: Introduced a new enumeration PLSQL_endSymbolState and field ora_plsql_expect_end_symbol to track the expected end symbol (slash or semicolon), enhancing the code's readability and maintainability.

	a. 修复按上键不能正常创建function/procedure的异常情况
@coderabbitai
Copy link

coderabbitai bot commented Sep 8, 2023

Walkthrough

The changes introduce a new enumeration and field to handle the end symbol state in PL/SQL code. This improves the lexer's handling of function/procedure endings, with updates to slash and semicolon processing.

Changes

File Summary
src/include/fe_utils/psqlscan_int.h Introduced PLSQL_endSymbolState enumeration and ora_plsql_expect_end_symbol field for better handling of PL/SQL end symbols.
src/oracle_fe_utils/ora_psqlscan.l Updated lexer logic to handle end of creation process, with improved handling of slashes and semicolons.

🐇💻

In the land of code, where the semicolons lie,

A rabbit hopped forth, with a twinkle in its eye.

With each slash and symbol, it danced and twirled,

Celebrating the changes, in this digital world. 🎉🌍


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between 6a66012 and 9c88ded commits.
Files selected for processing (2)
  • src/include/fe_utils/psqlscan_int.h (2 hunks)
  • src/oracle_fe_utils/ora_psqlscan.l (6 hunks)
Additional comments (Suppressed): 6
src/include/fe_utils/psqlscan_int.h (1)
  • 79-84: The new enumeration PLSQL_endSymbolState is introduced to manage different states of the end symbol in PL/SQL code. This seems to be a good approach for handling the end symbols (/ or ;) correctly during the creation process of functions/procedures in IvorySQL's PL/SQL compatibility mode.
src/oracle_fe_utils/ora_psqlscan.l (5)
  • 769-776: The new condition added to check for the end of the creation process seems to be correct. It checks if the expected end symbol is a slash and if both paren_depth and begin_depth are zero, or if is_oracle_slash() returns true. This should correctly identify the end of the creation process in most cases. However, it's important to verify that all possible edge cases have been considered and tested.

  • 794-800: The handling of semicolons has been updated to change the expected end symbol to a slash when the current expected end symbol is a semicolon. This seems to be a logical change given the context, but it would be good to verify that this doesn't introduce any unexpected behavior in other parts of the code that rely on the value of ora_plsql_expect_end_symbol.

  • 1086-1088: The state of ora_plsql_expect_end_symbol is reset to END_SYMBOL_INVALID when it's not null. This seems to be a cleanup operation to ensure that the state is reset after each use. However, it's important to verify that this doesn't interfere with any ongoing operations that might still be expecting an end symbol.

  • 1127-1130: The expected end symbol is set to END_SYMBOL_SEMICOLON when begin_depth is greater than zero. This seems to be a logical change given the context, but it would be good to verify that this doesn't introduce any unexpected behavior in other parts of the code that rely on the value of ora_plsql_expect_end_symbol.

  • 1453-1456: The initialization of ora_plsql_expect_end_symbol to END_SYMBOL_INVALID in psql_scan_reset() is a good practice as it ensures that the state is reset before each scan. This should prevent any lingering state from affecting subsequent scans.

Comment on lines +166 to +167
/* Used to handle funtion/procedure that does not end properly */
PLSQL_endSymbolState ora_plsql_expect_end_symbol;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new field ora_plsql_expect_end_symbol is added to the PsqlScanStateData struct, which stores the expected end symbol state. This change appears to be aimed at properly managing function/procedure endings. However, it would be beneficial to add a comment explaining what each state means and when it should be used.

- 	/* Used to handle funtion/procedure that does not end properly */
+ 	/* Used to handle function/procedure that does not end properly. 
+     * END_SYMBOL_INVALID: The end symbol state is invalid (default state).
+     * END_SYMBOL_SEMICOLON: A semicolon is expected as the end symbol.
+     * END_SYMBOL_SLASH: A slash is expected as the end symbol.
+     */

@Leo-XM-Zeng Leo-XM-Zeng closed this Sep 8, 2023
@Leo-XM-Zeng Leo-XM-Zeng reopened this Sep 8, 2023
@tanyang-star tanyang-star added enhancement New feature or request 3.0 Community Community Supported Feature CR code check labels Sep 11, 2023
@tanyang-star
Copy link
Collaborator

#477

@tanyang-star tanyang-star merged commit 8cff64e into IvorySQL:master Sep 11, 2023
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.0 Community Community Supported Feature CR code check enhancement New feature or request
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants