On Saturday, July 21, 2012 2:52:49 PM UTC-7, binarypaladin wrote:
>
> 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.
>>
>
> Actually, this works. I get this from the SQL:
>
> Model.plugin :prepared_statements
> Model[m1.id]
>
> Model.filter(:id=>:$id).prepare(:first, :m1).call(:id=>m1.id)
> => #<Network
> @values={:id=>"\u0016\u00EF|T\u00C1a\u0011\u00E1\u008BD\u0003+\u00CC\u0081
> \u001C"}>
>
> PREPARE m1: SELECT * FROM `models` WHERE (`id` = ?) LIMIT 1
> EXECUTE n1; ["\u0016\u00EF|T\u00C1a\u0011\u00E1\u008BD\u0003+\u00CC\u0081
> \u001C"]
>
That's good. I forgot that with jdbc/mysql it uses JDBC prepared
statements, which take separate arguments, unlike mysql prepared statements
which send the arguments as a separate query.
If you want to use prepared statements for all of your access that uses the
id field, that's an option. With the prepared_statements plugin, the only
time you'd need manual prepared statements is if you need to use id field
in a custom query. Considering that it is the primary key field, you may
be able to use the prepared_statements_with_pk plugin, though that has some
caveats.
>
>> 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
>>
>
> Depending on how this evolves, this might be the solution.
>
>
>> I don't suppose you'd be amenable to checking if it works on ruby 1.8?
>>
>
> Does running JRuby in 1.8 mode count? I got similar results except:
>
> m1 => #<Model @values={:id=>"\026\357|T\301a\021\341\213D\003+\314\201
> \034"}>
>
If you are getting similar results (with it not working correctly when used
in a regular query), then it doesn't appear to be an encoding issue at the
ruby level.
> If you want me to use real 1.8, let me know. I have to actually install it
> and get the project set up to work in it which will take a bit of time.
> (Can't use JDBC, etc.) With that sai, could this be JDBC specific? I can
> run this in MRI 1.8 or 1.9 and hit it with the C driver if you would like.
>
If the prepared_statements or typecast_on_load plugins can solve your
issue, then it's probably not worth the effort.
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/-/wLpcwDNwrM4J.
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.