为IvorySQL增添PACKAGE语法帮助

news/2025/10/27 16:52:50/文章来源:https://www.cnblogs.com/ivorysql/p/19169570

认识语法帮助

当使用psql工具登录数据库时,\h command可以查看语法帮助。比如查看create database语法:

psql (17.6)
Type "help" for help.ivorysql=# \h create database
Command:     CREATE DATABASE
Description: create a new database
Syntax:
CREATE DATABASE name[ WITH ] [ OWNER [=] user_name ][ TEMPLATE [=] template ][ ENCODING [=] encoding ][ STRATEGY [=] strategy ][ LOCALE [=] locale ][ LC_COLLATE [=] lc_collate ][ LC_CTYPE [=] lc_ctype ][ BUILTIN_LOCALE [=] builtin_locale ][ ICU_LOCALE [=] icu_locale ][ ICU_RULES [=] icu_rules ][ LOCALE_PROVIDER [=] locale_provider ][ COLLATION_VERSION = collation_version ][ TABLESPACE [=] tablespace_name ][ ALLOW_CONNECTIONS [=] allowconn ][ CONNECTION LIMIT [=] connlimit ][ IS_TEMPLATE [=] istemplate ][ OID [=] oid ]URL: https://www.postgresql.org/docs/17/sql-createdatabase.htmlivorysql=#

这也算是个小技巧,不需要死记太多的sql语法,使用时直接查看就行。不仅打印出了对应sql的语法,还打印出了该语法对应的官方文档URL。

语法帮助原理分析

主要是@SOURCE_ROOT/src/bin/psql/help.c中helpSQL函数实现查看语法的功能。

从Makefile看还得依赖sql_help.c, sql_help.h一起编译完成。而从meson.build看是make的时候才生成这两个文件的,并且是使用create_help.pl读取文档目录@SOURCE_ROOT@/doc/src/sgml/ref中的所有语法文档生成的。

sql_help = custom_target('psql_help',output: ['sql_help.c', 'sql_help.h'],depfile: 'sql_help.dep',command: [perl, files('create_help.pl'),'--docdir', '@SOURCE_ROOT@/doc/src/sgml/ref','--depfile', '@DEPFILE@','--outdir', '@OUTDIR@','--basename', 'sql_help',],
)
generated_sources += sql_help.to_list()
psql_sources += sql_help

可以看到doc/src/sgml/ref目录下确实包含了其他所有对象的create的sgml文件,并没有create_package的文件。

ls doc/src/sgml/ref/create*
doc/src/sgml/ref/create_access_method.sgml  doc/src/sgml/ref/create_extension.sgml             doc/src/sgml/ref/create_operator.sgml     doc/src/sgml/ref/create_server.sgml        doc/src/sgml/ref/create_tsdictionary.sgml
doc/src/sgml/ref/create_aggregate.sgml      doc/src/sgml/ref/create_foreign_data_wrapper.sgml  doc/src/sgml/ref/create_opfamily.sgml     doc/src/sgml/ref/create_statistics.sgml    doc/src/sgml/ref/create_tsparser.sgml
doc/src/sgml/ref/create_cast.sgml           doc/src/sgml/ref/create_foreign_table.sgml         doc/src/sgml/ref/create_policy.sgml       doc/src/sgml/ref/create_subscription.sgml  doc/src/sgml/ref/create_tstemplate.sgml
doc/src/sgml/ref/create_collation.sgml      doc/src/sgml/ref/create_function.sgml              doc/src/sgml/ref/create_procedure.sgml    doc/src/sgml/ref/create_table_as.sgml      doc/src/sgml/ref/create_type.sgml
doc/src/sgml/ref/create_conversion.sgml     doc/src/sgml/ref/create_group.sgml                 doc/src/sgml/ref/create_publication.sgml  doc/src/sgml/ref/create_table.sgml         doc/src/sgml/ref/create_user_mapping.sgml
doc/src/sgml/ref/create_database.sgml       doc/src/sgml/ref/create_index.sgml                 doc/src/sgml/ref/create_role.sgml         doc/src/sgml/ref/create_tablespace.sgml    doc/src/sgml/ref/create_user.sgml
doc/src/sgml/ref/createdb.sgml              doc/src/sgml/ref/create_language.sgml              doc/src/sgml/ref/create_rule.sgml         doc/src/sgml/ref/create_transform.sgml     doc/src/sgml/ref/createuser.sgml
doc/src/sgml/ref/create_domain.sgml         doc/src/sgml/ref/create_materialized_view.sgml     doc/src/sgml/ref/create_schema.sgml       doc/src/sgml/ref/create_trigger.sgml       doc/src/sgml/ref/create_view.sgml
doc/src/sgml/ref/create_event_trigger.sgml  doc/src/sgml/ref/create_opclass.sgml               doc/src/sgml/ref/create_sequence.sgml     doc/src/sgml/ref/create_tsconfig.sgml

增添create package语法帮助

仿照create_table.sgml或其他文件,生成create_package.sgml和create_package_body.sgml文件。

从create_help.pl可知:
cmd取自sgml文件中refname标签,help取自synopsis标签,docbook_id取自refentry id标签。

因此create_package.sgml为:

<!--
doc/src/sgml/ref/create_package.sgml
PostgreSQL documentation
--><refentry id="sql-createpackage"><indexterm zone="sql-createpackage"><primary>CREATE PACKAGE</primary></indexterm><refmeta><refentrytitle>CREATE PACKAGE</refentrytitle><manvolnum>7</manvolnum><refmiscinfo>SQL - Language Statements</refmiscinfo></refmeta><refnamediv><refname>CREATE PACKAGE</refname><refpurpose>define a new package</refpurpose></refnamediv><refsynopsisdiv>
<synopsis>
CREATE [ OR REPLACE ] PACKAGE [schema.] <replaceable class="parameter">package_name</replaceable>  [invoker_rights_clause] [IS | AS] item_list[, item_list ...]  
END [<replaceable class="parameter">package_name</replaceable>]invoker_rights_clause:AUTHID [CURRENT_USER | DEFINER]item_list: 
[function_declaration    | procedure_declaration   | type_definition         | cursor_declaration      | item_declaration
]function_declaration:FUNCTION <replaceable class="parameter">function_name</replaceable> [ (parameter_declaration[, ...]) ] RETURN datatype;procedure_declaration:PROCEDURE <replaceable class="parameter">procedure_name</replaceable> [ (parameter_declaration[, ...]) ]type_definition:record_type_definition      |ref_cursor_type_definitioncursor_declaration:CURSOR <replaceable class="parameter">name</replaceable>  [(cur_param_decl[, ...])] RETURN rowtype;item_declaration:cursor_declaration             |cursor_variable_declaration    |record_variable_declaration    |variable_declaration           |record_type_definition:TYPE record_type IS RECORD  ( variable_declaration [, variable_declaration]... ) ;ref_cursor_type_definition:TYPE type IS REF CURSOR [ RETURN type%ROWTYPE ];cursor_variable_declaration:curvar curtype;record_variable_declaration:recvar { record_type | rowtype_attribute | record_type%TYPE };variable_declaration:varname datatype [ [ NOT NULL ] := expr ]parameter_declaration:parameter_name [IN] datatype [[:= | DEFAULT] expr]</synopsis></refsynopsisdiv>

create_package_body.sgml为:

