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 PDF

Info

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
establishing
script
database
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
Application number
CN201910851107.XA
Other languages
Chinese (zh)
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.)
Ping An Property and Casualty Insurance Company of China Ltd
Original Assignee
Ping An Property and Casualty Insurance Company of China Ltd
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 Ping An Property and Casualty Insurance Company of China Ltd filed Critical Ping An Property and Casualty Insurance Company of China Ltd
Priority to CN201910851107.XA priority Critical patent/CN110780860A/en
Publication of CN110780860A publication Critical patent/CN110780860A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing

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

The embodiment of the application provides a method and a device for generating a table building script, computer equipment and a computer readable storage medium. The embodiment of the application belongs to a database development technology, and when a table building script is generated, an Excel file is obtained, wherein the Excel file contains table data required by building a database table, and the table data comprises a table name, fields contained in the database table and data types of the fields; analyzing the Excel file in a preset mode to obtain table data; correspondingly inserting the table data into a preset grammar format for establishing a database table through a first preset method to obtain a plurality of branch scripts; according to the grammar of a database management system used for establishing the database table, the plurality of sub-scripts are spliced through a second preset method to generate the script for establishing the database table, and the time cost for generating the table establishing script is saved and the efficiency for generating the table establishing script is improved through automatically generating the table establishing script.

Description

