CN106844369B - Objectification SQL sentence construction method and apparatus - Google Patents

Objectification SQL sentence construction method and apparatus Download PDF

Info

Publication number
CN106844369B
CN106844369B CN201510882493.0A CN201510882493A CN106844369B CN 106844369 B CN106844369 B CN 106844369B CN 201510882493 A CN201510882493 A CN 201510882493A CN 106844369 B CN106844369 B CN 106844369B
Authority
CN
China
Prior art keywords
sql
object class
preset
level
template
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
CN201510882493.0A
Other languages
Chinese (zh)
Other versions
CN106844369A (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.)
Beijing Gridsum Technology Co Ltd
Original Assignee
Beijing Gridsum 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 Beijing Gridsum Technology Co Ltd filed Critical Beijing Gridsum Technology Co Ltd
Priority to CN201510882493.0A priority Critical patent/CN106844369B/en
Publication of CN106844369A publication Critical patent/CN106844369A/en
Application granted granted Critical
Publication of CN106844369B publication Critical patent/CN106844369B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

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
    • G06F16/2448Query languages for particular applications; for extensibility, e.g. user defined types
    • 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/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/289Object oriented databases
    • 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
    • G06F8/315Object-oriented languages

Abstract

The invention discloses a construction method and a construction device for a objectified SQL sentence, which solve the problem of high spelling error rate of the existing SQL sentence. The main technical scheme of the invention is as follows: responding to a structured object SQL command, and determining an object class template of a first level; the object class template of the first level comprises at least one first preset SQL object class; calling the at least one first preset SQL object class and determining the at least one first preset SQL object class; and when receiving the parameter corresponding to the first preset SQL object class, determining an object class template of a second level, wherein the object class template of the second level at least comprises a second preset SQL object class, and the logical relationship between the first preset SQL object class and the second preset SQL object class is determined according to SQL language attribute rules. The invention is mainly used for constructing standard SQL sentences.

Description

