Topic: DBImage load from script and save from script

Hello friends,


I have the following script, i want to load some values and an image, in my following test script the value is loaded but the image does not show up. According to sqlitestudio there is a blob value in the image field of the table (logo and logo filename have values). Does anyone see why the image is not loaded?


procedure frmMain_Button1_OnClick (Sender: TObject; var Cancel: boolean);
begin
       frmMain.Edit1.Text := SQLExecute('SELECT name FROM table where id = 1');
       frmMain.DBImage1.LoadFromDatabase('table', 'logo', 1);
end;

Also, i am trying to update these values by script, in my following test script the text values are saved just fine, but the dbimage file does not update:


procedure frmMain_Button12_OnClick (Sender: TObject; var Cancel: boolean);
begin
       SQLExecute('UPDATE table SET name="'+frmMain.Edit1.Text+'",logo = "frmMain.DBImage1.Picture" WHERE id= 1');
end;

Thanks in advance

Re: DBImage load from script and save from script

.

Post's attachments

Attachment icon test2.7z 12.58 kb, 353 downloads since 2019-07-31 

Re: DBImage load from script and save from script

Thank you sibprogsistem! It works now.


Do you know the syntax to save DBImage by script? When i use this:


procedure frmMain_Button12_OnClick (Sender: TObject; var Cancel: boolean);
begin
       SQLExecute('UPDATE table SET name="'+frmMain.Edit1.Text+'",logo = "frmMain.DBImage1.Picture" WHERE id= 1');
end;

the value entered in SQLite is just "frmMain.DBImage1.Picture" which is wrong.

4 (edited by sibprogsistem 2019-07-31 10:29:27)

Re: DBImage load from script and save from script

procedure Form1_Button5_OnClick (Sender: string; var Cancel: boolean);
var
    sSQL: string;
    sFileName: string;
    sFieldName: string;

    Params: TParams;
    MemoryStream: TMemoryStream;
    Param: TParam;
begin
    sFileName := 'd:\db 1.jpg';
    sFieldName := 'somefile';

    sSQL := 'UPDATE test SET ' +sFieldName+'= :'+sFieldName+', '+sFieldName+'_filename="'+ExtractFileName(sFileName)+'" WHERE id=1';
    Params := TParams.Create(nil);


    // BLOB
    MemoryStream := TMemoryStream.Create;
    MemoryStream.LoadFromFile(sFileName); // load file to memory
    MemoryStream.Position := 0;
    Params.CreateParam(ftBlob, sFieldName, ptInput).LoadFromStream(MemoryStream, 15);  // 15 ftBlob (TBlobType)

    Form1.SQLConnection.Execute(sSQL, Params);

    MemoryStream.Free;
    Params.Free;
    Form1.TableGrid1.dbUpdate;
end;

Re: DBImage load from script and save from script

Thank you sibprogsistem! Made a few changes and it works perfectly!

Re: DBImage load from script and save from script

How to call user base image on next form.

 cbLoginS:= frmLogin.cbLogin.Text;
     MainPanel.label_user.Caption := 'Hello!  ' + cbLoginS;
     RegistrationPanel.label_userr.Caption := 'User:  ' + cbLoginS;

This is work for user name on the next form.
for picture I use the following script, but not working.

frmLogin.DBImage1.clear;
  frmLogin.DBImage1.loadfromdatabase('Users','userimage',frmLogin.cbLogin.dbitemid);
Post's attachments

Attachment icon Untitled.png 5.09 kb, 149 downloads since 2019-08-04 

JUST LEARNING, O GOD HELP ME.

Re: DBImage load from script and save from script

It should work, please attach your project.

Dmitry.

Re: DBImage load from script and save from script

Yes, Absolutely it's working, I have missed my table name.

JUST LEARNING, O GOD HELP ME.