| 1 | package DBIx::Skinny::DBD::mysql; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use base 'DBIx::Skinny::DBD::Base'; | ||
| 5 | |||
| 6 | sub sql_for_unixtime { "UNIX_TIMESTAMP()" } | ||
| 7 | |||
| 8 | sub bulk_insert { | ||
| 9 | my ($skinny, $table, $args) = @_; | ||
| 10 | |||
| 11 | return unless @$args; | ||
| 12 | |||
| 13 | my (@cols, @bind); | ||
| 14 | |||
| 15 | # setting cols | ||
| 16 | my ($first_arg,) = @{$args}; | ||
| 17 | for my $col (keys %{$first_arg}) { | ||
| 18 | push @cols, $col; | ||
| 19 | } | ||
| 20 | |||
| 21 | for my $arg (@{$args}) { | ||
| 22 | # deflate | ||
| 23 | for my $col (@cols) { | ||
| 24 | $arg->{$col} = $skinny->schema->call_deflate($col, $arg->{$col}); | ||
| 25 | push @bind, $skinny->schema->utf8_off($col, $arg->{$col}); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | my $sql = "INSERT INTO $table\n"; | ||
| 30 | $sql .= '(' . join(', ', @cols) . ')' . "\nVALUES "; | ||
| 31 | |||
| 32 | my $values = '(' . join(', ', ('?') x @cols) . ')' . "\n"; | ||
| 33 | $sql .= join(',', ($values) x (scalar(@bind) / scalar(@cols))); | ||
| 34 | |||
| 35 | $skinny->_execute($sql, \@bind); | ||
| 36 | |||
| 37 | return 1; | ||
| 38 | } | ||
| 39 | |||
| 40 | 1; | ||
| 41 |