I need to add large amounts of data to a BLOB, larger than I can store in
memory at one time. The code I am using does do this; however, it causes
the database to grow sometimes more than 10x the size of the data I'm
adding. I am sure I am doing this wrong and would appreciate any help
people can offer. Here is the code I am using.
internal static void AddFile(string file)
{
FileInfo f = new FileInfo(file);
FbTransaction transaction =
aquireDb.BeginTransaction(FbTransactionOptions.NoAutoUndo);
FbCommand cmd = new FbCommand();
cmd.Connection = aquireDb;
cmd.Transaction = transaction;
cmd.CommandText = "INSERT INTO FILES
(PATH,MD5,LASTACCESSED,LASTMODIFIED,CREATED,MATCHEDHASH) VALUES ('" +
f.FullName + "','md5','" + f.LastAccessTime + "','" + f.LastWriteTime +
"','" + f.CreationTime + "',1)";
cmd.ExecuteNonQuery();
cmd.CommandText = "SELECT GEN_ID(FILES_ID,0) FROM RDB$DATABASE";
long id = (long)cmd.ExecuteScalar();
using (FileStream fs = new FileStream(f.FullName, FileMode.Open,
FileAccess.Read))
{
BinaryReader br = new BinaryReader(fs);
byte[] data = br.ReadBytes(10240);
cmd.CommandText = "UPDATE FILES SET DATA = @data WHERE ID = @id";
cmd.Parameters.Add(new FbParameter("@id", 1));
cmd.Parameters.Add(new FbParameter("@data", data));
cmd.ExecuteNonQuery();
cmd.CommandText = "UPDATE FILES SET DATA = DATA||@data WHERE ID = @id";
while ((data = br.ReadBytes(data.Length)).Length > 0)
{
cmd.Parameters["@data"] = new FbParameter("@data", data);
cmd.ExecuteNonQuery();
}
transaction.Commit();
}
As you can see I am trying to append the data to itself. I couldn't find or
think of any other way to do this. I did find that if I add the data to a
BLOB without assigning it to a record the file size of the database grows by
the amount of data I'm adding. I do not know how to assign a BLOB value to
a certain record after the BLOB is already created though. Any help is
appreciated, thank you in advance.
------------------------------------------------------------------------------
_______________________________________________
Firebird-net-provider mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider