Batch Insert
This module lets you add several dances by putting one dance on each line, and separating the fields with pipe characters (the vertical bar, |).
After performing this series of insert operations, I like to show you the result. I could just show you a table with the data you pasted into the form, but if any of the insert operations failed at the MySQL level for any reason, this feedback would be inconsistent. So I prefer to do a search operation for the new records that were just added. That way, you can see at a glance if you got the insertions you expected. But how can we do this?
This particular method requires the following:
- The table has an ID field for each record.
- The ID field is specified as PRIMARY KEY and AUTO_INCREMENT.
Before performing the series of INSERT operations, I perform this query:
my $sql = "SELECT MAX(ID) FROM gen44_rom;";
This query returns the highest ID number currently in use. Since the ID field is set to AUTO_INCREMENT, we know that any records inserted after this time will have higher ID numbers. So we can find all the newly-inserted records like this:
my $sql = "SELECT * FROM gen44_rom WHERE ID > $maxid;";
Then we can display the newly-added records in a table, just as if we'd done a search operation from the search form.