Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created May 29, 2012 16:47
Show Gist options
  • Select an option

  • Save practicingruby/2829478 to your computer and use it in GitHub Desktop.

Select an option

Save practicingruby/2829478 to your computer and use it in GitHub Desktop.
def update(id, params)
# FIXME: This is not secure
sql = params.map { |k,v| "#{k} = #{v.inspect}" }.join(", ")
# BrokenRecord.database is just an instance of Sqlite::Database
BrokenRecord.database.execute %{
update #{@table_name}
set #{sql}
where id = #{id}
}
end
@steveklabnik

Copy link
Copy Markdown

you use ?s in the query and pass an array:

statement = db.prepare("insert into IntegrationLogin (Username, Password, ProjectID) values (?, ?, 1)")
statement.execute [params['username'], params['password']]

http://stackoverflow.com/questions/6231740/inserting-with-multiple-parameters-gives-sqlite3rangeexception

@practicingruby

Copy link
Copy Markdown
Author

@steveklabnik: Yeah, that works just fine for inserts, the problem is that I haven't sorted out how to do it with updates, because ? = ? seems to be invalid syntax.

@steveklabnik

Copy link
Copy Markdown

Ahhhhhhh. My bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment