From: lingutln Date: Thu, 9 May 2013 18:14:33 +0000 (+0000) Subject: Added stored procedures file X-Git-Url: http://gitweb.planteome.org/?a=commitdiff_plain;h=33eef3559e56a41fcc79fa60246783c12b07fb0f;p=old-jaiswallab-svn%2F.git Added stored procedures file svn path=/; revision=473 --- diff --git a/image_annotation_db/ia_upload/annotation_data_importer.pl b/image_annotation_db/ia_upload/annotation_data_importer.pl index 6b8a151..9dd9b21 100644 --- a/image_annotation_db/ia_upload/annotation_data_importer.pl +++ b/image_annotation_db/ia_upload/annotation_data_importer.pl @@ -37,6 +37,35 @@ sub establish_db_connection ); } + +sub insert_collection_data_into_database +{ + my($dbh, $collection_data) = @_; + my @collection_data_fields = split(/\t/, $collection_data); + + + #creating image_source + my($source_name) = trim($collection_data_fields[0]); + my($url) = trim($collection_data_fields[1]); + 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'}; + + + + #creating image_source_version + my($source_version) = trim($collection_data_fields[6]); + 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'}; + +} + + sub insert_image_data_into_database { @@ -46,26 +75,35 @@ sub insert_image_data_into_database # Creating curator data and storing the respective id - my($curator_first_name, $curator_last_name) = split(/ /, $image_data_fields[6], 2); - my $curator_email = $image_data_fields[7]; - my $curator_affiliation = $image_data_fields[8]; + my($curator_first_name, $curator_last_name) = split(/ /, trim($image_data_fields[6]), 2); + 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_insertid'}; + my $curator_id = $dbh->{mysql_insert_id}; # Creating taxon data and storing the respective id - my $species = $image_data_fields[4]; + 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); - my $taxon_id = $dbh->{'mysql_insertid'}; + + #$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');"); + $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]); - # preprocessing ip_comment data my $ip_comment = trim($image_data_fields[12]); @@ -76,14 +114,15 @@ sub insert_image_data_into_database my $source_db = trim($image_data_fields[14]); my $source_db_name = ""; my $source_db_id = ""; + if(defined $source_db) { ($source_db_name, $source_db_id) = split(/:/, $source_db, 2); } - my $doi = $image_data_fields[13]; - my $collection_location = $image_data_fields[9]; - my $collection_date = $image_data_fields[11]; - my $comments = $image_data_fields[15]; + my $doi = trim($image_data_fields[13]); + my $collection_location = trim($image_data_fields[9]); + my $collection_date = trim($image_data_fields[11]); + my $comments = trim($image_data_fields[15]); $dbh->do('INSERT INTO annotated_image (curator_id, taxon_id, image_path, collection_location, collection_date, ip_comment, doi, source_db_name, source_db_id, comments) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', undef, $curator_id, $taxon_id, $image_path, $collection_location, $collection_date, $ip_comment, $doi, $source_db_name, $source_db_id, $comments); @@ -109,34 +148,6 @@ sub insert_image_data_into_database } -sub insert_collection_data_into_database -{ - my($dbh, $collection_data) = @_; - my @collection_data_fields = split(/\t/, $collection_data); - - - #creating image_source - my($source_name) = trim($collection_data_fields[0]); - my($url) = trim($collection_data_fields[1]); - 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'}; - - - - #creating image_source_version - my($source_version) = trim($collection_data_fields[6]); - 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'}; - -} - - sub import_image_data { diff --git a/image_annotation_db/ia_upload/stored_procedures.sql b/image_annotation_db/ia_upload/stored_procedures.sql new file mode 100644 index 0000000..47a3736 --- /dev/null +++ b/image_annotation_db/ia_upload/stored_procedures.sql @@ -0,0 +1,7 @@ +# create stored procedure for importing taxon table + +delimiter // +create procedure import_taxon (species_id varchar(45), species_name varchar(80), genus varchar(80)) +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