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;
}
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.