Skip to content

Instantly share code, notes, and snippets.

@xavierlopezpujol
Created March 4, 2022 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xavierlopezpujol/2a26ebb434e18d7e4f1da24eab2df483 to your computer and use it in GitHub Desktop.
Save xavierlopezpujol/2a26ebb434e18d7e4f1da24eab2df483 to your computer and use it in GitHub Desktop.
Dump table from sql server with mORMot
program VolcarTablaSQLServer;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
SynCommons,
System.Generics.Collections,
SynOleDB,
SynDB;
type
TItem = class
Campo1 : string;
Campo2 : string;
end;
var Props: TOleDBConnectionProperties;
Conn: TSQLDBConnection;
Query: TSQLDBStatement;
Lista : TObjectList<TItem>;
Item : TItem;
t : TPrecisionTimer;
begin
ReportMemoryLeaksOnShutdown := true;
t.Start;
Props := TOleDBMSSQLConnectionProperties.Create('.\MSSQL','BBDD','usuario','contraseña');
try //
Lista := TObjectList<TItem>.create;
try
Conn := Props.NewConnection;
try
Query := Conn.NewStatement;
try
Query.Execute('select * from Articulos',true,[]);
while Query.Step do
begin
Item := TItem.Create;
Item.Campo1 := Query.ColumnString(0);
Item.Campo2 := Query.ColumnString(1);
Lista.Add(Item);
end;
writeln(formatUTF8('Registros=% Tiempo=%',[Lista.count , t.stop]));
finally
Query.Free;
end;
finally
Conn.Free;
end;
finally
Lista.free;
end;
finally
Props.Free;
end;
Readln;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment