Using MySQL var in Pocket Query Macro

Kai Sun April 2, 2014

I have the below SQL Script which is running fine in MySQL:

=============================================

set @Sunday1WeekAgo = subdate(curdate(),date_format(curdate(),'%w')+7);

select COUNT(DISTINCT TITLE) PagesCreated

from CONTENT

where CONTENTTYPE='PAGE' AND SPACEID is not null

AND creationdate>=@Sunday1WeekAgo

=============================================

But when I put it in Pocket Query SQL statement, it can be executed well.

the page has this error information:

There were errors executing this statement.

There were errors executing this statement. Please check whether the following parameters are given: []. If the parameters are correct or no parameters are required, something must be wrong with the query or the database connection. Use the debug mode for a error trace and/or contact your administrator.

Is it beacuse PocketQuery macro cannot identify mySQL var - @Sunday1WeekAgo ?

Anyone can help?

4 answers

0 votes
Christian Koch April 9, 2014

Actually, this has nothing to do with the PocketQuery macro itself but with the underlying Spring-JDBC implementation. Have you tried the workaround provided by Christian?

0 votes
Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2014

Actually, this has nothing to do with the PocketQuery macro itself but with the underlying Spring-JDBC implementation. Have you tried the workaround provided by Christian?

0 votes
Christian Koch April 2, 2014

Probably the Spring JDBC Query is having problems with the SET command before the SELECT statement. Why not using this statement?

Just an idea,

Christian

select COUNT(DISTINCT TITLE) PagesCreated
from CONTENT
where CONTENTTYPE='PAGE' AND SPACEID is not null
having creationdate>=subdate(curdate(),date_format(curdate(),'%w')+7);

Christian Koch April 2, 2014

I've made a short test with a starting SET command and got an org.springframework.jdbc.BadSqlGrammarException exception

Kai Sun April 9, 2014

Thanks for the help.

I think may this marco cannot support SET command well.

0 votes
Felix Grund (Scandio)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 2, 2014

Hi Kai,

can you please activate debug mode by checking the debug checkbox in the PocketQuery macro? You will then see the stack trace of the error. Please provide that error message here and I will analyse your problem further.

Regards,
Felix

Kai Sun April 9, 2014

(error_message.txt)

Kai Sun April 9, 2014

Sorry for the late, Felix.

I attached the error message and stack trace: (error_message.txt)

Maybe this marco does not support SET command?

Kai Sun April 9, 2014

Sorry for the late, Felix.

I attached the error message and stack trace.

Maybe this marco does not support SET command?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events