001: /*
002: * Created on Jul 3, 2004
003: *
004: * To change the template for this generated file go to
005: * Window>Preferences>Java>Code Generation>Code and Comments
006: */
007: package com.pk;
008:
009: import java.sql.Connection;
010: import java.sql.ResultSet;
011: import java.sql.ResultSetMetaData;
012: import java.sql.SQLException;
013: import java.sql.Statement;
014: import java.util.Vector;
015:
016: /**
017: * @author Isabelle
018: *
019: * To change the template for this generated type comment go to
020: * Window>Preferences>Java>Code Generation>Code and Comments
021: */
022: public class MySQLDialect implements DatabaseDialect {
023:
024: /* (non-Javadoc)
025: * @see com.pk.DatabaseDialect#getKeywords()
026: */
027: public Vector getKeywords() {
028:
029: Vector keywords = new Vector();
030: keywords.add("add");
031: keywords.add("all");
032: keywords.add("alter");
033: keywords.add("analyze");
034: keywords.add("and");
035: keywords.add("as");
036: keywords.add("asc");
037: keywords.add("asensitive");
038: keywords.add("auto_increment");
039: keywords.add("bdb");
040: keywords.add("before");
041: keywords.add("berkeleydb");
042: keywords.add("between");
043: keywords.add("both");
044: keywords.add("by");
045: keywords.add("call");
046: keywords.add("cascade");
047: keywords.add("case");
048: keywords.add("change");
049: keywords.add("check");
050: keywords.add("collate");
051: keywords.add("column");
052: keywords.add("columns");
053: keywords.add("condition");
054: keywords.add("constraint");
055: keywords.add("create");
056: keywords.add("cross");
057: keywords.add("cursor");
058: keywords.add("database");
059: keywords.add("databases");
060: keywords.add("dec");
061: keywords.add("declare");
062: keywords.add("default");
063: keywords.add("delete");
064: keywords.add("desc");
065: keywords.add("describe");
066: keywords.add("deterministic");
067: keywords.add("distinct");
068: keywords.add("distinctrow");
069: keywords.add("div");
070: keywords.add("drop");
071: keywords.add("else");
072: keywords.add("elseif");
073: keywords.add("enclosed");
074: keywords.add("escaped");
075: keywords.add("exists");
076: keywords.add("explain");
077: keywords.add("false");
078: keywords.add("fetch");
079: keywords.add("fields");
080: keywords.add("for");
081: keywords.add("force");
082: keywords.add("foreign");
083: keywords.add("found");
084: keywords.add("from");
085: keywords.add("fulltext");
086: keywords.add("grant");
087: keywords.add("group");
088: keywords.add("having");
089: keywords.add("if");
090: keywords.add("ignore");
091: keywords.add("in");
092: keywords.add("index");
093: keywords.add("infile");
094: keywords.add("inner");
095: keywords.add("insert");
096: keywords.add("into");
097: keywords.add("is");
098: keywords.add("iterate");
099: keywords.add("join");
100: keywords.add("key");
101: keywords.add("keys");
102: keywords.add("leading");
103: keywords.add("left");
104: keywords.add("like");
105: keywords.add("like");
106: keywords.add("lock");
107: keywords.add("not");
108: keywords.add("null");
109: keywords.add("on");
110: keywords.add("optimize");
111: keywords.add("or");
112: keywords.add("order");
113: keywords.add("outer");
114: keywords.add("primary");
115: keywords.add("rename");
116: keywords.add("replace");
117: keywords.add("right");
118: keywords.add("select");
119: keywords.add("set");
120: keywords.add("show");
121: keywords.add("starting");
122: keywords.add("table");
123: keywords.add("then");
124: keywords.add("to");
125: keywords.add("trailing");
126: keywords.add("true");
127: keywords.add("union");
128: keywords.add("unique");
129: keywords.add("update");
130: keywords.add("use");
131: keywords.add("values");
132: keywords.add("when");
133: keywords.add("where");
134: keywords.add("while");
135: keywords.add("with");
136: keywords.add("verbose");
137:
138: return keywords;
139: }
140:
141: /* (non-Javadoc)
142: * @see com.pk.DatabaseDialect#getTableInfoSQLString(java.lang.String, com.pk.ConnectionInformation)
143: */
144: public String getTableInfoSQLString(String argTableName,
145: ConnectionInformation argConnectionInformation) {
146:
147: return "desc " + argTableName;
148: }
149:
150: /* (non-Javadoc)
151: * @see com.pk.DatabaseDialect#getIndexInfoSQLString(java.lang.String, com.pk.ConnectionInformation)
152: */
153: public String getIndexInfoSQLString(String argTableName,
154: ConnectionInformation argConnectionInformation) {
155:
156: return "show index from " + argTableName;
157: }
158:
159: /* (non-Javadoc)
160: * @see com.pk.DatabaseDialect#getProcedureInfoSQLString(java.lang.String, com.pk.ConnectionInformation)
161: */
162: public String getProcedureInfoSQLString(String argProcedureName,
163: ConnectionInformation argConnectionInformation) {
164:
165: return null;
166: }
167:
168: /* (non-Javadoc)
169: * @see com.pk.DatabaseDialect#isSelectStatement(java.lang.String)
170: */
171: public boolean isSelectStatement(String argStatement) {
172: boolean isSelect = false;
173: if (argStatement.toUpperCase().startsWith("SELECT")
174: || argStatement.toUpperCase().startsWith("SHOW")
175: || argStatement.toUpperCase().startsWith("DESC")
176: || argStatement.toUpperCase().startsWith("EXPLAIN")) {
177: isSelect = true;
178: }
179: return isSelect;
180: }
181:
182: /* (non-Javadoc)
183: * @see com.pk.DatabaseDialect#isDescribeStatement(java.lang.String)
184: */
185: public boolean isDescribeStatement(String argStatement) {
186:
187: return false;
188: }
189:
190: /* (non-Javadoc)
191: * @see com.pk.DatabaseDialect#getDescribeSQLString(java.lang.String, com.pk.ConnectionInformation)
192: */
193: public String getDescribeSQLString(String argQuery,
194: ConnectionInformation argConnectionInformation) {
195:
196: return null;
197: }
198:
199: /* (non-Javadoc)
200: * @see com.pk.DatabaseDialect#doExecutePlan(java.lang.String, com.pk.ConnectionInformation, java.sql.Connection)
201: */
202: public String doExecutePlan(String argStatement,
203: ConnectionInformation argConnectionInformation,
204: Connection argConnection) throws SQLException {
205: int fieldSize = 1;
206: String padChar = " ";
207: String separatorChar = "| ";
208: Statement statement = argConnection.createStatement();
209: ResultSet resultSet = statement.executeQuery("explain "
210: + argStatement);
211:
212: StringBuffer outPut = new StringBuffer();
213: ResultSetMetaData rsmd = resultSet.getMetaData();
214: int NumOfColumns = rsmd.getColumnCount();
215: for (int x = 1; x <= NumOfColumns; x++) {
216: outPut.append(separatorChar);
217: outPut.append(Util.lPad(rsmd.getColumnName(x), fieldSize,
218: padChar));
219: outPut.append(" ");
220: }
221: String tmp = "";
222: while (resultSet.next()) {
223: outPut.append("\n");
224: for (int x = 1; x <= NumOfColumns; x++) {
225: outPut.append(separatorChar);
226: tmp = resultSet.getString(x);
227: if (tmp == null) {
228: tmp = "NULL";
229: }
230: outPut.append(Util.lPad(tmp, fieldSize, padChar));
231: outPut.append(" ");
232: }
233:
234: }
235: //TODO format output.
236: return outPut.toString();
237:
238: }
239:
240: /* (non-Javadoc)
241: * @see com.pk.DatabaseDialect#getPackageInfoSQLString(java.lang.String, com.pk.ConnectionInformation)
242: */
243: public String getPackageInfoSQLString(String argProcedureName,
244: ConnectionInformation argConnectionInformation) {
245: return null;
246: }
247:
248: }
|