KoRkOnY
KoRkOnY

Reputation:

Python: Retrieve Image from MSSQL

I'm working on a Python project that retrieves an image from MSSQL. My code is able to retrieve the images successfully but with a fixed size of 63KB. if the image is greater than that size, it just brings the first 63KB from the image!

The following is my code:

#!/usr/bin/python
import _mssql

mssql=_mssql.connect('<ServerIP>','<UserID>','<Password>')
mssql.select_db('<Database>')

x=1
while x==1:
    query="select TOP 1 * from table;"
    if mssql.query(query):
        rows=mssql.fetch_array()
        rowNumbers = rows[0][1]
        #print "Number of rows fetched: " + str(rowNumbers)
        for row in rows:
        for i in range(rowNumbers):
            FILE=open('/home/images/' + str(row[2][i][1]) + '-' + str(row[2][i][2]).strip() + ' (' + str(row[2][i][0]) + ').jpg','wb')
            FILE.write(row[2][i][4])
            FILE.close()
            print 'Successfully downloaded image: ' + str(row[2][i][0]) + '\t' + str(row[2][i][2]).strip() + '\t' + str(row[2][i][1])
    else:
        print mssql.errmsg()
        print mssql.stdmsg()
mssql.close()

Upvotes: 2

Views: 2778

Answers (2)

william
william

Reputation: 61

If your using freetds (I think you are): Search in your freetds.conf for the 'text size' setting.. standard its at 63 kb

Upvotes: 0

Trey Stout
Trey Stout

Reputation: 6911

It's kind of hard to tell what the problem is when you're using a database like this. Your query isn't explicitly selecting any columns, so we have no idea what your table structure is, or what types the columns are. I suspect the table format is not what you're expecting, or the columntype is incorrect for your data.

Also your code doesn't even look like it would run. You have "for row in rows:" and then don't indent after that. Maybe post your schema?

Upvotes: 1

Related Questions