CN115481137B - SQL statement-based software generation method, device, equipment and medium - Google Patents

SQL statement-based software generation method, device, equipment and medium Download PDF

Info

Publication number
CN115481137B
CN115481137B CN202211151003.6A CN202211151003A CN115481137B CN 115481137 B CN115481137 B CN 115481137B CN 202211151003 A CN202211151003 A CN 202211151003A CN 115481137 B CN115481137 B CN 115481137B
Authority
CN
China
Prior art keywords
file
sql
sql sentence
generating
protobuf
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.)
Active
Application number
CN202211151003.6A
Other languages
Chinese (zh)
Other versions
CN115481137A (en
Inventor
李天仕
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Woxiang Technology Co ltd
Original Assignee
Shenzhen Woxiang Technology Co 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 Shenzhen Woxiang Technology Co ltd filed Critical Shenzhen Woxiang Technology Co ltd
Priority to CN202211151003.6A priority Critical patent/CN115481137B/en
Publication of CN115481137A publication Critical patent/CN115481137A/en
Application granted granted Critical
Publication of CN115481137B publication Critical patent/CN115481137B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • 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/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • 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/25Integrating or interfacing systems involving database management systems
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/186Templates
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Mathematical Physics (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • General Health & Medical Sciences (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a software generation method, device, equipment and medium based on SQL sentences, and relates to the field of programming. According to the method, the original codes of the SQLC tool are modified, so that the modified SQLC tool can directly generate program software (with the same query function) corresponding to the SQL statement, technicians do not need to write the program codes, the workload can be reduced by writing the SQL statement, the database query function of the SQL statement can be rapidly oriented to and used by users, technicians are liberated from repeated work, and the production efficiency is improved.

Description

SQL statement-based software generation method, device, equipment and medium
Technical Field
The present invention relates to the field of programming, and in particular, to a method, apparatus, device, and medium for generating software based on SQL statements.
Background
In a practical production application in the IT (Internet Technology) industry, technicians are quite unfriendly in writing database operations (e.g., database queries) code using Go language (The Go Programming Language, a programming language). The database/sql (sql database, sql, structured Query Language, structured query language) standard library provides a relatively underlying interface. The technician needs to write a large number of repeated codes that implement the query function. And a large number of template codes are not only cumbersome to write, but also prone to error. And codes for realizing the query function written based on the Go language cannot be directly oriented to users and used by the users.
Therefore, a method for rapidly implementing the sql database query function to the user and being used by the user is needed.
The foregoing is provided merely for the purpose of facilitating understanding of the technical solutions of the present invention and is not intended to represent an admission that the foregoing is prior art.
Disclosure of Invention
The invention mainly aims to provide a software generation method, device, equipment and medium based on SQL sentences, which aim to solve the technical problem of how to quickly realize that the database query function of SQL sentences is oriented to users and used by the users.
In order to achieve the above object, the present invention provides a software generation method based on SQL statements, the software generation method based on SQL statements comprising the steps of:
receiving an SQL sentence file;
generating a query database function according to the SQL sentence in the SQL sentence file, wherein the query database function and the SQL sentence have the same service function;
and generating program software corresponding to the SQL statement based on the query database function and a preset universal code template.
Further, the step of generating a query database function according to the SQL statement in the SQL statement file comprises the following steps:
loading the SQL sentence to a preset SQLC tool;
and generating the query database function corresponding to the SQL statement through the SQLC tool.
Further, the SQL statement file corresponds to a table constraint file, and before the step of generating, by the SQLC tool, a query database function corresponding to the SQL statement, the method includes:
checking the SQL sentence based on the table constraint file or/and the specification of the SQLC tool to judge whether the SQL sentence has grammar errors;
and executing the step of generating a query database function according to the SQL sentence in the SQL sentence file when judging that the SQL sentence has no grammar error.
Further, the step of generating the program software corresponding to the SQL statement based on the query database function and a preset universal code template includes:
generating a Protobuf file according to a preset Protobuf format file and the SQL statement;
and loading the query database function and the Protobuf file to the universal code template to generate the program software.
Further, the preset Protobuf format file includes a plurality of Protobuf file templates, and the step of generating the Protobuf file according to the preset Protobuf format file and the SQL statement includes:
matching a target Protobuf file template corresponding to the SQL sentence from the preset Protobuf format file based on the feature quantity of the SQL sentence;
and taking the target Protobuf file template as the Protobuf file.
Further, the step of loading the query database function and the Protobuf file into the universal code template to generate the program software includes:
loading the query database function and the Protobuf file into the universal code template to obtain a program code corresponding to the program software;
compiling the program code to generate the program software, and generating an address interface corresponding to the program software through the Protobuf file and the SQL statement so that the program software can be acquired and used.
Further, after the step of determining whether the SQL statement has a grammar error, the method includes:
when judging that the SQL sentence has grammar errors, outputting prompt information that the SQL sentence in the SQL sentence file has grammar errors and cannot normally generate program software.
In addition, in order to achieve the above object, the present invention also provides a software generating device based on an SQL statement, the software generating device based on an SQL statement comprising:
the receiving module is used for receiving the SQL sentence file;
the first generation module is used for generating a query database function according to the SQL sentences in the SQL sentence file, wherein the query database function and the SQL sentences have the same service function;
and the second generation module is used for generating program software corresponding to the SQL sentence based on the query database function and a preset universal code template.
In addition, in order to achieve the above object, the present invention also provides an SQL statement-based software generation apparatus, including: the system comprises a memory, a processor and an SQL statement-based software generation program which is stored in the memory and can run on the processor, wherein the SQL statement-based software generation program realizes the steps of the SQL statement-based software generation method when being executed by the processor.
In addition, in order to achieve the above object, the present invention further provides a medium on which an SQL statement-based software generation program is stored, which when executed by a processor, implements the steps of the SQL statement-based software generation method described above.
The embodiment of the invention provides a software generation method, device, equipment and medium based on SQL sentences, which are used for receiving SQL sentence files through a modified SQLC tool; generating a query database function according to the SQL sentence in the SQL sentence file, wherein the query database function and the SQL sentence have the same service function; and generating program software corresponding to the SQL statement based on the query database function and a preset universal code template. In the invention, the source code of the SQLC tool is modified by means of the native SQLC tool, after the SQLC tool generates the query database function corresponding to the SQL sentence, the generated query database function is combined with the preset universal code template to obtain the program software with the same function as the SQL sentence, and the generated program software can meet the data query requirement of non-technical personnel. It can be understood that by modifying the original code of the SQLC tool, the modified SQLC tool can directly generate the program software (with the same query function) corresponding to the SQL statement, technicians do not need to write the program code, the workload can be reduced by writing the SQL statement, the database query function of the SQL statement can be rapidly oriented to users and used by the users, technicians are liberated from repeated work, and the production efficiency is enhanced.
Drawings
FIG. 1 is a schematic diagram of a device architecture of a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flowchart of a first embodiment of the SQL statement-based software generation method according to the present invention;
FIG. 3 is a flowchart of a second embodiment of the SQL statement-based software generation method according to the present invention;
FIG. 4 is a flowchart of a third embodiment of the SQL statement-based software generation method according to the present invention;
fig. 5 is a schematic diagram of a device structure involved in the software generation method based on SQL statements.
The achievement of the objects, functional features and advantages of the present invention will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
The main solutions of the embodiments of the present invention are: receiving an SQL sentence file; generating a query database function according to the SQL sentence in the SQL sentence file, wherein the query database function and the SQL sentence have the same service function; and generating program software corresponding to the SQL statement based on the query database function and a preset universal code template.
The technical problem that the database query function of the sql statement faces to and is used by the user cannot be realized rapidly in the prior art.
The invention provides a solution, through modifying the original code of the SQLC tool, the modified SQLC tool can directly generate the program software (with the same query function) corresponding to the SQL statement, technicians do not need to write the program code, and the workload can be reduced by writing the SQL statement, so that the database query function of the SQL statement can be rapidly oriented to users and used by the users, technicians are liberated from repeated work, and the production efficiency is enhanced.
As shown in fig. 1, fig. 1 is a schematic diagram of a terminal structure of a hardware running environment according to an embodiment of the present invention.
The device of the embodiment of the invention can be a PC, and also can be electronic terminal devices with data receiving, data processing and data sending functions such as a smart phone, a tablet personal computer, a portable computer and the like.
As shown in fig. 1, the apparatus may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein the communication bus 1002 is used to enable connected communication between these components. The user interface 1003 may include a Display, an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may further include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 may also optionally be a storage device separate from the processor 1001 described above.
Optionally, the device may also include a camera, RF (Radio Frequency) circuitry, sensors, audio circuitry, wiFi modules, and the like. Among other sensors, such as light sensors, motion sensors, and other sensors. Specifically, the light sensor may include an ambient light sensor that may adjust the brightness of the display screen according to the brightness of ambient light, and a proximity sensor that may turn off the display screen and/or the backlight when the mobile terminal moves to the ear. As one of the motion sensors, the gravity acceleration sensor can detect the acceleration in all directions (generally three axes), and can detect the gravity and the direction when the mobile terminal is stationary, and the mobile terminal can be used for recognizing the gesture of the mobile terminal (such as horizontal and vertical screen switching, related games, magnetometer gesture calibration), vibration recognition related functions (such as pedometer and knocking), and the like; of course, the mobile terminal may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, and the like, which are not described herein.
It will be appreciated by those skilled in the art that the terminal structure shown in fig. 1 is not limiting of the terminal and may include more or fewer components than shown, or may combine certain components, or a different arrangement of components.
As shown in fig. 1, an operating system, a network communication module, a user interface module, and an SQL statement-based software generation program may be included in the memory 1005 as one type of computer storage medium.
In the terminal shown in fig. 1, the network interface 1004 is mainly used for connecting to a background server and performing data communication with the background server; the user interface 1003 is mainly used for connecting a client (user side) and performing data communication with the client; and the processor 1001 may be configured to call an SQL statement-based software generation program stored in the memory 1005 and perform the following operations:
receiving an SQL sentence file;
generating a query database function according to the SQL sentence in the SQL sentence file, wherein the query database function and the SQL sentence have the same service function;
and generating program software corresponding to the SQL statement based on the query database function and a preset universal code template.
Further, the processor 1001 may call the software generation program based on the SQL statement stored in the memory 1005, and further perform the following operations:
the step of generating a query database function according to the SQL sentence in the SQL sentence file comprises the following steps:
loading the SQL sentence to a preset SQLC tool;
and generating the query database function corresponding to the SQL statement through the SQLC tool.
Further, the processor 1001 may call the software generation program based on the SQL statement stored in the memory 1005, and further perform the following operations:
the SQL statement file corresponds to a table constraint file, and before the step of generating a query database function corresponding to the SQL statement by the SQLC tool, the method comprises the following steps:
checking the SQL sentence based on the table constraint file or/and the specification of the SQLC tool to judge whether the SQL sentence has grammar errors;
and executing the step of generating a query database function according to the SQL sentence in the SQL sentence file when judging that the SQL sentence has no grammar error.
Further, the processor 1001 may call the software generation program based on the SQL statement stored in the memory 1005, and further perform the following operations:
the step of generating the program software corresponding to the SQL sentence based on the query database function and a preset universal code template comprises the following steps:
generating a Protobuf file according to a preset Protobuf format file and the SQL statement;
and loading the query database function and the Protobuf file to the universal code template to generate the program software.
Further, the processor 1001 may call the software generation program based on the SQL statement stored in the memory 1005, and further perform the following operations:
the preset Protobuf format file comprises a plurality of Protobuf file templates, and the step of generating the Protobuf file according to the preset Protobuf format file and the SQL sentence comprises the following steps:
matching a target Protobuf file template corresponding to the SQL sentence from the preset Protobuf format file based on the feature quantity of the SQL sentence;
and taking the target Protobuf file template as the Protobuf file.
Further, the processor 1001 may call the software generation program based on the SQL statement stored in the memory 1005, and further perform the following operations:
the step of loading the query database function and the Protobuf file into the universal code template to generate the program software comprises the following steps:
loading the query database function and the Protobuf file into the universal code template to obtain a program code corresponding to the program software;
compiling the program code to generate the program software, and generating an address interface corresponding to the program software through the Protobuf file and the SQL statement so that the program software can be acquired and used.
Further, the processor 1001 may call the software generation program based on the SQL statement stored in the memory 1005, and further perform the following operations:
after the step of determining whether the SQL sentence has a grammar error, the method includes:
when judging that the SQL sentence has grammar errors, outputting prompt information that the SQL sentence in the SQL sentence file has grammar errors and cannot normally generate program software.
Referring to fig. 2, in a first embodiment of the software generating method based on SQL statements of the present invention, the software generating method based on SQL statements includes:
step S10, receiving an SQL sentence file;
in this embodiment, the SQL statement file includes an SQL statement for implementing a database query function. In general, a technician can edit the SQL sentence by himself to perform related data query on the database, but a certain technical threshold still exists for realizing the query function through the SQL sentence. For non-technicians, the query software subjected to technician packaging conversion is required to meet the data query requirements of the non-technicians. It will be appreciated that when a technician edits a software code that implements the query function of an SQL statement, it is not friendly to the technician to use other programming languages, such as the Go language, to write database operation codes using the Go language, it is also error-prone, and the technician needs to write a corresponding software framework in addition to the Go language code corresponding to the SQL statement, so that tools that can be used by non-technicians are available, which is undoubtedly labor-intensive and time-consuming and energy-intensive for the technician. In this embodiment, the program software for implementing the corresponding function of the SQL statement is automatically generated. Firstly, an SQL sentence file for realizing the query function is received, and the SQL sentence in the SQL sentence file is the basis for realizing the query function, and also in the embodiment, is used as the basis for generating software with the data query function.
Step S20, generating a query database function according to the SQL sentence in the SQL sentence file, wherein the query database function and the SQL sentence have the same service function;
further, loading the SQL sentence to a preset SQLC tool; and generating the query database function corresponding to the SQL statement through the SQLC tool.
Specifically, the SQLC (Structured Query Language Compiler, SQL compiler) tool is a compiler of an SQL statement, and the SQL statement can be compiled into corresponding Go language program code by the SQLC tool, and the program code is a query database function. And the obtained query database function has the same function as SQL sentences. And the corresponding Go language code can be automatically generated by the SQLC tool by loading the SQL sentence into the SQLC tool. Moreover, the current native SQLC tool has a function of compiling the SQL statement into the Go language code, so that a detailed description thereof will be omitted herein. Furthermore, it should be noted that the Go language code generated by the native SQLC tool, i.e., the query database function described above, is only a partial code for implementing the SQL statement query function, and is not complete program software. The complete programming software still needs to be written by the technician based on Go language code generated by the native SQLC tool or the query database function described above.
And step S30, generating program software corresponding to the SQL sentence based on the query database function and a preset universal code template.
Further, generating a Protobuf file according to a preset Protobuf format file and the SQL statement; and loading the query database function and the Protobuf file to the universal code template to generate the program software.
Further, the preset Protobuf format file includes a plurality of Protobuf file templates, and the step of generating the Protobuf file according to the preset Protobuf format file and the SQL statement includes: matching a target Protobuf file template corresponding to the SQL sentence from the preset Protobuf format file based on the feature quantity of the SQL sentence; and taking the target Protobuf file template as the Protobuf file.
Specifically, in this embodiment, the preset SQLC tool is actually modified based on the native SQLC tool. The native SQLC tool has added thereto the code to generate protobuf (Google Protocol Buffers, google provides a tool library with efficient protocol data exchange formats, in this embodiment, http (HyperText Transfer Protocol, hypertext transfer protocol) interface files to be used to generate program software, and part of the generic template functions, such as: the preset SQLC tool is obtained by a Web (World Wide Web) framework, a database framework, main functions (main functions) and the like, and meanwhile, the preset SQLC tool also has the function of generating a query database function corresponding to the SQL sentence by the native SQLC tool. After the function of querying the database function is generated through a preset SQLC tool, a target Protobuf file template corresponding to the SQL sentence is matched from a preset Protobuf format file based on the characteristic quantity of the SQL sentence. It will be appreciated that, in the general case, the above SQL statement will be used for querying database data, and there are input parameters and corresponding output parameters corresponding to the input parameters in performing data query, for example, when performing student performance query, a student name or a student number needs to be input, and the results of subjects such as language, mathematics, english, physics, history, and the like of the student are correspondingly output. The feature quantity of the SQL sentence is the data type of the input parameter/output parameter in the SQL sentence or the number of the input parameter/output parameter. And matching based on the feature quantity of the SQL sentence to obtain the Protobuf file. Correspondingly, the universal template code required for generating the Protobuf file comprises the following steps:
protobufTemp:=`
syntmax= "proto3"; use of protobuf 3 protocol
package app.app;
option go_package="./buf";
service { {.servicename } {// since the name of the service is dynamically changed, a {.servicename } }' placeholder is reserved here;
{ {. FunList }// since the function name and number contained by the service are uncertain, here a { {. FunList }. Placeholder is reserved;
{ {. StructList }// since the input and output parameters of the function are not fixed, the { {. StructList }. Placeholder is reserved.
In the process of loading the query database function and the Protobuf file into a preset general code template, the general code template comprises a web framework, a database framework, a main function and the like, and in addition, a technician can set the general code template according to own requirements. The query database function, the Protobuf file and the universal code template can form program software for realizing the SQL statement query function. The non-technical personnel can meet the query requirement of the non-technical personnel through the generated software.
In this embodiment, the modified SQLC tool will receive the SQL statement file; generating a query database function according to the SQL sentence in the SQL sentence file, wherein the query database function and the SQL sentence have the same service function; and generating program software corresponding to the SQL statement based on the query database function and a preset universal code template. In the invention, the source code of the SQLC tool is modified by means of the native SQLC tool, after the SQLC tool generates the query database function corresponding to the SQL sentence, the generated query database function is combined with the preset universal code template to obtain the program software with the same function as the SQL sentence, and the generated program software can meet the data query requirement of non-technical personnel. It can be understood that by modifying the original code of the SQLC tool, the modified SQLC tool can directly generate the program software (with the same query function) corresponding to the SQL statement, technicians do not need to write the program code, the workload can be reduced by writing the SQL statement, the database query function of the SQL statement can be rapidly oriented to users and used by the users, technicians are liberated from repeated work, and the production efficiency is enhanced.
Further, referring to fig. 3, a second embodiment of the software generating method based on SQL statements of the present invention is proposed based on the first embodiment of the software generating method based on SQL statements of the present invention.
The SQL statement file corresponds to a table constraint file, and before the step of generating a query database function corresponding to the SQL statement by the SQLC tool, the method comprises the following steps:
step S210, checking the SQL sentence based on the table constraint file or/and the specification of the SQLC tool to judge whether the SQL sentence has grammar errors;
step S211, when it is determined that the SQL statement does not have a grammar error, executing the step of generating a query database function according to the SQL statement in the SQL statement file.
Step S212, when judging that the SQL sentence has grammar errors, outputting prompt information that the SQL sentence in the SQL sentence file has grammar errors and cannot normally generate program software.
Specifically, the received SQL statement file further includes a table constraint file, where the table constraint file is a constraint condition that the SQL statement written in the SQL statement is free from data problems, and generally the constraint condition included in the table constraint file may include: PRIMARY KEY (primary KEY constraint, primary KEY field cannot be NULL, must be UNIQUE), FOREIGN KEY (FOREIGN KEY constraint, determine the way of contact between tables, typically by the identification column of the primary table), UNIQUE (UNIQUE constraint, determine that the data in this field must be UNIQUE), NOT NULL (non-NULL constraint, determine that the data in this field must NOT be NULL), CHECK (CHECK constraint, set the data properties in this field), etc., which will NOT be described in detail herein. The SQL statement can be checked through the table constraint file or/and the specification of the original SQLC tool so as to ensure that the SQL statement of the compiling (generating the database query function) has no grammar error. The step of generating a query database function from the SQL statements in the SQL statement file may be performed directly for SQL statements that do not have syntax errors. And if the SQL statement with the grammar error exists, the SQL statement in the SQL statement file outputs the prompt information that the grammar error exists and the program software cannot be normally generated, so that a technician can correct the SQL statement after receiving the prompt information. For example, there is a cluster table whose constraint files are as follows:
CREATE TABLE`cluster`(
"ID" char (36) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ ci NOT NULL DEFAULT "COMMENT 'Cluster ID';
the `name` varchar (100) CHARACTER SET utf8COLLATEutf8_general_ ci NOT NULL DEFAULT ` COMMENT 'cluster name';
the 'desc' varchar (100) NOT NULL DEFAULT "COMMENT 'descriptive information';
'create_time' int NOT NULL DEFAULT '0' COMMENT 'creation time';
)
engine= InnoDB DEFAULT CHARSET =utf8command= 'cluster table'.
If an SQL statement is: name: getclusteriyuser: one select from cluster where user = 'Zhang san'. This sql is wrong since there is no user field in the table constraint file. Firstly, carrying out field analysis on the table constraint file to obtain available fields in the table constraint file as follows: id. name, desc, create _time four fields. And carrying out field analysis on the sql statement to obtain a non-usable field, and carrying out error reporting if the field is a user field.
It can be understood that in this embodiment, the SQL statement for generating the software program will be checked, and an error prompt will be output for the SQL statement with a grammar error, so as to avoid that the SQL statement with a grammar error causes an error in the process of generating the corresponding program software.
Further, referring to fig. 4, a third embodiment of the software generating method based on SQL statements of the present invention is proposed based on the first embodiment of the software generating method based on SQL statements of the present invention.
The step of loading the query database function and the Protobuf file into the universal code template to generate the program software comprises the following steps:
step S310, loading the query database function and the Protobuf file to the universal code template to obtain a program code corresponding to the program software;
step S320, compiling the program code to generate the program software, and generating an address interface corresponding to the program software through the Protobuf file and the SQL statement, so that the program software can be obtained and used.
Specifically, the query database function and the Protobuf file are loaded to the code template to obtain the complete program code of the program software, and the complete program code is compiled to obtain the program software. Wherein, the Protobuf file in the program software is combined with SQL sentences to generate the address interface of the program software. The Protobuf file generates a unique address interface of the program software according to the input parameters and the output parameters in the SQL sentence, and a non-technician can open the generated program software through the address interface and perform data query. For example, the SQLC tool would be an SQL statement: name: getclusterid: one SELECT FROM cluster WHERE id = question mark, translated into a query database function: getClusterById (ctx context. Context, id string) (Cluster, error). Generating a cluster_service.protobuf file through the query function:
based on the cluster_service.protobuf file, an interface address may be generated using a protoc tool. Generating an interface address file with a protoc tool includes: protoc-i./cluster_service.proto-go_out=/-twirp_out=/-openapiv2_out=/. The corresponding interface addresses are: type ClusterService interface { getclusterid (context, request) }. It can be understood that in this embodiment, the generated program software also generates a corresponding address interface, so that a non-technician can query by opening the address interface, thereby facilitating the use of the program software.
In addition, referring to fig. 5, an embodiment of the present invention further proposes an SQL statement-based software generating apparatus 1000, where the SQL statement-based software generating apparatus 1000 includes:
a receiving module 100, configured to receive an SQL statement file;
a first generation module 200, configured to generate a query database function according to an SQL statement in the SQL statement file, where the query database function and the SQL statement have the same service function;
and the second generating module 300 is configured to generate program software corresponding to the SQL statement based on the query database function and a preset generic code template.
Optionally, the first generating module 200 is further configured to:
loading the SQL sentence to a preset SQLC tool;
and generating the query database function corresponding to the SQL statement through the SQLC tool.
Optionally, the SQL statement file corresponds to a table constraint file, and the first generation module is further configured to:
checking the SQL sentence based on the table constraint file or/and the specification of the SQLC tool to judge whether the SQL sentence has grammar errors;
and executing the step of generating a query database function according to the SQL sentence in the SQL sentence file when judging that the SQL sentence has no grammar error.
Optionally, the second generating module 200 is further configured to:
generating a Protobuf file according to a preset Protobuf format file and the SQL statement;
and loading the query database function and the Protobuf file to the universal code template to generate the program software.
Optionally, the preset Protobuf format file includes a plurality of Protobuf file templates, and the second generating module 200 is further configured to:
matching a target Protobuf file template corresponding to the SQL sentence from the preset Protobuf format file based on the feature quantity of the SQL sentence;
and taking the target Protobuf file template as the Protobuf file.
Optionally, the second generating module 200 is further configured to:
loading the query database function and the Protobuf file into the universal code template to obtain a program code corresponding to the program software;
compiling the program code to generate the program software, and generating an address interface corresponding to the program software through the Protobuf file and the SQL statement so that the program software can be acquired and used.
Optionally, the first generating module 100 is further configured to:
when judging that the SQL sentence has grammar errors, outputting prompt information that the SQL sentence in the SQL sentence file has grammar errors and cannot normally generate program software.
The software generating device based on the SQL sentence provided by the invention adopts the software generating method based on the SQL sentence in the embodiment, and aims to solve the technical problem of how to quickly realize that the database query function of the SQL sentence is oriented to and used by a user. Compared with the prior art, the software generating device based on the SQL sentence has the same beneficial effects as the software generating method based on the SQL sentence provided by the embodiment, and other technical features in the software generating device based on the SQL sentence are the same as the features disclosed by the method of the embodiment, and are not repeated herein.
In addition, the embodiment of the invention also provides a software generating device based on the SQL sentence, which comprises: the system comprises a memory, a processor and an SQL statement-based software generation program which is stored in the memory and can run on the processor, wherein the SQL statement-based software generation program realizes the steps of the SQL statement-based software generation method when being executed by the processor.
The specific implementation manner of the software generating device based on the SQL sentence is basically the same as that of each embodiment of the new method for generating the software based on the SQL sentence, and is not repeated here.
In addition, the embodiment of the invention also provides a medium, wherein the medium stores a software generating program based on SQL sentences, and the steps of the software generating method based on SQL sentences are realized when the software generating program based on SQL sentences is executed by a processor.
The specific implementation manner of the medium of the present invention is basically the same as the above embodiments of the software generation method based on the SQL statement, and will not be repeated here.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present invention are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present invention may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) as described above, comprising instructions for causing a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) to perform the method according to the embodiments of the present invention.
The foregoing description is only of the preferred embodiments of the present invention, and is not intended to limit the scope of the invention, but rather is intended to cover any equivalents of the structures or equivalent processes disclosed herein or in the alternative, which may be employed directly or indirectly in other related arts.

Claims (5)

1. The software generation method based on the SQL sentence is characterized by comprising the following steps of:
receiving an SQL sentence file;
generating a query database function according to the SQL sentence in the SQL sentence file, wherein the query database function and the SQL sentence have the same service function;
generating program software corresponding to the SQL statement based on the query database function and a preset universal code template;
wherein, the step of generating a query database function according to the SQL sentence in the SQL sentence file comprises the following steps:
loading the SQL sentence to a preset SQLC tool;
generating the query database function corresponding to the SQL statement through the SQLC tool;
wherein, the SQL sentence file corresponds to a table constraint file, and before the step of generating a query database function corresponding to the SQL sentence by the SQLC tool, the method comprises:
checking the SQL sentence based on the table constraint file or/and the specification of the SQLC tool to judge whether the SQL sentence has grammar errors;
executing the step of generating a query database function according to the SQL sentence in the SQL sentence file when judging that the SQL sentence has no grammar error;
the step of generating the program software corresponding to the SQL sentence based on the query database function and a preset universal code template comprises the following steps:
generating a Protobuf file according to a preset Protobuf format file and the SQL statement;
loading the query database function and the Protobuf file to the universal code template to generate the program software;
the step of generating the Protobuf file according to the preset Protobuf format file and the SQL sentence comprises the following steps:
matching a target Protobuf file template corresponding to the SQL sentence from the preset Protobuf format file based on the characteristic quantity of the SQL sentence, wherein the characteristic quantity of the SQL sentence is the data type of input parameters/output parameters in the SQL sentence or the quantity of each input parameter/output parameter;
taking the target Protobuf file template as the Protobuf file;
wherein the step of loading the query database function and the Protobuf file into the universal code template to generate the program software includes:
loading the query database function and the Protobuf file into the universal code template to obtain a program code corresponding to the program software;
compiling the program code to generate the program software, and generating an address interface corresponding to the program software through the Protobuf file and the SQL statement so that the program software can be acquired and used.
2. The method for generating software based on SQL statement according to claim 1, wherein after the step of judging whether the SQL statement has a syntax error, the method comprises:
when judging that the SQL sentence has grammar errors, outputting prompt information that the SQL sentence in the SQL sentence file has grammar errors and cannot normally generate program software.
3. An SQL statement-based software generation apparatus, comprising:
the receiving module is used for receiving the SQL sentence file;
the first generation module is used for generating a query database function according to the SQL sentences in the SQL sentence file, wherein the query database function and the SQL sentences have the same service function;
the second generation module is used for generating program software corresponding to the SQL sentence based on the query database function and a preset universal code template;
wherein, the step of generating a query database function according to the SQL sentence in the SQL sentence file comprises the following steps:
loading the SQL sentence to a preset SQLC tool;
generating the query database function corresponding to the SQL statement through the SQLC tool;
the table constraint file corresponding to the SQL sentence file comprises the following steps before the step of generating a query database function corresponding to the SQL sentence by the SQLC tool:
checking the SQL sentence based on the table constraint file or/and the specification of the SQLC tool to judge whether the SQL sentence has grammar errors;
executing the step of generating a query database function according to the SQL sentence in the SQL sentence file when judging that the SQL sentence has no grammar error;
the step of generating the program software corresponding to the SQL sentence based on the query database function and a preset universal code template comprises the following steps:
generating a Protobuf file according to a preset Protobuf format file and the SQL statement;
loading the query database function and the Protobuf file to the universal code template to generate the program software;
the step of generating the Protobuf file according to the preset Protobuf format file and the SQL sentence comprises the following steps:
matching a target Protobuf file template corresponding to the SQL sentence from the preset Protobuf format file based on the characteristic quantity of the SQL sentence, wherein the characteristic quantity of the SQL sentence is the data type of input parameters/output parameters in the SQL sentence or the quantity of each input parameter/output parameter;
taking the target Protobuf file template as the Protobuf file;
wherein the step of loading the query database function and the Protobuf file into the universal code template to generate the program software includes:
loading the query database function and the Protobuf file into the universal code template to obtain a program code corresponding to the program software;
compiling the program code to generate the program software, and generating an address interface corresponding to the program software through the Protobuf file and the SQL statement so that the program software can be acquired and used.
4. An SQL statement-based software generation apparatus, comprising: memory, a processor and an SQL statement-based software generation program stored on the memory and executable on the processor, which when executed by the processor implements the steps of the SQL statement-based software generation method of any one of claims 1 to 2.
5. A medium, wherein a software generating program based on SQL statements is stored on the medium, and the software generating program based on SQL statements realizes the steps of the software generating method based on SQL statements according to any one of claims 1 to 2 when being executed by a processor.
CN202211151003.6A 2022-09-21 2022-09-21 SQL statement-based software generation method, device, equipment and medium Active CN115481137B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211151003.6A CN115481137B (en) 2022-09-21 2022-09-21 SQL statement-based software generation method, device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211151003.6A CN115481137B (en) 2022-09-21 2022-09-21 SQL statement-based software generation method, device, equipment and medium

Publications (2)

Publication Number Publication Date
CN115481137A CN115481137A (en) 2022-12-16
CN115481137B true CN115481137B (en) 2023-10-31

Family

ID=84392801

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211151003.6A Active CN115481137B (en) 2022-09-21 2022-09-21 SQL statement-based software generation method, device, equipment and medium

Country Status (1)

Country Link
CN (1) CN115481137B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110674205A (en) * 2019-09-23 2020-01-10 苏州达家迎信息技术有限公司 Single table query method, device, terminal and readable storage medium
CN114153852A (en) * 2021-12-07 2022-03-08 北京奇艺世纪科技有限公司 Data query method, device, equipment and storage medium

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6877000B2 (en) * 2001-08-22 2005-04-05 International Business Machines Corporation Tool for converting SQL queries into portable ODBC

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110674205A (en) * 2019-09-23 2020-01-10 苏州达家迎信息技术有限公司 Single table query method, device, terminal and readable storage medium
CN114153852A (en) * 2021-12-07 2022-03-08 北京奇艺世纪科技有限公司 Data query method, device, equipment and storage medium

Also Published As

Publication number Publication date
CN115481137A (en) 2022-12-16

Similar Documents

Publication Publication Date Title
US8762962B2 (en) Methods and apparatus for automatic translation of a computer program language code
CN110955416A (en) Interface document generation method, device, equipment and computer storage medium
CN108549538B (en) Code detection method and device, storage medium and test terminal
CN111459495B (en) Unit test code file generation method, electronic device and storage medium
CN112015430A (en) JavaScript code translation method and device, computer equipment and storage medium
CN110716715A (en) Application program development method, device, equipment and medium
CN111061464B (en) Analysis code generation method, device, equipment and storage medium
CA2684822A1 (en) Data transformation based on a technical design document
CN111723002A (en) Code debugging method and device, electronic equipment and storage medium
JP2023541186A (en) Visualization page rendering method, device, equipment and storage medium
CN110737689A (en) Data standard conformance detection method, device, system and storage medium
CN112395843A (en) PHP code-based service processing method, device, equipment and medium
CN112527386B (en) Application program issuing method and device
CN111984262A (en) WeChat cascading style sheet file processing method, device, equipment and storage medium
CN115481137B (en) SQL statement-based software generation method, device, equipment and medium
CN110688315A (en) Interface code detection report generation method, electronic device, and storage medium
EP3514697A1 (en) Electronic device and search keyword processing method thereof
TW201839632A (en) Method and device for processing natural language
CN112199254B (en) Data model scanning method, system, computer device and storage medium
CN112667202B (en) Software design method and device combining MDA and BPMN
CN111539200B (en) Method, device, medium and electronic equipment for generating rich text
CN114116683B (en) Multi-language processing method and device for computing platform and readable storage medium
CN112306493A (en) Hot repair patch generation method and device, storage medium and computer equipment
CN111488286A (en) Method and device for independently developing Android module
CN106648925B (en) Mobile terminal and method for acquiring character string information thereof

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
GR01 Patent grant
GR01 Patent grant