Wednesday, June 10, 2009

Advantage PostgreSQL XML power

All of us know the greatness of the opensource database PostgreSQL, which is shortly called as PGSQL. This article outrights the power of XML functions usage available in the postgreSQL database.

Lets take a small sample.

Create a small table

CREATE TABLE "user_add"
(
id serial NOT NULL,
"name" character(100) NOT NULL,
address character varying(100),
phone character varying (12),
city character varying(20),
CONSTRAINT id PRIMARY KEY (id)
)

now let insert some sample records for our further actions


INSERT INTO "user_add"("name", address, phone,city)
VALUES ( 'John', '10, East st,Chennai', '111-111-111','Texas');

INSERT INTO "user_add"("name", address, phone)
VALUES ( 'Peter', '11, West st,Chennai', '222-222-222','Texas');

INSERT INTO "user_add"("name", address, phone)
VALUES ( 'Mike', '12, North st,Chennai', '333-333-333','Newyork');


now if you do a select of the table as select * from user_add;

1 | John | 10, East st,Chennai | 111-111-111 | Texas
2 | Peter | 11, West st,Chennai | 222-222-222 | Texas
3 | Mike | 12, North st,Chennai | 333-333-333 | Newyork

now I plan to give these data for an web service request or an ajax request for a request of user by city.

Generally we will be getting this data and then will be formulating that as xml format, which generally is a very consuming and exhausting process, PostgreSQL provides a simplistic way to achive this using its power full xml functions

here is a query

SELECT xmlelement (name city,
xmlattributes(city as "city" ),
xmlagg(xmlelement(name user,
xmlattributes(name as name),
(xmlelement(name address,address)),
(xmlelement(name phone,phone))
)
)
)
as xml from user_add where city = 'Texas' group by city;

you should get the xml



So just inaf to be passed on directly. Sounds amazing....


Monday, August 4, 2008

Get Reviewboard running using apache.


ServerName yourservername
DocumentRoot /var/www/html/reviewboard
ErrorDocument 500 /errordocs/500.html
# Serve django pages

PythonPath "['/var/www/html/'] + ['/var/www/html/reviewboard'] + sys.path"
SetEnv DJANGO_SETTINGS_MODULE reviewboard.settings
SetHandler mod_python
PythonHandler django.core.handlers.modpython
PythonAutoReload Off
PythonDebug Off

# Serve static media without running it through mod_python (overrides the above)

SetHandler None

# Alias static media requests to filesystem
Alias /media /usr/lib/python2.4/site-packages/django/contrib/admin/media
Alias /css /var/www/html/reviewboard/htdocs/css
Alias /images /var/www/html/reviewboard/htdocs/images
Alias /scripts /var/www/html/reviewboard/htdocs/scripts
Alias /errordocs/ /var/www/html/reviewboard/htdocs/errordocs




The /var/www/html/reviewboard is the path of the my review board installation and
/usr/lib/python2.4/site-packages/django/contrib/admin/media is the path of the django installation.

Thursday, October 18, 2007

Sethu Canal Project

Hi Readers,

I would like to express my view on the sethu Canal project (so called Ram Sethu), I neither offend or defend the existence of Ram here. But the political parties mainly caste parties are taking it a issue and everyone including the ruling government is trying to make votes in the election of of it.

Does it not affects the progress of our nation , Are we going to hurdle each projects this way.

We have to think forward, lets for an argument lets take Rama has built that bridge. Wasn't he doing it against the nature that time and what the problem now coming up.

Its all in the minds of politicians to grab votes from the people.

Crores of money will go wasted which have been invested in that so far, who bears the burden , not the politician but the tax payers.

Development projects with a true concerned should be appreciated and carried out without hurdles.

That is the only way to get in the vision 2020.

Friday, August 24, 2007

PHP PDO

PDO :
Sounds like a catchy word, but true its is a very good module that has been available with PHP 5.

