Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support class syntax in HQL query #163

Closed
tmortagne opened this issue Aug 7, 2015 · 13 comments
Closed

Support class syntax in HQL query #163

tmortagne opened this issue Aug 7, 2015 · 13 comments

Comments

@tmortagne
Copy link

In HQL you can have things like "select mymodel.name from com.myproject.MyModelClass as mymodel" but jsqlparser throw a "com is not a valid database reference".

@wumpz
Copy link
Member

wumpz commented Aug 7, 2015

The actual snapshot accepts more multiparty names. Saying that the hsql class extention would be more difficult to implement because the hierarchy could be much deeper. So it would work here by coincidence. Your class package deepness could be handled. So try the actual snapshot.

@tmortagne
Copy link
Author

Ok thanks, will do when I get some time.

@tmortagne
Copy link
Author

What is in the current master does not seems to be enough in my case.

select doc.fullName from XWikiDocument as doc, com.xpn.xwiki.objects.StringProperty as str

gives me

net.sf.jsqlparser.JSQLParserException
    at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:51)
    at com.xpn.xwiki.internal.store.hibernate.query.HqlQueryUtils.isSafe(HqlQueryUtils.java:140)
    at com.xpn.xwiki.internal.store.hibernate.query.HqlQueryUtilsTest.isSafe(HqlQueryUtilsTest.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered " "." ". "" at line 1, column 69.
Was expecting one of:
    <EOF> 
    "AS" ...
    "DO" ...
    "ON" ...
    "ANY" ...
    "KEY" ...
    "PERCENT" ...
    "JOIN" ...
    "LEFT" ...
    "CROSS" ...
    "OPEN" ...
    "FULL" ...
    "WHERE" ...
    "FOR" ...
    "PIVOT" ...
    "XML" ...
    "USING" ...
    "GROUP" ...
    "INNER" ...
    "RIGHT" ...
    "VALUE" ...
    "HAVING" ...
    "VALUES" ...
    "NATURAL" ...
    "REPLACE" ...
    "TRUNCATE" ...
    "CAST" ...
    "OVER" ...
    "PARTITION" ...
    "EXTRACT" ...
    "MATERIALIZED" ...
    "START" ...
    "CONNECT" ...
    "SIBLINGS" ...
    "COLUMN" ...
    "NULLS" ...
    "FIRST" ...
    "LAST" ...
    "ROWS" ...
    "RANGE" ...
    "FOLLOWING" ...
    "ROW" ...
    <S_IDENTIFIER> ...
    <S_QUOTED_IDENTIFIER> ...
    ";" ...
    "," ...
    "PIVOT" ...
    "PIVOT" ...
    "AS" ...
    <S_IDENTIFIER> ...
    <S_QUOTED_IDENTIFIER> ...
    "CAST" ...
    "DO" ...
    "EXTRACT" ...
    "FIRST" ...
    "FOLLOWING" ...
    "LAST" ...
    "MATERIALIZED" ...
    "NULLS" ...
    "PARTITION" ...
    "RANGE" ...
    "ROW" ...
    "ROWS" ...
    "SIBLINGS" ...
    "VALUE" ...
    "XML" ...
    "COLUMN" ...
    "REPLACE" ...
    "TRUNCATE" ...
    "KEY" ...
    "ANY" ...
    "OPEN" ...
    "OVER" ...
    "VALUES" ...
    "PERCENT" ...
    "ON" ...
    "USING" ...
    "LEFT" ...
    "RIGHT" ...
    "FULL" ...
    "INNER" ...
    "NATURAL" ...
    "CROSS" ...
    "JOIN" ...
    "," ...
    "WHERE" ...
    "START" ...
    "CONNECT" ...
    "GROUP" ...
    "HAVING" ...
    "FOR" ...

    at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:12986)
    at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:12842)
    at net.sf.jsqlparser.parser.CCJSqlParser.Statement(CCJSqlParser.java:77)
    at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:49)
    ... 25 more
