lib/pg_conn.rb in pg_conn-0.13.1 vs lib/pg_conn.rb in pg_conn-0.13.2

- old
+ new

@@ -560,17 +560,31 @@ # Update record(s) def update(schema = nil, table, expr, hash) table = [schema, table].compact.join(".") assignments = hash.map { |k,v| "#{k} = #{quote_literal(v)}" }.join(", ") - constraint = (expr.is_a?(String) ? expr : "id = #{quote_literal(expr)}") + constraint = + case expr + when String; expr + when Integer; "id = #{quote_literal(expr)}" + when Array; "id in #{quote_literal_list(expr)}" + else + raise ArgumentError + end exec %(update #{table} set #{assignments} where #{constraint}) end # Delete record(s) def delete(schema = nil, table, expr) table = [schema, table].compact.join(".") - constraint = (expr.is_a?(String) ? expr : "id = #{quote_literal(expr)}") + constraint = + case expr + when String; expr + when Integer; "id = #{quote_literal(expr)}" + when Array; "id in #{quote_literal_list(expr)}" + else + raise ArgumentError + end exec %(delete from #{table} where #{constraint}) end # Execute SQL statement(s) in a transaction and return the number of # affected records (if any). Also sets #timestamp unless a transaction is