February 01, 2019
"Hello World" due Feb 8
SELECT * FROM FOO
cat FOO
A link to the submission system is on the syllabus.
There's a handy "create account" link.
Use your UBIT email address to create an account.
// StringReaders create a reader from a string
Reader input = new StringReader("SELECT * FROM R")
// CCJSqlParser takes a Reader or InputStream
CCJSqlParser parser = new CCJSqlParser(input)
// CCJSqlParser.Statement() returns the next
// complete Statement object from the reader or
// input stream (or null if the stream is empty).
Statement statement = parser.Statement()
// System.in is an InputStream
CCJSqlParser parser = new CCJSqlParser(System.in)
Statement statement = parser.Statement();
// loop until you hit the last statement
while(statement != null){
//
// Do something with statement
//
// ... then read the next statement
statement = parser.Statement();
}
while(statement != null){
if(statement instanceof Select){
Select select = (Select)statement;
// Do something with `select`
} else if(statement instanceof CreateTable){
CreateTable create = (CreateTable)statement;
// Do something with `create`
} else {
throw new SqlException("Can't handle: "+statement);
}
statement = parser.Statement()
}
Select select = (Select)statement;
SelectBody body = select.getSelectBody();
if(body instanceof /* ... */){
// ...
}
Select select = (Select)statement;
SelectBody body = select.getSelectBody();
if(body instanceof PlainSelect){
PlainSelect plain = (PlainSelect)body;
// Do something with `plain`
}
SELECT [distinct] [selectItems]
FROM [fromItem], [joins, ...]
WHERE [where]
GROUP BY [groupByColumnReferences]
HAVING [having]
ORDER BY [orderByElements]
LIMIT [limit]
Everything in [brackets] has a method in PlainSelect