Make a MySQL query from Inno Setup

2

I'm doing an installer, which needs to send a query at the end of the installation and after mounting the sMySQL service. I have no idea how this is done, this would be in the CODE section in PascalScript.

Once the installation is finished, an XML is accessed to load them at a pair of ListBox , by having them selected we send the data (which includes Country, Currency and some others). Previously it was done through JAVA with IzPack , with the following code.

    String insert = "INSERT INTO 'simarin'.'moneda' ('mon_id', 'moneda', 'abr', 'tipoCambio', 'singPlur', 'caracter','mn' ,'img16', 'img24', 'img32', 'status') "
            + "VALUES (" + ((isPrincipal) ? "1" : "null") + ", '" + de.getName() + "', '" + de.getWSMoneda().getAbr() + "', " + convert(a.getWSMoneda(), de.getWSMoneda()) + " "
            + ", '" + de.getWSMoneda().getSingPlur() + "', '" + de.getWSMoneda().getCaracter()
            + "'," + (isPrincipal ? 1 : 0) + " ,?, ?, ?, 1);";

    PreparedStatement pse = conn.prepareStatement(insert);
    pse.setBlob(1, b16);
    pse.setBlob(2, b24);
    pse.setBlob(3, b32);
    pse.execute();

It's the code that was passed to me to translate it to Inno Setup but I have no idea how to do it. Does anyone know what it would be like?

    
asked by Angel Montes de Oca 31.05.2017 в 00:26
source

1 answer

1

The solution I found was to create a script SQL :

function Create_Insertar_MonedasSQL(): boolean;
var
  rutaApp, fileName : string;
  lines : TArrayOfString;                       

begin
  rutaApp := ExpandConstant('{app}');
  Result := true;
  fileName := rutaApp+'\scripts\insertar-monedas.sql';
  SetArrayLength(lines, 2);
  lines[0] := 'INSERT INTO 'xxn'.'moneda' ('mon_id', 'moneda', 'abr', 'tipoCambio', 'singPlur', 'caracter','mn' ,'img16', 'img24', 'img32', 'status')';
  lines[1] := 'VALUES (1,"'+moneda+'","'+abr+'",'+tipoCambio+',"'+singPlur+'","'+caracter+'",'+mn+',0x'+img16b+',0x'+img24b+',0x'+img32b+','+status+');'; 
  Result := SaveStringsToFile(filename,lines,false);
  exit;
end;

Then create a bat to execute the script:

function Create_Insertar_MonedasBAT(): boolean;
var
  rutaApp, fileName : string;
  lines : TArrayOfString;                       

begin
  rutaApp := ExpandConstant('{app}');
  Result := true;
  fileName := rutaApp+'\scripts\insertar-monedas.bat';
  SetArrayLength(lines, 3);
  lines[0] := '@ECHO OFF';
  lines[1] := 'ECHO Insertando Datos...'; 
  lines[2] := '"'+rutaApp+'\MySQL\MySQL Server 5.5\bin\mysql.exe" -u root --password='+fieldPassword.text+' -P '+fieldPuerto.text+' < "'+rutaApp+'\scripts\insertar-monedas.sql"';    
  Result := SaveStringsToFile(filename,lines,false);
  exit;
end;

We call this all in NextButtonClick

if (CurPageID = Pagina) then
  begin
    Create_Insertar_MonedasSQL();
    Create_Insertar_MonedasBAT();
    Exec(ExpandConstant('{app}\scripts\insertar-monedas.bat'), '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode1);

    if (ResultCode1 <> 0)then
          MsgBox('Error al insertar moneda'+#13#10+'consulte al servicio técnico', mbError, MB_OK);   

end;  
    
answered by 21.07.2017 / 18:08
source