Search code examples
delphisqliteunidac

Delphi: SQLite and UniDac


Need to store some data in SQLite. To work with SQLite chose UniDac, but there is a problem: when in the UniConnection, in the field "Database", I choose SQLite and enter the name of the database - get the error "Unsupported metadata kind". Database file is not created. What is the problem? As previously worked with UniDac, then such problems are not observed.


Solution

  • UniDAC 4.1.6 with Delphi XE2 I'm not seeing any issues. SQLite3.dll must be in the system path or the same directory as your executable. Very basic example below creates the data file when btnConnect is clicked.

    unit uMain;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.DBGrids, UniProvider,
      SQLiteUniProvider, Data.DB, MemDS, DBAccess, Uni, Vcl.ExtCtrls, Vcl.DBCtrls,
      Vcl.StdCtrls;
    
    type
      TfrmMain = class(TForm)
        UniDataSource1: TUniDataSource;
        UniConnection1: TUniConnection;
        UniQuery1: TUniQuery;
        SQLiteUniProvider1: TSQLiteUniProvider;
        DBGrid1: TDBGrid;
        edtDBName: TEdit;
        Label1: TLabel;
        DBNavigator1: TDBNavigator;
        btnConnect: TButton;
        procedure btnConnectClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      frmMain: TfrmMain;
    
    implementation
    
    {$R *.dfm}
    
    procedure TfrmMain.btnConnectClick(Sender: TObject);
    begin
      if (btnConnect.Caption = 'Connect') then
      begin
        UniConnection1.ProviderName := 'SQLite';
        UniConnection1.Database := ExtractFilePath(Application.ExeName)
         + edtDBName.Text;
        UniConnection1.Connect;
        btnConnect.Caption := 'Disconnect';
      end
      else
      begin
        UniConnection1.Disconnect;
        btnConnect.Caption := 'Connect';
      end;
    end;