Hi!
I'm beginner in SQL.
See this sample:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Sqlite3DS, db, FileUtil, Forms, Controls, Graphics, Dialogs, DBGrids, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Insert_Button: TButton;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Sqlite3Dataset1: TSqlite3Dataset;
procedure Insert_ButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Inherited;
with Sqlite3Dataset1 do
begin
if not(TableExists) then
begin
FieldDefs.Clear;
FieldDefs.Add('id', ftAutoInc);
FieldDefs.Add('text', ftString);
CreateTable;
end;
Open;
end;
end;
procedure TForm1.Insert_ButtonClick(Sender: TObject);
begin
with Sqlite3Dataset1 do
if TableExists then
begin
Open;
Insert;
FieldByName('text').AsString := 'test';
Post;
ApplyUpdates;
end;
end;
end.
If I use the INSERT button, then new record inserted to the correct position, I see this in the DBGrid1.
But if I reopen this database, inserted field positions are last, these field are in the last position.
For me now very need the correct order, how can I get records in the inserted order? What is the simplest way?
I don't know why "insert" this method, if the result is "append"...
Thanks!