Python: Retrieve Image from MSSQL
Posted
by KoRkOnY
on Stack Overflow
See other posts from Stack Overflow
or by KoRkOnY
Published on 2009-03-27T20:03:56Z
Indexed on
2010/03/22
8:51 UTC
Read the original article
Hit count: 383
Dear All, 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()
© Stack Overflow or respective owner