⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.pas

📁 ODAC+SDAC源代码
💻 PAS
📖 第 1 页 / 共 3 页
字号:
    MSSQL.SQL.Text := SQL;
    MSSQL.Execute;
  finally
    MSSQL.Free;
  end;
end;

function TfmMain.SPCallTest(StoredProc: TComponent; Count: integer):integer;
var
  i:integer;
  ExecTime:integer;
begin
  if StoredProc is TMSStoredProc then
    meResult.Lines.Add('> SDAC')
  else
    if StoredProc is TStoredProc then
      meResult.Lines.Add('> BDE')
    else
    if StoredProc is TADOStoredProc then
       meResult.Lines.Add('> ADO');
    if StoredProc is TSQLStoredProc then
       meResult.Lines.Add('> dbExpress');

  TickInfo.Start;
  for i := 1 to Count do begin
    if StoredProc is TMSStoredProc then begin
     with TMSStoredProc(StoredProc) do begin
        if i = 1 then begin
          StoredProcName := 'Master_Insert';
          Prepare;
        end;

        ParamByName('p_Code').AsInteger := i;
        ParamByName('p_Field1').AsString := '01234567890123456789';
        ParamByName('p_Field2').AsString := '12345678901234567890';
        ParamByName('p_Field3').AsString := '23456789012345678901';

        Execute;
      end;
    end
    else
      if StoredProc is TStoredProc then begin
        with TStoredProc(StoredProc) do begin
          if i = 1 then begin
            StoredProcName := 'MASTER_INSERT';
            Params.Clear;
            with TParam(Params.Add) do begin
              Name := '@p_Code';
              ParamType := ptInput;
              DataType := ftInteger;
            end;

            with TParam(Params.Add) do begin
              Name := '@p_Field1';
              ParamType := ptInput;
              DataType := ftString;
            end;

            with TParam(Params.Add) do begin
              Name := '@p_Field2';
              ParamType := ptInput;
              DataType := ftString;
            end;

            with TParam(Params.Add) do begin
              Name := '@p_Field3';
              ParamType := ptInput;
              DataType := ftString;
            end;
            Prepare;
          end;

          ParamByName('@p_Code').AsInteger := i;
          ParamByName('@p_Field1').AsString := '01234567890123456789';
          ParamByName('@p_Field2').AsString := '12345678901234567890';
          ParamByName('@p_Field3').AsString := '23456789012345678901';

          ExecProc;
        end;
      end
      else
        if StoredProc is TADOStoredProc then begin
          with TADOStoredProc(StoredProc) do begin
            if i = 1 then begin
              ProcedureName := 'MASTER_INSERT';
              Parameters.Refresh;
            end;
            Parameters.ParamByName('@p_Code').Value := i;
            Parameters.ParamByName('@p_Field1').Value := '01234567890123456789';
            Parameters.ParamByName('@p_Field2').Value := '12345678901234567890';
            Parameters.ParamByName('@p_Field3').Value := '23456789012345678901';

            ExecProc;
          end;
        end else
        if StoredProc is TSQLStoredProc then begin
          with TSQLStoredProc(StoredProc) do begin
            if i = 1 then begin
              StoredProcName := 'MASTER_INSERT';
              Prepared := True;
            end;

            if StoredProc = BorlandSQLStoredProc then begin
              Params.ParamValues['@p_Code'] := i;
              Params.ParamValues['@p_Field1'] := '01234567890123456789';
              Params.ParamValues['@p_Field2'] := '12345678901234567890';
              Params.ParamValues['@p_Field3'] := '23456789012345678901';
            end
            else
            begin
              Params.ParamValues['p_Code'] := i;
              Params.ParamValues['p_Field1'] := '01234567890123456789';
              Params.ParamValues['p_Field2'] := '12345678901234567890';
              Params.ParamValues['p_Field3'] := '23456789012345678901';
            end;
            ExecProc;
//            Prepared := false;
          end;
        end
  end;

  ExecTime := TickInfo.GetInterval;
  meResult.Lines.Add('Executed ' + IntToStr(Count) + ' times in ' +  IntervalToStr(ExecTime));

  Result := ExecTime;
end;

(*function TfmMain.DataLoadingTest(Loader:TComponent; Count:integer): integer;
const
  ArrSize = 100;
var
  i:integer;
  LoadTime:integer;
  SQL:string;
  Index:integer;
begin
  SQL := 'INSERT INTO Loaded (Code, Field1) VALUES (:Code, :Field1)';
//  SQL := 'begin null; end;';

  if Loader is TMSQuery then begin
    meResult.Lines.Add('> SDAC');
    TMSQuery(Loader).SQL.Text := SQL;
  end
  else
  if Loader is TMSSQL then begin
    meResult.Lines.Add('> SDAC[SQL]');
    TMSSQL(Loader).SQL.Text := SQL;
  end
  else
  if Loader is TMSLoader then begin
    meResult.Lines.Add('> SDAC[Loader]');
  end
  else
    if Loader is TQuery then begin
      meResult.Lines.Add('> BDE');
      TQuery(Loader).SQL.Text := SQL;
    end
    else
      if Loader is TADOQuery then begin
        meResult.Lines.Add('> ADO');
        TADOQuery(Loader).SQL.Text := SQL;
      end;
      if Loader is TSQLQuery then begin
        meResult.Lines.Add('> SQL');
        TSQLQuery(Loader).SQL.Text := SQL;
      end;

  TickInfo.Start;

  Index := 1;

  if Loader is TMSLoader then begin
    LoadCount := Count;
    TMSLoader(Loader).Load;
  end
  else
    for i := 1 to Count do begin
      if Loader is TMSQuery then begin
        TMSQuery(Loader).Prepare;
        TMSQuery(Loader).ParamByName('Code').AsInteger := i;
        TMSQuery(Loader).ParamByName('Field1').AsString := '01234567890123456789';
        TMSQuery(Loader).Execute;
      end
      else
      if Loader is TMSSQL then begin
        TMSSQL(Loader).Prepare;
        TMSSQL(Loader).ArrayLength := ArrSize;
        TMSSQL(Loader).ParamByName('Code').ItemAsInteger[Index] := i;
        TMSSQL(Loader).ParamByName('Field1').ItemAsString[Index] := '01234567890123456789';
        Inc(Index);
        if (Index > ArrSize) or (i = Count) then begin
          if (i = Count) and (Count mod ArrSize > 0) then
            TMSSQL(Loader).Execute(Count mod ArrSize)
          else
            TMSSQL(Loader).Execute(ArrSize);
          Index := 1;
        end;
      end
      else
        if Loader is TQuery then begin
          TQuery(Loader).Prepare;
          TQuery(Loader).ParamByName('Code').AsInteger := i;
          TQuery(Loader).ParamByName('Field1').AsString := '01234567890123456789';
          TQuery(Loader).ExecSQL;
        end
        else
          if Loader is TADOQuery then begin
            TADOQuery(Loader).Parameters.ParamByName('Code').Value := i;
            TADOQuery(Loader).Parameters.ParamByName('Field1').Value := '01234567890123456789';
            TADOQuery(Loader).ExecSQL;
          end else
            if Loader is TSQLQuery then begin
              TSQLQuery(Loader).prepared := True;
              TSQLQuery(Loader).ParamByName('Code').DataType := ftString;
              TSQLQuery(Loader).ParamByName('Code').Value := i;
              TSQLQuery(Loader).ParamByName('Field1').DataType := ftString;
              TSQLQuery(Loader).ParamByName('Field1').Value := '01234567890123456789';
              TSQLQuery(Loader).ExecSQL;
            end;
    end;

{  if Loader is TMSQuery then begin
    TMSQuery(Loader).UnPrepare;
  end
  else
  if Loader is TMSSQL then begin
    TMSSQL(Loader).UnPrepare;
  end
  else
    if Loader is TQuery then begin
      TQuery(Loader).UnPrepare;
    end
    else
      if Loader is TADOQuery then begin
      end;}

  LoadTime := TickInfo.GetInterval;
  meResult.Lines.Add('Loaded ' + IntToStr(Count) + ' recs in ' + IntervalToStr(LoadTime));

  Result := LoadTime;
end;*)

procedure TfmMain.FormShow(Sender: TObject);
begin
  edFetchRows.Text := IntToStr(MSQuery.FetchRows);
end;

procedure TfmMain.CheckConnected;
begin
  if (not MSConnection.Connected) or
    (cbBDE.Checked and not Database.Connected) or
    (cbADO.Checked and not ADOConnection.Connected) or
    (cbdbExpress.Checked and not BorlandSQLConnection.Connected) or
    (cbdbExpSda.Checked and not CrLabSQLConnection.Connected) then
    raise Exception.Create('You must connect first!');
end;

procedure TfmMain.PrintResults;
  procedure Process(CheckBox: TCheckBox; Res: string);
  begin
    if CheckBox.Checked then
      meResult.Lines.Add(CheckBox.Caption + ' ' + Res);
  end;

begin
  meResult.Lines.Add('---------------');
  Process(cbSDAC, lbSDAC.Caption);
  Process(cbBDE, lbBDE.Caption);
  Process(cbADO, lbADO.Caption);
  Process(cbdbExpress, lbdbExpress.Caption);
  Process(cbdbExpSda, lbdbExpSda.Caption);
  meResult.Lines.Add('===============');
end;

procedure TfmMain.btConnectClick(Sender: TObject);
begin
  edFetchRowsExit(nil);

  if not MSConnection.Connected then begin
    MSConnection.Connect;
    meResult.Lines.Add('SDAC connected');
  end;

  if cbBDE.Checked and not Database.Connected then begin
    Database.Params.Values['USER NAME'] := MSConnection.UserName;
    Database.Params.Values['PASSWORD'] := MSConnection.Password;
    Database.Params.Values['SERVER NAME'] := MSConnection.Server;
    Database.Params.Values['DATABASE NAME'] := MSConnection.Database;
    Database.Open;
    meResult.Lines.Add('BDE connected');
  end;

  if cbADO.Checked and not ADOConnection.Connected then begin
    ADOConnection.ConnectionString := MSConnection.ConnectString;
    ADOConnection.Open;
    meResult.Lines.Add('ADO connected');
  end;

  if cbdbExpress.Checked and not BorlandSQLConnection.Connected then begin
    BorlandSQLConnection.Params.Values['User_Name'] := MSConnection.UserName;
    BorlandSQLConnection.Params.Values['Password'] := MSConnection.Password;
    BorlandSQLConnection.Params.Values['HostName'] := MSConnection.Server;
    BorlandSQLConnection.Params.Values['DataBase'] := MSConnection.Database;

    BorlandSQLConnection.Connected := True;
    meResult.Lines.Add('dbExpress connected');
  end;
                         
  if cbdbExpSda.Checked and not CrLabSQLConnection.Connected then begin
    CrLabSQLConnection.Params.Values['User_Name'] := MSConnection.UserName;
    CrLabSQLConnection.Params.Values['Password'] := MSConnection.Password;
    CrLabSQLConnection.Params.Values['HostName'] := MSConnection.Server;
    CrLabSQLConnection.Params.Values['DataBase'] := MSConnection.Database;

    CrLabSQLConnection.Connected := True;
    meResult.Lines.Add('dbExpSda connected');
  end;
end;

procedure TfmMain.btDisconnectClick(Sender: TObject);
begin
  MSConnection.Disconnect;
  BorlandSQLConnection.Connected := false;
  CrLabSQLConnection.Connected := false;
  ADOConnection.Close;
  Database.Close;
  meResult.Lines.Add('Disconected');
end;

procedure TfmMain.btFetchTestClick(Sender: TObject);
const
  Step = 10000;
var
  i: integer;
  ResSDAC, ResBDE, ResADO, ResdbExp, ResdbExpSda: integer;
  mBDE, mADO, mdbExp, mdbExpSda: double;
