尝试使用 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 的评论:我不太了解数据源和什么样的 blob。这是其中一种情况,其他团队的人说:“嘿,这是这个合作伙伴的一些数据,让我们看看里面有什么”
但是,当尝试将 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 错误是否会出现,无论如何......