Skip to content

Commit 8ee9c84

Browse files
committed
Tweak bulk_insert for SQLite and Oracle
1 parent 58eac4e commit 8ee9c84

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

lib/Data/ObjectDriver/Driver/DBD/Oracle.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ sub bulk_insert {
6868
my $table = shift;
6969
my $cols = shift;
7070
my $rows_ref = shift;
71+
my $attrs = shift || {};
7172

7273
my $sql = "INSERT INTO $table("
7374
. join(',', @$cols)
@@ -76,7 +77,11 @@ sub bulk_insert {
7677
. ")";
7778
my $sth = $dbh->prepare($sql);
7879
foreach my $row (@{ $rows_ref || []}) {
79-
$sth->execute(@$row);
80+
my $i = 1;
81+
for (my $j = 0; $j < @$cols; $j++) {
82+
$sth->bind_param($i++, $row->[$j], $attrs->{$cols->[$j]});
83+
}
84+
$sth->execute;
8085
}
8186
return 1;
8287
}

lib/Data/ObjectDriver/Driver/DBD/SQLite.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,18 @@ sub bulk_insert {
4646

4747
my $cols = shift;
4848
my $rows_ref = shift;
49+
my $attrs = shift || {};
4950

5051
my $sql = "INSERT INTO $table(" . join(',', @{$cols}) . ") VALUES (" . join(',', map {'?'} @{$cols}) . ")\n";
5152

5253
my $sth = $dbh->prepare($sql);
5354

5455
foreach my $row (@{$rows_ref}) {
55-
$sth->execute(@{$row});
56+
my $i = 1;
57+
for (my $j = 0; $j < @$cols; $j++) {
58+
$sth->bind_param($i++, $row->[$j], $attrs->{$cols->[$j]});
59+
}
60+
$sth->execute;
5661
}
5762

5863
# For now just write all data, at some point we need to lookup the

0 commit comments

Comments
 (0)