A database operation method and device, a storage medium and an electronic device
By using a state machine to identify and switch statement states, the problem of the inability to separate SQL and PL/SQL code segments is solved, enabling efficient splitting and execution of database operations.
Patent Information
- Application Number
- CN202310097383.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-18
- Publication Date
- 2025-12-26
- Estimated Expiration
- 2043-01-18
AI Technical Summary
Existing technologies cannot effectively separate SQL and PL/SQL code statements, resulting in low database operation efficiency.
By identifying and switching statement states using a state machine, the terminator of the code statement segment type can be determined, accurately separating SQL and PL/SQL statement segments.
It enables precise splitting and manipulation of SQL and PL/SQL code, improving database operation efficiency.
Smart Images

Figure CN116028524B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present specification relates to the technical field of database, and particularly relates to a database operation method and device, a storage medium and an electronic device. BACKGROUND
[0002] At present, when operating a database, a user can use a code written by a structured query language (SQL) and a procedural language / SQL (PL / SQL) to perform operations such as data query, data update, data access, and privacy data protection.
[0003] In actual application, it is usually required to respectively split a statement segment of the SQL and a statement segment of the PL / SQL from a code statement written by the user, and perform a database operation through the split statement segments. However, at present, the statement segments contained in the code statement cannot be effectively split. SUMMARY
[0004] Embodiments of the present specification provide a database operation method and device, a storage medium and an electronic device to partially solve the problems in the prior art.
[0005] Embodiments of the present specification adopt the following technical solutions:
[0006] The present specification provides a database operation method, which comprises:
[0007] obtaining a code statement;
[0008] traversing a statement unit contained in the code statement, and determining a current statement state;
[0009] identifying a statement segment type of a statement segment in which the currently traversed statement unit is located as a statement segment type corresponding to the statement state;
[0010] determining an end symbol corresponding to the statement segment type;
[0011] when the end symbol is traversed, determining that the statement segment of the statement segment type ends, changing the statement state, and continuing to traverse a remaining statement unit of the code statement until all statement segments contained in the code statement are traversed;
[0012] for each statement segment type, splitting each statement segment corresponding to the statement segment type from the code statement;
[0013] performing an operation on the database according to each statement segment corresponding to each statement segment type which is split.
[0014] Optionally, the statement state comprises: a first statement state corresponding to the first statement segment type, and a second statement state corresponding to the second statement segment type.
[0015] When the end symbol of the statement segment type is reached, it is determined that the statement segment of the statement segment type ends, and the statement state is changed, specifically comprising:
[0016] When the end symbol corresponding to the first statement segment type is reached, it is determined that the statement segment of the first statement segment type ends, and the first statement state is changed to the second statement state.
[0017] When the end symbol corresponding to the second statement segment type is reached, it is determined that the statement segment of the second statement segment type ends, and when the start symbol corresponding to the first statement segment type is reached after the end symbol corresponding to the second statement segment type, the second statement state is changed to the first statement state.
[0018] Optionally, the end symbol corresponding to the statement segment type is determined, specifically comprising:
[0019] If it is determined that the statement segment type is the first statement segment type, it is determined whether a specified statement unit is identified before the start symbol corresponding to the first statement segment type is reached.
[0020] If the specified statement unit is not identified before the start symbol corresponding to the first statement segment type is reached, a preset delimiter is determined as the end symbol corresponding to the first statement segment type.
[0021] Optionally, the method further comprises:
[0022] If the specified statement unit is identified before the start symbol corresponding to the first statement segment type is reached, a delimiter defined by the specified statement unit is determined as the end symbol corresponding to the first statement segment type.
[0023] Optionally, the specified statement unit comprises: delimiter.
[0024] Optionally, the first statement segment type comprises: a PL / SQL statement segment type, and the second statement segment type comprises: a SQL statement segment type.
[0025] The present specification provides a database operation device, comprising:
[0026] An acquisition module is configured to acquire a code statement.
[0027] A first determination module is configured to traverse a statement unit contained in the code statement, and determine a current statement state.
[0028] The identification module is configured to identify a statement segment type of a statement segment in which a current traversed statement unit is located as the statement segment type corresponding to the statement state;
[0029] The second determination module is configured to determine an end symbol corresponding to the statement segment type;
[0030] The traversal module is configured to determine that the statement segment of the statement segment type ends when the end symbol is traversed, change the statement state, and continue to traverse remaining statement units of the code statement until all statement segments contained in the code statement are traversed.
[0031] The splitting module is configured to split each statement segment corresponding to each statement segment type from the code statement.
[0032] The operation module is configured to operate the database according to each statement segment corresponding to each statement segment type that is split.
[0033] Optionally, the traversal module is specifically configured to determine that the statement segment of the first statement segment type ends when the end symbol corresponding to the first statement segment type is traversed, and change the first statement state to the second statement state; determine that the statement segment of the second statement segment type ends when the end symbol corresponding to the second statement segment type is traversed, and change the second statement state to the first statement state when the start statement unit corresponding to the first statement segment type is traversed after the end symbol corresponding to the second statement segment type. The statement state includes a first statement state and a second statement state. The first statement state corresponds to the first statement segment type, and the second statement state corresponds to the second statement segment type.
[0034] Optionally, the second determination module is specifically configured to determine whether a specified statement unit is identified before the start statement unit corresponding to the first statement segment type is traversed if it is determined that the statement segment type is the first statement segment type, and determine a preset delimiter as the end symbol corresponding to the first statement segment type if the specified statement unit is not identified before the start statement unit corresponding to the first statement segment type is traversed.
[0035] Optionally, the second determination module is further configured to determine the end symbol corresponding to the first statement segment type according to a delimiter defined by the specified statement unit if the specified statement unit is identified before the start statement unit corresponding to the first statement segment type is traversed.
[0036] Optionally, the specified statement unit includes a delimiter.
[0037] Optionally, the first statement segment type comprises a PL / SQL statement segment type, and the second statement segment type comprises a SQL statement segment type.
[0038] The present specification provides a computer readable storage medium, the storage medium stores a computer program, and the computer program is executed by a processor to implement the database operation method.
[0039] The present specification provides an electronic device, which comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the database operation method when executing the program.
[0040] The above at least one technical solution adopted by the embodiment of the present specification can achieve the following beneficial effects:
[0041] In the embodiment of the present specification, the code statement is obtained, the statement units contained in the code statement are traversed, the current statement state is determined, the statement segment type of the statement segment in which the currently traversed statement unit is located is identified as the statement segment type corresponding to the current statement state, the end symbol corresponding to the statement segment type is determined, when the end symbol is traversed, it is determined that the statement segment of the statement segment type ends, the current statement state is changed, and the remaining statement units of the code statement are continuously traversed until all the statement segments contained in the code statement are traversed. Finally, the database is operated based on each statement segment corresponding to each statement segment type split out. In this method, different statement states corresponding to different statement segment types are set, so that the statement segments of different statement segment types can be accurately split out from the code statement by switching the statement state. BRIEF DESCRIPTION OF DRAWINGS
[0042] The accompanying drawings, which are included to provide a further understanding of the present specification, constitute a part of the present specification, and the illustrative embodiments of the present specification and their description serve to explain the present specification, and do not constitute an improper limitation on the present specification. In the drawings:
[0043] Figure 1 A schematic diagram of a PL / SQL code block is provided for the embodiment of the present specification;
[0044] Figure 2 A flowchart of a database operation method is provided for the embodiment of the present specification;
[0045] Figure 3 A schematic diagram of a code statement traversal flow not containing a specified statement unit is provided for the embodiment of the present specification;
[0046] Figure 4 A schematic diagram of a code statement traversal flow containing a specified statement unit is provided for the embodiment of the present specification;
[0047] Figure 5 A schematic diagram of code statements without specified statement units provided for an embodiment of the present specification;
[0048] Figure 6 A schematic diagram of code statements with specified statement units provided for an embodiment of the present specification;
[0049] Figure 7 A structural schematic diagram of a database operation apparatus provided for an embodiment of the present specification;
[0050] Figure 8 A structural schematic diagram of an electronic device provided for an embodiment of the present specification. DETAILED DESCRIPTION
[0051] In operation on a database, although SQL and PL / SQL are different language types supported by the database, the database needs to parse and execute SQL statement segments and PL / SQL statement segments (i.e. PL / SQL code blocks) respectively. However, when a user writes an operation for the database, the user may write in a mixed manner of SQL and PL / SQL.
[0052] Each SQL statement is separated by a semicolon. A PL / SQL statement segment is composed of a PL specific syntax and several SQL statements, so the PL / SQL statement segment contains part of the SQL statements, which causes the PL / SQL statement segment to be unable to be separated by the semicolon.
[0053] In addition, the PL / SQL statement segment is as shown in Figure 1 In Figure 1 , the PL / SQL statement segment starts from begin and ends at end, wherein "……dbms_output.put_line('hello world'); " is a SQL statement.
[0054] In order to make the purpose, technical solutions and advantages of the present specification clearer, the technical solutions of the present specification will be described clearly and completely in combination with the specific embodiments of the present specification and corresponding drawings. Obviously, the described embodiments are only some of the embodiments of the present specification, but not all the embodiments. Based on the embodiments in the present specification, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present specification.
[0055] The technical solutions provided by the embodiments of the present specification will be described in detail below in combination with the drawings.
[0056] Figure 2 A flow schematic diagram of a database operation method provided for the present specification is provided, the database operation method is applied to a database client, comprising:
[0057] S200: Obtain a code statement.
[0058] In the embodiments of the present specification, in response to a user input operation, the database client obtains a code statement input by the user. The code statement is used to operate data in the database. The code statement can be composed of a same statement segment type, or composed of at least two statement segment types. A statement segment of a statement segment type can include one or more statements.
[0059] It should be noted that there can be multiple SQL statements in a statement segment of the PL / SQL statement segment type.
[0060] S202: Traverse the statement units included in the code statement, and determine a current statement state.
[0061] S204: Identify the statement segment type of the statement segment in which the currently traversed statement unit is located as the statement segment type corresponding to the statement state.
[0062] S206: Determine an end symbol corresponding to the statement segment type.
[0063] S208: When the end symbol is traversed, it is determined that the statement segment of the statement segment type ends, the statement state is changed, and the remaining statement units of the code statement are continuously traversed until all statement segments included in the code statement are traversed.
[0064] In the embodiments of the present specification, in order to distinguish the statement segments of different statement segment types, the state machine can be switched to split each statement segment corresponding to each statement segment type in the code statement according to the statement state of the different statement segment types. The state machine can represent different statement states, and one statement state corresponds to one statement segment type. In addition, the statement state includes at least a first statement state and a second statement state, the first statement state corresponds to the first statement segment type, and the second statement state corresponds to the second statement segment type.
[0065] In the embodiments of the present specification, after the code statement is acquired, the acquired code statement can be subjected to lexical analysis to determine each statement unit contained in the code statement except the comment statement. The statement unit can refer to the smallest unit that cannot be split to constitute the code statement. For a statement in the code statement, the statement can be composed of a plurality of statement units. The statement unit can include a word, a delimiter, etc. The word can include a word composed of an arbitrary string, such as begin and delimiter. The delimiter can include a semicolon (;) and a slash ( / ), etc.
[0066] After determining the statement units contained in the code statement, the statement units contained in the code statement can be sequentially traversed. In the process of traversal, the real-time statement state of the state machine can be determined, so as to classify the statement segment type of the statement segment in which the statement unit traversed in real time is located based on the real-time statement state of the state machine, to obtain each statement segment corresponding to each statement segment type.
[0067] Specifically, the current statement state can be determined first, and then the statement segment type of the statement segment in which the statement unit currently traversed is located is identified as the statement segment type corresponding to the current statement state. Subsequently, the end symbol (i.e., the end delimiter) corresponding to the statement segment type corresponding to the current statement state is determined.
[0068] When the end symbol corresponding to the statement segment type corresponding to the current statement state is traversed, it is determined that the statement segment of the statement segment type corresponding to the current statement state is ended, and the current statement state is changed (i.e., the current statement state is switched). After the current statement state is changed, the remaining statement units of the code statement are continuously traversed until all the statement segments contained in the code statement are traversed. The all the statement segments contained in the code statement can include the statement segments of one statement segment type, or the statement segments of a plurality of statement segment types.
[0069] Before the end symbol corresponding to the statement segment type corresponding to the current statement state is traversed, if the end symbol corresponding to another statement segment type is traversed, the position of the end symbol corresponding to the other statement segment type is not taken as the end position of the statement segment of the statement segment type corresponding to the current statement state.
[0070] It should be noted that the end symbol of the first statement segment type corresponding to the first statement state can be a slash ( / ), and the end symbol of the second statement segment type corresponding to the second statement state can be a semicolon (;).
[0071] Next, taking the first statement segment type and the second statement segment type as examples, the process of classifying the statement segment types of the statement segments in the code statement is described. When the statement state is changed, the second statement state can be taken as the default state of the state machine.
[0072] In the process of sequentially traversing the statement units included in the code statement, if it is determined that the current statement state is the first statement state, the statement segment type of the statement segment in which the currently traversed statement unit is located is identified as the first statement segment type corresponding to the first statement state. Then, it is determined whether the specified statement unit is identified before the starting statement unit corresponding to the first statement segment type is traversed. If the specified statement unit is not identified, the preset delimiter is taken as the ending symbol corresponding to the first statement segment type. The starting statement unit corresponding to the first statement segment type can be a statement unit located at the starting position of the statement segment of the first statement segment type. The starting statement unit can include declare, begin, createfunction, create procedure, etc. The specified statement unit can include delimiter. The preset delimiter can include a slash.
[0073] If the specified statement unit is identified, the ending symbol corresponding to the first statement segment type can be determined according to the delimiter defined by the specified statement unit.
[0074] Further, it can be determined whether the delimiter defined by the specified statement unit is the ending symbol (i.e., a semicolon) corresponding to the second statement segment type. If the delimiter defined by the specified statement unit is the ending symbol corresponding to the second statement segment type, the preset delimiter corresponding to the first statement segment type is taken as the ending symbol corresponding to the first statement segment type. If the delimiter defined by the specified statement unit is not the ending symbol corresponding to the second statement segment type, the delimiter defined by the specified statement unit is taken as the ending symbol corresponding to the first statement segment type. The delimiter defined by the specified statement unit can be any defined delimiter, such as “;”, “ / ”, “$$”, etc.
[0075] After the ending symbol corresponding to the first statement segment type is determined, the traversal of the statement units after the starting statement unit continues. When the ending symbol corresponding to the first statement segment type is traversed, it can be determined that the statement segment of the first statement segment type ends, and then the first statement state is changed to the second statement state. That is, the statement state of the state machine is switched to the default state.
[0076] In the process of sequentially traversing the statement units contained in the code statement, if it is determined that the current statement state is the second statement state, the statement segment type of the statement segment in which the currently traversed statement unit is located is identified as a second statement segment type corresponding to the second statement state. Then, a separator preset for the second statement segment type is taken as an ending symbol corresponding to the second statement segment type. The separator preset for the second statement segment type can include a semicolon.
[0077] After the statement unit following the currently traversed statement unit is continuously traversed, when the ending symbol corresponding to the second statement segment type is traversed, it is determined that the statement segment of the second statement segment type ends. Then, when the starting statement unit corresponding to the first statement segment type is traversed after the ending symbol corresponding to the second statement segment type, the current second statement state is changed to the first statement state.
[0078] Wherein, before the statement unit following the currently traversed statement unit is continuously traversed, it can be first judged whether the currently traversed statement unit is the starting statement unit of the first statement segment type. If the currently traversed statement unit is the starting statement unit of the first statement segment type, the current second statement state can be changed to the first statement state. Then, the statement segment type of the statement segment in which the currently traversed statement unit is located is re-identified as the first statement segment type corresponding to the first statement state, and the ending symbol corresponding to the first statement segment type is determined. Finally, the statement unit following the currently traversed statement unit is continuously traversed until the ending symbol corresponding to the first statement segment type is traversed.
[0079] If the currently traversed statement unit is not the starting statement unit of the first statement segment type, the statement segment type of the statement segment in which the currently traversed statement unit is located does not need to be identified as the first statement segment type corresponding to the first statement state, and the statement unit following the currently traversed statement unit is continuously traversed until the ending symbol corresponding to the second statement segment type is traversed.
[0080] In addition, before traversing the statement unit after the currently traversed statement unit, it can be determined whether the currently traversed statement unit is a specified statement unit. If the currently traversed statement unit is not a specified statement unit, it is determined whether the currently traversed statement unit is a starting statement unit of the first statement segment type. If the currently traversed statement unit is a starting statement unit of the first statement segment type, the current second statement state can be changed to a first statement state. Then, the statement segment type of the statement segment in which the currently traversed statement unit is located is re-identified as the first statement segment type corresponding to the first statement state, and the end symbol corresponding to the first statement segment type is determined. Finally, the traversal of the statement unit after the currently traversed statement unit is continued until the end symbol corresponding to the first statement segment type is traversed. If the currently traversed statement unit is not a starting statement unit of the first statement segment type, the statement segment type of the statement segment in which the currently traversed statement unit is located does not need to be identified as the first statement segment type corresponding to the first statement state, and the traversal of the statement unit after the currently traversed statement unit is continued until the end symbol corresponding to the second statement segment type is traversed.
[0081] If the currently traversed statement unit is a specified statement unit, the statement containing the specified statement unit is parsed, the delimiter defined by the specified statement unit is determined, and is saved. Then, it is determined whether the statement unit after the statement containing the specified statement unit is a starting statement unit of the first statement segment type.
[0082] If the statement unit after the statement containing the specified statement unit is a starting statement unit of the first statement segment type, the current second statement state can be changed to a first statement state. Then, the statement segment type of the statement segment in which the currently traversed statement unit is located is re-identified as the first statement segment type corresponding to the first statement state, and the end symbol corresponding to the first statement segment type is determined. Finally, the traversal of the statement unit after the currently traversed statement unit is continued until the end symbol corresponding to the first statement segment type is traversed.
[0083] In determining the end symbol corresponding to the first statement segment type, it can be determined whether the delimiter defined by the specified statement unit is the end symbol corresponding to the second statement segment type (i.e., a semicolon). If the delimiter defined by the specified statement unit is the end symbol corresponding to the second statement segment type, the preset delimiter corresponding to the first statement segment type is taken as the end symbol corresponding to the first statement segment type. If the delimiter defined by the specified statement unit is not the end symbol corresponding to the second statement segment type, the delimiter defined by the specified statement unit is taken as the end symbol corresponding to the first statement segment type.
[0084] If the statement unit following the specified statement unit is not a starting statement unit of the first statement section type, the statement section type of the statement section in which the currently traversed statement unit is located is not identified as the first statement section type corresponding to the current statement state, and the delimiter defined by the specified statement unit is not taken as the ending symbol corresponding to the second statement section type. The traversal of the statement unit following the currently traversed statement unit is continued until the ending symbol corresponding to the second statement section type is reached.
[0085] S210: For each statement section type, each statement section corresponding to the statement section type is split from the code statement.
[0086] S212: The database is operated according to each statement section corresponding to each statement section type that is split.
[0087] In the embodiments of the present specification, after the statement units included in the code statement are traversed in sequence, all the statement sections included in the code statement can be classified according to the traversal result, and each statement section belonging to the statement section type corresponding to the different statement state is determined, i.e., each statement section belonging to the first statement section type and each statement section belonging to the second statement section type in the code statement is determined. Then, for each statement section type, each statement section corresponding to the statement section type is split from the code statement. Finally, the database is operated according to each statement section corresponding to each statement section type that is split. The operations are, for example, data query, update, access, privacy data protection, etc.
[0088] Specifically, each statement section corresponding to each statement section type can be sent to the server of the database. The server of the database processes the data stored in the database for each statement section corresponding to each statement section type, obtains a processing result, and feeds back the processing result to the client of the database, so as to display the processing result to the user.
[0089] As shown in the above Figure 2 As shown in the above
[0090] Based on the description of steps S202-S208, Figure 2 Two flow diagrams for traversing code statements are provided in this specification. Figure 3 A flow diagram for traversing code statements without including a specified statement unit is provided for the embodiments of this specification, Figure 4 A flow diagram for traversing code statements including a specified statement unit is provided for the embodiments of this specification.
[0091] Next, the flow diagram for traversing code statements without including a specified statement unit is described in conjunction with the code statements shown in Figure 5 Figure 3 The flow diagram for traversing code statements without including a specified statement unit is described in conjunction with the code statements shown in
[0092] In step S202, Figure 3 the code statements are traversed one by one. Since the default state of the state machine is the second statement state, it is determined whether the current statement state is the second statement state. If the current statement state is the second statement state, the statement segment type of the statement segment in which the statement unit currently being traversed (i.e., the first statement unit begin in Figure 5 ) is identified as the second statement segment type, and the end symbol corresponding to the second statement segment type is determined. It is determined whether the statement unit currently being traversed is the start statement unit of the first statement segment type. If the statement unit currently being traversed is the start statement unit of the first statement segment type (i.e., begin in Figure 5 is the start statement unit), the current statement state is changed to the first statement state, and the statement segment type of the statement segment in which the statement unit currently being traversed (i.e., the first statement unit begin in Figure 5 ) is identified as the first statement segment type, and the end symbol corresponding to the first statement segment type is determined. The statement units after the start statement unit are traversed, and it is determined whether the statement unit currently being traversed is the end symbol corresponding to the first statement segment type. If the statement unit currently being traversed is the end symbol corresponding to the first statement segment type (i.e., / in Figure 5 ), it is determined that the first statement segment type ends, and a statement segment of the first statement segment type (i.e., begin...dbms_output.put_line('hello world');end; in Figure 5 ) can be split from the code statements. Then, the current statement state is changed to the second statement state, and the statement segment type of the statement segment in which the statement unit currently being traversed (i.e., the select position in Figure 5 ) is identified as the second statement segment type, and the end symbol corresponding to the second statement segment type is determined. Then, the above determination steps are repeated. That is, it is determined whether the statement unit currently being traversed (i.e., the select position in Figure 5 whether the current traversed statement unit is a start statement unit of the first statement segment type, if the current traversed statement unit is not the start statement unit of the first statement segment type (the "select" in Figure 5 is not the start statement unit), continue to traverse the next statement unit, and when the end symbol (the ";" in Figure 5 ) corresponding to the second statement segment type is traversed, it is determined that the second statement segment type ends, and a statement segment of the second statement segment type (the "select 1 from dual;" in Figure 5 ) can be split from the code statement.
[0093] In addition, the code statement shown in Figure 6 is used to illustrate the code statement traversal process of the code statement containing the specified statement unit shown in Figure 4 .
[0094] In Figure 4 , each statement unit in the code statement is traversed in turn, and since the default state of the state machine is the second statement state, it is determined whether the current statement state is the second statement state, if the current statement state is the second statement state, the statement segment type of the statement segment in which the statement unit currently traversed in the code statement (i.e., the first statement unit delimiter in Figure 5 ) is identified as the second statement segment type, and the end symbol corresponding to the second statement segment type is determined. Then, it is determined whether the currently traversed statement unit is the specified statement unit (for example, the specified statement unit is delimiter), if the currently traversed statement unit is the specified statement unit (the delimiter in Figure 6 is the specified statement unit), the statement containing the specified statement unit is parsed, the delimiter (the "$$" in Figure 6 ) defined by the specified statement unit is determined, and is saved. The next statement unit (the begin in Figure 6 ) after the statement containing the specified statement unit is continued to be traversed. It is determined whether the currently traversed statement unit (i.e., the begin in Figure 6 ) is the specified statement unit, if the currently traversed statement unit is not the specified statement unit, it is determined whether the currently traversed statement unit (i.e., the begin in Figure 6 ) is a start statement unit of the first statement segment type, if the currently traversed statement unit (i.e., the begin in Figure 6 is the start statement unit of the first statement segment type) is the start statement unit of the first statement segment type, the current statement state is changed from the second statement state to the first statement state, and the currently traversed statement unit (i.e., the begin in Figure 6The statement block containing the `begin` statement is identified as the first statement block type. Then, it is determined whether the delimiter defined by the specified statement unit is the end-of-line character corresponding to the second statement block type. If the delimiter defined by the specified statement unit is not the end-of-line character corresponding to the second statement block type, then the delimiter defined by the specified statement unit (`begin`) is... Figure 6 The "$$" symbol in the first statement segment is used as the terminator for the first statement segment type. The process continues iterating through the statement units following the initial statement unit, checking if each encountered statement unit is the terminator for the first statement segment type. If the encountered statement unit is the terminator for the first statement segment type (i.e., ...), then the process continues. Figure 6 When "$$" is used, the end of the first statement segment type is determined, and a statement segment of the first statement segment type can be obtained from the code statements. Figure 6 The code snippet shows "begin……dbms_output.put_line('hello world'); end;". Afterwards, the current statement state is changed from the first statement state to the second statement state, and the currently traversed statement unit (i.e., ...) is... Figure 6 The statement segment containing the second delimiter is identified as the second statement segment type, and the terminator corresponding to the second statement segment type is determined. The above judgment steps are repeated. That is, it is determined whether the currently traversed statement unit is the specified statement unit. If the currently traversed statement unit is the specified statement unit (…), then… Figure 6 The second delimiter in the code specifies a statement unit. It parses statements containing the specified statement unit to determine the delimiter defined by that unit. Figure 6 The semicolon (;) is used to save the statement. The process continues iterating through the next statement unit following the statement containing the specified statement unit. Figure 6 The `select` operator in the `select` method determines the currently traversed statement unit. Figure 6 If the currently iterated statement unit is not the specified statement unit, then it checks whether the currently iterated statement unit is the starting statement unit of the first statement segment type. Figure 6 If the `select` statement in the specified statement unit is not the starting statement unit, the current statement state remains unchanged as the second statement state, and the delimiter defined in the specified statement unit will be changed. Figure 6 The semicolon (;) in the code serves as the terminator for the second statement segment type. The process continues iterating through the next statement unit until the terminator for the second statement segment type is encountered. Figure 5 When the semicolon (;) is used, the end of the second statement segment type is determined, and a statement segment of the second statement segment type is obtained from the code statement. Figure 7 (e.g., "select 1 from dual;").
[0095] The database operation method provided in the embodiments of the present specification is based on the same idea, and the present specification also provides a corresponding device, a storage medium and an electronic device.
[0096] Figure 2 A structural schematic diagram of a database operation device provided in the embodiments of the present specification, the device comprises:
[0097] The acquisition module 701 is configured to acquire a code statement.
[0098] The first determination module 702 is configured to traverse a statement unit included in the code statement and determine a current statement state.
[0099] The recognition module 703 is configured to recognize a statement segment type of a statement segment in which the currently traversed statement unit is located as a statement segment type corresponding to the statement state.
[0100] The second determination module 704 is configured to determine an end symbol corresponding to the statement segment type.
[0101] The traversal module 705 is configured to determine that a statement segment of the statement segment type ends when the end symbol is traversed, change the statement state, and continue to traverse the remaining statement units of the code statement until all statement segments included in the code statement are traversed.
[0102] The splitting module 706 is configured to split each statement segment corresponding to each statement segment type from the code statement for each statement segment type.
[0103] The operation module 707 is configured to operate the database according to each statement segment corresponding to each statement segment type that is split.
[0104] Optionally, the statement state comprises a first statement state and a second statement state, the first statement state corresponds to a first statement segment type, and the second statement state corresponds to a second statement segment type.
[0105] Optionally, the second determination module 704 is specifically configured to determine that a statement segment of the first statement segment type ends when an end symbol corresponding to the first statement segment type is traversed, change the first statement state to the second statement state, and determine that a statement segment of the second statement segment type ends when an end symbol corresponding to the second statement segment type is traversed, and change the second statement state to the first statement state when a starting statement unit corresponding to the first statement segment type is traversed after the end symbol corresponding to the second statement segment type.
[0106] Optionally, the second determining module 704 is specifically configured to: if it is determined that the sentence segment type is a first sentence segment type, determine whether a specified sentence unit is recognized before a starting sentence unit corresponding to the first sentence segment type is traversed; and if the specified sentence unit is not recognized before the starting sentence unit corresponding to the first sentence segment type is traversed, determine a preset delimiter as an ending symbol corresponding to the first sentence segment type.
[0107] Optionally, the second determining module 704 is further configured to: if the specified sentence unit is recognized before the starting sentence unit corresponding to the first sentence segment type is traversed, determine an ending symbol corresponding to the first sentence segment type according to a delimiter defined by the specified sentence unit.
[0108] Optionally, the specified sentence unit includes a delimiter.
[0109] Optionally, the first sentence segment type includes a PL / SQL sentence segment type, and the second sentence segment type includes a SQL sentence segment type.
[0110] The specification also provides a computer readable storage medium, which stores a computer program. The computer program is executed by a processor and can be used to execute the above-mentioned Figure 2 The database operation method is provided.
[0111] Based on the database operation method shown in the specification, the specification also provides a structure diagram of the unmanned device. Figure 8 As shown in the structure diagram of the unmanned device, the specification embodiment further provides Figure 8 As shown in the structure diagram of the unmanned device, the specification embodiment further provides Figure 2 At the hardware level, the unmanned device includes a processor, an internal bus, a network interface, a memory and a non-volatile memory, and of course can also include other hardware required by the business. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs to implement the above-mentioned Figure 1 The database operation method is provided.
[0112] Of course, in addition to the software implementation, the specification does not exclude other implementation manners, such as logic devices or software and hardware combined manner, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but also can be hardware or logic device.
[0113] In the 1990s, it was quite obvious to distinguish whether an improvement in a technology was in hardware (e.g., improvement in circuit structures of diodes, transistors, switches, etc.) or in software (improvement in method flow). However, as technology has evolved, many improvements in method flow today can be considered as direct improvements in hardware circuit structures. Designers almost always obtain the corresponding hardware circuit structures by programming the improved method flow into hardware circuits. Therefore, it cannot be said that an improvement in a method flow cannot be implemented by hardware entity modules. For example, a programmable logic device (PLD) (e.g., a field programmable gate array (FPGA)) is an integrated circuit whose logic function is determined by user programming of the device. A digital system is "integrated" on a PLD by the designer programming it, rather than by asking a chip manufacturer to design and fabricate a custom integrated circuit chip. Moreover, instead of manually fabricating integrated circuit chips, this programming is now mostly implemented by "logic compiler" software, which is similar to software compilers used in program development, and the original code to be compiled is written in a specific programming language, which is called a hardware description language (HDL), and there are many such languages, 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., and the most commonly used are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should be aware that, as long as the method flow is logically programmed in the above-mentioned hardware description languages and programmed into an integrated circuit, a hardware circuit implementing the logical method flow can be easily obtained.
[0114] The controller can be implemented in any suitable way, e.g. the controller can take the form of 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, an application specific integrated circuit (ASIC), a programmable logic controller and an embedded microcontroller, examples of controllers include but are not limited to the following microcontrollers: ARC625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320, the memory controller can also be implemented as part of the control logic of the memory. The skilled person will also appreciate that in addition to implementing the controller in pure computer readable program code, it is also possible to implement the controller in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers and embedded microcontrollers to perform the same functions by logically programming the method steps. The controller can thus be considered a hardware component, and the means included therein for performing various functions can be considered structures within the hardware component. Alternatively, or even additionally, the means for performing various functions can be considered both software modules that implement the methods and structures within the hardware component.
[0115] The systems, apparatuses, modules or units illustrated by the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer can be, for example, a personal computer, a laptop computer, a cellular phone, 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.
[0116] For the sake of description, the above apparatuses are described in functional division and are described respectively as various units. Of course, the functions of the units can be implemented in the same or multiple software and / or hardware when implementing the present specification.
[0117] Those skilled in the art will understand that the embodiments of the present specification can be provided as a method, a system or a computer program product. Therefore, the present specification can take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware aspects. Moreover, the present specification can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0118] This specification is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this specification. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can 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 a machine for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0119] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0120] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes The steps of the function specified in one or more boxes.
[0121] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0122] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0123] Computer-readable media includes permanent and non-permanent, movable and non-movable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules 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 technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible to a computing device. According to the definition herein, computer-readable media does not include transitory media such as modulated data signals and carriers.
[0124] It should also be noted that the terms "comprising", "comprising" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or apparatus that includes a list of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or apparatus. Without more limitations, the element defined by the statement "comprising a" does not exclude the presence of additional identical elements in the process, method, article or apparatus that includes the element.
[0125] Those skilled in the art will appreciate that embodiments of the present specification can be provided as methods, systems or computer program products. Therefore, the present specification can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Moreover, the present specification can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0126] The present specification can be described in the general context of computer-executable instructions, such as program modules, executed by computers. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The present specification can also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in both local and remote computer storage media, including storage devices.
[0127] The various embodiments described in this specification are described using a numbering of embodiments approach: these are each individually integrated contributions pertaining to different but related aspects of the description. Each of the various embodiments can stand on its own, and each can be combined with the subject matter of other embodiments to produce further embodiments. Where the same numbers appear in different embodiments, such numbers are used for the sake of ease of understanding only and do not imply that the embodiments in which such numbers appear are the same or similar.
[0128] The above description is embodied in the form of only a description of embodiments of the present specification, and is not intended to limit the present specification. Various changes and modifications can be made by those skilled in the art based on the present specification. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification should be included in the scope of the claims of the present specification.
Claims
1. A database operation method, comprising: obtaining a code statement; traversing statement units contained in the code statement and determining a current statement state; the statement state comprises a first statement state and a second statement state, the first statement state corresponds to a first statement segment type, and the second statement state corresponds to a second statement segment type; the first statement segment type comprises a PL / SQL statement segment type, and the second statement segment type comprises a SQL statement segment type; identifying a statement segment type of a statement segment in which a currently traversed statement unit is located as a statement segment type corresponding to the statement state; determining an end symbol corresponding to the statement segment type; when the end symbol is traversed, determining that a statement segment of the statement segment type ends, changing the statement state, and continuing to traverse remaining statement units of the code statement until all statement segments contained in the code statement are traversed; for each statement segment type, splitting each statement segment corresponding to the statement segment type from the code statement; operating the database according to each statement segment corresponding to each statement segment type that is split. 2.The method of claim 1, when the end symbol is traversed, determining that the statement segment of the statement segment type ends and changing the statement state, specifically comprising: when the end symbol corresponding to the first statement segment type is traversed, determining that the statement segment of the first statement segment type ends, and changing the first statement state to the second statement state; when the end symbol corresponding to the second statement segment type is traversed, determining that the statement segment of the second statement segment type ends, and when a starting statement unit corresponding to the first statement segment type is traversed after the end symbol corresponding to the second statement segment type, changing the second statement state to the first statement state. 3.The method of claim 1, determining the end symbol corresponding to the statement segment type, specifically comprising: if it is determined that the statement segment type is the first statement segment type, judging whether a specified statement unit is identified before a starting statement unit corresponding to the first statement segment type is traversed; if the specified statement unit is not identified before the starting statement unit corresponding to the first statement segment type is traversed, determining a preset delimiter as the end symbol corresponding to the first statement segment type. 4.The method of claim 3, further comprising: if the specified statement unit is identified before the starting statement unit corresponding to the first statement segment type is traversed, determining a delimiter defined by the specified statement unit as the end symbol corresponding to the first statement segment type.
5. The method of claim 4, the specifying statement unit comprising: delimiter. 6.A database operation apparatus, comprising: an obtaining module, configured to obtain a code statement; a first determining module, configured to traverse statement units contained in the code statement and determine a current statement state. The statement state comprises a first statement state and a second statement state, the first statement state corresponds to a first statement segment type, and the second statement state corresponds to a second statement segment type. The identification module is configured to identify a statement segment type of a statement segment in which a currently iterated statement unit is located as the statement segment type corresponding to the statement state. The second determination module is configured to determine an end delimiter corresponding to the statement segment type. The iteration module is configured to determine that the statement segment of the statement segment type ends when the end delimiter is iterated to, change the statement state, and continue to iterate the remaining statement units of the code statement until all statement segments contained in the code statement are iterated out. The splitting module is configured to split each statement segment corresponding to each statement segment type from the code statement. The operation module is configured to operate the database according to each statement segment corresponding to each statement segment type.
7. The apparatus of claim 6, wherein the traversing module is specifically configured for determining that a statement segment of the first statement segment type ends when a terminal corresponding to the first statement segment type is traversed to, and changing the first statement state to the second statement state. When the end delimiter corresponding to the second statement segment type is iterated to, it is determined that the statement segment of the second statement segment type ends, and when the start statement unit corresponding to the first statement segment type is iterated to after the end delimiter corresponding to the second statement segment type, the second statement state is changed to the first statement state. The statement state comprises a first statement state and a second statement state, the first statement state corresponds to a first statement segment type, and the second statement state corresponds to a second statement segment type.
8. The apparatus of claim 6, the second determination module is specifically configured to determine whether a specified statement unit is identified before the start statement unit corresponding to the first statement segment type is iterated out if it is determined that the statement segment type is the first statement segment type; and determine a preset delimiter as the end delimiter corresponding to the first statement segment type if the specified statement unit is not identified before the start statement unit corresponding to the first statement segment type is iterated out.
9. The apparatus of claim 8, the second determination module is further configured to determine the delimiter corresponding to the first statement segment type according to a delimiter defined by the specified statement unit if the specified statement unit is identified before the start statement unit corresponding to the first statement segment type is iterated out.
10. The apparatus of claim 9, the assignment statement element comprising: delimiter.
11. A computer readable storage medium, the storage medium storing a computer program, the computer program being executed by a processor to implement the method of any one of claims 1-5.
12. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, the processor implementing the method of any one of claims 1-5 when executing the program.
Citation Information
Patent Citations
Database flash-back method and device based on WAL log file
CN115454960A
Data updating method and device, storage medium and equipment
CN115587107A