Skip to content

Instantly share code, notes, and snippets.

@stephenca
Created June 13, 2012 09:12
Show Gist options
  • Save stephenca/2922963 to your computer and use it in GitHub Desktop.
Save stephenca/2922963 to your computer and use it in GitHub Desktop.
Script to populate eav.sql
!/usr/bin/perl
use common::sense;
use DBI;
my $sql = <<'INSERT';
INSERT INTO attr_value_pairs ( attr, value )
VALUES ( ?, ? )
INSERT
my $isql = <<'SQL';
INSERT INTO targets ( email, attr_value_id )
VALUES ( ?, ? );
SQL
my $dbh = DBI->connect( 'dbi:mysql:database=emails;host=localhost'
, emaildb => 'password'
, { PrintError => 0
, RaiseError => 0
} )
or die("Failed to connect: " . $DBH::errstr );
my $ins0 = $dbh->prepare($sql);
my $ins1 = $dbh->prepare($isql);
for my $i ( 0 .. 500000 ) {
my $email = sprintf( 'x%[email protected]', $i );
my %demog = ( forename => sprintf( 'Fore%s', $i )
, surname => sprintf( 'Sur%s', $i )
, title => 'Mr' );
for my $k (keys %demog) {
$ins0->execute( $k, $demog{$k} );
my $id = $dbh->last_insert_id(undef,undef,'attr_value_pairs',undef);
$ins1->execute( $email, $id );
}
}
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment