Recent

Author Topic: SQLite3 Relational bases  (Read 13746 times)

Sieben

  • Sr. Member
  • ****
  • Posts: 299
Re: SQLite3 Relational bases
« Reply #15 on: December 21, 2021, 06:22:51 pm »
At line #9 you're trying to refresh a query that doesn't have a result set, thus the error (remember Open vs ExecSQL?). I guess you want to refresh the query that actually holds your result set from the table in question.
« Last Edit: December 21, 2021, 06:52:13 pm by Sieben »
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

Pe3s

  • Full Member
  • ***
  • Posts: 145
Re: SQLite3 Relational bases
« Reply #16 on: December 21, 2021, 06:30:25 pm »
here is the code
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button3Click(Sender: TObject);
  2.     begin
  3.       if MessageDlg('Pytanie', 'Czy usunac', mtWarning, mbYesNo, 0) = mrYes then
  4.       begin
  5.         SQLQuery1.SQL.Text := 'DELETE FROM base WHERE id=:id';
  6.         SQLQuery1.ParamByName('id').AsString := Form1.Caption;
  7.         SQLQuery1.ExecSQL;
  8.         SQLTransaction1.Commit;
  9.         SQLQuery1.Refresh;
  10.       end;
  11.     end;  
  12.  

af0815

  • Hero Member
  • *****
  • Posts: 937
Re: SQLite3 Relational bases
« Reply #17 on: December 21, 2021, 08:30:44 pm »
After a ExecSQL nothing is open, so a Refresh here is complete false. On the other hand, there is nothing to Refresh after a Delete statement.

You can use Refresh if you use the correct Sql, Update, delete and insert SQL of a query. After Open the query, it is handling the insert, update, delete and select statement by itself. This is one point if you can use Refresh.
regards
Andreas

JanRoza

  • Hero Member
  • *****
  • Posts: 640
    • http://www.silentwings.nl
Re: SQLite3 Relational bases
« Reply #18 on: December 21, 2021, 09:58:45 pm »
After the Commit first make sure that SQLQuery1.SQL.Text contains your select statement again and only then do the refresh.
Now you are refreshing a Delete statement, which is not what you want.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Laz: Lazarus 2.2.2 FPC 3.2.2
       CodeTyphon 7.8 FPC 3.3.1

Pe3s

  • Full Member
  • ***
  • Posts: 145
Re: SQLite3 Relational bases
« Reply #19 on: December 28, 2021, 11:15:16 am »
I made the record updates
Code: Pascal  [Select][+][-]
  1. SQLQuery1.SQL.Text := 'UPDATE ......';
  2.  SQLQuery1.ExecSQL;
  3.   SQLTransaction1.Commit;
  4.  
If I call the SELECT command, the record focus is reset, how to correct the record so that the record remains selected after the update

JanRoza

  • Hero Member
  • *****
  • Posts: 640
    • http://www.silentwings.nl
Re: SQLite3 Relational bases
« Reply #20 on: December 28, 2021, 02:27:09 pm »
Focus is reset because you use SQLTransaction1.Commit which closes the database, try SQLTransaction1.CommitRetaining.
The database will then not be closed after committing the changes and you can continue working.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Laz: Lazarus 2.2.2 FPC 3.2.2
       CodeTyphon 7.8 FPC 3.3.1

Pe3s

  • Full Member
  • ***
  • Posts: 145
Re: SQLite3 Relational bases
« Reply #21 on: December 28, 2021, 05:09:12 pm »
After using ComitRetaining
does not refresh the view in the table

JanRoza

  • Hero Member
  • *****
  • Posts: 640
    • http://www.silentwings.nl
Re: SQLite3 Relational bases
« Reply #22 on: December 28, 2021, 07:32:35 pm »
How do you view the table?
If you use database dependant elements like DbGrid, DbListbox, etc. than the table view refreshes as soon as you update data in the table.
Not knowing what you are doing makes it hard to give a good answer.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Laz: Lazarus 2.2.2 FPC 3.2.2
       CodeTyphon 7.8 FPC 3.3.1

Pe3s

  • Full Member
  • ***
  • Posts: 145
Re: SQLite3 Relational bases
« Reply #23 on: December 29, 2021, 09:32:59 am »
Code: Pascal  [Select][+][-]
  1.  SQLQuery1.SQL.Text := 'UPDATE database SET Name=:Name, Product=:Product,  WHERE id=:id';
  2.   SQLQuery1.ParamByName('Name').AsString := LabeledEdit1.Text;
  3.   SQLQuery1.ParamByName('Product').AsString := LabeledEdit2.Text;
  4.   SQLQuery1.ParamByName('id').AsInteger := SQLQuery1.FieldByName('id').AsInteger;
  5.   SQLQuery1.ExecSQL;
  6.   SQLTransaction1.CommitRetaining;
  7.  SQLQuery1.SQL.Text := 'SELECT * FROM database';
  8.   SQLQuery1.Open;
  9.  

The changes appear after restarting the program

 

TinyPortal © 2005-2018