Wednesday, January 30, 2008

Regular Expressions Across Multiple Lines

I was looking at this huge java file which had hundreds of SQL statements and thousands of java code interleaved like a spaghetti ! What I really needed was to analyze all the SQL statements in the file since they were all related to a single application which we were supposed to modify. I needed a mechanism to extract all the SQL statements from the file for sake of brevity.

Simple regular expressions using vim or sed did not work since they all deal with a single line, but each one of them provide a mechanism to match regular expression over multiple lines.

sed - the following command will extract all lines between a 'select' and the first ';' following that. Hence you would have printed all the sql queries from a file

sed -ne '/^select/,/;/p' SqlIntensiveFile.java

vim - using the 'g' command can achieve the same. For e.g. the following will delete all the sql queries from the file.

%g/select/,/;/d

Wednesday, January 23, 2008

Formatting Oracle Timestamp

create table temp (a timestamp)

insert into temp values(sysdate)

select to_char(a,'MM/DD/YYYY HH24:MI:SS:FF3') from temp

http://www.databasejournal.com/features/oracle/article.php/2234501

Oracle Instance Configuration Parameters

To find out the parameters that oracle is using for configuring an instance, logon to that instance using sqlplus and execute the following command.

sql> show parameters

This will display list of all oracle configuration parameters with their current values

Monday, January 14, 2008

Block Select in Vim

Go to the visual mode using "ctrl + v" instead of "v", then use the motion arrow keys *hjkl* to select the block you want.

Perform any copy/delete/edit function you would normally perform using vim ( y , d etc)!

Saturday, January 5, 2008

GET POST PUT

When a browser requests a normal page from a server, it uses the "GET" method. This is the standard way to get back information from a server. The information itself may come from a static page, a CGI program, a server-side include page or any other source handled by the server. By definition it is safe for a browser to obtain a page by GET as many times as it likes - it will never cause any permanent action on the server (such as entering a product order).

To perform a permanent action on the server, the "POST" method is used. This method must be handled by a program or script, and the browser should not re-request a POST page without getting the user to confirm it. This POST method is used when a script or program requires a lot of form data input or when the request makes the server perform a real action such as entering an order.

The "PUT" method is similar to the POST method in that it can cause information to be updated on the server. The difference is that the POST method is normally handed a script which is explicitly named by the resource (that is, something that already exists), while a PUT request could be directed at a resource which does not (yet) exist. Another difference is that the POST method can be used in response to a form, while the PUT method can only contain a single data item. The PUT method is suited for publishing pages.


Reference :
http://www.apacheweek.com/features/put