Wednesday, September 23, 2015

Using if else construct in C - II

#include <stdio.h>
#include <conio.h>

void main ()
{
                clrscr();
                int a;
                printf("FORTUNE TELLER\n");
                printf("please Enter a number between 1 and 5:\t");
                scanf("%d", &a);
                if (a==1)
                {
                                printf("You will have a nice day\n");
                }
                else if (a==2)
                {
                                printf("You will meet some one special today\n");
                }
                else if (a==3)
                {
                                printf("You will win a lottery today\n");
                }
                else if (a==4)
                {
                                printf("You will get a special gift today\n");
                }
                else if (a==5)
                {
                                printf("You will find your true love today today\n");
                }
                else
                {
                                printf("Please enter a number between 1 and 5\n");
                }
                getch();
}
Output:  
FORTUNE TELLER
Enter a number between 1 and 5:   5
You will find true love today.


Using if else construct in C

#include <stdio.h>
#include <conio.h>
void main
{
                clrscr();
                int a;
                printf("Please enter a number: \n");
                scanf("%d",&a);
                if
                                (a<20)
                {
                                printf("%d is less than 20\n", a);
                }
                else
                {
                                printf("%d is greater than 20\n", a);
                }
                getch();
}

Output:  
Please enter a number: 22
22 is greater than 20.

Tuesday, September 15, 2015

C Programming - Scanning and Printing

#include <stdio.h>
#include <conio.h>
int main()
{
                clrscr();
                char adjective[20];
                char food[20];
                char chore[20];
                char furniture[20];
                printf("Enter an adjective:");
                scanf("%s",&adjective);
                printf("Enter a food:");
                scanf("%s",&food);
                printf("entr a household chore (past tense):");
                scanf("%s",&chore);
                printf("Enter an item of furniture:");
                scanf("%s",&furniture);
                printf("\n\nDont touch that %s %s!\n",adjective,food);
                printf("I just %s the %s!\n",chore,furniture);
                getch();
                return(0);
}

Output:  
Dont touch that (adjective) (food)

I just (chore) the (furniture)!

Learning C - print your name

#include <stdio.h>
#include <conio.h>

void main()
{
                clrscr();
                char name[20];
                printf("Enter your name ");
                scanf("%s",&name);
                printf("Hi %s, glad to meet you. ",&name);
                getch();
}


Output: Hi (your name) glad to meet you.

First C Program




#include <stdio.h> 
#include <conio.h> 
void main()
{
            clrscr();
/* my first program in C */
            printf("Hello, World! \n"); 
            getch();
}

1.      The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler to include stdio.h file before going to actual compilation.
2.      The second line of the program #include <conio.h> is a preprocessor command, which tells a C compiler to include conio.h file before going to actual compilation.
3.      The next line void main() is the main function where program execution begins. Void line tells the compiler that the main() function returns no values.
4.      clrscr() function is for clearing  the console.
5.      The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments in the program. So such lines are called comments in the program.
6.      The next line printf(“Hello, World!\n”); is another function available in C which causes the message "Hello, World!" to be displayed on the screen. \n is for entering to a new line.
7.      The getch(); helps to read from keyboard. The function helps to keep the console displayed.


This will be theresult displayed in the console.


Hello, World!

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.

Sunday, June 14, 2015

Customizing SEO Title in WCS


WCS is using SEOPAGEDEFDESC table for maintaining the SEO related attributes such as meta tile, description and keywords. Google crawlers are using the values in meta description and keyword fields while calculating the ranking. Hence it is important to have meaningful & product/category specific values to be generated in each of the pages displayed to the user.

We can either insert values corresponding to each category and product pages in this table or we can insert substitution parameters defined by WCS, which will get evaluated during runtime. There is a pre-defined set of substitution parameters defined by WCS, a few them can be used only in category pages and others in product pages. For eg: <seo:productShortDescription> can be used only in product details pages.

By default, the SEOPAGEDEFDESC table will be populated with the substitution parameters defined by WCS.

There can be situations, where business want us to configure a different set of title and meta description by providing a template, which is applicable to all products/categories. This can be done by using a script/stored procedure to generate meta title and keyword for each product/category based on the template and insert it into the above table. In this case, there will be an entry in  SEOPAGEDEFDESC against each and every product/category. Each time, a new product gets added to WCS, this activity should happen.

Another option to handle this situation is by creating new substitution parameters. This can be done by inserting a new substitution parameter name in SEOPAGEDEFSUBPARAM table. Insert an entry in CMDREG table to override the default implementation class used for substitution parameter.

INSERT INTO CMDREG (storeent_id,interface,classname) VALUES (0, 'com.ibm.commerce.seo.pagedefinition.commands.ProcessSEOSubstitutionParameterCmd', 'com.test.commerce.CustomSubstitutionCmdImpl')

The business logic to generate meta title and description as per the template provided needs to be written in the CustomSubstitutionCmdImpl.