Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Prepared Statements. #202

Closed
bunnylushington opened this issue Oct 4, 2015 · 2 comments
Closed

Invalid Prepared Statements. #202

bunnylushington opened this issue Oct 4, 2015 · 2 comments

Comments

@bunnylushington
Copy link

Hi -- I'm having an issue with sumo:persist/2 (using the MySQL store) where initial calls to a store work just fine but subsequent calls with a different number of map elements fail with an "Incorrect arguments to EXECUTE" error. Here's a minimal example of what I mean and the query log that accompanies it:

-module(sumo_test).
-behavior(sumo_doc).

-export([sumo_sleep/1, sumo_wakeup/1, sumo_schema/0]).

-export([test/0]).

sumo_sleep(Data) -> Data.

sumo_wakeup(Data) -> Data.

sumo_schema() -> sumo:new_schema(?MODULE, [
  sumo:new_field(id,     string,  [{length, 36}, id, not_null]),
  sumo:new_field(name,   string,  [{length, 16}]),
  sumo:new_field(age,    integer, []),
  sumo:new_field(weight, text,    []) ]).

test() ->
  X = #{ id => "one", weight => "120 lbs." },
  Y = #{ id => "two", name => "Joe Quuxor", age => 22},
  sumo:persist(?MODULE, X),
  sumo:persist(?MODULE, Y).
[debug] sumo_store_mysql:log:478 Preparing query: sumo_test_update_stmt: <<"INSERT INTO `sumo_test` (`weight`,`id`) VALUES (?,?) ON DUPLICATE KEY UPDATE `weight`=?">>
[debug] sumo_store_mysql:log:478 Executed Query: sumo_test_update_stmt -> ["120 lbs.","one","120 lbs."] (110.633ms)
[debug] sumo_store_mysql:log:478 Using already prepared query: sumo_test_update_stmt: {1,<<"INSERT INTO `sumo_test` (`weight`,`id`) VALUES (?,?) ON DUPLICATE KEY UPDATE `weight`=?">>}
[debug] sumo_store_mysql:log:478 Executed Query: sumo_test_update_stmt -> ["Joe Quuxor","two",22,"Joe Quuxor",22] (1.566ms)
** exception throw: {error,<<"HY000:Incorrect arguments to EXECUTE">>}
     in function  sumo:persist/2 (.../_build/default/lib/sumo_db/src/sumo.erl, line 185)

I don't think I'm doing anything that should be invalid here but please let me know if the error's on my end. Thanks!

@elbrujohalcon
Copy link
Member

The problem is that sumo expects you to always provide all the fields to persist the ones that are null (including the id) should have theundefined value.

@bunnylushington
Copy link
Author

Ah! Well that's fair enough; I was being sort of lazy with my approach. It appears that the functions exported from sumo_internal are sufficient to suss out what fields need to be present. Thanks for your quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants