Can we use :xdo_user_name for filter logic with WebLogic? - oracle

Can we use :xdo_user_name for filter logic with WebLogic?
I created a datamodel in oracle BI Publisher,with where clause like below:
WHERE (EMPLOYEE_NO = :xdo_user_name)
which works normally if I login with an employee account.
But I would like to make it show all data when I login as 'weblogic',so I changed it to:
WHERE (EMPLOYEE_NO = :xdo_user_name
OR (CASE WHEN :xdo_user_name = 'weblogic' THEN 1=1 END))
Error is shown:
Character dat, right truncation occurred:for example, an update or insert value is a string that is too long for the column, or a datetime value cannot be assigned to a host variable, because it is too small.
Not so sure about why this error show up. Please advise.

Try it like this...
WHERE EMPLOYEE = CASE WHEN :xdo_user_name = 'weblogic' THEN EMPLOYEE ELSE :xdo_user_name END
this way, when logged in as 'weblogic', where condition will return True for every row - otherwise it will be True just for rows where EMPLOYEE = :xdo_user_name.
Regards...

Related

How to skip update when parameter is null/0 in spring batch with JdbcBatchItemWriter

We have a scenario wherein while doing a batch update on a table using JdbcBatchItemWriter, We are not finding a way to not update is the attribute is null. We don't want to have too many queries and ItemPreparedStatementSetter so we have a single query to update all fields in the table. Different batch jobs set update different attributes of the table
List<Report> summaryList = getSummaryList()
JdbcBatchItemWriter<ItemMktDcGpReport> writer1 = new JdbcBatchItemWriter<>();
String sql_update = GenericConstants.UPDATE_QUERY;
writer1.setDataSource(dataSource);
ItemPreparedStatementSetter<Report> updatePreparedStatementSetter = new ItemMergeUpdatePreparedItemSetter();
writer1.setItemPreparedStatementSetter(updatePreparedStatementSetter);
writer1.setSql(sql_update);
writer1.afterPropertiesSet();
writer1.write(summaryList);
Tried the following seeing few examples on conditional update at the query but it doesn't help yet.
Below is the query. Any help on this will be very much appreciated.
UPDATE_QUERY = "update [dbo].[test_tbl]
SET test_col1 = CASE When ?!=0 then ?
else test_col1 end ,
test_col2 = CASE When ?!=0 then ?
else test_col2 WHERE market=? and country = ?"
I don't want to construct the SQL query based on parameter as I will lose out on the bulk writing feature of JdbcBatchItemWriter. Can someone please suggest the right approach to solve this problem and possibly correct the SQL query I'm writing?

how to update select column in Spring data?

Please check the below query I am trying to update a row by the composite key
my key combination is like:
int id
int versionId
String languageId
and query is:
#Transactional
#Modifying
#Query("update languageEntity l set l.language = :language where l.languageId = :languageId")
int UpdateProcessLanguage(#Param("language ") String processDesTranslation, #Param("languageId ") UserLanguageId languageId);
I am not getting any exception. function is returning 0, means no row effected.
please check what is worng.
It's hard to say without knowing the data. As a first step I would log the generated SQL statements (see how to log sql statements in spring-boot) and check if they look right.
Why you dont wan't to use save() method for that? Just change language property on your object and pass it to the save method. It will update the row.

For table cmdb_rel_ci, I want to retrieve unique parent.sys_class_name with count for "type=In Rack::Rack contains"

For table cmdb_rel_ci, I want to retrieve unique parent.sys_class_name with count for "type=In Rack::Rack contains". I am doing practice in out of the box instance.
At table level URL is as below:
URL
I want to retrieve result from above URL with my below script.
var count = new GlideAggregate('cmdb_rel_ci');
count.addQuery('type','e76b8c7b0a0a0aa70082c9f7c2f9dc64');// sys_id of type In Rack::Rack contains e76b8c7b0a0a0aa70082c9f7c2f9dc64
count.addAggregate('COUNT', 'parent.sys_class_name');
count.query();
while(count.next()){
var parentClassName = count.parent.sys_class_name.toString();
var parentClassNameCount = count.getAggregate('COUNT','parent.sys_class_name');
gs.log(parentClassName + " : " + parentClassNameCount );
}
The issue is I am getting parentClassName empty.
Try this instead:
var parentClassName = count.getValue("parent.sys_class_name")
Since it's a GlideAggregate query (instead of GlideRecord), the query being issued isn't returning all of the fields on the target table. With GlideRecord, dot-walking through a reference field (e.g. parent.sys_class_name) automatically resolves that referenced record to provide access to its field values. This is made possible by the fact that the driving/original query brought back the value of the parent field. This is not happening with GlideAggregate. The query in this case basically looks like:
SELECT cmdb1.`sys_class_name` AS `parent_sys_class_name`, count(*)
FROM (cmdb_rel_ci cmdb_rel_ci0 LEFT JOIN cmdb cmdb1 ON cmdb_rel_ci0.`parent` = cmdb1.`sys_id` )
WHERE cmdb_rel_ci0.`type` = 'e76b8c7b0a0a0aa70082c9f7c2f9dc64'
GROUP BY cmdb1.`sys_class_name`
ORDER BY cmdb1.`sys_class_name`
So, you actually have access specifically to that dot-walked sys_class_name that's being grouped, but not through the dot-walk. The call to getValue("parent.sys_class_name") is expectedly resolved to the returned column aliased as parent_sys_class_name.
That being said, what you're doing probably should also work, based on user expectations, so you've not done anything incorrect here.

case when sum ( condition )= sum (condition) and condition then using db2 system database

Good night, I am working in DB2 and I have been having some troubles making a query with case when
I have to find a way to make a query to define if a record of some category is valid only if the required fields of the relation are required and have been marked as selected, but in this case some registrys are empty and then I must exclude, I have a query like this:
Select (case (sum(category_id) where required='true' and selected='true') = sum(category_id) where required='true' then 'Yes'
else 'no'
from category_table
The problem, is that in some category the required field are all false (it's means do not exist) then I must put a condition like the sum equal to cero, but i always get a syntax error. I have something like this,
Select (case (sum(category_id) where required='true' and selected='true') = sum(category_id) where required='true' and (count(category_id) where required='true' != 0 ) then 'Yes'
else 'no'
from category_table
I have this problem in db2, saddly I can not put the original query hear because the proxy of my work don't le me pass emails to outside or even login at the web page from there.
I would be grateful for any help.
Have you tried using the VALUE function? if no rows will qualify the case conditions then you'll get Zero in the result.

custom reason message for magento reward points

How to add a custom reason message for a reward action ?
I have created :
$customerId = 1303177;
$points = 10;
$customer = Mage::getModel('customer/customer')->load($customerId);
$reward = Mage::getModel('enterprise_reward/reward')
->setCustomer($customer)
->setWebsiteId(2)
->loadByCustomer();
$reward->setPointsDelta($points)
->setAction(Enterprise_Reward_Model_Reward::REWARD_ACTION_ADMIN)
->setComment('Added programmatically')
->updateRewardPoints();
i like to add something like
$reward->setReason('bonus point');
that would be visible in the reason column of the customer reward history ( back office )
If reason column already exists in the Rewards database table, then all you need is to use
$reward->setReason('bonus point');
$reward->save();
to save the values.
But if reason column doesn't exist then first create a new column reason in the database and then use the above code to save the values in that field.

Resources