[go: up one dir, main page]

CN104461531B - A kind of implementation method of reporting system SQL - Google Patents

A kind of implementation method of reporting system SQL Download PDF

Info

Publication number
CN104461531B
CN104461531B CN201410722935.0A CN201410722935A CN104461531B CN 104461531 B CN104461531 B CN 104461531B CN 201410722935 A CN201410722935 A CN 201410722935A CN 104461531 B CN104461531 B CN 104461531B
Authority
CN
China
Prior art keywords
function
custom
parameter
stored procedure
report
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Expired - Fee Related
Application number
CN201410722935.0A
Other languages
Chinese (zh)
Other versions
CN104461531A (en
Inventor
聂作先
王平阳
张顺淼
杨海燕
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Fujian University of Technology
Original Assignee
Fujian University of Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Fujian University of Technology filed Critical Fujian University of Technology
Priority to CN201410722935.0A priority Critical patent/CN104461531B/en
Publication of CN104461531A publication Critical patent/CN104461531A/en
Application granted granted Critical
Publication of CN104461531B publication Critical patent/CN104461531B/en
Expired - Fee Related legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Stored Programmes (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开了报表系统自定义函数实现方法,包括以下步骤:步骤1):自定义函数及参数登记;步骤2):自定义函数相关存储过程创建;步骤3):在报表中使用自定义函数;步骤4):识别报表中的自定义函数;步骤5):自定义函数参数列表中变量识别与替换;步骤6):准备参数并调用自定义函数关联存储过程;步骤7):执行自定义函数关联存储过程并返回结果;步骤8):接收自定义函数关联存储过程返回结果并应用到报表中。本发明创建自定义函数的技术门槛较低,报表用户只需要熟悉存储过程的设计就可以创建自定义函数,只要在设计器中登记了自定义函数的名称和参数信息并提交及在数据库中创建了关联存储过程就完成了自定义函数的创建及部署。

The invention discloses a method for realizing a self-defined function of a report system, which includes the following steps: step 1): registering a self-defined function and parameters; step 2): creating a stored procedure related to a self-defined function; step 3): using a self-defined function in a report ; Step 4): Identify the custom function in the report; Step 5): Identify and replace variables in the custom function parameter list; Step 6): Prepare parameters and call the custom function associated stored procedure; Step 7): Execute custom The function associates the stored procedure and returns the result; Step 8): Receive the returned result of the custom function associated stored procedure and apply it to the report. The technical threshold for creating self-defined functions in the present invention is low, and report users only need to be familiar with the design of stored procedures to create self-defined functions, as long as the name and parameter information of the self-defined functions are registered in the designer and submitted and created in the database After the associated stored procedure is completed, the creation and deployment of the custom function is completed.

Description

一种报表系统自定义函数的实现方法A Realization Method of Custom Function in Reporting System

技术领域technical field

本发明涉及计算机软件应用领域,尤其涉及一种报表系统自定义函数的实现方法。The invention relates to the field of computer software applications, in particular to a method for realizing a self-defined function of a reporting system.

背景技术Background technique

自定义函数功能是商业报表系统的重要功能之一,它允许报表设计者或报表用户将格式转换函数及业务处理逻辑包装为函数的形式供设计报表时使用,实现代码重用及特定应用领域的特色需求。The custom function function is one of the important functions of the commercial report system, which allows the report designer or report user to package the format conversion function and business processing logic into a function form for use when designing reports, realizing code reuse and the characteristics of specific application fields need.

报表是企业应用软件必不可少的部分,为了方便报表的开发,各类报表开发系统中都提供了一定数量的系统函数以完成一些通用的功能,如数学处理、字符串处理、日期格式转换等。但在实际应用中,根据应用领域的具体需要,报表设计者还需要经常用到一些系统函数中没有的功能,如特定格式的日期格式转换或数字格式转换,以及与应用业务逻辑相关的处理功能,这些功能就需要报表设计者自行设计成自定义函数供其反复使用。Reports are an essential part of enterprise application software. In order to facilitate the development of reports, various report development systems provide a certain number of system functions to complete some common functions, such as mathematical processing, string processing, date format conversion, etc. . However, in practical applications, according to the specific needs of the application field, report designers often need to use some functions that are not available in the system functions, such as date format conversion or number format conversion in specific formats, and processing functions related to application business logic , these functions need to be designed by the report designer as a custom function for repeated use.

在当前主流的商业报表系统中,大多提供了设计自定义函数的方法。微软公司Visual Studio集成开发环境中的水晶报表(Crystal Report)系统中,提供了自定义函数编辑器供用户设计自定义函数,设计完成后可以发布到报表系统的储备库中与所有其他设计者共享使用。水晶报表自定义函数设计及发布都比较简单,但需要使用VISUAL BASIC或水晶报表专用的编程语言编写,而且对代码功能有诸多限制,如在自定义函数中不能使用报表或数据库字段,这极大地限制了自定义函数的应用范围。Most of the current mainstream commercial reporting systems provide methods for designing custom functions. In the Crystal Report (Crystal Report) system in Microsoft's Visual Studio integrated development environment, a custom function editor is provided for users to design custom functions. After the design is completed, it can be published to the report system's repository and shared with all other designers. use. The design and publishing of crystal report custom functions are relatively simple, but they need to be written in VISUAL BASIC or a programming language dedicated to crystal report, and there are many restrictions on code functions. For example, report or database fields cannot be used in custom functions, which greatly The scope of application of custom functions is limited.

