【发布时间】:2021-10-06 23:10:51
【问题描述】:
Firebird 的文档暗示您可以将大 (> 60K) 字符串写入表中的 blob 值。所以如果你有这个:
CREATE TABLE MyBlobTable (
theId int PRIMARY KEY NOT NULL,
theBlob BLOB SUB_TYPE 1
)
那么这应该可以工作:
insert into MyBlobTable (theId, theBlob) values (1, '[60K characters in a string]')
(受http://web.firebirdsql.org/dotnetfirebird/blob-sub_type-1-reading-example-csharp.html启发的示例)
但我发现 C# 驱动程序和 FlameRobin 都不能写入这个值。你得到'Unexpected end of command'(指向字符串中大约 32K 的点,这有点可疑)
我认为有一种特殊的方法可以引用或转义数据值,或者可能是此 Java 代码 (http://www.firebirdfaq.org/faq372/) 的 C# 等效项,其中将二进制文件直接读入陈述。我没有对文本数据做任何花哨的事情,因此如果需要,我愿意将其存储为二进制 blob。
谢谢!
更新:“参数化查询”是我正在寻找的短语。我在做什么:
FbParameter param = new FbParameter("@blobVal", FbDbType.Text);
param.Value = myLargeString;
String query = "insert into MyBlobTable (theId, theBlob) values (1, @blobVal)";
using (FbConnection conn = [something from my pool]) {
using (FbCommand cmd = new FbCommand(query, conn)) {
cmd.Parameters.Add(param);
cmd.ExecuteNonQuery();
}
}
【问题讨论】:
-
你能提醒我们什么是 SUBTYPE 1 吗?无论如何,尝试使用参数。
-
BLOB SUB_TYPE 1 映射到 C# 中的字符串,而 BLOB 映射到字节数组。