PyrexKidd has asked for the wisdom of the Perl Monks concerning the following question:
I am using Perl and MySQL to create a customer catalog. What I would like to do is create a change log, so when I update the primary table I have a record of it.
I have created my tables as such:
CREATE TABLE catalog ( phone_number VARCHAR(10) PRIMARY KEY NOT NULL, name VARCHAR(255), address VARCHAR(255), notes VARCHAR(255) ); CREATE TABLE change_log ( transaction_id INT(10) PRIMARY KEY NOT NULL AUTO INCREMENT, timestamp TIMESTAMP, number_record VARCHAR(255), action VARCHAR(255) );
So I update the DB pragmatically like so:
#!/usr/bin/perl use strict; use warnings; use DBI; use DBD::mysql; #this is my config module use DBase::MySQL::Config qw(DB_CUSTOMER_CATALOG DB_USER DB_PW); my $dbh = DBI->connect(DB_CUSTOMER_CATALOG, DB_USER, DB_PW); my $query = "INSERT INTO catalog (phone_number) VALUES ('5555555555'), + ('1111111111');"; $dbh->do($query); $dbh->disconnect();
What I would like to do is: if a record exists, update the record with name, address, etc. and insert a new record into the change log, with number affected and action performed. If a record doesn't exist, insert the new record into the customer catalog (along with name, address, and any notes where applicable) and add a new record to the change log noting the addition.
Thanks in advance for any assistance. This one has had me stuck.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Perl and MySQL for Activity Log
by davido (Cardinal) on Apr 27, 2011 at 06:30 UTC | |
|
Re: Using Perl and MySQL for Activity Log
by moritz (Cardinal) on Apr 27, 2011 at 08:17 UTC | |
by bart (Canon) on Apr 27, 2011 at 10:40 UTC | |
|
Re: Using Perl and MySQL for Activity Log
by wind (Priest) on Apr 27, 2011 at 06:45 UTC | |
|
Re: Using Perl and MySQL for Activity Log
by anonymized user 468275 (Curate) on Apr 27, 2011 at 13:11 UTC | |
|
Re: Using Perl and MySQL for Activity Log
by eff_i_g (Curate) on Apr 27, 2011 at 14:32 UTC | |
|
Re: Using Perl and MySQL for Activity Log
by Anonymous Monk on Apr 27, 2011 at 13:01 UTC |