Geregistreerd: wo nov 17 2004, 09:54 berichten: 14
Hi,
I have a problem inserting data into a table. My connection is active. When I execute ASQLite3Table1.AppendRecord(), the record is added in the DBGrid control, but when I close the program and open it again, the record is not saved. With .append, .fieldValues and .post, it works fine, and the DB component used is the same.
Here is the code I execute:
procedure TForm1.Button1Click(Sender: TObject); begin
// this seems to work, but is not saved in the db. ASQLite3Table1.AppendRecord();
{ // this works (is saved in the DB) ASQLite3Table1.append; ASQLite3Table1.FieldValues := Edit1.text; ASQLite3Table1.FieldValues := '30'; ASQLite3Table1.Post; } end;
Do I have to close the SQLite DB or anything to save the DB content?
Geregistreerd: wo jan 25 2006, 04:34 Woonplaats: groningen (NL) berichten: 1561
I have to check this out. The BDE documentation says
For indexed Paradox and dBASE tables, the record is inserted into the dataset in a position based on its index. For unindexed Paradox and dBASE tables, the record is added to the end of the dataset. For SQL databases, the physical location of the append is implementation-specific. For indexed tables, the index is updated with the new record information.
So I'll probabely have something to do. I never have used this function. You could try to put a transaction around it:
Geregistreerd: wo jan 25 2006, 04:34 Woonplaats: groningen (NL) berichten: 1561
Well eh...
The appendrecord works on the resultset of the query. This means that it shows in the grid, but there's never a database action around it. This will cause inpredictable errors. This makes sence, since you cannot append in a sql based database, nor insert between records. This function was solely meant for paradox and dbase like tables. I'm still investigating the bde to find a work-around or to prevent this function to be called. Fact is that using this function the database vcl (where the sqlite components are derived from) is not actually calling the update/insert statements where it should. I'm looking for an override...
Geregistreerd: wo jan 25 2006, 04:34 Woonplaats: groningen (NL) berichten: 1561
Yes, the field type should be integer primary key. See documentation of sqlite. If you use ttable component you need to set the autoinc property to enable this behaviour. Keep in mind too that data is saved the text way and datatypes are emulated in the delphi component. If you need a string type use the char varchar or text type. You always need to specify a datatype (ftstring is default)