Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

How can I change my script to make multiple connections to do the job

by terrykhatri531 (Novice)
on Jan 10, 2013 at 17:45 UTC ( #1012710=perlquestion: print w/replies, xml ) Need Help??
terrykhatri531 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

The following script does the job with one connection to the database however I need to add routines to make multiple connections to the database to do the job like adding another variable for example $conn=20; and avoid the table name conflicts, can someone please help me do that.

#!/usr/bin/perl use strict; use warnings; use DBI; my $tables=1000; my $rows=100000; my $dbh = DBI->connect ('DBI:Oracle:host=EM12;sid=orcl',"hr","hr") or die "Failed to connect to database: " . DBI->errstr; for my $i (1..$tables) { my $sql = "CREATE TABLE test_data$i(". "id PRIMARY KEY,". "group_id NOT NULL,". "created_at NOT NULL,". "text NOT NULL) AS ". "SELECT ". "rownum,". "MOD(rownum, 5),". "TO_DATE('1-jan-07', ' +dd-mon-yy') + INTERVAL '1' MINUTE * rownum,". "CAST ('xyz' || rownum + AS VARCHAR2(50)) ". "FROM dual ". "CONNECT BY LEVEL <= $rows"; $dbh->do($sql) or die DBI->errstr; } $dbh->disconnect;
Thank you very much in advance.

Regards

Terry
  • Comment on How can I change my script to make multiple connections to do the job
  • Download Code

Replies are listed 'Best First'.
Re: How can I change my script to make multiple connections to do the job
by NetWallah (Abbot) on Jan 10, 2013 at 18:20 UTC
    This meets your specifications:
    my $conn = 20; my @dbh = map { DBI->connect ('DBI:Oracle:host=EM12;sid=orcl',"hr","hr +") or die "Failed to connect to database: " . DBI->errstr} 1..$co +nn; for my $t (1..$tables){ my $sql = .... $dbh[$t % $conn]->do ($sql) or die DBI->errstr; }
    What this achieves is less clear.

                 "By three methods we may learn wisdom: First, by reflection, which is noblest; Second, by imitation, which is easiest; and third by experience, which is the bitterest."           -Confucius

      Hi,

      This is excellent, I love this forum, and thank you very much for your help.

      Regards

      Terry

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1012710]
Approved by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2016-10-01 18:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?






    Results (3 votes). Check out past polls.