Map SQLite3 (Synopse) SQLite3 Column in Delphi7 TListView

I would like to take the next module (DrivesData) and display the disk column in TListView. I have never worked with SQLite3's (Synopse) code, so I hope someone can push you in the right direction a bit.

Just add the DrivesData block to the uses clause, then run it and it will create a database file “drives.sqlite” with a list of drives “A” to “Z”.

unit DrivesData;

interface

uses
  SynCommons, SQLite3Commons;

type
  TDrives = class(TSQLRecord)
  private
    { Private declarations }
    FDrive: RawUTF8;
  protected
    { Protected declarations }
    FDrivesModel: TSQLModel;
    FDrivesDatabase: TSQLRest;
  public
    { Public declarations }
    constructor Create(); override;
    destructor Destroy(); override;
  published
    { Published declarations }
    property Drive: RawUTF8 read FDrive write FDrive;
  end;

var
  DriveRecord: TDrives;

implementation

uses
  SQLite3;

function CreateDrivesModel(): TSQLModel;
begin
  Result := TSQLModel.Create([TDrives]);
end;

{ TDrives }
constructor TDrives.Create();
var
  X: Char;
begin
  inherited Create();

  FDrivesModel := CreateDrivesModel();
  FDrivesDatabase := TSQLRestServerDB.Create(FDrivesModel, 'drives.sqlite');

  TSQLRestServerDB(FDrivesDatabase).DB.Execute(
    'CREATE TABLE IF NOT EXISTS drives ' +
    '(id INTEGER PRIMARY KEY, drive TEXT NOT NULL UNIQUE COLLATE NOCASE);');

  for X := 'A' to 'Z' do
  begin
    TSQLRestServerDB(FDrivesDatabase).DB.Execute(
      'INSERT OR IGNORE INTO drives (drive) VALUES ("' + X + ':")');
  end;
end;

destructor TDrives.Destroy();
begin
  if Assigned(FDrivesDatabase) then
    FDrivesDatabase.Free();

  if Assigned(FDrivesModel) then
    FDrivesModel.Free();

  inherited Destroy();
end;

initialization
  DriveRecord := TDrives.Create();

finalization
  if Assigned(DriveRecord) then
    DriveRecord.Free();

end.
+3
source share
1 answer

Nice try!

But I'm afraid that you are missing some elements of the frame:

  • , MVC: a TSQLRecord , MVC TSQLModel TSQLRest ;
  • ORM, SQL- (CREATE TABLE INSERT): , ( )!

, TSQLRestServerDB , TSQLRestClientDB ( TSQLRestServerDB), . , .

Char. UTF-8, AnsiChar StringToUtf8() ( , Unicode Delphi).

( SAD, , SynFile).

, VCL (, TListBox), TSQLTableJSON. SAD ( , ).

, StackOverflow , . http://synopse.info, . .

!

+3

All Articles