Comments (9)
@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
from tds.
@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 TDS.Raw{binary: ...}
. And now people should be able to create Ecto types that encode/decode to raw. :)
from tds.
@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!
from tds.
@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?
from tds.
@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?
from tds.
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)
from tds.
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 cast
as you suggested:
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!
from tds.
@mjaric facing something similar with geometry/geography type,
it would be nice to have a away to get the raw data from the db
from tds.
@fnicastri, I created issue #147 for geometry support, it is not that simple and I don't want to block image support
from tds.
Related Issues (20)
- Getting MatchError even when passing correct credential HOT 10
- Ecto.Adapters.SQL.query/4 does not set correct type for parameters. HOT 7
- Need help with output parameter - SQL Server 2016 HOT 2
- Federated Auth HOT 3
- Implicit conversion from data type varbinary to date is not allowed HOT 18
- Current Status of this project? HOT 19
- Pull ntlm_auth to master HOT 3
- Support for Table Value Parameters in Tds adapter HOT 3
- Casting to nvarchar(max) returns nil results. HOT 4
- TLS connection error with OTP 25 HOT 5
- FunctionClauseError following a connection redirect HOT 3
- Azure Sql Database error NXDOMAIN HOT 1
- Bureaucracy HOT 2
- Geometry column type support HOT 8
- Connect to SQL server over TCP HOT 4
- Azure Redirect TCP connection closes every 2 minutes HOT 5
- Error connecting to local MSSQL database
- TDS and query prefixes to access several databases inside MSSQL HOT 1
- Ecto queries timeout when using the Ecto.Adapters.Tds adapter to query 10000 rows with columns of floating point numbers HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tds.