Wednesday, December 29, 2010

Progress Bar and Threading in C# .NET

Hi,
Adding a progress bar and updating it without freezing the main UI Form has always been tough for many .NET programmers. Here is a skeleton (demo) application on how to update progress bar on the main window from a secondary thread. This is a skeleton application which you can use as such just by inserting your code snippet in the right place.

Download Source Code (Visual Studio 2008 Project)

You can download and modify the source code for any purpose free of cost.

Wednesday, December 1, 2010

"GROUP BY" does not group some data - Why?


"GROUP BY" clause (tested in PostgreSQL) does not group rows by on-the-fly temporary columns included in SELECT statement. For example, the below SQL will not group properly since 'manager_name' column is included in 'GROUP BY'. But, removing it from 'GROUP BY' will work properly.

Erroneous sql:
SELECT
    emp.name,
    salary.year,
    SUM(salary.amount),
    'Ela' as manager_name -- On the fly temporary column
FROM
    emp
JOIN
   salary ON salary.emp_id = emp.id
GROUP BY   
    emp.name,
    salary.year,
    manager_name -- <-- Here is the problem! This should be removed.
ORDER BY
    emp.name,
    salary.year;   
Corrected SQL:
SELECT
    emp.name,
    salary.year,
    SUM(salary.amount),
    'Ela' as manager_name
FROM
    emp
JOIN
   salary ON salary.emp_id = emp.id
GROUP BY   
    emp.name,
    salary.year
ORDER BY
    emp.name,
    salary.year;   

Monday, November 22, 2010

Introduction to Postgres Stored Procedure


Postgres does not directly seem to support stored procedures. However, it supports it through functions and cursors. Here is an example how to write a stored procedures in PostgreSQL:

1. Create a function that returns a cursor.

CREATE OR REPLACE FUNCTION
    get_employees(emp_cursor refcursor, dept_id int)
RETURNS refcursor AS 
$BODY$
    DECLARE
        sql_statement character varying;
    BEGIN

        sql_statement = 'SELECT id, name FROM emp WHERE dept_id = ' || CAST(dept_id AS character varying);
        
        OPEN emp_cursor FOR EXECUTE sql_statement;
        RETURN emp_cursor;
        
    END
$BODY$
LANGUAGE 'plpgsql' ;

That's all. Your stored procedure is ready to be accessed from your application code.

2. To call the sp from your code, you need to run two sql statements consecutively within a single transaction. Given below is sample JAVA code (A similar approach/workaround should be available in other languages too):
/*
Create your connection object here.
*/

connection.setAutoCommit(false);

/*
The above is required since every statement will be committed automatically by default. If your language does not support the above methodology, try database level transaction with BEGIN END statements.
*/

Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT get_employees('emp_cursor', 1);");
resultSet = statement.executeQuery("FETCH ALL IN emp_cursor;");

/*
Do whatever stuff you want to do with the result set.
*/

connection.commit(); //Commit the transaction
connection.close();

Thursday, August 12, 2010

Wicket quickstart modifed for request response

Download Project Source

1. Initial Screen
2. Enter something and click "Update"
3. Resulting page
This is the first time I am trying a JAVA application (10 years back I had just opened the big JAVA book and left it as such and fully concentrated on C++ and .NET). The above application is a modified version of the quickstart wicket project available in apache website. I have modified it to a request response application which is quite easy to understand if you are a C++ or .NET programmer. (You must have some basic knowledge about wicket)

Tuesday, July 27, 2010

Apache wtih PHP - Ready to use Installation Package

This is a readymade PHP-Apache installation package to work with PHP on Apache Web Server on Windows. Simply download and install the setup. Your PHP development enviornment will be ready right away. This package comes with the following:
PHP Version 5.2.6
Apache Version 2.2.10 (Win32)
PHP MySQL extension

NOTE: Apache will be installed to port number 9090.

Download Setup

This setup is suitable for development environments only. Extra care/settings should be considered for production environments.

Monday, July 19, 2010

Plugin to view Adilife Profiles with Photo

Click here to download setup.

This is a plugin for Pattukottai KMV www.adilife.com. I am a registered member of adilife.com and developed this for my personal use. This plugin is a local application done using Apache and PHP (I am not a well-versed PHP programmer, so forgive me for any bugs.). I have been using this for quite a few months and is useful. This plugin will work until there are no changes or upgrades to adilife pages. (Noted as on 26/07/2010.). If you see any problems with this plugin, please drop me a message.

Advantage of this add-in:
Currently adilife.com does not display profile-photos in search results. This add-in will make the search results display photographs. This saves a lot of time and makes you visit every profile in adilife.com in a very short period of time. Also, this is not a complete application, so some adilife pages may not work as expected. In such cases, please login to www.adilife.com directly to visit such pages.

Instructions to use:
1. Download the installer and install it on your Windows machine. Install it to the location suggested by the installer to avoid possible bugs. Click here to download setup.
NOTE: Vista Users must run the application as Administrator.

2. Once the installation is over, click on "Adilife Plugin" Desktop shortcut icon.

3. You must see adilife login page. You need to login to adilife through this page.
Attention Vista Users (XP users can skip this and go to next step):
On Windows Vista, if you see any error like "Page not found", then run "cmd" (command prompt) as administrator. From command prompt, type the following and press enter:
C:\AdilifePlugin\apache-install.bat.
Now, follow from step 2.


4. After logging in, search for profiles. You must see the results getting displayed with photographs.

You can also shortlist profiles and view them all in one single page. You can even organize the profiles. See the available options here:
IconOption
Shortlist
Interest Sent
Interest Received
Rejected
Clear
Move

Use the menu displayed on top of every page to see your organized profiles.

Instructions to Uninstall:
Start Menu ==> Programs ==> Adilife Plugin ==> Uninstall Adilife Plugin