mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-07 11:08:02 +02:00
* Small example for CSV Dataset examples/showcsv.pp
git-svn-id: trunk@38542 -
This commit is contained in:
parent
55402a2182
commit
5925568526
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -2019,6 +2019,7 @@ packages/fcl-db/examples/loadlibdemo.pp svneol=native#text/plain
|
||||
packages/fcl-db/examples/logsqldemo.lpi svneol=native#text/plain
|
||||
packages/fcl-db/examples/logsqldemo.pas svneol=native#text/plain
|
||||
packages/fcl-db/examples/pqeventstest.pp svneol=native#text/plain
|
||||
packages/fcl-db/examples/showcsv.pp svneol=native#text/plain
|
||||
packages/fcl-db/examples/sqlite3loadlib.lpr svneol=native#text/plain
|
||||
packages/fcl-db/examples/sqlparser.pp svneol=native#text/plain
|
||||
packages/fcl-db/fpmake.pp svneol=native#text/plain
|
||||
|
@ -4,6 +4,7 @@
|
||||
<Version Value="9"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<SaveOnlyProjectUnits Value="True"/>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
|
@ -47,6 +47,9 @@ begin
|
||||
FConn.UserName:=AUserName;
|
||||
FConn.Password:=APassword;
|
||||
FConn.Transaction:=TSQLTransaction.Create(Self);
|
||||
FConn.Transaction.Params.Add('version1');
|
||||
FConn.Transaction.Params.Add('read_committed');
|
||||
FConn.Transaction.Params.Add('isc_tpb_lock_read=PARMTAB');
|
||||
FConn.OnLog:=@DoSQLLog;
|
||||
FConn.LogEvents:=LogAllEventsExtra;
|
||||
FConn.Connected:=True;
|
||||
|
48
packages/fcl-db/examples/showcsv.pp
Normal file
48
packages/fcl-db/examples/showcsv.pp
Normal file
@ -0,0 +1,48 @@
|
||||
program showcsv;
|
||||
|
||||
{$mode objfpc}
|
||||
{$H+}
|
||||
|
||||
uses db,csvdataset, classes, sysutils;
|
||||
|
||||
Procedure usage;
|
||||
|
||||
begin
|
||||
Writeln('Usage: ',ExtractFIleName(Paramstr(0)),' [-h] [-c col] filename');
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
Var
|
||||
FN,Column : String;
|
||||
F : TField;
|
||||
|
||||
begin
|
||||
if (paramcount=0) or (paramstr(1)='-h') then
|
||||
usage;
|
||||
if (Paramstr(1)='-c') then
|
||||
begin
|
||||
Column:=Paramstr(2);
|
||||
FN:=Paramstr(3);
|
||||
end
|
||||
else if ParamCount<>1 then
|
||||
Usage
|
||||
else
|
||||
FN:=Paramstr(1);
|
||||
With TCSVDataset.Create(Nil) do
|
||||
try
|
||||
CSVOptions.FirstLineAsFieldNames:=True;
|
||||
LoadFromFile(FN);
|
||||
Active:=True;
|
||||
While not EOF do
|
||||
begin
|
||||
Write(RecNo,' : ');
|
||||
For F in FIelds do
|
||||
if (Column='') or (Column=F.FIeldName) then
|
||||
Write(' ',F.AsString);
|
||||
Writeln;
|
||||
Next;
|
||||
end;
|
||||
finally
|
||||
Free;
|
||||
end;
|
||||
end.
|
@ -4,6 +4,7 @@
|
||||
<Version Value="9"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<SaveOnlyProjectUnits Value="True"/>
|
||||
<LRSInOutputDirectory Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
|
@ -1,4 +1,4 @@
|
||||
unit TestDBBasics;
|
||||
unit TestDBBasics;
|
||||
|
||||
{$IFDEF FPC}
|
||||
{$mode Delphi}{$H+}
|
||||
|
Loading…
Reference in New Issue
Block a user