summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar √Čtienne Deparis 2020-03-28 14:55:45 +0100
committerGravatar √Čtienne Deparis 2020-03-28 14:55:45 +0100
commit99b87beb10464bde73631a977606edde2a523a79 (patch)
tree7a837e130f75c71114b161df6a9f01417736933d
parent18b9cc533f55b9a4275f6e5694b8d868f290944e (diff)
downloadstatus-99b87beb10464bde73631a977606edde2a523a79.tar.gz
status-99b87beb10464bde73631a977606edde2a523a79.tar.xz
status-99b87beb10464bde73631a977606edde2a523a79.zip
feat: Better protect update_status method
-rw-r--r--lib/sqlite_helper.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/sqlite_helper.rb b/lib/sqlite_helper.rb
index bfcc391..cc77647 100644
--- a/lib/sqlite_helper.rb
+++ b/lib/sqlite_helper.rb
@@ -82,7 +82,7 @@ module SqliteHelper
parse_status_details(status)
end
- def update_status(new_details, email)
+ def build_fields_and_bindings(new_details)
fields = []
bindings = []
new_details.each do |k, v|
@@ -95,9 +95,15 @@ module SqliteHelper
@details[k] = v
end
end
+ [fields, bindings]
+ end
+
+ def update_status(new_details, email)
+ mapping = build_fields_and_bindings(new_details)
+ fields = mapping[0].join(', ') + ','
@db.execute(
- "UPDATE statuses SET #{fields.join(', ')}, details = ? WHERE email = ?;",
- bindings + [YAML.dump(@details), email]
+ "UPDATE statuses SET #{fields} details = ? WHERE email = ?;",
+ mapping[1] + [YAML.dump(@details), email]
)
end
end