润乾报表系统、杰表报表系统及X5报表平台都是以JAVA语言开发WEB报表的解析引擎,因此,它们均要求自定义函数使用JAVA语言开发,其配置使用也要按照一定的规则对配置文件进行编辑。例如在润乾报表系统中添加一个自定义函数的流程如下:Runqian report system, Jiebiao report system and X5 report platform are all analytical engines for developing WEB reports in JAVA language. Therefore, they all require self-defined functions to be developed in JAVA language, and their configuration and use must also be configured according to certain rules. to edit. For example, the process of adding a custom function in Runqian report system is as follows:

1、编写自定义函数的java类,继承com.runqian.report4.model.expression.Function这个类。1. Write the java class of the custom function and inherit the com.runqian.report4.model.expression.Function class.

2、在java的类路径的config目录下,找到customFunctions.properties文件,并在其中进行自定义函数类及函数名的登记。2. In the config directory of the java class path, find the customFunctions.properties file, and register the custom function class and function name in it.

3、在设计器端,将customFunctions.properties文件复制到\designer\web\WEB-INF\classes\config下,将类文件复制到designer\web\WEB-INF\classes下,有包名的,相应的建包路径。3. On the designer side, copy the customFunctions.properties file to \designer\web\WEB-INF\classes\config, and copy the class files to designer\web\WEB-INF\classes. If there is a package name, corresponding The build path of the package.

4、在web端,将customFunctions.properties文件复制到\webapps\demo\WEB-INF\classes\config下,将类文件复制到\webapps\demo\WEB-INF\classes下,有包名的,相应的建包路径。4. On the web side, copy the customFunctions.properties file to \webapps\demo\WEB-INF\classes\config, and copy the class files to \webapps\demo\WEB-INF\classes. If there is a package name, corresponding The build path of the package.

5、重启设计器。5. Restart the designer.

6、在设计器中运用自定义函数。6. Use custom functions in the designer.

上述自定义函数实现方法优点是功能强大,可以充分利用JAVA编程语言提供的编程能力,对用户的格式转换功能及业务逻辑处理功能都比较容易实现。The advantage of the method for realizing the above-mentioned self-defined function is that it is powerful in function, can make full use of the programming capability provided by the JAVA programming language, and is relatively easy to realize the format conversion function and business logic processing function for the user.

还有一种自定义函数的实现方案可以简单地设计和应用自定义函数【1】。在此方案中,自定义函数用四元组Fun={自定义函数名,SQL查询语句,输入参数个数,输出参数个数}定义,函数的功能由其中的SQL查询语句实现,报表用户只需编写此SQL查询语句,无需使用其他的编程语言。上述自定义函数四元组都确定后,就可提交到数据库,供其他报表用户共享使用。使用时可以像系统函数一样嵌入在表达式中。此方案的自定义函数解析过程如下:There is also a custom function implementation scheme that can simply design and apply a custom function [1]. In this solution, the user-defined function is defined by the quaternion Fun={custom function name, SQL query statement, number of input parameters, number of output parameters}, and the function of the function is realized by the SQL query statement. It is necessary to write this SQL query statement without using other programming languages. After the above-mentioned custom function quadruples are determined, they can be submitted to the database for shared use by other report users. When used, it can be embedded in an expression like a system function. The custom function parsing process of this scheme is as follows:

1、包含自定义函数的表达式中的变量识别与替换,所有变量都替换为具体的值,为自定义函数求值做准备。1. Variable identification and replacement in expressions containing custom functions, all variables are replaced with specific values to prepare for the evaluation of custom functions.

2、识别表达式中的自定义函数。2. Identify custom functions in expressions.

3、通过数据库中存储的用户自定义函数函数名,查到对应的SQL查询语句及参数个数信息与取得的变量个数进行比较,以验证变量定义个数是否正确。3. Through the function name of the user-defined function stored in the database, the corresponding SQL query statement and parameter number information are compared with the obtained variable number to verify whether the variable definition number is correct.

4、用表达式中的自定义函数的实际参数值替换SQL查询语句中的参数变量。4. Replace the parameter variable in the SQL query statement with the actual parameter value of the custom function in the expression.

5、执行上一步经变量替换后的SQL查询语句,得到返回值,即作为自定义函数的求值结果替换其在表达式中的出现。5. Execute the SQL query statement after variable substitution in the previous step, and get the return value, which is to replace its appearance in the expression as the evaluation result of the custom function.

对于润乾报表系统、杰表报表系统及X5报表平台等基于JAVA的自定义函数实现方法,其主要缺点在于:The main disadvantages of JAVA-based custom function implementation methods such as Runqian Reporting System, Jiebiao Reporting System and X5 Reporting Platform are:

创建自定义函数的技术门槛较高。各种报表系统在设计自定义函数时都要求用户使用指定的编程语言并按规定的格式编码,需要数据库操作的自定义函数还要掌握SQL编程。The technical threshold for creating custom functions is high. Various report systems require users to use a specified programming language and code in a prescribed format when designing custom functions, and master SQL programming for custom functions that require database operations.

