CN116028524A - Database operation method and device, storage medium and electronic equipment - Google Patents

Database operation method and device, storage medium and electronic equipment Download PDF

Info

Publication number
CN116028524A
CN116028524A CN202310097383.8A CN202310097383A CN116028524A CN 116028524 A CN116028524 A CN 116028524A CN 202310097383 A CN202310097383 A CN 202310097383A CN 116028524 A CN116028524 A CN 116028524A
Authority
CN
China
Prior art keywords
sentence
statement
segment type
unit
state
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310097383.8A
Other languages
Chinese (zh)
Inventor
陈小伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Oceanbase Technology Co Ltd
Original Assignee
Beijing Oceanbase 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 Oceanbase Technology Co Ltd filed Critical Beijing Oceanbase Technology Co Ltd
Priority to CN202310097383.8A priority Critical patent/CN116028524A/en
Publication of CN116028524A publication Critical patent/CN116028524A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the specification acquires a code statement, traverses statement units contained in the code statement, determines a current statement state, and recognizes the statement section type of a statement section where the currently traversed statement unit is located as the statement section type corresponding to the current statement state. Determining an ending symbol corresponding to the sentence segment type, determining that the sentence segment of the sentence segment type is ended when the sentence segment is traversed to the ending symbol, changing the current sentence state, and continuing to traverse the rest sentence units of the code sentence until all sentence segments contained in the code sentence are traversed. And finally, operating the database based on each sentence segment corresponding to each type of the split sentence segments. In the method, different sentence states corresponding to different sentence segment types are set, and sentence segments of the different sentence segment types can be accurately split from the code sentence in a manner of switching the sentence states.

Description

Database operation method and device, storage medium and electronic equipment
Technical Field
The present disclosure relates to the field of database technologies, and in particular, to a database operation method, a database operation device, a storage medium, and an electronic device.
Background
Currently, when operating a database, a user can perform operations such as data query, data update, data access, and protection of private data by using codes written in a structured query language (Structured Query Language, SQL) and a procedural SQL (Procedural Language/SQL, PL/SQL).
In practical applications, it is generally required to separate the statement section of SQL and the statement section of PL/SQL from the code statement written by the user, and execute the database operation by the separated statement sections. However, the statement fragments contained in the code statements are not currently efficiently split.
Disclosure of Invention
Embodiments of the present disclosure provide a database operation method, apparatus, storage medium, and electronic device, so as to partially solve the foregoing problems in the prior art.
The embodiment of the specification adopts the following technical scheme:
the present specification provides a database operating method, the method comprising:
acquiring a code statement;
traversing statement units contained in the code statement, and determining the current statement state;
Identifying the sentence segment type of the sentence segment where the currently traversed sentence unit is located as the sentence segment type corresponding to the sentence state;
determining an ending symbol corresponding to the sentence segment type;
when traversing to the ending symbol, determining that the sentence segment of the sentence segment type is ended, changing the sentence state, and continuing traversing the rest sentence units of the code sentence until all sentence segments contained in the code sentence are traversed;
aiming at each sentence segment type, splitting each sentence segment corresponding to the sentence segment type from the code sentence;
and operating the database according to each statement segment corresponding to each type of the split statement segments.
Optionally, the sentence state includes: the first sentence state corresponds to a first sentence segment type, and the second sentence state corresponds to a second sentence segment type;
when traversing to the ending symbol, determining that the sentence segment of the sentence segment type is ended, and changing the sentence state, specifically comprising:
when traversing to the ending symbol corresponding to the first sentence segment type, determining that the sentence segment of the first sentence segment type is ended, and changing the first sentence state into the second sentence state;
And when traversing to the ending symbol corresponding to the second sentence segment type, determining that the sentence segment of the second sentence segment type ends, and traversing to the starting sentence unit corresponding to the first sentence segment type after traversing to the ending symbol corresponding to the second sentence segment type, and changing the second sentence state into the first sentence state.
Optionally, determining the ending symbol corresponding to the sentence segment type specifically includes:
if the sentence segment type is determined to be the first sentence segment type, judging whether a specified sentence unit is identified before traversing out the initial sentence unit corresponding to the first sentence segment type;
if the appointed statement unit is not identified before the initial statement unit corresponding to the first statement section type is traversed, determining a preset separator to be an ending symbol corresponding to the first statement section type.
Optionally, the method further comprises:
if a specified statement unit is identified before traversing the starting statement unit corresponding to the first statement section type, determining an ending symbol corresponding to the first statement section type according to the separator defined by the specified statement unit.
Optionally, the specified statement unit includes: relimiter.
Optionally, the first sentence segment type includes: PL/SQL statement segment types, the second statement segment type comprising: SQL statement segment type.
The database operating device provided in the present specification includes:
the acquisition module is used for acquiring code sentences;
the first determining module is used for traversing statement units contained in the code statement and determining the current statement state;
the identifying module is used for identifying the sentence segment type of the sentence segment where the currently traversed sentence unit is located as the sentence segment type corresponding to the sentence state;
the second determining module is used for determining an ending symbol corresponding to the sentence segment type;
the traversing module is used for determining that the sentence segment of the sentence segment type is ended when the ending symbol is traversed, changing the sentence state and continuing to traverse the rest sentence units of the code sentence until all sentence segments contained in the code sentence are traversed;
the splitting module is used for splitting each sentence segment type from the code sentences to obtain each sentence segment corresponding to the sentence segment type;
and the operation module is used for operating the database according to each statement segment corresponding to each split statement segment type.
Optionally, the traversing module is specifically configured to determine that a sentence segment of the first sentence segment type ends when traversing to an ending symbol corresponding to the first sentence segment type, and change the first sentence state to the second sentence state; when traversing to the ending symbol corresponding to the second sentence segment type, determining that the sentence segment of the second sentence segment type ends, and when traversing to the starting sentence unit corresponding to the first sentence segment type after traversing to the ending symbol corresponding to the second sentence segment type, changing the second sentence state to the first sentence state; the statement state includes: the sentence processing system comprises a first sentence state and a second sentence state, wherein the first sentence state corresponds to a first sentence segment type, and the second sentence state corresponds to a second sentence segment type.
Optionally, the second determining module is specifically configured to determine whether a specified sentence unit is identified before traversing out a starting sentence unit corresponding to the first sentence segment type if the sentence segment type is determined to be the first sentence segment type; if the appointed statement unit is not identified before the initial statement unit corresponding to the first statement section type is traversed, determining a preset separator to be an ending symbol corresponding to the first statement section type.
Optionally, the second determining module is further configured to determine, if a specified sentence unit is identified before traversing out the start sentence unit corresponding to the first sentence segment type, an ending symbol corresponding to the first sentence segment type according to a separator defined by the specified sentence unit.
Optionally, the specified statement unit includes: relimiter.
Optionally, the first sentence segment type includes: PL/SQL statement segment types, the second statement segment type comprising: SQL statement segment type.
A computer-readable storage medium is provided in the present specification, the storage medium storing a computer program that, when executed by a processor, implements the database operating method described above.
The electronic device provided by the specification comprises a memory, a processor and a computer program stored on the memory and capable of running on the processor, wherein the processor realizes the database operation method when executing the program.
The above-mentioned at least one technical scheme that this description embodiment adopted can reach following beneficial effect:
in the embodiment of the specification, a code sentence is obtained, sentence units contained in the code sentence are traversed, a current sentence state is determined, and a sentence segment type of a sentence segment where the currently traversed sentence unit is located is identified as a sentence segment type corresponding to the current sentence state. Determining an ending symbol corresponding to the sentence segment type, determining that the sentence segment of the sentence segment type is ended when the sentence segment is traversed to the ending symbol, changing the current sentence state, and continuing to traverse the rest sentence units of the code sentence until all sentence segments contained in the code sentence are traversed. And finally, operating the database based on each sentence segment corresponding to each type of the split sentence segments. In the method, different sentence states corresponding to different sentence segment types are set, so that sentence segments of the different sentence segment types can be accurately split from a code sentence in a manner of switching the sentence states.
Drawings
The accompanying drawings, which are included to provide a further understanding of the specification, illustrate and explain the exemplary embodiments of the present specification and their description, are not intended to limit the specification unduly. In the drawings:
FIG. 1 is a schematic diagram of a block of PL/SQL code provided by an embodiment of the present specification;
FIG. 2 is a flowchart of a database operation method according to an embodiment of the present disclosure;
FIG. 3 is a schematic diagram of a code statement traversal process without a specified statement unit provided in an embodiment of the present disclosure;
FIG. 4 is a schematic diagram of a code statement traversal process including a specified statement unit provided in an embodiment of the present disclosure;
FIG. 5 is a schematic diagram of a code statement provided in an embodiment of the present disclosure that does not include a specified statement unit;
FIG. 6 is a schematic diagram of a code statement provided in an embodiment of the present disclosure that includes a specified statement unit;
fig. 7 is a schematic structural diagram of a database operating device according to an embodiment of the present disclosure;
fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure.
Detailed Description
In operating a database, although SQL and PL/SQL are different language types supported by the database, the database needs to parse and execute SQL statement fragments and PL/SQL statement fragments (i.e., PL/SQL code blocks), respectively. While a user may write operations to a database, a mixture of SQL and PL/SQL may be used.
Wherein the separator of each SQL sentence is a semicolon. The PL/SQL sentence segment is composed of PL specific grammar and several SQL sentences, so that the PL/SQL sentence segment contains partial SQL sentences, which results in the PL/SQL sentence segment being unable to be separated by semicolons.
In addition, the PL/SQL statement fragment is shown in FIG. 1. In FIG. 1, the PL/SQL statement segment begins with begin to end, where "… … dbms_output.put_line ('hello world'); "is an SQL statement.
For the purposes of making the objects, technical solutions and advantages of the present specification more apparent, the technical solutions of the present specification will be clearly and completely described below with reference to specific embodiments of the present specification and corresponding drawings. It will be apparent that the described embodiments are only some, but not all, of the embodiments of the present specification. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are intended to be within the scope of the present disclosure.
The following describes in detail the technical solutions provided by the embodiments of the present specification with reference to the accompanying drawings.
Fig. 2 is a schematic flow chart of a database operation method provided in the present specification, where the database operation method is applied to a database client, and includes:
S200: code statements are obtained.
In the embodiment of the specification, in response to a user input operation, the database client acquires a code sentence input by a user. Wherein the code statements are used to operate on data in the database. The code sentence can be composed of sentence sections of the same sentence section type, can also be composed of sentence sections of at least two sentence section types, and the sentence section of one sentence section type can contain only one sentence or can contain a plurality of sentences. That is, a code statement may be a code block composed of multiple statements. In addition, the sentence segment type includes at least: a first sentence segment type, a second sentence segment type. The first statement section type may refer to a PL/SQL statement section type and the second statement section type may refer to an SQL statement section type.
It should be noted that there may be a plurality of SQL statements in a statement segment of the PL/SQL statement segment type.
S202: traversing statement units contained in the code statement, and determining the current statement state.
S204: and identifying the sentence segment type of the sentence segment where the currently traversed sentence unit is located as the sentence segment type corresponding to the sentence state.
S206: and determining an ending symbol corresponding to the sentence segment type.
S208: when traversing to the ending symbol, determining that the sentence segment of the sentence segment type is ended, changing the sentence state, and continuing traversing the rest sentence units of the code sentence until all sentence segments contained in the code sentence are traversed.
In the embodiment of the present disclosure, in order to distinguish the sentence segments of different sentence segment types, each sentence segment corresponding to each sentence segment type in the code sentence may be split by switching the state machine for the sentence states of the different sentence segment types. The state machine may represent different sentence states, one sentence state corresponding to each sentence segment type. In addition, the sentence states include at least: the first sentence state corresponds to the first sentence segment type, and the second sentence state corresponds to the second sentence segment type.
In the embodiment of the present specification, after the code sentence is obtained, the obtained code sentence may be lexically parsed, and each sentence unit other than the comment sentence included in the code sentence may be determined. The statement unit may be an inseparable minimum unit constituting a code statement, and may be constituted of a plurality of statement units for one of the code statements. The statement unit may include: words, separators, etc. The words may include: begin, delimiter, etc. words composed of arbitrary character strings, separators may include: division (;) and slash (/), etc.
After each statement unit included in the code statement is determined, the statement units included in the code statement may be traversed sequentially. In the traversing process, the real-time sentence state of the state machine can be determined, so that sentence segment types of sentence segments where the sentence units traversed in real time are located are classified based on the real-time sentence state of the state machine, and each sentence segment corresponding to each sentence segment type is obtained.
Specifically, the current sentence state may be determined first, and then, the sentence segment type of the sentence segment where the currently traversed sentence unit is located is identified as the sentence segment type corresponding to the current sentence state. Then, an ending symbol (i.e., ending separator) corresponding to the sentence segment type corresponding to the current sentence state is determined.
When traversing to the ending symbol corresponding to the sentence segment type corresponding to the current sentence state, determining that the sentence segment of the sentence segment type corresponding to the current sentence state is ended, and changing the current sentence state (namely, switching the current sentence state). After changing the current statement state, traversing the rest statement units of the code statement until all statement segments contained in the code statement are traversed. All the sentence segments contained in the code sentence can contain sentence segments of one sentence segment type, and can also contain sentence segments of multiple sentence segment types.
Before traversing to the ending symbol corresponding to the sentence segment type corresponding to the current sentence state, if traversing to the ending symbol corresponding to the other sentence segment type, the position of the ending symbol corresponding to the other sentence segment type is not used as the ending position of the sentence segment type corresponding to the current sentence state.
The ending symbol of the first sentence segment type corresponding to the first sentence state may be a diagonal bar (/), and the ending symbol of the second sentence segment type corresponding to the second sentence state may be a semicolon (;).
Next, a description will be given of a procedure of classifying the sentence segment types of the sentence segments in the code sentence, taking two sentence segment types, i.e., the first sentence segment type and the second sentence segment type, as examples. When the sentence state is changed, the second sentence state may be set as a default state of the state machine.
In the process of traversing the statement units contained in the code statement in sequence, if the current statement state is determined to be the first statement state, the statement section type of the statement section where the currently traversed statement unit is located is identified as the first statement section type corresponding to the first statement state. Then, judging whether a specified sentence unit is identified before traversing the initial sentence unit corresponding to the first sentence segment type, and if the specified sentence unit is not identified, taking a preset separator as an ending symbol corresponding to the first sentence segment type. The starting sentence unit corresponding to the first sentence segment type may refer to a sentence unit located at a sentence segment starting position of the first sentence segment type, and the starting sentence unit may include: declare, begin, create function, create procedure, etc. The specified statement unit may include: relimiter. The preset separator may include: and (5) a diagonal rod.
If the specified sentence unit is identified, the ending symbol corresponding to the first sentence segment type may be determined according to the separator defined by the specified sentence unit.
Further, it may be judged whether or not the separator defined by the specified sentence unit is the ending symbol (i.e., semicolon) corresponding to the second sentence segment type. If the separator defined by the specified sentence unit is the ending character corresponding to the second sentence segment type, the preset separator corresponding to the first sentence segment type is used as the ending character corresponding to the first sentence segment type. And if the separator defined by the specified sentence unit is not the ending character corresponding to the second sentence segment type, taking the separator defined by the specified sentence unit as the ending character corresponding to the first sentence segment type. Wherein, the delimiter defined by the specified statement unit may refer to an arbitrarily defined delimiter, such as: "; ","/"," $$ "etc.
After determining the ending symbol corresponding to the first sentence segment type, continuing to traverse the sentence units after the starting sentence unit, and when traversing to the ending symbol corresponding to the first sentence segment type, determining that the sentence segment of the first sentence segment type ends, and then changing the first sentence state into the second sentence state. That is, the statement state of the state machine is switched to the default state.
In the process of traversing the sentence units contained in the code sentences in sequence, if the current sentence state is determined to be the second sentence state, identifying the sentence segment type of the sentence segment where the currently traversed sentence unit is located as the second sentence segment type corresponding to the second sentence state. Then, a separator preset for the second sentence segment type is used as an ending symbol corresponding to the second sentence segment type. Wherein the separator preset for the second sentence segment type may include a semicolon.
And continuing traversing the statement units after the statement units traversed currently, and determining that the statement sections of the second statement section type are ended when the ending symbol corresponding to the second statement section type is traversed. Then, when traversing to the starting sentence unit corresponding to the first sentence segment type after traversing to the ending symbol corresponding to the second sentence segment type, changing the current second sentence state to the first sentence state.
Before proceeding with traversing the sentence unit after the currently traversed sentence unit, it may be determined whether the currently traversed sentence unit is the starting sentence unit of the first sentence segment type. If the currently traversed sentence unit is the initial sentence unit of the first sentence segment type, the current second sentence state can be changed into the first sentence state. And then, identifying the sentence segment type of the sentence segment where the currently traversed sentence unit is located as a first sentence segment type corresponding to the first sentence state, and determining an ending symbol corresponding to the first sentence segment type. And finally, traversing the statement units after the currently traversed statement unit until traversing to the ending symbol corresponding to the first statement segment type.
If the currently traversed sentence unit is not the starting sentence unit of the first sentence segment type, the sentence segment type of the sentence segment where the currently traversed sentence unit is located is not required to be identified as the first sentence segment type corresponding to the first sentence state, and the sentence units after the currently traversed sentence unit are continuously traversed until the ending symbol corresponding to the second sentence segment type is traversed.
In addition, before traversing the sentence unit after the currently traversed sentence unit, whether the currently traversed sentence unit is a specified sentence unit or not may be judged, and if the currently traversed sentence unit is not the specified sentence unit, whether the currently traversed sentence unit is a starting sentence unit of the first sentence segment type or not may be judged. If the currently traversed sentence unit is the initial sentence unit of the first sentence segment type, the current second sentence state can be changed into the first sentence state. And then, identifying the sentence segment type of the sentence segment where the currently traversed sentence unit is located as a first sentence segment type corresponding to the first sentence state, and determining an ending symbol corresponding to the first sentence segment type. And finally, traversing the statement units after the currently traversed statement unit until traversing to the ending symbol corresponding to the first statement segment type. If the currently traversed sentence unit is not the starting sentence unit of the first sentence segment type, the sentence segment type of the sentence segment where the currently traversed sentence unit is located is not required to be identified as the first sentence segment type corresponding to the first sentence state, and the sentence units after the currently traversed sentence unit are continuously traversed until the ending symbol corresponding to the second sentence segment type is traversed.
If the currently traversed sentence unit is the appointed sentence unit, analyzing the sentence containing the appointed sentence unit, determining the separator defined by the appointed sentence unit, and storing. Then, it is judged whether or not a sentence unit subsequent to a sentence containing a specified sentence unit is a starting sentence unit of the first sentence segment type.
If the sentence unit after the sentence containing the specified sentence unit is the starting sentence unit of the first sentence segment type, the current second sentence state can be changed to the first sentence state. And then, identifying the sentence segment type of the sentence segment where the currently traversed sentence unit is located as a first sentence segment type corresponding to the first sentence state, and determining an ending symbol corresponding to the first sentence segment type. And finally, traversing the statement units after the currently traversed statement unit until traversing to the ending symbol corresponding to the first statement segment type.
In determining the ending symbol corresponding to the first sentence segment type, it may be determined whether the separator defined by the specified sentence unit is the ending symbol corresponding to the second sentence segment type (i.e., a semicolon). If the separator defined by the specified sentence unit is the ending character corresponding to the second sentence segment type, the preset separator corresponding to the first sentence segment type is used as the ending character corresponding to the first sentence segment type. And if the separator defined by the specified sentence unit is not the ending character corresponding to the second sentence segment type, taking the separator defined by the specified sentence unit as the ending character corresponding to the first sentence segment type.
If the sentence unit after the sentence containing the appointed sentence unit is not the initial sentence unit of the first sentence section type, the sentence section type of the sentence section where the currently traversed sentence unit is positioned is not required to be identified as the first sentence section type corresponding to the first sentence state, and the separator defined by the appointed sentence unit is used as the ending character corresponding to the second sentence section type. And traversing statement units after the currently traversed statement unit until traversing to the ending symbol corresponding to the second statement segment type.
S210: and splitting each sentence segment type from the code sentences to obtain each sentence segment corresponding to the sentence segment type.
S212: and operating the database according to each statement segment corresponding to each type of the split statement segments.
In the embodiment of the present disclosure, after each sentence unit included in a code sentence is traversed in sequence, all sentence segments included in the code sentence may be classified according to the traversing result, and each sentence segment belonging to a sentence segment type corresponding to different sentence states is determined, that is, each sentence segment belonging to a first sentence segment type and each sentence segment belonging to a second sentence segment type in the code sentence are determined. Then, for each sentence segment type, each sentence segment corresponding to the sentence segment type is split from the code sentence. And finally, operating the database according to each sentence segment corresponding to each type of the split sentence segments. Operations such as: data querying, updating, accessing, privacy data protection, etc.
Specifically, each sentence segment corresponding to each sentence segment type may be sent to the server side of the database. The server side of the database processes the data stored in the database aiming at each sentence segment corresponding to each sentence segment type to obtain a processing result, and feeds the processing result back to the client side of the database so as to display the processing result to a user.
As can be seen from the method shown in fig. 2, the present specification obtains a code sentence, traverses a sentence unit included in the code sentence, determines a current sentence state, and identifies a sentence segment type of a sentence segment where the currently traversed sentence unit is located as a sentence segment type corresponding to the current sentence state. Determining an ending symbol corresponding to the sentence segment type, determining that the sentence segment of the sentence segment type is ended when the sentence segment is traversed to the ending symbol, changing the current sentence state, and continuing to traverse the rest sentence units of the code sentence until all sentence segments contained in the code sentence are traversed. And finally, operating the database based on each sentence segment corresponding to each type of the split sentence segments. In the method, different sentence states corresponding to different sentence segment types are set, so that sentence segments of the different sentence segment types can be accurately split from a code sentence in a manner of switching the sentence states.
Based on the description of steps S202 to S208 of fig. 2, a flow diagram of two traversal code statements is provided in this specification. Fig. 3 is a schematic diagram of a code sentence traversal process provided in the embodiment of the present disclosure, where the code sentence traversal process does not include a specified sentence unit, and fig. 4 is a schematic diagram of the code sentence traversal process provided in the embodiment of the present disclosure, where the code sentence traversal process includes a specified sentence unit.
Next, a code sentence traversal flow shown in fig. 3, which does not include a specified sentence unit, will be described with reference to the code sentence shown in fig. 5.
In fig. 3, each sentence unit in the code sentence starts to be traversed in turn, and since the default state of the state machine is the second sentence state, it is determined whether the current sentence state is the second sentence state, if the current sentence state is the second sentence state, the sentence segment type of the sentence segment where the sentence unit currently traversed in the code sentence (i.e., the first sentence unit begin in fig. 5) is located is identified as the second sentence segment type, and the ending symbol corresponding to the second sentence segment type is determined. Judging whether the currently traversed sentence unit is a starting sentence unit of a first sentence segment type, if the currently traversed sentence unit is the starting sentence unit of the first sentence segment type (begin in fig. 5 is the starting sentence unit), changing the current sentence state into the first sentence state, identifying the sentence segment type of the sentence segment where the currently traversed sentence unit (i.e. the first sentence unit begin in fig. 5) is located as the first sentence segment type, and determining an ending symbol corresponding to the first sentence segment type. And continuing to traverse the sentence units after the starting sentence unit, judging whether the currently traversed sentence unit is an ending symbol corresponding to the first sentence segment type, if the currently traversed sentence unit is the ending symbol corresponding to the first sentence segment type (namely "/" infig. 5), determining that the first sentence segment type is ended, and splitting the code sentence to obtain a sentence segment of the first sentence segment type (begin … … dbms_output. Put_line ('hello world'); end; "in fig. 5). Then, the current sentence state is changed from the first sentence state to the second sentence state, the sentence segment type of the sentence segment where the currently traversed sentence unit (i.e., the select position in fig. 5) is located is identified as the second sentence segment type, and the ending symbol corresponding to the second sentence segment type is determined, and then the above-mentioned judging steps are repeated. That is, it is determined whether the currently traversed statement unit (i.e., the select position in fig. 5) is the start statement unit of the first statement section type. If the currently traversed statement unit is not the starting statement unit of the first statement section type (select in fig. 5 is not the starting statement unit), then the next statement unit is traversed continuously, when traversing to the terminator corresponding to the second statement section type (";" in fig. 5), the second statement section type is determined to be ended, and a statement section of the second statement section type (select 1from real; "in fig. 5) can be split from the code statement.
The code word traversing flow including the specified word and word unit shown in fig. 4 will be described with reference to the code word and word shown in fig. 6.
In fig. 4, each sentence unit in the code sentence starts to be traversed in turn, and since the default state of the state machine is the second sentence state, it is determined whether the current sentence state is the second sentence state, if the current sentence state is the second sentence state, the sentence segment type of the sentence segment where the sentence unit currently traversed in the code sentence (i.e., the first sentence unit delimiter in fig. 5) is located is identified as the second sentence segment type, and the ending symbol corresponding to the second sentence segment type is determined. Then, whether the currently traversed sentence unit is a specified sentence unit (for example, the specified sentence unit is a specification sentence unit) is judged, and if the currently traversed sentence unit is the specified sentence unit (the specification sentence unit in fig. 6), a sentence including the specified sentence unit is analyzed, and separators ("$$") defined by the specified sentence unit are determined and stored. The traversal continues for the next statement unit (begin in fig. 6) after the statement containing the specified statement unit. Judging whether the currently traversed sentence unit (i.e., begin in fig. 6) is a specified sentence unit, judging whether the currently traversed sentence unit (i.e., begin in fig. 6) is a first sentence segment type starting sentence unit if the currently traversed sentence unit is not the specified sentence unit, and changing the current sentence state from the second sentence state to the first sentence state and identifying the sentence segment type of the sentence segment where the currently traversed sentence unit (i.e., begin in fig. 6) is located as the first sentence segment type if the currently traversed sentence unit (i.e., begin in fig. 6) is the first sentence segment type starting sentence unit. Then, judging whether the separator defined by the appointed statement unit is an ending character corresponding to the second statement section type, if the separator defined by the appointed statement unit is not the ending character corresponding to the second statement section type, the delimiter defined by the statement unit will be specified (in fig. 6 "$$") as an ending symbol corresponding to the first sentence segment type. And continuing to traverse the sentence units after the starting sentence unit, judging whether the traversed sentence unit is an ending symbol corresponding to the first sentence segment type, and determining that the first sentence segment type is ended when the traversed sentence unit is the ending symbol corresponding to the first sentence segment type (i.e. "$$in fig. 6), so that a sentence segment of the first sentence segment type (begin … … dbms_output. Put_line ('hello world'); end;") in fig. 6) can be obtained by splitting from the code sentence. Then, the current sentence state is changed from the first sentence state to the second sentence state, the sentence segment type of the sentence segment where the current traversed sentence unit (i.e. the second relimiter in fig. 6) is located is identified as the second sentence segment type, the ending symbol corresponding to the second sentence segment type is determined, and the above-mentioned judging steps are repeated. That is, whether the currently traversed sentence unit is a specified sentence unit is determined, and if the currently traversed sentence unit is a specified sentence unit (the second delimiter in fig. 6 is a specified sentence unit), a sentence including the specified sentence unit is analyzed, and separators defined by the specified sentence unit are determined (";" in fig. 6) and stored. Continuing to traverse the next sentence unit (select in fig. 6) after the sentence containing the specified sentence unit, judging whether the currently traversed sentence unit (select in fig. 6) is the specified sentence unit, if the currently traversed sentence unit is not the specified sentence unit, judging whether the currently traversed sentence unit is the starting sentence unit of the first sentence segment type, if the currently traversed sentence unit is not the starting sentence unit of the first sentence segment type (select in fig. 6 is not the starting sentence unit), without changing the current sentence state, the current sentence state is still the second sentence state, and taking the separator (";" in fig. 6) defined by the specified sentence unit as the ending symbol corresponding to the second sentence segment type. Continuing to traverse the next sentence unit, determining that the second sentence segment type is ended when traversing to the terminator (";" in fig. 6) corresponding to the second sentence segment type, and splitting a sentence segment (select 1from real; in fig. 5) of the second sentence segment type from the code sentence.
The database operation method provided for the embodiment of the present specification further provides a corresponding apparatus, a storage medium, and an electronic device based on the same concept.
Fig. 7 is a schematic structural diagram of a database operating device according to an embodiment of the present disclosure, where the device includes:
an acquiring module 701, configured to acquire a code statement;
a first determining module 702, configured to traverse statement units included in the code statement, and determine a current statement state;
an identifying module 703, configured to identify a sentence segment type of a sentence segment where a currently traversed sentence unit is located as a sentence segment type corresponding to the sentence state;
a second determining module 704, configured to determine an ending symbol corresponding to the sentence segment type;
a traversing module 705, configured to determine that a sentence segment of the sentence segment type ends when traversing to the ending symbol, change the sentence state, and continue traversing the remaining sentence units of the code sentence until all sentence segments included in the code sentence are traversed;
a splitting module 706, configured to split each sentence segment type from the code sentence to obtain each sentence segment corresponding to the sentence segment type;
And an operation module 707, configured to operate the database according to each sentence segment corresponding to each type of the split sentence segments.
Optionally, the sentence state includes: the first sentence state corresponds to a first sentence segment type, and the second sentence state corresponds to a second sentence segment type;
optionally, the second determining module 704 is specifically configured to determine that the sentence segment of the first sentence segment type ends when traversing to the ending symbol corresponding to the first sentence segment type, and change the first sentence state to the second sentence state; and when traversing to the ending symbol corresponding to the second sentence segment type, determining that the sentence segment of the second sentence segment type ends, and traversing to the starting sentence unit corresponding to the first sentence segment type after traversing to the ending symbol corresponding to the second sentence segment type, and changing the second sentence state into the first sentence state.
Optionally, the second determining module 704 is specifically configured to determine, if the sentence segment type is determined to be the first sentence segment type, whether a specified sentence unit is identified before traversing out the start sentence unit corresponding to the first sentence segment type; if the appointed statement unit is not identified before the initial statement unit corresponding to the first statement section type is traversed, determining a preset separator to be an ending symbol corresponding to the first statement section type.
Optionally, the second determining module 704 is further configured to determine, if a specified sentence unit is identified before traversing out the start sentence unit corresponding to the first sentence segment type, an ending symbol corresponding to the first sentence segment type according to a separator defined by the specified sentence unit.
Optionally, the specified statement unit includes: relimiter.
Optionally, the first sentence segment type includes: PL/SQL statement segment types, the second statement segment type comprising: SQL statement segment type.
The present specification also provides a computer readable storage medium storing a computer program which when executed by a processor is operable to perform the database operating method provided in figure 2 above.
Based on the database operation method shown in fig. 2, the embodiment of the present disclosure further provides a schematic structural diagram of the unmanned device shown in fig. 8. At the hardware level, as in fig. 8, the unmanned device includes a processor, an internal bus, a network interface, a memory, and a non-volatile storage, although it may include hardware required for other services. The processor reads the corresponding computer program from the nonvolatile memory into the memory and then runs the same to implement the database operating method shown in fig. 2.
Of course, other implementations, such as logic devices or combinations of hardware and software, are not excluded from the present description, that is, the execution subject of the following processing flows is not limited to each logic unit, but may be hardware or logic devices.
In the 90 s of the 20 th century, improvements to one technology could clearly be distinguished as improvements in hardware (e.g., improvements to circuit structures such as diodes, transistors, switches, etc.) or software (improvements to the process flow). However, with the development of technology, many improvements of the current method flows can be regarded as direct improvements of hardware circuit structures. Designers almost always obtain corresponding hardware circuit structures by programming improved method flows into hardware circuits. Therefore, an improvement of a method flow cannot be said to be realized by a hardware entity module. For example, a programmable logic device (Programmable Logic Device, PLD) (e.g., field programmable gate array (Field Programmable Gate Array, FPGA)) is an integrated circuit whose logic function is determined by the programming of the device by a user. A designer programs to "integrate" a digital system onto a PLD without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Moreover, nowadays, instead of manually manufacturing integrated circuit chips, such programming is mostly implemented by using "logic compiler" software, which is similar to the software compiler used in program development and writing, and the original code before the compiling is also written in a specific programming language, which is called hardware description language (Hardware Description Language, HDL), but not just one of the hdds, but a plurality of kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), lava, lola, myHDL, PALASM, RHDL (Ruby Hardware Description Language), etc., VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog are currently most commonly used. It will also be apparent to those skilled in the art that a hardware circuit implementing the logic method flow can be readily obtained by merely slightly programming the method flow into an integrated circuit using several of the hardware description languages described above.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer readable medium storing computer readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable logic controllers, and embedded microcontrollers, examples of which include, but are not limited to, the following microcontrollers: ARC625D, atmel AT91SAM, microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic of the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller in a pure computer readable program code, it is well possible to implement the same functionality by logically programming the method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers, etc. Such a controller may thus be regarded as a kind of hardware component, and means for performing various functions included therein may also be regarded as structures within the hardware component. Or even means for achieving the various functions may be regarded as either software modules implementing the methods or structures within hardware components.
The system, apparatus, module or unit set forth in the above embodiments may be implemented in particular by a computer chip or entity, or by a product having a certain function. One typical implementation is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being functionally divided into various units, respectively. Of course, the functions of each element may be implemented in one or more software and/or hardware elements when implemented in the present specification.
It will be appreciated by those skilled in the art that embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, the present specification may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present description can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
The present description is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the specification. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations 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 one typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
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). Memory is an example of computer-readable media.
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 storage media for a computer 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, which can be used to store information that can be accessed by a computing device. Computer-readable media, as defined herein, does not include transitory computer-readable media (transmission media), such as modulated data signals and carrier waves.
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 one … …" does not exclude the presence of other like elements in a process, method, article or apparatus that comprises the element.
It will be appreciated by those skilled in the art that embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, the present specification may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present description can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
The description may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing is merely exemplary of the present disclosure and is not intended to limit the disclosure. Various modifications and alterations to this specification will become apparent to those skilled in the art. Any modifications, equivalent substitutions, improvements, or the like, which are within the spirit and principles of the present description, are intended to be included within the scope of the claims of the present description.

