Search This Blog

Wednesday, February 12, 2014

Oracle Database Commands

In Oracle unlike mysql, the database is represented by a schema owner.

A database schema is a logical container for data structures, called schema objects. Examples of schema objects are tables and indexes.

A database user has a password and particular database privileges assigned by the database admin.

In Oracle each user owns a single schema, which has the same name as the user. The schema contains the data for the user owning the schema. For example, the user "chamara" owns the schema "chamara" which contains schema objects such as tables in the database. In a production database, the schema owner usually represents a database application rather than a person.

Using the following commands u can create a schema in oracle database, which is a database you can used within your application.

Connect to the database as the db admin;
 sqlplus sys/admin as sysdba  

Drop user/schema if exists;
 drop user chamaraa cascade;

Create user/schema;
 create user chamaraa identified by chamaraa account unlock;

Grant connect permission;
 grant connect to chamaraa;

Grant other permisssions;
 grant create session,dba to chamaraa;

finally;
 commit;
 exit;

Connect to the created schema;
 sqlplus chamaraa/chamaraa@orcl

Running a script;
 SQL> @C:\path\oracle.sql;


Saturday, February 8, 2014

Simple HTTP GET request processor with Perl

Perl script;

 #!/usr/bin/perl  
 use HTTP::Daemon;  
 use HTTP::Status;  
 use Net::HTTP;  
 my $server = HTTP::Daemon->new(  
   LocalAddr => 'chamaradell',   
   LocalPort => '3113') || die;  
 system(clear);    
 print ("HTTP Server is up at: <URL: ", $server->url, "\n");  
 while(my $client = $server->accept) {  
   while(my $request = $client->get_request) {  
      if($request->method eq 'GET') {  
        print "GET request accepted\n";        
        $client->send_status_line(200, "OK");  
       $client->send_header("Content-Type", "text/html");  
       $client->send_file_response("index.html");  
       $client->close;  
      }  
   }   
   $client->close;  
   undef($client);  
 }  

A simple html page;

 <!DOCTYPE html>  
 <html>  
   <body>  
    <h1>Index</h1>  
    <p>This is a test HTTP Server<p>  
   </body>  
 </html>  

The HTTP server will be started after running the perl script. Now if the browser is pointed to the correct url;

 http://chamaradell:3113/  

This will give the html page in the browser.

If the content is requested using curl (as following);

 $ curl -v -X GET http://chamaradell:3113  

The content will be returned as;

 * Rebuilt URL to: http://chamaradell:3113/  
 * Adding handle: conn: 0x19ecbd0  
 * Adding handle: send: 0  
 * Adding handle: recv: 0  
 * Curl_addHandleToPipeline: length: 1  
 * - Conn 0 (0x19ecbd0) send_pipe: 1, recv_pipe: 0  
 * About to connect() to chamaradell port 3113 (#0)  
 *  Trying 127.0.1.1...  
 * Connected to chamaradell (127.0.1.1) port 3113 (#0)  
 > GET / HTTP/1.1  
 > User-Agent: curl/7.32.0  
 > Host: chamaradell:3113  
 > Accept: */*  
 >   
 < HTTP/1.1 200 OK  
 < Content-Type: text/html  
 < HTTP/1.1 200 OK  
 < Date: Sat, 08 Feb 2014 17:32:49 GMT  
 * Server libwww-perl-daemon/6.01 is not blacklisted  
 < Server: libwww-perl-daemon/6.01  
 < Content-Type: text/html  
 < Content-Length: 112  
 < Last-Modified: Sat, 08 Feb 2014 17:25:01 GMT  
 <   
 <!DOCTYPE html>  
 <html>  
   <body>  
    <h1>Index</h1>  
    <p>This is a test HTTP Server<p>  
   </body>  
 </html>  
 * Connection #0 to host chamaradell left intact  

The HTTP Status 200 is returned by the server by default. You can return any status using that method and test various http clients with this server, for various conditions.