I am using IBM-Informix for my school project as part of "Informix on-campus" ativity conduted by IBM.
however it is giving me error as "(USE31) - Too few points for geometry type in ST_LineFromText.", in the second linefromtext function.
The problem in the second call to ST_LineFromText() is that you are attempting to pass parameters into it, which isn't possible. You have:
ST_LineFromText('linestring (0 0,v1.pre 0,v1.pre v1.post,0 v1.post,0 0 )',5)
The string contains 'v1.pre' which is not a valid number, etc. If you need to parameterize your query, you either need to generate the string with those values in place, or you need to use a different method. One crude but possible solution is:
ST_LineFromText('linestring (0 0,' || v1.pre || ' 0,' || v1.pre || ' ' ||
v1.post || ',0 ' || v1.post || ',0 0 )', 5)
This may not do the job - but illustrates the problem.
Related
Hi I am trying to run a joins query in rails. I am trying to output specific data from my User model while also getting data from my contactDetails model.. Code:
User.where(user_type: :lender).all.each do |user|
result <<
"#{user.id}, " +
"#{user.contact_details},"
end
The above prints out fine but when I add:
User.where(user_type: :lender).all.each do |user|
result <<
"#{user.id}, " +
"#{user.contact_details}," +
"#{user.contact_details.city}," +
"#{user.contact_details.region}, "
end
Cannot find region or city.
I think what's happening is user.contact_details is returning nil.
That would allow the first interpolation to work, as "#{nil}" just returns an empty string.
However, in the second example, when you call user.contact_details.city and user.contact_details.region, you're calling the methods city and region on nil, hence the error.
You can account for this using the safe operator to return empty strings, i.e.
user.contact_details&.city
# or in older Ruby versions
user.contact_details.try(:city)
Whether you want to have empty strings returned when the association exists is up to you, however, if you don't want them adding you could do something like:
result_string = user.id.to_s
if user.contact_details.present?
result_string += "#{user.contact_details}," +
"#{user.contact_details.city}," +
"#{user.contact_details.region}, "
end
result << result_string
Finally, if you're expecting contact_details to be present, the problem likely lies in their creation and attachment to the user model - if that's the case, I'd suggest having a look at how you're doing this, and opening a new question with the relevant info if you can't get it to work.
Hope that helps - let me know if you've any questions on this at all.
I have solved this using present? method and then placing Ternary operators inside the code to a none applicable message for users who have not provided contact details. There was no need to add includes or joins:
User.where(user_type: :lender).all.each do |user|
result <<
"#{user.id}, " +
"#{user.contact_details.present? ? user.contact_details.country : ' N/A '}," +
"#{user.contact_details.present? ? user.contact_details.region : ' N/A ' }," +
"#{user.contact_details.present? ? user.contact_details.city : ' N/A '}"
end
I am new into using Velocity but this is what I am attempting to do.
Based on a issue type "service request" and custom field option 'a' set description to display 'x'
Based on a issue type "service request" and custom field option 'b' set description to display 'y'
Based on a issue type "service request" and custom field option 'c' set description to display 'z'
I have used the following for this
if (($issue.key == '') & ($issue.type().getname == 'service request') & ($customfieldmanager().getcustomfieldoption = '11504') & ($id == 'a'))
set ($description = 'x')
elseif ($id == 'b')
set ($description = 'y')
else ($id == 'c')
set ($description = 'z')
Seems not to recognise the the custom field id or the custom field selection id.
Anyone recommend what could be going wrong here, I have had no luck and have tried a few different ways and have spent a few days attempting to work this out.
Help would be appreciated.
For logical "AND" use "&&" instead "&". Please see here: http://velocity.apache.org/engine/devel/user-guide.html#relationalandlogicaloperators
if, else, set should have "#" in front.
if else need "end": https://click.apache.org/docs/velocity/user-guide.html#conditionals
In your sample, issue and customfieldmanager should be in velocity scope. So JIRA (or your JIRA plugin) action should have appropriate getIssue() and getCustomFieldManager() methods and you can access them in velocity as $issue and $customFieldManager (or $getIssue() and $getCustomFieldManager()). Pay attention to cases and brackets. Similar situation with getname and getcustomfieldoption. Please see here: https://stackoverflow.com/a/17069545/1537800
I am not sure about lower/upper cases in method names, but corrected version may look like:
#if ($issue.key == '' && $issue.getType().getName() == 'service request' && $customFieldManager.getCustomFieldOption() == '11504' && $id == 'a')
#set ($description = 'x')
#elseif ($id == 'b')
#set ($description = 'y')
#else ($id == 'c')
#set ($description = 'z')
#end
In the view of a rail's app, I want to achieve:
If user's height isn't nil: return the height value with string "cm"
Otherwise: return string "N/A".
I'm wondering if there's a way to do this. The code below:
user.try(:profile_name).try(:push("as Alias")) || "N/A"
isn't working. The part try(:push("cm")) gives me an error. I thought of using the << operator to append strings by using , but I think there should be a neater way to complete this. Is there anyone who can give me a hint?
--another similar example which I want to accomplish but not working:
user.try(:height).try(:to_s).try(:push("cm")) || "N/A"
How about:
(user && user.profile.present?) ? "#{user.profile} as Alias" : 'N/A'
I'm breaking my head for the past three days in calling a DB2 stored procedure from VB Script. I can able to call a SP that is simple but not the one with more IN/OUT parameters.
I use the below code to add parameters for the SP.
oADO_CMD.CommandType = 4
oADO_CMD.CommandText = "schema.sp_name"
oADO_CMD.Parameters.Refresh
Const adVarChar = 200
Const adParamInput = 1
Const adParamOutput = 2
oADO_CMD.Parameters.append oADO_CMD.CreateParameter("test", adVarChar, adParamInput, 4, "1000")
oADO_CMD.Parameters.append oADO_CMD.CreateParameter("tester", adVarChar, adParamInput, 6, "")
when i run in front end i use the below query and it works fine.
call schema.sp_name('1000','')
Everything works fine in one SP but when i use the same method for another SP it just throws me error. But in front end when i give the same data, i can receive the records.
When i looked into the SP about the error im getting it is related to preparing cursor. Seriously i'm not sure what it is because im not very good in SP's. Is this anything about passing values from vbs to DB2 SP ?. Because there are some parameters where i need to pass empty values within double quotes.. or some other thing that causes error... ?
Here is some lines from SP.
CreateSQL.
------------,
MOVE SPACES TO lc_SQLStatement.
EXEC SQL
SET :lc_SQLStatement = TRIM(:lc_SelectClause) || " " ||
TRIM(:lc_FromClause) || " " ||
TRIM(:lc_WhereClause)
END-EXEC.
STRING lc_SelectClause DELIMITED BY SIZE
MOVE SPACES TO lc_SQLStatement.
EXEC SQL
SET :lc_SQLStatement = TRIM(:lc_SelectClause) || " " ||
TRIM(:lc_FromClause) || " " ||
TRIM(:lc_WhereClause)
END-EXEC.
STRING lc_SelectClause DELIMITED BY SIZE
lc_FromClause DELIMITED BY SIZE
lc_WhereClause DELIMITED BY SIZE
INTO lc_SQLStatement
END-STRING.
CreateDynamCursor.
-------------------
EXEC SQL
PREPARE cu_SearchCR FROM :lc_SQLStatement
END-EXEC.
EVALUATE SQLCODE
WHEN 0
CONTINUE
WHEN OTHER
MOVE lnc_04 TO pc_ReturnCode
MOVE lnc_PrepCurErr TO pc_RetCodeDescription
END-EVALUATE.
I'm getting the pc_ReturnCode and pc_RetCodeDescription values as "04" and "error while preparing cu_SearchCR".
I have this simple condition in my ruby code:
if user.text != ("Empty" || "Damaged")
do something...
the thing is that when it is "Damaged" it still enters the loop, so I have to use this:
if user.text != "Empty"
if user.text != "Damaged"
...
..
What is the correct syntax to make the first one work?
Thanks!
Use this:
unless ["Empty", "Damaged"].include?(user.text)
...
end
The problem with your first approach is that a || b means that: if a != nil then it is a, else it is b. As you can see it is good for variables, not constants as they are rarely nil. Your expression ("Empty" || "Damaged") simply equals "Empty".
You want to use the this as a binary operator, the correct form would be:
if (user.text != "Empty") && (user.text != "Damaged")
The upper solution is just shorter. It consists of an array of elements you want to avoid, and you just simply check is the user.text is not present in it.
#Matzi has the right answer, for sure. But here's why what you're doing is failing:
Your statement ("Empty" || "Damaged") evaluates to "Empty"
You're saying return either one of these, whichever non-false thing you find first. In Ruby, any string, number or Object returns true, so you return "Empty" every time.
A better way to lay it out if you really want to use an if statement:
if user.text != "Empty" && user.text != "Damaged"
...
end
I assume, by the way, that you're trying to say "If the user text is neither Damaged nor Empty".
Hope that helps.
if ((text != "Empty") && (text != "Damaged"))