自定义函数的部署复杂,在自定义函数较多时工作量大且易出错。The deployment of custom functions is complex, and when there are many custom functions, the workload is heavy and error-prone.

对于以四元组Fun={自定义函数名,SQL查询语句,输入参数个数,输出参数个数}实现的自定义函数方案,其主要不足在于功能受限,自定义函数执行及结果获取都是通过SQL查询语句实现的,难以实现包含业务逻辑规则的自定义函数功能。此外它还有效率低的缺点,即每次执行SQL查询语句数据库服务器都需要对其进行语法检查。For the self-defined function scheme realized by the quaternion Fun={custom function name, SQL query statement, number of input parameters, number of output parameters}, its main disadvantage is that the functions are limited, and the execution of the custom function and the acquisition of results are difficult. It is implemented through SQL query statements, and it is difficult to implement custom functions including business logic rules. In addition, it also has the disadvantage of low efficiency, that is, the database server needs to check the syntax of the SQL query statement every time it is executed.

综合分析当前各主流报表系统的自定义函数功能实现,发现存在如下问题:A comprehensive analysis of the implementation of custom functions in current mainstream reporting systems reveals the following problems:

创建自定义函数的技术门槛较高。各种报表系统在设计自定义函数时都要求用户使用指定的编程语言并按规定的格式编码,需要数据库操作的自定义函数还要掌握SQL编程。这意味着普通的报表设计者和用户可能需要学习一门新的编程语言及其开发工具以设计自定义函数。The technical threshold for creating custom functions is high. Various report systems require users to use a specified programming language and code in a prescribed format when designing custom functions, and master SQL programming for custom functions that require database operations. This means that ordinary report designers and users may need to learn a new programming language and its development tools to design custom functions.

自定义函数的部署复杂。在各种报表系统的自定义函数部署过程中,通常涉及到多个文件的创建与编辑,并要将其放入指定文件路径下,有些报表系统还需要重新启动设计器以让自定义函数生效,过程复杂,在自定义函数较多时工作量大且易出错。Deployment of custom functions is complex. In the process of custom function deployment of various reporting systems, the creation and editing of multiple files are usually involved, and they must be placed in the specified file path. Some report systems also need to restart the designer for the custom function to take effect , the process is complex, and when there are many custom functions, the workload is heavy and error-prone.

发明内容Contents of the invention

本发明目的在于提供一种以较低的技术门槛及简单的部署方式以解决背景技术提及的技术问题的报表系统自定义函数实现方法。The purpose of the present invention is to provide a reporting system custom function implementation method that solves the technical problems mentioned in the background art with a low technical threshold and a simple deployment method.

本发明提供的技术方案是:一种报表系统自定义函数实现方法,包括以下步骤:The technical solution provided by the present invention is: a method for realizing a self-defined function of a reporting system, comprising the following steps:

步骤1):自定义函数及参数登记。此步骤在报表设计器的功能界面上完成。报表设计者需提供自定义函数的名字、参数数目及每个参数的参数名及其描述,然后提交到系统数据库即可完成登记过程。报表系统函数用前缀$识别,而自定义函数用前缀$$识别,如一个函数若形如$FUNC(),则是系统函数,若形如$$FUNC(),则是自定义函数。此增加前缀的函数命名方法有利于区分普通带括号表达式、系统函数及自定义函数。Step 1): Custom function and parameter registration. This step is done on the functional interface of the report designer. The report designer needs to provide the name of the custom function, the number of parameters, and the parameter name and description of each parameter, and then submit it to the system database to complete the registration process. Report system functions are identified with the prefix $, while custom functions are identified with the prefix $$. For example, if a function is in the form of $FUNC(), it is a system function, and if it is in the form of $$FUNC(), it is a custom function. This method of adding a prefix to the function name helps to distinguish between ordinary parenthesized expressions, system functions, and custom functions.

步骤2):自定义函数相关存储过程创建。此步骤在数据库管理系统中完成。所有自定义函数的功能都由其相关的存储过程实现。自定义函数相关存储过程的名字为自定义函数名字去掉前缀$$而得到,如自定义函数名为$$myFunc(),则其关联存储过程名为myFunc(),这种函数名与存储过程名的相关定义方法保证了解析自定义函数时可以直接从自定义函数名得到其相关存储过程名,而无需从数据库中检索。所有自定义函数相关存储过程的参数列表采用统一格式myFunc(inParams,outParam),不管自定义函数包含多少个参数,但其相关存储过程均只包含一个输入参数和一个输出参数,输入参数用于向存储过程传递参数值,若自定义函数有多个参数,则此多个参数被组合在一起传递至输入参数,输出参数用于返回存储过程执行结果。自定义函数相关存储过程中的处理逻辑包含如下步骤:A)接收输入参数,将组合在一起的多个参数分解成单个参数;B)对每个参数进行类型转换,转换成需要的数据类型;C)执行自定义函数的处理逻辑;D)将执行结果设置到输出参数并返回。Step 2): Create stored procedures related to custom functions. This step is done in the database management system. The functions of all custom functions are realized by their related stored procedures. The name of the stored procedure related to the custom function is obtained by removing the prefix $$ from the name of the custom function. For example, the name of the custom function is $$myFunc(), and the name of the associated stored procedure is myFunc(). This function name is the same as the stored procedure The relative definition method of the name guarantees that the related stored procedure name can be directly obtained from the custom function name when parsing the custom function without searching from the database. The parameter list of all custom function-related stored procedures adopts the unified format myFunc(inParams,outParam). No matter how many parameters the custom function contains, its related stored procedures only contain one input parameter and one output parameter. The input parameters are used to The stored procedure passes parameter values. If the custom function has multiple parameters, the multiple parameters are combined and passed to the input parameters, and the output parameters are used to return the execution result of the stored procedure. The processing logic in the stored procedure related to the custom function includes the following steps: A) receiving input parameters, decomposing multiple parameters combined into a single parameter; B) performing type conversion for each parameter, and converting it into the required data type; C) Execute the processing logic of the custom function; D) Set the execution result to the output parameter and return it.

