On Saturday, July 21, 2012 10:55:23 AM UTC-7, binarypaladin wrote:
>
> Yuck. :)
>>
>
> I had a feeling you'd say something like that. Anything involving "MySQL"
> has become "yuck" for me since using PostgreSQL regularly. It even has a
> native UUID type! (Or a native network address type or... the list goes on
> really.)
>
>
>> If I had to guess, this is an encoding issue. What is m1.id.encoding?
>>
>
> m1.id.encoding => #<Encoding:ASCII-8BIT>
>
OK. So it is returned in binary. Theoretically, you should get an error
if it has to convert unless all bytes are in the 7-bit ASCII range. I'm
not sure why, but it is taking your string:
"\u0016\u00EF|T\u00C1a\u0011\u00E1\u008BD\u0003+\u00CC\u0081 \u001C"
And appending it to the query string as:
"?|T?a?D+́ "
Can you try using the prepared_statements plugin and do Model[m1.id] (or
>> just create and execute a similar prepared statement manually)?
>>
>
> You'd have to give me a more concrete example. I just read through the
> prepared statements doc, but don't understand its application.
>
Model.plugin :prepared_statements
Model[m1.id]
or:
Model.filter(:id=>:$id).prepare(:first, :m1).call(:id=>m1.id)
With either of these methods, it should use a placeholder, and pass the
variable as a prepared statement argument. Unfortunately, I'm not sure
that will work on mysql, because on mysql prepared statement arguments are
still sent in a query.
One way to handle this is to typecast to UUID on model load, and the add a
>> literalizer for UUID to use the uuid2binary function with the uuid string
>> value. That may work.
>>
>
> That's certainly a workable solution. I found the TypecastOnLoad plugin
> but I'm having trouble finding how to craft a literalizer for a given
> object. Is there documentation on this somewhere?
>
class Model
plugin :typecast_on_load, :id
def id=(v)
v.is_a?(String) ? super(UUIDTools::UUID.parse_raw(v) : super
end
end
class UUID
def sql_literal(ds)
"uuid2binary(#{ds.literal(to_s)})"
end
end
> I wonder if the m1.id is encoded differently, and when you put it in a
>> query string, it transcodes (because the query string has a different
>> encoding), changing the bytes, which causes the lookup to fail.
>>
>
> I don't know. I tried a bunch of encoding related stuff that didn't help
> much. Ha.
>
I don't suppose you'd be amenable to checking if it works on ruby 1.8?
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/kc9gnAP8ULAJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.