Re: inserting data coming from a hash
-- Robert <catcher@xxxxxxxxxxxxx>
This is my hash structure:
"Veterans Day" => {
date => '20051111',
type => 'US',
federal => 'true',
active => 'true',
},
Would I just use a placeholder (?) in my statement and pass it in via
that? It will be in a loop as I have quite a few.
Use a hash slice to extract the values in order:
# @fields is the collection of keys from your
# data that match the order of your query.
#
# Nice thing about this trick is that you
# can have more keys in the data than you
# actually insert (e.g., the data may require
# more than one query to insert).
my @fieldz = qw( date type federal active );
my $sth = $dbh->prepare
(
q{
insert
blah blah
values
( ?, ?, ?, ? )
}
);
...
# sometime later you set up a hash[ref] of
# stuff to insert and just hash-slice it
# to get what you need out:
my $data =
{
date => ... ,
type => ... ,
federal => ... ,
active => ... ,
foo => ... , # these don't hurt anything
bar => ... , # since @fields doesn't include them.
}
$sth->execute( @{$data}{@fieldz} );
--
Steven Lembark 85-09 90th Street
Workhorse Computing Woodhaven, NY 11421
lembark@xxxxxxxxxxx 1 888 359 3508
.
Relevant Pages
- Re: handling a duplicate key error from field to field
... Private Sub txtItem_AfterUpdate ... Why are you saving the record to update the field with a query? ... blah blah blah ... typed in the first field is a duplicate key they get the long-winded default ... (microsoft.public.access.formscoding) - Re: Problem emailing query results
... Cleans MI from FN field and concatenates FN.LN.@xxxxxxxxxxxxx as Email field ... that the attached query shows FN LN and the TWO ... "See attached blah blah", True ... assign it to the SQL property of the QueryDef before calling SendObject, ... (microsoft.public.access.modulesdaovba) - Re: Problem emailing query results
... This query generates only one ... Allen Browne - Microsoft MVP. ... "See attached blah blah", True ... assign it to the SQL property of the QueryDef before calling SendObject, ... (microsoft.public.access.modulesdaovba) - Re: Export Data to Multiple XML Files
... selecting on some value of the primary key. ... Let's call the query qryExportOne. ... Dim dbD As DAO.Database ... OutFile = blah blah blah ... (microsoft.public.access.externaldata) - Re: Query Data Type Conversion issue with Criteria
... Even though the actual selected data did not have a ... null in it when looking at the query results, ... I set up the string handling for this specific query, ... Blah blah blah ... ... (comp.databases.ms-access) |
|