in reply to Re: Re: Re: OT: Oracle SQL issues
in thread OT: Oracle SQL issues

my $qs = 'insert into Promotions (' . join(',', keys %{$hash->{promoti +on}} ) . ',Date_Created,Date_Modified) values (' . join(',', ('?') x scalar( keys %{$hash->{promotion}} ) ) . ',SYSDATE,SYSDATE)'; $sth = $dbh->prepare( $qs ); $sth->execute( @{$hash->{promotion}}{ keys %{$hash->{promotion}} } );

You'll note that my two SYSDATE entries are not part of the bind parameters because I'd expect bind to escape them as strings. When I do a dump of $hash->{promotion} (not quite the same data as I was using in my earlier example):

$VAR1 = { 'Title' => 'Signup PagePoints', 'Trigger_Value' => '', 'Uses_Maximum' => 0, 'Reward_Type' => '5', 'Reward_Quantity' => '50', 'Trigger_Quantity' => '', 'Uses_PerCustomer' => '1', 'Promotion_Phrase' => '50 free page points at signup!', 'Status' => 0, 'Date_Start' => undef, 'Trigger_Type' => '4', 'ID' => '1', 'Date_End' => undef, 'Reward_Value' => '' };

Replies are listed 'Best First'.
Re:... OT: Oracle SQL issues
by seesik (Initiate) on Sep 13, 2001 at 20:11 UTC
    i'm not sure if you're using that hash slice in the execute or not, but if you are, that'd likely be the problem area. execute wants values that correspond to the order of the bind params, and keys %{$hash->{$table}} is going to return a list of the cols (and thus the values) in some arbitrary order. that might actually result in
    $sth->execute(undef, '','50', 0, undef, '','1',1','50 free page points + at signup!',....);
    that obviously supplies undef/NULL for columns that are NOT NULL constrained.

    anyway, if that's just test code, and you're actually doing some $sth->execute(@{$hash->{$table}}{@ordered_cols}), then i'd say that something is still b0rked, and we need to keep looking..

      keys is (i believe) guaranteed to return the hash entries in the same order every time. I've used this technique in the past without hassle.