MySQL::Insert - extended inserts for MySQL via DBI
# Insert two rows into sample_table using $dbh database handle use MySQL::Insert; $MySQL::Insert::MAX_ROWS_TO_QUERY = 1000; my $inserter = MySQL::Insert->new( $dbh, 'sample_table', [ @field_names ], %param ); # Param can be: # statement = 'INSERT' | 'REPLACE' | 'INSERT IGNORE' (by default) # on_duplicate_update = { field_name => field_value, .. } (not used by default) # simple insertion $inserter->insert_row( { fldname => 'fldvalue1' } ); $inserter->insert_row( { fldname => 'fldvalue2' } ); # multirow insertion $inserter->insert_row( { fldname => 'fldvalue3' }, { fldname => 'fldvalue4' } ); $inserter->insert_row( [ 'fldvalue5' ], [ 'fldvalue6' ] } ); # Insert row into sample_table using $dbh database handle # If fldvalue3 is passed as scalar ref then it is not quoted # Used to insert MySQL built-in functions like NOW() and NULL values. # @field_names must be predefined in case of arrayref row data usage $inserter->insert_row( { fldname => \'NOW()' } ); undef $inserter;
Use multiple-row INSERT syntax that include several VALUES lists. (for example INSERT INTO test VALUES ('1',Some data',2234),('2','Some More Data',23444)). EXTENDED INSERT syntax is more efficient of execution many insert queries. It is not compatible with most RDBMSes.
The following methods are available:
Create new MySQL::Insert object
Set fields list (by plain list or list reference)
Get fields list (or its quantity in scalar context)
Schedule row for insertion
Gleb Tumanov <gleb at reg.ru> (original author) Walery Studennikov <despair at cpan.org> (CPAN distribution)
<gleb at reg.ru>
<despair at cpan.org>
Please report any bugs or feature requests to bug-mysql-insert at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MySQL-Insert. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-mysql-insert at rt.cpan.org
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install MySQL::Insert, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MySQL::Insert
CPAN shell
perl -MCPAN -e shell install MySQL::Insert
For more information on module installation, please visit the detailed CPAN module installation guide.