1 | public class ScriptDB2ViewAction extends SquirrelAction↵ | | 1 | public class ScriptSybaseASEProcedureAction extends SquirrelAction↵
|
2 | {↵ | | 2 | {↵
|
3 | ↵ | | 3 | /**↵
|
| | | 4 | * ↵
|
| | | 5 | */↵
|
4 | private static final long serialVersionUID = 1L;↵ | | 6 | private static final long serialVersionUID = 1L;↵
|
|
5 | ↵ | | 7 | ↵
|
6 | private ISession _session;↵ | | 8 | private ISession _session;↵
|
|
|
7 | public ScriptDB2ViewAction(IApplication app, Resources rsrc, ISession session)↵ | | 9 | public ScriptSybaseASEProcedureAction(IApplication app, Resources rsrc, ISession session)↵
|
8 | {↵ | | 10 | {↵
|
9 | super(app, rsrc);↵ | | 11 | super(app, rsrc);↵
|
10 | _session = session;↵ | | 12 | _session = session;↵
|
11 | }↵ | | 13 | }↵
|
|
|
12 | public void actionPerformed(ActionEvent evt)↵ | | 14 | public void actionPerformed(ActionEvent evt)↵
|
13 | {↵ | | 15 | {↵
|
14 | try↵ | | 16 | try↵
|
15 | {↵ | | 17 | {↵
|
|
16 | Statement stat = _session.getSQLConnection().createStatement();↵ | | 18 | ↵
|
|
17 | SessionInternalFrame sessMainFrm = _session.getSessionInternalFrame();↵ | | 19 | IDatabaseObjectInfo[] dbObjs = _session.getSessionInternalFrame().getObjectTreeAPI().getSelectedDatabaseObjects();↵
|
|
18 | IDatabaseObjectInfo[] dbObjs = sessMainFrm.getObjectTreeAPI().getSelectedDatabaseObjects();↵ | | 20 | Statement stat = _session.getSQLConnection().createStatement();↵
|
|
|
19 | StringBuffer script = new StringBuffer();↵ | | 21 | StringBuffer script = new StringBuffer();↵
|
20 | for (int i = 0; i < dbObjs.length; i++)↵ | | 22 | for (int i = 0; i < dbObjs.length; i++)↵
|
21 | {↵ | | 23 | {↵
|
22 | ITableInfo ti = (ITableInfo) dbObjs[i];↵ | | 24 | IProcedureInfo pi = (IProcedureInfo) dbObjs[i];↵
|
|
23 | ///////////////////////////////////////////////////////////↵ | | 25 | ///////////////////////////////////////////////////////////↵
|
24 | // IBM DB 2 specific code to read view definitions.↵ | | 26 | // SybaseASE specific code to read procedure definitions.↵
|
25 | String sql =↵ | | 27 | String sql =↵
|
26 | "SELECT TEXT " +↵ | | 28 | "Select text " +↵
|
27 | "FROM SYSIBM.SYSVIEWS " +↵ | | 29 | "from sysobjects inner join syscomments on syscomments.id = sysobjects.id " +↵
|
28 | "WHERE NAME = '" + ti.getSimpleName() + "'";↵ | | 30 | "where name = '" + pi.getSimpleName().replace(";1", "") + "'";↵
|
|
29 | ResultSet res = stat.executeQuery(sql);↵ | | 31 | ResultSet res = stat.executeQuery(sql);↵
|
|
30 | res.next();↵ | | 32 | while(res.next()↵
|
|
| | | 33 | )↵
|
| | | 34 | {↵
|
31 | script.append(res.getString("TEXT"));↵ | | 35 | script.append(res.getString("↵
|
| | | 36 | text")); ↵
|
| | | 37 | }↵
|
32 | script.append(getStatementSeparator());↵ | | 38 | script.append(getStatementSeparator());↵
|
33 | res.close();↵ | | 39 | res.close();↵
|
34 | //↵ | | 40 | //↵
|
35 | ///////////////////////////////////////////////////////////↵ | | 41 | ///////////////////////////////////////////////////////////↵
|
36 | }↵ | | 42 | }↵
|
|
37 | stat.close();↵ | | 43 | stat.close();↵
|
|
| | | 44 | SessionInternalFrame sessMainFrm = _session.getSessionInternalFrame();↵
|
38 | sessMainFrm.getSQLPanelAPI().appendSQLScript(script.toString());↵ | | 45 | sessMainFrm.getSQLPanelAPI().appendSQLScript(script.toString());↵
|
39 | sessMainFrm.getSessionPanel().selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB);↵ | | 46 | sessMainFrm.getSessionPanel().selectMainTab(ISession.IMainPanelTabIndexes.SQL_TAB);↵
|
40 | }↵ | | 47 | }↵
|
41 | catch (Exception e)↵ | | 48 | catch (Exception e)↵
|
42 | {↵ | | 49 | {↵
|
43 | throw new RuntimeException(e);↵ | | 50 | throw new RuntimeException(e);↵
|
44 | }↵ | | 51 | }↵
|
45 | }↵ | | 52 | }↵
|
|
46 | private String getStatementSeparator()↵ | | 53 | private String getStatementSeparator()↵
|
47 | {↵ | | 54 | {↵
|
48 | String statementSeparator = _session.getQueryTokenizer().getSQLStatementSeparator();↵ | | 55 | String statementSeparator = _session.getQueryTokenizer().getSQLStatementSeparator();↵
|
|
49 | if (1 < statementSeparator.length())↵ | | 56 | if (1 < statementSeparator.length())↵
|
50 | {↵ | | 57 | {↵
|
51 | statementSeparator = "\n" + statementSeparator + "\n";↵ | | 58 | statementSeparator = "\n" + statementSeparator + "\n";↵
|
52 | }↵ | | 59 | }↵
|
|
53 | return statementSeparator | | 60 | return statementSeparator
|