SQL plugin: how return the result of a SQL select count query in a velocity variable type "number litteral"

Hi all,

I'm using the SQL plugin in a macro and I do a SQL select count request.

The request render a string (for example) <p>3</p>

I have removed the tags but the variable ($OK), is always a string so that I cannot do any calculation after.

Here after is the code:

#set($KO=$helper.renderConfluenceMacro("{sql:datasource=confluence|table=false}
select count(PROJECT.CONTENTID)
from
(select (CONTENT_LABEL.CONTENTID) as CONTENTID
from CONTENT_LABEL,LABEL
where
LABEL.NAME='mi-securetransport'  AND LABEL.LABELID = CONTENT_LABEL.LABELID) PROJECT,
(select (CONTENT_LABEL.CONTENTID) as CONTENTID
from CONTENT_LABEL,LABEL
where
LABEL.NAME='ko'  AND LABEL.LABELID = CONTENT_LABEL.LABELID) LABELOK

where
PROJECT.CONTENTID = LABELOK.CONTENTID
{sql}"))


#set($KO1 = $KO.replaceAll("&lt;p&gt;",""))
#set($KO2 = $KO1.replaceAll("&lt;/p&gt;",""))
#set($KO3 = $KO2 + 10)

$KO3

KO3 render the string concatenation of KO2 and 10

Have you any solution?

Thanks

1 answer

1 accepted

Thanks Bob, I hope a lot with your answer but I have tried this in a Confluence macro

#set($intString = "9")
#set($Integer = 0)
$Integer.parseInt($intString)

#set( $ALL = $Integer + 5 )
$ALL

and $ALL always render the concatenation of 9 and 5.

I surely missed something (I'm not a programmer)

What is your opinion?

Best regards

Sorry Bob, now it works.

I did that

#set($intString = "9")
#set($Integer = 0)
#set ($a =$Integer.parseInt($intString))



#set( $ALL = $a + 5 )
$ALL

Thanks a lot

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

862 views 23 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you