anchor.diff:  -export([create_schema/2]).
   -export([persist/2]).
   -export([delete/3, delete_all/2]).
  --export([prepare/2, execute/2, execute/3]).
  +-export([prepare/3, execute/2, execute/3]).
   -export([find_all/2, find_all/5, find_by/3, find_by/5]).
   
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
positive.code: 
  find_all(DocName, OrderField, Limit, Offset, State) ->
    % Select * is not good...
    Sql0 =
      ["SELECT * FROM ", escape(atom_to_list(DocName)), " "],
    Sql1 =
      case OrderField of
        undefined ->
          Sql0;
        _ ->
          [Sql0, " ORDER BY ", escape(atom_to_list(OrderField)), " "]
      end,
    Sql2 =
      case Limit of
        0 ->
          Sql1;
        _ ->
          [Sql1, " LIMIT ", integer_to_list(Offset), ",", integer_to_list(Limit)]
      end,
    prepare(find_all, Sql2),
    case execute(find_all, State) of
      #result_packet{rows = Rows, field_list = Fields} ->
        Docs   = lists:foldl(
          fun(Row, DocList) ->
  
negative.code:     Id -> Id
    end,
    NewDoc = sumo:set_field(IdField, NewId, Doc),
    % Needed because the queries will carry different number of arguments.
    Statement = case NewId of
      0 -> insert;
      NewId -> update
    end,
    StatementName = prepare(DocName, Statement, fun() ->
      [ColumnDqls, ColumnSqls] = lists:foldl(
        fun({Name, _Value}, [Dqls, Sqls]) ->
          Dql = [escape(atom_to_list(Name))],
          Sql = "?",
          [[Dql|Dqls], [Sql|Sqls]]
        end,
        [[], []],
        NewDoc#sumo_doc.fields
      ),
      [
        "INSERT INTO ", escape(atom_to_list(DocName)),
        " (", string:join(ColumnDqls, ","), ")",
        " VALUES (", string:join(ColumnSqls, ","), ")",
        " ON DUPLICATE KEY UPDATE ",
        string:join([[ColumnName, "=?"] || ColumnName <- ColumnDqls], ",")
      ]
    end),
  
    ColumnValues = lists:reverse([V || {_K, V} <- NewDoc#sumo_doc.fields]),
    case execute(StatementName, lists:append(ColumnValues, ColumnValues), State) of
      #ok_packet{insert_id = InsertId} ->
        % XXX TODO darle una vuelta mas de rosca
        % para el manejo general de cuando te devuelve el primary key
  