38 |
|
|
39 |
$log->info($self->dsn); |
$log->info($self->dsn); |
40 |
|
|
41 |
$self->{_rows} = []; |
$self->{_rows} = {}; |
42 |
|
$self->{_sth} = {}; |
43 |
|
|
44 |
$self->{_dbh} = DBI->connect( $self->dsn, $self->user, $self->passwd, { RaiseError => 1 } ); |
$self->{_dbh} = DBI->connect( $self->dsn, $self->user, $self->passwd, { RaiseError => 1 } ); |
45 |
|
|
70 |
|
|
71 |
$id = $self->input . '-' . $id if $self->input; |
$id = $self->input . '-' . $id if $self->input; |
72 |
|
|
73 |
my @rows = @{ $ds->{_rows} }; |
foreach my $table ( keys %{ $ds->{_rows} } ) { |
|
foreach my $row ( @rows ) { |
|
74 |
|
|
75 |
my @cols = sort keys %$row; |
my @rows = @{ $ds->{_rows}->{$table} }; |
76 |
|
foreach my $row ( @rows ) { |
77 |
|
|
78 |
my $sql = join( '' |
my @cols = sort keys %$row; |
|
, 'insert into ' |
|
|
, ( $self->table || $self->input || 'webpac2' ) |
|
|
. ' (' . join(',', @cols), ')' |
|
|
, ' values (' |
|
|
, join(',', map { '?' } 0 .. $#cols ) |
|
|
, ')' |
|
|
); |
|
|
warn "# SQL: $sql\n"; |
|
|
my $sth = $self->{_dbh}->prepare( $sql ); |
|
79 |
|
|
80 |
warn "# row ",dump( $row ); |
my $sth_id = $table . ':' . join(',',@cols); |
81 |
$sth->execute( map { $row->{$_} } @cols ); |
|
82 |
} |
my $sth |
83 |
|
= $self->{_sth}->{$sth_id} |
84 |
|
; |
85 |
|
|
86 |
|
if ( ! $sth ) { |
87 |
|
|
88 |
|
my $sql = join( '' |
89 |
|
, 'insert into ' |
90 |
|
, $table |
91 |
|
. ' (' . join(',', @cols), ')' |
92 |
|
, ' values (' |
93 |
|
, join(',', map { '?' } 0 .. $#cols ) |
94 |
|
, ')' |
95 |
|
); |
96 |
|
|
97 |
|
$log->debug( "SQL $sth_id: $sql" ); |
98 |
|
|
99 |
|
$sth |
100 |
|
= $self->{_sth}->{$sth_id} |
101 |
|
= $self->{_dbh}->prepare( $sql ) |
102 |
|
; |
103 |
|
}; |
104 |
|
|
105 |
|
$log->debug( "row $table ", sub { dump( $row ) } ); |
106 |
|
$sth->execute( map { $row->{$_} } @cols ); |
107 |
|
|
108 |
|
push @{ $self->{_rows}->{$table} }, $_ foreach @rows; |
109 |
|
|
110 |
push @{ $self->{_rows} }, $_ foreach @rows; |
} |
111 |
|
} |
112 |
|
|
113 |
return 1; |
return 1; |
114 |
} |
} |