in reply to Perl Access Database

For this type of scenario, I usually store individual column names and values in a pair of arrays and join them, something like this
if(is_valid($form{'field1'})){ push(@fields, 'field1'); push(@values, $form{'field1'}); } if(is_valid($form{'field2'})){ push(@fields, 'field2'); push(@values, $form{'field2'}); } # repeat, with appropriate validity tests, for # each field/column $query = $dbh->prepare("insert into table (" . join(',',@fields) . ") values (" . join(',', @values) . ")"); $query->execute;

Replies are listed 'Best First'.
Re: Re: Perl Access Database
by Spudnuts (Pilgrim) on May 23, 2001 at 00:55 UTC
    Prepared DBI queries are even nicer--you don't have to worry about doing the escaping of the values. Just use a ? for each value in @values in the SQL statement and then pass @values into $query->execute().