Objectification SQL sentence construction method and apparatus
Technical Field
The invention relates to the technical field of information, in particular to a method and a device for constructing a objectified Structured Query Language (SQL) statement.
Background
With the rapid development of information technology, most applications are more or less database-based for data storage and management. This process necessarily involves SQL (Structured Query Language) operations, however whatever data access framework is employed, such as Hibernate (object relational mapping framework for open source code), iBatis (persistent layer framework for Java and. NET based SQL mapping), etc., the construction of customized SQL statements is necessarily required as long as complex SQL processing and performance related optimizations are involved.
At present, the construction process of an SQL statement is presented in a character string mode, compilers of various languages cannot capture spelling errors of the SQL statement, the spelling errors of the SQL statement are always inevitable problems in the SQL construction process, the SQL statement can be found only when a program runs after errors occur, and if the business is complex, the positioning process is time-consuming, so that the efficiency of searching for the SQL error statement in the prior art is low.
Disclosure of Invention
In view of the above, the present invention has been made to provide a method and apparatus for constructing a objectified SQL statement that overcomes or at least partially solves the above-mentioned problems.
In order to achieve the purpose, the invention mainly provides the following technical scheme:
in one aspect, an embodiment of the present invention provides a method for constructing a objectified SQL statement, where the method includes:
responding to a structured object SQL command, and determining an object class template of a first level; the object class template of the first level comprises at least one first preset SQL object class;
calling the at least one first preset SQL object class and determining the at least one first preset SQL object class;
and when receiving the parameter corresponding to the first preset SQL object class, determining an object class template of a second level, wherein the object class template of the second level at least comprises a second preset SQL object class, and the logical relationship between the first preset SQL object class and the second preset SQL object class is determined according to SQL language attribute rules.
On the other hand, an embodiment of the present invention further provides a device for constructing a objectified SQL statement, where the device includes:
the response unit is used for responding to the structured objectification SQL command and determining an object class template of the first level; the object class template of the first level comprises at least one first preset SQL object class;
the calling unit is used for calling the at least one first preset SQL object class and determining the at least one first preset SQL object class;
and the determining unit is used for determining an object class template of a second hierarchy when receiving the parameter corresponding to the first preset SQL object class, wherein the object class template of the second hierarchy at least comprises a second preset SQL object class, and the logical relationship between the first preset SQL object class and the second preset SQL object class is determined according to SQL language attribute rules.
By the technical scheme, the technical scheme provided by the embodiment of the invention at least has the following advantages:
the embodiment of the invention provides a method and a device for constructing a objectified SQL statement, which respond to a command for constructing the objectified SQL and determine an object type template of a first level; the object class template of the first level comprises at least one first preset SQL object class; calling the at least one first preset SQL object class and determining the at least one first preset SQL object class; and when receiving the parameter corresponding to the first preset SQL object class, determining an object class template of a second level, wherein the object class template of the second level at least comprises a second preset SQL object class, and the logical relationship between the first preset SQL object class and the second preset SQL object class is determined according to SQL language attribute rules. Compared with the structured SQL sentences which are expressed in the form of character strings at present, the structured SQL sentences constructed by the method can avoid common spelling errors on the language level by quickly constructing the objectified SQL sentences based on the objectified SQL framework, and the constructed objectified SQL sentences have good maintainability and are more favorable for maintenance compared with large-scale character strings SQL sentences constructed based on the objectified SQL framework.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 is a flowchart of a method for constructing an objectified SQL statement according to an embodiment of the present invention;
FIG. 2 is a flow chart of another method for constructing a objectified SQL statement according to the embodiment of the present invention;
fig. 3 is a structural block diagram of an apparatus for constructing an objectified SQL statement according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
In order to make the advantages of the technical solutions of the present invention clearer, the present invention is described in detail below with reference to the accompanying drawings and examples.
The embodiment of the invention provides a method for constructing a objectified SQL statement, which comprises the following steps of:
s101, responding to a structured objectification SQL command, and determining an object class template of a first level.
The object class template of the first hierarchy includes a plurality of first preset SQL object classes, where the first preset SQL object classes are pre-configured according to rules of an SQL language, the first preset SQL object classes may be specifically written according to a first operation command in the SQL language, and the first operation command in the SQL language may specifically be SELECT, DELETE, UPDATE, CREATE, INSERT, DROP, and the like.
In the embodiment of the present invention, the structured objectification SQL command may specifically be input into a program editing interface to implement outputting an object class template of a first level, where the object template of the first level includes a plurality of first preset SQL classes, such as a SELECT class, a DELETE class, and an UPDATE class.
It should be noted that, the SQL object class in the objectified SQL statement is edited in advance, and in the embodiment of the present invention, the SQL statement may be classified by the SQL syntax, and divided into the following forms: the SQL clauses (Select, Where, join, GroupBy, etc.), operators, expressions, functions, SQL statements, predicates, table operations, set operations, etc. are not specifically limited in the embodiments of the present invention, and then classes of these objects are created, so that when a user inputs an object and then the SQL statements, these classes can be directly called, and then corresponding parameters are filled in these classes, and the structure of the objectified SQL statements can be completed.
S102, calling the at least one first preset SQL object class, and determining the at least one first preset SQL object class.
In the embodiment of the invention, when a first preset SQL object class selected by a client is received, the first preset SQL object class is called and determined, and then the first preset SQL object class selected by the client is displayed. It should be noted that one or more SQL object classes selected by the client, such as a SELECT class, a DELETE class, and an UPDATE class, may be received, and the embodiment of the present invention is not limited in particular.
For example, if the first preset SQL object class selected by the client is a SELECT class, it is shown that the SELECT class is specifically as follows:
SqlSession sesstion=new SqlSession(config);
ISqlExpression sqlExpression=
sesstion.Select(Metadata_Column_PERSON_AGE)
it should be noted that the PERSON _ AGE in the SELECT class in this example is a specific table name and field name input by the user side.
S103, when the parameters corresponding to the first preset SQL object class are received, determining an object class template of a second level.
The object class template of the second level at least comprises a second preset SQL object class, and the logical relationship between the first preset SQL object class and the second preset SQL object class is determined according to SQL language attribute rules.
Specifically, the logical relationship between the first preset SQL object class and the second preset SQL object class may be determined based on the logical order of the SQL language itself, for example, the SQL language execution format, the data object priority setting, and the like.
For the embodiment of the present invention, the parameter is mainly information describing the data attribute, and specifically may be a field information object and a table object; the parameter may also be an SQL condition setting parameter, a specific setting numerical parameter, or the like, and the embodiment of the present invention is not particularly limited.
For example, a conventionally spelled SQL statement "SELECT age FROM Person year < 16" may be represented by the following objected SQL statement:
SqlSession sesstion=new SqlSession(config);
ISqlExpression sqlExpression=
sesstion.Select(Metadata_Column_PERSON_AGE)
.From(Metadata_Table_PERSON)
.Where(new Predicate(Metadata_Column_PERSON_AGE
,Operators.LessThan,16));
it can be seen FROM this example that the above-mentioned objectified SQL statement can implement the function of the regular spelling SQL statement "SELECT age FROM Person word < 16", that is, the age field information with the age less than 16 is searched FROM Person table, the objectified SQL statement writes the regular SQL statement through the class in the programming language, and the written objectified structured objectified SQL statement is strictly performed according to SQL syntax and is consistent with the logic of the regular spelling SQL.
In the embodiment of the invention, because the writing of the SQL sentence is realized in a class mode, the compiler of the system can be effectively utilized to check the conventional spelling errors when writing the SQL sentence, and the system can automatically report the errors once the SQL spelling errors occur in the writing process, thereby fundamentally eliminating the problem of the SQL spelling errors based on character strings.
The embodiment of the invention provides a method for constructing an objectified SQL statement, which responds to an objectified SQL constructing command and determines an object type template of a first level; the object class template of the first level comprises at least one first preset SQL object class; calling the at least one first preset SQL object class and determining the at least one first preset SQL object class; and when receiving the parameter corresponding to the first preset SQL object class, determining an object class template of a second level, wherein the object class template of the second level at least comprises a second preset SQL object class, and the logical relationship between the first preset SQL object class and the second preset SQL object class is determined according to SQL language attribute rules. Compared with the structured SQL sentences which are expressed in the form of character strings at present, the structured SQL sentences constructed by the method can avoid common spelling errors on the language level by quickly constructing the objectified SQL sentences based on the objectified SQL framework, and the constructed objectified SQL sentences have good maintainability and are more favorable for maintenance compared with large-scale character strings SQL sentences constructed based on the objectified SQL framework.
The embodiment of the invention provides another objectification SQL statement construction method, as shown in FIG. 2, the method comprises the following steps:
s201, configuring SQL object classes corresponding to all terms in the SQL respectively.
Each term in SQL (Structured Query Language) is a statement formed in SQL, Where the statement formed in SQL may specifically be an operation command such as Select, Where, join, GroupBy, update, or some operation and expression in SQL statement, or some function, predicate, table operation, set operation, or the like, and the embodiments of the present invention are not limited specifically.
For the embodiment of the present invention, before configuring the SQL object classes corresponding to the respective terms in the SQL, the method further includes: according to the syntax rule sequence in the SQL, the terms in the SQL are divided into levels, wherein each level at least comprises one term, and the SQL term sequence relationship between the levels from high to low conforms to the logic sequence of the SQL language; the configuring the SQL object class corresponding to each term in the SQL respectively comprises: configuring SQL object classes corresponding to the words in the same level in the SQL respectively; and configuring corresponding object class templates for the SQL object classes of the same level.
S202, when receiving a structured objectification SQL command input by the client, outputting an object class template of a first level.
The object class template of the first hierarchy includes a plurality of first preset SQL object classes, where the first preset SQL object classes are pre-configured according to rules of an SQL language, the first preset SQL object classes may be specifically written according to a first operation command in the SQL language, and the first operation command in the SQL language may specifically be SELECT, DELETE, UPDATE, CREATE, INSERT, DROP, and the like.
In this embodiment of the present invention, the structured objectification SQL command may specifically be input into a program editing interface to implement outputting an object class template of a first level, where the object template of the first level includes a plurality of first preset SQL classes, such as a SELECT class SELECT, a DELETE class DELETE, and an UPDATE class UPDATE.
It should be noted that, the SQL object class in the objectified SQL statement is edited in advance, and in the embodiment of the present invention, the SQL statement may be classified by the SQL syntax, and divided into the following forms: the SQL clauses (Select, Where, join, GroupBy, etc.), operators, expressions, functions, SQL statements, predicates, table operations, set operations, etc. are not specifically limited in the embodiments of the present invention, and then classes of these objects are created, so that when a user inputs an object after the SQL statement, these classes can be directly called, and then corresponding parameters are filled in these classes, and the input of the objectified SQL statement can be completed.
S203, when the first preset SQL object class selected by the client is received, displaying the first preset SQL object class selected by the client.
In the embodiment of the invention, when a first preset SQL object class selected by a client is received, the first preset SQL object class selected by the client is displayed. It should be noted that one or more SQL object classes selected by the client, such as a SELECT class, a DELETE class, and an UPDATE class, may be received, and the embodiment of the present invention is not limited in particular.
In the embodiment of the invention, because the writing of the SQL sentence is realized in an object type mode, the compiler of the system can be effectively utilized to check the conventional spelling errors when writing the SQL sentence, and the system can automatically report the errors once the SQL spelling errors occur in the writing process, thereby fundamentally eliminating the problem of the SQL spelling errors based on character strings.
And S204, outputting an object class template of a second level when receiving the parameters which are input by the client and correspond to the first preset SQL object class.
The object class template of the second level at least comprises a second preset SQL object class, and it needs to be explained that the objectified SQL sentence constructed by the embodiment of the method is strictly carried out according to SQL grammar and is consistent with the logic of daily spelling SQL, so that the objectified SQL sentence represents the SQL sentence of the existing character string, and the spelling error in the objectified SQL sentence can be effectively detected by using a compiler in the system, thereby fundamentally eliminating the problem of the SQL spelling error based on the character string, and further improving the efficiency of searching the SQL error sentence by the invention.
For the embodiment of the present invention, the parameter is mainly information describing the data attribute, and specifically may be a field information object and a table object; the parameter may also be an SQL condition setting parameter, a specific setting numerical parameter, or the like, and the embodiment of the present invention is not particularly limited.
S205, judging whether the first preset SQL object class and the second preset SQL object class can be converted into SQL sentences or not.
In the embodiment of the present invention, if it is not possible to convert the first preset SQL object class and the second preset SQL object class into SQL statements, it is indicated that the structured objected SQL statements have no spelling errors. The constructor is different from the intelligent analysis construction device in the market, and is only responsible for translating the specified SQL object into the SQL sentence which is standard or suitable for a certain specific database according to the sequence of user organization.
For example: the comparison predicate in the predicate objectified SQL statement is described as follows:
sesstion.Where(
new ComparisonPredicate
(Metedata_Comlumn_PERSON_AGE,Operators.NotEqual,16))
and translating the objectified SQL statement, wherein the specific result of translation is Where age < 16.
It should be noted that, unlike the ORM (Object Relational Mapping), the present invention can automatically infer the SQL statement that the user wants to express according to the received objected SQL statement relationship, the structure of the SQL statement completely depends on the objected SQL statement input by the user, and a programmer in a qualified SQL field can completely write the SQL statement that can be described based on the SQL language itself using the objected SQL class; a programmer who initially participates in SQL can write out wrong logic expressions, which are completely allowed, and support that errors are generated during operation. In addition, the invention can support a specific database by providing a standard ISqlBuilder interface contract and matching with an ISqlProvider standard interface.
And S206a, if not, outputting SQL grammar error prompt information.
In the embodiment of the present invention, if the first preset SQL object class and the second preset SQL object class cannot be converted into SQL statements, SQL syntax error prompt information is output. The invention carries out syntax check on the SQL sentence during operation through the SQL constructor in the system, thereby being capable of rapidly positioning errors.
S206b, if yes, executing the SQL statement.
Step S206b is a parallel step of step S206a, and if the first preset SQL object class and the second preset SQL object class can be converted into SQL statements, the SQL statements are executed.
And S207b, recording the SQL sentences with execution errors.
In the embodiment of the invention, when the SQL statement is executed, the mapper can enable the system to know how to convert the field corresponding to the query into the attribute of the entity to be queried, the system can perform performance statistics on each SQL execution, and then record the SQL statement with the execution error, so as to facilitate subsequent optimization. Meanwhile, the SQL execution process with object errors is tracked, so that problems can be conveniently checked.
The embodiment of the invention provides another objectification SQL statement construction method, when receiving an objectification SQL command input by a client, outputting a first-level object class template, wherein the first-level object class template comprises a plurality of first preset SQL object classes; when a first preset SQL object class selected by a client is received, displaying the first preset SQL object class selected by the client; and when receiving a parameter which is input by a client and corresponds to the first preset SQL object class, outputting an object class template of a second level, wherein the object class template of the second level at least comprises a second preset SQL object class, and the sequential relation between the first preset SQL object class and the second preset SQL object class conforms to the logic sequence of the SQL language. Compared with the structured SQL sentences which are expressed in the form of character strings at present, the structured SQL sentences constructed by the method can avoid common spelling errors on the language level by quickly constructing the objectified SQL sentences based on the objectified SQL framework, and the constructed objectified SQL sentences have good maintainability and are more favorable for maintenance compared with large-scale character strings SQL sentences constructed based on the objectified SQL framework.
Further, an embodiment of the present invention provides an apparatus for constructing a objectified SQL statement, as shown in fig. 3, where the apparatus includes: a response unit 31, a retrieval unit 32 and a determination unit 33.
A response unit 31, configured to determine an object class template of a first level in response to constructing the objectified SQL command; the object class template of the first level comprises at least one first preset SQL object class.
The retrieving unit 32 is configured to retrieve the at least one first preset SQL object class, and determine the at least one first preset SQL object class.
The determining unit 33 is configured to determine an object class template of a second hierarchy when receiving a parameter corresponding to the first preset SQL object class, where the object class template of the second hierarchy at least includes a second preset SQL object class, and a logical relationship between the first preset SQL object class and the second preset SQL object class is determined according to SQL language attribute rules.
It should be noted that, for other corresponding descriptions of the functional units involved in the objectified SQL statement constructing apparatus provided in the embodiment of the present invention, reference may be made to corresponding descriptions of the method shown in fig. 1, which are not described herein again, but it should be clear that the apparatus in the embodiment can correspondingly implement all the contents in the foregoing method embodiments.
The embodiment of the invention provides a Structured Query Language (SQL) statement constructing device, which is used for outputting a first-level object class template when receiving a structured SQL command input by a client, wherein the first-level object class template comprises a plurality of first preset SQL object classes; when a first preset SQL object class selected by a client is received, displaying the first preset SQL object class selected by the client; and when receiving a parameter which is input by a client and corresponds to the first preset SQL object class, outputting an object class template of a second level, wherein the object class template of the second level at least comprises a second preset SQL object class, and the sequential relation between the first preset SQL object class and the second preset SQL object class conforms to the logic sequence of the SQL language. Compared with the structured SQL sentences which are expressed in the form of character strings at present, the structured SQL sentences constructed by the method can avoid common spelling errors on the language level by quickly constructing the objectified SQL sentences based on the objectified SQL framework, and the constructed objectified SQL sentences have good maintainability and are more favorable for maintenance compared with large-scale character strings SQL sentences constructed based on the objectified SQL framework.
Further, an embodiment of the present invention provides another apparatus for constructing a objectified SQL statement, which includes:
and the output unit is used for outputting an object class template of a first level when receiving a structured object SQL command input by a client, wherein the object class template of the first level comprises at least one first preset SQL object class.
And the display unit is used for displaying the first preset SQL object class selected by the client when the first preset SQL object class selected by the client is received.
The output unit is further configured to output an object class template of a second hierarchy when receiving a parameter corresponding to the first preset SQL object class input by the client, where the object class template of the second hierarchy at least includes a second preset SQL object class, and a sequential relationship between the first preset SQL object class and the second preset SQL object class conforms to a logical order of the SQL language itself.
Further, the apparatus further comprises:
and the configuration unit is used for configuring the SQL object classes corresponding to all the terms in the SQL respectively.
Further the apparatus further comprises: and dividing the unit.
The dividing unit is used for dividing the terms in the SQL into levels according to the grammar rule sequence in the SQL, wherein each level at least comprises one term, and the SQL term sequence relation between the levels from high to low conforms to the logic sequence of the SQL language.
The configuration unit is specifically configured to configure SQL object classes corresponding to the terms in the same hierarchy in the SQL.
The configuration unit is specifically configured to configure the corresponding object class template for the SQL object classes of the same hierarchy.
Further, the apparatus further comprises:
the judging unit is used for judging whether the first preset SQL object class and the second preset SQL object class can be converted into SQL sentences or not.
The output unit is further configured to output SQL logic error prompt information if the first preset SQL object class and the second preset SQL object class cannot be converted into SQL statements.
Further, the apparatus further comprises:
and the execution unit is used for executing the SQL statement if the first preset SQL object class and the second preset SQL object class can be converted into the SQL statement.
And the recording unit is used for recording the SQL sentences with the execution errors.
It should be noted that, for other corresponding descriptions of the functional units involved in the objectified SQL statement constructing apparatus provided in the embodiment of the present invention, reference may be made to corresponding descriptions of the method shown in fig. 2, which are not described herein again, but it should be clear that the apparatus in the embodiment can correspondingly implement all the contents in the foregoing method embodiments.
The embodiment of the invention provides a Structured Query Language (SQL) statement constructing device, which is used for outputting a first-level object class template when receiving a structured SQL command input by a client, wherein the first-level object class template comprises a plurality of first preset SQL object classes; when a first preset SQL object class selected by a client is received, displaying the first preset SQL object class selected by the client; and when receiving a parameter which is input by a client and corresponds to the first preset SQL object class, outputting an object class template of a second level, wherein the object class template of the second level at least comprises a second preset SQL object class, and the sequential relation between the first preset SQL object class and the second preset SQL object class conforms to the logic sequence of the SQL language. Compared with the structured SQL sentences which are expressed in the form of character strings at present, the structured SQL sentences constructed by the method can avoid common spelling errors on the language level by quickly constructing the objectified SQL sentences based on the objectified SQL framework, and the constructed objectified SQL sentences have good maintainability and are more favorable for maintenance compared with large-scale character strings SQL sentences constructed based on the objectified SQL framework.
The objectification SQL sentence construction device comprises a processor and a memory, wherein the output unit, the configuration unit, the display unit, the dividing unit, the judging unit, the execution unit, the recording unit and the like are stored in the memory as program units, and the processor executes the program units stored in the memory to realize corresponding functions.
The processor comprises a kernel, and the kernel calls the corresponding program unit from the memory. The kernel can be set to be one or more, and the efficiency of searching the SQL error statement is improved by adjusting the kernel parameters.
The memory may include volatile memory in a computer readable medium, Random Access Memory (RAM) and/or nonvolatile memory such as Read Only Memory (ROM) or flash memory (flash RAM), and the memory includes at least one memory chip.
The present application further provides a computer program product adapted to perform program code for initializing the following method steps when executed on a data processing device: when receiving a structured object SQL command input by a client, outputting an object class template of a first level, wherein the object class template of the first level comprises a plurality of first preset SQL object classes; when a first preset SQL object class selected by a client is received, displaying the first preset SQL object class selected by the client; and when receiving a parameter which is input by a client and corresponds to the first preset SQL object class, outputting an object class template of a second level, wherein the object class template of the second level at least comprises a second preset SQL object class, and the sequential relation between the first preset SQL object class and the second preset SQL object class conforms to the logic sequence of the SQL language.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). The memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
The above are merely examples of the present application and are not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.

