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
)
Then this should work:
insert into MyBlobTable (theId, theBlob) values (1, '[60K characters in a string]')
(example inspired by http://web.firebirdsql.org/dotnetfirebird/blob-sub_type-1-reading-example-csharp.html)
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)
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.
Thanks!
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();
}
}
You are adding text inline in the query. Then there are limits: first query text in Firebird 2.5 and earlier is limited to 64 KB, in Firebird 3.0 this was increased to 10 MB, but some tools may still use the API in a way that limits it to 64KB. There is also a limit to the string literal size: 32KB, or since Firebird 3.0 64KB if it is a literal for a blob value.
If you want to add more data to a blob, you need to stream it to the blob using parametrized queries. See this example: