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 http://web.firebirdsql.org/dotnetfirebird/blob-sub_type-1-reading-example-csharp.html)
但我发现 C# 驱动程序和 FlameRobin 都不能写入这个值。你得到“命令意外结束”(指向字符串中大约 32K 的位置,这有点可疑)
我认为有一种特殊的方法来引用或转义数据值,或者可能是此 Java 代码 (http://www.firebirdfaq.org/faq372/) 的 C# 等效方法,其中二进制文件直接读入语句中。我没有对文本数据做任何花哨的事情,所以如果需要的话我愿意将其存储为二进制 blob。
Thanks!
更新:“参数化查询”是我正在寻找的短语。我在做什么:
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();
}
}