Re: COPY table FROM STDIN

[prev] [thread] [next] [Date index for 2004/07/23]

From: Andy Harrison
Subject: Re: COPY table FROM STDIN
Date: 19:30 on 23 Jul 2004
On Fri, 23 Jul 2004 09:14:52 -0400, Andy Harrison <aharrison@xxxxx.xxx> wrote:
> How can I do this from Class::DBI?
> 
> 
> > $ret = $dbh->func($line, 'putline');

All set.  This little snippet I wrote does it just fine.

    sub load_sql_file {

        my ( $class, $table, $file_handle, $filename ) = @_;

        $file_handle->close and open $file_handle, $filename ||
            die "unable to reopen $filename:  $!, $@\n";

        my $dbh = $class->db_Main;

        my $sth = $dbh->prepare( "COPY " . $table .  " FROM STDIN" );

        $sth->execute() or die "Unable to execute query: $! ",
            $sth->errstr;
        
        while ( <$file_handle> ) { 
            my $ret = $dbh->func( $_, 'putline' );
        }

        $dbh->disconnect;
    }

        -- 
        Andy Harrison

COPY table FROM STDIN
Andy Harrison 13:14 on 23 Jul 2004

Re: COPY table FROM STDIN
Andy Harrison 19:30 on 23 Jul 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52