步骤3):在报表中使用自定义函数。此步骤在报表设计器中完成。在报表中使用自定义函数比较简单,按照其在步骤1中定义的格式单独使用或用在表达式中即可。Step 3): Use the custom function in the report. This step is done in Report Designer. It is relatively simple to use a custom function in a report, and it can be used alone or in an expression according to the format defined in step 1.

步骤4):识别报表中的自定义函数。此步骤在报表解析与创建引擎中完成。在报表表达式解析求值过程中,根据自定义函数命名的前缀命名规则,识别其中的自定义函数,提取出来准备解析。Step 4): Identify the custom functions in the report. This step is done in the report parsing and creation engine. In the process of parsing and evaluating report expressions, according to the prefix naming rules of custom function names, the custom functions are identified and extracted for parsing.

步骤5):自定义函数参数列表中变量识别与替换。此步骤在报表解析与创建引擎中完成。步骤4提取出的自定义函数的参数列表中,可能包含变量、常量及其他函数。本步骤包括如下子步骤:对其中的变量及其他函数进行识别;求取参数中变量的实际值,对参数中的函数进行计算得到结果值;用参数变量的实际值替换其在参数列表中的出现,用参数中函数的执行结果值替换其在参数列表中的出现。经过上述步骤,自定义函数的参数列表中仅包含常量。Step 5): Identify and replace variables in the custom function parameter list. This step is done in the report parsing and creation engine. The parameter list of the custom function extracted in step 4 may contain variables, constants and other functions. This step includes the following sub-steps: identify the variables and other functions in it; obtain the actual value of the variable in the parameter, calculate the function in the parameter to obtain the result value; replace the actual value of the parameter variable in the parameter list occurrences, replaces its occurrences in the parameter list with the value of the function's execution result in the parameter. After the above steps, the parameter list of the custom function only contains constants.

步骤6):准备参数并调用自定义函数关联存储过程。此步骤在报表解析与创建引擎中完成。包括如下步骤:准备自定义函数关联存储过程的输入参数。将步骤5中得到的只含常量的参数表去掉前后的括号,赋值给输入参数;设置自定义函数关联存储过程的输出参数;去掉自定义函数名的前缀$$,作为存储过程名;使用存储过程名及参数设置数据库访问组件,提交存储过程到数据库服务器执行。Step 6): Prepare parameters and call the custom function associated stored procedure. This step is done in the report parsing and creation engine. The method includes the following steps: preparing the input parameters of the stored procedure associated with the custom function. Remove the parentheses before and after the constant from the parameter table obtained in step 5, and assign it to the input parameter; set the output parameter of the stored procedure associated with the custom function; remove the prefix $$ of the custom function name, and use it as the stored procedure name; use the stored procedure The procedure name and parameters set the database access component, and submit the stored procedure to the database server for execution.

步骤7):执行自定义函数关联存储过程并返回结果。此步骤在数据库管理系统中实现。Step 7): Execute the custom function associated stored procedure and return the result. This step is implemented in the database management system.

步骤8):接收自定义函数关联存储过程返回结果并应用到报表中。此步骤在报表解析与创建引擎中完成。Step 8): Receive the result returned by the custom function associated stored procedure and apply it to the report. This step is done in the report parsing and creation engine.

本发明的有益效果是:The beneficial effects of the present invention are:

本发明提供的一种报表系统自定义函数处理方案,其核心思想在于所有自定义函数均由数据库存储过程实现。各种商业数据库管理系统都提供了设计存储过程的机制,其中包含各种流程控制机制、大量格式处理函数、数学函数及日期函数等,同时可以直接操作SQL语句。存储过程还有一个优点就是一次编译后,以后重复执行无需再编译,执行效率较高,而用其他编程语言提交到数据库系统的SQL查询语句每次执行前都要执行编译操作。The core idea of the self-defined function processing scheme of the report system provided by the present invention is that all the self-defined functions are realized by database stored procedures. Various commercial database management systems provide mechanisms for designing stored procedures, which include various process control mechanisms, a large number of format processing functions, mathematical functions, and date functions, etc., and can directly operate SQL statements. Another advantage of the stored procedure is that after one compilation, it does not need to be recompiled for repeated execution in the future, and the execution efficiency is high, while the SQL query statement submitted to the database system in other programming languages must be compiled before each execution.

