【问题标题】:Python: Retrieve Image from MSSQLPython:从 MSSQL 中检索图像
【发布时间】:2009-03-27 20:03:56
【问题描述】:

我正在开发一个从 MSSQL 检索图像的 Python 项目。我的代码能够成功检索图像,但大小固定为 63KB。如果图像大于该大小,它只会从图像中取出前 63KB!

以下是我的代码:

#!/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()

【问题讨论】:

  • 存储图片的列的数据类型是什么?

标签: python sql-server file-io


【解决方案1】:

当您使用这样的数据库时,很难说出问题所在。您的查询没有明确选择任何列,因此我们不知道您的表结构是什么,或者这些列是什么类型。我怀疑表格格式不是您所期望的,或者您的数据的列类型不正确。

此外,您的代码甚至看起来都不会运行。你有“for row in rows:”,然后不要缩进。也许发布您的架构?

【讨论】:

  • 您好,感谢 chmod700 的回答 .. 我正在使用“图像”数据类型字段,这就是我在下面的代码行中使用的字段:FILE.write(row[2 ][i][4]) 我怀疑我与 MS SQL 服务器的连接,所以我使用了 pyODBC,但我遇到了同样的问题。有什么想法吗?
【解决方案2】:

如果您使用的是 freetds(我认为您是):在您的 freetds.conf 中搜索“文本大小”设置。标准为 63 kb

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    • 2014-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多