sub
new {
my
$class
=
shift
;
my
%args
=
@_
;
my
$self
=
bless
\
%args
,
$class
;
return
$self
;
}
sub
do_batch {
my
$self
=
shift
;
my
%args
=
@_
;
my
$parent
=
$args
{parent};
my
$query_str
=
$args
{query};
my
$opts
=
$args
{opts};
my
$dbi_binds
=
$args
{dbi_binds} || [];
die
'query not defined'
unless
(
$query_str
);
my
$dbh
=
$parent
->get_dbh();
my
$log
=
$opts
->{
log
};
my
$H
=
$opts
->{output};
my
$query
=
$parent
->get_query_object(
$query_str
,
$opts
);
my
$bindvalues
=
$parent
->get_bindvalue_object(
$query
,
$opts
);
my
$key
=
$query
->get_key();
my
@batch
=
$bindvalues
->increment();
while
(
@batch
) {
my
$bound_query
=
$query
->bind_batch(\
@batch
);
$parent
->{__last_query_key__} =
$key
;
$parent
->{__last_query__} =
$bound_query
;
if
(
defined
$opts
->{pre_hook} &&
ref
$opts
->{pre_hook} eq
'CODE'
) {
$opts
->{pre_hook}->();
}
$opts
->{
log
}->info(
$query
->bindstr(
$bound_query
,
@$dbi_binds
))
if
(
$opts
->{
log
});
if
(
defined
$H
) {
if
(
ref
(
$H
) eq
'CODE'
) {
$H
->(
$bound_query
,
@_
);
}
elsif
(
ref
(
$H
) eq
'ARRAY'
) {
push
@$H
,
$query
->bindstr(
$bound_query
,
@$dbi_binds
);
}
elsif
(
ref
(\
$H
) eq
'GLOB'
) {
print
$H
$query
->bindstr(
$bound_query
,
@$dbi_binds
);
}
}
else
{
$dbh
->
do
(
$bound_query
,
undef
,
@$dbi_binds
);
}
if
(
defined
$opts
->{post_hook} &&
ref
$opts
->{post_hook} eq
'CODE'
) {
$opts
->{post_hook}->();
}
@batch
=
$bindvalues
->increment();
last
unless
(
@batch
);
$parent
->auto_throttle(
$opts
);
$parent
->throttle(
$opts
);
}
$parent
->clear(
$key
);
}
1;