blackadder has asked for the wisdom of the Perl Monks concerning the following question:
Then I follow the above with this sql statement to obtain the primary key values of the Hosts record.$DB->Sql("INSERT INTO Hosts(Host_Name,SAN,location,Country) VALUES ('$host', '$clean_data{$host}'SAN'}', '$clean_data{$host}{'location'}', '$clean_data{$host}{'country'}')");
And then with the following code and sql statment, I insert the primary key value into Apps record to create a relationship between the two (I have already created two blank corresponding tables in ms-access with one-to-many relationship between hosts and apps).die "Sql Failed" . $DB->Error( ) . "\n" if ($DB->Sql ("SELECT Host_ID FROM Hosts WHERE Host_Name='$host'")); my $rec_indx; while ($DB->FetchRow()) { my %data = $DB->DataHash(); $rec_indx = $data{"Host_ID"}; print qq(index key is $rec_indx\n); }
My question is;for my $info (@{$clean_data{$host}{'applications'}}) { unless ($seen{@{$info}}++) { $DB->Sql("INSERT INTO Apps (App_Name,Description,Host_ID) VALUES ('$$info[0]', '$$info[11]', '$rec_indx')"); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SQL statment to insert if none exits and to obtain the primary key of a record with one visit!
by Transient (Hermit) on Jun 16, 2005 at 16:28 UTC | |
by jfroebe (Parson) on Jun 16, 2005 at 16:35 UTC | |
by jhourcle (Prior) on Jun 16, 2005 at 21:05 UTC | |
|
Use indexes, sequences
by mugwumpjism (Hermit) on Jun 16, 2005 at 21:40 UTC |