本发明的优点包括:(1)创建自定义函数的技术门槛较低,报表用户只需要熟悉存储过程的设计就可以创建自定义函数,而各种数据库管理系统中创建存储过程的方法简单、语法接近。用户无需使用其他编程工具和编程语言。(2)自定义函数部署简单,只要在设计器中登记了自定义函数的名称和参数信息并提交及在数据库中创建了关联存储过程就完成了自定义函数的创建及部署。The advantages of the present invention include: (1) The technical threshold for creating a custom function is relatively low, and report users only need to be familiar with the design of stored procedures to create custom functions, while the methods for creating stored procedures in various database management systems are simple and easy to use. near. Users do not need to use other programming tools and programming languages. (2) The self-defined function is easy to deploy, as long as the name and parameter information of the self-defined function are registered in the designer and submitted, and the associated stored procedure is created in the database, the creation and deployment of the self-defined function is completed.

附图说明Description of drawings

当结合附图考虑时,通过参照下面的详细描述,能够更完整更好地理解本发明以及容易得知其中许多伴随的优点,但此处所说明的附图用来提供对本发明的进一步理解,构成本发明的一部分,本发明的示意性实施例及其说明用于解释本发明,并不构成对本发明的不当限定,其中:A more complete and better understanding of the invention, and many of its attendant advantages, will readily be learned by reference to the following detailed description when considered in conjunction with the accompanying drawings, but the accompanying drawings illustrated herein are intended to provide a further understanding of the invention and constitute A part of the present invention, the exemplary embodiment of the present invention and its description are used to explain the present invention, and do not constitute an improper limitation of the present invention, wherein:

图1是本发明的报表系统自定义函数实现方法的总体流程框图;Fig. 1 is the overall flow diagram of the report system self-defined function realization method of the present invention;

图2是自定义函数关联存储过程内部处理流程的流程框图;Figure 2 is a flowchart of the internal processing flow of the custom function associated stored procedure;

图3是自定义函数参数列表中变量识别与替换的流程框图;Fig. 3 is a flow chart of variable identification and replacement in the custom function parameter list;

图4是准备参数并调用自定义函数关联存储过程的流程框图。Fig. 4 is a flow chart of preparing parameters and calling a custom function associated stored procedure.

具体实施方式detailed description

为使本发明的上述目的、特征和优点能够更加明显易懂,下面结合附图和具体实施方式对本发明作进一步详细的说明。In order to make the above objects, features and advantages of the present invention more comprehensible, the present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.

参考附图,下面以一个自定义函数的定义与解析的具体过程说明本发明的技术方案。Referring to the accompanying drawings, the technical solution of the present invention will be described below with a specific process of definition and analysis of a self-defined function.

假定需要一个自定义函数将默认日期格式“08/25/2014”转换为中文日期格式,如“二零一四年八月二十五日”,根据附图1,将经过如下步骤:chnDate(today(),’YYYY年MM月DD日’)将当天日期格式化为中国日期格式。Assume that a custom function is needed to convert the default date format "08/25/2014" into a Chinese date format, such as "August 25th, 2014". According to attached drawing 1, the following steps will be taken: chnDate( today(), 'YYYYYYYYYMMDDDD') will format the date of the day into the Chinese date format.

步骤1):自定义函数及参数登记。登记自定义函数为$$chnDate(oldDate,format),$$chnDate是自定义函数名,oldDate是默认格式的待转换日期,format是期望转换成的格式。Step 1): Custom function and parameter registration. Register the custom function as $$chnDate(oldDate,format), where $$chnDate is the name of the custom function, oldDate is the date to be converted in the default format, and format is the desired format.

步骤2):自定义函数相关存储过程创建。在数据库管理系统中创建一个存储过程,形如chnDate(inParams,outParam),inParams是输入参数,outParam是输出参数,均为字符串类型。存储过程chnDate中实现附图2的处理逻辑,对inParams中用逗号分隔的旧的日期及期望格式两个参数值分解成两个字符串型的参数值,并分别转换成日期类型及结构体类型,然后对其进行处理并将执行结果设置到输出参数outParam返回。Step 2): Create stored procedures related to custom functions. Create a stored procedure in the database management system, in the form of chnDate(inParams, outParam), inParams is the input parameter, and outParam is the output parameter, both of which are string types. Implement the processing logic in Figure 2 in the stored procedure chnDate, decompose the comma-separated old date and expected format parameter values in inParams into two string-type parameter values, and convert them into date type and structure type respectively , and then process it and set the execution result to the output parameter outParam to return.

步骤3):在报表中使用自定义函数。使用例子如Step 3): Use the custom function in the report. Examples of use such as

$STRCAT(“打印日期:”,$$chnDate($TDODAY(),’YYYY年MM月DD日’)),其中系统函数$STRCAT()用于将两个字符串拼接成一个字符串,系统函数$TDODAY()用于获取默认格式的当前日期,若当前日期是“08/25/2014”,则上述例子将得到字符串“打印日期:二零一四年八月二十五日”。自定义函数的参数个数应与步骤1中登记的相同。$STRCAT("Print date:", $$chnDate($TDODAY(), 'YYYY, MM, DD')), the system function $STRCAT() is used to concatenate two strings into one string, and the system The function $TDODAY() is used to obtain the current date in the default format. If the current date is "08/25/2014", the above example will get the string "printed date: August 25, 2014". The number of parameters of the user-defined function should be the same as that registered in step 1.

