import java.util.Vector;
+import net.sourceforge.phpdt.sql.IConstants;
import net.sourceforge.phpdt.sql.parser.SQLLexx;
import net.sourceforge.phpdt.sql.parser.Token;
-public class SQLParser {
- public static final String COMMENT = "--";
- public static final String ENDLINE = ";";
- public static Vector parse(String query) {
- Vector commands = new Vector();
- try {
- //System.out.println("-------------------1");
- Vector tokens = SQLLexx.parse(query);
- //System.out.println("-------------------2");
- StringBuffer buffer = new StringBuffer();
- for (int i = 0; i < tokens.size(); i++) {
- //System.out.println("-------------------3");
- Token t = (Token) tokens.elementAt(i);
- if (t.getType() == t.COMMENT) {
- // ignore comments
- } else if (t.getType() == t.SEPARATOR) {
- String newCommand = buffer.toString().trim();
- if (!newCommand.equals("")) {
- commands.addElement(newCommand);
- }
- buffer = new StringBuffer();
- } else {
- buffer.append(t.getValue());
- }
- }
- String newCommand = buffer.toString().trim();
- if (!newCommand.equals("")) {
- commands.addElement(newCommand);
- }
- } catch (Throwable e) {
- e.printStackTrace();
- }
- System.out.println("Returning");
- return commands;
- }
+public class SQLParser implements IConstants {
+ public static final String COMMENT = "--";
+ public static final String ENDLINE = ";";
+ public static Vector parse(String query) {
+ Vector commands = new Vector();
+ try {
+ //System.out.println("-------------------1");
+ Vector tokens = SQLLexx.parse(query);
+ //System.out.println("-------------------2");
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < tokens.size(); i++) {
+ //System.out.println("-------------------3");
+ Token t = (Token) tokens.elementAt(i);
+ if (t.getType() == t.COMMENT) {
+ // ignore comments
+ } else if (t.getType() == t.SEPARATOR) {
+ String newCommand = buffer.toString().trim();
+ if (!newCommand.equals("")) {
+ commands.addElement(newCommand);
+ }
+ buffer = new StringBuffer();
+ } else {
+ buffer.append(t.getValue());
+ }
+ }
+ String newCommand = buffer.toString().trim();
+ if (!newCommand.equals("")) {
+ commands.addElement(newCommand);
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ if (DEBUG) {
+ System.out.println("Returning");
+ }
+ return commands;
+ }
}
\ No newline at end of file