Re: Anyone using Ruby for scripting?

From: Octavian Rasnita <orasnita_at_gmail.com>
Date: Thu, 16 Sep 2010 09:56:35 +0300
Message-ID: <56727D1D9CDF4CFABB46D4F8C8459603_at_octavian>



I recommend Perl.

Not only that it is very flexible and you can use Oracle very easy with it, but you will also have access to the dozens of thousands of Perl modules you can install from CPAN that might also help you to do many things even easier.

A program that access an Oracle database could look like:

use DBI;

my $dbh = DBI->connect("dbi:Oracle:host=10.10.10.10;sid=orcl", "username", "password");

my $sth = $dbh->prepare("insert into users(name, email) values(?, ?)");

$sth->execute('John', 'me_at_host.com'); $sth->execute('Brian', 'b_at_host.net');

my $sth2 = $dbh->prepare("select name, email from users where locality=?"); $sth2->execute('Erevan');

while (my $row = $sth2->fetchrow_hashref) { print $row->{NAME}, "|", $row->{EMAIL}, "\n"; }

Or you will be able to use an ORM like DBIx::Class and after generating the Perl classes for your database schema say... MyDB::Schema using a command, you will need to use a code like:

use MyDB::Schema;

my $schema = MyDB::Schema->connect("dbi:Oracle:host=10.10.10.10;sid=orcl", "username", "password");

my $users = $schema->resultset("Users");

$users->create({
  name => 'john',
  email => 'me_at_host.com',
});

my $users_from_erevan = $users->search({locality => 'Erevan');

Then you will be able to use related data from other tables without doing other queries using something like:

while (my $user = $users_from_erevan->next) {   print $user->name, "|", $user->email, "\n";   print $user->supervisor->name;

  my $clients = $user->clients;

  while (my $client = $clients->next) {
    print $client->name;
  }
}

--Octavian

  • Original Message ----- From: "Steve Harville" <steve.harville_at_gmail.com> To: "Oracle-L Group" <oracle-l_at_freelists.org> Sent: Wednesday, September 15, 2010 3:58 PM Subject: Anyone using Ruby for scripting?

> I'm looking for a common scripting language for system administration
> and Oracle administration. I have lots of shell scripts that work fine
> on Linux but I need something that works unchanged on Windows too. I
> want to rewrite the shell scripts and the new scripts should be easy
> to read and comprehend.
> Any pros, cons or tips would be appreciated.

>

> Steve Harville
>

> http://www.linkedin.com/in/steveharville
> --
> http://www.freelists.org/webpage/oracle-l
>
>
--
http://www.freelists.org/webpage/oracle-l
Received on Thu Sep 16 2010 - 01:56:35 CDT

Original text of this message