Today I came across another statement that JSqlParser couldn't parse:
"select newid()"
It's generated by Hibernate SQLServerDialect and used whenever it tries to insert something into a table with GUIDs. To make the JSqlParser accept this statement, I had to make everything after the SelectItemsList in a PlainSelect optional and create dummy lists for the fromItems.
Maybe you can include it in the next version of JSqlParser, since some RDBMS use these kinds of statements to provide clients with special information about recent actions and stuff.
If you don't, there's at least a hint for other users in the forums ;)
- Tangresh
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I realized the dummy lists were a bad idea since in all other cases when something doesn't exist, it's just null instead of an empty list. So, this would be better:
Today I came across another statement that JSqlParser couldn't parse:
"select newid()"
It's generated by Hibernate SQLServerDialect and used whenever it tries to insert something into a table with GUIDs. To make the JSqlParser accept this statement, I had to make everything after the SelectItemsList in a PlainSelect optional and create dummy lists for the fromItems.
*selectItems=SelectItemsList()
*
+[
* // TODO
* [IntoClause()]
* fromItems=FromItemsList()
* joins=JoinsList()
* [ where=WhereClause() { plainSelect.setWhere(where); }]
* [ groupByColumnReferences=GroupByColumnReferences() { plainSelect.setGroupByColumnReferences(groupByColumnReferences); }]
* [ having=Having() { plainSelect.setHaving(having); }]
* [ orderByElements = OrderByElements() { plainSelect.setOrderByElements(orderByElements); } ]
* [ limit = Limit() { plainSelect.setLimit(limit); } ]
+]
*{
* plainSelect.setSelectItems(selectItems);
+ if (fromItems == null)
+ fromItems = new ArrayList();
* plainSelect.setFromItems(fromItems);
+ if (joins != null)
* if (joins.size() > 0)
* plainSelect.setJoins(joins);
* return plainSelect;
*}
Maybe you can include it in the next version of JSqlParser, since some RDBMS use these kinds of statements to provide clients with special information about recent actions and stuff.
If you don't, there's at least a hint for other users in the forums ;)
- Tangresh
I realized the dummy lists were a bad idea since in all other cases when something doesn't exist, it's just null instead of an empty list. So, this would be better:
*selectItems=SelectItemsList()
*
+[
* // TODO
* [IntoClause()]
* fromItems=FromItemsList()
* joins=JoinsList()
* [ where=WhereClause() { plainSelect.setWhere(where); }]
* [ groupByColumnReferences=GroupByColumnReferences() { plainSelect.setGroupByColumnReferences(groupByColumnReferences); }]
* [ having=Having() { plainSelect.setHaving(having); }]
* [ orderByElements = OrderByElements() { plainSelect.setOrderByElements(orderByElements); } ]
* [ limit = Limit() { plainSelect.setLimit(limit); } ]
+]
*{
* plainSelect.setSelectItems(selectItems);
* plainSelect.setFromItems(fromItems);
+ if (joins != null)
* if (joins.size() > 0)
* plainSelect.setJoins(joins);
* return plainSelect;
*}