Saturday, August 22, 2015

Empty String and NULL values in Oracle DB

If you Want to get empty vales(null values ) from the db. What you will do?

Consider the below example:

We have one Employee table.IT is having fields - Emp_id, Emp_name, Emp_salary and Emp_status
Possible values for the Emp_status are Settled – S
                                                                Cancelled – C
                                                                Not settled – ‘’ or NULL

insert into Employee (Emp_id, Emp_name, Emp_salary, Emp_status) VALUES ('1','A','10000','S');
insert into Employee (Emp_id, Emp_name, Emp_salary, Emp_status) VALUES ('2','B','5000','C');
insert into Employee (Emp_id, Emp_name, Emp_salary, Emp_status) VALUES ('3','C','8000','');
insert into Employee (Emp_id, Emp_name, Emp_salary, Emp_status) VALUES (4','D','10000',NULL);
insert into Employee (Emp_id, Emp_name, Emp_salary, Emp_status) VALUES ('5','E','10000', '  ');

Select * from Employee;

Emp_id
Emp_name
Emp_salary
Emp_status
1
A
10000
S
2
B
5000
C
3
C
8000

4
D
10000

5
E
10000


Emp_status, will be showing the status of employee Salary. S and C (Settled/Cancelled), if it is not settled they are not storing any values(’ ’).

If the user want to select the not settled records, the records that of NULL values need to select from DB. So the user will select
The Actual number of not settled records are 3 (last 3 rows – 3,4 and 5)

Select count(*) from Employee where Emp_status = ''; -- 0  
We are excepting to get count as one for the above query.
But it will not display any rows, since empty strings behave as null values in Oracle.

Select count(*) from Employee where Emp_status = NULL – 0

NULL has no datatype, Null is untyped. So that NULL can fit into any of the datatype column.
But we can't use usual operands (=,<,> ..) to compare null.
So Oracle is providing IS NULL and IS NOT NULL condtions to compare NULL values in DB.

Select count(*)  from Employee where Emp_status is null; -- 2
We have 5th row containing the space. But it will not display for the above query.

Select count(*)  from Employee where trim(Emp_status) is null; -- 3
To display all the rows which is not having any values we have to use above query.

We have one more way to compare NULL:-

NVL(expr1, expr2)

If expr1 contains a NULL value, then replace it with the value of expr2
NVL(trim(Emp_status),'N')  - All the Emp_status which is having NULL will be stored as ‘N’
select count(*) from Employee where NVL(trim(Emp_status),'N') = 'N';           -- 3



The above query will give correct count.

Monday, August 17, 2015

Setting up webserver to use with WCS

Here I will be explaining how to setup an IBM HTTP web server for use with a WCS local development environment. 
Setup steps:
Download the installables and execute the installation script

Keep all the defaults. Especially the directory name: C:\Program Files\IBM HTTP Server this will save you from altering the config files later on.



Do Typical




Uncheck Run as service and IBM HTTP Administration as Service



Update the web server configuration




 Edit the httpd.conf file by by replacing all occurrences of <IHSInstallDir> to the IHS install directory.
 Edit the plugin-cfg.xml by replacing all occurrences of <IHSInstallDir> to the IHS install directory.
 Start your Commerce instance
 Add port 1080 to the virtual host



- Goto the admin console ( http://localhost:9060/ibm/console/secure/logon.do ) - Goto Environment -> Virtual Hosts -> WC_default_host -> Host Aliases - Add a new Alias Host Name: * Port: 1080






Testing steps
1. Start the web server server
Run c:\Program Files\IBM HTTP Server\bin\Apache.exe
2. Start your Commerce Server
3. Test dynamic content
Add the 1080 port to any browsing page. Here are some examples

Finding Unique Exception Details from Logs in WCS

In WCS, all the log details will be generated in SystemOut.log and trace.log files, unless the logging feature is customized. It will be difficult to go through the logs and findout the list of unique exceptions in it, especially in a production environment which will be running in unix/aix servers.

The following unix commands can be used to findout unique exceptions in logs

Getting all the unique exception:

Direct your putty output to a text file and execute the following grep. The text file will have all the exception.

grep -io "[a-zA-Z.0-9]*exception" SystemOut.log | sort -i | uniq

Instead of grepping  exceptions alone we grep the entire lines. This will have little more details.

Direct your putty output to a text file and execute the following grep. The text file will have all the exception with whole line from exception trace.
               
 grep -i 'exception' SystemOut.log | sort -u | uniq –u


Enabling Recently Viewed Section in WCS

WCS supports inbuilt functionality to display recently viewed section to the user. It will display the products the customer has recently viewed. To enable the functionality, the following configuration changes need to be done in wc-server.xml file, which will be present under xml/config/wc-server.xml in WC project.

1. Open wc-server.xml file

2. Look for tag "<Marketing" and set the value of its "version" attribute to "Dialog"

3. Search for "<PersistentSession" element and set the value of the "cookieExpiry" attribute to "30"

4. Search for "<PersonalizationId" element, and set its "enable" attribute to "true"

5. Look for the following string compClassName="com.ibm.commerce.marketing.dialog.trigger.SensorEventListener" and set the value of "enable" attribute to "true"

6. Search for compClassName="com.ibm.commerce.marketingcenter.events.runtime.ExperimentEvaluationECEventListenerImpl". Change the value of its attribute "enable" to "true"


7. Save the changes and restart the server.