I am trying to display sql query results as below
sql.eachRow(select * from issue)
{row->
// log.error("loggggg" +row.values().toString());
}
But it is not displaying results. Am i doing something wrong?
can someone help on this
Hello Vineela,
The name of the table should be jiraissue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How is your whole code?
it should be "select * from jiraissue" with quotes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yah it is "select * from jiraissue" with quotes
try {
sql = new Sql(conn);
def sqlQueryREC ="select * from jiraissue";
sql.eachRow(sqlQueryREC )
{row->
log.error("results")
}
Nothing is being printed from that log.error. Is my sql.eachRow method syntax correct?
If so how should i display all the rows and what is the syntax for it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
log.error("results") only logs results string if that's the one you see in logs.
However, if you do not see anything in the log file, just go to script console and try below code, you should see all issues in console, but jiraissue table may contain lots of issues so trying with another table should be wise (like issuestatus)
Try this one for jiraissue
import com.atlassian.jira.component.ComponentAccessor
import groovy.sql.Sql
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface
import java.sql.Connection
def delegator = (DelegatorInterface) ComponentAccessor.getComponent(DelegatorInterface)
String helperName = delegator.getGroupHelperName("default");
Connection conn = ConnectionFactory.getConnection(helperName);
Sql sql = new Sql(conn)
StringBuffer sb = new StringBuffer()
try {
sql = new Sql(conn);
sql.eachRow("select * from jiraissue") {
log.warn("${it}")
sb << "$it.id $it.summary"
}
return sb
} finally {
sql.close()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am getting below error
BUG! exception in phase 'class generation' in source unit 'file:/var/lib/jira/atlassian/application-data/jira/scripts/Listener/SWPRCreateReleaseListener.groovy' Trying to access private constant field [com.atlassian.jira.event.issue.AbstractIssueEventListener#log] from inner class
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So you're using this in issue listener. And in AbstractIssueEventListener there is also log instance variable.
You should define your own log variable to use it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
log issue is now resolved but nothing is being displayed which is in try block
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Tuncay Senturk _Snapbytes_
I am trying to extract id value from sql query
Connection conn = ConnectionFactory.getConnection(helperName);
log.debug("connection succees")
Sql sql = new Sql(conn)
def row;
StringBuffer sb = new StringBuffer()
try {
sql.eachRow("""select ji.id as ID from jiraissue ji
left join project p with(nolock)
on ji.project = p.id
where p.pkey='SWRM' and ji.summary='19.10'""") {
log.warn("${it}")
sb << "${it}"
}
sb.toString()
return sb
} finally {
sql.close()
}
sb value is returning as [id:873319], how to just extract the ID from this result as I need to pass this id in my code
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is throwing error "No such property id for class"
ANy other way to extract the id value
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is case sensitive, if you used above query (as ID), you should use sb.ID otherwise sb.id
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey,
I couldn't notice your code.
You are using below statement
sb << "${it}"
I think you should use below to get only id
sb << "${it.ID}"
and
return sb.toString()
But if there are multiple rows (e.g. id:100, id:101, id:102) it will produce the result as 100101102 as I mentioned before.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My result would return only one row and your code above is still throwing an error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't know your latest code but I tried below code
import com.atlassian.jira.component.ComponentAccessor
import groovy.sql.Sql
import org.ofbiz.core.entity.ConnectionFactory
import org.ofbiz.core.entity.DelegatorInterface
import java.sql.Connection
def delegator = (DelegatorInterface) ComponentAccessor.getComponent(DelegatorInterface)
String helperName = delegator.getGroupHelperName("default");
Connection conn = ConnectionFactory.getConnection(helperName);
Sql sql = new Sql(conn)
def resultId
try {
sql = new Sql(conn);
sql.eachRow("select * from jiraissue where id = 10000") {
resultId = "${it.ID}"
}
return resultId
} finally {
sql.close()
}
And here is the result
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As shown in the above screenshot I am even getting error on ${it.ID} as No such property ID for class.
How to resolve it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where is screenshot? What is your latest code? I'm blind as a bat, how can I help in this way?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I said about the screenshot you have attached.. error in the screenshot of yours
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oohh, you can skip that error, that's just visual.
The context in compile time and runtime are different.
Did you see the Result in my screenshot, it works and returns 10000.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry I forgot to update here, Yes it worked and thanks a lot for your help :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Pleasure! I'm glad that it worked ;)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And also please bear in mind that there is a loop here, so it might not have single result. In my code, I was concatenating all id values into stringbuilder.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.