Caused by:
net.sf.jsqlparser.parser.ParseException: Encountered " "." ". "" at line 1, column 69.
Was expecting one of:
    <EOF> 
    "AS" ...
    "DO" ...
    "ON" ...
    "ANY" ...
    "KEY" ...
    "PERCENT" ...
    "JOIN" ...
    "LEFT" ...
    "CROSS" ...
    "OPEN" ...
    "FULL" ...
    "WHERE" ...
    "FOR" ...
    "PIVOT" ...
    "XML" ...
    "USING" ...
    "GROUP" ...
    "INNER" ...
    "RIGHT" ...
    "VALUE" ...
    "HAVING" ...
    "VALUES" ...
    "NATURAL" ...
    "REPLACE" ...
    "TRUNCATE" ...
    "CAST" ...
    "OVER" ...
    "PARTITION" ...
    "EXTRACT" ...
    "MATERIALIZED" ...
    "START" ...
    "CONNECT" ...
    "SIBLINGS" ...
    "COLUMN" ...
    "NULLS" ...
    "FIRST" ...
    "LAST" ...
    "ROWS" ...
    "RANGE" ...
    "FOLLOWING" ...
    "ROW" ...
    <S_IDENTIFIER> ...
    <S_QUOTED_IDENTIFIER> ...
    ";" ...
    "," ...
    "PIVOT" ...
    "PIVOT" ...
    "AS" ...
    <S_IDENTIFIER> ...
    <S_QUOTED_IDENTIFIER> ...
    "CAST" ...
    "DO" ...
    "EXTRACT" ...
    "FIRST" ...
    "FOLLOWING" ...
    "LAST" ...
    "MATERIALIZED" ...
    "NULLS" ...
    "PARTITION" ...
    "RANGE" ...
    "ROW" ...
    "ROWS" ...
    "SIBLINGS" ...
    "VALUE" ...
    "XML" ...
    "COLUMN" ...
    "REPLACE" ...
    "TRUNCATE" ...
    "KEY" ...
    "ANY" ...
    "OPEN" ...
    "OVER" ...
    "VALUES" ...
    "PERCENT" ...
    "ON" ...
    "USING" ...
    "LEFT" ...
    "RIGHT" ...
    "FULL" ...
    "INNER" ...
    "NATURAL" ...
    "CROSS" ...
    "JOIN" ...
    "," ...
    "WHERE" ...
    "START" ...
    "CONNECT" ...
    "GROUP" ...
    "HAVING" ...
    "FOR" ...

    at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:12986)
    at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:12842)
    at net.sf.jsqlparser.parser.CCJSqlParser.Statement(CCJSqlParser.java:77)
    at net.sf.jsqlparser.parser.CCJSqlParserUtil.parse(CCJSqlParserUtil.java:49)
    at com.xpn.xwiki.internal.store.hibernate.query.HqlQueryUtils.isSafe(HqlQueryUtils.java:140)
    at com.xpn.xwiki.internal.store.hibernate.query.HqlQueryUtilsTest.isSafe(HqlQueryUtilsTest.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

@wumpz
Copy link
Member

wumpz commented Aug 19, 2015

Multipart names were developed to accept database object names. Therefore there is a server schema etc. variable. Class hierarchy would be a different concept of names. I will think about it (being at the beach swimming in the ocean😉). Cheers Tobias

@tmortagne
Copy link
Author

Thanks for taking that into account :) I have a workaround in the meantime don't worry, just wanted to mention the issue in case other have the need.

@vmassol
Copy link

vmassol commented Jun 15, 2018

hi @wumpz thanks for considering this.

Actually it's a bit more important. Thomas mentioned that we have some workaround which is true but this is causing some API of ours to fail and thus forcing our users to use the XWiki APIs in a certain or it'll fail for them. We cannot really control how they use the XWiki APIs (even though we can document it). So it would be very nice if there was a solution :)

Maybe we could even help out although we're totally newbies in the jsqlparser code base?

@wumpz
Copy link
Member

wumpz commented Jun 15, 2018

I will look into this with higher priority.

@vmassol
Copy link

vmassol commented Jun 15, 2018

Awesome Tobias! thanks a lot

@wumpz wumpz closed this as completed in 1db3ff5 Jun 17, 2018
wumpz added a commit that referenced this issue Jun 17, 2018
@vmassol
Copy link

vmassol commented Jun 17, 2018

Thanks so much Tobias! :) So this will be in jsqlparser 1.3 (or maybe in 1.2.1)?

@wumpz
Copy link
Member

wumpz commented Jun 17, 2018

The change should do it. The problem was to still accept some SqlServer multipart name specials. (database..table).

@vmassol always at work ? ;) This will be in JSqlParser 1.3. I think a major version increment is not necessary. Nevertheless I would appreciate some testing at your side. I included multiple tests.

Cheers Tobias and thx for using JSqlParser

@vmassol
Copy link

vmassol commented Jun 17, 2018

Yes we'll build it and test it, thanks!

@vmassol
Copy link

vmassol commented Jun 17, 2018

always at work ? ;)

Same for you! :)

@vmassol
Copy link

vmassol commented Jun 21, 2018

@wumpz I've tested it and it works! Thx, now waiting for the release so that I can fix it in XWiki. Good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants