import java.sql.SQLException; import java.util.Vector; import java.io.*; import Zql.*; /** *
* ZDemo is able to send SQL queries to simple CSV (comma-separated values) * files; the CSV syntax used here is very simple: * The 1st line contains the column names * Other lines contain column values (tuples) * Values are separated by commas, so they can't contain commas (it's just * for demo purposes). * Example: * Create a num.db text file that contains the following: * a,b,c,d,e * 1,1,1,1,1 * 2,2,2,2,2 * 1,2,3,4,5 * 5,4,3,2,1 * You can then run ZDemo, and query it; some legal queries follow: * select * from num; * select a, b from num; * select a+b, c from num; * select * from num where a = 1 or e = 1; * select * from num where a = 1 and b = 1 or e = 1; * select d, e from num where a + b + c <= 3; * select * from num where 3 = a + b + c; * select * from num where a = b or e = d - 1; * select * from num where b ** a <= 2; **/ public class t1 { public static void main(String args[]) { try { ZqlParser p = null; if(args.length < 1) { System.out.println("Reading SQL from stdin (quit; or exit; to quit)"); p = new ZqlParser(System.in); } else { p = new ZqlParser(new DataInputStream(new FileInputStream(args[0]))); } // Read all SQL statements from input ZStatement st; while((st = p.readStatement()) != null) { System.out.println(st.toString()); // Display the statement /* see the contents of each objects */ if(st instanceof ZQuery) { // An SQL query Vector sel = ((ZQuery)st).getSelect(); System.out.println("\n\nselect clause:"); for(int i=0; i