-
Notifications
You must be signed in to change notification settings - Fork 78
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
Image type support? #137
Comments
@mjaric @mobileoverlord @moogle19 any thoughts on this one? If you can point me in the right direction I'd happily create a PR to fix this. Thank you! |
@markquezada I'm a bit rusty, haven't work on driver for some time. But you can try to work with binary (varbinary(max) to be precise). What do you think your system would benefit from actual image type? |
@mjaric thanks for getting back to me. I'm working with a legacy system that is already using the mssql image type so I can't really change it. All I need is a way to get the binary string out of the db so I can render it as an image from a controller endpoint. Is there a way to get the driver to just return the raw string from the db? Even if not using it from within an ecto schema? |
The simplest way is to cast(columName as varbinary) in select. Then it will be picked up as binary in elixir. You can create ecto custom type using above to pack it nicely. For raw tds usage, I was planning 2-3 years ago to add pluggable serialization bit I think it is not there (probably never done) |
Unfortunately since using a custom ecto type seems to first require the raw data to be decoded via the TDS adapter, it still failed when I went down that route. That said, I was able to access the data directly, using query =
from s in Student,
select: fragment("CAST(? AS varbinary(max))", s.picture_data),
where: s.id == ^id,
where: not is_nil(s.picture_data)
case Repo.one(query) do
nil -> {:error, :no_image}
binary_data -> {:ok, binary_data}
end Thanks! |
@mjaric facing something similar with geometry/geography type, |
@markquezada, What if field in your model is :binary instead of :string? I'm referring to original issue at top. Somehow I didn't notice it earlier. For geometry, I'll see if ecto custom type could help |
@mjaric I believe the issue happens before the Ecto type, because TDS does not know how to decode this. We either need to explicitly support them all OR we could return unknown types as |
@fnicastri, I created issue #147 for geometry support, it is not that simple and I don't want to block image support |
Environment
ssl_opts
,socket_options
, ...): n/aExpected behavior
Actual behavior
I get a runtime error:
Looks like it's not parsing the binary format correctly. I'd be happy to send in a PR to fix this but so far can't find any documentation on the binary format for the Image column type
The text was updated successfully, but these errors were encountered: