Created
February 7, 2012 11:26
-
-
Save masapico/1759228 to your computer and use it in GitHub Desktop.
Ruby: SQLite3 insert binary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "sqlite3" | |
| db = SQLite3::Database.new("test.sqlite3") | |
| sql = <<SQL | |
| create table test( | |
| content blob | |
| ) | |
| SQL | |
| db.execute_batch(sql) | |
| binary = File.open("test.pdf", "rb").read | |
| db.execute("insert into test (content) values(?)", SQLite3::Blob.new(binary)) | |
| res = db.execute("select content from test") | |
| File.open("res2.pdf", "wb").write(res[0][0]) | |
| p res[0][0].size |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment