Ver Mensaje Individual
  #2  
Antiguo 25-04-2007
Nasca Nasca is offline
Miembro
 
Registrado: abr 2007
Ubicación: Almería (España)
Posts: 249
Reputación: 18
Nasca Va por buen camino
Lo puedes hacer a través del componente de conexión, yo lo tengo montado a través de una tabla donde tengo las distintas sentencias y luego voy ejecutando las mismas recursivamente con algo como esta sentencia:

Código Delphi [-]

function TfCriteriumACm.EjecutarSentencia: Integer;
var
 TD: TTransactionDesc;
 resultado : Integer;
begin
if not(sqlcdatos.Connected) then
  begin
   Showmessage('La conexióa la base de datos no está abierta!!!');
   Result := -100;
   Exit;
  end;
if not(cdsUpdateSQL.Active) or (cdsUpdateSQLSENTENCIA_SQL.IsNull) then
  begin
   Showmessage('La tabla de sentencias SQL de actualización no está abierta o no hay sentencia que ejecutar!!!');
   Result := -100;
   Exit;
  end;
if (cdsUpdateSQLTIPO.Value = 'stUnknow') or (cdsUpdateSQLTIPO.Value = '') then
   begin
    cdsUpdateSQL.Edit;
    cdsUpdateSQLRESULTADO.Value := -1;
    cdsUpdateSQLRESULTADO_TEXTO.Value := 'Sentencia desconocida, no ejecutada!';
    Result := -1;
    Exit;
   end;
if (cdsUpdateSQLTIPO.Value = 'stSetTerm') or (cdsUpdateSQLTIPO.Value = 'stSelect')
    or (cdsUpdateSQLTIPO.Value = 'stCreateDatabase') then
   begin
    cdsUpdateSQL.Edit;
    cdsUpdateSQLRESULTADO.Value := -1;
    cdsUpdateSQLRESULTADO_TEXTO.Value := 'Sentencia no ejecutable';
    Result := -1;
    Exit;
   end;

TD.TransactionID := cdsUpdateSQLORDEN.Value;
TD.IsolationLevel := xilREADCOMMITTED;
sqlcdatos.StartTransaction(TD);
try
 resultado := sqlcdatos.ExecuteDirect(cdsUpdateSQLSENTENCIA_SQL.AsString);
 sqlcdatos.Commit(TD);
 cdsUpdateSQL.Edit;
 cdsUpdateSQLRESULTADO.Value := resultado;
 cdsUpdateSQLRESULTADO_TEXTO.Value := 'Sentencia ejecutada sin problemas';
 Result := resultado;
except
  On E: Exception Do
     begin
       sqlcdatos.Rollback(TD);
       cdsUpdateSQL.Edit;
       cdsUpdateSQLRESULTADO.Value := -13;
       cdsUpdateSQLRESULTADO_TEXTO.Value := ('Error: '+E.Message);
       Result := -13;
     end;
end;

Parte de la lógica es por guardar y devolver un valor que me permita detener el script sql, pero si entresacas lo importante (el final) puedes apañarte.
Responder Con Cita