Recent

Author Topic: Problem using bookmarks  (Read 2287 times)

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Problem using bookmarks
« on: September 20, 2017, 09:20:07 pm »
Hi,

I'm struggling a little over using TSQLQuery and I'm hoping someone can point me in the right direction.
I've got SQLQuery fully working through Obective Inspector and I can do all the normal activities with it using the Navigation bar.
However I want to add a picture to the main table pointed to by SQLQuery.
I'm suing the following code:
Code: Pascal  [Select][+][-]
  1.   pFilename:='D:/test.jpg';
  2.   form1.SQLQuery7.SQL.Text := 'update maindata set org_logo = :org_logo where id = :ID';
  3.   form1.SQLQuery7.Params.ParamByName('id').Value:=form1.SQLQuery1.FieldValues['ID'];
  4.   form1.SQLQuery7.Params.ParamByName('org_logo').LoadFromFile(pFileName,ftBlob);
  5.   form1.SQLQuery7.ExecSQL;

Which works fine on the press of a button. However, it doesn't show on the form's DBImage linked to the org_logo that is updated above.
So I use....
Code: Pascal  [Select][+][-]
  1.   form1.SQLTransaction1.CommitRetaining;
  2.   form1.SQLQuery1.Refresh;

....to refresh the maindata form and it does show the picture.

However, when I do this the main record set (SQLQuery) goes back to the first record (as would be expected) and I want it to stay on the record I've added the picture to.

I have tried many things, but I thought I'd just save my stress levels and ask how it would be best done.
I tried using TBookMark to save where I was before and then restore after as in:
Code: Pascal  [Select][+][-]
  1.   bmCurrentRecord:=Form1.SQLQuery1.GetBookmark ;
  2.   form1.SQLTransaction1.CommitRetaining;
  3.   form1.SQLQuery1.Refresh;
  4.   form1.SQLQuery1.GotoBookmark (bmCurrentRecord);

But this works the first time on the first record, but crashes with an exception at any other time.

I also tried looking for a .GotoReocrd, or a .Find=??? or something that I could use to go to a particular record, but can see anything unless I'm completely missing it. Alternatively, a method for saving the picture in the table and then showing it on the current form view.

Any help would be really appreciated.

Many thanks in advance
Dave
 
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Problem using bookmarks
« Reply #1 on: September 20, 2017, 10:01:10 pm »
Hi,

Ok, I've found .Locate which does the job, but it would be good to understand why the .Bookmark approach didn't work, i.e. what might case the exception to be raised.

Thanks
Dave
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Problem using bookmarks
« Reply #2 on: September 20, 2017, 10:08:47 pm »
To put it the simplest way I can, a bookmark is a pointer to the record's data in memory. By calling refresh you deallocate the current memory and re query the results from the server. Any bookmark that you had saved before the refresh call is now invalid and needs to be discarded.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

daveinhull

  • Sr. Member
  • ****
  • Posts: 297
  • 1 divided by nothing must still be 1!
Re: Problem using bookmarks
« Reply #3 on: September 20, 2017, 10:19:31 pm »
Thanks taazz for taking the time to get back to me, and yes of course that makes complete sense and in the back of my mind I was felling that it was to do with the .refresh.
Version #:1.8.4 Date 2019-01-08 FPC Version: 3.0.4 and SVN Revision 57972 for x86_64-win64-win32/win64

 

TinyPortal © 2005-2018