Wednesday, 8 October 2014

Mysql - Alter/Remove default value of a column

Mysql Tech Byte: 
We can remove just the default values of a column(s) in Mysql using the following command. 

Single Column: 
ALTER TABLE < TableName > ALTER < ColumnName > DROP DEFAULT; 

If we execute the above statement, the default value for that particular column will be dropped. 

Multiple Columns: 
ALTER TABLE < TableName > ALTER < ColumnName1 > DROP DEFAULT, ALTER < ColumnName2 > DROP DEFAULT; 

Modify a default value: 

ALTER TABLE < TableName > ALTER < ColumnName1 > DROP DEFAULT, ALTER < ColumnName2 > SET DEFAULT 100; 

This statement removes a default value for ColumnName1 and alters the DEFAULT value of ColumnName2 from its previous value to the new value 100.

Wednesday, 3 October 2012

Language & Country in C#

1. To get the language in full Text like (English/Dutch) use the following code.

CultureInfo.CurrentCulture.Parent.DisplayName

2. To get language in two letter form like (en/ja . .) use the following code.

CultureInfo.CurrentCulture.Parent.Name;

3. To get Country in full Text like "United States/Japan" use the following Code

RegionInfo.CurrentRegion.DisplayName;

4. To get Country in two letter format like (US/JP) use the following code.

RegionInfo.CurrentRegion.Name;

Hope this helps someone.

Have a nice day.
Edwin.

Friday, 23 March 2012

MFC Dialog - Simulate a Mouse Click


Beginner Series.

Sometimes when you are trying to select a row in a listbox (CListBox) which is place in your by name <YourDialogName>, you might do all that should be done to select a row programatically.  But when nothing else works, here is a short cut.  You might notice that if you click on an entry in a list box, you selchanged method will be called.  But when you do a "SetCurSel", it might not be called, because your row will not get selected.  In that case the following short cut works.  You may vary the time interval given in Sleep method based on your mouse configuration.

void <YourDialogName>::SelectRow(int row)
{
     //COMMENT: listBox_URLis the name of the list box, whose row should be selected.


     RECT r; 

     listBox_URL.GetItemRect(row,&r);

     int x=r.left + 10, y= r.top+5;
     const int lParam=y<<16 | x;  // Infuse the X & Y co-ordinates into the lParam
     const int wParam=0;
     listBox_URL.SendMessage(WM_LBUTTONDOWN,wParam,lParam);
     Sleep(20);
     listBox_URL.SendMessage(WM_LBUTTONUP,wParam,lParam); 
}

MFC Dialog - Escape/Enter key disable

Beginner Series


When we start to program using an MFC Dialog, handling the Escape key and Enter key seems to be a challenge.  One way is to override the PreTranslateMessage of the Dialog.
Following is a code snippet


Please replace the <DialogName> with the actual name of the dialog which you have created.  


1. In the header file <DialogName>.h file add the following method, under the protected access modifier. 


virtual BOOL PreTranslateMessage(MSG* msg);


2. In the <DialogName>.cpp file add the following code



BOOL <DialogName>::PreTranslateMessage(MSG* msg)
{
       //COMMENT: Get the ID from which this message is received.
         // If the control matches, then see whether the Windows message is KEYDOWN. 
         // Then check whether the key pressed is Enter key.  Return false.  
         // By returning false, we are instructing the dialog to avoid the default behavior, which might 
         // be to close the dialog.


UINT ctrlID=GetDlgCtrlID(msg->hwnd);
if(ctrlID==<YOUR_CONTROL_ID> )  
{
if(msg->message == WM_KEYDOWN)
{
if(msg->wParam==VK_ENTER)
{
return FALSE;
}
}
}

if(msg->message == WM_KEYDOWN)
{
if(msg->wParam == VK_ESCAPE)
{
return FALSE;
}
}
      // For all the others, please go ahead with the default behavior.  

      return CDialog::PreTranslateMessage(msg);
}

Saturday, 3 March 2012

How to read from registry and display a value.

The Windows Registry is an integral part of the Windows Operating System.  Many of the configurations are not explicitly provided to users.  But folks from Microsoft decide to pin it down only in the registry.  So if you are into Windows programming eventually there will be a need for reading from and writing to registry.  The following examples do just that.  I am newbie to Windows Programming though have a substantial experience and interest in programming.

