01: /*
02: * $Author$
03: * $Id$
04: * This is free software, as software should be; you can redistribute
05: * it and/or modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08:
09: * See LICENSE.txt for the full license covering this software/program/code.
10: */
11:
12: package isql.commands;
13:
14: import isql.Command;
15: import util.PerlWrapper;
16: import isql.*;
17: import util.*;
18: import javax.swing.JTextArea;
19: import javax.swing.table.TableModel;
20: import java.awt.Font;
21: import java.util.*;
22:
23: /**
24: * The command object associated with the abbr command, used to
25: * store abbreviations.
26: * @author rahul kumar <rahul_kumar@yahoo.com>
27: * @see XXX
28: */
29:
30: public class ScriptCommand implements Command {
31:
32: /** ctor/constructor.
33: */
34: public ScriptCommand() {
35: }
36:
37: public String[] getCommandList() {
38: return commands;
39: }
40:
41: public void execute(SQLForm form, String fword, String SQLString) {
42: _form = form;
43: SQLTabbedPane tp = _form.tp;
44: SQLJDBC myjdbc = _form.myjdbc;
45:
46: if (fword.equals("insertscript")) {
47: final String usage = "Usage:insertscript table targetfile";
48: String[] tmp = PerlWrapper.perlMatch(
49: "insertscript\\s+(\\w+)\\s+(.+)", SQLString);
50: if (tmp != null) {
51: //System.out.println("got:"+ tmp[0]+":"+ tmp[1]);
52: int count = myjdbc.createInsertScript(tmp[0], tmp[1],
53: 0, 1000); // XXX
54: _form.setErrorArea('\n' + "Written " + count
55: + " rows to " + tmp[1]);
56: } else {
57: _form
58: .popup(usage
59: + "- Please give a source tablename and filename to write to.");
60: }
61: return;
62: }
63: // create a create table script
64: if (fword.equals("createscript")) {
65: final String usage = "Usage:createscript table targetfile";
66: String[] tmp = PerlWrapper.perlMatch(
67: "createscript\\s+(\\w+)\\s+(.+)", SQLString);
68: if (tmp != null) {
69: //System.out.println("got:"+ tmp[0]+":"+ tmp[1]);
70: myjdbc.createCreateScript(tmp[0], tmp[1]);
71: _form.setErrorArea('\n' + "Written create script to "
72: + tmp[1]);
73: } else {
74: _form
75: .popup(usage
76: + "- Please give a source tablename and filename to write to.");
77: }
78: return;
79: }
80:
81: }
82:
83: public String getUsage(String s) {
84: return usage;
85: }
86:
87: String commands[] = { "insertscript", "createscript" };
88: SQLForm _form;
89:
90: final String usage = "<insertscript|createscript> <table> <filename>";
91:
92: ////// START INSTANCE VARIABLES //////
93:
94: ////// START CONSTANTS AND CLASS LEVEL VARIABLES //////
95: static final String P = "ScriptCommand"; // used in exception strings
96:
97: } // end of class
|