Hi, I think the firebird-support is better place to ask. I don't know
the blob handling internals, but my guess is, that the concatenating
is creating new blob pages for complete content. Hence your database
is bigger than expected (anyway the previous pages will be free and
used later for other data).

On Fri, Apr 3, 2009 at 17:49, Justin Sommercorn <jus...@paraben.com> wrote:
> 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
> Firebird-net-provider@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/firebird-net-provider
>



-- 
Jiri {x2} Cincura (CTO x2develop.com)
http://blog.vyvojar.cz/jirka/ | http://www.ID3renamer.com

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Firebird-net-provider mailing list
Firebird-net-provider@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to