CN110019266B - SQL statement generation method and device - Google Patents

SQL statement generation method and device Download PDF

Info

Publication number
CN110019266B
CN110019266B CN201711052564.XA CN201711052564A CN110019266B CN 110019266 B CN110019266 B CN 110019266B CN 201711052564 A CN201711052564 A CN 201711052564A CN 110019266 B CN110019266 B CN 110019266B
Authority
CN
China
Prior art keywords
modified
attribute
attribute value
changed
sql statement
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
CN201711052564.XA
Other languages
Chinese (zh)
Other versions
CN110019266A (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 CN201711052564.XA priority Critical patent/CN110019266B/en
Publication of CN110019266A publication Critical patent/CN110019266A/en
Application granted granted Critical
Publication of CN110019266B publication Critical patent/CN110019266B/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/23Updating
    • G06F16/235Update request formulation
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Mathematical Physics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method for generating an SQL statement, which comprises the steps of obtaining an object to be modified, each attribute of the object to be modified and an attribute value of each attribute; creating a snapshot of the object to be modified, detecting each attribute value of the modified object based on snapshot detection of the object to be modified, and determining the changed attribute in the object to be modified and the attribute value of the changed attribute; and generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute, wherein the SQL statement only relates to the changed attribute in the object to be modified, so that the SQL statement is simple, and the problem that the modification result submitted first is covered by the modification result submitted later can be avoided under the concurrent condition.

Description

SQL statement generation method and device
Technical Field
The invention relates to the technical field of databases, in particular to a method and a device for generating SQL statements.
Background
Object Relational Mapping (ORM) is a programming technique for implementing conversion between data of different types of systems in an Object-oriented programming language.
The ORM framework is generally used for mapping between database models and objects used in a program, and is characterized in that: after the object is modified in the program, the ORM automatically generates a corresponding SQL statement and submits the generated SQL statement to the database.
Taking the object model "employee" as an example, the "employee" includes attributes: the name, age and work location correspond to a table in the database, the table includes a primary key id, and 5 columns of name, age and work location, and it is assumed that there is one employee a, id is 10, name is xiaoming, age is 24, place is beijing. The user edits the personal data of employee a, changes the age to 25, and submits the data.
The conventional ORM framework first obtains information of employee a, generates an object, as shown in fig. 1-a, and stores corresponding name, age, and location attributes as attributes of the object. When modified, the traditional ORM framework generates the following SQL statements according to the values of the attributes of the object: "update employee set name ═ xiaoming, age ═ 25, place ═ Beijing where id ═ 10", and submit the modified SQL statement to the database. The modified results are shown in fig. 1-b. It can be seen that the traditional ORM framework does not determine which fields are actually modified, but adds all the attributes of the object to the SQL statement, which results in a lengthy SQL statement.
And, assuming that another user also edited the data of employee a at this time, the modified object is still the original object, as shown in fig. 2-a. If the user changes the place attribute of employee a to shanghai, the ORM framework will generate the following SQL statement: "update employee set name ═ xiaoming, age ═ 24, place ═ shanghaiwhere id ═ 10". At this time, the result after the modified SQL statement is submitted is shown in FIG. 2-b. Obviously, the previous modification of employee a by the previous user is covered, in which case even if the corresponding row is not locked during the modification, the later submission still covers the results of the previous modification, and the employee is 24 at age and has a shanghai location in the database.
In summary, when an object is modified by an existing ORM framework, a generated SQL statement is too long, and a problem that a modification result submitted first is covered by a modification result submitted later is easily caused.
Disclosure of Invention
In view of the above, the present invention is proposed to provide a method and apparatus for generating an SQL statement that overcomes or at least partially solves the above-mentioned problems.
In order to achieve the above purpose, the invention provides the following specific technical scheme:
a method for generating SQL statements comprises the following steps:
acquiring an object to be modified, each attribute of the object to be modified and an attribute value of each attribute;
creating a snapshot of the object to be modified;
when a user modifies the object to be modified to obtain a modified object, acquiring the modified object and each attribute value of the modified object;
detecting each attribute value of the modified object according to each attribute value recorded in the snapshot of the object to be modified, and determining the changed attribute in the object to be modified and the attribute value of the changed attribute;
and generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute.
Preferably, after the obtaining the object to be modified, each attribute of the object to be modified, and the attribute value of each attribute, the method further includes:
traversing all attributes in the object to be modified, and judging whether variable attributes exist in the object to be modified;
if yes, the snapshot of the object to be modified is created;
if not, the object to be modified is judged to be incapable of being modified.
Preferably, the creating the snapshot of the object to be modified includes:
and deeply copying the attribute values of all the attributes in the object to be modified to generate a snapshot of the object to be modified.
Preferably, the detecting, according to each attribute value recorded in the snapshot of the object to be modified, each attribute value of the modified object, and determining the changed attribute in the object to be modified and the attribute value of the changed attribute include:
traversing all attributes of the modified object to obtain all variable attributes of the modified object;
and sequentially judging whether the attribute value of each variable attribute of the modified object is changed compared with the corresponding attribute value recorded in the snapshot to obtain the changed attribute in the object to be modified and the attribute value of the changed attribute.
Preferably, after the generating the SQL statement for modifying the object to be modified, the method further includes:
and submitting the SQL sentences for modifying the objects to be modified to a database.
An apparatus for generating an SQL statement, comprising:
the device comprises a first acquisition unit, a second acquisition unit and a processing unit, wherein the first acquisition unit is used for acquiring an object to be modified, each attribute of the object to be modified and an attribute value of each attribute;
the creating unit is used for creating a snapshot of the object to be modified;
the second obtaining unit is used for obtaining the modified object and each attribute value of the modified object when a user modifies the object to be modified to obtain the modified object;
the detection unit is used for detecting each attribute value of the modified object according to each attribute value recorded in the snapshot of the object to be modified, and determining the changed attribute in the object to be modified and the attribute value of the changed attribute;
and the generating unit is used for generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute.
Preferably, the detection unit includes:
the traversal subunit is configured to traverse all the attributes of the modified object to obtain all the variable attributes of the modified object;
and the judging subunit is used for sequentially judging whether the attribute value of each variable attribute of the modified object is changed compared with the corresponding attribute value recorded in the snapshot, so as to obtain the changed attribute in the object to be modified and the attribute value of the changed attribute.
Preferably, the apparatus further comprises:
and the submitting unit is used for submitting the SQL sentences for modifying the objects to be modified to a database.
A storage medium including a stored program,
and when the program runs, controlling the device on which the storage medium is located to execute the SQL statement generation method.
A processor for running a program,
wherein the program executes the generation method of the SQL statement in any one of the above operations.
By means of the technical scheme, the method for generating the SQL statement provided by the invention obtains the object to be modified, each attribute of the object to be modified and the attribute value of each attribute; creating a snapshot of the object to be modified, detecting each attribute value of the modified object based on snapshot detection of the object to be modified, and determining the changed attribute in the object to be modified and the attribute value of the changed attribute; and generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute, wherein the SQL statement only relates to the changed attribute in the object to be modified, so that the SQL statement is simple, and the problem that the modification result submitted first is covered by the modification result submitted later can be avoided under the concurrent condition.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
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-a is a diagram of an object model before first modification in the background art;
1-b show a diagram of an object model after a first modification in the background art;
FIG. 2-a is a diagram of an object model before a second modification in the background art;
FIG. 2-b is a diagram illustrating an object model after a second modification in the prior art;
FIG. 3 is a flow chart of a method for generating an SQL statement disclosed in the embodiment of the invention;
FIG. 4-a is a diagram illustrating a snapshot of a first modification of an object model to be modified and an object to be modified disclosed in an embodiment of the present invention;
4-b illustrate a snapshot of the first modified object model and the object to be modified disclosed in embodiments of the present invention;
FIG. 5-a is a diagram illustrating a snapshot of a second modification of an object model to be modified and an object to be modified disclosed in the embodiments of the present invention;
5-b illustrate a snapshot of the second modified object model and the object to be modified disclosed in embodiments of the present invention;
FIG. 6 is a flow chart of another SQL statement generation method disclosed in the embodiments of the present invention;
fig. 7 shows a schematic structural diagram of a generating device of an SQL statement disclosed in the 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.
Referring to fig. 3, fig. 3 is a flowchart of a method for generating an SQL statement disclosed in this embodiment, which specifically includes the following steps:
s101: acquiring an object to be modified, each attribute of the object to be modified and an attribute value of each attribute;
an object here is a data structure, the object comprising a plurality of attributes, each attribute having an attribute value. For example: the "employee" is a target, and has attributes such as name, age, and work place, with the attribute value of name being xiaoming, the attribute value of age being 24, and the attribute value of work place being beijing.
The object to be modified is an object which needs to be modified by a user.
S102: creating a snapshot of the object to be modified;
specifically, the attribute values of all the attributes in the object to be modified are deeply copied, and a snapshot of the object to be modified is generated.
The snapshot is created when the object to be modified is obtained, whether the object to be modified is modified or not is followed, the snapshot of the object to be modified is kept unchanged, and after the SQL statement for modifying the object to be modified is submitted to the database, the snapshot of the object to be modified is automatically deleted.
S103: when a user modifies the object to be modified to obtain a modified object, acquiring the modified object and each attribute value of the modified object;
after the user modifies the object to be modified, the modification of the object to be modified is submitted to the database, but the modification of the object to be modified cannot be directly submitted to the database, and only a medium such as an ORM framework and the like is needed to generate a corresponding SQL statement according to the modified object, so that the SQL statement can be successfully submitted to the database.
S104: detecting each attribute value of the modified object according to each attribute value recorded in the snapshot of the object to be modified, and determining the changed attribute in the object to be modified and the attribute value of the changed attribute;
s105: and generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute.
It is understood that the generated SQL statement for modifying the object to be modified only relates to the changed attribute.
For further explanation of the method for generating an SQL statement disclosed in this embodiment, taking an object "employee" in the background art as an example, please refer to fig. 4-a when acquiring an object to be modified, where fig. 4-a is a snapshot of an object model to be modified and the object to be modified, and attributes in the snapshot are added' to distinguish from attributes of the object to be modified. And when the user modifies the object to be modified and submits the modification to the database, comparing the snapshot with the object attribute. As can be seen in this example, age and age' are not equal, and if they are the same, the following SQL statement is generated: "update employee set 25where id 10". After the database is submitted, the final result is shown in fig. 4-b, and it can be seen that the SQL statement only contains the changed attributes, which shortens the length of the SQL statement.
Assuming that another user modifies the location attribute of the "employee", wherein the object model to be modified and the snapshot of the object to be modified are shown in fig. 5-a, after the user modifies the object to be modified and submits the modification to the database, the snapshots are compared in the same way, the place is not equal to the place', and the generated SQL statement is: "update employee set place ═ sharghaiwhere id ═ 10". After the database is submitted, the final result is shown in fig. 5-b, and it can be seen that the statement only updates the place value, even if the statement is executed concurrently with the above age-updating statement (whether or not there is a lock), and the last data in the database is correct, the age is 25, and the location is shanghai, so as to avoid the problem that the modification result submitted first is covered by the modification result submitted later.
The embodiment discloses a method for generating an SQL statement, which comprises the steps of obtaining an object to be modified, each attribute of the object to be modified and an attribute value of each attribute; creating a snapshot of the object to be modified, detecting each attribute value of the modified object based on snapshot detection of the object to be modified, and determining the changed attribute in the object to be modified and the attribute value of the changed attribute; and generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute, wherein the SQL statement only relates to the changed attribute in the object to be modified, so that the SQL statement is simple, and the problem that the modification result submitted first is covered by the modification result submitted later can be avoided under the concurrent condition.
Referring to fig. 6, fig. 6 is a flowchart of another method for generating an SQL statement disclosed in this embodiment, which specifically includes the following steps:
s201: acquiring an object to be modified, each attribute of the object to be modified and an attribute value of each attribute;
s202: traversing all attributes in the object to be modified, and judging whether variable attributes exist in the object to be modified; if not, executing S203, if yes, executing S204;
s203: and judging that the object to be modified cannot be modified.
It can be understood that the object to be modified can be modified only when the variable attribute exists in the object to be modified, and when the variable attribute does not exist in the object to be modified, and it is determined that the object to be modified cannot be modified, there are no steps of creating a snapshot of the object to be modified, and so on, thereby avoiding resource waste caused by creating a snapshot when the object cannot be modified.
S204: creating a snapshot of the object to be modified;
s205: when a user modifies the object to be modified to obtain a modified object, acquiring the modified object and each attribute value of the modified object;
s206: detecting each attribute value of the modified object according to each attribute value recorded in the snapshot of the object to be modified, and determining the changed attribute in the object to be modified and the attribute value of the changed attribute;
s207: and generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute.
Preferably, the specific implementation process of S206 is as follows:
traversing all attributes of the modified object to obtain all variable attributes of the modified object;
and sequentially judging whether the attribute value of each variable attribute of the modified object is changed compared with the corresponding attribute value recorded in the snapshot to obtain the changed attribute in the object to be modified and the attribute value of the changed attribute.
All the variable attributes of the modified object are obtained by traversing all the attributes of the modified object, and then whether the variable attributes change or not is judged, so that the judgment of each attribute of the modified object is avoided, and the efficiency of determining the changed attributes in the object to be modified is improved.
Referring to fig. 7, the method for generating an SQL statement disclosed in the foregoing embodiment correspondingly discloses a device for generating an SQL statement, which specifically includes:
a first obtaining unit 101, configured to obtain an object to be modified, each attribute of the object to be modified, and an attribute value of each attribute;
a creating unit 102, configured to create a snapshot of the object to be modified;
a second obtaining unit 103, configured to obtain, when a user modifies the object to be modified to obtain a modified object, the modified object and each attribute value of the modified object;
a detecting unit 104, configured to detect each attribute value of the modified object according to each attribute value recorded in the snapshot of the object to be modified, and determine a changed attribute in the object to be modified and an attribute value of the changed attribute;
the generating unit 105 is configured to generate an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute.
Preferably, the detection unit 104 includes:
the traversal subunit is configured to traverse all the attributes of the modified object to obtain all the variable attributes of the modified object;
and the judging subunit is used for sequentially judging whether the attribute value of each variable attribute of the modified object is changed compared with the corresponding attribute value recorded in the snapshot, so as to obtain the changed attribute in the object to be modified and the attribute value of the changed attribute.
Preferably, the apparatus further comprises:
and the submitting unit is used for submitting the SQL sentences for modifying the objects to be modified to a database.
The embodiment discloses a generating device of an SQL statement, which is used for acquiring an object to be modified, each attribute of the object to be modified and an attribute value of each attribute; creating a snapshot of the object to be modified, detecting each attribute value of the modified object based on snapshot detection of the object to be modified, and determining the changed attribute in the object to be modified and the attribute value of the changed attribute; and generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute, wherein the SQL statement only relates to the changed attribute in the object to be modified, so that the SQL statement is simple, and the problem that the modification result submitted first is covered by the modification result submitted later can be avoided under the concurrent condition.
The SQL sentence generating device comprises a processor and a memory, wherein the first acquiring unit, the creating unit, the second acquiring unit, the detecting unit, the generating 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 accuracy of generating the SQL statement is improved by adjusting the parameters of the kernel.
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.
An embodiment of the present invention provides a storage medium, on which a program is stored, and when the program is executed by a processor, the method for generating the SQL statement is implemented.
The embodiment of the invention provides a processor, which is used for running a program, wherein the generation method of the SQL statement is executed when the program runs.
The embodiment of the invention provides equipment, which comprises a processor, a memory and a program which is stored on the memory and can run on the processor, wherein the processor executes the program and realizes the following steps:
acquiring an object to be modified, each attribute of the object to be modified and an attribute value of each attribute;
creating a snapshot of the object to be modified;
when a user modifies the object to be modified to obtain a modified object, acquiring the modified object and each attribute value of the modified object;
detecting each attribute value of the modified object according to each attribute value recorded in the snapshot of the object to be modified, and determining the changed attribute in the object to be modified and the attribute value of the changed attribute;
and generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute.
Further, after the obtaining the object to be modified, each attribute of the object to be modified, and the attribute value of each attribute, the method further includes:
traversing all attributes in the object to be modified, and judging whether variable attributes exist in the object to be modified;
if yes, the snapshot of the object to be modified is created;
if not, the object to be modified is judged to be incapable of being modified.
Further, the creating a snapshot of the object to be modified includes:
and deeply copying the attribute values of all the attributes in the object to be modified to generate a snapshot of the object to be modified.
Further, the detecting each attribute value of the modified object according to each attribute value recorded in the snapshot of the object to be modified, and determining the changed attribute of the object to be modified and the attribute value of the changed attribute, includes:
traversing all attributes of the modified object to obtain all variable attributes of the modified object;
and sequentially judging whether the attribute value of each variable attribute of the modified object is changed compared with the corresponding attribute value recorded in the snapshot to obtain the changed attribute in the object to be modified and the attribute value of the changed attribute.
Further, after the generating the SQL statement for modifying the object to be modified, the method further includes:
and submitting the SQL sentences for modifying the objects to be modified to a database.
The device herein may be a server, a PC, a PAD, a mobile phone, etc.
The present application further provides a computer program product adapted to perform a program for initializing the following method steps when executed on a data processing device:
acquiring an object to be modified, each attribute of the object to be modified and an attribute value of each attribute;
creating a snapshot of the object to be modified;
when a user modifies the object to be modified to obtain a modified object, acquiring the modified object and each attribute value of the modified object;
detecting each attribute value of the modified object according to each attribute value recorded in the snapshot of the object to be modified, and determining the changed attribute in the object to be modified and the attribute value of the changed attribute;
and generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute.
Further, after the obtaining the object to be modified, each attribute of the object to be modified, and the attribute value of each attribute, the method further includes:
traversing all attributes in the object to be modified, and judging whether variable attributes exist in the object to be modified;
if yes, the snapshot of the object to be modified is created;
if not, the object to be modified is judged to be incapable of being modified.
Further, the creating a snapshot of the object to be modified includes:
and deeply copying the attribute values of all the attributes in the object to be modified to generate a snapshot of the object to be modified.
Further, the detecting each attribute value of the modified object according to each attribute value recorded in the snapshot of the object to be modified, and determining the changed attribute of the object to be modified and the attribute value of the changed attribute, includes:
traversing all attributes of the modified object to obtain all variable attributes of the modified object;
and sequentially judging whether the attribute value of each variable attribute of the modified object is changed compared with the corresponding attribute value recorded in the snapshot to obtain the changed attribute in the object to be modified and the attribute value of the changed attribute.
Further, after the generating the SQL statement for modifying the object to be modified, the method further includes:
and submitting the SQL sentences for modifying the objects to be modified to a database.
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.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus 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 apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in the process, method, article, or apparatus that comprises the element.
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 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 (8)

1. A method for generating an SQL statement is characterized by comprising the following steps:
acquiring an object to be modified, each attribute of the object to be modified and an attribute value of each attribute;
creating a snapshot of the object to be modified;
when a user modifies the object to be modified to obtain a modified object, acquiring the modified object and each attribute value of the modified object;
traversing all attributes of the modified object to obtain all variable attributes of the modified object;
sequentially judging whether the attribute value of each variable attribute of the modified object is changed compared with the corresponding attribute value recorded in the snapshot to obtain the changed attribute in the object to be modified and the attribute value of the changed attribute;
and generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute.
2. The method according to claim 1, wherein after the obtaining of the object to be modified, each attribute of the object to be modified, and the attribute value of each attribute, the method further comprises:
traversing all attributes in the object to be modified, and judging whether variable attributes exist in the object to be modified;
if yes, the snapshot of the object to be modified is created;
if not, the object to be modified is judged to be incapable of being modified.
3. The method of claim 1, wherein creating the snapshot of the object to be modified comprises:
and deeply copying the attribute values of all the attributes in the object to be modified to generate a snapshot of the object to be modified.
4. The method according to claim 1, wherein after said generating the SQL statement that modifies the object to be modified, the method further comprises:
and submitting the SQL sentences for modifying the objects to be modified to a database.
5. An apparatus for generating an SQL statement, comprising:
the device comprises a first acquisition unit, a second acquisition unit and a processing unit, wherein the first acquisition unit is used for acquiring an object to be modified, each attribute of the object to be modified and an attribute value of each attribute;
the creating unit is used for creating a snapshot of the object to be modified;
the second obtaining unit is used for obtaining the modified object and each attribute value of the modified object when a user modifies the object to be modified to obtain the modified object;
the traversal subunit is configured to traverse all the attributes of the modified object to obtain all the variable attributes of the modified object;
a judging subunit, configured to sequentially judge whether an attribute value of each variable attribute of the modified object changes compared with a corresponding attribute value recorded in the snapshot, so as to obtain a changed attribute in the object to be modified and an attribute value of the changed attribute;
and the generating unit is used for generating an SQL statement for modifying the object to be modified according to the changed attribute in the object to be modified and the attribute value of the changed attribute.
6. The apparatus of claim 5, further comprising:
and the submitting unit is used for submitting the SQL sentences for modifying the objects to be modified to a database.
7. A storage medium characterized in that the storage medium includes a stored program,
wherein, when the program runs, the device of the storage medium is controlled to execute the SQL statement generation method according to any one of claims 1-4.
8. A processor, for running a program,
wherein the program runtime performs the generation method of the SQL statement according to any of claims 1-4.
CN201711052564.XA 2017-10-30 2017-10-30 SQL statement generation method and device Active CN110019266B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711052564.XA CN110019266B (en) 2017-10-30 2017-10-30 SQL statement generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711052564.XA CN110019266B (en) 2017-10-30 2017-10-30 SQL statement generation method and device

Publications (2)

Publication Number Publication Date
CN110019266A CN110019266A (en) 2019-07-16
CN110019266B true CN110019266B (en) 2021-06-29

Family

ID=67186730

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711052564.XA Active CN110019266B (en) 2017-10-30 2017-10-30 SQL statement generation method and device

Country Status (1)

Country Link
CN (1) CN110019266B (en)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7296028B1 (en) * 2004-04-30 2007-11-13 Sap Ag System and method for mapping object-oriented program code to a database layer
CN101183387A (en) * 2007-12-14 2008-05-21 沈阳东软软件股份有限公司 Increment data capturing method and system
CN102841889A (en) * 2011-06-20 2012-12-26 中兴通讯股份有限公司 Method and device for achieving efficient database access based on ORM (object relational mapping) architecture
CN105550242A (en) * 2015-12-08 2016-05-04 方正移动传媒技术(北京)有限公司 Data processing method and device of relational database

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7296028B1 (en) * 2004-04-30 2007-11-13 Sap Ag System and method for mapping object-oriented program code to a database layer
CN101183387A (en) * 2007-12-14 2008-05-21 沈阳东软软件股份有限公司 Increment data capturing method and system
CN102841889A (en) * 2011-06-20 2012-12-26 中兴通讯股份有限公司 Method and device for achieving efficient database access based on ORM (object relational mapping) architecture
CN105550242A (en) * 2015-12-08 2016-05-04 方正移动传媒技术(北京)有限公司 Data processing method and device of relational database

Also Published As

Publication number Publication date
CN110019266A (en) 2019-07-16

Similar Documents

Publication Publication Date Title
CN110955431B (en) Processing method and device of compiling environment
CN106897342B (en) Data verification method and equipment
CN106844369B (en) Objectification SQL sentence construction method and apparatus
CN106933823B (en) Data synchronization method and device
CN106951231B (en) Computer software development method and device
CN110019111B (en) Data processing method, data processing device, storage medium and processor
CN109033365B (en) Data processing method and related equipment
CN106933842B (en) Database query method and device
CN108415934B (en) Hive table repairing method, device, equipment and computer readable storage medium
CN113434533A (en) Data tracing tool construction method, data processing method, device and equipment
CN110825764B (en) SQL script generation method, system, storage medium and processor
CN109388644B (en) Data updating method and device
CN108241620B (en) Query script generation method and device
CN109977317B (en) Data query method and device
CN110019266B (en) SQL statement generation method and device
CN111159192B (en) Big data based data warehousing method and device, storage medium and processor
CN111125087A (en) Data storage method and device
CN111427863A (en) Data migration method, device and equipment based on domain model
CN110019357B (en) Database query script generation method and device
CN108241695B (en) Information processing method and device
CN105760383A (en) Method and device for detecting index alteration in ETL (extract-transform-load) task
WO2017088547A1 (en) Data upgrading method and apparatus
CN108228604B (en) Model construction method based on memory object, information query method and device
CN114064118A (en) Code migration method, device, equipment, storage medium and program product
CN108062329B (en) Data import 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

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

Applicant after: Beijing Guoshuang Technology Co.,Ltd.

Address before: 100086 Beijing city Haidian District Shuangyushu Area No. 76 Zhichun Road cuigongfandian 8 layer A

Applicant before: Beijing Guoshuang Technology Co.,Ltd.

CB02 Change of applicant information
GR01 Patent grant
GR01 Patent grant