1 package com.quantum.sql.parser;
3 import java.util.Vector;
6 public class SQLParser {
9 * Parses a query string into executable units.
11 * @return a Vector of Strings, with the individual executable units.
13 public static Vector parse(String query) {
14 Vector commands = new Vector();
15 Vector groups = new Vector();
17 Vector tokens = SQLLexx.parse(query);
18 StringBuffer buffer = new StringBuffer();
19 StringBuffer groupBuffer = new StringBuffer();
20 for (int i = 0; i < tokens.size(); i++) {
21 Token t = (Token) tokens.elementAt(i);
22 if (t.getType() == Token.COMMENT) {
24 } else if (t.getType() == Token.SEPARATOR) {
25 groupBuffer.append(t.getValue());
26 String newCommand = buffer.toString().trim();
27 if (!newCommand.equals("")) { //$NON-NLS-1$
28 commands.addElement(newCommand);
30 buffer = new StringBuffer();
32 // We append the tokens to the buffer until it's a separator or group.
33 buffer.append(t.getValue());
34 groupBuffer.append(t.getValue());
37 String newCommand = buffer.toString().trim();
38 if (!newCommand.equals("")) { //$NON-NLS-1$
39 commands.addElement(newCommand);
41 } catch (Throwable e) {
44 Vector result = new Vector();
45 result.addAll(groups);
46 result.addAll(commands);