CN110780860A - Generation method and device of table building script, computer equipment and storage medium - Google Patents
Generation method and device of table building script, computer equipment and storage medium Download PDFInfo
- Publication number
- CN110780860A CN110780860A CN201910851107.XA CN201910851107A CN110780860A CN 110780860 A CN110780860 A CN 110780860A CN 201910851107 A CN201910851107 A CN 201910851107A CN 110780860 A CN110780860 A CN 110780860A
- Authority
- CN
- China
- Prior art keywords
- database
- script
- establishing
- database table
- preset
- 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.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/31—Programming languages or programming paradigms
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2282—Tablespace storage structures; Management thereof
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/427—Parsing
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Data Mining & Analysis (AREA)
- Databases & Information Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本申请实施例提供了一种建表脚本的生成方法、装置、计算机设备及计算机可读存储介质。本申请实施例属于数据库开发技术,实现建表脚本的生成时,获取Excel文件,Excel文件中包含建立数据库表所需的表数据,表数据包括表名称、所述数据库表中包含的字段及其数据类型;通过预设方式解析Excel文件以得到表数据;通过第一预设方法,将表数据对应插入预设的用于建立数据库表的语法格式中以得到多个分脚本;根据建立数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个分脚本进行拼接以生成建立数据库表的脚本,通过自动生成建表脚本,节省了生成建表脚本的时间成本,提高了建表脚本的生成的效率。
Embodiments of the present application provide a method, apparatus, computer device, and computer-readable storage medium for generating a table building script. The embodiment of the present application belongs to the database development technology. When the generation of the table building script is realized, an Excel file is obtained, and the Excel file contains the table data required for building a database table, and the table data includes the table name, the fields contained in the database table and its data type; parse the Excel file through a preset method to obtain table data; through the first preset method, the table data is correspondingly inserted into the preset grammar format for establishing a database table to obtain a plurality of subscripts; according to establishing a database table The syntax of the database management system used is to splicing a plurality of sub-scripts through the second preset method to generate a script for creating a database table, and by automatically generating a table-building script, the time cost of generating the table-building script is saved, and the construction is improved. Efficiency of table script generation.
Description
技术领域technical field
本申请涉及数据库开发技术领域,尤其涉及一种建表脚本的生成方法、装置、计算机设备及计算机可读存储介质。The present application relates to the technical field of database development, and in particular, to a method, apparatus, computer device, and computer-readable storage medium for generating a table building script.
背景技术Background technique
建立数据库表,简称建表,建立数据库表的脚本,简称建表脚本,又可以称为建表脚本。由于任何数据需求都离不开数据库表,所以建表是开发的第一步。传统技术中,建表一般是通过IT行业的编码人员通过书写代码来建立数据库表的脚本,尤其是需要建立多个数据库表时,建表是个既繁杂又没有技术含量的工作,并且容易出现字符及格式等笔误,尤其字段很多的情况,更要花费很大的时间成本,导致大大降低了建表脚本的生成效率。The creation of database tables, referred to as table creation, and the script for creating database tables, referred to as table creation scripts, can also be referred to as table creation scripts. Since any data requirement is inseparable from a database table, building a table is the first step in development. In traditional technology, table building is generally a script for creating database tables by coders in the IT industry by writing codes. Especially when multiple database tables need to be created, table building is a complicated and non-technical work, and characters are prone to appear. and format and other clerical errors, especially when there are many fields, it will cost a lot of time, which greatly reduces the generation efficiency of the table building script.
发明内容SUMMARY OF THE INVENTION
本申请实施例提供了一种建表脚本的生成方法、装置、计算机设备及计算机可读存储介质,能够解决传统技术中建表脚本的生成效率低的问题。The embodiments of the present application provide a method, apparatus, computer device, and computer-readable storage medium for generating a table building script, which can solve the problem of low generation efficiency of the table building script in the traditional technology.
第一方面,本申请实施例提供了一种建表脚本的生成方法,所述方法包括:获取Excel文件,所述Excel文件中包含建立数据库表所需的表数据,所述表数据包括建立所述数据库表所需的表名称、所述数据库表中包含的字段及所述字段的数据类型;通过预设方式解析所述Excel文件以得到所述表数据;通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本;根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本。In a first aspect, an embodiment of the present application provides a method for generating a table building script, the method comprising: obtaining an Excel file, where the Excel file contains table data required for building a database table, and the table data includes creating all the tables. The table name required by the database table, the field contained in the database table and the data type of the field; the Excel file is parsed by a preset method to obtain the table data; The table data is correspondingly inserted into the preset grammar format for establishing the database table to obtain a plurality of subscripts; according to the grammar of the database management system used for establishing the database table, multiple The subscripts are spliced to generate a script for building the database table.
第二方面,本申请实施例还提供了一种建表脚本的生成装置,包括:获取单元,用于获取Excel文件,所述Excel文件中包含建立数据库表所需的表数据,所述表数据包括建立所述数据库表所需的表名称、所述数据库表中包含的字段及所述字段的数据类型;解析单元,用于通过预设方式解析所述Excel文件以得到所述表数据;插入单元,用于通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本;生成单元,用于根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本。In a second aspect, an embodiment of the present application further provides a device for generating a table building script, including: an acquisition unit configured to acquire an Excel file, where the Excel file contains table data required for establishing a database table, and the table data Including the table name required for establishing the database table, the field contained in the database table and the data type of the field; a parsing unit for parsing the Excel file by a preset method to obtain the table data; inserting a unit for correspondingly inserting the table data into a preset syntax format for establishing the database table by a first preset method to obtain a plurality of subscripts; a generating unit for establishing the database table according to the Using the syntax of the database management system, a plurality of the sub-scripts are spliced by a second preset method to generate a script for establishing the database table.
第三方面,本申请实施例还提供了一种计算机设备,其包括存储器及处理器,所述存储器上存储有计算机程序,所述处理器执行所述计算机程序时实现所述建表脚本的生成方法。In a third aspect, an embodiment of the present application further provides a computer device, which includes a memory and a processor, the memory stores a computer program, and the processor generates the table building script when executing the computer program method.
第四方面,本申请实施例还提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时使所述处理器执行所述建表脚本的生成方法。In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor executes the table building process Script generation method.
本申请实施例提供了一种建表脚本的生成方法、装置、计算机设备及计算机可读存储介质。本申请实施例实现建表脚本的生成时,只需开发人员将字段名称和表名称写入Excel文件,计算机设备获取所述Excel文件,所述Excel文件中包含建立数据库表所需的表数据,所述表数据包括建立所述数据库表所需的表名称、所述数据库表中包含的字段及所述字段的数据类型,即可自动通过预设方式解析所述Excel文件以得到所述表数据,并通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本,然后根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本,从而实现了自动生成建表脚本,相对于传统技术中由开发人员通过书写代码生成建立数据库表的脚本,本申请实施例通过自动生成建表脚本,让开发人员从繁杂而没有技术含量的机械性劳动中解脱出来,节省了生成建表脚本的时间成本,提高了建表脚本的生成的效率。Embodiments of the present application provide a method, apparatus, computer device, and computer-readable storage medium for generating a table building script. When the embodiment of the present application realizes the generation of the table building script, the developer only needs to write the field name and the table name into the Excel file, and the computer device obtains the Excel file, and the Excel file contains the table data required for building the database table, The table data includes the table name required to establish the database table, the fields contained in the database table and the data type of the field, and the Excel file can be automatically parsed by a preset method to obtain the table data. , and through the first preset method, the table data is correspondingly inserted into the preset grammatical format for establishing the database table to obtain a plurality of subscripts, and then according to the database management system used for establishing the database table The grammar, the second preset method is used to splicing a plurality of the sub-scripts to generate the script for establishing the database table, thereby realizing the automatic generation of the table-building script. The script of the database table, the embodiment of the present application, by automatically generating the table-building script, frees developers from complicated and unskilled mechanical labor, saves the time and cost of generating the table-building script, and improves the generation of the table-building script. s efficiency.
附图说明Description of drawings
为了更清楚地说明本申请实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to explain the technical solutions of the embodiments of the present application more clearly, the following briefly introduces the accompanying drawings used in the description of the embodiments. For those of ordinary skill, other drawings can also be obtained from these drawings without any creative effort.
图1为本申请实施例提供的建表脚本的生成方法的流程示意图;1 is a schematic flowchart of a method for generating a table building script provided by an embodiment of the present application;
图2为本申请实施例提供的建表脚本的生成装置的示意性框图;以及FIG. 2 is a schematic block diagram of an apparatus for generating a table building script provided by an embodiment of the present application; and
图3为本申请实施例提供的计算机设备的示意性框图。FIG. 3 is a schematic block diagram of a computer device according to an embodiment of the present application.
具体实施方式Detailed ways
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
应当理解,当在本说明书和所附权利要求书中使用时,术语“包括”和“包含”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。It is to be understood that, when used in this specification and the appended claims, the terms "comprising" and "comprising" indicate the presence of the described features, integers, steps, operations, elements and/or components, but do not exclude one or The presence or addition of a number of other features, integers, steps, operations, elements, components, and/or sets thereof.
还应当理解,在此本申请说明书中所使用的术语仅仅是出于描述特定实施例的目的而并不意在限制本申请。如在本申请说明书和所附权利要求书中所使用的那样,除非上下文清楚地指明其它情况,否则单数形式的“一”、“一个”及“该”意在包括复数形式。It should also be understood that the terminology used in the specification of the application herein is for the purpose of describing particular embodiments only and is not intended to limit the application. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural unless the context clearly dictates otherwise.
还应当进一步理解,在本申请说明书和所附权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。It should also be further understood that, as used in this specification and the appended claims, the term "and/or" refers to and including any and all possible combinations of one or more of the associated listed items .
本申请实施例提供的建表脚本的生成方法可应用于终端或者服务器等计算机设备中,通过安装于终端或者服务器上的软件来实现所述建表脚本的生成方法的步骤,其中所述终端可以为手机、笔记本电脑、平板电脑或者台式电脑等电子设备,所述服务器可以为云服务器或者服务器集群等。以终端为例,本申请实施例提供的建表脚本的生成方法的具体实现过程如下:终端获取Excel文件,所述Excel文件中包含建立数据库表所需的表数据,所述表数据包括建立所述数据库表所需的表名称、所述数据库表中包含的字段及所述字段的数据类型,所述表数据由开发人员填写入所述Excel文件中,终端通过预设方式解析所述Excel文件以得到所述表数据,通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本,根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本。The method for generating a table building script provided by the embodiments of the present application can be applied to computer equipment such as a terminal or a server, and the steps of the method for generating a table building script are implemented by software installed on the terminal or server, wherein the terminal can It is an electronic device such as a mobile phone, a notebook computer, a tablet computer or a desktop computer, and the server may be a cloud server or a server cluster. Taking a terminal as an example, the specific implementation process of the method for generating a table building script provided by the embodiment of the present application is as follows: the terminal obtains an Excel file, and the Excel file contains table data required for establishing a database table, and the table data includes the table data required for establishing a database table. Describe the required table name of the database table, the field contained in the database table and the data type of the field, the table data is filled in the Excel file by the developer, and the terminal parses the Excel file by default In order to obtain the table data, through the first preset method, the table data is correspondingly inserted into the preset grammar format for establishing the database table to obtain a plurality of subscripts, according to the use of establishing the database table. The syntax of the database management system is based on the second preset method, and a plurality of the sub-scripts are spliced to generate a script for establishing the database table.
需要说明的是,在实际操作过程中,上述建表脚本的生成方法的应用场景仅仅用于说明本申请技术方案,并不用于限定本申请技术方案。It should be noted that, in the actual operation process, the application scenarios of the above table building script generation method are only used to illustrate the technical solutions of the present application, and are not used to limit the technical solutions of the present application.
图1为本申请实施例提供的建表脚本的生成方法的示意性流程图。该建表脚本的生成方法应用于终端或者服务器中,该方法通过安装于所述终端或服务器中的应用软件来实现,具体可例如为以系统方式存在,其中,所述终端或者服务器即是用于执行完成建表脚本的生成方法的全部或者部分功能的计算机设备。请参阅图1,如图1所示,该方法包括以下步骤S101-S104:FIG. 1 is a schematic flowchart of a method for generating a table building script according to an embodiment of the present application. The method for generating a table building script is applied to a terminal or a server, and the method is implemented by application software installed in the terminal or server, which may exist in a system manner, for example, wherein the terminal or server is a A computer device that performs all or part of the functions of the generation method of the table building script. Please refer to FIG. 1. As shown in FIG. 1, the method includes the following steps S101-S104:
S101、获取Excel文件,所述Excel文件中包含建立数据库表所需的表数据,所述表数据包括建立所述数据库表所需的表名称、所述数据库表中包含的字段及所述字段的数据类型。S101. Acquire an Excel file, where the Excel file contains table data required for establishing a database table, and the table data includes a table name required for establishing the database table, a field contained in the database table, and the value of the field. type of data.
具体地,建立数据库表的脚本,实则指建立数据库表的代码。创建一个数据库中的表,一般代码结构为:Specifically, the script for creating the database table actually refers to the code for creating the database table. To create a table in a database, the general code structure is:
CREATE TABLE表名称CREATE TABLE table name
((
列名称1数据类型,column name 1 data type,
列名称2数据类型,column name 2 data type,
.............
))
由于创建一个数据库表至少需要数据库表的表名称、所述数据库表中包含的字段及所述字段的数据类型,并且表名称、所述数据库表中包含的字段及所述字段的数据类型是需要用户进行自定义的,所以这部分内容需要用户通过Excel文件进行设置,比如,上述例子中,Excel模板中就会包含表名称、列名称1及其数据类型、列名称2及其数据类型2等字段。可以预先在所述终端或服务器中用于实现本发明方法的系统中设置用户填写表数据的Excel模板,用户可以在阅读使用说明后,下载系统自带的Excel模板,根据Excel模板填写表结构,其中,用户根据Excel模板填写表结构,是指用户根据模板Excel填写Excel模板中包含的数据库表包含的表名、字段等信息,并将表结构填写完毕Excel模板生成的Excel文件保存到本地目录,后续例如通过“上传文件”按钮从本地目录中将Excel文件进行上传,也即通过点击“选择文件”选择Excel文件将Excel文件从本地进行上传以使计算机设备获取Excel文件。其中,Excel模板中,可以默认Sheet1页是导航页,放置各个表的概览信息,从Sheet2页开始按照模板填写表结构,后续脚本会根据Sheet2页、Sheet3页……等的表结构自动生成建表脚本。Since creating a database table requires at least the table name of the database table, the fields contained in the database table and the data types of the fields, and the table name, the fields contained in the database table and the data types of the fields are required User-defined, so this part of the content needs to be set by the user through the Excel file. For example, in the above example, the Excel template will contain the table name, column name 1 and its data type, column name 2 and its data type 2, etc. field. The system for implementing the method of the present invention in the terminal or server can be pre-set with an Excel template for the user to fill in the table data, and the user can download the Excel template that comes with the system after reading the instructions for use, and fill in the table structure according to the Excel template, Among them, the user fills in the table structure according to the Excel template, which means that the user fills in the table name, fields and other information contained in the database table contained in the Excel template according to the template Excel, and saves the Excel file generated by the Excel template after filling in the table structure to the local directory. Subsequently, for example, upload the Excel file from the local directory through the "Upload File" button, that is, click "Select File" to select the Excel file to upload the Excel file locally, so that the computer device obtains the Excel file. Among them, in the Excel template, the default Sheet1 page is the navigation page, and the overview information of each table is placed. From the Sheet2 page, fill in the table structure according to the template, and the subsequent script will automatically generate and build the table according to the table structure of the Sheet2 page, Sheet3 page, etc. script.
计算机设备获取用户上传的Excel文件,所述Excel文件中包含建立数据库表所需的表名称、字段及所述字段的数据类型,也即包含建立数据库表所需的表名称、数据库表中包含的列名称及列字段的数据类型。The computer equipment obtains the Excel file uploaded by the user, and the Excel file contains the table name, the field and the data type of the field required for establishing the database table, that is, the table name required for establishing the database table, the data type contained in the database table are included in the Excel file. The column name and the data type of the column field.
S102、通过预设方式解析所述Excel文件以得到所述表数据。S102. Parse the Excel file in a preset manner to obtain the table data.
其中,预设方式包括JAR包及Python中的库。JAR包包括JAVA中的POI包和JXL包;Python中的库包括Xlrd库。Among them, the default methods include JAR packages and libraries in Python. JAR packages include POI packages and JXL packages in JAVA; libraries in Python include Xlrd library.
具体地,计算机设备通过预设方式解析所述Excel文件以得到所述表数据,比如,计算机设备使用JAR包解析所述Excel文件以得到建表的表数据,所述表数据包括表名、字段名及该字段的数据类型。Specifically, the computer device parses the Excel file in a preset manner to obtain the table data. For example, the computer device uses a JAR package to parse the Excel file to obtain table data for creating a table, where the table data includes table name, field name and the data type of the field.
进一步地,在一个实施例中,所述通过预设方式解析所述Excel文件以得到所述表数据的步骤包括:Further, in one embodiment, the step of parsing the Excel file in a preset manner to obtain the table data includes:
通过JAVA中POI包或者Jxl.jar获取所述Excel文件中包含的所述表数据。The table data contained in the Excel file is obtained through the POI package in JAVA or Jxl.jar.
具体地,利用第三方JAR包解析Excel内容,在JAVA中采用JAR包读取Excel表格的内容,一种方式是导入POI包,另一种方式是导入JXL包。JAVA通过POI包解析Excel,在POI中,解析XLS格式的Excel表格使用的是HSSFWorkbook,解析.XLSX格式的表格使用的是XSSFWorkbook,从而获得建立数据库表需要的表名、字段名及字段的数据类型等Excel文件的内容,其中,JAVA通过包jxl.jar,可以实现从Excel文件中读取指定的行和列的值,Java读取Excel文件,并可以将Excel文件变为二维String数组,从而获取建表所需的表名和字段名。Specifically, use the third-party JAR package to parse the Excel content, and use the JAR package to read the content of the Excel table in JAVA. One way is to import the POI package, and the other way is to import the JXL package. JAVA parses Excel through the POI package. In POI, HSSFWorkbook is used for parsing Excel tables in XLS format, and XSSFWorkbook is used for parsing tables in .XLSX format, so as to obtain the table name, field name and field data type required to create a database table. Wait for the content of the Excel file. Among them, JAVA can read the value of the specified row and column from the Excel file through the package jxl.jar, and Java can read the Excel file and turn the Excel file into a two-dimensional String array, thus Get the table name and field name required to create a table.
S103、通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本。S103. Using the first preset method, correspondingly insert the table data into a preset syntax format for establishing the database table to obtain a plurality of sub-scripts.
具体地,若要创建一个SQL数据库管理系统的数据库表A,该数据库表A包含两列B和C,人工书写的创建表的脚本为:Specifically, to create a database table A of a SQL database management system, the database table A contains two columns B and C, and the manually written script for creating the table is:
CREATE TABLE表名称A;//ADD1CREATE TABLE table name A; //ADD1
((
列名称B数据类型;//ADD2column name B datatype; //ADD2
列名称C数据类型;//ADD3column name C datatype; //ADD3
.............
))
预先设置建立所述数据库表的语法格式为:The pre-set syntax format for establishing the database table is:
CREATE TABLE X1;//ADD1CREATE TABLE X1; //ADD1
((
X2 X3;//ADD2x2 x3; //add2
X4 X5;//ADD3x4 x5; // ADD3
.............
))
通过本申请实施例的方法创建生成数据库表A的脚本时,用户仅需通过简单操作则可自动生成,例如通过点击系统上的“选择文件夹”以选择存放生成的建表脚本的目录,最后,点击“生成脚本”即可。其中,生成建表脚本是利用第三方Jar包解析Excel文件的内容,比如Java通过POI包解析Excel文件,由于Excel文件中包含用户根据Excel模板填写的表名称A、列名称B及其数据类型、列名称C及其数据类型等字段,从而获得建立数据库表需要的表名称A、列名称B及其数据类型、列名称C及其数据类型等字段。When the script for generating database table A is created by the method of this embodiment of the present application, the user only needs to perform a simple operation to generate the script automatically, for example, by clicking "Select Folder" on the system to select the directory for storing the generated table-building script, and finally , and click Generate Script. Among them, generating the table building script is to use the third-party Jar package to parse the content of the Excel file. For example, Java parses the Excel file through the POI package. Since the Excel file contains the table name A, column name B and its data type, which are filled in by the user according to the Excel template, Fields such as column name C and its data type, so as to obtain fields such as table name A, column name B and its data type, column name C and its data type required to create a database table.
在一个实施例中,第一预设方法包括StringBuffer类Insert方法。所述通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本的步骤包括:In one embodiment, the first preset method includes an Insert method of the StringBuffer class. The step of correspondingly inserting the table data into a preset syntax format for establishing the database table by the first preset method to obtain a plurality of subscripts includes:
通过StringBuffer类的Insert方法,将所述表数据对应插入预设的用于建立所述数据库表的SQL语法格式中以得到多个SQL分脚本。Through the Insert method of the StringBuffer class, the table data is correspondingly inserted into the preset SQL syntax format for establishing the database table to obtain multiple SQL subscripts.
具体地,JAVA中,通过第三方JAR包解析Excel内容后会获得表名称A、列名称B及其数据类型、列名称C及其数据类型,然后使用StringBuffer类的Insert方法,比如使用如下脚本:public insert(int offset,int i),表示将int参数的字符串表示形式插入此序列中,将表名称A插入CREATE TABLE后ADD1的位置X1处,将列名称B及其数据类型分别对应插入ADD2的位置X2处和X3处,将列名称C及其数据类型插入ADD3的位置X4处和X5处,从而获得多个分脚本,比如,“CREATE TABLE表名称A”、“列名称B数据类型”、“列名称C数据类型;//ADD3”。Specifically, in JAVA, after parsing the Excel content through a third-party JAR package, the table name A, column name B and its data type, column name C and its data type are obtained, and then the Insert method of the StringBuffer class is used, for example, the following script is used: public insert(int offset,int i), which means to insert the string representation of the int parameter into this sequence, insert the table name A into the position X1 of ADD1 after CREATE TABLE, and insert the column name B and its data type into ADD2 respectively At positions X2 and X3, insert the column name C and its data type into the positions X4 and X5 of ADD3 to obtain multiple subscripts, such as "CREATE TABLE table name A", "column name B data type" , "column name C datatype; //ADD3".
S104、根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本。S104. According to the syntax of the database management system used for establishing the database table, splicing a plurality of the sub-scripts through a second preset method to generate a script for establishing the database table.
其中,第二预设方法包括StringBuffer类中的append方法和appendTo方法。The second preset method includes the append method and the appendTo method in the StringBuffer class.
具体地,获得多个分脚本后,根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本。Specifically, after obtaining a plurality of sub-scripts, according to the syntax of the database management system used for establishing the database table, the plurality of sub-scripts are spliced by a second preset method to generate a script for establishing the database table.
进一步地,在一个实施例中,所述根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本的步骤包括:Further, in one embodiment, according to the grammar of the database management system used for establishing the database table, a plurality of the sub-scripts are spliced by a second preset method to generate a script for establishing the database table. The steps include:
根据建立所述数据库表所使用的数据库管理系统的语法,通过StringBuffer类中的Append方法将多个所述分脚本进行拼接以得到建立所述数据库表的初始脚本;According to the grammar of the database management system used for establishing the database table, a plurality of the subscripts are spliced by the Append method in the StringBuffer class to obtain the initial script for establishing the database table;
采用ToString方法将所述初始脚本进行字符串格式化以生成建立所述数据库表的脚本。The initial script is string-formatted using the ToString method to generate a script for building the database table.
具体地,以上述SQL数据库管理系统为例,获得多个SQL分脚本之后,按照SQL语法,采用StringBuffer类将多个分脚本拼接成建表脚本。其中,除了使用StringBuffer类拼接SQL脚本,也可以使用StringBuilder类拼接SQL脚本。拼接SQL脚本,实则为采用Stringbuffer根据SQL语法不停的append SQL脚本,最后Tostring一下。其中,publicStringBuffer append(String s),将指定的字符串追加到此字符序列,Tostring方法是把Tostring()前面的数据转换成字符串格式,ToString方法会返回一个“以文本方式表示”此对象的字符串。比如,将上述举例中获得的“CREATE TABLE表名称A”、“列名称B数据类型”及“列名称C数据类型”等SQL脚本,通过Stringbuffer根据SQL语法不停的append SQL脚本,最后Tostring一下,套用SQL语法的上述格式,即可通过本申请实施例的方法获得与上述人工书写的创建表A的脚本一样的建表A的SQL脚本。Specifically, taking the above-mentioned SQL database management system as an example, after obtaining multiple SQL sub-scripts, the StringBuffer class is used to splicing the multiple sub-scripts into a table building script according to the SQL syntax. Among them, in addition to using the StringBuffer class to splice SQL scripts, you can also use the StringBuilder class to splice SQL scripts. The splicing of SQL scripts is actually the use of Stringbuffer to continuously append SQL scripts according to SQL syntax, and finally Tostring. Among them, publicStringBuffer append(String s), appends the specified string to this character sequence, the Tostring method converts the data in front of Tostring() into a string format, and the ToString method returns a "text representation" of this object. string. For example, use the SQL scripts such as "CREATE TABLE table name A", "column name B data type" and "column name C data type" obtained in the above example, and append the SQL script continuously through Stringbuffer according to the SQL syntax, and finally Tostring it. , and applying the above-mentioned format of the SQL syntax, the SQL script for creating table A that is the same as the script for creating table A manually written above can be obtained by the method of the embodiment of the present application.
本申请实施例实现建表脚本的生成时,只需开发人员将字段名称和表名称写入Excel文件,计算机设备获取所述Excel文件,所述Excel文件中包含建立数据库表所需的表数据,所述表数据包括建立所述数据库表所需的表名称、所述数据库表中包含的字段及所述字段的数据类型,即可自动通过预设方式解析所述Excel文件以得到所述表数据,并通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本,然后根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本,从而实现了自动生成建表脚本,相对于传统技术中由开发人员通过书写代码生成建立数据库表的脚本,本申请实施例通过自动生成建表脚本,让开发人员从繁杂而没有技术含量的机械性劳动中解脱出来,节省了生成建表脚本的时间成本,提高了建表脚本的生成的效率。When the embodiment of the present application realizes the generation of the table building script, the developer only needs to write the field name and the table name into the Excel file, and the computer device obtains the Excel file, and the Excel file contains the table data required for building the database table, The table data includes the table name required to establish the database table, the fields contained in the database table and the data type of the field, and the Excel file can be automatically parsed by a preset method to obtain the table data. , and through the first preset method, the table data is correspondingly inserted into the preset grammatical format for establishing the database table to obtain a plurality of subscripts, and then according to the database management system used for establishing the database table The grammar, the second preset method is used to splicing a plurality of the sub-scripts to generate the script for establishing the database table, thereby realizing the automatic generation of the table-building script. The script of the database table, the embodiment of the present application, by automatically generating the table-building script, frees developers from complicated and unskilled mechanical labor, saves the time and cost of generating the table-building script, and improves the generation of the table-building script. s efficiency.
在一个实施例中,所述Excel文件中包含多个工作表,所述通过预设方式解析所述Excel文件以得到所述表数据的步骤之前,还包括:In one embodiment, the Excel file contains a plurality of worksheets, and before the step of parsing the Excel file in a preset manner to obtain the table data, the method further includes:
循环遍历所述Excel文件的每个工作表;loop through each worksheet of the Excel file;
所述通过预设方式解析所述Excel文件以得到所述表数据的步骤包括:The step of parsing the Excel file by default to obtain the table data includes:
通过预设方式解析每个所述工作表以得到每个所述工作表对应的数据库表的表数据。Parse each of the worksheets in a preset manner to obtain table data of a database table corresponding to each of the worksheets.
其中,遍历,英文为Traversal,是指沿着某条搜索路线,依次对树中每个结点均做一次且仅做一次访问。Among them, traversal, which is called Traversal in English, means that along a certain search route, each node in the tree is visited once and only once.
具体地,针对Excel文件包含多个工作表,每个工作表对应建立一个数据库表的情形,需要对每个工作表逐一进行解析。计算机设备获取Excel文件,通过预设方式解析所述Excel文件中包含的第一个工作表,然后循环遍历Excel文件的所有Sheet页以获得各个对应待建表所需的表名称、所述数据库表中包含的字段及所述字段的数据类型,也即通过预设方式解析每个所述工作表以将每个所述工作表转换为二维数组以得到每个所述工作表对应的数据库表的表数据,通过第一预设方法将每个所述表数据对应插入预设的建立所述数据库表的语法格式以得到每个数据库表对应的多个分脚本,根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将每个数据库表对应的多个分脚本分别进行拼接以对应生成多个建立所述数据库表的脚本,从而获得各个对应待建表的建表脚本。Specifically, in the case that the Excel file contains multiple worksheets, and each worksheet corresponds to a database table, it is necessary to analyze each worksheet one by one. The computer equipment obtains the Excel file, parses the first worksheet contained in the Excel file by a preset method, and then loops through all the Sheet pages of the Excel file to obtain the table name required for each corresponding table to be built, the database table The fields contained in and the data types of the fields, that is, each of the worksheets is parsed by a preset method to convert each of the worksheets into a two-dimensional array to obtain the database table corresponding to each of the worksheets The table data, each of the table data is correspondingly inserted into the preset syntax format for establishing the database table by the first preset method to obtain a plurality of subscripts corresponding to each database table, according to the method for establishing the database table. Using the syntax of the database management system, the multiple sub-scripts corresponding to each database table are spliced respectively by the second preset method to correspondingly generate multiple scripts for establishing the database table, so as to obtain the construction of each corresponding to-be-built table. Table script.
通过Excel文件中包含多个工作表,用户只需要根据Excel模板填写待建立的多个数据库表中建立每个数据库表所需的表名称、所述数据库表中包含的字段及所述字段的数据类型等表数据,结合预设的建立所述数据库表的语法格式,通过本申请实施例的技术方法可以实现大批量通过Excel表结构一键生成Hive建表脚本,节省了时间成本,让开发人员从繁杂而没有技术含量的机械性劳动中解脱出来,不仅节省了开发人员的人力成本、提高了开发质量和编码效率,而且,该建立数据库表的方法的使用对使用者没有任何编码能力要求,即使没有编码基础的人员也能够独立完成建表脚本这一项工作,提高了建表脚本的生成的效率。其中,Hive是基于Hadoop的一个数据仓库工具。By including multiple worksheets in the Excel file, the user only needs to fill in the table name, the fields contained in the database table and the data of the fields required to create each database table in the multiple database tables to be created according to the Excel template Table data such as types, combined with the preset grammar format for establishing the database table, through the technical method of the embodiment of the present application, a large batch of Hive table building scripts can be generated through the Excel table structure with one click, which saves time and cost and allows developers to Freeing from complicated and unskilled mechanical labor not only saves the labor cost of developers, improves development quality and coding efficiency, but also does not require any coding ability for users to use the method of establishing database tables. Even people without coding foundation can independently complete the work of the table building script, which improves the generation efficiency of the table building script. Among them, Hive is a data warehouse tool based on Hadoop.
在一个实施例中,所述通过预设方式解析每个所述工作表以得到每个所述工作表对应的数据库表的表数据的步骤包括:In one embodiment, the step of parsing each of the worksheets in a preset manner to obtain table data of a database table corresponding to each of the worksheets includes:
通过预设方式解析每个所述工作表,将每个所述工作表转换为二维数组以得到每个所述工作表对应的所述数据库表的表数据;Parse each of the worksheets in a preset manner, and convert each of the worksheets into a two-dimensional array to obtain table data of the database table corresponding to each of the worksheets;
所述通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本的步骤包括:The step of correspondingly inserting the table data into a preset syntax format for establishing the database table by the first preset method to obtain a plurality of subscripts includes:
通过第一预设方法,将每个所述工作表对应的所述数据库表的表数据对应插入预设的用于建立所述数据库表的语法格式中以得到每个所述数据库表对应的多个分脚本;Through the first preset method, the table data of the database table corresponding to each of the worksheets is correspondingly inserted into the preset syntax format for establishing the database table to obtain the multiple data corresponding to each of the database tables. a subscript;
所述根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本的步骤包括:The step of splicing a plurality of the subscripts to generate the script for establishing the database table by the second preset method according to the grammar of the database management system used for establishing the database table includes:
根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将每个所述数据库表对应的多个所述分脚本分别进行拼接以对应生成建立每个所述数据库表的脚本。According to the grammar of the database management system used to establish the database table, the multiple sub-scripts corresponding to each of the database tables are spliced separately by the second preset method to generate correspondingly the corresponding database table. script.
具体地,对于建立多个数据库表的情形,Excel文件中每一个工作表包含的内容对应一个数据库表,也即一个Sheet页对应一个数据库表,Excel文件中一个工作表包含建立一个数据库表需要的表名称、所述数据库表中包含的字段及所述字段的数据类型,比如,要建立A、B、C、D及E五个数据库表,建立A数据库表需要的表名称、所述数据库表中包含的字段及所述字段的数据类型在一个工作表中,建立B数据库表需要的表名称、所述数据库表中包含的字段及所述字段的数据类型在另一个工作表中,依次类推,建立E数据库表需要的表名称、所述数据库表中包含的字段及所述字段的数据类型在第五个工作表中,对应A、B、C、D及E五个数据库表,Excel文件中至少对应包含有五个工作表。对于Excel文件中包含多个工作表的情形,Excel模板中就会包含多个工作表,每个工作表包含建立一个数据库表所需要的表名称、列名称1及其数据类型等信息。Specifically, in the case of establishing multiple database tables, the content contained in each worksheet in the Excel file corresponds to a database table, that is, a Sheet page corresponds to a database table, and a worksheet in the Excel file contains the required information for establishing a database table. Table name, fields contained in the database table and data types of the fields, for example, to create five database tables A, B, C, D and E, the table name required to create the database table A, the database table The fields contained in and the data types of the fields are in one worksheet, the table name required to create the B database table, the fields contained in the database table and the data types of the fields are in another worksheet, and so on , the table name required to establish the E database table, the field contained in the database table and the data type of the field are in the fifth worksheet, corresponding to five database tables of A, B, C, D and E, and the Excel file contains at least five worksheets. For the case that the Excel file contains multiple worksheets, the Excel template will contain multiple worksheets, and each worksheet contains information such as the table name, column name 1 and its data type required to create a database table.
在一个实施例中,所述根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本的步骤之后,还包括:In one embodiment, after the step of splicing a plurality of the sub-scripts according to the syntax of the database management system used for establishing the database table by a second preset method to generate the script for establishing the database table ,Also includes:
使用IO流把建立所述数据库表的脚本进行封装。The script that builds the database table is encapsulated using IO streams.
其中,IO流,英文为Input Output Stream,中文为输入输出流,IO流就是以流的方式进行输入输出。Among them, IO stream, English is Input Output Stream, Chinese is input and output stream, IO stream is input and output in the form of stream.
具体地,建表脚本的生成时,开发人员将字段名称和表名称写入Excel文件,将所述Excel文件上传至计算机设备,计算机设备获取所述Excel文件,自动通过预设方式解析所述Excel文件以得到建立所述数据库表所需的表名称、所述数据库表中包含的字段及所述字段的数据类型等表数据,并通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本,然后根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本,再使用IO流把建立所述数据库表的脚本进行封装。比如,对于建立多个数据库表,Excel文件中包含多个Sheet页的情形,计算机设备获取Excel文件,然后循环遍历Excel的所有Sheet页以获得各个Sheet页对应待建表的建表脚本,再用IO流把SQL脚本写成本地文件,其中,Java的IO是实现输入和输出的基础,可以方便的实现数据的输入和输出操作。在Java中把不同的输入源和输出源(比如键盘、文件或者网络连接等)抽象表述为“流”(英文为Stream)。通过流的形式允许Java程序使用相同的方式来访问不同的输入源和输出源。Specifically, when the table building script is generated, the developer writes the field name and the table name into an Excel file, uploads the Excel file to a computer device, and the computer device obtains the Excel file, and automatically parses the Excel file by a preset method. file to obtain table data such as the table name required to establish the database table, the fields contained in the database table and the data types of the fields, and by the first preset method, the table data is correspondingly inserted into the preset In order to obtain a plurality of sub-scripts in the grammar format used for establishing the database table, then according to the grammar of the database management system used for establishing the database table, the plurality of sub-scripts are spliced by the second preset method to generate a script for establishing the database table, and then use the IO stream to encapsulate the script for establishing the database table. For example, in the case of creating multiple database tables and the Excel file contains multiple Sheet pages, the computer device obtains the Excel file, and then loops through all the Sheet pages of Excel to obtain the table building script corresponding to the table to be built for each Sheet page, and then use The IO stream writes the SQL script into a local file. Among them, Java IO is the basis for realizing input and output, which can easily realize the input and output operations of data. In Java, different input sources and output sources (such as keyboards, files or network connections, etc.) are abstractly expressed as "streams" (Stream in English). Streams allow Java programs to access different input and output sources in the same way.
需要说明的是,上述各个实施例所述的建表脚本的生成方法,可以根据需要将不同实施例中包含的技术特征重新进行组合,以获取组合后的实施方案,但都在本申请要求的保护范围之内。It should be noted that, in the methods for generating table building scripts described in the above-mentioned embodiments, the technical features contained in different embodiments can be recombined as required to obtain a combined implementation scheme, but all of them are within the requirements of this application. within the scope of protection.
请参阅图2,图2为本申请实施例提供的建表脚本的生成装置的示意性框图。对应于上述建表脚本的生成方法,本申请实施例还提供一种建表脚本的生成装置。如图2所示,该建表脚本的生成装置包括用于执行上述建表脚本的生成方法的单元,该装置可以被配置于终端或者服务器等计算机设备中。具体地,请参阅图2,该建表脚本的生成装置200包括获取单元201、解析单元202、插入单元203及生成单元204。Please refer to FIG. 2 , which is a schematic block diagram of an apparatus for generating a table building script according to an embodiment of the present application. Corresponding to the above method for generating a table building script, an embodiment of the present application further provides an apparatus for generating a table building script. As shown in FIG. 2 , the apparatus for generating a table building script includes a unit for executing the above-mentioned method for generating a table building script, and the apparatus may be configured in a computer device such as a terminal or a server. Specifically, please refer to FIG. 2 , the table building
其中,获取单元201,用于获取Excel文件,所述Excel文件中包含建立数据库表所需的表数据,所述表数据包括建立所述数据库表所需的表名称、所述数据库表中包含的字段及所述字段的数据类型;Wherein, the obtaining
解析单元202,用于通过预设方式解析所述Excel文件以得到所述表数据;parsing
插入单元203,用于通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本;The inserting
生成单元204,用于根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本。The generating
在一个实施例中,所述Excel文件中包含多个工作表,所述建表脚本的生成装置200还包括:In one embodiment, the Excel file includes a plurality of worksheets, and the
循环单元,用于循环遍历所述Excel文件的每个工作表;a loop unit for looping through each worksheet of the Excel file;
所述解析单元202,用于通过预设方式解析每个所述工作表以得到每个所述工作表对应的数据库表的表数据。The
在一个实施例中,所述解析单元202,用于通过预设方式解析每个所述工作表,将每个所述工作表转换为二维数组以得到每个所述工作表对应的所述数据库表的表数据;In one embodiment, the
所述插入单元203,用于通过第一预设方法,将每个所述工作表对应的所述数据库表的表数据对应插入预设的用于建立所述数据库表的语法格式中以得到每个所述数据库表对应的多个分脚本;The inserting
所述生成单元204,用于根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将每个所述数据库表对应的多个所述分脚本分别进行拼接以对应生成建立每个所述数据库表的脚本。The generating
在一个实施例中,所述插入单元203,用于通过StringBuffer类的Insert方法,将所述表数据对应插入预设的用于建立所述数据库表的SQL语法格式中以得到多个SQL分脚本。In one embodiment, the inserting
在一个实施例中,所述生成单元204包括:In one embodiment, the generating
拼接子单元,用于根据建立所述数据库表所使用的数据库管理系统的语法,通过StringBuffer类中的Append方法将多个所述分脚本进行拼接以得到建立所述数据库表的初始脚本;The splicing subunit is used for splicing a plurality of described sub-scripts to obtain the initial script of establishing the database table by the Append method in the StringBuffer class according to the syntax of the database management system used for establishing the database table;
格式化子单元,用于采用ToString方法将所述初始脚本进行字符串格式化以生成建立所述数据库表的脚本。The formatting subunit is used to format the initial script by using the ToString method to generate a script for establishing the database table.
在一个实施例中,所述解析单元202,用于通过JAVA中POI包或者Jxl.jar获取所述Excel文件中包含的所述表数据。In one embodiment, the
在一个实施例中,所述建表脚本的生成装置200还包括:In one embodiment, the generating
封装单元,用于使用IO流把建立所述数据库表的脚本进行封装。The encapsulation unit is used to encapsulate the script for establishing the database table by using the IO stream.
需要说明的是,所属领域的技术人员可以清楚地了解到,上述建表脚本的生成装置和各单元的具体实现过程,可以参考前述方法实施例中的相应描述,为了描述的方便和简洁,在此不再赘述。It should be noted that those skilled in the art can clearly understand that, for the specific implementation process of the above-mentioned table building script generating device and each unit, reference may be made to the corresponding descriptions in the foregoing method embodiments. For the convenience and brevity of the description, in This will not be repeated here.
同时,上述建表脚本的生成装置中各个单元的划分和连接方式仅用于举例说明,在其他实施例中,可将建表脚本的生成装置按照需要划分为不同的单元,也可将建表脚本的生成装置中各单元采取不同的连接顺序和方式,以完成上述建表脚本的生成装置的全部或部分功能。At the same time, the division and connection methods of each unit in the above-mentioned table-building script generating device are only used for illustration. In other embodiments, the table-building script generating device may be divided into different units as required, or the table building Each unit in the script generating device adopts different connection sequences and methods to complete all or part of the functions of the above-mentioned table building script generating device.
上述建表脚本的生成装置可以实现为一种计算机程序的形式,该计算机程序可以在如图3所示的计算机设备上运行。The above-mentioned generating apparatus for a table building script can be implemented in the form of a computer program, and the computer program can be executed on the computer device as shown in FIG. 3 .
请参阅图3,图3是本申请实施例提供的一种计算机设备的示意性框图。该计算机设备300可以是台式机电脑或者服务器等计算机设备,也可以是其他设备中的组件或者部件。Please refer to FIG. 3 , which is a schematic block diagram of a computer device provided by an embodiment of the present application. The
参阅图3,该计算机设备300包括通过系统总线301连接的处理器302、存储器和网络接口305,其中,存储器可以包括非易失性存储介质303和内存储器304。Referring to FIG. 3 , the
该非易失性存储介质303可存储操作系统3031和计算机程序3032。该计算机程序3032被执行时,可使得处理器302执行一种上述建表脚本的生成方法。The
该处理器302用于提供计算和控制能力,以支撑整个计算机设备300的运行。The
该内存储器304为非易失性存储介质303中的计算机程序3032的运行提供环境,该计算机程序3032被处理器302执行时,可使得处理器302执行一种上述建表脚本的生成方法。The
该网络接口305用于与其它设备进行网络通信。本领域技术人员可以理解,图3中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备300的限定,具体的计算机设备300可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。例如,在一些实施例中,计算机设备可以仅包括存储器及处理器,在这样的实施例中,存储器及处理器的结构及功能与图3所示实施例一致,在此不再赘述。The
其中,所述处理器302用于运行存储在存储器中的计算机程序3032,以实现如下步骤:获取Excel文件,所述Excel文件中包含建立数据库表所需的表数据,所述表数据包括建立所述数据库表所需的表名称、所述数据库表中包含的字段及所述字段的数据类型;通过预设方式解析所述Excel文件以得到所述表数据;通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本;根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本。Wherein, the
在一实施例中,所述处理器302在实现所述获取Excel文件的步骤时,所述Excel文件中包含多个工作表,所述处理器302在实现所述通过预设方式解析所述Excel文件以得到所述表数据的步骤之前,还实现以下步骤:In one embodiment, when the
循环遍历所述Excel文件的每个工作表;loop through each worksheet of the Excel file;
所述处理器302在实现所述通过预设方式解析所述Excel文件以得到所述表数据的步骤时,具体实现以下步骤:When the
通过预设方式解析每个所述工作表以得到每个所述工作表对应的数据库表的表数据。Parse each of the worksheets in a preset manner to obtain table data of a database table corresponding to each of the worksheets.
在一实施例中,所述处理器302在实现所述通过预设方式解析每个所述工作表以得到每个所述工作表对应的数据库表的表数据的步骤时,具体实现以下步骤:In one embodiment, when the
通过预设方式解析每个所述工作表,将每个所述工作表转换为二维数组以得到每个所述工作表对应的所述数据库表的表数据;Parse each of the worksheets in a preset manner, and convert each of the worksheets into a two-dimensional array to obtain table data of the database table corresponding to each of the worksheets;
所述处理器302在实现所述通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本的步骤时,具体实现以下步骤:When the
通过第一预设方法,将每个所述工作表对应的所述数据库表的表数据对应插入预设的用于建立所述数据库表的语法格式中以得到每个所述数据库表对应的多个分脚本;Through the first preset method, the table data of the database table corresponding to each of the worksheets is correspondingly inserted into the preset syntax format for establishing the database table to obtain the multiple data corresponding to each of the database tables. subscript;
所述处理器302在实现所述根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本的步骤时,具体实现以下步骤:The
根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将每个所述数据库表对应的多个所述分脚本分别进行拼接以对应生成建立每个所述数据库表的脚本。According to the grammar of the database management system used to establish the database table, the multiple sub-scripts corresponding to each of the database tables are spliced separately by the second preset method to generate correspondingly the corresponding database table. script.
在一实施例中,所述处理器302在实现所述通过第一预设方法,将所述表数据对应插入预设的用于建立所述数据库表的语法格式中以得到多个分脚本的步骤时,具体实现以下步骤:In one embodiment, the
通过StringBuffer类的Insert方法,将所述表数据对应插入预设的用于建立所述数据库表的SQL语法格式中以得到多个SQL分脚本。Through the Insert method of the StringBuffer class, the table data is correspondingly inserted into the preset SQL syntax format for establishing the database table to obtain multiple SQL subscripts.
在一实施例中,所述处理器302在实现所述根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本的步骤时,具体实现以下步骤:In one embodiment, when the
根据建立所述数据库表所使用的数据库管理系统的语法,通过StringBuffer类中的Append方法将多个所述分脚本进行拼接以得到建立所述数据库表的初始脚本;According to the grammar of the database management system used for establishing the database table, a plurality of the subscripts are spliced by the Append method in the StringBuffer class to obtain the initial script for establishing the database table;
采用ToString方法将所述初始脚本进行字符串格式化以生成建立所述数据库表的脚本。The initial script is string-formatted using the ToString method to generate a script for building the database table.
在一实施例中,所述处理器302在实现所述通过预设方式解析所述Excel文件以得到所述表数据的步骤时,具体实现以下步骤:In one embodiment, when the
通过JAVA中POI包或者Jxl.jar获取所述Excel文件中包含的所述表数据。The table data contained in the Excel file is obtained through the POI package in JAVA or Jxl.jar.
在一实施例中,所述处理器302在实现所述根据建立所述数据库表所使用的数据库管理系统的语法,通过第二预设方法将多个所述分脚本进行拼接以生成建立所述数据库表的脚本的步骤之后,还实现以下步骤:In one embodiment, when the
使用IO流把建立所述数据库表的脚本进行封装。The script that builds the database table is encapsulated using IO streams.
应当理解,在本申请实施例中,处理器302可以是中央处理单元(CentralProcessingUnit,CPU),该处理器302还可以是其他通用处理器、数字信号处理器(DigitalSignal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable GateArray,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。其中,通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。It should be understood that, in this embodiment of the present application, the
本领域普通技术人员可以理解的是实现上述实施例的方法中的全部或部分流程,是可以通过计算机程序来完成,该计算机程序可存储于一计算机可读存储介质。该计算机程序被该计算机系统中的至少一个处理器执行,以实现上述方法的实施例的流程步骤。It can be understood by those skilled in the art that all or part of the processes in the methods of the above embodiments can be implemented by a computer program, and the computer program can be stored in a computer-readable storage medium. The computer program is executed by at least one processor in the computer system to implement the flow steps of the above-described method embodiments.
因此,本申请还提供一种计算机可读存储介质。该计算机可读存储介质可以为非易失性的计算机可读存储介质,该计算机可读存储介质存储有计算机程序,该计算机程序被处理器执行时使处理器执行如下步骤:Therefore, the present application also provides a computer-readable storage medium. The computer-readable storage medium may be a non-volatile computer-readable storage medium, and the computer-readable storage medium stores a computer program, and when the computer program is executed by the processor, causes the processor to perform the following steps:
一种计算机程序产品,当其在计算机上运行时,使得计算机执行以上各实施例中所描述的建表脚本的生成方法的步骤。A computer program product, when running on a computer, causes the computer to execute the steps of the method for generating a table building script described in the above embodiments.
所述计算机可读存储介质可以是前述设备的内部存储单元,例如设备的硬盘或内存。所述计算机可读存储介质也可以是所述设备的外部存储设备,例如所述设备上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,所述计算机可读存储介质还可以既包括所述设备的内部存储单元也包括外部存储设备。The computer-readable storage medium may be an internal storage unit of the aforementioned device, such as a hard disk or a memory of the device. The computer-readable storage medium may also be an external storage device of the device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card equipped on the device , Flash card (Flash Card) and so on. Further, the computer-readable storage medium may also include both an internal storage unit of the device and an external storage device.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的设备、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and brevity of description, for the specific working process of the above-described devices, devices and units, reference may be made to the corresponding processes in the foregoing method embodiments, which will not be repeated here.
所述计算机可读存储介质可以是U盘、移动硬盘、只读存储器(Read-Only Memory,ROM)、磁碟或者光盘等各种可以存储程序代码的计算机可读存储介质。The computer-readable storage medium may be various computer-readable storage media that can store program codes, such as a U disk, a removable hard disk, a read-only memory (Read-Only Memory, ROM), a magnetic disk, or an optical disk.
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. Interchangeability, the above description has generally described the components and steps of each example in terms of function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Skilled artisans may implement the described functionality using different methods for each particular application, but such implementations should not be considered beyond the scope of this application.
在本申请所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的。例如,各个单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative. For example, the division of each unit is only a logical function division, and other division methods may be used in actual implementation. For example, multiple units or components may be combined or may be integrated into another system, or some features may be omitted, or not implemented.
本申请实施例方法中的步骤可以根据实际需要进行顺序调整、合并和删减。本申请实施例装置中的单元可以根据实际需要进行合并、划分和删减。另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以是两个或两个以上单元集成在一个单元中。The steps in the method of the embodiment of the present application may be adjusted, combined and deleted in sequence according to actual needs. Units in the apparatus of the embodiment of the present application may be combined, divided, and deleted according to actual needs. In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit.
该集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分,或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台电子设备(可以是个人计算机,终端,或者网络设备等)执行本申请各个实施例所述方法的全部或部分步骤。The integrated unit, if implemented in the form of a software functional unit and sold or used as an independent product, may be stored in a storage medium. Based on this understanding, the technical solutions of the present application are essentially or part of contributions to the prior art, or all or part of the technical solutions can be embodied in the form of software products, and the computer software products are stored in a storage medium , including several instructions to cause an electronic device (which may be a personal computer, a terminal, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.
以上所述,仅为本申请的具体实施方式,但本申请明的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。The above are only specific implementations of the present application, but the scope of protection disclosed in the present application is not limited to this. Any person skilled in the art can easily think of various equivalents within the technical scope disclosed in the present application. Modifications or substitutions of the present application shall be included within the scope of protection of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910851107.XA CN110780860A (en) | 2019-09-10 | 2019-09-10 | Generation method and device of table building script, computer equipment and storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201910851107.XA CN110780860A (en) | 2019-09-10 | 2019-09-10 | Generation method and device of table building script, computer equipment and storage medium |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN110780860A true CN110780860A (en) | 2020-02-11 |
Family
ID=69383439
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201910851107.XA Pending CN110780860A (en) | 2019-09-10 | 2019-09-10 | Generation method and device of table building script, computer equipment and storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN110780860A (en) |
Cited By (11)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111459943A (en) * | 2020-04-03 | 2020-07-28 | 中国建设银行股份有限公司 | Data processing method, device, system, equipment and storage medium |
| CN111708779A (en) * | 2020-06-11 | 2020-09-25 | 中国建设银行股份有限公司 | Data management method, system, management equipment and storage medium |
| CN112035565A (en) * | 2020-09-03 | 2020-12-04 | 天元大数据信用管理有限公司 | Method for generating sql script according to word document |
| CN112558952A (en) * | 2020-12-16 | 2021-03-26 | 中国平安人寿保险股份有限公司 | Program statement generation method, program statement generation device, computer device and storage medium |
| CN112632101A (en) * | 2020-12-22 | 2021-04-09 | 平安普惠企业管理有限公司 | Script generation method and device, computer equipment and storage medium |
| CN112632946A (en) * | 2020-12-22 | 2021-04-09 | 平安普惠企业管理有限公司 | Method, apparatus, computer device and storage medium for automatic table building |
| CN113220691A (en) * | 2021-05-31 | 2021-08-06 | 北京互金新融科技有限公司 | Database table creating method and device for database table, and electronic equipment |
| CN113326248A (en) * | 2021-05-17 | 2021-08-31 | 上海中通吉网络技术有限公司 | Method and device for quickly building database |
| CN113553337A (en) * | 2021-07-26 | 2021-10-26 | 中国工商银行股份有限公司 | Method, system, device, storage medium, and program product for generating database script |
| CN114969099A (en) * | 2022-06-24 | 2022-08-30 | 平安普惠企业管理有限公司 | SQL script generation method, device, equipment and storage medium based on Java language |
| CN117194476A (en) * | 2023-09-07 | 2023-12-08 | 中国银行股份有限公司 | SQL script generation method, device, equipment and storage medium |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20080183766A1 (en) * | 2007-01-31 | 2008-07-31 | Weston David W | Methods and systems for inductive data transformation |
| CN108984653A (en) * | 2018-06-27 | 2018-12-11 | 广州市南方人力资源评价中心有限公司 | A method of realizing the online development management of multisystem |
| CN110019485A (en) * | 2018-02-07 | 2019-07-16 | 中国平安人寿保险股份有限公司 | A kind of product data storage method, terminal device and storage medium |
-
2019
- 2019-09-10 CN CN201910851107.XA patent/CN110780860A/en active Pending
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20080183766A1 (en) * | 2007-01-31 | 2008-07-31 | Weston David W | Methods and systems for inductive data transformation |
| CN110019485A (en) * | 2018-02-07 | 2019-07-16 | 中国平安人寿保险股份有限公司 | A kind of product data storage method, terminal device and storage medium |
| CN108984653A (en) * | 2018-06-27 | 2018-12-11 | 广州市南方人力资源评价中心有限公司 | A method of realizing the online development management of multisystem |
Non-Patent Citations (1)
| Title |
|---|
| PATRICK CHAN 等: "《Java 2类库 增补版》", 31 January 2001, 北京:机械工业出版社 , pages: 726 - 728 * |
Cited By (12)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111459943A (en) * | 2020-04-03 | 2020-07-28 | 中国建设银行股份有限公司 | Data processing method, device, system, equipment and storage medium |
| CN111708779A (en) * | 2020-06-11 | 2020-09-25 | 中国建设银行股份有限公司 | Data management method, system, management equipment and storage medium |
| CN112035565A (en) * | 2020-09-03 | 2020-12-04 | 天元大数据信用管理有限公司 | Method for generating sql script according to word document |
| CN112558952A (en) * | 2020-12-16 | 2021-03-26 | 中国平安人寿保险股份有限公司 | Program statement generation method, program statement generation device, computer device and storage medium |
| CN112632101A (en) * | 2020-12-22 | 2021-04-09 | 平安普惠企业管理有限公司 | Script generation method and device, computer equipment and storage medium |
| CN112632946A (en) * | 2020-12-22 | 2021-04-09 | 平安普惠企业管理有限公司 | Method, apparatus, computer device and storage medium for automatic table building |
| CN113326248A (en) * | 2021-05-17 | 2021-08-31 | 上海中通吉网络技术有限公司 | Method and device for quickly building database |
| CN113220691A (en) * | 2021-05-31 | 2021-08-06 | 北京互金新融科技有限公司 | Database table creating method and device for database table, and electronic equipment |
| CN113220691B (en) * | 2021-05-31 | 2024-02-06 | 北京互金新融科技有限公司 | Database table creation method, database table creation device and electronic equipment |
| CN113553337A (en) * | 2021-07-26 | 2021-10-26 | 中国工商银行股份有限公司 | Method, system, device, storage medium, and program product for generating database script |
| CN114969099A (en) * | 2022-06-24 | 2022-08-30 | 平安普惠企业管理有限公司 | SQL script generation method, device, equipment and storage medium based on Java language |
| CN117194476A (en) * | 2023-09-07 | 2023-12-08 | 中国银行股份有限公司 | SQL script generation method, device, equipment and storage medium |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN110780860A (en) | Generation method and device of table building script, computer equipment and storage medium | |
| US10705942B1 (en) | Simulated testing of API | |
| CN107656914B (en) | Configurable table generation method and device, terminal equipment and storage medium | |
| CN108388622B (en) | API interface dynamic generation method and device, computer equipment and storage medium | |
| CN102929867A (en) | Technology for automated document translation | |
| WO2021217911A1 (en) | Method and apparatus for constructing service website project, and computer device and storage medium | |
| CN110888720A (en) | Task processing method and device, computer equipment and storage medium | |
| US10915377B2 (en) | Automatically building a web API definition from a microservice or web application | |
| US9990343B2 (en) | System and method for in-browser editing | |
| CN107741935B (en) | Data importing method and data importing device | |
| CN107943465B (en) | Method and device for generating HTML form | |
| CN110580174B (en) | Application component generation method, server and terminal | |
| CN113900725B (en) | Interface configuration method, device, computer equipment and storage medium | |
| CN109062572A (en) | A kind of component call method, apparatus, equipment and storage medium | |
| CN113778405A (en) | Cross-platform APP construction method, device, system and medium | |
| CN111858727A (en) | A system and method for exporting data from multiple data sources based on template configuration | |
| CN110659027A (en) | Code generation method and device and electronic equipment | |
| CN113495730B (en) | Resource package generation and parsing method and device | |
| CN115129360A (en) | Code file management method and device, electronic equipment and storage medium | |
| CN115113898A (en) | Dynamic update method, device, computer equipment and storage medium of micro-application | |
| CN114996131A (en) | Method and device for mind map conversion test case | |
| CN110058849A (en) | Generation method, device, computer equipment and the storage medium of flow chart | |
| CN114239529A (en) | Document generation method, device, device and medium based on template engine | |
| CN114741365A (en) | Product model obtaining method and device, terminal equipment and storage medium | |
| CN111078529B (en) | Client writing module testing method and device and electronic equipment |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20200211 |
|
| RJ01 | Rejection of invention patent application after publication |