Created
March 4, 2022 15:12
-
-
Save xavierlopezpujol/2a26ebb434e18d7e4f1da24eab2df483 to your computer and use it in GitHub Desktop.
Dump table from sql server with mORMot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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