I found the problem. before I had the insertion method as follows:
procedure Tform33.Insert_data_ART;
var i:integer;
sql:string;
ms:TStream;
blopfield:Tfield;
begin
ShowMessage(inttostr(num_regs_fb_ART));
ms:=TMemoryStream.Create;
for I := 1 to num_regs_fb_ART do
begin
try
Artigos_imgTable.Active:=false;
Artigos_imgTable.Close;
sql:= ('INSERT INTO Artigos_img (Codigo_arm,Referencia,Designacao1,'+
'preco1,imagem) ' +
'VALUES' +
' (''' + Codigo_arm[i] + ''', ' +
'''' +Referencia[i] + ''', ' +
'''' + Designacao1[i] + ''', ' +
'' + preco1[i] + ');' );
Artigos_imgTable.CommandText:=sql;
ms.Position:=0;
try
Artigos_imgTable.active:=true;
with Artigos_imgTable do
begin
Insert;
blopfield:=FieldByName('imagem');
ms:=CreateBlobStream(blopfield,bmWrite);
BinaryAsBITMap[I].SaveToStream(ms);
end;
except
on e:exception do
infotext(e.Message);
end;
try
Artigos_imgTable.CommandText:=sql;
Artigos_imgTable.ExecSQL(true);
except on E: Exception do
ShowMessage(e.message);
end;
finally
ms.Free;
end;
end;
infoText('Dados Atualizados...');
end;
So since it’s type BLOB as the first input data is a 0 or a 1 and as Sqlite shapes the field type to the input data type, the database assumed I was inserting a long int.
The correct way to insert a BLOB is as follows:
procedure Tform33.Insert_data_ART;
var i:integer;
sql:string;
ms:TStream;
LTransaction: TDBXTransaction;
LParams: TParams;
begin
for I := 1 to num_regs_fb_ART do
begin
sql:= ('INSERT INTO Artigos (Codigo_arm,Referencia,Designacao1,'+
'preco1,Imagem) ' +
'VALUES' +
' (''' + Codigo_arm[i] + ''', ' +
'''' +Referencia[i] + ''', ' +
'''' + Designacao1[i] + ''', ' +
'''' + preco1[i] + ''', ' +
':Imagem)' );
try
LTransaction:=Gia_1C.BeginTransaction;
LParams:=TParams.Create(nil);
ms:=TMemoryStream.Create;
BinaryAsBITMap[I].SaveToStream(ms);
try
LParams.CreateParam(ftBlob,'Imagem',ptinput);
LParams.ParamByName('Imagem').LoadFromStream(ms,ftblob);
Gia_1C.Execute(SQL,Lparams);
Gia_1C.CommitFreeAndNil(LTransaction);
finally
FreeAndNil(ms);
FreeAndNil(Lparams);
end;
except on E: Exception do
infoText(e.Message);
end;
end;
infoText('Dados Atualizados...');
end;
What version of your SQLITE ?
– Junior Moreira
I searched the installation files of Delphi but found nothing there. On the Internet I only find articles related to examples of SQLITE operations
– Bruno Ribeiro