<!--
doc/src/sgml/ref/create_package_body.sgml
PostgreSQL documentation
--><refentry id="sql-createpackagebody"><indexterm zone="sql-createpackagebody"><primary>CREATE PACKAGE BODY</primary></indexterm><refmeta><refentrytitle>CREATE PACKAGE BODY</refentrytitle><manvolnum>7</manvolnum><refmiscinfo>SQL - Language Statements</refmiscinfo></refmeta><refnamediv><refname>CREATE PACKAGE BODY</refname><refpurpose>define a new package body</refpurpose></refnamediv><refsynopsisdiv>
<synopsis>CREATE [ OR REPLACE ] PACKAGE BODY [schema.] <replaceable class="parameter">package_name</replaceable> [IS | AS][item_list[, item_list ...]] | item_list_2 [, item_list_2 ...][initialize_section]
END [ <replaceable class="parameter">package_name</replaceable> ];initialize_section:BEGIN statement[, ...]item_list: 
[function_declaration    | procedure_declaration   | type_definition         | cursor_declaration      | item_declaration
]item_list_2:
[function_declarationfunction_definitionprocedure_declarationprocedure_definitioncursor_definition
]function_definition:FUNCTION <replaceable class="parameter">function_name</replaceable> [ (parameter_declaration[, ...]) ] RETURN datatype  [IS | AS][declare_section] body;procedure_definition:PROCEDURE <replaceable class="parameter">procedure_name</replaceable> [ (parameter_declaration[, ...]) ] [IS | AS] [declare_section] body;cursor_definition:CURSOR <replaceable class="parameter">name</replaceable> [ (cur_param_decl[, ...]) ] RETURN rowtype IS select_statement;body:BEGIN statement[, ...] END [name];statement:[<<LABEL>>] pl_statments[, ...];</synopsis></refsynopsisdiv>

当然还需对helpSQL函数做些修改,当查询的语法帮助为create package(body)时,展示IvorySQL对应的官方文档URL。

for (i = 0; QL_HELP[i].cmd; i++)
{if (pg_strncasecmp(topic, QL_HELP[i].cmd, len) == 0 ||strcmp(topic, "*") == 0){PQExpBufferData buffer;char       *url;initPQExpBuffer(&buffer);QL_HELP[i].syntaxfunc(&buffer);if (pg_strncasecmp(QL_HELP[i].docbook_id, "sql-createpackage",17) == 0)url = "https://www.ivorysql.org/en/docs/compatibillity_features/package \n""DETAIL: https://docs.ivorysql.org/en/ivorysql-doc/v4.6/v4.6/28";elseurl = psprintf("https://www.postgresql.org/docs/%s/%s.html",strstr(PG_VERSION, "devel") ? "devel" : PG_MAJORVERSION,QL_HELP[i].docbook_id);/* # of newlines in format must match constant above! */fprintf(output, _("Command:     %s\n""Description: %s\n""Syntax:\n%s\n\n""URL: %s\n\n"),QL_HELP[i].cmd,_(QL_HELP[i].help),buffer.data,url);if (pg_strncasecmp(QL_HELP[i].docbook_id, "sql-createpackage",17))free(url);termPQExpBuffer(&buffer);/* If we have an exact match, exit.  Fixes \h SELECT */if (pg_strcasecmp(topic, QL_HELP[i].cmd) == 0)break;}
}

重新编译安装psql工具后,已经可以查看create package的语法帮助了。

\h create package

psql (17.6)
Type "help" for help.ivorysql=# \h create package
Command:     CREATE PACKAGE
Description: define a new package
Syntax:
CREATE [ OR REPLACE ] PACKAGE [schema.] package_name  [invoker_rights_clause] [IS | AS] item_list[, item_list ...]  
END [package_name]invoker_rights_clause:AUTHID [CURRENT_USER | DEFINER]item_list: 
[function_declaration    | procedure_declaration   | type_definition         | cursor_declaration      | item_declaration
]function_declaration:FUNCTION function_name [ (parameter_declaration[, ...]) ] RETURN datatype;procedure_declaration:PROCEDURE procedure_name [ (parameter_declaration[, ...]) ]type_definition:record_type_definition      |ref_cursor_type_definitioncursor_declaration:CURSOR name  [(cur_param_decl[, ...])] RETURN rowtype;item_declaration:cursor_declaration             |cursor_variable_declaration    |record_variable_declaration    |variable_declaration           |record_type_definition:TYPE record_type IS RECORD  ( variable_declaration [, variable_declaration]... ) ;ref_cursor_type_definition:TYPE type IS REF CURSOR [ RETURN type%ROWTYPE ];cursor_variable_declaration:curvar curtype;record_variable_declaration:recvar { record_type | rowtype_attribute | record_type%TYPE };variable_declaration:varname datatype [ [ NOT NULL ] := expr ]parameter_declaration:parameter_name [IN] datatype [[:= | DEFAULT] expr]URL: https://www.ivorysql.org/en/docs/compatibillity_features/package 
DETAIL: https://docs.ivorysql.org/en/ivorysql-doc/v4.6/v4.6/28ivorysql=#

