program Ole; {$APPTYPE CONSOLE} {$mode objfpc}{$H+} uses ComObj, Variants; function IIF(b: boolean; sTrue: string; sFalse: string = ''): string; begin if b then result := sTrue else result := sFalse; end; const adOpenForwardOnly = $00000000; adLockReadOnly = $00000001; var cn, rs: OleVariant; s: string; i: integer; begin // CoInitialize(NIL); //connect db cn := CreateOleObject('ADODB.Connection'); {$ifdef access} // Access over MS Jet OLE DB 4.0 cn.Open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb'); {$endif} {$ifdef mdbODBC} // Access 97-2003, Microsoft Access ODBC Driver cn.Open('Driver={Microsoft Access Driver (*.mdb)};Dbq=D:\test.mdb;Locale Identifier=1031;Uid=Admin;Pwd=;'); {$endif} {$ifdef accdbODBC} // Access 2007-2013, Microsoft Access accdb ODBC Driver cn.Open('Driver={Microsoft Access Driver (*.accdb)};Dbq=d:\test.accdb;Locale Identifier=1031;Uid=Admin;Pwd=;'); {$endif} {$ifdef accessNETWORK} // OLE DB Provider for Microsoft Directory Services // uses Microsoft Access Database Engine 2010 cn.Open('Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\server\shareDB\test.mdb;'); {$endif} {$ifdef mysqlnew} // MySQL ODBC 5.2 cn.Open('Provider=MSDASQL;DRIVER={MySQL ODBC 5.2a Driver};SERVER=localhost;DATABASE=testsql;UID=root;PWD=root;'); {$endif} {$ifdef mysqlold} // MySQL ODBC 3.51 cn.Open('Provider=MSDASQL.1;Extended Properties="Driver={MySQL ODBC 3.51 Driver};Server=localhost;Port=3306;Database=testsql;User=root;Password=root;Option=3;"'); {$endif} {$ifdef mysql} // MSSQL cn.Open('Provider=SQLOLEDB.1;Initial Catalog=TestDB;Data Source=localhost;Persist Security Info=False;User ID=root;Password=root;'); {$endif} {$ifdef mysqlexpress} // MSSQL Express 2008 cn.Open('Provider=SQLNCLI10.1;Initial Catalog=TestDB;Data Source=localhost\SQLEXPRESS;Persist Security Info=False;User ID=root;Password=root;'); {$endif} //select rs := CreateOleObject('ADODB.Recordset'); rs.Open('SELECT * FROM testTable', cn, adOpenForwardOnly, adLockReadOnly); s := ''; //list fieldnames for i:=0 to rs.Fields.count-1 do s := s + IIF(i>0, ';') + rs.Fields[i].Name; s := s + #13#10; //list values while not rs.eof do begin for i:=0 to rs.Fields.count-1 do s := s + IIF(i>0, ';') + VarToStr(rs.Fields[i].Value); s := s + #13#10; rs.MoveNext; end; WriteLn(s); //close recordset rs.Close; rs := unassigned; //close connection; cn.Close; cn := unassigned; // CoUnInitialize; end.