Claims (14)

1. A method of database operation, the method comprising:
acquiring a code statement;
traversing statement units contained in the code statement, and determining the current statement state;
identifying the sentence segment type of the sentence segment where the currently traversed sentence unit is located as the sentence segment type corresponding to the sentence state;
determining an ending symbol corresponding to the sentence segment type;
When traversing to the ending symbol, determining that the sentence segment of the sentence segment type is ended, changing the sentence state, and continuing traversing the rest sentence units of the code sentence until all sentence segments contained in the code sentence are traversed;
aiming at each sentence segment type, splitting each sentence segment corresponding to the sentence segment type from the code sentence;
and operating the database according to each statement segment corresponding to each type of the split statement segments.
2. The method of claim 1, wherein the statement state comprises: the first sentence state corresponds to a first sentence segment type, and the second sentence state corresponds to a second sentence segment type;
when traversing to the ending symbol, determining that the sentence segment of the sentence segment type is ended, and changing the sentence state, specifically comprising:
when traversing to the ending symbol corresponding to the first sentence segment type, determining that the sentence segment of the first sentence segment type is ended, and changing the first sentence state into the second sentence state;
and when traversing to the ending symbol corresponding to the second sentence segment type, determining that the sentence segment of the second sentence segment type ends, and traversing to the starting sentence unit corresponding to the first sentence segment type after traversing to the ending symbol corresponding to the second sentence segment type, and changing the second sentence state into the first sentence state.
3. The method of claim 1, determining an ending symbol corresponding to the sentence segment type, specifically comprising:
if the sentence segment type is determined to be the first sentence segment type, judging whether a specified sentence unit is identified before traversing out the initial sentence unit corresponding to the first sentence segment type;
if the appointed statement unit is not identified before the initial statement unit corresponding to the first statement section type is traversed, determining a preset separator to be an ending symbol corresponding to the first statement section type.
4. A method as claimed in claim 3, the method further comprising:
if a specified statement unit is identified before traversing the starting statement unit corresponding to the first statement section type, determining an ending symbol corresponding to the first statement section type according to the separator defined by the specified statement unit.
5. The method of claim 4, wherein the specifying statement unit comprises: relimiter.
6. The method of any one of claims 2 to 5, wherein the first sentence fragment type comprises: PL/SQL statement segment types, the second statement segment type comprising: SQL statement segment type.
7. A database operating apparatus comprising:
The acquisition module is used for acquiring code sentences;
the first determining module is used for traversing statement units contained in the code statement and determining the current statement state;
the identifying module is used for identifying the sentence segment type of the sentence segment where the currently traversed sentence unit is located as the sentence segment type corresponding to the sentence state;
the second determining module is used for determining an ending symbol corresponding to the sentence segment type;
the traversing module is used for determining that the sentence segment of the sentence segment type is ended when the ending symbol is traversed, changing the sentence state and continuing to traverse the rest sentence units of the code sentence until all sentence segments contained in the code sentence are traversed;
the splitting module is used for splitting each sentence segment type from the code sentences to obtain each sentence segment corresponding to the sentence segment type;
and the operation module is used for operating the database according to each statement segment corresponding to each split statement segment type.
8. The apparatus of claim 7, wherein the traversing module is specifically configured to determine that a sentence segment of the first sentence segment type ends and change the first sentence state to the second sentence state when traversing to an ending symbol corresponding to the first sentence segment type; when traversing to the ending symbol corresponding to the second sentence segment type, determining that the sentence segment of the second sentence segment type ends, and when traversing to the starting sentence unit corresponding to the first sentence segment type after traversing to the ending symbol corresponding to the second sentence segment type, changing the second sentence state to the first sentence state; the statement state includes: the sentence processing system comprises a first sentence state and a second sentence state, wherein the first sentence state corresponds to a first sentence segment type, and the second sentence state corresponds to a second sentence segment type.
9. The apparatus of claim 7, wherein the second determining module is specifically configured to determine whether a specified sentence unit is identified before traversing out a starting sentence unit corresponding to a first sentence segment type if the sentence segment type is determined to be the first sentence segment type; if the appointed statement unit is not identified before the initial statement unit corresponding to the first statement section type is traversed, determining a preset separator to be an ending symbol corresponding to the first statement section type.
10. The apparatus of claim 9, wherein the second determining module is further configured to determine, if a specified statement unit is identified before traversing out a start statement unit corresponding to the first statement section type, an ending symbol corresponding to the first statement section type according to a separator defined by the specified statement unit.
11. The apparatus of claim 10, the specified statement unit comprising: relimiter.
12. The apparatus of any of claims 8-11, the first sentence segment type comprising: PL/SQL statement segment types, the second statement segment type comprising: SQL statement segment type.
13. A computer readable storage medium storing a computer program which, when executed by a processor, implements the method of any of the preceding claims 1-6.
14. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the method of any of the preceding claims 1-6 when the program is executed.
CN202310097383.8A 2023-01-18 2023-01-18 Database operation method and device, storage medium and electronic equipment Pending CN116028524A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310097383.8A CN116028524A (en) 2023-01-18 2023-01-18 Database operation method and device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310097383.8A CN116028524A (en) 2023-01-18 2023-01-18 Database operation method and device, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN116028524A true CN116028524A (en) 2023-04-28

Family

ID=86081108

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310097383.8A Pending CN116028524A (en) 2023-01-18 2023-01-18 Database operation method and device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN116028524A (en)

Similar Documents

Publication Publication Date Title
CN110245002B (en) System interaction method, device, equipment and storage medium
CN107038206B (en) LSM tree establishing method, LSM tree data reading method and server
CN117312394B (en) Data access method and device, storage medium and electronic equipment
CN115756449B (en) Page multiplexing method and device, storage medium and electronic equipment
CN116663618B (en) Operator optimization method and device, storage medium and electronic equipment
CN116860259B (en) Method, device and equipment for model training and automatic optimization of compiler
CN113434533A (en) Data tracing tool construction method, data processing method, device and equipment
CN117828360A (en) Model training method, model training device, model code generating device, storage medium and storage medium
CN116521705A (en) Data query method and device, storage medium and electronic equipment
CN115982416A (en) Data processing method and device, readable storage medium and electronic equipment
CN110245137B (en) Index processing method, device and equipment
CN115390852A (en) Method and device for generating uniform abstract syntax tree and program analysis
CN116185532A (en) Task execution system, method, storage medium and electronic equipment
CN116644090B (en) Data query method, device, equipment and medium
CN116341642B (en) Data processing method and device, storage medium and electronic equipment
CN110083602B (en) Method and device for data storage and data processing based on hive table
CN116010419A (en) Method and device for creating unique index and optimizing logic deletion
CN115017915B (en) Model training and task execution method and device
CN116028524A (en) Database operation method and device, storage medium and electronic equipment
CN115878654A (en) Data query method, device, equipment and storage medium
CN115391426A (en) Data query method and device, storage medium and electronic equipment
CN115563116A (en) Database table scanning method, device and equipment
CN114333102A (en) Parameter configuration method and configuration device of unmanned equipment
CN113343141A (en) Webpage obtaining method and device
CN117992600B (en) Service execution method and device, storage medium and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination