我想将任意整数的向量写入 sqlite3 db。这是我所做的一个示例:
packed = struct.pack("ii", [7739119, 962812])
print packed # prints '\xef\x16v\x00\xfc\xb0\x0e\x00'
c.execute("INSERT INTO vecs(content) VALUES(?)", [packed])
在这里, sqlite3 抱怨:
sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that
can interpret 8-bit bytestrings (like text_factory = str).
It is highly recommended that you instead just switch your application to Unicode strings.
该vecs
列是一个BLOB
. 为什么抱怨?我知道我的打包字符串不是有效的 utf-8 字符串,但我不在乎,我想存储原始字节。我该怎么做 ?