在空白窗体上添加: TFDConnection, TFDPhysSQLiteDriverLink, TFDGUIxWaitCursor, TMemo
procedure TForm1.FormCreate(Sender: TObject); var List: TStrings; V: Variant; begin FDConnection1.Open('DriverID=SQLite; Database=C:TempFDDemo.sdb'); List := TStringList.Create; FDConnection1.GetInfoReport(List); Memo1.Clear; Memo1.Lines.Add('==> 获取连接信息:'); Memo1.Lines.AddStrings(List); FDConnection1.GetTableNames('', '', '', List); Memo1.Lines.Add(#13#10'==> 获取数据库中的表名列表:'); Memo1.Lines.AddStrings(List); FDConnection1.GetTableNames('', '', '', List, [], [tkView]); Memo1.Lines.Add(#13#10'==> 获取数据库中的查询名列表:'); Memo1.Lines.AddStrings(List); FDConnection1.GetFieldNames('', '', 'Orders', '', List); Memo1.Lines.Add(#13#10'==> 获取 Orders 表中的字段名列表:'); Memo1.Lines.AddStrings(List); V := FDConnection1.ConnectionMetaDataIntf.GetTables([], [tkTable], '', '', '').Rows[0].GetData(0); Memo1.Lines.Add(#13#10'==> 获取第一个表中第一列的第一个数据:'); Memo1.Lines.Add(V); List.Free; end;
{结果如下:} {............................................................... ==> 获取连接信息: ================================ Connection definition parameters ================================ Name=Unnamed DriverID=SQLite Database=C:TempFDDemo.sdb ================================ FireDAC info ================================ Tool = RAD Studio XE6 FireDAC = 10.0.1 (Build 69712) Platform = Windows 32 bit Defines = FireDAC_NOLOCALE_META;FireDAC_MONITOR ================================ Client info ================================ Loading driver SQLite ... DLL = Client version = 3.8.3.1 Compile options = ENABLE_COLUMN_METADATA;ENABLE_FTS3; ENABLE_FTS3_PARENTHESIS;ENABLE_FTS4;ENABLE_RTREE; ENABLE_STAT4;HAS_CODEC;OMIT_AUTOINIT; OMIT_DEPRECATED;SYSTEM_MALLOC;TEMP_STORE=2; THREADSAFE=2 ================================ Session info ================================ Current catalog = Current schema = Total changes = 0 Database encoding = UTF8 Encryption mode = Cache size = 10000 ==> 获取数据库中的表名列表: Categories CustomerCustomerDemo CustomerDemographics Customers Employees EmployeeTerritories FDQA_all_types FDQA_ascii_types FDQA_batch_test FDQA_bcd FDQA_blob FDQA_Categories FDQA_db_types FDQA_details_autoinc FDQA_FK_tab FDQA_ForAsync FDQA_identity_tab FDQA_locktable FDQA_map1 FDQA_map2 FDQA_map3 FDQA_map4 FDQA_master_autoinc FDQA_Maxlength FDQA_novalstable FDQA_numbers FDQA_OrderDetails FDQA_parambind FDQA_Products FDQA_tabwithpk FDQA_timestamp FDQA_transtable FDQA_V_Test FDQA_WString "Order Details" Orders Products Region Shippers Suppliers Territories ==> 获取数据库中的查询名列表: FDQA_V_Test ==> 获取 Orders 表中的字段名列表: OrderID CustomerID EmployeeID OrderDate RequiredDate ShippedDate ShipVia Freight ShipName ShipAddress ShipCity ShipRegion ShipPostalCode ShipCountry ==> 获取第一个表中第一列的第一个数据: 1 ...............................................................}
FireDAC 下主要有四个 SQLite 的相关单元: FireDAC.Phys.SQLiteCli // 最底层的 API; 利用它可以像 C 语言一样写程序 FireDAC.Phys.SQLiteWrapper // 主功能包装; 利用它可以像 C++ 一样写程序; 这可能是我以后使用最多的 FireDAC.Phys.SQLiteMeta // 元信息包装 FireDAC.Phys.SQLite // 实现 FireDAC 相关接口; 使用 FireDAC 的方式操作 SQLite 可能是最简单的, 更重要的是: FireDAC 操作所有数据库的方法是一样的
FireDAC.Phys.SQLiteWrapper 提供的 TSQLiteDatabase 类表示 SQLite 数据库, 使用它时一般无须创建,
直接从 FDConnection1.CliObj 或 FDConnection1.ConnectionIntf.CliObj 转换即可.
{示例:通过 TSQLiteDatabase 类获取 CharacterSet} uses FireDAC.Phys.SQLiteWrapper; procedure TForm1.Button1Click(Sender: TObject); var db: TSQLiteDatabase; begin db := TSQLiteDatabase(FDConnection1.CliObj); //假定 FDConnection1 已连接 ShowMessage(db.CharacterSet); //UTF8 end;