是否可以将大字符串写入Firebird Blob? [英] Is it possible to write large strings to Firebird blob?
问题描述
Firebird的文档暗示您可以将大(> 60K)字符串写入表中的Blob值.所以,如果你有这个:
The documentation for Firebird implies that you can write large (> 60K) strings to a blob value in a table. So if you have this:
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都不能写入该值.您会得到意外的命令结尾"(指向字符串中约32K的位置,这有点可疑)
But I've found that neither C# drivers nor FlameRobin can write this value. You get 'Unexpected end of command' (pointing to a spot about 32K into the string, which is a little suspicious)
我认为有一种特殊的方法可以引用或转义数据值,或者是C#等效于此Java代码(http://www.firebirdfaq.org/faq372/),其中直接将二进制文件读取到陈述.我对文本数据没有任何幻想,因此可以根据需要将其存储为二进制blob.
I figure there is a special way to quote or escape the data values, or maybe a C# equivalent of this Java code (http://www.firebirdfaq.org/faq372/) where a binary file is read directly into the statement. I'm not doing anything fancy with the text data so I'm open to storing it as a binary blob if needed.
谢谢!
更新:参数化查询"是我一直在寻找的短语.我在做什么:
Update: "parameterized queries" is the phrase that I was looking for. What I'm doing:
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();
}
}
推荐答案
您正在查询中直接添加文本.然后有限制:Firebird中的第一个查询文本限制为64 kB,varchar大小也有限制.
You are adding text inline in the query. Then there are limits: first query text in Firebird is limited to 64 kB, there is also a limit to the varchar size.
如果要将更多数据添加到Blob,则需要使用参数化查询将其流式传输到Blob.参见示例: http://www.firebirdsql.org/en/net-examples-of-use/#update_text_blob_field
If you want to add more data to a blob, you need to stream it to the blob using parametrized queries. See for an example: http://www.firebirdsql.org/en/net-examples-of-use/#update_text_blob_field
这篇关于是否可以将大字符串写入Firebird Blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!