Skip to content

Commit

Permalink
Added new feature to "check_exists" processor - overwrite. This will
Browse files Browse the repository at this point in the history
allow already existing records to be removed from the db and readded
(data will continue into output file)
  • Loading branch information
cdimartino committed Jan 28, 2010
1 parent e6feebd commit aa93f42
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/etl/processor/check_exist_processor.rb
Expand Up @@ -32,6 +32,7 @@ def initialize(control, configuration)
@target = configuration[:target] || raise(ETL::ControlError, "target must be specified")
@table = configuration[:table] || raise(ETL::ControlError, "table must be specified")
@columns = configuration[:columns]
@overwrite = configuration[:overwrite] || false

q = "SELECT COUNT(*) FROM #{table_name}"
@should_check = ETL::Engine.connection(target).select_value(q).to_i > 0
Expand Down Expand Up @@ -66,9 +67,19 @@ def process(row)
q << conditions.join(" AND ")
q << " LIMIT 1"

#puts "query: #{q}"
# puts "query: #{q}"
result = conn.select_one(q)
return row if result.nil?
if result.nil?
return row
else
if @overwrite == true
del = "DELETE FROM #{table_name} WHERE " + conditions.join(" AND ")
# puts "Overwriting record: #{del}"
result = conn.delete(del)
# puts "Deleted #{result} rows"
return row
end
end
end

private
Expand Down

0 comments on commit aa93f42

Please sign in to comment.