Recent

Author Topic: Tutorial updated for PostgreSQL  (Read 5642 times)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Tutorial updated for PostgreSQL
« on: September 14, 2012, 05:19:57 pm »
Hi all,

I just updated the
http://wiki.lazarus.freepascal.org/SQLdb_Tutorial1
for PostgreSQL.

As always, reports on errors/omissions and possible improvements are more than welcome.

Thanks a lot,
BigChimp
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Tutorial updated for PostgreSQL
« Reply #1 on: September 15, 2012, 07:39:30 am »
nice tutorial!

where you say you haven't found a way to delete via a key stroke

can you not have a key up event (might have to have a key up even for multiple components calling the same function - not sure if there is a global key up)

procedure Tmyform.doDeleteKeyCheck(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if (key=KEYVAL) then
     query1.CancelUpdates;
     query1.delete;
     query1.applyUpdates;
  end;
end;

or am I missing the point!
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Tutorial updated for PostgreSQL
« Reply #2 on: September 15, 2012, 09:31:57 am »
No, that looks good. Never knew about the .Delete functionality. Too much SQL indoctrination too even consider it existed ;)

Now I'm searching like crazy where the delete key is defined. I vaguely remember I have to include some unit with keyboard codes but which one???!
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Tutorial updated for PostgreSQL
« Reply #3 on: September 15, 2012, 10:01:13 am »
sorry you will have to define the delete sql property with something like

delete from acme where acmeid=:acmeid

it looks like you don't actually need to define the queries parameter for the key as I assume it just uses the first one in the sql it comes to....
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Tutorial updated for PostgreSQL
« Reply #4 on: September 15, 2012, 10:08:15 am »
Actually it seems to work fine as is (the query is simple enough so SQLDB can figure out the DELETESQL property contents).
I actually meant the VK_DELETE keycode - have opened another topic on it:
lazarus.freepascal.org/index.php/topic,18221
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Tutorial updated for PostgreSQL
« Reply #5 on: September 15, 2012, 01:05:34 pm »
actually nix the cancelUpdates not only is it not needed it looks like it can stop delete from working, which is odd cause I'm sure it worked last night....
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Tutorial updated for PostgreSQL
« Reply #6 on: September 15, 2012, 07:33:21 pm »
procedure Tmyform.doDeleteKeyCheck(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  if (key=KEYVAL) then
     query1.CancelUpdates;
     query1.delete;
     query1.applyUpdates;
  end;
end;

Unfortunately, for the delete key (VK_DELETE) that must be tweaked because it currently deletes the record if you're editing a field and e.g. trying to delete a letter by pressing the delete key.
Did this:
Code: [Select]
procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState
  );
begin
  // Check for del key being hit and delete the current record in response
  // as long as we're not editing data
  if (key=VK_DELETE) and (not(DBGrid1.EditorMode)) then
  begin
    //... delete current record and apply updates to db:
    SQLQuery1.Delete;
    SQLQuery1.ApplyUpdates;
  end;
end;

Suggestions for improvement welcome.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

codifies

  • Jr. Member
  • **
  • Posts: 98
    • bedroomcoders
Re: Tutorial updated for PostgreSQL
« Reply #7 on: September 15, 2012, 07:51:23 pm »
LOL or is that DOH

I think its acceptable to inhibit the delete key removal of a record while the focus is in an edit box...

personally I'd use alt+d via a button keyboard shortcut - accelerators I think they used to be called...
Lazarus 2.3.0 r3945f73 FPC 3.2.0 x86_64-linux-gtk2

 

TinyPortal © 2005-2018