将Blob数据插入Sqlite3(GeoPackage)

时间:2019-01-11 17:20:14

标签: python python-3.x sqlite geo

我在将WKB或知名二进制文件写入sqlite数据库/ geopackage(它们是相同类型的数据库)时遇到问题。

这是用于生成折线数据集的create语句。

CREATE TABLE line 
(OBJECTID INTEGER primary key autoincrement not null, 
Shape MULTILINESTRING)

WKB如下:

bytearray(b'\x01\x05\x00\x00\x00\x02\x00\x00\x00\x01\x02\x00\x00\x00\x04\x00\x00\x00\x96C\x8b\x9a\xd0@`\xc18\xd6\xc5=\xd2\xc5RA\x93\xa9\x825\x02=`\xc1\xb0Y\xf5\xd1\xed\xa6RAZd;W\x913`\xc1 Zd\xfb\x1c\xc0RA\xaa\x82Q%p/`\xc18\xcd;\x92\x19\xaeRA\x01\x02\x00\x00\x00\x03\x00\x00\x00z\xc7)TzD`\xc1\xb8\x8d\x06\xb8S\x9fRA\xbb\xb8\x8d:{"`\xc1X\xec/\xb7\xbb\x9eRA\x00\x91~Eo"`\xc1\x00\xb3{F\xff]RA')

当我将二进制数据插入列中时,我没有收到错误,只是插入了NULL。


sql = """INSERT INTO line (Shape)
                 VALUES(?)"""
val = [binaryfromabove]
cur.execute(sql, val)

我也尝试过使用sqlite3.Binary()

sql = """INSERT INTO line (Shape)
                 VALUES(?)"""
val = [sqlite3.Binary(binaryfromabove)]
cur.execute(sql, val)

插入的行始终为NULL。

有什么想法吗?

0 个答案:

没有答案