Search This Blog

30 December 2010

How to check if a javascript global variable is defined or not in a javascript function?

We can do it with following code,

if (variablename == undefined){
        variablename = 'XYZ';
}

But for some reason, firefox will throws error with above code. So the solution to that problem is,
if(window.variablename == undefined){
       window.variablename = 'XYZ';
}

29 December 2010

How to insert NULL value in PostgreSQL date column?

The simple query is like,
INSERT INTO table (date_field) VALUES (NULL);

But when we try to run this insert query through PHP application, where we don't know whether the variable is NULL or contain some value, it starts giving error. Here we need to do some programming and query manipulation as shown below,

<?
if(empty($dbDate)) $dbDate = '0000-00-00';
$myQry = "INSERT INTO table (date_field) VALUES (CASE $dbDate WHEN 0 THEN NULL ELSE TO_DATE('{$dbDate}', 'YYYY-MM-DD') END)";

/*Remaining code comes here */
?>

28 December 2010

How to Enable Macro in Microsoft Office Excel 2007?

  • Open Microsoft Office Excel 2007 Click on Office logo at the very Left hand Top
  • Then select "Excel Options", select "Trust Centre" on left hand side and click on "Trust Centre Settings"
  • Select "Macro Settings" and then select "Enable all Macros", if Macros are also written in Visual Basics programming, put check before "Trust access to the VBA project object model"

26 December 2010

How to find Serial number of machine?

To find out the serial number of the machine, go to windows command prompt and type following command on the command prompt,
  1. Start > cmd
  2. C:\Users\XYZ > wmic csproduct get identifyingnumber,vendor,name
It will give you the output like
IdentifyingNumber    Name          Vendor
L3ZZ896                  5897X7Y     LENOVO

Where IdentifyingNumber is Serial number of machine, Name is Productid and Vendor is the name of manufacturer

22 December 2010

CONCAT_WS for PostgreSQL

PostgreSQL do not have function like CONCAT_WS of MySQL, but writing the query as given below we can do much more...


SELECT ARRAY_TO_STRING(ARRAY[initial, firstname, lastname] , ' ') AS user
FROM users

Same as CONCAT_WS function, the above query will ignore fields which are having NULL values, and return the concatenation of remaining fields. But if your fields contains blank value, modify the above query as given below, to get the proper result

SELECT ARRAY_TO_STRING(ARRAY[
CASE title WHEN '' THEN NULL ELSE title END,
CASE firstname WHEN '' THEN NULL ELSE firstname END,
CASE lastname WHEN '' THEN NULL ELSE lastname END], ' ') AS user
FROM users

18 December 2010

Migrate Data from Access 97 to PostgreSQL

To migrate data from Access to PostgreSQL, so many tools are available online. I did try to migrate data with few tools, but no success. I encounter issues with the tables which has boolean fields and with the tables in which access date() and time() function are being used to set default value of a column.

The best way to migrate data from Access to PostgreSQL database, I found is through PostgreSQL ODBC driver. To check how to install and setup PostgreSQL ODBC driver go to Install & Setup PostgreSQL ODBC Driver . Once finished with installation and setup of PostgreSQL ODBC driver, you are ready to migrate the data.

How to migrate data from Access to PostgreSQL using PostgreSQL ODBC?
  • Open the access database, select the table, then click on file, Save As/Export, a “Save As” popup will appear, select “To an external file or database” radio button and click ok.
  • Then in the new popup for “Save as type” select “ODBC database”.
  • An Export window will appear, change the table name if required, or just click ok.
  • “Select Data Source” window will appear, select your PostgreSQL DSN, that you have created as mentioned above. And click ok.
  • Selected table will get exported to your postgres database.

15 December 2010

Install & Setup PostgreSQL ODBC Driver

Install PostgreSQL ODBC Driver
  • Download the latest PostgreSQL 32-bit ODBC Driver by choosing a mirror from http://wwwmaster.postgresql.org/download/mirrors-ftpand then navigating to the odbc/versions/msi/ folder. The current version is psqlodbc_08_03_0100.zip which was released Jan-22-2008.
  • Unzip psqlodbc_08_03_0100.zip
  • Run the psqlodbc.msi file
Setup PostgreSQL ODBC Driver
  • Click Start, Control Panel, then switch the control panel to “Classical View”, if it's already not in classical view or select "System and Security" category.
  • ODBC located inside Administrative Tools folder. Double click ODBC Data Sources. ODBC Data Source Administrator window displays.
  • Select File DSN tab and click Add button, select “PostgreSQL Unicode” from the popup opened.
  • Type in a name “pgCon” for "Create New Data Source” and Click Next
  • Then Click Finish and fill in relevant server, db, username and password.
  • Click the Connection button and uncheck Bools as char as shown in Manager Connection Page 1
  • Click the Page 2 button and check True is -1, and uncheck updateable cursors as shown ODBC Manager Connection Pg 2 and then click OK
  • A DSN (Data Source) with name “ pgCon ” is created and ready to use...

12 December 2010

How to Fix Corrupted Vista Profile?

Follow the following steps in order to recreate a user’s Vista profile when it gets corrupted.
  1. log into user’s workstation with your admin account
  2. Delete user’s local profile on C: drive under users folder
  3. Click on Start and run and type “Regedit”
  4. This will open Registry Editor Window
  5. Click on + sign besides HKEY_LOCAL_MACHINE
  6. Click on + sign besides SOFTWARE
  7. Click on + sign besides MICROSOFT
  8. Click on + sign besides WINDOWS NT
  9. Click on + sign besides CURRENT VERSION
  10. Click on + sign besides PROFILELIST and delete the SID number points to user name in Right side Pane
  11. Close Registry Editor window.
  12. Now RDP into the Server hosting that user’s profile.
  13. Go to Profiles folder and locate the user’s windows vista profile
  14. Rename this profile folder
  15. Ask the user to login and then logoff
  16. Now copy the user’s favorites and Desktop icons from the renamed profile folder to the new profile folder
  17. Ask user to login again and this will create a new profile for the user successfully.

11 December 2010

How to fix network printer dirver error for HP printers

  1. Delete the printer having printing problem from the printer window.
  2. Click on Start and Run and type in Regedit.
  3. This will open Registry editor window.
  4. Click on + sign besides HKEY_LOCAL_MACHINE
  5. Click on + sign besides SYSTEM
  6. Click on + sign besides CurrentControlSet
  7. Click on + sign besides Control
  8. Click on + sign besides Print
  9. Click on + sign besides Environments
  10. Click on + sign besides Windows NT x86
  11. Click on + sign besides Drivers
  12. Click on + sign besides Version-3
  13. Right click on the printer name and delete it
  14. Click on + sign besides Monitors and delete the folder for that printer
  15. Close the Registry Editor
  16. Go to System32 folder under C:\Windows\System32
  17. Click to open spool folder and click to open drivers folder
  18. Click to open w32x86 folder and click on 3 folder
  19. Under 3 folder delete all the instances for the printer giving problems
  20. Reboot computer and install the printer again
  21. It should work fine now.