0

I make this simple MySQL query using ActiveRecord::Base

sql = "SELECT * FROM schedules WHERE id = 1"
schedule = (ActiveRecord::Base.connection.select_rows sql)[0]

It happens that schedule[9] is BLOB data, but it gets retrieved as a ruby String object. Is that normal? How are BLOB objects represented in ruby? Coming from the Objective-C world, BLOB data is usually represented by NSData objects. Is there some kind of equivalent in Ruby?

3
  • What does schedule.class show? String perhaps? Commented Jul 6, 2012 at 20:54
  • @thisfeller schedule is an Array object Commented Jul 6, 2012 at 20:57
  • If you can, use p schedule and visually inspect the array. An array of bytes, perhaps? Commented Jul 6, 2012 at 21:05

2 Answers 2

1

Strings in ruby are just a sequence of arbitrary bytes - there is no separate data type.

Strings can be given an encoding which tells ruby to interpret the bytes as utf-8, utf-16, ISO-latin etc. when doing various operations on them but there's also the ASCII-8bit encoding (bit of a misnomer) which just means arbitrary bytes.

Sign up to request clarification or add additional context in comments.

Comments

0

If it isn't a serialized record in your model than a Blob is nothing other than a string which doesn't have size constraints. Strings are the base "data" object in Ruby.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.