home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 26 / CD_ASCQ_26_1295.iso / vrac / sql_load.zip / MAIN.PAS < prev    next >
Pascal/Delphi Source File  |  1995-07-04  |  3KB  |  134 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, DB, DBTables, StdCtrls;
  8.  
  9. type
  10.   TfrmMain = class(TForm)
  11.     dfAlias: TEdit;
  12.     Label1: TLabel;
  13.     Label2: TLabel;
  14.     dfInputFile: TEdit;
  15.     Label3: TLabel;
  16.     dfOutputFile: TEdit;
  17.     btnStart: TButton;
  18.     dbMain: TDatabase;
  19.     qLoad: TQuery;
  20.     Button1: TButton;
  21.     procedure btnStartClick(Sender: TObject);
  22.     procedure Button1Click(Sender: TObject);
  23.   private
  24.     { Private declarations }
  25.   public
  26.     { Public declarations }
  27.   end;
  28.  
  29.   procedure procLoadData;
  30.  
  31. var
  32.   frmMain: TfrmMain;
  33.  
  34. implementation
  35.  
  36. {$R *.DFM}
  37.  
  38. procedure TfrmMain.btnStartClick(Sender: TObject);
  39. begin
  40.   dbMain.Connected:=False;
  41.   dbMain.ALIASName:=dfAlias.Text;
  42.   Screen.Cursor:=crHourglass;
  43.   try
  44.     dbMain.Connected:=True;
  45.     messagedlg('Successful connection', mtInformation, [mbOK],0);
  46.     procLoadData;
  47.   except
  48.     on E: EDatabaseError do
  49.       begin
  50.       messagedlg('Connection Failed',mtError, [mbOK],0);
  51.       screen.Cursor:=crDefault;
  52.       end;
  53.   end;
  54.  
  55. end;
  56.  
  57. procedure procLoadData;
  58.    function fnStripSQL(strSQL: String):String;
  59.    var
  60.       strTemp: String;
  61.       strOut: String;
  62.       nIndex: Integer;
  63.    begin
  64.       nIndex:=1;
  65.       strOut:='';
  66.       while nIndex<Length(strSQL) do
  67.         begin
  68.           strTemp:='';
  69.           strTemp:=Copy(strSQL, nIndex, 1);
  70.           if not((strTemp=#10) or (strTemp=#13)) then
  71.              strOut:=strOut+strTemp;
  72.           nIndex:=nIndex+1;
  73.         end;
  74.       fnStripSQL:=strOut;
  75.    end;
  76.  
  77. var
  78.    nFileIn, nFileOut: TextFile;
  79.    bLoop: Boolean;
  80.    strSQL: String;
  81. begin
  82.    screen.cursor:=crHourglass;
  83.    {Open the files for read/write}
  84.    AssignFile(nFileIn, frmMain.dfInputFile.Text);
  85.    AssignFile(nFileOut, frmMain.dfOutputFile.Text);
  86.    Rewrite(nFileOut);
  87.    Reset(nFileIn);
  88.  
  89.    While not EOF(nFileIn) do
  90.      begin
  91.      {Read nFileIn into the Query SQL String list until we hit a ';'}
  92.      frmMain.qLoad.Close;
  93.      frmMain.qLoad.SQL.Clear;
  94.      bLoop:=False;
  95.      While bLoop=False do
  96.        begin
  97.        ReadLn(nfileIn, strSQL);
  98.        {strSQL:=fnStripSQL(strSQL);}
  99.        WriteLn(nFileOut, strSQL);
  100.        {If the last character is a ';' then stop reading}
  101.        if pos(';', strSQL)<>0 then
  102.           begin
  103.           bLoop:=True;
  104.           frmMain.qLoad.SQL.Add(strSQL);
  105.           end;
  106.        if strSQL='' then bLoop:=True;
  107.  
  108.        end;
  109.      try
  110.        WriteLn(nFileOut, 'Executing.........');
  111.        frmMain.qLoad.ExecSQL;
  112.      except
  113.        on E: EDatabaseError do
  114.           begin
  115.           WriteLn(nfileOut, 'FAILED - '+ E.Message);
  116.           end;
  117.      end;
  118.  
  119.      end;
  120.  
  121.    closefile(nFileIn);
  122.    CloseFile(nFileOut);
  123.    screen.cursor:=crDefault;
  124.    messagedlg('DONE', mtInformation, [mbOK],0);
  125.  
  126. end;
  127.  
  128. procedure TfrmMain.Button1Click(Sender: TObject);
  129. begin
  130.   Close;
  131. end;
  132.  
  133. end.
  134.