步骤4):识别报表中的自定义函数。根据自定义函数前缀及括号匹配关系,可以很容易地识别$STRCAT(“打印日期:”,$$chnDate($TDODAY(),’YYYY年MM月DD日’))中的自定义函数$$chnDate($TDODAY(),’YYYY年MM月DD日’)。Step 4): Identify the custom functions in the report. According to the custom function prefix and bracket matching relationship, it is easy to identify the custom function $$ in $STRCAT("print date:",$$chnDate($TDODAY(),'YYYYYYYYYMMDDDD')) chnDate($TDODAY(), 'MM, DD, YYYY').

步骤5):自定义函数参数列表中变量识别与替换。$$chnDate($TDODAY(),’YYYY年MM月DD日’)中,其参数列表为“$TDODAY(),’YYYY年MM月DD日’”,其中$TDODAY()为系统函数,需要求值,假设求值得到结果:08/25/2014,用其替换$TDODAY()在$$chnDate($TDODAY(),’YYYY年MM月DD日’)中的出现,得到$$chnDate(‘08/25/2014’,’YYYY年MM月DD日’)。至此,自定义函数的参数列表中仅包含常量。Step 5): Identify and replace variables in the custom function parameter list. In $$chnDate($TDODAY(), 'MM, DD, YYYY'), the parameter list is "$TDODAY(), 'MM, DD, YYYY'", where $TDODAY() is a system function and needs to be Evaluate, assuming that the result of the evaluation is: 08/25/2014, use it to replace the occurrence of $TDODAY() in $$chnDate($TDODAY(),'YYYYYYYYYMMDDDD'), and get $$chnDate( '08/25/2014', 'MM DD YYYY'). So far, the parameter list of the custom function contains only constants.

步骤6):准备参数并调用自定义函数关联存储过程。包括如下步骤:1、自定义函数关联存储过程的输入参数值为“‘08/25/2014’,’YYYY年MM月DD日’”。2、设置自定义函数关联存储过程的输出参数;3、以chnDate作为存储过程名;4、使用存储过程名及参数设置数据库访问组件,提交存储过程到数据库服务器执行。Step 6): Prepare parameters and call the custom function associated stored procedure. It includes the following steps: 1. The input parameter value of the stored procedure associated with the custom function is "'08/25/2014', 'MM, DD, YYYY'". 2. Set the output parameters of the stored procedure associated with the custom function; 3. Use chnDate as the stored procedure name; 4. Use the stored procedure name and parameters to set the database access component, and submit the stored procedure to the database server for execution.

步骤7):执行步骤6)中设置的存储过程并返回结果,此处返回结果为“二零一四年八月二十五日”。Step 7): Execute the stored procedure set in step 6) and return the result, where the returned result is "August 25, 2014".

步骤8):接收步骤7)中存储过程返回结果并应用到报表表达式中,即将步骤7)返回结果替换自定义函数$$chnDate($TDODAY(),’YYYY年MM月DD日’)在表达式$STRCAT(“打印日期:”,$$chnDate($TDODAY(),’YYYY年MM月DD日’))中的出现,得到$STRCAT(“打印日期:”,“二零一四年八月二十五日”),至此,自定义函数解析结束。Step 8): Receive the result returned by the stored procedure in step 7) and apply it to the report expression, that is, replace the result returned by step 7) with the custom function $$chnDate($TDODAY(), 'MM, DD, YYYY') in The occurrence of the expression $STRCAT("print date:", $$chnDate($TDODAY(), 'YYYY, MM, DD, YYYY')) gets $STRCAT("print date:", "2014 August 25"), so far, the custom function analysis is over.

本发明还可以有其它的替代技术方案,比如:The present invention can also have other alternative technical solutions, such as:

在步骤1)中,自定义函数的名字也可以不带特殊的前缀,则在报表引擎解析时可以先从系统数据库中获取所有系统函数及自定义函数的名字列表,再与报表中用到的函数进行比对。In step 1), the name of the custom function can also be without a special prefix, then when the report engine parses, it can first obtain the name list of all system functions and custom functions from the system database, and then compare them with the names used in the report function for comparison.

在步骤2)中,自定义函数关联的存储过程名也可以保存到数据库中自定义函数的记录中,则存储过程名及其关联自定义函数名之间可以没有派生关系,其关联关系可以从自定义函数在数据库中的登记信息中找到。则在为自定义函数调用关联存储过程时要先从数据库中获取该自定义函数关联的存储过程名。此外,自定义函数的处理逻辑也可以用数据库系统中的用户自定义SQL函数实现,与使用存储过程不同在于,在存储过程中处理结果通过输出参数返回,而在用户自定义SQL函数中处理结果通过函数返回值返回。In step 2), the stored procedure name associated with the custom function can also be saved in the record of the custom function in the database, then there may be no derivation relationship between the stored procedure name and its associated custom function name, and its association relationship can be obtained from The custom function is found in the registration information in the database. Then, when calling an associated stored procedure for a custom function, the name of the stored procedure associated with the custom function must first be obtained from the database. In addition, the processing logic of the user-defined function can also be realized by the user-defined SQL function in the database system. The difference from using the stored procedure is that the processing result is returned through the output parameter in the stored procedure, while the result is processed in the user-defined SQL function Return by function return value.

