01: /*
02: * WbRemoveVar.java
03: *
04: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
05: *
06: * Copyright 2002-2008, Thomas Kellerer
07: * No part of this code maybe reused without the permission of the author
08: *
09: * To contact the author please send an email to: support@sql-workbench.net
10: *
11: */
12: package workbench.sql.wbcommands;
13:
14: import java.sql.SQLException;
15: import workbench.resource.ResourceMgr;
16: import workbench.sql.SqlCommand;
17: import workbench.sql.VariablePool;
18: import workbench.sql.StatementRunnerResult;
19: import workbench.util.SqlUtil;
20:
21: /**
22: *
23: * @author support@sql-workbench.net
24: */
25: public class WbRemoveVar extends SqlCommand {
26: public static final String VERB = "WBVARDELETE";
27:
28: public WbRemoveVar() {
29: }
30:
31: public String getVerb() {
32: return VERB;
33: }
34:
35: protected boolean isConnectionRequired() {
36: return false;
37: }
38:
39: public StatementRunnerResult execute(String aSql)
40: throws SQLException {
41: StatementRunnerResult result = new StatementRunnerResult();
42: String var = SqlUtil.stripVerb(aSql);
43:
44: String msg = null;
45:
46: if (var == null || var.length() == 0) {
47: result.addMessage(ResourceMgr
48: .getString("ErrVarRemoveWrongParameter"));
49: result.setFailure();
50: return result;
51: } else {
52: boolean removed = VariablePool.getInstance().removeValue(
53: var);
54: if (removed) {
55: msg = ResourceMgr.getString("MsgVarDefVariableRemoved");
56: } else {
57: msg = ResourceMgr
58: .getString("MsgVarDefVariableNotRemoved");
59: }
60: msg = msg.replaceAll("%var%", var);
61: }
62:
63: result.addMessage(msg);
64: result.setSuccess();
65:
66: return result;
67: }
68:
69: }
|