Forums


Aducom Software :: Forums :: Delphi SQLite Version 3.0.x Components :: Bugs/Enhancement requests
 
<< Voorgaande discussie | Volgende discussie >>
InsertRecord or AppendRecord
Moderators: aducom, aducomadmin2
Auteur Bericht
cyrn
wo nov 17 2004, 10:09
Geregistreerde deelnemer #134
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?

Thanks,

Nic
Terug omhoog
aducom
wo nov 17 2004, 10:21

Geregistreerde deelnemer #1
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:

ASQLite3Table1.BeginTransaction;
ASQLite3Table1.AppendRecord();
ASQLite3Table1.Commit;

But I'm not sure. Will come back to you.
Albert

albert
Terug omhoog
cyrn
wo nov 17 2004, 10:25
Geregistreerde deelnemer #134
Geregistreerd: wo nov 17 2004, 09:54
berichten: 14
You meant a .StartTransaction (not a .BeginTransaction)?
I tried, it doesn't work.

Will wait for your answer,

Thanks,
Nic
Terug omhoog
aducom
do nov 18 2004, 09:24

Geregistreerde deelnemer #1
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...

albert

albert
Terug omhoog
aducom
do nov 18 2004, 09:50

Geregistreerde deelnemer #1
Geregistreerd: wo jan 25 2006, 04:34
Woonplaats: groningen (NL)
berichten: 1561
Will you apply next patch and report the test results?

procedure TASQLite3BaseQuery.InternalAddRecord(Buffer: Pointer; Append: boolean);
begin
DebugEnter('TASQLite3BaseQuery.InternalAddRecord');
FSaveChanges := true;
if Append then
InternalLast;
Post;
// FResult.Insert(FCurRec, pchar(Buffer), Connection.SQLite3_LastInsertRow(
// Connection.DBHandle));
DebugLeave('TASQLite3BaseQuery.InternalAddRecord');
end;


albert

albert
Terug omhoog
cyrn
do nov 18 2004, 10:32
Geregistreerde deelnemer #134
Geregistreerd: wo nov 17 2004, 09:54
berichten: 14
Hi,

This works, for InsertRecord and for AppendRecord, the records are saved in the DB.

The only problem is that when I execute

ASQLite3Table1.appendRecord();

the nil is supposed to autoincrement the id of the record, but it leaves the field empty, blank. It tried with a table created as follows:

create table text2 (id autoinc, text string);

and also with

create table texte2 (id, texte);


Do you have an idea?

Nic
Terug omhoog
aducom
do nov 18 2004, 03:00

Geregistreerde deelnemer #1
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)

albert

albert
Terug omhoog
 

Ga naar:     Terug omhoog

Publiceer deze discussie: RSS 0.92 Publiceer deze discussie: RSS 2.0 Publiceer deze discussie: RDF
Powered by e107 Forum System