以上实例的说明只是用于帮助理解本发明的核心思想;同时,对于本领域的一般技术人员,依据本发明的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本发明的限制。The description of the above examples is only used to help understand the core ideas of the present invention; meanwhile, for those of ordinary skill in the art, according to the ideas of the present invention, there will be changes in the specific implementation methods and application ranges. , the contents of this specification should not be construed as limiting the present invention.

Claims (2)

1.一种报表系统自定义函数实现方法,其特征在于,包括以下步骤:1. A report system self-defined function realization method, is characterized in that, comprises the following steps: 步骤1):自定义函数及参数登记;在报表设计器的功能界面上,报表设计者提供自定义函数的名字、参数数目及每个参数的参数名及其描述,然后提交到系统数据库;自定义函数用前缀$$识别;Step 1): Registration of custom functions and parameters; on the function interface of the report designer, the report designer provides the name of the custom function, the number of parameters, and the parameter name and description of each parameter, and then submits it to the system database; The definition function is identified with the prefix $$; 步骤2):自定义函数相关存储过程创建;在数据库管理系统中,所有自定义函数的功能都由其相关的存储过程实现;自定义函数相关存储过程的名字为自定义函数名字去掉前缀$$而得到;所有自定义函数相关存储过程的参数列表采用统一格式;相关存储过程均只包含一个输入参数和一个输出参数,输入参数用于向存储过程传递参数值,若自定义函数有多个参数,则此多个参数被组合在一起传递至输入参数,输出参数用于返回存储过程执行结果;Step 2): Create the stored procedure related to the custom function; in the database management system, the functions of all custom functions are realized by its related stored procedure; the name of the stored procedure related to the custom function is the name of the custom function minus the prefix $$ And get; the parameter list of all custom function-related stored procedures adopts a unified format; the relevant stored procedures only contain one input parameter and one output parameter, and the input parameter is used to pass parameter values to the stored procedure. If the custom function has multiple parameters , the multiple parameters are combined and passed to the input parameters, and the output parameters are used to return the execution result of the stored procedure; 步骤3):在报表中使用自定义函数;在报表设计器中,按照自定义函数在步骤1中定义的格式单独使用或用在表达式中;Step 3): Use the custom function in the report; in the report designer, use it alone or in an expression according to the format defined in step 1 of the custom function; 步骤4):识别报表中的自定义函数;在报表表达式解析求值过程中,根据自定义函数命名的前缀命名规则,识别其中的自定义函数,提取出来准备解析;Step 4): Identify the custom functions in the report; in the process of parsing and evaluating report expressions, identify the custom functions in them according to the prefix naming rules of the custom function names, and extract them for parsing; 步骤5):自定义函数参数列表中变量识别与替换;步骤4)提取出的自定义函数的参数列表中,对其中的变量及其它函数进行识别;求取参数中变量的实际值,对参数中的函数进行计算得到结果值;用参数变量的实际值替换其在参数列表中的出现,用参数中函数的执行结果值替换其在参数列表中的出现;经过上述步骤,自定义函数的参数列表中仅包含常量;Step 5): Identify and replace variables in the custom function parameter list; step 4) identify the variables and other functions in the parameter list of the self-defined function extracted in step 4); obtain the actual value of the variable in the parameter, and the parameters The function in is calculated to obtain the result value; replace its appearance in the parameter list with the actual value of the parameter variable, and replace its appearance in the parameter list with the execution result value of the function in the parameter; after the above steps, the parameter of the custom function The list contains only constants; 步骤6):准备参数并调用自定义函数关联存储过程;包括如下步骤:Step 6): Prepare parameters and call the custom function associated stored procedure; including the following steps: 准备自定义函数关联存储过程的输入参数,将步骤5)中得到的只含常量的参数表去掉前后的括号,赋值给输入参数;Prepare the input parameters of the custom function-associated stored procedure, remove the parentheses before and after the constant-only parameter table obtained in step 5), and assign it to the input parameter; 设置自定义函数关联存储过程的输出参数;Set the output parameters of the stored procedure associated with the custom function; 去掉自定义函数名的前缀$$,作为存储过程名;Remove the prefix $$ of the custom function name as the stored procedure name; 使用存储过程名及参数设置数据库访问组件,提交存储过程到数据库服务器执行;Use the stored procedure name and parameters to set the database access component, and submit the stored procedure to the database server for execution; 步骤7):执行自定义函数关联存储过程并返回结果;Step 7): Execute the custom function associated stored procedure and return the result; 步骤8):接收自定义函数关联存储过程返回结果并应用到报表中。Step 8): Receive the result returned by the custom function associated stored procedure and apply it to the report. 2.根据权利要求1所述的一种报表系统自定义函数实现方法,其特征在于,步骤2)中,自定义函数相关存储过程中的处理逻辑包含如下步骤:2. a kind of reporting system self-defined function implementation method according to claim 1, is characterized in that, in step 2), the processing logic in the relevant stored procedure of self-defined function comprises the following steps: A)接收输入参数,将组合在一起的多个参数分解成单个参数;A) receiving input parameters, decomposing multiple parameters combined into a single parameter; B)对每个参数进行类型转换,转换成需要的数据类型;B) perform type conversion on each parameter, and convert it into the required data type; C)执行自定义函数的处理逻辑;C) Execute the processing logic of the custom function; D)将执行结果设置到输出参数并返回。D) Set the execution result to the output parameter and return it.
CN201410722935.0A 2014-12-02 2014-12-02 A kind of implementation method of reporting system SQL Expired - Fee Related CN104461531B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201410722935.0A CN104461531B (en) 2014-12-02 2014-12-02 A kind of implementation method of reporting system SQL

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201410722935.0A CN104461531B (en) 2014-12-02 2014-12-02 A kind of implementation method of reporting system SQL

