Topic: [Help] Syntax or data type problem

Hello people.  I am having a data type problem to do an insert into a table.  Below I put the complete procedure to get the idea.

procedure frm_conf_ihs_OnShow (Sender: TObject; Action: string);
var
v_checkconf,v_titulo_left,v_lema_left,v_tiempo_actualizacion_datos_ds: Integer;
v_banner_logo,v_banner_banner,v_banner_titulo,v_banner_lema: String;
begin

v_checkconf := SQLExecute('SELECT count(id) FROM conf_ihs_est');

If (v_checkconf = 0) then
begin
MessageBox('No se ha encontrado una configuración, se establecerá una por defecto.','Configuración Dashboard',MB_Ok+MB_ICONINFORMATION);

v_banner_logo := '';
v_banner_banner := '';
v_banner_titulo := 'InteligenciaVial';
v_banner_lema := 'Escuela de Automovilismo';
v_titulo_left := 120;
v_lema_left := 120;
v_tiempo_actualizacion_datos_ds := 20000;

SQLExecute('INSERT INTO conf_ihs_est'+
          '(banner_logo, banner_banner, banner_titulo, banner_lema, titulo_left, lema_left, tiempo_actualizacion_datos_ds) '+
          'VALUES("'+v_banner_logo+'","'+v_banner_banner+'","'+v_banner_titulo+'","'+v_banner_lema+'",'+v_titulo_left+','+v_lema_left+','+v_tiempo_actualizacion_datos_ds+')');
End;

end;

The error gives me with the integer values.  I think it is the syntax that I am using or if the data has to be cast.

Another question, if you notice I want to insert by default 2 images.  What is the data type for an image?

Re: [Help] Syntax or data type problem

load image

procedure SaveFileToDatabase (Tablename, Fieldname, Filename: string; id: integer);
var
    sSQL: string;
    sFileName: string;
    sFieldName: string;

    Params: TParams;
    MemoryStream: TMemoryStream;
    Param: TParam;
begin
    sSQL := 'UPDATE '+Tablename+' SET ' +Fieldname+'= :'+Fieldname+', '+Fieldname+'_filename="'+ExtractFileName(Filename)+'" WHERE id='+IntToStr(id);
    Params := TParams.Create(nil);


    // BLOB
    MemoryStream := TMemoryStream.Create;
    MemoryStream.LoadFromFile(Filename); // load file to memory
    MemoryStream.Position := 0;
    Params.CreateParam(ftBlob, Fieldname, ptInput).LoadFromStream(MemoryStream, 15);  // 15 ftBlob (TBlobType)

    Form1.SQLConnection.Execute(sSQL, Params);

    MemoryStream.Free;
    Params.Free;
end;


  // использование процедуры
  SaveFileToDatabase('TableName', 'FieldName', 'd:\db 1.jpg', 1); // последний параметр это идентификатор записи  в таблице

Re: [Help] Syntax or data type problem

Here I leave you a project with what I want to do.  In the scripts there are commented lines, those comments correspond to things that I have no idea how to proceed.  It may be necessary to change the data type of the variables associated with the images.  If you could figure out how to load and save the images to and from the db in the objects of the 2 forms, it would be very helpful.

Post's attachments

Attachment icon Load and Save Data.zip 656.56 kb, 261 downloads since 2021-03-19 

Re: [Help] Syntax or data type problem

wenchester21 wrote:

Here I leave you a project with what I want to do.  In the scripts there are commented lines, those comments correspond to things that I have no idea how to proceed.  It may be necessary to change the data type of the variables associated with the images.  If you could figure out how to load and save the images to and from the db in the objects of the 2 forms, it would be very helpful.

HELP, HELP ☝️☝️☝️☝️☝️☝️☝️

Re: [Help] Syntax or data type problem

Just a quick question, if you are wanting to save the image to the database, why aren't you using the dbImage component?

Using this would make your life much easier.

On a clear disk you can seek forever

Re: [Help] Syntax or data type problem

I totally agree with CDB. It seems you are making this more difficult than it really should be. See attached. You can accomplish what you want with very little script. And the only reason for the script is because of the awkward setup of the forms. I did make an assumption and that is there will only be one record in this table. If there is going to be more than one record then your forms will need to change to accommodate such.

Post's attachments

Attachment icon Load and Save Data Revised.zip 676.23 kb, 281 downloads since 2021-03-25 

Re: [Help] Syntax or data type problem

CDB wrote:

Just a quick question, if you are wanting to save the image to the database, why aren't you using the dbImage component?

Using this would make your life much easier.

I have never used this component with scripts, so advanced actions with it become difficult, but it is all a matter of study and looking at some examples. Thanks brother

Re: [Help] Syntax or data type problem

ehwagner wrote:

I totally agree with CDB. It seems you are making this more difficult than it really should be. See attached. You can accomplish what you want with very little script. And the only reason for the script is because of the awkward setup of the forms. I did make an assumption and that is there will only be one record in this table. If there is going to be more than one record then your forms will need to change to accommodate such.

I will review and tell you later, thanks for taking a look.