Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Change some insertions through stored procedures and password hiding.
authorlingutln <lingutln@localhost>
Fri, 10 May 2013 22:56:35 +0000 (22:56 +0000)
committerlingutln <lingutln@localhost>
Fri, 10 May 2013 22:56:35 +0000 (22:56 +0000)
svn path=/; revision=475

image_annotation_db/ia_upload/DbiFloret.pm [new file with mode: 0644]
image_annotation_db/ia_upload/annotation_data_importer.pl
image_annotation_db/ia_upload/stored_procedures.sql

diff --git a/image_annotation_db/ia_upload/DbiFloret.pm b/image_annotation_db/ia_upload/DbiFloret.pm
new file mode 100644 (file)
index 0000000..f27b3b7
--- /dev/null
@@ -0,0 +1,45 @@
+
+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;
index 9dd9b212b41953957889870d5640e79d3f7e201d..80b972ff1c203c38f38819fb595e1eb25c466b0a 100644 (file)
@@ -24,6 +24,7 @@
 use strict;
 use English;
 use DBI;
+use DbiFloret qw(dbconnect);
 use String::Util qw(:all);
 
 # configurations
@@ -32,9 +33,7 @@ use constant IMAGE_DATA_DIR => "image_data";
 
 sub establish_db_connection
 {
-  return DBI->connect('DBI:mysql:image_annotation;host=floret.cgrb.oregonstate.edu', 'lingutln', 'nikhil_iadb',
-         { RaiseError => 1 }
-        );
+  return DbiFloret::dbconnect();
 }
 
 
@@ -50,9 +49,11 @@ sub insert_collection_data_into_database
   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
@@ -60,8 +61,12 @@ sub insert_collection_data_into_database
   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();
+
 
 }
 
@@ -79,27 +84,24 @@ sub insert_image_data_into_database
   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]);
index 149e728499305f07a47a1e48b71b9417ff458dd5..513f10c9bf741c0fdf182495698eb523c14dd169 100644 (file)
@@ -1,7 +1,42 @@
--- 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 //
+
+