Publications (2)

Publication Number Publication Date
CN104461531A CN104461531A (en) 2015-03-25
CN104461531B true CN104461531B (en) 2017-11-07

Family

ID=52907642

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201410722935.0A Expired - Fee Related CN104461531B (en) 2014-12-02 2014-12-02 A kind of implementation method of reporting system SQL

Country Status (1)

Country Link
CN (1) CN104461531B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106227896A (en) * 2016-08-28 2016-12-14 杭州合众数据技术有限公司 A kind of big data visualization fractional analysis method
CN108255967B (en) * 2017-12-26 2021-03-02 平安科技(深圳)有限公司 Method and device for calling storage process, storage medium and terminal
CN108536400A (en) * 2018-04-12 2018-09-14 珠海横琴盛达兆业科技投资有限公司 A kind of pharmacy's receipt Method of printing based on jatoolsPrinter
CN110083386B (en) * 2019-04-04 2024-03-19 平安普惠企业管理有限公司 Random number generation control method, device, computer equipment and storage medium
CN109992259B (en) * 2019-04-15 2020-10-30 成都四方伟业软件股份有限公司 Function dynamic creating method and device and electronic equipment
CN112799671B (en) * 2019-11-13 2024-10-18 北京配天技术有限公司 Function analysis method and computer equipment thereof
CN111708992B (en) * 2020-05-06 2023-07-14 咪咕文化科技有限公司 Report data access method, device, electronic equipment and storage medium
CN112416322A (en) * 2020-11-20 2021-02-26 城云科技(中国)有限公司 Implementation method for acquiring previous data in data set according to self-circulation function
CN115794043B (en) * 2023-01-31 2023-06-09 帆软软件有限公司帆软南京分公司 System and method for calculating table data aggregation processing of BI tool

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101710273A (en) * 2009-10-28 2010-05-19 金蝶软件(中国)有限公司 Method and device for analyzing multi-dimensional query sentence in online analysis processing server
CN102096664A (en) * 2009-12-09 2011-06-15 新奥特(北京)视频技术有限公司 Report generating method
CN102436498A (en) * 2011-11-14 2012-05-02 深圳市华力特电气股份有限公司 Report generation method and related device
US8656367B1 (en) * 2011-07-11 2014-02-18 Wal-Mart Stores, Inc. Profiling stored procedures

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101710273A (en) * 2009-10-28 2010-05-19 金蝶软件(中国)有限公司 Method and device for analyzing multi-dimensional query sentence in online analysis processing server
CN102096664A (en) * 2009-12-09 2011-06-15 新奥特(北京)视频技术有限公司 Report generating method
US8656367B1 (en) * 2011-07-11 2014-02-18 Wal-Mart Stores, Inc. Profiling stored procedures
CN102436498A (en) * 2011-11-14 2012-05-02 深圳市华力特电气股份有限公司 Report generation method and related device

Also Published As

Publication number Publication date
CN104461531A (en) 2015-03-25

Similar Documents

Publication Publication Date Title
CN104461531B (en) A kind of implementation method of reporting system SQL
US9465590B2 (en) Code generation framework for application program interface for model
Miles et al. Prime: A methodology for developing provenance-aware applications
US20040158820A1 (en) System for generating an application framework and components
US8701087B2 (en) System and method of annotating class models
US9251222B2 (en) Abstracted dynamic report definition generation for use within information technology infrastructure
CN102279750A (en) Iterative code generation method based on domain knowledge sharing
WO2012034440A1 (en) Method and device for generating database upgrading script
KR20080084966A (en) Conforming web services to an updated contract
CN102663103A (en) Configurable method for automatically generating database and accessing data
US20110029767A1 (en) System and Method for Transforming Configuration Data Items in a Configuration Management Database
WO2018233673A1 (en) Method and apparatus for configuring model code in controller, and storage medium
CN109614084A (en) Web program and its rapid development framework, development method and related equipment
CN112130849B (en) Code automatic generation method and device
CN101055521B (en) Mapping rule visualized generation method and system
US9052906B2 (en) Modularized customization of a model in a model driven development environment
CN112799638B (en) Non-invasive rapid development method, platform, terminal and storage medium
CN113672233B (en) Server out-of-band management method, device and equipment based on Redfish
Le Zou et al. On synchronizing with web service evolution
CN114265636A (en) A configuration method and device of a communication protocol, and a storage medium
CN109241158B (en) Data source customization method and device for rule management
Aksoy et al. MATAWS: A multimodal approach for automatic WS semantic annotation
CN116755684B (en) OAS Schema generation method, device, equipment and medium
CN119440515B (en) Data model creation method, device, electronic device and storage medium
US20250110977A1 (en) System and method for generating an executable data query

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CF01 Termination of patent right due to non-payment of annual fee

Granted publication date: 20171107

Termination date: 20201202

CF01 Termination of patent right due to non-payment of annual fee