According to execute_array in DBI, it sounds very much like this will accomplish what you want. Can you show us the code you tried to implement this that failed? Caveat: I've never tried to do this.

Update: I did a little prototyping for my own edification based on the code examples in the above link. I successfully got column-wise insertions with:

#!/usr/bin/perl use strict; use warnings; use DBI; my $db = DBI->connect("dbi:SQLite:dbname=junk.db","","", { PrintError => 0, RaiseError => 0, }); $db->do(<<EOSQL); DROP TABLE content EOSQL $db->do(<<EOSQL) or die "Table create failed: ", $db->errstr; CREATE TABLE content ( one VARCHAR2(10) NOT NULL, two VARCHAR2(10) NOT NULL, three VARCHAR2(10) NOT NULL, four VARCHAR2(10) NOT NULL, CONSTRAINT pk PRIMARY KEY (one) ) EOSQL my @data = (['a' .. 'd'], ['e' .. 'h'], ['i' .. 'l'], ['m' .. 'p'], ); my $query = $db->prepare(<<EOSQL); INSERT INTO content ( one, two, three, four ) VALUES (?,?,?,?) EOSQL my $tuples = $query->execute_array( { ArrayTupleStatus => \my @tuple_status }, @data, ); print $query->errstr if defined $query->errstr; if ($tuples) { print "Successfully inserted $tuples records\n"; } else { for my $tuple (0 .. @tuple_status-1) { my $status = $tuple_status[$tuple]; $status = [0, "Skipped"] unless defined $status; next unless ref $status; printf "Failed to insert (%s, %s): %s\n", $data[0][$tuple], $data[1][$tuple], $data[2][$tuple], $dat +a[3][$tuple], $status->[1]; } }

If instead you have a row-wise data structure, you can swap the above execute_array for:

my $tuples = $query->execute_array( { ArrayTupleStatus => \my @tuple_status, ArrayTupleFetch => sub { return shift @data; }, }, );

In reply to Re: Bind 2D array to SQL by kennethk
in thread Bind 2D array to SQL by sinpeak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.