introduced IConstant.DEBUG flag
[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.IConstants;
6 import net.sourceforge.phpdt.sql.parser.SQLLexx;
7 import net.sourceforge.phpdt.sql.parser.Token;
8
9 public class SQLParser implements IConstants {
10   public static final String COMMENT = "--";
11   public static final String ENDLINE = ";";
12   public static Vector parse(String query) {
13     Vector commands = new Vector();
14     try {
15       //System.out.println("-------------------1");
16       Vector tokens = SQLLexx.parse(query);
17       //System.out.println("-------------------2");
18       StringBuffer buffer = new StringBuffer();
19       for (int i = 0; i < tokens.size(); i++) {
20         //System.out.println("-------------------3");
21         Token t = (Token) tokens.elementAt(i);
22         if (t.getType() == t.COMMENT) {
23           // ignore comments
24         } else if (t.getType() == t.SEPARATOR) {
25           String newCommand = buffer.toString().trim();
26           if (!newCommand.equals("")) {
27             commands.addElement(newCommand);
28           }
29           buffer = new StringBuffer();
30         } else {
31           buffer.append(t.getValue());
32         }
33       }
34       String newCommand = buffer.toString().trim();
35       if (!newCommand.equals("")) {
36         commands.addElement(newCommand);
37       }
38     } catch (Throwable e) {
39       e.printStackTrace();
40     }
41     if (DEBUG) {
42       System.out.println("Returning");
43     }
44     return commands;
45   }
46 }