Error in ecto adapters

Hey guy, i’m trying to use Ecto.Adapters.SQL.query , but it fails when i use this query:

Ecto.Adapters.SQL.query(EBPRepo,"SELECT ItemId, RealStock FROM StockItem WHERE ItemId = ($1)", ["******"])

The error:

** (MatchError) no match of right hand side value: {:error, %Tds.Error{message: nil, mssql: %{class: 16, line_number: 1, msg_text: "Impossible de convertir une valeur char en money. La valeur char a une syntaxe incorrecte.", number: 235, proc_name: "", server_name: "NS3072398\\EBP_2017", state: 0}}}

Thanks for your help everyone!!!

Hi!

Seems like the error says

Unable to convert char value to money. The char value has incorrect syntax.

Should there maybe be some type casting added to your query?

Also, maybe this could be helpful: SQL Server Helper - SQL Server Error Messages

1 Like

Type casting?? like what??

Thanks, i’ll take care of this link

But I solve the problems using this query:

Ecto.Adapters.SQL.query(EBPRepo,"SELECT ItemId, RealStock FROM StockItem FROM ItemId = '#{id}'")

It’s not a best practice to me but it’s the only solution i have!!

1 Like

This is a solution only if you trust that there won’t be sql injection like

id = "1'; delete from StockItem; select '"

Type casting?? like what??

Judging just by the error, you’d need to cast ItemId to money type or ensure that it can be casted automatically.

For more info we’d need to see your table structure and the actual failing query.

1 Like