Code Sample:

The following code sample provides a simple functionality.  This part of code reads the registry key responsible for supressing the java-script error dialog when we browse web pages using Internet Explorer.

Registry Key : HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main

Key Type      : REG_SZ  // Null Terminated string value

void readEntriesFromRegistry()
{
     wchar_t disableScriptDebugger[128]=L"Software\\Microsoft\\Internet Explorer\\Main";
     wchar_t keyValue[3]; // I know the value might be either 'yes' or 'no'
     int keySize=sizeof(wchar_t)*3; // Size in bytes.
     int          errorCode=-1;  // Initialize errorCode
     HKEY hKey=0;             // Initialize key
    // Open Registry key.
 errorCode=RegOpenKeyEx(HKEY_CURRENT_USER,disableScriptDebugger,0,KEY_READ,&hKey);

     if(errorCode==0)
     {
          // Read the value for the registry key.  The value is stored in keyValue
   errorCode=RegQueryValueEx(hKey,L"Disable Script Debugger",0,&keyType,(LPBYTE)keyValue,&keySize);
     }
     CString str(keyValue);
     ATLTRACE(L"The value is : %s \n",str);
    RegCloseKey(hKey);
}  

Note:
If you use the above code snippet repeatedly allocate memory for keyValue and size for keySize everytime, since you may get errorCode as 234 instead of 0.















}

Saturday, 25 February 2012

Oracle SQL Fundamental 1 - Practice Exercise 2


1. select last_name, salary from employees where salary > 12000
2. select last_name, department_id from employees where employee_id=176
3. select last_name, salary from employees where salary not between 5000 and 12000
4. select last_name,job_id,hire_date from employees where last_name in ('Matos', 'Taylor')
5. select last_name, department_id from employees where department_id in (20,50)
6. select last_name, salary from employees where (salary between 5000 and 12000) AND DEPARTMENT_ID in (20,50)
7. select last_name, hire_date from employees where hire_date >='01-JAN-1994' and hire_date<='31-Dec-1994'
8. select last_name, hire_date from employees where manager_id is null
9. select last_name, salary, COMMISSION_PCT from employees where commission_pct is not null
10. select last_name, salary from employees where salary>&salary_amount
11. select employee_id,last_name,salary,department_id from employees where manager_id =&ID_OF_MANAGER order by &ORDER_BY_COLUMN
12. select last_name from employees where last_name like '__a%'
13. select last_name from employees where last_name like '%a%e%' or last_name like '%e%a%'
14. select last_name,job_id, salary from employees where job_id in ('SA_REP','ST_CLERK')  and 17. salary not in (2500,3500,7000)
15. select last_name, salary, commission_pct, salary * commission_pct "Commission" from employees where commission_pct=.2

Wednesday, 22 February 2012

Oracle SQL Fundamental 1 - Practice Exercise 1

List of questions and answers to practice exercises given in Oracle Course Material.

Exercise - 1
1. The following SELECT statement executes successfully.
select last_name, job_id, salary as Sal from employees;
Ans: TRUE

2. The following SELECT statement executes successfully.
select * from job_grades;
Ans: TRUE

3. There are 4 coding errors in the following SQL statement can you identify them ?

select employee_id, last_name sal x 12  ANNUAL SALARY from employees
Errors.
1. Comma after last_name
2. Comma after sal x 12
3. Opening double quote before Annual salary
4. Ending double quote after Annual salary.

Questions 4,5,6 cannot be answered, it just has to be understood.

Question 7.
select employee_id , last_name, job_id,hire_date as "Start Date" from employees

Question 9
select distinct job_id from employees;

Q 10
select employee_id "Emp #",last_name Employee,job_id Job, hire_date as "HireDate" from employees

Q11 - Two possible answers I could think.
1. select last_name||' , '||job_id "Employee and Title" from employees

2. select concat(last_name,concat(' , ',job_id)) "Employee and Title" from employees

Question 12
select employee_id||','||first_name||','||last_name||','||email||','||phone_number||','||hire_date||','||job_id||','||salary||','||commission_pct||','||manager_id||','||department_id "The Output" from employees