Skip to content

Commit

Permalink
Update sqlite calls to have binds in an array (Deprecated in 1.3 and …
Browse files Browse the repository at this point in the history
…removed in 2.0)
  • Loading branch information
malomalo committed May 16, 2024
1 parent b1ab93b commit 34a21a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion bob_ross.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'byebug'

# Runtime
s.add_runtime_dependency 'sqlite3'
s.add_runtime_dependency 'sqlite3', '>= 1.3.0'
s.add_runtime_dependency 'terrapin'
s.add_runtime_dependency 'mini_mime'
end
12 changes: 6 additions & 6 deletions lib/bob_ross/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def migrate
end

def get(hash, transform)
@db.execute(<<-SQL, hash, transform).to_a
@db.execute(<<-SQL, [hash, transform]).to_a
SELECT hash, transparent, transform, size, transformed_mime, transformed_at FROM transformations
WHERE hash = ? AND transform = ?
SQL
Expand All @@ -95,7 +95,7 @@ def get(hash, transform)

def use(hash, transform, mime)
file = File.open(destination(hash, transform, mime))
@db.execute(<<-SQL, Time.now.to_i, hash, transform, mime)
@db.execute(<<-SQL, [Time.now.to_i, hash, transform, mime])
UPDATE transformations
SET last_used_at = ?
WHERE hash = ? AND transform = ? AND transformed_mime = ?;
Expand All @@ -117,7 +117,7 @@ def set(hash, transparent, transform, mime, path)

FileUtils.mkdir_p(File.dirname(dest))
FileUtils.cp(path, dest)
@db.execute(<<-SQL, hash, transparent ? 1 : 0, transform, stat.size, mime, Time.now.to_i, Time.now.to_i)
@db.execute(<<-SQL, [hash, transparent ? 1 : 0, transform, stat.size, mime, Time.now.to_i, Time.now.to_i])
INSERT INTO transformations (hash, transparent, transform, size, transformed_mime, transformed_at, last_used_at)
VALUES (?, ?, ?, ?, ?, ?, ?)
SQL
Expand All @@ -134,13 +134,13 @@ def set(hash, transparent, transform, mime, path)
end

def del(hash)
entries = @db.execute(<<-SQL, hash).to_a
entries = @db.execute(<<-SQL, [hash]).to_a
SELECT hash, transform, transformed_mime FROM transformations
WHERE hash = ?
SQL

entries.each do |entry|
@db.execute(<<-SQL, entry[0], entry[1], entry[2])
@db.execute(<<-SQL, [entry[0], entry[1], entry[2]])
DELETE FROM transformations
WHERE hash = ? AND transform = ? AND transformed_mime = ?
SQL
Expand All @@ -165,7 +165,7 @@ def purge!(buffer = 0)
if r.nil?
return
else
@db.execute(<<-SQL, r[0], r[1], r[2])
@db.execute(<<-SQL, [r[0], r[1], r[2]])
DELETE FROM transformations
WHERE hash = ? AND transform = ? AND transformed_mime = ?
SQL
Expand Down

0 comments on commit 34a21a1

Please sign in to comment.