Thanks... I'll test it and let you know if it works.

Yariv

On Dec 6, 2007 7:28 PM, David King <[EMAIL PROTECTED]> wrote:
>
> >> It looks like the ErlSQL serialization that works for MySQL doesn't
> >> work for Postgres. Check out erlsql.erl. It may be required to pass
> >> it
> >> an extra 'dialect' parameter that it will use to determine the right
> >> serialization.
> > Here's the SQL that's generated:
> > erlydb_psql:193 INSERT INTO my_model(created_on,name) VALUES
> > (20071122142510,'foo');
> > I am fascinated and horrified that MySQL parses 20071122142510 as a
> > timestamp.
> > Do you know of an easy fix off of the top of your head, or should I
> > dive in?
>
> So I dove in, the fix is below. After the patch, the SQL looks like:
>
> erlydb_psql:193 INSERT INTO my_model(created_on,name) VALUES
> ('2007-11-09 04:31:38','my_name')
>
> According to <http://dev.mysql.com/doc/refman/5.0/en/datetime.html>
> and <http://www.postgresql.org/docs/8.0/interactive/datatype-datetime.html
>  >, the time format should work on Postgres and MySQL, but can
> somebody please test it on MySQL and make sure that it works there?
>
>
>
>
>
> Index: src/erlsql/erlsql.erl
> ===================================================================
> --- src/erlsql/erlsql.erl       (revision 215)
> +++ src/erlsql/erlsql.erl       (working copy)
> @@ -45,6 +45,8 @@
>           unsafe_sql/2,
>           encode/1]).
>
> +-compile(export_all).
> +
>   -define(L(Obj), io:format("LOG ~w ~p\n", [?LINE, Obj])).
>
>   %% @doc Generate an iolist (a tree of strings and/or binaries)
> @@ -128,16 +130,19 @@
>       Res;
>   encode({datetime, Val}, AsBinary) ->
>       encode(Val, AsBinary);
> -encode({{Year, Month, Day}, {Hour, Minute, Second}}, false) ->
> -    Res = two_digits([Year, Month, Day, Hour, Minute, Second]),
> -    lists:flatten(Res);
> -encode({TimeType, Val}, AsBinary)
> -  when TimeType == 'date';
> -       TimeType == 'time' ->
> -    encode(Val, AsBinary);
> -encode({Time1, Time2, Time3}, false) ->
> -    Res = two_digits([Time1, Time2, Time3]),
> -    lists:flatten(Res);
> +encode({{Year,Month,Day}, {Hour,Minute,Second}}, false) ->
> +  [Year1,Month1,Day1,Hour1,Minute1,Second1] =
> +    lists:map(fun two_digits/1,[Year, Month, Day, Hour, Minute,
> Second]),
> +  lists:flatten(io_lib:format("'~s-~s-~s ~s:~s:~s'",
> +
> [Year1,Month1,Day1,Hour1,Minute1,Second1]));
> +encode({date, {Year, Day, Month}}, false) ->
> +  [Year1,Month1,Day1] =
> +    lists:map(fun two_digits/1,[Year, Month, Day]),
> +  lists:flatten(io_lib:format("'~s-~s-~s'",[Year1,Month1,Day1]));
> +encode({time, {Hour, Minute, Second}}, false) ->
> +  [Hour1,Minute1,Second1] =
> +    lists:map(fun two_digits/1,[Hour, Minute, Second]),
> +  lists:flatten(io_lib:format("'~s:~s:~s'",[Hour1,Minute1,Second1]));
>   encode(Val, _AsBinary) ->
>       {error, {unrecognized_value, {Val}}}.
>
>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"erlyweb" group.
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/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to