Claims (6)

1. A method for constructing a objectified SQL statement, which is characterized by comprising the following steps:
according to a syntax rule sequence in SQL, dividing the terms in SQL into levels, wherein each level at least comprises one term, and the SQL term sequence relationship between the levels from high to low conforms to the logic sequence of the SQL language;
configuring SQL object classes corresponding to the words in the same level in the SQL respectively;
configuring corresponding object class templates for SQL object classes of the same level;
responding to a structured object SQL command, and determining an object class template of a first level; the object class template of the first level comprises at least one first preset SQL object class; the first preset SQL object class is classified through SQL grammar, SQL sentences are divided into SQL clauses, operators, expressions, functions, SQL sentences, predicates, table operation and set operation, and then classes of the objects are created;
calling the at least one first preset SQL object class and determining the at least one first preset SQL object class;
when receiving a parameter corresponding to the first preset SQL object class, determining an object class template of a second level, wherein the object class template of the second level at least comprises a second preset SQL object class, and the logical relationship between the first preset SQL object class and the second preset SQL object class is determined according to SQL language attribute rules;
judging whether the first preset SQL object class and the second preset SQL object class can be converted into SQL sentences or not;
if not, outputting SQL logic error prompt information.
2. The method according to claim 1, wherein after determining whether the first preset SQL object class and the second preset SQL object class can be converted into SQL statements, the method further comprises:
if yes, executing the SQL statement;
and recording SQL statements with execution errors.
3. An apparatus for constructing a objectified SQL statement, comprising:
the response unit is used for responding to the structured objectification SQL command and determining an object class template of the first level; the object class template of the first level comprises at least one first preset SQL object class; the first preset SQL object class is classified through SQL grammar, specifically, SQL sentences are divided into SQL clauses, operators, expressions, functions, SQL sentences, predicates, table operation and set operation, and then classes of the objects are created;
the calling unit is used for calling the at least one first preset SQL object class and determining the at least one first preset SQL object class;
the determining unit is used for determining an object class template of a second hierarchy when receiving the parameter corresponding to the first preset SQL object class, wherein the object class template of the second hierarchy at least comprises a second preset SQL object class, and the logical relationship between the first preset SQL object class and the second preset SQL object class is determined according to SQL language attribute rules;
wherein the apparatus further comprises: dividing the cells;
the dividing unit is used for dividing the terms in the SQL into levels according to the grammar rule sequence in the SQL, wherein each level at least comprises one term, and the SQL term sequence relation between the levels from high to low conforms to the logic sequence of the SQL language;
the configuration unit is specifically used for configuring SQL object classes corresponding to the terms in the same level in the SQL respectively;
the configuration unit is specifically used for configuring corresponding object class templates for the SQL object classes of the same level;
the judging unit is used for judging whether the first preset SQL object class and the second preset SQL object class can be converted into SQL sentences or not;
and the output unit is used for outputting SQL logic error prompt information if the first preset SQL object class and the second preset SQL object class cannot be converted into SQL statements.
4. The apparatus of claim 3, further comprising:
the execution unit is used for executing the SQL statement if the first preset SQL object class and the second preset SQL object class can be converted into the SQL statement;
and the recording unit is used for recording the SQL sentences with the execution errors.
5. A storage medium, characterized in that the storage medium comprises a stored program, and when the program runs, the storage medium is controlled by a device to execute the objectified SQL statement construction method according to any one of claims 1 to 2.
6. A processor, configured to run a program, wherein the program runtime performs the objectified SQL statement construction method of any of claims 1 to 2.
CN201510882493.0A 2015-12-03 2015-12-03 Objectification SQL sentence construction method and apparatus Active CN106844369B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201510882493.0A CN106844369B (en) 2015-12-03 2015-12-03 Objectification SQL sentence construction method and apparatus

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201510882493.0A CN106844369B (en) 2015-12-03 2015-12-03 Objectification SQL sentence construction method and apparatus

Publications (2)

Publication Number Publication Date
CN106844369A CN106844369A (en) 2017-06-13
CN106844369B true CN106844369B (en) 2020-12-29

Family

ID=59149691

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201510882493.0A Active CN106844369B (en) 2015-12-03 2015-12-03 Objectification SQL sentence construction method and apparatus

Country Status (1)

Country Link
CN (1) CN106844369B (en)

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107622080B (en) * 2017-07-28 2020-10-30 创新先进技术有限公司 Data processing method and equipment
CN110020072A (en) * 2017-09-30 2019-07-16 北京国双科技有限公司 A kind of data processing method and terminal based on Elasticsearch
CN109508182B (en) * 2018-09-18 2022-05-17 广州虎牙信息科技有限公司 Method, server and computer storage medium for fast generating instruction
CN109522324A (en) * 2018-11-02 2019-03-26 平安医疗健康管理股份有限公司 A kind of SQL scenario generation method, device and computer equipment
CN111737233A (en) * 2020-06-24 2020-10-02 浙江大华技术股份有限公司 Data monitoring method and device
CN117251473B (en) * 2023-11-20 2024-03-15 摩斯智联科技有限公司 Vehicle data query analysis method, system, device and storage medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5905982A (en) * 1997-04-04 1999-05-18 International Business Machines Corporation Handling null values in SQL queries over object-oriented data
CN103617273A (en) * 2013-12-05 2014-03-05 用友软件股份有限公司 SOL script objectification method and system
CN103914290A (en) * 2012-12-31 2014-07-09 杭州勒卡斯广告策划有限公司 Operating command processing method and device

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5905982A (en) * 1997-04-04 1999-05-18 International Business Machines Corporation Handling null values in SQL queries over object-oriented data
CN103914290A (en) * 2012-12-31 2014-07-09 杭州勒卡斯广告策划有限公司 Operating command processing method and device
CN103617273A (en) * 2013-12-05 2014-03-05 用友软件股份有限公司 SOL script objectification method and system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
MyBatis 3用户指南;srtillery1029;《百度文库:https://wenku.baidu.com/view/37a0990a76c66137ee06195d.html?rec_flag=default&sxts=1566807365422》;20120218;第1-56页 *

