01: /*
02: * WbDescribeTable.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.db.TableIdentifier;
16:
17: import workbench.resource.ResourceMgr;
18: import workbench.sql.SqlCommand;
19: import workbench.sql.StatementRunnerResult;
20: import workbench.storage.DataStore;
21: import workbench.util.SqlUtil;
22:
23: /**
24: *
25: * @author support@sql-workbench.net
26: */
27: public class WbDescribeTable extends SqlCommand {
28: private static final String VERB = "DESC";
29:
30: public WbDescribeTable() {
31: }
32:
33: public String getVerb() {
34: return VERB;
35: }
36:
37: public StatementRunnerResult execute(String sql)
38: throws SQLException {
39: StatementRunnerResult result = new StatementRunnerResult();
40: String table = SqlUtil.stripVerb(SqlUtil.makeCleanSql(sql,
41: false, false, '\''));
42:
43: TableIdentifier tbl = new TableIdentifier(table);
44:
45: DataStore ds = currentConnection.getMetadata()
46: .getTableDefinition(tbl);
47: if (ds == null || ds.getRowCount() == 0) {
48: result.setFailure();
49: String msg = ResourceMgr
50: .getString("ErrTableOrViewNotFound");
51: msg = msg.replaceAll("%name%", table);
52: result.addMessage(msg);
53: } else {
54: result.setSuccess();
55: result.addDataStore(ds);
56: }
57: return result;
58: }
59:
60: }
|