如何在FIrebird fdb python库中设置set_stream_blob_threshold?

问题描述

尝试使用fdb(2.0.1)和pyodbc将数据从Firebird DB迁移到MS sql Server。由于Firebird数据库中存在超过64K的Blob,因此会将它们作为BlobReader对象返回。因为我不想自己处理这些字节,而是使用pyodbc编写它们。文档说您可以通过将-1传递给cursor.set_stream_blob_threshold来关闭64K阈值。但是,这似乎不起作用,因为抛出了fdb.fbcore.ProgrammingError ...

https://fdb.readthedocs.io/en/v2.0/reference.html#fdb.Cursor.set_stream_blob_treshold

这是我调用函数的方式:

import fdb

class Firebird:

    def __init__(self,db_name: str):
        self.__fb_conn = fdb.connect(database=db_name,user='someuser',password='somepass',charset='ISO8859_1')
        self.__fb_cursor = self.__fb_conn.cursor()

        #change the blob safety threshold to unlimited for troubleshooting
        self.__fb_cursor.set_stream_blob_treshold(-1) #doesn't work :(

以下是错误的堆栈跟踪:

(.venv) >python3.8.exe -i
Python 3.8.5 (tags/v3.8.5:580fbb0,Jul 20 2020,15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help","copyright","credits" or "license" for more information.
>>> from commonlibs import Firebird
>>>
>>> fb = Firebird('somedb.fdb')
Traceback (most recent call last):
  File "<stdin>",line 1,in <module>
  File "C:\Users\user1\dev\commonlibs\Firebird.py",line 13,in __init__
    self.__fb_cursor.set_stream_blob_treshold(int(-1)) #doesn't work :(
  File "C:\Users\user1\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\python38\site-packages\fdb\fbcore.py",line 3930,in set_stream_blob_treshold
    raise ProgrammingError
fdb.fbcore.ProgrammingError

Per Mark的评论: 我对数据源和什么样的斑点不太了解。在这种情况下,其他团队的人说:“嘿,这是来自该合作伙伴的一些数据,让我们看看里面是什么”

但是,当尝试将obj.read()值传递给BlobReader对象的pyodbc时,确实插入了一些Blob。但是,对于许多pyodbc,它们将报告此错误

 pyodbc.Error: ('HY000','[HY000] [Microsoft][ODBC sql Server Driver]Warning: Partial insert/update. The insert/update of a text or image column(s) did not succeed. (0) (sqlPutData); [HY000] [Microsoft][ODBC sql Server Driver][sql Server]The text,ntext,or image pointer value conflicts with the column name specified. (7125)')

我很希望我可以通过设置该阈值来避免所有这些pyodbc和.read()东西,但是我不知道pyodbc错误是否会出现……

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)