\h create package body

psql (17.6)
Type "help" for help.ivorysql=# \h create package body
Command:     CREATE PACKAGE BODY
Description: define a new package body
Syntax:
CREATE [ OR REPLACE ] PACKAGE BODY [schema.] package_name [IS | AS][item_list[, item_list ...]] | item_list_2 [, item_list_2 ...][initialize_section]
END [ package_name ];initialize_section:BEGIN statement[, ...]item_list: 
[function_declaration    | procedure_declaration   | type_definition         | cursor_declaration      | item_declaration
]item_list_2:
[function_declarationfunction_definitionprocedure_declarationprocedure_definitioncursor_definition
]function_definition:FUNCTION function_name [ (parameter_declaration[, ...]) ] RETURN datatype  [IS | AS][declare_section] body;procedure_definition:PROCEDURE procedure_name [ (parameter_declaration[, ...]) ] [IS | AS] [declare_section] body;cursor_definition:CURSOR name [ (cur_param_decl[, ...]) ] RETURN rowtype IS select_statement;body:BEGIN statement[, ...] END [name];statement:[<<LABEL>>] pl_statments[, ...];URL: https://www.ivorysql.org/en/docs/compatibillity_features/package 
DETAIL: https://docs.ivorysql.org/en/ivorysql-doc/v4.6/v4.6/28ivorysql=#

小结

psql的语法帮助文档挺好用的,本次给IvorySQL-4.6适配create package(body)语法帮助文档算是比较系统的了解了下语法帮助文档的原理。

引用:

[1]
helpSQL:
https://github.com/IvorySQL/IvorySQL/blob/IvorySQL_4.6/src/bin/psql/help.c#L575

[2]
URL: https://www.ivorysql.org/en/docs/Compatibillity_Features/package

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/947888.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MATLAB 时间序列小波周期分析

1. 文件结构 WaveletPeriod/ ├── main_wavelet_period.m % 一键运行 ├── wavelet_power_spectrum.m % 小波功率谱 + 显著性 ├── period_peak_detect.m % 自动周期峰值 ├── plot_wavelet_results.m …

# 情绪日历应用(python AI项目)

📖 项目简介 这是一个基于人脸情绪识别的智能日历应用,能够:📅 记录你每天的情绪状态 😊 自动识别照片中的情绪 💬 提供情绪陪伴聊天 📊 统计月度情绪变化🏗️ 代码结构详解 1. 导入模块部分 - 程序的&q…

读《程序员修炼之道:从小工到专家》

读《程序员修炼之道》,仍被书中 “务实的程序员” 理念戳中。它没教复杂算法,却把成长拆成可落地的日常:像 “ DRY 原则” 让我改掉重复写工具类的习惯,“不要重复发明轮子” 提醒我先调研再动手,而 “持续学习”…

本地运行nginx服务,模拟线上环境访问项目

一、了解nginx Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一个IMAP/POP3/SMTP服务。 Nginx也是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行…

git提交远程项目步骤

git提交远程项目步骤一个比较复杂的情况 远程已经有了代码的前提下,我复制一份到本地修改,然后再提交到原仓库 分两种情况,一种是想全部覆盖远程的代码,另一种是只是在原代码基础上做了一些修改,只需要提交一下p…

基于Redis海量数据场景分布式ID生成实践

概述 在现代分布式系统中,生成全局唯一的ID是一个常见且重要的需求。在微服务架构中,各个服务可能需要生成唯一标识符,如用户ID、订单ID等。传统的自增ID已经无法满足在集群环境下保持唯一性的要求,而分布式ID解决…

电梯调度算法结对编程作业

1、项目仓库地址:https://z.gitee.cn/zgca/repos/zgca/elevator_arrange/sources 2、项目简介 3、PSP表格 4、接口设计介绍 5、模块接口的设计与实现过程 6、结对编程过程中的问题总结 7、界面模块的详细设计过程 8、…

【完结22章】从0到1,LangChain+RAG全链路实战AI知识库

【完结22章】从0到1,LangChain+RAG全链路实战AI知识库 学习地址:……/s/1hIjOa9HEwE-81qiVg6TUyA 提取码:qe8c 在信息爆炸的时代,企业积累的文档、报告、代码和各类数据资产正以前所未有的速度增长。传统的知识管理…

分享精选文章合集 - 2025-10-27

分享精选文章合集 - 2025-10-27汇总2025-10-27的精品精选求职与招聘文章。大家好,我是jobleap.cn的小九。 今日热门信息 - jobleap4u.com 内容概览:共 100 篇内容(按发布时间倒序排列,数据源自提供的ArticleCollec…

20232416 2025-2026-1 《网络与系统攻防技术》实验三实验报告

20232416 2025-2026-1 《网络与系统攻防技术》实验三实验报告 1.实验内容 (1)正确使用msf编码器,veil-evasion,自己利用shellcode编程等免杀工具或技巧正确使用msf编码器,使用msfvenom生成jar、php等文件 veil,加壳…

2025 年搅拌器搅拌设备,侧入式搅拌设备,斜插式揽拌设备,卧式搅拌设备厂家最新推荐,聚焦资质、案例、售后的五家企业深度解读

引言 随着工业领域对搅拌设备精细化、高效化需求的不断提升,搅拌器、侧入式、斜插式、卧式等各类搅拌设备的市场关注度持续攀升。为帮助企业精准筛选优质设备厂家,通用机械工业协会搅拌设备分会联合第三方检测机构,…

芯片实现路线图

在集成电路(IC)设计中,“物理实现”是将抽象的逻辑设计落地为可生产布局(Layout)的关键阶段,其中包含floor-planning(布局规划)、placement(布局布置)、routing(布线)与physical verification(物理验证)…

2025 年环保搅拌设备,搅拌装置设备,框式搅拌设备厂家最新推荐,实力品牌深度解析采购无忧之选!

引言 随着环保理念在工业领域的深度渗透,环保搅拌设备、搅拌装置设备及框式搅拌设备的市场需求持续攀升,企业对设备的性能、可靠性及环保性要求愈发严格。为助力企业精准筛选优质厂家,通用机械工业协会搅拌设备分会…

2025 年顶入式搅拌设备,直叶搅拌设备,节能减排搅拌设备厂家最新推荐,技术实力与市场口碑深度解析

引言 在工业生产中,顶入式、直叶式及节能减排搅拌设备作为关键装备,其性能与品质直接影响企业生产效率与环保水平。为精准筛选优质厂家,通用机械工业协会搅拌设备分会于 2025 年初开展专项测评,采用 “技术指标 + …

10.27总结

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int score=sc.nextInt(); if(score<60)System.out.println("不及格"); …

BongoCat日志搜索程序:正则表达式与高级筛选

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

WPF 自定义控件库

一、使用场景开发自定义控件库时,向外部暴露可复用的样式、模板、画笔等资源。 多模块应用中,共享通用资源(如主题样式)。 需要避免资源键命名冲突的场景。二 ,程序 1.静态的后台代码 资源键// MyControlLibrary/R…

2025质量可靠的义乌刺绣工厂推荐榜

2025质量可靠的义乌刺绣工厂推荐下。在义乌及周边区域,刺绣工厂数量众多,而质量可靠是企业选择合作方的核心考量因素。 Top1:浦江县俊贤刺绣有限公司 推荐程度:★★★★★ 浦江县俊贤刺绣有限公司虽位于浦江,但与…

c# 使用 jwt

基于 oauth2.0 协议, 具体原理可以参考:https://www.ruanyifeng.com/blog/2018/07/json_web_token-tutorial.htmlpublic class JWTHelper{private const string salt = "123";//盐//获得jwt令牌public sta…

2025义乌做刺绣的厂家推荐榜单

2025义乌做刺绣的厂家推荐下。义乌及周边区域作为纺织服饰配套产业集聚地,刺绣加工领域企业数量众多,涵盖传统手绣、机械刺绣等不同类型,产品可适配服装、家居装饰、礼品等多个应用场景。 Top1:浦江县俊贤刺绣有限…