I have 2 tables: ‘listings’ and ‘multipleDupeCopies’
All the entries in ‘multipleDupeCopies’ also exist in ‘listings’ and need to be deleted from it.
So I wrote a simple SQLite3 query wrapped in a Ruby script to carry out this task.
Its so simple that I don’t understand why it wouldn’t work. I’ve spent several hours trying to understand it but nothing has changed, tried different ways to write the query still the same result: The entries from listings are not deleted! I can see the output to the text file that’s generated after running the script but the table still has all the entries intact. Nothing deleted!!
Here is the script:
require 'sqlite3'
db = SQLite3::Database.new('development.sqlite3')
db.results_as_hash = true;
rows= db.execute("SELECT * FROM multipleDupeCopies ")
rows.each do |row|
puts 'Deleting...'
rowid = row['id']
puts rowid
db.execute("DELETE FROM listings WHERE listings.id = 'rowid' ")
end
Any suggestions please?
EDIT:
Schema for listings
CREATE TABLE "listings"
(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"name" VARCHAR(255),
"telephone" VARCHAR(255),
"fax" VARCHAR(255),
"suite" VARCHAR(255),
"address" VARCHAR(255),
"city" VARCHAR(255),
"province" VARCHAR(255),
"postal_code" VARCHAR(255),
"latitude" VARCHAR(255),
"longitude" VARCHAR(255),
............... many more columns NOT relevant
"created_at" datetime NOT NULL,
"updated_at" datetime NOT NULL
)
Schema for multipleDupeCopies
CREATE TABLE "multipleDupeCopies"
(
"id" INTEGER PRIMARY KEY NOT NULL,
"name" VARCHAR(255),
"telephone" VARCHAR(255),
"fax" VARCHAR(255),
"suite" VARCHAR(255),
"address" VARCHAR(255),
"city" VARCHAR(255),
"province" VARCHAR(255),
"postal_code" VARCHAR(255),
"latitude" VARCHAR(255),
"longitude" VARCHAR(255),
"url" VARCHAR(255)
)
This query worked for me: Thanks to @a_horse_with_no_name ‘s comment