# Mssql image field: ado returns an array

**URL:** <https://www.ruby-forum.com/t/mssql-image-field-ado-returns-an-array/128140>\
**Category:** Ruby\
**Created:** [February 5, 2008, 10:51am UTC](https://www.ruby-forum.com/t/mssql-image-field-ado-returns-an-array/128140 "2008-02-05T10:51:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [February 5, 2008, 10:51am UTC](https://www.ruby-forum.com/t/mssql-image-field-ado-returns-an-array/128140/1 "2008-02-05T10:51:41Z")

</div>

Hi,  
Im trying to get an image out a mssql image type datafield thru DBI:ADO.  
The problem is that the result returned is an array and not a binary  
string and thus the image is garbage when i write it to a file. Is there  
a way to turn the array into a binary string ? Or some other solution ?

this is the function i use to get the photo out of the database:  
def self.get\_photo(dbh)  
sql = "SELECT p\_photo, photoinfo, photo " +  
"FROM photos " +  
"WHERE p\_photo = ‘0’ "  
sth = dbh.prepare(sql)  
sth.execute()  
row = sth.fetch  
return row[2]  
end

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [February 17, 2008, 4:29pm UTC](https://www.ruby-forum.com/t/mssql-image-field-ado-returns-an-array/128140/2 "2008-02-17T16:29:14Z")

</div>

David De vits wrote:

> Hi,  
> Im trying to get an image out a mssql image type datafield thru DBI:ADO.  
> The problem is that the result returned is an array and not a binary  
> string and thus the image is garbage when i write it to a file. Is there  
> a way to turn the array into a binary string ? Or some other solution ?
> 
> this is the function i use to get the photo out of the database:  
> def self.get\_photo(dbh)  
> sql = "SELECT p\_photo, photoinfo, photo " +  
> "FROM photos " +  
> "WHERE p\_photo = ‘0’ "  
> sth = dbh.prepare(sql)  
> sth.execute()  
> row = sth.fetch  
> return row[2]  
> end

Hi

Did You get any result? I have the same problem and don’t know how to  
do.

Kind Regards.

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [February 20, 2008, 9:11am UTC](https://www.ruby-forum.com/t/mssql-image-field-ado-returns-an-array/128140/3 "2008-02-20T09:11:56Z")

</div>

Simon Vetterli wrote:

> Hi
> 
> Did You get any result? I have the same problem and don’t know how to  
> do.
> 
> Kind Regards.

Hello,

No, sadly enough i still have the problem and no time to digg deeper in  
rails to try and fix this. Maybe some rails guru can help us out.

---

<div class="post-metadata">

**Author:** ![davox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/90ced4/32.png) [@davox](https://www.ruby-forum.com/u/davox)\
**Post date:** [February 20, 2008, 6:54pm UTC](https://www.ruby-forum.com/t/mssql-image-field-ado-returns-an-array/128140/4 "2008-02-20T18:54:23Z")

</div>

David De vits wrote:

> Simon Vetterli wrote:
> 
> > Hi
> > 
> > Did You get any result? I have the same problem and don’t know how to  
> > do.
> > 
> > Kind Regards.
> 
> Hello,
> 
> No, sadly enough i still have the problem and no time to digg deeper in  
> rails to try and fix this. Maybe some rails guru can help us out.

Hi

I try this week or in start of next how to do it. I made it with MySQL  
and noch I have to porting to MSSQL. I will contact You when it’s works.

Kind Regards.
