Skip to content

Commit 6f501be

Browse files
committed
SqlToJsonParser Lib
1 parent e3ef973 commit 6f501be

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

.idea/workspace.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SqlToJsonParser.jar

-538 KB
Binary file not shown.
564 Bytes
Binary file not shown.
Binary file not shown.

src/com/inzapp/sqlToJsonParser/core/SqlToJsonParser.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,50 @@
11
package com.inzapp.sqlToJsonParser.core;
22

3+
import com.inzapp.sqlToJsonParser.config.Config;
4+
import org.json.JSONObject;
5+
36
import java.io.BufferedReader;
47
import java.io.FileOutputStream;
58
import java.io.FileReader;
69

710
public class SqlToJsonParser {
11+
/**
12+
* main method
13+
* used for executable jar
14+
*
15+
* @param args not used
16+
*/
17+
public static void main(String[] args) {
18+
String inputFileName = Config.INPUT_FILE_NAME;
19+
String outputFileName = Config.OUTPUT_FILE_NAME;
20+
if (args != null && args.length == 2) {
21+
inputFileName = args[0];
22+
outputFileName = args[1];
23+
}
24+
25+
SqlToJsonParser sqlToJsonParser = new SqlToJsonParser();
26+
SqlVisitor sqlVisitor = new SqlVisitor();
27+
try {
28+
String sql = sqlToJsonParser.readSqlFromFile(inputFileName);
29+
if (sql == null)
30+
throw new Exception("input file does not exist");
31+
32+
JSONObject json = sqlVisitor.parse(sql);
33+
if (json == null)
34+
throw new Exception("sql syntax error");
35+
36+
String jsonString = json.toString(4);
37+
System.out.println("input sql\n\n" + sql);
38+
System.out.println("output json\n\n" + jsonString);
39+
40+
sqlToJsonParser.saveFile(jsonString, outputFileName);
41+
System.out.println("parse success");
42+
} catch (Exception e) {
43+
sqlToJsonParser.saveFile(Config.SQL_SYNTAX_ERROR, outputFileName);
44+
System.out.println(e.getMessage());
45+
}
46+
}
47+
848
/**
949
* used for java code
1050
*

0 commit comments

Comments
 (0)