Committing patch from grEvenX to fix bug #1839622 RSE Path error
[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.sql.parser.SQLLexx;
6 import net.sourceforge.phpdt.sql.sql.parser.Token;
7
8 public class SQLParser {
9         public static final String COMMENT = "--"; //$NON-NLS-1$
10         public static final String ENDLINE = ";"; //$NON-NLS-1$
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() == Token.COMMENT) {
22                                         // ignore comments
23                                 } else if (t.getType() == Token.SEPARATOR) {
24                                         String newCommand = buffer.toString().trim();
25                                         if (!newCommand.equals("")) { //$NON-NLS-1$
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("")) { //$NON-NLS-1$
35                                 commands.addElement(newCommand);
36                         }
37                 } catch (Throwable e) {
38                         e.printStackTrace();
39                 }
40                 System.out.println("Returning"); //$NON-NLS-1$
41                         return commands;
42         }
43 }