If you're using numeric ID's, why not use the database's autonumber feature?
You can query the autonumber ID after performing the insert using
SELECT LAST_INSERT_ID() (assuming MySQL)
What I'm missing in your question is how the events relate to the articles (which is quite important in determining how to fill the article_event_index-table).
Where does the content of variables @url_prepare, @html_
pages_files_extended, @output_concord_files_prepare, @sys_time_prepare come from?
You will probably need to insert everything in one go:
Loop through files-to-be-processed {
insert article
fetch article_ID
loop through events {
insert event
fetch event_ID
insert (article_ID, event_ID)
}
}
Also, to avoid sql injection and use good practice, try this to insert:
my $sth_insert_article = $dbh->prepare( qq(INSERT INTO article (url, h
+tml_extr_text, concord_file, sys_time) VALUES (?, ?, ?, ?))) or die "
+Unable to prepare insert statement: " . $dbh->errstr;
foreach my $article_index (0 .. @output_concord_files_prepare) {
my $records_inserted = $sth_insert_article->execute($url_prepare[$
+article_index], $html_pages_files_extended[$article_index], $output_c
+oncord_files_prepare[$article_index], $sys_time_prepare[$article_inde
+x]);
if ($records_inserted != 1) {
die "Error inserting records, only [$records_inserted] got ins
+erted: " . $sth->insert_article->errstr;
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.