|
23 | 23 | import java.util.regex.Pattern;
|
24 | 24 | import java.util.regex.PatternSyntaxException;
|
25 | 25 | import java.util.stream.Collectors;
|
| 26 | +import javax.script.ScriptEngine; |
| 27 | +import javax.script.ScriptEngineManager; |
26 | 28 |
|
27 | 29 | import org.jline.builtins.Completers;
|
28 | 30 | import org.jline.keymap.KeyMap;
|
|
75 | 77 | import static sqlline.BuiltInProperty.PROPERTIES_FILE;
|
76 | 78 | import static sqlline.BuiltInProperty.RIGHT_PROMPT;
|
77 | 79 | import static sqlline.BuiltInProperty.ROW_LIMIT;
|
| 80 | +import static sqlline.BuiltInProperty.SCRIPT_ENGINE; |
78 | 81 | import static sqlline.BuiltInProperty.SHOW_COMPLETION_DESCR;
|
79 | 82 | import static sqlline.BuiltInProperty.SHOW_ELAPSED_TIME;
|
80 | 83 | import static sqlline.BuiltInProperty.SHOW_HEADER;
|
@@ -130,6 +133,7 @@ public class SqlLineOpts implements Completer {
|
130 | 133 | put(NUMBER_FORMAT, SqlLineOpts.this::setNumberFormat);
|
131 | 134 | put(OUTPUT_FORMAT, SqlLineOpts.this::setOutputFormat);
|
132 | 135 | put(PROPERTIES_FILE, SqlLineOpts.this::setPropertiesFile);
|
| 136 | + put(SCRIPT_ENGINE, SqlLineOpts.this::setScriptEngine); |
133 | 137 | put(SHOW_COMPLETION_DESCR,
|
134 | 138 | SqlLineOpts.this::setShowCompletionDesc);
|
135 | 139 | put(TABLE_STYLE, SqlLineOpts.this::setTableStyle);
|
@@ -523,7 +527,8 @@ public void set(SqlLineProperty key, Object value) {
|
523 | 527 | ? (String) value : String.valueOf(value);
|
524 | 528 | valueToSet = DEFAULT.equalsIgnoreCase(strValue)
|
525 | 529 | ? key.defaultValue() : value;
|
526 |
| - if (!key.getAvailableValues().isEmpty() |
| 530 | + if (!DEFAULT.equalsIgnoreCase(strValue) |
| 531 | + && !key.getAvailableValues().isEmpty() |
527 | 532 | && !key.getAvailableValues().contains(valueToSet.toString())) {
|
528 | 533 | sqlLine.error(
|
529 | 534 | sqlLine.loc("unknown-value",
|
@@ -1083,6 +1088,24 @@ public Pattern getCompiledConfirmPattern() {
|
1083 | 1088 | public String getHistoryFlags() {
|
1084 | 1089 | return get(HISTORY_FLAGS);
|
1085 | 1090 | }
|
| 1091 | + |
| 1092 | + public String getScriptEngine() { |
| 1093 | + return get(SCRIPT_ENGINE); |
| 1094 | + } |
| 1095 | + |
| 1096 | + public void setScriptEngine(String engineName) { |
| 1097 | + if (DEFAULT.equalsIgnoreCase(engineName)) { |
| 1098 | + set(SCRIPT_ENGINE, SCRIPT_ENGINE.defaultValue()); |
| 1099 | + return; |
| 1100 | + } |
| 1101 | + final ScriptEngineManager engineManager = new ScriptEngineManager(); |
| 1102 | + ScriptEngine scriptEngine = engineManager.getEngineByName(engineName); |
| 1103 | + if (scriptEngine == null && engineManager.getEngineFactories().isEmpty()) { |
| 1104 | + sqlLine.error(sqlLine.loc("not-supported-script-engine-no-available", |
| 1105 | + engineName)); |
| 1106 | + } |
| 1107 | + set(SCRIPT_ENGINE, engineName); |
| 1108 | + } |
1086 | 1109 | }
|
1087 | 1110 |
|
1088 | 1111 | // End SqlLineOpts.java
|
0 commit comments