SQL Plugin copied from Quantum plugin and refactored for PHPEclipse
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.sql / src / net / sourceforge / phpdt / sql / sql / SQLParser.java
1 package net.sourceforge.phpdt.sql.sql;
2
3 import java.util.Vector;
4
5 import net.sourceforge.phpdt.sql.parser.SQLLexx;
6 import net.sourceforge.phpdt.sql.parser.Token;
7
8 public class SQLParser {
9         public static final String COMMENT = "--";
10         public static final String ENDLINE = ";";
11         public static Vector parse(String query) {
12                         Vector commands = new Vector();
13                 try {
14                 //System.out.println("-------------------1");
15                         Vector tokens = SQLLexx.parse(query);
16                 //System.out.println("-------------------2");
17                         StringBuffer buffer = new StringBuffer();
18                         for (int i = 0; i < tokens.size(); i++) {
19                 //System.out.println("-------------------3");
20                                 Token t = (Token) tokens.elementAt(i);
21                                 if (t.getType() == t.COMMENT) {
22                                         // ignore comments
23                                 } else if (t.getType() == t.SEPARATOR) {
24                                         String newCommand = buffer.toString().trim();
25                                         if (!newCommand.equals("")) {
26                                                 commands.addElement(newCommand);
27                                         }
28                                         buffer = new StringBuffer();
29                                 } else {
30                                         buffer.append(t.getValue());
31                                 }
32                         }
33                         String newCommand = buffer.toString().trim();
34                         if (!newCommand.equals("")) {
35                                 commands.addElement(newCommand);
36                         }
37                 } catch (Throwable e) {
38                         e.printStackTrace();
39                 }
40                 System.out.println("Returning");
41                         return commands;
42         }
43 }