In quick terms I would say this is like a generic odbc database abstraction method, IE you could write applications that can work seamlessly with different databases with it.

Here is the explanation from PHP site

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.

PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility.


How to get it

Its available as PECL and also as a PHP module.

The PHP module is best and performance and speed. For configuring goto PHP site

How do I use it

$db = new PDO('mysql:host=localhost;dbname=$database', $dbuser, $dbpass)
or

class myclass extends pdo{

function __construct(){

parent::construct('mysql:host=localhost;dbname=$database', $dbuser, $dbpass);

}

/***

my code */


}

and now

$db=new myclass();


There are three important things in the PDO we need to understand

PDO object
PDO Statement object
PDO Error handler


PDO object is the object we insantiate

ie $db=new pdo('mysql:host=localhost;dbname=$database', $dbuser, $dbpass);

where $db is the pdo object.

Lets see an example of connecting and updating a record in a table test

$db=new pdo('mysql:host=localhost;dbname=$database', $dbuser, $dbpass);

$db_stmt=$db->prepare("update test set name=:name,address=:address where id=:id");

now $db_stmt is the PDO statement handle.

We had made the sql prepare here this is very effective when you want to update an array of users like

$users=array(
0=>array("name"=>"name1","address"=>"test1","id"=>1),
1=>array("name"=>"name2","address"=>"test2","id"=>2),
2=>array("name"=>"name3","address"=>"test3","id"=>3));

//note you have to

foreach($users as $key=>$user){
foreach($user as $col=>$val){
//bind the value for :name , :address ,:id here

$db_stmt->bindValue(":".$col,$val);
//to my knowledge the bindValue will work for binding all values.
//I see this bindParam is not working for the values in where class
//refer php manual for more options
}
//execute it
$db_stmt->execute();
}

There you go you should have updated 3 records.

you can always execute in the old way of

$db->exec("DELETE FROM test WHERE id=1");

which will return the no of affected rows for this.

Please put comments if you have any doubts.

Friday, July 27, 2007

A Tribute to South INDIA

Friends
I would like to tribute this video in honor of south India , where I do hail from, This video describes about my native town srirangam and also about the Greatest king Raja Raja Cholan.
Its a 52 mins video but worth seeing.

Google News on Tamil

Monday, June 18, 2007

US Visa Guidelines


Its required to be there at least an hour before the interview time of yours.

Keep your passport and visa interview letter Ready to show to the security at the gate.

Make sure you do not have any mobile or electronic devices or cosmetics or sharp elements with you.

All your covers / letters should be uncovered and never keep some closed cover material.

You need to undergo a clear security check and also they will check all your documents so dont keep any thing in closed cover , take it in a file so that you / they can handle it easily

Next on passing on to a Big heavy door You will be either asked to sit or directly asked to stand in a queue , There hand over your passport / visa interview and the visa application form,Visa payment slip altogether to the person.

The person may ask you to write your name in the application form in your native language and every thing will be given in a file by them and you need to proceed to the next part.

You will be asked to be in a queue and called upon your interview time and in there you will be asked for a biometric finger print recognition of your left index finger and right index finger , here you have to give you passport alone.Once this is over you will be asked either to wait or will be taken to another queue to the visa counselor.

Here on going to the counselor hand over the file given outside in a flat way via that glass door.

Wait till you are called by them and greet the person like Hello , Good morning or approriate to the time you meet them..

Keep your files in handy so that give them the documents what they need do not give the entire folder.

Be clear on your
Purpose of travel.
Date of travel.
Stay.
Sponsor.
Previous travel to US and other countries.(with date and period of stay and purpose)
Your salary(both monthly and annualy)
Your company details
Your Client details



Question generally which were asked was

1) How are you

2) Whom do you work for.

3) What your company do

4) Who is your client

5) What kind of business they do


5) Whats is your monthly or annual salary

6) What is the purpose of visit




Then the counselor will say your visa is approved or not approved.


if approved they will take the passport else they will return it to you.