Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Coloboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 31-08-2010
Avatar de movorack
[movorack] movorack is offline
Miguel A. Valero
 
Registrado: feb 2007
Ubicación: Bogotá - Colombia
Posts: 1.346
Poder: 22
movorack Va camino a la famamovorack Va camino a la fama
y si la inserción es muchisimo mas compleja?

Código SQL [-]
INSERT INTO films (code, title) VALUES ('B6717', get_title('B6717'));

INSERT INTO films (code, title, did, date_prod, kind) VALUES
    ('B6717', 'Tampopo', 110, '1985-02-10', 'Comedy'),
    ('HG120', 'The Dinner Game', 140, DEFAULT, 'Comedy');

INSERT INTO films SELECT * FROM tmp_films WHERE date_prod < '2004-05-07';
__________________
Buena caza y buen remar... http://mivaler.blogspot.com
Responder Con Cita
  #2  
Antiguo 31-08-2010
Avatar de ingabraham
ingabraham ingabraham is offline
Miembro
 
Registrado: ago 2007
Posts: 614
Poder: 20
ingabraham Va por buen camino
Por ejemplo he intentado hacerlo, como algo asi.

Código Delphi [-]
 
Procedure TUDBDatos.GuardarEnTabla(Tabla,CadenaCampos:string);
var
  Vsql : string;
begin
   Vsql := 'Insert Into '+ Tabla +'  Values('+ CadenaCampos+')';
   with ibguardar do
   begin
    close;
    SQL.Clear;
    SQL.Add(Vsql);
    ExecSQL;
   end;
   IBTransaction.CommitRetaining;
end;
 
el llamado podria ser.
 
