USING DATA TYPE LONG RAW WITH SetLongVariable Function

memofer

Member
I AM TRYING TO INSERT A FILE .JPG OF 4KB ON A FIELD TYPE LONG RAW.
NOW I AM SEEING IN DELPHI 5 THE EXAMPLE ON HELP, THIS ARE USING THE FUNCTION SetLongVariable.
I CAN'T UNDERSTAND HOW TO USE THE BUFFER AND LENGTH PARAMETERS.
CAN YOU HELP, HOW CAN INSERT THAT FILE .JPG OF 4KB ON A FIELD TYPE LONG RAW?
PLEASE, THANK YOU.
 
If you use an insert statement with a long raw variable, you can indeed use the SetLongVariable function. You must have the JPG file in memory, and you must know the exact size. The Buffer parameter is a pinter to the memory location of the JPG file in memory. The Length parameter is the size in bytes of the JPG file in memory.
 
I am using that code by get a pointer whith a file .JPG :
var clave:integer;
Lei,Ajpg : Integer;
Result : boolean;
bf : Pointer;
begin
Ajpg := FileOpen('c:\memo.jpg',fmOpenRead);
if Ajpg > 0 then
begin
getmem(bf,7000);
Lei := FileRead(Ajpg,bf^,7000);
fileclose(Ajpg);
try
with OInsertQuery do
begin
SetVariable('id',clave_foto);
SetLongVariable('img',bf,Lei);
Execute;
W_DM.OracleSession1.Commit;
FreeMem(bf,Lei);
clave := GetVariable('id');
Result := True;
StrFile.Free;
end;
This is the Query of OInsertQuery:
begin
SELECT seq_imagen.nextval INTO :id FROM dual;
INSERT INTO Imagen (Clave,Grafico) VALUES (:id,rawtohex(:Img));
end;

Now, when I use that OInsertQuery, that just insert half of the image on DataBase.
Or if I put a file .JPG of more 4KB that send me a message like this:
ORA-01461: can bind a LONG value only for insert into a LONG column.

Please, help me, as I can correct this?
how can Insert full image .jpg of 4kb?
please.
 
You should omit the rawtohex function, and should also omit the PL/SQL Block (otherwise the :img variable is a PL/SQL variable, and therefore limited to 32KB):
Code:
INSERT INTO Imagen
 (Clave, Grafico)
VALUES
 (seq_imagen.nextval, :Img)
RETURNING
  Clave into :id
I assume that "Grafico" is a Long Raw column, and that :Img is a Long Raw variable, so no conversion is needed.
 
MARCO KALTER
THANK YOU.

I READ YOUR COMMENTS, AND I THINK THAT YOU ARE A GREAT PERSON.

I AM FROM MEXICO.

THANK YOU SO MUCH
I WILL NOT GET TIRED TO BE THANKFUL
 
Back
Top