Discussion:
Image Blob (SQL Server 2005; DBExpress) wrong datasize after Insert
(too old to reply)
Jens Froherz
2008-02-06 18:02:30 UTC
Permalink
Picture not completely saved in MS SQL Server 2005 database...

Table in MS- SQL Server 2005

CREATE TABLE BILDTBL
(
IDNR INTEGER NOT NULL,
BILD IMAGE,
CONSTRAINT PK_BILDTBL PRIMARY KEY (IDNR)
);

procedure speicherebild(datei: String)
var
QU: TSQLQuery;
pic: TPicture;
ms: TMemoryStream;
begin
pic.loadFromFile(datei);

ms := TMemorystream.create;
try

pic.Graphic.SaveToStream(ms);

QU.Close;
QU.SQL.clear;
QU.SQL.ADD('INSERT INTO BILDTBL(IDNR,BILD)VALUES(:id,:bd)');
QU.Params[0].DataType := ftinteger;
QU.quleer1.Params[0].asinteger := 1;
QU.Params[0].DataType := ftBlob;
QU.quleer1.Params[0].assign(pic.Graphic); //oder
QU.quleer1.Params[0].loadfromstream(MS,ftBlob);
//beide Zuweisungen funktionieren gleich

QU.Execsql;
QU.Close;

finally
ms.free;
end;
end;

The procedure works with no error, but the Image in the Database Blob Field
(Type Image) is cutted at beginning and at the end. The picture is not
reproduceable.
What is wrong....????
Dan Downs
2008-02-14 04:11:35 UTC
Permalink
A couple things from your example, all I'm seeing is Params[0] and no
Params[1]. Also there isn't a MS.Position := 0; to reset your memory
stream position.

I know streaming in and out through ADO, but not DBX, so I'm not used to
seeing QU.Params[0].DataType := ftInteger; type of assignments, but I
guess they would be needed if DBX doesn't use variants like ADO does.

Also what is the datalength() of the field after inserting?

DD
Jens Froherz
2008-02-16 14:19:41 UTC
Permalink
you are right, but the missing param[1] was a mistake by me, while writing
the example, the second param must have a number 1;
the code works with no error, but as result, if you look in the binary data
in the table, the data is not the same, like the data in picture file....
Post by Dan Downs
A couple things from your example, all I'm seeing is Params[0] and no
Params[1]. Also there isn't a MS.Position := 0; to reset your memory stream
position.
I know streaming in and out through ADO, but not DBX, so I'm not used to
seeing QU.Params[0].DataType := ftInteger; type of assignments, but I
guess they would be needed if DBX doesn't use variants like ADO does.
Also what is the datalength() of the field after inserting?
DD
Dan Downs
2008-02-16 16:54:57 UTC
Permalink
Post by Jens Froherz
you are right, but the missing param[1] was a mistake by me, while writing
the example, the second param must have a number 1;
the code works with no error, but as result, if you look in the binary data
in the table, the data is not the same, like the data in picture file....
k, but not right how? to short? to long? extra bytes like like it was
text converted to unicode or not enough like crlf converted to lf?


DD

Loading...