perl hookup - 50 cents worth
perl hookup - 50 cents worth
am 17.06.2006 19:20:14 von shedd2005-tennis
Express 10g Release 2 (10.2), perl 5.8, XP
I installed Oracle's free Express 10g on my XP home box
to learn SQL and so on. Worked great. No DBA, but at least
now, at work, I can look like I know something. :-)
Now I want to hookup perl and motor the database from scripts.
Where can I go to get all the setup info and get a simple
example script. Thanks
Re: perl hookup - 50 cents worth
am 17.06.2006 21:47:40 von Alexander
http://search.cpan.org/~timb/DBI-1.51/lib/DBI/FAQ.pm
Further links:
http://search.cpan.org/~timb/DBI-1.51/
http://www.activestate.com/Products/Download/Download.plex?i d=ActivePerl
http://ppm.activestate.com/PPMPackages/zips/8xx-builds-only/ Windows/
You may have some trouble finding a ppm for DBD::Oracle, as it must
match both your Perl version and your Oracle version. So if all you want
to do is to learn SQL, install PostgreSQL (http://www.postgresql.org/)
and DBD::Pg.
And by the way, run Oracle on a non-Windows OS if you need decent
performance.
Alexander
Hugh Shedd wrote:
>Express 10g Release 2 (10.2), perl 5.8, XP
>
>I installed Oracle's free Express 10g on my XP home box
>to learn SQL and so on. Worked great. No DBA, but at least
>now, at work, I can look like I know something. :-)
>
>Now I want to hookup perl and motor the database from scripts.
>Where can I go to get all the setup info and get a simple
>example script. Thanks
>
>
>
>
>
>
--
Alexander Foken
mailto:alexander@foken.de http://www.foken.de/alexander/
Re: perl hookup - 50 cents worth
am 18.06.2006 02:31:01 von ron
On Sat, 17 Jun 2006 10:20:14 -0700 (PDT), Hugh Shedd wrote:
Hi Hugh
> I installed Oracle's free Express 10g on my XP home box to learn
See /very/ recent messages to this list for some of my experiences.
> Now I want to hookup perl and motor the database from scripts.
1) Create Oracle user: xyz/seekrit
2) Create a system DSN, specifying (a) a name, e.g. oracle-xyz (b) a TNS=
Service
Name of 'XE'. No other options need be set
3) Run this, just like you would for any database (yes, the she-bang line is=
correct, it's for Apache under Windows [1]):
-----><8-----
#!/usr/bin/perl
#
# Name:
#=09test-oracle.pl.
use strict;
use warnings;
use DBI;
# ---------------------
print 'Before connect: ', scalar localtime(), ". \n";
my($dbh_1) = DBI -> connect('dbi:ODBC:oracle-user', 'xyz', 'seekrit',
{RaiseError =3D> 1, PrintError =3D> 0});
print 'After connect: ', scalar localtime(), ". \n"; # Expect 16 seconds=
delay.
eval{$dbh_1 -> do('drop table t')};
eval{$dbh_1 -> do('create table t(i integer)')};
my($sth_1);
$sth_1 =3D $dbh_1 -> prepare('insert into t(i) values (?)');
$sth_1 -> execute($_) for (1 .. 5);
$sth_1 -> finish();
$sth_1 =3D $dbh_1 -> prepare('select * from t');
$sth_1 -> execute();
my($data);
while ($data =3D $sth_1 ->fetch() )
{
=09print "$$data[0]. \n";
}
-----><8-----
[1] http://savage.net.au/Perl/html/upgrade-perl-apache.html
--
Cheers
Ron Savage, ron@savage.net.au on 18/06/2006
http://savage.net.au/index.html
Let the record show: Microsoft is not an Australian company
Re: perl hookup - 50 cents worth
am 18.06.2006 04:14:17 von ron
On Sun, 18 Jun 2006 10:31:01 +1000, Ron Savage wrote:
Hi Ron
For a native Windows command line ODBC client, see also:
http://www.dmst.aueb.gr/dds/sw/outwit/odbc.html
--
Cheers
Ron Savage, ron@savage.net.au on 18/06/2006
http://savage.net.au/index.html
Let the record show: Microsoft is not an Australian company
Re: perl hookup - 50 cents worth
am 19.06.2006 15:31:55 von Tim.Bunce
Hello Ron. Just a couple of minor comments on your example code...
On Sun, Jun 18, 2006 at 10:31:01AM +1000, Ron Savage wrote:
>
> $sth_1 = $dbh_1 -> prepare('insert into t(i) values (?)');
>
> $sth_1 -> execute($_) for (1 .. 5);
> $sth_1 -> finish();
FYI the call to finish() isn't needed here (or in most of the other
places you'll see it used).
> $sth_1 = $dbh_1 -> prepare('select * from t');
> $sth_1 -> execute();
> my($data);
> while ($data = $sth_1 ->fetch() )
> {
> print "$$data[0]. \n";
> }
Using fetchrow_arrayref() is preferable to it's old alias fetch().
The fetch method is retained as a shorthand that's more appropriate
when bind_columns() is being used.
Tim.
p.s. Your style of adding spaces around the method call arrows is
rather unusual - very few people do that.
Re: perl hookup - 50 cents worth
am 20.06.2006 01:50:12 von ron
On Mon, 19 Jun 2006 14:31:55 +0100, Tim Bunce wrote:
Hi Tim
Thanx for the feedback. I don't delude myself into calling it peer review=
:-).
>> $sth_1 -> execute($_) for (1 .. 5);
>> $sth_1 -> finish();
> FYI the call to finish() isn't needed here (or in most of the other
> places you'll see it used).
I realize draining the results of a query with while/fetch does not need to=
be
followed by finish, but I believed this /was/ one of those 'other places'.
Learning never stops.
I do have a policy of using finish when switching from execute to fetch. I=
guess
that's redundant.
> Using fetchrow_arrayref() is preferable to it's old alias fetch().
> The fetch method is retained as a shorthand that's more appropriate
> when bind_columns() is being used.
I notice you don't actually say the code wrong... The reason I used fetch -=
which is not my first preference - was I've seen so many programmers who I
thought knew more than I do using it without binding, that I recently began=
adopting it. I'll have a rethink.
> p.s. Your style of adding spaces around the method call arrows is
> rather unusual - very few people do that.
I'm aware of that.
I like burning up machine cycles getting the parser to scan the extra=
spaces,
since it's the only way I can get Windows to do something even vaguely=
useful.
And it makes a nice contrast to the code of those who put the very same=
extra
spaces inside if statements, writing if ( x ) where I would use if (x).=
[Truely,
I did not check the source of DBI to see where you stand on this issue.]
--
Cheers
Ron Savage, ron@savage.net.au on 20/06/2006
http://savage.net.au/index.html
Let the record show: Microsoft is not an Australian company