Ver Mensaje Individual
  #4  
Antiguo 11-05-2007
Avatar de delphi.com.ar
delphi.com.ar delphi.com.ar is offline
Federico Firenze
 
Registrado: may 2003
Ubicación: Buenos Aires, Argentina *
Posts: 5.932
Reputación: 26
delphi.com.ar Va por buen camino
Antes que nada un par de comentarios, por como veo el código evidentemente lo "tomé prestado" del componente de las RxLibs. Lo otro que quiero que sepas, es que hace este código: Se trata de una aplicación que crea paquetes "autoejecutables" donde estos paquetes pueden ser scripts, querys, ejecutables, archivos, fuentes.... Este procedimiento es el asociado a un TADOConnection y te lo recorté un poco para que solo quede lo que necesitas:

Código Delphi [-]
var
  ADOConn: TADOConnection;
  AScript: TStringList;
begin
  ADOConn := TADOConnection.Create(nil);
  try
    with ADOConn do
    begin
      ConnectionString := '.........';
      Open;
      ExecuteScript(AScript, ADOConn, 'GO');
      Close;
    end;
  finally
    ADOConn.Free;
  end;
end


Código Delphi [-]
procedure ExecuteScript(SQL: TStrings; AADOConn: TADOConnection; ASeparator: string);
var
  iRecAffected: Integer;
  StatementNo: Integer;
  S, LastStr, L, T: string;
  SQLFilled: Boolean;
  I, CurrStatement,
  iCol: Integer;
  AQuerySQL: TStringList;
const
  QUERY_FIELD_SEPARATOR = ' ';
begin
  LastStr := '';
  AQuerySQL := TStringList.Create;
  try
    I := 0;
    StatementNo := -1;
    CurrStatement := 0;
    while I < SQL.Count do
    begin
      AQuerySQL.BeginUpdate;
      try
        AQuerySQL.Clear;
        SQLFilled := False;
        repeat
          if LastStr <> '' then
          begin
            AQuerySQL.Add(LastStr);
            LastStr := '';
          end;
          if I < SQL.Count then
          begin
            S := (SQL[i]);
            Inc(I);
            if CompareText(Trim(S), ASeparator) = 0 then
              SQLFilled := True
            else if S <> '' then
              AQuerySQL.Add(S);
          end
          else SQLFilled := True;
        until SQLFilled;
      finally
        AQuerySQL.EndUpdate;
      end;

      if AQuerySQL.Count > 0 then
      begin
        if (StatementNo < 0) or (StatementNo = CurrStatement) then
        begin
          AADOConn.Execute(AQuerySQL.Text, iRecAffected);
          if StatementNo = CurrStatement then Break;
        end;
        Inc(CurrStatement);
      end;
    end;
  finally
    AQuerySQL.Free;
  end;
end;

Saludos!
__________________
delphi.com.ar

Dedique el tiempo suficiente para formular su pregunta si pretende que alguien dedique su tiempo en contestarla.
Responder Con Cita