[英]syntax to UPDATE a BLOB field in an existing SQLite record?
What is the syntax to UPDATE
a BLOB
field in an existing SQLite
record, using Python? 使用Python
UPDATE
现有SQLite
记录中的BLOB
字段的语法是什么? I create a 13x13 array of floats and want to Update a specific record (ie using a WHERE
clause) in my table with that array. 我创建了一个13x13的浮点数组,并希望使用该数组更新表中的特定记录(即使用
WHERE
子句)。
What is the proper UPDATE
syntax? 正确的
UPDATE
语法是什么?
The array has the following form: 数组具有以下形式:
[ 4.65640926e+00 5.59250259e+00 5.28963852e+00 1.60680866e+00
-3.39492680e-01 -4.76834650e-01 -4.76834650e-01 -2.29132240e-01
1.49733067e+00 1.51563072e+00 1.49733067e+00 9.53471420e-01
-1.40306473e+00]
[ 5.28963852e+00 5.34537315e+00 5.05013466e+00 1.48362923e+00
-3.69843300e-01 -4.76834650e-01 -4.76834650e-01 -2.29132240e-01
7.60705290e-01 1.49733067e+00 9.53471420e-01 3.05504260e-01
-1.40306473e+00]
Totaling 13 rows of 13 sub-arrays. 共有13个子阵列的13行。
Thank you, Bill 谢谢你,比尔
The syntax for the SQL is :- SQL的语法是:
UPDATE mytable SET myblobcolumn = x'ffeedd' WHERE your_where_clause;
Where 哪里
Obviously the above are only representations, you would have to substitute appropriate values 显然,以上只是表示形式,您必须替换适当的值
A friend pointed me to this solution, which works nicely. 一位朋友向我指出了这种解决方案,效果很好。 The original answer was from StackOverflow, to give proper credit.
最初的答案来自StackOverflow,以给予适当的感谢。
def adapt_array(arr): """ Reformat a numpy array so as to be writeable to SQLite BLOB fields Input: Numpy Array Returns: formatted Binary BLOB compatable Code Source: Python insert numpy array into sqlite3 database """ out = io.BytesIO() np.save(out, arr) out.seek(0) return sqlite3.Binary(out.read()) def Adapt_array(arr):“”“重新格式化numpy数组以便可写入SQLite BLOB字段输入:Numpy Array返回:格式与二进制BLOB兼容的代码源: Python将numpy数组插入sqlite3数据库 ”“” out = io.BytesIO ()np.save(out,arr)out.seek(0)返回sqlite3.Binary(out.read())
def convert_array(text): """ Reformat a SQLite BLOB field into the originating Numpy array Input: Numpy BLOB from SQLite Returns: numpy array Code Source: Python insert numpy array into sqlite3 database """ out = io.BytesIO(text) out.seek(0) return np.load(out) def convert_array(text):“”“将SQLite BLOB字段重新格式化为原始的Numpy数组输入:来自SQLite的Numpy BLOB返回:numpy array代码源: Python将numpy数组插入sqlite3数据库 ”“” out = io.BytesIO(text) out.seek(0)返回np.load(out)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.