NAME
DBIx::BulkLoader::Mysql - Perl extension for mysql bulk loading
SYNOPSIS
use DBIx::BulkLoader::Mysql;# non repeating portion of the insert statementmy $insert='insert into bulk_insert (col_a,col_b,col_c) values ';# repeating portion of the insert statementmy $placeholders='(?,?,?)';# how many rows to buffer until insert is calledmy $bulk_insert_count=5;# db connectionmy $dbh=DBI->connect(db connection info here);my $placeholder_count=3;my ($bulk,$error)=DBIx::BulkLoader::Mysql->new(dbh=>$dbh,sql_insert=>$insert,placeholders=>$placeholders);die $error unless $bulk;for( 1 .. 50 ) {$bulk->insert(qw(a b c));}# inserted 50 rows at once$bulk->insert(qw(l l x));# inserted 0 rows$bulk->insert(qw(l l x));# inserted 0 rows$bulk->flush;# inserted 2 rows 1 at a time
DESCRIPTION
Simple buffering bulk loader interface for mysql.
EXPORT
None.
OO Methods
This section covers the OO methods for this package.
- •
-
my ($bulk,$error)=DBIx::BulkLoader::Mysql->new(%hash);
Package constructor.
$bulk is undef on error$error explains why $bulk is undefConstructor options
dbh=>$dbhSets the DBH objectsql_insert=>$insertContains the body of the sql statement minus theplaceholder segment.placeholders=>$placeholdersPlaceholder segment of the sql statementplaceholder_count=>3Optional argumentIf you get strange insert counts or dbi bailsset this option manuallybulk_insert_count=>50Optional argumentSets the number of rows to buffer for insert.prepare_args=>{}Optional argumentArguments to be passed to $dbh->prepareSee DBD::mysql
- •
-
$bulk->flush;Empties the placeholder buffer
- •
-
$bulk->insert($x,$y,$z);Inserts the placeholder arguments onto the buffer stack. This does not cause an insert, unless the total number of rows is the same as the constructor call "bulk_insert_count=>50".
- •
-
my
$columns=$bulk->get_placeholder_count;Gets the total number of column placeholders.
- •
-
my
$buffer_size=$bulk->get_buffer_size;Gets the total size of the array used for insert.
- •
-
my
$sql_single=$bulk->single_sql;Gets the raw sql statement used for single row inserts.
- •
-
my
$bulk_sql=$bulk->bulk_sql;Gets the raw sql statement used for bulk row inserts.
- •
-
my
$single_sth=$bulk->get_prepared_single_sth;Gets the prepared statement handle for single row inserts.
- •
-
my
$bulk_sth=$bulk->get_prepared_bulk_sth;Gets the prepared statement handle for bulk row inserts.
- •
-
my
@buffer=$bulk->get_buffered_data;Returns a list containing the current buffered data
SEE ALSO
DBI, DBD::mysql
Source Forge Project
If you find this software usefil please donate to the Source Forge Project.
DBIx BulkLoader Mysql <https://sourceforge.net/projects/dbix-bulkloader/>
AUTHOR
Michael Shipper
COPYRIGHT AND LICENSE
Copyright (C) 2010 by Michael Shipper
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.