Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   SQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=6)
-   -   ¿cargar un campo blob por codigo? (https://www.clubdelphi.com/foros/showthread.php?t=21440)

fredo 17-05-2005 21:19:45

¿cargar un campo blob por codigo?
 
Hola, como puedo cargar un blob por codigo en MySQL eje.

update tabla set imagen = "" :confused:
where x

nesecito hacerlo por codigo....

Kreyser 18-05-2005 14:01:28

Hola.

Yo lo hago tal q así:

Código:

sql:='UPDATE fotos SET imagen = :PImagen ';
DataModule1.ZQuery1.ParamByName('PImagen').LoadFromFile('C:\Img.jpg', ftGraphic);

Espero te sirva o al menos oriente.
De todas formas, una búsqueda en el foro por blob + imagen te brindará otras alternativas.:D
Saludos.

fredo 18-05-2005 14:56:59

Ok
 
OK, muchas gracias, queria hacerlo sin parametros, en DBExpress, y es muy buena idea, muchas gracias. Pero la idea es hacerlo por codigo como String, lo que pasa es que tengo una rutina que se encarga de gestionar cambios entre DBExpress y el motor de Base de Datos, esta rutina genera el codigo adecuado para actualizar, insertar o borrar registros, sin embargo esta no me sirve para los campos Blob, para todo el resto si.... asi que necesita darle soporte para Blobs. Adjunto el codigo y si alguien puede mejorarlo mejor aun.... eta funcion sirve para poner delimitadores a los diferentes tipos de datos y convertirloe en un estring aplicable a un update o insert...



Function TFrm_Main.Delimitador(DataSet:TSimpleDataSet;Campo:String;Old_Value:Boolean):String;
var d,m,a:Word;
TextoAux,Flotante:String;
i:Integer;
Nuevo:Boolean;
FloatAux:Double;
FechaAux:TDateTime;

Begin
with DataSet do
Begin
Nuevo:=False;
Try
If fieldbyname(Campo).DataType in [ftInteger,ftFloat,ftCurrency]
Then
Begin
FloatAux:=fieldbyname(Campo).OldValue;
end
else
Begin
If fieldbyname(Campo).DataType in [ftDate,ftTime,ftDateTime]
then FechaAux:=fieldbyname(Campo).OldValue
else Flotante:=fieldbyname(Campo).OldValue;
end;
except
Nuevo:=true;
end;

if fieldbyname(Campo).DataType in [ftString,ftMemo,ftBlob] then
Begin
If not(fieldbyname(Campo).DataType in [ftBlob])
then
Begin
Flotante:='';
If (Old_Value) and (not Nuevo) then TextoAux:=fieldbyname(Campo).OldValue
else TextoAux:=fieldbyname(Campo).AsSTring;
for i:=1 to length(TextoAux) do
Begin
if (TextoAux[i] = '"') or
(TextoAux[i] = '\') or
(TextoAux[i] = '''')
then Flotante:=Flotante+'\';
Flotante:=Flotante+TextoAux[i];
end;
Result:='"'+Flotante+'"';
end
else
Begin
If (Old_Value) and (not Nuevo)
then
Begin
Result:=':Foto'+Campo;
dataset.ParamByname(':Foto'+Campo).AsBlob:= fieldbyname(Campo).OldValue;
end
else
Begin
Result:=':Foto'+Campo;
dataset.ParamByname(':Foto'+Campo).AsBlob:= fieldbyname(Campo).Value;

// aqui deberia trasformar el blob en algo entendible en texto, pero no funciona, porque necesito tener el codigo ya formando parte de la quiery, por lo que se cae al hacer la insercion....
end;
end;
End
else
Begin


if fieldbyname(Campo).DataType in [ftDate,ftTime,ftDateTime] then
Begin
If (Old_Value) and (not Nuevo)
then DecodeDate(fieldbyname(Campo).OldValue,a,m,d)
Else DecodeDate(fieldbyname(Campo).AsDateTime,a,m,d);
Result:=''''+FormatFloat('00',a)+'-'+FormatFloat('00',m)+'-'+FormatFloat('00',d)+'''';
End
else
Begin
If fieldbyname(Campo).DataType in [ftInteger] then
Begin
If (Old_Value) and (not Nuevo)
then Result:=IntTostr(fieldbyname(Campo).OldValue)
else Result:=IntTostr(fieldbyname(Campo).AsInteger);
end
else
Begin
If (Old_Value) and (not Nuevo)
then
Begin
Flotante:=fieldbyname(Campo).OldValue;
end
else Flotante:=fieldbyname(Campo).AsString;
//Showmessage(Campo+':'+Flotante+' - '+fieldbyname(Campo).AsString);
for i:=1 to length(Flotante) do
begin
if Flotante[i] = ',' then Flotante[i]:='.';
end;
Result:=Flotante;
end;
end;
end;
end;
end;


Saludos y gracias....


La franja horaria es GMT +2. Ahora son las 13:24:35.

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