在空白窗體上添加: TFDConnection, TFDPhysSQLiteDriverLink, TFDGUIxWaitCursor, TMemo
procedure TForm1.FormCreate(Sender: TObject); var List: TStrings; V: Variant; begin FDConnection1.Open('DriverID=SQLite; Database=C:\Temp\FDDemo.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:\Temp\FDDemo.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 操作所有數據庫的方法是一樣的
{示例:通過 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;