--- /dev/null
+
+package DbiFloret;
+
+use DBI;
+use Term::ReadKey;
+
+
+sub dbconnect {
+ my $self = @_;
+
+ print "Username: ";
+ chomp(my $username = <STDIN>);
+ print "Password: ";
+ ReadMode('noecho');
+ chomp(my $password = <STDIN>);
+ ReadMode(0);
+ print "\nDatabase: ";
+ chomp(my $database = <STDIN>);
+
+ my $dbh = DBI->connect("DBI:mysql:$database;host=floret.cgrb.oregonstate.edu", $username, $password,
+ { RaiseError=> 1, AutoCommit=>1 }
+ ) or die "Failed to connect to database: $DBI::errstr";
+
+
+ return $dbh;
+}
+
+sub dbconnect_auto {
+ my $self =@_;
+
+ my $username = $_[0];
+ my $password = $_[1];
+ my $database = $_[2];
+
+ my $dbh = DBI->connect("DBI:mysql:$database;host=floret.cgrb.oregonstate.edu", $username, $password,
+ { RaiseError=> 1, AutoCommit=>1 }
+ ) or die "Failed to connect to database: $DBI::errstr";
+
+
+ return $dbh;
+}
+
+
+return 1;
+
use strict;
use English;
use DBI;
+use DbiFloret qw(dbconnect);
use String::Util qw(:all);
# configurations
sub establish_db_connection
{
- return DBI->connect('DBI:mysql:image_annotation;host=floret.cgrb.oregonstate.edu', 'lingutln', 'nikhil_iadb',
- { RaiseError => 1 }
- );
+ return DbiFloret::dbconnect();
}
my($contact_email) = trim($collection_data_fields[3]);
my($contributor_name) = trim($collection_data_fields[2]);
- $dbh->do('INSERT INTO image_source (source_name, url, contact_email, contributor_name) VALUES(?, ?, ?, ?)', undef, $source_name, $url, $contact_email, $contributor_name);
- my $image_source_id = $dbh->{'mysql_insertid'};
-
+ my $image_source_id;
+ my $sth = $dbh->prepare("call import_image_source('$source_name', '$url', '$contact_email', '$contributor_name');");
+ $sth->execute();
+ $sth->bind_col(1, \$image_source_id);
+ $sth->fetch();
#creating image_source_version
my($contribution_date) = trim($collection_data_fields[4]);
my($publication_id) = trim($collection_data_fields[5]);
- $dbh->do('INSERT INTO image_source_version (image_source_id, source_version, contribution_date, publication_id) VALUES(?, ?, ?, ?)', undef, $image_source_id, $source_version, $contribution_date, $publication_id);
- my $image_source_version_id = $dbh->{'mysql_insertid'};
+ my $image_source_version_id;
+ my $sth = $dbh->prepare("call import_image_source_version('$image_source_id', '$source_version', '$contribution_date', '$publication_id');");
+ $sth->execute();
+ $sth->bind_col(1, \$image_source_version_id);
+ $sth->fetch();
+
}
my $curator_email = trim($image_data_fields[7]);
my $curator_affiliation = trim($image_data_fields[8]);
- $dbh->do('INSERT INTO curator (firstname, lastname, primary_email, affiliation) VALUES(?, ?, ?, ?)', undef, $curator_first_name, $curator_last_name, $curator_email, $curator_affiliation);
- my $curator_id = $dbh->{mysql_insert_id};
+ my $curator_id;
+ my $sth = $dbh->prepare("call import_curator('$curator_first_name', '$curator_last_name', '$curator_email', '$curator_affiliation');");
+ $sth->execute();
+ $sth->bind_col(1, \$curator_id);
+ $sth->fetch();
# Creating taxon data and storing the respective id
my $species = trim($image_data_fields[4]);
- my $species = "temp";
my ($genus, $species_name) = split(/\s/, $species, 2);
my $species_id = trim($image_data_fields[5]);
- #$dbh->do('INSERT INTO taxon (species_id, species_name, genus) VALUES(?, ?, ?)', undef, $species_id, $species_name, $genus);
- #$dbh->do("call import_taxon($species_id, $species_name, $genus);");
my $taxon_id;
- my $sth = $dbh->prepare("call import_taxon('temp_id', 'temp_name', 'temp_genus');");
+ my $sth = $dbh->prepare("call import_taxon('$species_id', '$species_name', '$genus');");
$sth->execute();
$sth->bind_col(1, \$taxon_id);
$sth->fetch();
- print "taxon_id is $taxon_id";
-
- #my $taxon_id = $dbh->{mysql_insert_id};
# Forming image_path by concatinating import_location and filename
my $image_path = trim($image_data_fields[1]) . trim($image_data_fields[0]);
--- create stored procedure for importing taxon table
+-- create(drop and create if exists) stored procedure for importing data into image_source table
+DROP procedure if exists import_image_source;
+delimiter //
+create procedure import_image_source (source_name varchar(80), url varchar(255), contact_email varchar(80), contributor_name varchar(80))
+begin
+insert into image_source (source_name, url, contact_email, contributor_name) values (source_name, url, contact_email, contributor_name);
+select last_insert_id();
+end //
+
+
+-- create(drop and create if exists) stored procedure for importing data into image_source_version table
+
+DROP procedure if exists import_image_source_version;
+delimiter //
+create procedure import_image_source_version (image_source_id int(11), source_version varchar(45), contribution_date date, publication_id varchar(45))
+begin
+insert into image_source_version (image_source_id, source_version, contribution_date, publication_id) values (image_source_id, source_version, contribution_date, publication_id);
+select last_insert_id();
+end //
+
+-- create(drop and create if exists) stored procedure for importing data into curator table
+
+DROP procedure if exists import_curator;
+delimiter //
+create procedure import_curator (firstname varchar(80), lastname varchar(80), primary_email varchar(80), affiliation varchar(80))
+begin
+insert into curator (firstname, lastname, primary_email, affiliation) values (firstname, lastname, primary_email, affiliation);
+select last_insert_id();
+end //
+
+-- create(drop and create if exists) stored procedure for importing data into taxon table
+
+DROP procedure if exists import_taxon;
delimiter //
create procedure import_taxon (species_id varchar(45), species_name varchar(80), genus varchar(80))
+begin
insert into taxon (species_id, species_name, genus) values (species_id, species_name, genus);
select last_insert_id();
-end //
\ No newline at end of file
+end //
+
+