01: /*
02: * DeleteAnalyzer.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.gui.completion;
13:
14: import java.util.ArrayList;
15: import java.util.List;
16: import workbench.db.TableIdentifier;
17: import workbench.db.WbConnection;
18: import workbench.util.SqlUtil;
19: import workbench.util.TableAlias;
20:
21: /**
22: *
23: * @author support@sql-workbench.net
24: */
25: public class DeleteAnalyzer extends BaseAnalyzer {
26: public DeleteAnalyzer(WbConnection conn, String statement,
27: int cursorPos) {
28: super (conn, statement, cursorPos);
29: }
30:
31: protected void checkContext() {
32: this .context = -1;
33:
34: int wherePos = SqlUtil.getKeywordPosition("WHERE", sql);
35: checkOverwrite();
36:
37: if (wherePos == -1 || wherePos > -1 && cursorPos < wherePos) {
38:
39: context = CONTEXT_TABLE_LIST;
40: String q = this .getQualifierLeftOfCursor();
41: if (q != null) {
42: this .setOverwriteCurrentWord(false);
43: this .schemaForTableList = q;
44: } else {
45: this .schemaForTableList = this .dbConnection
46: .getMetadata().getCurrentSchema();
47: }
48: } else {
49: // current cursor position is after the WHERE
50: // so we'll need a column list
51: context = CONTEXT_COLUMN_LIST;
52: String table = SqlUtil.getDeleteTable(sql);
53: if (table != null)
54: tableForColumnList = new TableIdentifier(table);
55: }
56: }
57:
58: public List<TableAlias> getTables() {
59: String table = SqlUtil.getDeleteTable(this .sql);
60: TableAlias a = new TableAlias(table);
61: List<TableAlias> result = new ArrayList<TableAlias>(1);
62: result.add(a);
63: return result;
64: }
65:
66: }
|