var Str : String;
begin
   Str   :=  ''''+EdNro.TEXT+''''+','+''''+EdCedula.TEXT+''''+','+''''+EdNombre.TEXT+''''+','+''''+EdDir.TEXT+'''  '+','+''''+EdTel.TEXT+''''+','+''''+EdCargo.TEXT+''''+','+''''+DateToStr(FIngreso.date)+''''+','+'''  '+EdSueldo.TEXT+''''+','+''''+EdPorc.TEXT+''''+','+''''+'Activo'+'''' ;
 
 UDBDatos.GuardarEnTabla('EMPLEADOS',Str);
- pero tengo problemas cuando sean fechas tipo date que no se como enviarlas o reales.

-siempre utilizo los qry por que me dan mas facilidad y opciones para realizar mas consultas sql.
__________________
Enseñar es la virtud de un sabio.
Responder Con Cita
  #3  
Antiguo 31-08-2010
cloayza cloayza is offline
Miembro
 
Registrado: may 2003
Ubicación: San Pedro de la Paz, Chile
Posts: 948
Poder: 25
cloayza Tiene un aura espectacularcloayza Tiene un aura espectacular
Referente a la pregunta, escribi un pequeno codigo que hace lo que requiere...

Pero como dice Movorack, si es un codigo mas complejo no servira o hay que implementar las restricciones y demas...

Espero te ayude...

Aqui va...
Trabaja en base a 2 vectores de tipo Variant, uno para los campos y otro para los valores, ademas se le debe indicar el nombre de la tabla...

Las funciones habilitadas son:
Select, Insert, Delete, Update;

Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TSQLType=(sqSelect, sqInsert, sqDelete, sqUpdate);

  TSQLArray=array of Variant;

  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Label1: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    chkInsert: TRadioButton;
    chkSelect: TRadioButton;
    chkUpdate: TRadioButton;
    chkDelete: TRadioButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    AFields, AValues:TSQLArray;
    function CreateSQL(fTable:string; fFields:TSQLArray; fValues:TSQLArray;fSqlType:TSQLType):string;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.CreateSQL(fTable:string; fFields:TSQLArray; fValues:TSQLArray;fSqlType:TSQLType):string;
var
   i:Integer;
   fSql,fVal:string;

   function GetValue():String;
   begin
        case VarType(fValues[i]) of
             varString,
             varDate     : Result:=QuotedStr(fValues[i]);
             varByte,
             varWord,
             varShortInt,
             varSmallint,
             varInteger,
             varLongWord,
             varInt64    : Result:=IntToStr(fValues[i]);
             varSingle,
             varDouble   : Result:=FloatTostr(fValues[i]);
             varBoolean  : if fValues[i] then
                              Result:=QuotedStr('True')
                           else
                              Result:=QuotedStr('False');
        end;
end;
begin
     case (fSqlType) Of
         sqSelect:begin
                       fSql:='';
                       for i := Low(fFields)to High(fFields) do
                       begin
                            fSql:=fSql+fFields[i];
                            if i< High(fFields) then
                               fSql:=fSql+', '
                       end;
                       Result:=Format('SELECT %s FROM %s',[fSql, fTable]);
                  end;
         sqInsert:begin
                       fSql:=''; fVal:='';
                       for i := Low(fFields)to High(fFields) do
                       begin
                            fSql:=fSql+fFields[i];

                            fVal:=fVal+GetValue();

                            if i< High(fFields) then
                            begin
                                 fSql:=fSql+', ';
                                 fVal:=fVal+',';
                            end;
                       end;
                       Result:=Format('INSERT INTO %s (%s) VALUES (%s)',[fTable,fSQL, fVal]);
                  end;
         sqDelete,
         sqUpdate:begin
                       fSql:=''; fVal:='';
                       for i := Low(fFields)to High(fFields) do
                       begin
                            fVal:=GetValue();

                            {Concatena Campo y Valor a asignar...}
                            fSql:=fSql+Format('%s=%s',[fFields[i],fVal]);

                            if i< High(fFields) then
                            begin
                                 if fSqlType=sqUpdate then
                                    fSql:=fSql+', '
                                 else
                                    fSql:=fSql+' AND '
                            end;
                       end;

                       if fSqlType=sqUpdate then
                          Result:=Format('UPDATE %s SET %s;',[fTable,fSQL, fVal])
                       else
                          Result:=Format('DELETE FROM %s WHERE (%s)',[fTable,fSQL, fVal])
                  end;
     end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
     {Dimensiona los vectores}
     SetLength(AFields,6);
     SetLength(AValues,6);

     {Asigna los nombre de los campos...}
     AFields[0]:='Id';
     AFields[1]:='Nombre';
     AFields[2]:='Fecha';
     AFields[3]:='Logico';
     AFields[4]:='Num_Entero';
     AFields[5]:='Num_Real'; 

    {Asigna los valores de cada campo...}
     AValues[0]:=10;
     AValues[1]:='Club Delphi';
     AValues[2]:=Date;
     AValues[3]:=True;
     AValues[4]:=199999;
     AValues[5]:=1000.00;

    {Se llama al procedimiento CreateSQL...}
    {Edit1.Text ->Para ingresar el nombre de la tabla...}
     
     if chkSelect.checked then
        memo1.lines.Text:=CreateSQL(Edit1.Text, AFields, AValues, sqSelect)
     else if chkInsert.Checked then
        memo1.lines.Text:=CreateSQL(Edit1.Text, AFields, AValues, sqInsert)
     else if chkDelete.Checked then
        memo1.lines.Text:=CreateSQL(Edit1.Text, AFields, AValues, sqDelete)
     else if chkUpdate.Checked then
        memo1.lines.Text:=CreateSQL(Edit1.Text, AFields, AValues, sqUpdate)
end;
end.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
condicionar un procedimiento dentro de otro procedimiento yossi Varios 7 17-05-2010 11:47:14
procedimiento dentro de procedimiento chechu Varios 6 25-11-2005 00:34:48
Insert me cierra otro Insert motrildelphi Conexión con bases de datos 0 05-05-2005 13:20:27
Ayuda, como llamar a un procedimiento desde otro procedimiento? Ariatna Varios 1 01-02-2005 05:05:35
Insert Con Ibx AGAG4 Conexión con bases de datos 8 09-09-2004 21:29:15


La franja horaria es GMT +2. Ahora son las 16:45:52.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi