Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Delete after Import MOD: - for 2.1.0 - S1S2.pm

Quote Reply
Delete after Import MOD: - for 2.1.0 - S1S2.pm
Hello!

I made a little modification as a start to delete and empty the row after the import has found that there is a link with the same URL existing in the new dababase table.

It works for the import problems and if you have to import the old table again and the S1S2.pm will identity the duplicate and not isert it. It however does not delete the link from the old table, which is what I thought would be better. The code is as follows:

Code:
warning("Unable to insert validated link `$$row[0]' (SQL query: `INSERT INTO ${e_prefix}Links $links_ins_cols VALUES $links_ins_vals'): ".$insert_link_sth->errstr);


my $import_from_old_db = $i_dbh{$Links::DBSQL::Links::db_name}->prepare("SELECT URL FROM $Links::DBSQL::Links::db_table") or critical("Unable to prepare query `SELECT URL FROM $Links::DBSQL::Links::db_table': ".$i_dbh{$Links::DBSQL::Links::db_name}->errstr);

$import_from_old_db->execute() or critical("Unable to execute query `SELECT URL FROM $Links::DBSQL::Links::db_table': ".import_from_old_db->errstr);

my $export_to_new_db = $e_dbh->prepare("SELECT URL FROM ${e_prefix}Links WHERE URL = ?") or critical("Unable to prepare query `SELECT URL FROM ${e_prefix}Links WHERE URL = ?': ".$e_dbh->errstr);

while (my $row = $import_from_old_db->fetchrow_arrayref) {
$export_to_new_db->execute($$row[0]) or warning("Unable to execute query `SELECT URL FROM ${e_prefix}Links WHERE URL = ?': ".$export_to_new_db->errstr);

if ($export_to_new_db->fetchrow_array) {
$e_dbh->do("DELETE FROM $Links::DBSQL::Links::db_table") or critical "Unable to delete URL: ".$e_dbh->errstr;
next;
}
}

I have made some mistakes somewhere above and needs to be corrected. It works fine if there are duplicates. However it deletes the links from the old table even if a link does not belong to a category and is not a duplicate!

What I do not know is how to define in the WHERE clause of one table and equate the field value to anather table. My problem is that the query does not work for delete - as follows:

DELETE FROM $Links::DBSQL::Links::db_table

WHERE $Links::DBSQL::Links::db_table.URL = ${e_prefix}Links.URL

This does not work!

Can anyone help? Are there any problems in the above code? I would like that the two URLs are checked and then deleted after having found duplicate.


Last edited by:

rajani: Dec 17, 2001, 10:13 AM
Quote Reply
Re: [rajani] Delete after Import MOD: - for 2.1.0 - S1S2.pm In reply to
Hi,

You just need:

DELETE FROM $Links::DBSQL::Links::db_table WHERE URL = '$$row[0]'

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Delete after Import MOD: - for 2.1.0 - S1S2.pm In reply to
Hello Alex!

Ack, stupid me.

Thanks


Quote Reply
Re: [Alex] Delete after Import MOD: - for 2.1.0 - S1S2.pm In reply to
Hello Alex!

Works perfect and marvellous! Just tested. Out of four criterias it worked only for three. Now all four works fine. I will develop further some more in here what I think also is interesting for such imports like I have to do.

Thanks, very helpful.