Also Published As

Publication number Publication date
CN106844369A (en) 2017-06-13

Similar Documents

Publication Publication Date Title
CN106844369B (en) Objectification SQL sentence construction method and apparatus
CN107491485B (en) Method for generating execution plan, plan unit device and distributed NewSQ L database system
US20170083573A1 (en) Multi-query optimization
US7694278B2 (en) Data cube script development and debugging systems and methodologies
CN107622080B (en) Data processing method and equipment
US9009175B2 (en) System and method for database migration and validation
CN106951231B (en) Computer software development method and device
CN106354483B (en) Data processing method and device and electronic equipment
CN110555035A (en) Method and device for optimizing query statement
US10423416B2 (en) Automatic creation of macro-services
CN114625732A (en) Query method and system based on Structured Query Language (SQL)
US9104724B2 (en) Dynamic bridging of application and data servers
WO2021253641A1 (en) Shading language translation method
CN113434533A (en) Data tracing tool construction method, data processing method, device and equipment
CN109657803A (en) The building of machine learning model
CN114297204A (en) Data storage and retrieval method and device for heterogeneous data source
CN105867886B (en) Method and device for writing table
US20190026081A1 (en) Method and device for generating code assistance information
CN112182637A (en) Safety control system, method, device and storage medium
CN108241620B (en) Query script generation method and device
CN109376154B (en) Data reading and writing method and data reading and writing system
CN113448942B (en) Database access method, device, equipment and storage medium
US9910616B2 (en) Dynamic data access
CN112181951B (en) Heterogeneous database data migration method, device and equipment
CN114116773A (en) Structured Query Language (SQL) text auditing method and device

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
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 100083 No. 401, 4th Floor, Haitai Building, 229 North Fourth Ring Road, Haidian District, Beijing

Applicant after: Beijing Guoshuang Technology Co.,Ltd.

Address before: 100086 Cuigong Hotel, 76 Zhichun Road, Shuangyushu District, Haidian District, Beijing

Applicant before: Beijing Guoshuang Technology Co.,Ltd.

GR01 Patent grant
GR01 Patent grant