in reply to Re: Using a multi-level hash in an insert statement...
in thread Using a multi-level hash in an insert statement...

This line:
$sth->bind_param( $i++, $holidays->{$name}->{$_} ) foreach keys %{$hol +idays->{$name}};
Will cause transposing (e.g. '20050101' to be stored as 'name') of the key/values in the insert, because you can't rely on the order that keys() returns.
Unforunately needs to be something like:
$sth->bind_param( $i++, $holidays->{$name}->{$_} ) foreach qw/ name da +te type federal active /;

Or, even better, would be to use SQL::Abstract (disadvantage is that it can't be prepare'd):
use SQL::Abstract; my $sql = SQL::Abstract->new; while( my ($name,$data) = each %holidays ) { my %data = ( %$data, name => $name ); # assuming hash only has key +s corresponding to cols in table my($stmt, @bind) = $sql->insert('your_table_name', \%data); $dbh->do($stmt, {}, @bind); }

Replies are listed 'Best First'.
Re^3: Using a multi-level hash in an insert statement...
by Transient (Hermit) on Apr 21, 2005 at 15:09 UTC
    Ah yes.. my mistake - forgotten about that sort order bit.

    using named placeholders - while not supported for all DB's, would work in lieu of this.