2

需要在 SQLite 中存储一些数据。使用 SQLite 选择 UniDac,但有一个问题:在 UniConnection 中,在“数据库”字段中,我选择 SQLite 并输入数据库的名称 - 得到错误“不支持的元数据类型”。未创建数据库文件。问题是什么?正如之前与 UniDac 合作的那样,没有观察到此类问题。

4

1 回答 1

2

UniDAC 4.1.6 with Delphi XE2 我没有看到任何问题。SQLite3.dll 必须位于系统路径或与可执行文件相同的目录中。以下非常基本的示例在单击 btnConnect 时创建数据文件。

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;
于 2012-05-30T01:55:45.523 回答