Generation method and device of table building script, computer equipment and storage medium
Technical Field
The present application relates to the field of database development technologies, and in particular, to a method and an apparatus for generating a table creation script, a computer device, and a computer readable storage medium.
Background
Establishing a database table, called table establishment for short, and establishing a script of the database table, called table establishment script for short, also called table establishment script. Building a table is the first step in development, as any data requirements do not leave the database table. In the conventional technology, table building is generally a script for building a database table by writing codes by a coding person in the IT industry, and particularly when a plurality of database tables need to be built, table building is a complex and technical-content-free work, and writing errors such as characters and formats are easy to occur, especially under the condition of a large number of fields, a large time cost is more spent, so that the generation efficiency of the table building script is greatly reduced.
Disclosure of Invention
The embodiment of the application provides a method and a device for generating a table building script, computer equipment and a computer readable storage medium, which can solve the problem of low generation efficiency of the table building script in the prior art.
In a first aspect, an embodiment of the present application provides a method for generating a table creation script, where the method includes: obtaining an Excel file, wherein the Excel file comprises table data required by establishing a database table, and the table data comprises a table name required by establishing the database table, fields contained in the database table and data types of the fields; analyzing the Excel file in a preset mode to obtain the table data; correspondingly inserting the table data into a preset grammar format for establishing the database table through a first preset method to obtain a plurality of branch scripts; and according to the grammar of a database management system used for establishing the database table, splicing the sub-scripts by a second preset method to generate a script for establishing the database table.
In a second aspect, an embodiment of the present application further provides an apparatus for generating a table creating script, including: the system comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring an Excel file, the Excel file comprises table data required by establishing a database table, and the table data comprises a table name required by establishing the database table, fields contained in the database table and data types of the fields; the analysis unit is used for analyzing the Excel file in a preset mode to obtain the table data; the inserting unit is used for correspondingly inserting the table data into a preset grammar format for establishing the database table through a first preset method so as to obtain a plurality of branch scripts; and the generating unit is used for splicing the sub scripts by a second preset method according to the grammar of a database management system used for establishing the database table so as to generate the 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, where the memory stores a computer program, and the processor implements the method for generating the table creating script when executing the computer program.
In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the computer program causes the processor to execute the method for generating the table creating script.
The embodiment of the application provides a method and a device for generating a table building script, computer equipment and a computer readable storage medium. When the generation of the table building script is realized in the embodiment of the application, a developer only needs to write a field name and a table name into an Excel file, a computer device acquires the Excel file, the Excel file contains table data required for establishing a database table, the table data comprises the table name required for establishing the database table, fields contained in the database table and data types of the fields, the Excel file can be automatically analyzed in a preset mode to obtain the table data, the table data is correspondingly inserted into a preset grammar format for establishing the database table through a first preset method to obtain a plurality of sub-scripts, then the sub-scripts are spliced through a second preset method according to the grammar of a database management system used for establishing the database table to generate the script for establishing the database table, and therefore the script is automatically generated and built the table, compared with the traditional technology in which a developer generates a script for establishing a database table by writing codes, the embodiment of the application automatically generates the table establishing script, so that the developer is relieved from complicated mechanical labor without technical content, the time cost for generating the table establishing script is saved, and the efficiency for generating the table establishing script is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a flowchart illustrating a method for generating a table-building script according to an embodiment of the present disclosure;
FIG. 2 is a schematic block diagram of a table creating script generating apparatus provided in an embodiment of the present application; and
fig. 3 is a schematic block diagram of a computer device provided in an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the present application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in the specification of the present application and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
The method for generating the table building script provided by the embodiment of the application can be applied to computer equipment such as a terminal or a server, and the steps of the method for generating the table building script are realized through software installed on the terminal or the server, wherein the terminal can be an electronic device such as a mobile phone, a notebook computer, a tablet computer or a desktop computer, and the server can be a cloud server or a server cluster. Taking a terminal as an example, the specific implementation process of the method for generating the table building script provided by the embodiment of the application is as follows: the method comprises the steps that a terminal obtains an Excel file, wherein the Excel file comprises table data required for establishing a database table, the table data comprises a table name required for establishing the database table, fields included in the database table and data types of the fields, the table data is filled in the Excel file by developers, the Excel file is analyzed by the terminal in a preset mode to obtain the table data, the table data are correspondingly inserted into a preset syntax format used for establishing the database table through a first preset method to obtain a plurality of sub-scripts, and the sub-scripts are spliced through a second preset method according to syntax of a database management system used for establishing the database table to generate scripts for establishing the database table.
It should be noted that, in the actual operation process, the application scenario of the generation method of the table creating script is only used for illustrating the technical solution of the present application, and is not used for limiting the technical solution of the present application.
Fig. 1 is a schematic flowchart of a method for generating a table creation script according to an embodiment of the present application. The method for generating the table building script is applied to a terminal or a server, and the method is realized by application software installed in the terminal or the server, and specifically, the method can exist in a system manner, for example, wherein the terminal or the server is a computer device for executing all or part of functions of the method for generating the table building script. Referring to fig. 1, as shown in fig. 1, the method includes the following steps S101-S104:
s101, obtaining an Excel file, wherein the Excel file comprises table data required by establishing a database table, and the table data comprises a table name required by establishing the database table, a field contained in the database table and a data type of the field.
Specifically, the script for creating the database table refers to the code for creating the database table. Creating a table in a database, the general code structure being:
CREATE TABLE NAME
(
The column name 1 is the data type of,
the column name 2 is the data type of,
.......
)
since creating a database table at least requires table names of the database table, fields contained in the database table, and data types of the fields, and the table names, the fields contained in the database table, and the data types of the fields need to be customized by a user, this part of contents need to be set by the user through an Excel file, for example, in the above example, an Excel template will contain fields such as table name, column name 1, and data type thereof, column name 2, and data type 2 thereof. The Excel template of the user filling form data can be set in the system for realizing the method in the terminal or the server in advance, the user can download the Excel template carried by the system after reading the use description, and fill the form structure according to the Excel template, wherein, the user filling the form structure according to the Excel template means that the user fills in the form name, field and other information contained in the database table contained in the Excel template according to the template Excel, and stores the Excel file generated by the Excel template with the filled form structure into a local directory, and subsequently uploads the Excel file from the local directory by clicking a 'upload file' button, namely, the Excel file is uploaded from the local directory by clicking a 'select file' to select the Excel file so as to enable the computer equipment to acquire the Excel file. In the Excel template, a Sheet1 page can be defaulted as a navigation page, overview information of each table is placed, a table structure is filled in from a Sheet2 page according to the template, and a subsequent script automatically generates a table building script according to the table structures of the Sheet2 page, the Sheet3 page … … and the like.
The method comprises the steps that computer equipment obtains an Excel file uploaded by a user, wherein the Excel file comprises a table name and a field required by establishing a database table and the data type of the field, namely the table name required by establishing the database table, a column name and the data type of the column field contained in the database table.
S102, analyzing the Excel file in a preset mode to obtain the table data.
The preset mode comprises a JAR package and a library in Python. The JAR package comprises a POI package and a JXL package in JAVA; the libraries in Python include Xlrd libraries.
Specifically, the computer device parses the Excel file in a preset manner to obtain the table data, for example, the computer device parses the Excel file using a JAR package to obtain table data for creating a table, where the table data includes a table name, a field name, and a data type of the field.
Further, in an embodiment, the step of parsing the Excel file in a preset manner to obtain the table data includes:
and obtaining the table data contained in the Excel file through a POI package or Jxl.
Specifically, a third-party JAR package is used for analyzing Excel content, the JAR package is adopted in JAVA to read the content of an Excel table, one mode is to import a POI package, and the other mode is to import a JXL package. The method comprises the steps that JAVA analyzes Excel through a POI package, in the POI, XSSFWorkbook is used for analyzing an Excel table in an XLS format, so that the content of Excel files such as table names, field names and data types of fields required by establishing a database table is obtained, wherein JAVA reads specified row and column values from the Excel files through a jxl.
S103, correspondingly inserting the table data into a preset grammar format for establishing the database table through a first preset method to obtain a plurality of branch scripts.
Specifically, if a database table a of the SQL db management system is to be created, the database table a includes two columns B and C, and the manually written script for creating the table is:
CREATE TABLE name A; // ADD1
(
Column name B data type; // ADD2
Column name C data type; // ADD3
.......
)
Presetting a syntax format for establishing the database table as follows:
CREATE TABLE X1;//ADD1
(
X2 X3;//ADD2
X4 X5;//ADD3
.......
)
when the script for generating the database table A is created by the method of the embodiment of the application, the user can automatically generate the script only by simple operation, for example, clicking a 'selection folder' on a system to select a directory for storing the generated script for creating the table, and finally clicking a 'generation script'. The generating of the table building script is to analyze the content of the Excel file by using a third party Jar package, for example, Java analyzes the Excel file through a POI package, and since the Excel file contains fields such as a table name a, a column name B and a data type thereof, a column name C and a data type thereof, and the like, which are filled in by a user according to an Excel template, the table name a, the column name B and a data type thereof, the column name C and a data type thereof, and the like, which are required for building a database table are obtained.
In one embodiment, the first preset method comprises a StringBuffer-like Insert method. The step of correspondingly inserting the table data into a preset grammar format for establishing the database table to obtain a plurality of sub-scripts by a first preset method comprises the following steps:
and correspondingly inserting the table data into a preset SQL syntax format for establishing the database table through an Insert method of a StringBuffer class to obtain a plurality of SQL branch scripts.
Specifically, in JAVA, after the third-party JAR package parses the content of Excel, the table name a, the column name B and its data type, the column name C and its data type are obtained, and then an Insert method of the StringBuffer class is used, for example, the following script is used: public insert (int offset, int i) indicating that a string representation of int parameter is inserted into the sequence, a TABLE name a is inserted at a position X1 of ADD1 after CREATE TABLE, a column name B and its data type are inserted at a position X2 and a position X3 of ADD2, respectively, and a column name C and its data type are inserted at a position X4 and a position X5 of ADD3, thereby obtaining a plurality of branch scripts, such as "CREATE TABLE name a", "column name B data type", "column name C data type; // ADD3 ".
And S104, according to the grammar of a database management system used for establishing the database table, splicing the sub-scripts by a second preset method to generate a script for establishing the database table.
Wherein the second preset method comprises an append method and an append method in the StringBuffer class.
Specifically, after a plurality of sub-scripts are obtained, the plurality of sub-scripts are spliced through a second preset method according to the grammar of a database management system used for establishing the database table to generate a script for establishing the database table.
Further, in an embodiment, the step of splicing the plurality of sub-scripts by a second preset method according to a syntax of a database management system used for building the database table to generate a script for building the database table includes:
according to the grammar of a database management system used for establishing the database table, splicing the branch scripts by an appendix method in a StringBuffer class to obtain an initial script for establishing the database table;
and adopting a ToString method to carry out character string formatting on the initial script so as to generate a script for establishing the database table.
Specifically, taking the SQL database management system as an example, after obtaining a plurality of SQL sub-scripts, according to the SQL syntax, the plurality of sub-scripts are spliced into a table building script by using a StringBuffer class. Besides using the StringBuffer class to splice the SQL script, the StringBuilder class can be used to splice the SQL script. Splicing the SQL script, namely continuously splicing the applet SQL script according to the SQL grammar by adopting the Stringbuffer, and finally performing Tosting. The public String buffer applied (strings) adds the specified character String to the character sequence, the Tostring method converts the data before the Tostring () into a character String format, and the Tostring method returns a character String "representing the object in text". For example, the SQL script for creating TABLE a, which is the same as the script for creating TABLE a written manually, can be obtained by the method in the embodiment of the present application by applying the above format of SQL syntax to the SQL script for creating TABLE a that is obtained in the above example through Stringbuffer according to the appended SQL syntax without stopping by Stringbuffer, and finally tosting.
When the generation of the table building script is realized in the embodiment of the application, a developer only needs to write a field name and a table name into an Excel file, a computer device acquires the Excel file, the Excel file contains table data required for establishing a database table, the table data comprises the table name required for establishing the database table, fields contained in the database table and data types of the fields, the Excel file can be automatically analyzed in a preset mode to obtain the table data, the table data is correspondingly inserted into a preset grammar format for establishing the database table through a first preset method to obtain a plurality of sub-scripts, then the sub-scripts are spliced through a second preset method according to the grammar of a database management system used for establishing the database table to generate the script for establishing the database table, and therefore the script is automatically generated and built the table, compared with the traditional technology in which a developer generates a script for establishing a database table by writing codes, the embodiment of the application automatically generates the table establishing script, so that the developer is relieved from complicated mechanical labor without technical content, the time cost for generating the table establishing script is saved, and the efficiency for generating the table establishing script is improved.
In one embodiment, the Excel file includes a plurality of worksheets, and before the step of parsing the Excel file in a preset manner to obtain the sheet data, the method further includes:
circularly traversing each worksheet of the Excel file;
the step of analyzing the Excel file in a preset mode to obtain the table data comprises the following steps:
and analyzing each worksheet in a preset mode to obtain table data of the database table corresponding to each worksheet.
Traversal, in english, Traversal means that each node in the tree is sequentially visited once and only once along a certain search route.
Specifically, for the situation that the Excel file contains a plurality of worksheets, and each worksheet corresponds to one database table, each worksheet needs to be analyzed one by one. Computer equipment acquires an Excel file, analyzes a first worksheet contained in the Excel file in a preset mode, then circularly traverses all Sheet pages of the Excel file to obtain a table name required by each corresponding table to be built, a field contained in a database table and a data type of the field, namely analyzes each worksheet in a preset mode to convert each worksheet into a two-dimensional array to obtain table data of the database table corresponding to each worksheet, correspondingly inserts each table data into a preset syntax format for establishing the database table to obtain a plurality of sub-scripts corresponding to each database table through a first preset method, respectively splices the plurality of sub-scripts corresponding to each database table through a second preset method according to the syntax of a database management system used for establishing the database table to correspondingly generate a plurality of scripts for establishing the database table, thereby obtaining the table building scripts corresponding to the tables to be built.
Through the fact that the Excel file comprises a plurality of worksheets, a user only needs to fill in table names, fields contained in the database tables, data types of the fields and other table data required by the establishment of each database table in a plurality of database tables to be established according to an Excel template, combines a preset syntactic format for establishing the database tables, by the technical method of the embodiment of the application, massive Hive list building scripts can be generated by one key of the Excel list structure, the time cost is saved, developers are relieved from complicated mechanical labor without technical content, the labor cost of the developers is saved, the development quality and the coding efficiency are improved, moreover, the use of the method of creating database tables does not require any encoding capability for the user, even personnel without a coding base can independently complete the work of the table building script, and the generation efficiency of the table building script is improved. Wherein Hive is a data warehouse tool based on Hadoop.
In an embodiment, the step of parsing each worksheet in a preset manner to obtain table data of a database table corresponding to each worksheet includes:
analyzing each worksheet in a preset mode, and converting each worksheet into a two-dimensional array to obtain table data of the database table corresponding to each worksheet;
the step of correspondingly inserting the table data into a preset grammar format for establishing the database table to obtain a plurality of sub-scripts by a first preset method comprises the following steps:
correspondingly inserting the table data of the database table corresponding to each worksheet into a preset syntax format for establishing the database table through a first preset method to obtain a plurality of sub-scripts corresponding to each database table;
the step of splicing the plurality of sub-scripts by a second preset method according to the grammar of the database management system used for establishing the database table to generate the script for establishing the database table comprises the following steps:
and according to the syntax of a database management system used for establishing the database tables, respectively splicing the sub-scripts corresponding to each database table by a second preset method to correspondingly generate the scripts for establishing each database table.
Specifically, for the case of establishing a plurality of database tables, the content of each worksheet in the Excel file corresponds to one database table, that is, one Sheet page corresponds to one database table, one worksheet in the Excel file includes the table name required for establishing one database table, the fields included in the database table, and the data types of the fields, for example, A, B, C, D and E five database tables are to be established, the table name required for establishing a database table, the fields included in the database table, and the data types of the fields are in one worksheet, the table name required for establishing B database table, the fields included in the database table, and the data types of the fields are in another worksheet, and so on, the table name required for establishing E database table, the fields included in the database table, and the data types of the fields are in a fifth worksheet, corresponding to A, B, C, D and E five database tables, at least five worksheets are correspondingly contained in the Excel file. For the situation that the Excel file comprises a plurality of worksheets, the Excel template comprises a plurality of worksheets, and each worksheet comprises information such as a sheet name, a column name 1 and a data type of the worksheet required by building a database table.
In one embodiment, after the step of generating a script for building the database table by splicing the plurality of sub-scripts by a second preset method according to the syntax of the database management system used for building the database table, the method further includes:
and packaging the script for establishing the database table by using IO flow.
Wherein, the IO Stream, English is Input Output Stream, Chinese is Input Output Stream, and the IO Stream is Input and Output in a Stream mode.
Specifically, when a table building script is generated, a developer writes a field name and a table name into an Excel file, uploads the Excel file to computer equipment, the computer equipment acquires the Excel file, automatically analyzes the Excel file in a preset mode to obtain table names required for building a database table, fields contained in the database table, data types of the fields and other table data, correspondingly inserts the table data into a preset syntax format for building the database table through a first preset method to obtain a plurality of sub-scripts, splices the sub-scripts through a second preset method according to syntax of a database management system used for building the database table to generate a script for building the database table, and then packages the script for building the database table through IO streams. For example, for the situation that a plurality of database tables are established, and an Excel file comprises a plurality of Sheet pages, the computer device acquires the Excel file, then circularly traverses all Sheet pages of the Excel to obtain a Sheet building script corresponding to each Sheet page to be subjected to Sheet building, and writes the SQL script into a local file by using IO streams, wherein Java IO is a basis for realizing input and output, and the input and output operations of data can be conveniently realized. Different input and output sources (such as keyboard, files or network connections) are abstractly expressed in Java as "streams" (streamin english). Streaming allows Java programs to access different input and output sources in the same way.
It should be noted that, in the method for generating a table-building script described in each of the above embodiments, the technical features included in different embodiments may be recombined as needed to obtain a combined implementation, but all of them are within the protection scope claimed in the present application.
Referring to fig. 2, fig. 2 is a schematic block diagram of a table creating script generating apparatus according to an embodiment of the present application. Corresponding to the method for generating the table building script, the embodiment of the application further provides a device for generating the table building script. As shown in fig. 2, the generating apparatus of the table creating script includes a unit for executing the generating method of the table creating script, and the apparatus may be configured in a computer device such as a terminal or a server. Specifically, referring to fig. 2, the generating apparatus 200 of the table creating script includes an obtaining unit 201, a parsing unit 202, an inserting unit 203, and a generating unit 204.
The obtaining unit 201 is configured to obtain an Excel file, where the Excel file includes table data required to establish a database table, and the table data includes a table name required to establish the database table, a field included in the database table, and a data type of the field;
the analyzing unit 202 is configured to analyze the Excel file in a preset manner to obtain the table data;
an inserting unit 203, configured to insert the table data into a preset syntax format for establishing the database table correspondingly by using a first preset method to obtain a plurality of sub-scripts;
the generating unit 204 is configured to splice the multiple sub-scripts by a second preset method according to a syntax of a database management system used for establishing the database table, so as to generate a script for establishing the database table.
In one embodiment, the Excel file includes a plurality of worksheets, and the apparatus 200 for generating a sheet creation script further includes:
the circulation unit is used for circularly traversing each worksheet of the Excel file;
the analyzing unit 202 is configured to analyze each worksheet in a preset manner to obtain table data of a database table corresponding to each worksheet.
In an embodiment, the parsing unit 202 is configured to parse each worksheet in a preset manner, and convert each worksheet into a two-dimensional array to obtain table data of the database table corresponding to each worksheet;
the inserting unit 203 is configured to correspondingly insert, by using a first preset method, table data of the database table corresponding to each worksheet into a preset syntax format for establishing the database table to obtain a plurality of sub-scripts corresponding to each database table;
the generating unit 204 is configured to splice the multiple sub-scripts corresponding to each database table through a second preset method according to a syntax of a database management system used for establishing the database table, so as to correspondingly generate a script for establishing each database table.
In an embodiment, the inserting unit 203 is configured to correspondingly Insert the table data into a preset SQL syntax format for building the database table by using an Insert method of a StringBuffer class to obtain a plurality of SQL split scripts.
In one embodiment, the generating unit 204 includes:
the splicing subunit is used for splicing the plurality of branch scripts by an appendix method in a StringBuffer class according to the grammar of a database management system used for establishing the database table to obtain an initial script for establishing the database table;
and the formatting subunit is used for performing character string formatting on the initial script by adopting a ToString method to generate a script for establishing the database table.
In an embodiment, the parsing unit 202 is configured to obtain the table data included in the Excel file through a POI package in JAVA or jxl.
In one embodiment, the apparatus 200 for generating a table-building script further comprises:
and the packaging unit is used for packaging the script for establishing the database table by using IO stream.
It should be noted that, as can be clearly understood by those skilled in the art, the generation apparatus of the table creating script and the specific implementation process of each unit may refer to the corresponding description in the foregoing method embodiment, and for convenience and conciseness of description, no further description is provided herein.
Meanwhile, the division and connection manner of each unit in the generating device of the table building script are only used for illustration, in other embodiments, the generating device of the table building script may be divided into different units as required, or each unit in the generating device of the table building script may adopt different connection order and manner to complete all or part of the functions of the generating device of the table building script.
The above-described generating means of the tabulation script may be implemented in the form of a computer program which may be run on a computer device as shown in fig. 3.
Referring to fig. 3, fig. 3 is a schematic block diagram of a computer device according to an embodiment of the present application. The computer device 300 may be a computer device such as a desktop computer or a server, or may be a component or part of another device.
Referring to fig. 3, the computer device 300 includes a processor 302, memory, which may include a non-volatile storage medium 303 and an internal memory 304, and a network interface 305 connected by a system bus 301.
The nonvolatile storage medium 303 may store an operating system 3031 and a computer program 3032. The computer program 3032, when executed, causes the processor 302 to perform a method of generating a spreadsheet script as described above.
The processor 302 is used to provide computing and control capabilities to support the operation of the overall computer device 300.
The internal memory 304 provides an environment for running the computer program 3032 in the non-volatile storage medium 303, and when the computer program 3032 is executed by the processor 302, the processor 302 can be caused to execute a method for generating the table-building script.
The network interface 305 is used for network communication with other devices. Those skilled in the art will appreciate that the configuration shown in fig. 3 is a block diagram of only a portion of the configuration associated with the present application and does not constitute a limitation of the computer apparatus 300 to which the present application is applied, and that a particular computer apparatus 300 may include more or less components than those shown, or may combine certain components, or have a different arrangement of components. For example, in some embodiments, the computer device may only include a memory and a processor, and in such embodiments, the structures and functions of the memory and the processor are consistent with those of the embodiment shown in fig. 3, and are not described herein again.
Wherein the processor 302 is configured to run a computer program 3032 stored in the memory to implement the following steps: obtaining an Excel file, wherein the Excel file comprises table data required by establishing a database table, and the table data comprises a table name required by establishing the database table, fields contained in the database table and data types of the fields; analyzing the Excel file in a preset mode to obtain the table data; correspondingly inserting the table data into a preset grammar format for establishing the database table through a first preset method to obtain a plurality of branch scripts; and according to the grammar of a database management system used for establishing the database table, splicing the sub-scripts by a second preset method to generate a script for establishing the database table.
In an embodiment, when the processor 302 implements the step of obtaining an Excel file, the Excel file includes a plurality of worksheets, and before the processor 302 implements the step of analyzing the Excel file in a preset manner to obtain the sheet data, the following steps are further implemented:
circularly traversing each worksheet of the Excel file;
when the processor 302 implements the step of analyzing the Excel file in the preset manner to obtain the table data, the following steps are specifically implemented:
and analyzing each worksheet in a preset mode to obtain table data of the database table corresponding to each worksheet.
In an embodiment, when the processor 302 implements the step of parsing each worksheet in a preset manner to obtain the table data of the database table corresponding to each worksheet, the following steps are specifically implemented:
analyzing each worksheet in a preset mode, and converting each worksheet into a two-dimensional array to obtain table data of the database table corresponding to each worksheet;
when the processor 302 implements the step of correspondingly inserting the table data into a preset syntax format for establishing the database table by using the first preset method to obtain a plurality of sub-scripts, the following steps are specifically implemented:
correspondingly inserting the table data of the database table corresponding to each worksheet into a preset syntax format for establishing the database table through a first preset method to obtain a plurality of sub-scripts corresponding to each database table;
when the processor 302 implements the step of splicing the plurality of sub-scripts by a second preset method according to the syntax of the database management system used for establishing the database table to generate the script for establishing the database table, the following steps are specifically implemented:
and according to the syntax of a database management system used for establishing the database tables, respectively splicing the sub-scripts corresponding to each database table by a second preset method to correspondingly generate the scripts for establishing each database table.
In an embodiment, when the processor 302 implements the step of correspondingly inserting the table data into a preset syntax format for establishing the database table by using the first preset method to obtain a plurality of sub-scripts, the following steps are specifically implemented:
and correspondingly inserting the table data into a preset SQL syntax format for establishing the database table through an Insert method of a StringBuffer class to obtain a plurality of SQL branch scripts.
In an embodiment, when the processor 302 implements the step of splicing the plurality of sub-scripts by a second preset method according to the syntax of the database management system used for building the database table to generate the script for building the database table, the following steps are specifically implemented:
according to the grammar of a database management system used for establishing the database table, splicing the branch scripts by an appendix method in a StringBuffer class to obtain an initial script for establishing the database table;
and adopting a ToString method to carry out character string formatting on the initial script so as to generate a script for establishing the database table.
In an embodiment, when the processor 302 implements the step of analyzing the Excel file in a preset manner to obtain the table data, the following steps are specifically implemented:
and obtaining the table data contained in the Excel file through a POI package or Jxl.
In an embodiment, after implementing the step of splicing the plurality of sub-scripts by a second preset method according to the syntax of the database management system used for building the database table to generate the script for building the database table, the processor 302 further implements the following steps:
and packaging the script for establishing the database table by using IO flow.
It should be understood that, in the embodiment of the present Application, the Processor 302 may be a Central Processing Unit (CPU), and the Processor 302 may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable gate arrays (FPGAs) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
It will be understood by those skilled in the art that all or part of the processes in the method for implementing the above embodiments may be implemented by a computer program, and the computer program may 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 embodiments of the method described above.
Accordingly, the present application also provides a computer-readable storage medium. The computer readable storage medium may be a non-volatile computer readable storage medium, the computer readable storage medium storing a computer program that, when executed by a processor, causes the processor to perform the steps of:
a computer program product which, when run on a computer, causes the computer to perform the steps of the method of generating a spreadsheet script described in the embodiments above.
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 Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), etc. provided on the device. Further, the computer-readable storage medium may also include both an internal storage unit and an external storage device of the apparatus.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses, devices and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The computer readable storage medium may be a usb disk, a removable hard disk, a Read-Only Memory (ROM), a magnetic disk or an optical disk, and various computer readable storage media capable of storing program codes.
Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative. For example, the division of each unit is only one logic function division, and there may be another division manner in actual implementation. For example, various elements 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 application can be sequentially adjusted, combined and deleted according to actual needs. The units in the device of the embodiment of the application can be combined, divided and deleted according to actual needs. In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing an electronic device (which may be a personal computer, a terminal, or a network device) to perform all or part of the steps of the method according to the embodiments of the present application.
The above description is only for the specific embodiments of the present application, but the scope of the present application is not limited thereto, and any person skilled in the art can easily conceive various equivalent modifications or substitutions within the technical scope of the present application, and these modifications or substitutions should be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A method for generating a tabulation script, the method comprising:
obtaining an Excel file, wherein the Excel file comprises table data required by establishing a database table, and the table data comprises a table name required by establishing the database table, fields contained in the database table and data types of the fields;
analyzing the Excel file in a preset mode to obtain the table data;
correspondingly inserting the table data into a preset grammar format for establishing the database table through a first preset method to obtain a plurality of branch scripts;
and according to the grammar of a database management system used for establishing the database table, splicing the sub-scripts by a second preset method to generate a script for establishing the database table.
2. The method for generating a spreadsheet script of claim 1, wherein said Excel file contains a plurality of worksheets, and before said step of parsing said Excel file in a predetermined manner to obtain said spreadsheet data, further comprising:
circularly traversing each worksheet of the Excel file;
the step of analyzing the Excel file in a preset mode to obtain the table data comprises the following steps:
and analyzing each worksheet in a preset mode to obtain table data of the database table corresponding to each worksheet.
3. The method for generating a table creation script according to claim 2, wherein the step of parsing each worksheet in a preset manner to obtain table data of a database table corresponding to each worksheet comprises:
analyzing each worksheet in a preset mode, and converting each worksheet into a two-dimensional array to obtain table data of the database table corresponding to each worksheet;
the step of correspondingly inserting the table data into a preset grammar format for establishing the database table to obtain a plurality of sub-scripts by a first preset method comprises the following steps:
correspondingly inserting the table data of the database table corresponding to each worksheet into a preset syntax format for establishing the database table through a first preset method to obtain a plurality of sub-scripts corresponding to each database table;
the step of splicing the plurality of sub-scripts by a second preset method according to the grammar of the database management system used for establishing the database table to generate the script for establishing the database table comprises the following steps:
and according to the syntax of a database management system used for establishing the database tables, respectively splicing the sub-scripts corresponding to each database table by a second preset method to correspondingly generate the scripts for establishing each database table.
4. The method for generating a table creating script according to claim 1, wherein the step of correspondingly inserting the table data into a preset syntax format for creating the database table by a first preset method to obtain a plurality of sub-scripts comprises:
and correspondingly inserting the table data into a preset SQL syntax format for establishing the database table through an Insert method of a StringBuffer class to obtain a plurality of SQL branch scripts.
5. The method for generating a table building script according to claim 4, wherein the step of generating a script for building the database table by splicing a plurality of the sub-scripts by a second preset method according to the syntax of a database management system used for building the database table comprises:
according to the grammar of a database management system used for establishing the database table, splicing the branch scripts by an appendix method in a StringBuffer class to obtain an initial script for establishing the database table;
and adopting a ToString method to carry out character string formatting on the initial script so as to generate a script for establishing the database table.
6. The method for generating a form creation script according to claim 1, wherein the step of parsing the Excel file in a preset manner to obtain the form data comprises:
and obtaining the table data contained in the Excel file through a POI package or Jxl.
7. The method for generating a table building script according to claim 1, wherein after the step of generating a script for building the database table by splicing the plurality of sub-scripts by a second preset method according to the syntax of a database management system used for building the database table, the method further comprises:
and packaging the script for establishing the database table by using IO flow.
8. An apparatus for generating a tabulation script, comprising:
the system comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring an Excel file, the Excel file comprises table data required by establishing a database table, and the table data comprises a table name required by establishing the database table, fields contained in the database table and data types of the fields;
the analysis unit is used for analyzing the Excel file in a preset mode to obtain the table data;
the inserting unit is used for correspondingly inserting the table data into a preset grammar format for establishing the database table through a first preset method so as to obtain a plurality of branch scripts;
and the generating unit is used for splicing the sub scripts by a second preset method according to the grammar of a database management system used for establishing the database table so as to generate the script for establishing the database table.
9. A computer device, comprising a memory and a processor coupled to the memory; the memory is used for storing a computer program; the processor is configured to execute a computer program stored in the memory to perform the steps of the method of generating a tabulation script as claimed in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program which, when executed by a processor, causes the processor to carry out the steps of the method of generating a table-building script according to any one of claims 1-7.
CN201910851107.XA 2019-09-10 2019-09-10 Generation method and device of table building script, computer equipment and storage medium Pending CN110780860A (en)

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 (5)

* Cited by examiner, † Cited by third party
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
CN112632101A (en) * 2020-12-22 2021-04-09 平安普惠企业管理有限公司 Script generation method and device, computer equipment and storage medium
CN113220691A (en) * 2021-05-31 2021-08-06 北京互金新融科技有限公司 Database table creating method and device for database table, and electronic equipment

Citations (3)

* Cited by examiner, † Cited by third party
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

Patent Citations (3)

* Cited by examiner, † Cited by third party
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

Cited By (6)

* Cited by examiner, † Cited by third party
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
CN112632101A (en) * 2020-12-22 2021-04-09 平安普惠企业管理有限公司 Script generation method and device, computer equipment and storage medium
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

Similar Documents

Publication Publication Date Title
CN110780860A (en) Generation method and device of table building script, computer equipment and storage medium
US9256582B2 (en) Conversion of a presentation to Darwin Information Typing Architecture (DITA)
CN109460219B (en) Method for quickly serializing interface control file
CN107741935B (en) Data importing method and data importing device
US20150317156A1 (en) Systems and Methods for Automated Generation of Interactive Documentation Based on Web Application Description Language Files
CN107943465B (en) Method and device for generating HTML (Hypertext markup language) form
CN111241182A (en) Data processing method and apparatus, storage medium, and electronic apparatus
CN104978325A (en) Webpage processing method and device, and user terminal
US9990343B2 (en) System and method for in-browser editing
KR100762712B1 (en) Method for transforming of electronic document based on mapping rule and system thereof
CN111078529B (en) Client writing module testing method and device and electronic equipment
CN115495082B (en) TLV format data automatic conversion method and related equipment
CN115841095A (en) Document establishing method, system, medium and equipment
CN114201215A (en) Interface document generation method and device, electronic equipment and storage medium
US10402482B2 (en) Content management system
US11341154B2 (en) Normalizing encodings of requested data from a common data schema to a target data schema
CN111736805B (en) Method and device for processing Excel table
US10922106B2 (en) Systems and methods for providing globalization features in a service management application interface
CN117492824A (en) Interface component generation method and device
CN115268902A (en) Method, device and equipment for generating Html page
CN115334072A (en) File information processing method and device and electronic equipment
CN115983230A (en) Word document generation method and device based on JSON data
CN113961244A (en) Page conversion method, device, equipment and storage medium
CN116955279A (en) File uploading method, device, equipment and storage medium
CN114691107A (en) Front-end point burying method, device, equipment and storage medium

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