begin
  CheckConnected;

  Chart.Title.Text.Text := 'Fetch Test';
  for i := 0 to Chart.SeriesCount - 1 do
    Chart.Series[i].Clear;
  Chart.BottomAxis.Minimum := 0;
  Chart.BottomAxis.Maximum := 11 * Step;
  mBDE := 0;
  mADO := 0;
  mdbExp := 0;
  mdbExpSda := 0;

  for i := 1 to 10 do begin
    ResSDAC := 0;
    ResBDE := 0;
    ResADO := 0;
    ResdbExp := 0;
    ResdbExpSda := 0;

    meResult.Lines.Add('---------------');
  // BDE
    if cbBDE.Checked then begin
      ResBDE := FetchTest(BDEQuery, i*Step);
      Chart.Series[1].AddXY(i*Step, ResBDE/1000, '', clTeeColor);
    end;
  // SDAC
    if cbSDAC.Checked then begin
      ResSDAC := FetchTest(MSQuery, i*Step);
      Chart.Series[0].AddXY(i*Step, ResSDAC/1000, '', clTeeColor);
    end;
  // ADO
    if cbADO.Checked then begin
      ResADO := FetchTest(ADOQuery, i*Step);
      Chart.Series[2].AddXY(i*Step, ResADO/1000, '', clTeeColor);
    end;
  // dbExpress
    if cbdbExpress.Checked then begin
      ResdbExp := FetchTest(BorlandSQLQuery, i*Step);
      Chart.Series[3].AddXY(i*Step, ResdbExp/1000, '', clTeeColor);
    end;
  // dbExpSda
    if cbdbExpSda.Checked then begin
      ResdbExpSda := FetchTest(CrLabSQLQuery, i*Step);
      Chart.Series[4].AddXY(i*Step, ResdbExpSda/1000, '', clTeeColor);
    end;

    if ResSDAC > 0 then begin
      mBDE := ((i - 1)*mBDE + ResBDE/ResSDAC)/i;
      mADO := ((i - 1)*mADO + ResADO/ResSDAC)/i;
      mdbExp := ((i - 1)*mdbExp + ResdbExp/ResSDAC)/i;
      mdbExpSda := ((i - 1)*mdbExpSda + ResdbExpSda/ResSDAC)/i;
      lbSDAC.Caption := FloatToStrF(1, ffGeneral, 5, 3);
      lbBDE.Caption := FloatToStrF(mBDE, ffGeneral, 5, 3);
      lbADO.Caption := FloatToStrF(mADO, ffGeneral, 5, 3);
      lbdbExpress.Caption := FloatToStrF(mdbExp, ffGeneral, 5, 3);
      lbdbExpSda.Caption := FloatToStrF(mdbExpSda, ffGeneral, 5, 3);
      lbBDE.Update;
      lbADO.Update;
      lbdbExpress.Update;
      lbdbExpSda.Update;
    end;

    Chart.Update;
  end;
  PrintResults;
end;

procedure TfmMain.btMasterDetailTestClick(Sender: TObject);
var
  i:integer;
  ResSDAC, ResBDE, ResADO, ResdbExp, ResdbExpSda: integer;
  mBDE, mADO, mdbExp, mdbExpSda: double;
begin
  CheckConnected;

  Chart.Title.Text.Text := 'Master/Detail Test';
  for i := 0 to Chart.SeriesCount - 1 do
    Chart.Series[i].Clear;
  Chart.BottomAxis.Minimum := 0;
  Chart.BottomAxis.Maximum := 110;

  mBDE := 0;
  mADO := 0;
  mdbExp := 0;
  mdbExpSda := 0;
  for i := 1 to 10 do begin
    ResSDAC := 0;
    ResBDE := 0;
    ResADO := 0;
    ResdbExp := 0;
    ResdbExpSda := 0;

    meResult.Lines.Add('---------------');
  // SDAC
    if cbSDAC.Checked then begin
      ResSDAC := MasterDetailTest(MSQuery, MSQuery1, i*10);
      Chart.Series[0].AddXY(i*10, ResSDAC/1000, '', clTeeColor);
    end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -