forked from opengaussexamples/examples
revise
This commit is contained in:
parent
9a06b2e574
commit
2566ca965b
|
|
@ -4,13 +4,18 @@
|
|||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="d8d12963-4777-48e3-9669-309cf5e41d60" name="更改" comment="add Loop">
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/Document/Exception in Oracle" afterDir="false" />
|
||||
<list default="true" id="d8d12963-4777-48e3-9669-309cf5e41d60" name="更改" comment="add Exception document">
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/Parser/AST/Exception/CustomExceptionNode.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/Parser/AST/Exception/ExceptionActionNode.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/Parser/AST/Exception/ExceptionNode.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/Parser/AST/Exception/Invalid_numberNode.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/Parser/AST/Exception/OtherExceptionNode.java" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/src/main/java/Parser/AST/Exception/Zero_divideNode.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/Document/Todolist" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Document/Todolist" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/Document/Exception in Oracle" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Document/Exception in Oracle" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/Generator/OpenGaussGenerator.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Generator/OpenGaussGenerator.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/Lexer/OracleLexer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Lexer/OracleLexer.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Main.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/main/java/Parser/OracleParser.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/Parser/OracleParser.java" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
|
@ -108,20 +113,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1723106789329</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00024" summary="add todolist">
|
||||
<created>1725896687932</created>
|
||||
<option name="number" value="00024" />
|
||||
<option name="presentableId" value="LOCAL-00024" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1725896687932</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00025" summary="add select">
|
||||
<created>1725937361130</created>
|
||||
<option name="number" value="00025" />
|
||||
<option name="presentableId" value="LOCAL-00025" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1725937361130</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00026" summary="add select">
|
||||
<created>1725955766774</created>
|
||||
<option name="number" value="00026" />
|
||||
|
|
@ -451,7 +442,21 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1726326745123</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="73" />
|
||||
<task id="LOCAL-00073" summary="add Exception document">
|
||||
<created>1726413056810</created>
|
||||
<option name="number" value="00073" />
|
||||
<option name="presentableId" value="LOCAL-00073" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1726413056811</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00074" summary="add Exception document">
|
||||
<created>1726413069101</created>
|
||||
<option name="number" value="00074" />
|
||||
<option name="presentableId" value="LOCAL-00074" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1726413069101</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="75" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
|
@ -466,7 +471,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="refractor" />
|
||||
<MESSAGE value="add select convert rules" />
|
||||
<MESSAGE value="add update ast class" />
|
||||
<MESSAGE value="add update convert rules" />
|
||||
|
|
@ -491,7 +495,8 @@
|
|||
<MESSAGE value="add Loop keywords" />
|
||||
<MESSAGE value="add Loop ast classes" />
|
||||
<MESSAGE value="add Loop" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="add Loop" />
|
||||
<MESSAGE value="add Exception document" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="add Exception document" />
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<watches-manager>
|
||||
|
|
|
|||
|
|
@ -11,10 +11,3 @@ EXCEPTION
|
|||
-- other exceptions
|
||||
WHEN OTHERS THEN
|
||||
DBMS_OUTPUT.PUT_LINE('Caught an exception: ' || SQLERRM);
|
||||
|
||||
Example:
|
||||
EXCEPTION
|
||||
WHEN ZERO_DIVIDE THEN
|
||||
DBMS_OUTPUT.PUT_LINE('Caught an exception: Division by zero');
|
||||
WHEN OTHERS THEN
|
||||
DBMS_OUTPUT.PUT_LINE('Caught an exception: ' || SQLERRM);
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package Generator;
|
||||
|
||||
import Interface.ColumnType;
|
||||
import Lexer.OracleLexer;
|
||||
import Lexer.Token;
|
||||
import Parser.AST.ASTNode;
|
||||
import Parser.AST.AlterTable.AlterAddColumnNode;
|
||||
|
|
@ -233,14 +234,43 @@ public class OpenGaussGenerator {
|
|||
break;
|
||||
}
|
||||
}
|
||||
List<Token> tokens = new ArrayList<>();
|
||||
tokens.add(new Token(Token.TokenType.KEYWORD, "RAISE"));
|
||||
tokens.add(new Token(Token.TokenType.KEYWORD, "NOTICE"));
|
||||
tokens.add(new Token(Token.TokenType.STRING, "'%'"));
|
||||
tokens.add(new Token(Token.TokenType.SYMBOL, ","));
|
||||
tokens.add(new Token(Token.TokenType.IDENTIFIER, printObj));
|
||||
tokens.add(new Token(Token.TokenType.SYMBOL, ";"));
|
||||
node.setTokens(tokens);
|
||||
if (!printObj.contains("||")) {
|
||||
List<Token> tokens = new ArrayList<>();
|
||||
tokens.add(new Token(Token.TokenType.KEYWORD, "RAISE"));
|
||||
tokens.add(new Token(Token.TokenType.KEYWORD, "NOTICE"));
|
||||
tokens.add(new Token(Token.TokenType.STRING, "'%'"));
|
||||
tokens.add(new Token(Token.TokenType.SYMBOL, ","));
|
||||
tokens.add(new Token(Token.TokenType.IDENTIFIER, printObj));
|
||||
tokens.add(new Token(Token.TokenType.SYMBOL, ";"));
|
||||
node.setTokens(tokens);
|
||||
}
|
||||
else {
|
||||
OracleLexer lexer = new OracleLexer(printObj.replace("||", " "));
|
||||
String output = "";
|
||||
List<Token> outputObj = new ArrayList<>();
|
||||
for (Token token: lexer.getTokens()) {
|
||||
if (token.hasType(Token.TokenType.STRING)) {
|
||||
output += token.getValue().replace("'", "");
|
||||
}
|
||||
else if (token.hasType(Token.TokenType.IDENTIFIER)) {
|
||||
output += "%";
|
||||
outputObj.add(token);
|
||||
}
|
||||
else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
List<Token> tokens = new ArrayList<>();
|
||||
tokens.add(new Token(Token.TokenType.KEYWORD, "RAISE"));
|
||||
tokens.add(new Token(Token.TokenType.KEYWORD, "NOTICE"));
|
||||
tokens.add(new Token(Token.TokenType.STRING, "'" + output + "'"));
|
||||
for (Token token: outputObj) {
|
||||
tokens.add(new Token(Token.TokenType.SYMBOL, ","));
|
||||
tokens.add(token);
|
||||
}
|
||||
tokens.add(new Token(Token.TokenType.SYMBOL, ";"));
|
||||
node.setTokens(tokens);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ public class OracleLexer {
|
|||
, ":=", "IF", "ELSIF", "BEGIN", ".."
|
||||
// Loop
|
||||
, "LOOP", "EXIT", "WHILE", "FOR", "IN", "CONTINUE"
|
||||
// Exception
|
||||
, "EXCEPTION", "SQLERRM", "ZERO_DIVIDE", "INVALID_NUMBER"
|
||||
};
|
||||
private static final Pattern TOKEN_PATTERN = Pattern.compile(
|
||||
"(NUMBER\\(.*?\\))|" + // NUMBER() function
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
package Parser.AST.Exception;
|
||||
|
||||
import Lexer.Token;
|
||||
import Parser.AST.ASTNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CustomExceptionNode extends ASTNode {
|
||||
public CustomExceptionNode () {
|
||||
super();
|
||||
setTokens(new ArrayList<>());
|
||||
}
|
||||
|
||||
public CustomExceptionNode (ASTNode node) {
|
||||
super(node);
|
||||
setTokens(new ArrayList<>());
|
||||
}
|
||||
|
||||
public CustomExceptionNode (List<Token> tokens) {
|
||||
super(tokens);
|
||||
setTokens(new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ASTNode node, StringBuilder queryString) {
|
||||
queryString.append(toString() + " ");
|
||||
for (ASTNode child : node.getChildren()) {
|
||||
child.visit(child, queryString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package Parser.AST.Exception;
|
||||
|
||||
public class ExceptionActionNode {
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package Parser.AST.Exception;
|
||||
|
||||
public class ExceptionNode {
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package Parser.AST.Exception;
|
||||
|
||||
public class Invalid_numberNode {
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package Parser.AST.Exception;
|
||||
|
||||
public class OtherExceptionNode {
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
package Parser.AST.Exception;
|
||||
|
||||
public class Zero_divideNode {
|
||||
}
|
||||
Loading…
Reference in New Issue