Recent

Author Topic: SQLite3 [Newbie Question]  (Read 1871 times)

arwen

  • Full Member
  • ***
  • Posts: 104
    • http://www.flussiliberi.it/
SQLite3 [Newbie Question]
« on: May 11, 2020, 09:35:39 am »
Good morning everyone.
I am developing a small application on Lazarus 2.0.8 using sqlite and I need some information.

I am using these components:
TSQLite3Connection
TSQLQuery
TSQLTransaction
TDataSource
TDBGrid
TDBNavigator

1 - If in the Grid I create a new record but do not fill in at least one column the post is not successful and the system signals me "No insert query specified and failed to generate one. (No field found for insert or update-statement found) "
How to handle this situation?

2 - In a table with a UNIQUE integer field, if I try to insert a record with a duplicate field it is not inserted (correct reaction) but how do I manage the situation and reset the query or transaction without having to close the form?
In practice how do I handle the error cleanly?

Thanks in advance

LacaK

  • Hero Member
  • *****
  • Posts: 698
Re: SQLite3 [Newbie Question]
« Reply #1 on: May 11, 2020, 12:04:34 pm »
1: IMO in this case you must manually define InsertSQL property of TSQLQuery object
2: Try, look at OnUpdateError event handler of TSQLQuery object

More info you can found at https://wiki.freepascal.org/Working_With_TSQLQuery

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1272
Re: SQLite3 [Newbie Question]
« Reply #2 on: May 11, 2020, 12:40:49 pm »
hello,
Good morning everyone.
I am developing a small application on Lazarus 2.0.8 using sqlite and I need some information.

I am using these components:
TSQLite3Connection
TSQLQuery
TSQLTransaction
TDataSource
TDBGrid
TDBNavigator

coming with Lazarus > 1.8,  have a look to the example with all these components :   Lazarus/examples/database/image_mushrooms

Features:
- Use SqlDb and lazreport components.
- Sqlite3 or Firebird embedded database DeadlyMushrooms with 5 mushrooms.

Friendly, J.P
« Last Edit: May 11, 2020, 12:45:08 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

QEnnay

  • Full Member
  • ***
  • Posts: 129
Re: SQLite3 [Newbie Question]
« Reply #3 on: May 11, 2020, 05:21:40 pm »
I am developing a small application on Lazarus 2.0.8 using sqlite and I need some information.

It would help greatly if you would include the code you are using to insert the records.

You are telling us the color of your car and asking for help on why it doesn't start.

SQlit3 works fine, so it can only be the code you are using. I suggest you also spend some time with YT tutorials.
Linux-Mint 20.1 x64 + Cinnamon; Lenovo Flex 5 Ryzen 5 4500, 16GB memory
FPC: 3.2.0-1, Lazarus 2.0.12-0, all 64bit

arwen

  • Full Member
  • ***
  • Posts: 104
    • http://www.flussiliberi.it/
Re: SQLite3 [Newbie Question]
« Reply #4 on: May 11, 2020, 05:58:24 pm »
This is the code I'm working on

arwen

  • Full Member
  • ***
  • Posts: 104
    • http://www.flussiliberi.it/
Re: SQLite3 [Newbie Question]
« Reply #5 on: May 13, 2020, 12:26:27 pm »
 :D I should have solved it.

In InsertSQL added : INSERT OR ABORT INTO cod_a (cod_a,desc_cod_a) VALUES(:cod_a,:desc_cod_a);
Implemented OnPostError and OnUpdateError event  :

Code: Pascal  [Select][+][-]
  1. procedure TForm2.SQLQueryCodAPostError(DataSet: TDataSet; E: EDatabaseError;
  2.   var DataAction: TDataAction);
  3. begin
  4.   MessageDlg('Errore sul DataBase per POST',
  5.   E.Message+LineEnding+LineEnding+
  6.   'VERIFICARE E CORREGGERE I DATI INSERITI',mtError,[MbOK],0);
  7.  
  8. end;
  9.  
  10. procedure TForm2.SQLQueryCodAUpdateError(Sender: TObject;
  11.   DataSet: TCustomBufDataset; E: EUpdateError; UpdateKind: TUpdateKind;
  12.   var Response: TResolverResponse);
  13. begin
  14.   MessageDlg('Errore sul DataBase per UPDATE',
  15.   E.Message+LineEnding+LineEnding+
  16.   'VERIFICARE E CORREGGERE I DATI INSERITI',mtError,[MbOK],0);
  17. end;
  18.  

1: IMO in this case you must manually define InsertSQL property of TSQLQuery object
2: Try, look at OnUpdateError event handler of TSQLQuery object

More info you can found at https://wiki.freepascal.org/Working_With_TSQLQuery

 

TinyPortal © 2005-2018