No announcement yet.

Error in loop inserting records. Strange code generation

  • Filter
  • Time
  • Show
Clear All
new posts

  • Error in loop inserting records. Strange code generation

    Hi all,

    I have to call to Mulder and Scully from X Files because I don't understand.

    I have a blank app with this code.
    PHP Code:
    $n 1;
    $query "INSERT INTO tpvproducto(nombreProducto, departamentoProducto, codigoBarras, refProducto, stockTeorico, iva, guuid) VALUES ('" .$nombreProducto."',".$departamentoProducto.",".$codigoBarras.",".$refProducto.",".$stockTeorico.",".$iva.",'".$guuid."')";
    $query.$n \n";
    If I execute, it's echo 487 inserts on screen. All ok.

    If I uncomment sc_exec_sql sentence, It start to work, until an error appears on screen.

    INSERT INTO tpvproducto(nombreProducto, departamentoProducto, codigoBarras, refProducto, stockTeorico, iva, guuid) VALUES ('SALON ANIMAL PR','ff80808149379c060149385f33d40030',null,'ZAP',0,21,'40288041493e8e0501494232397502f8') 1
    Se produjo un error al acceder a la base de datos
    Duplicate entry 'ZAP' for key 'refProducto'
    Obviously, I throw the process on an empty table, and if you see on SQL (last number) n is equal 1, this means is the first "row". But script inserted 25 records inserted on the table, this record included, for this reason is failing. Why the hell is suppose it's starting to process it again?

    I don't know if it's related, but code generated is like this:
    PHP Code:
    1012|     echo $query.$n \n";
    1014|     $n++;
    1016|     // Code below is what SC generates for sc_exec_sql
    1017|      $nm_select $query
    1018|          $_SESSION['scriptcase']['sc_sql_ult_comando'] = $nm_select;
    1019|       $_SESSION['scriptcase']['sc_sql_ult_conexao'] = ''
    1020|          $rf $this->Db->Execute($nm_select);
    1021|          if ($rf === false)
    1022|          {
    1023|              $this->Erro->mensagem (__FILE____LINE__"banco"$this->Ini->Nm_lang['lang_errm_dber'], $this->Db->ErrorMsg());
    1024|              if ($this->Ini->sc_tem_trans_banco)
    1025|              {
    1026|                  $this->Db->RollbackTrans(); 
    1027|                  $this->Ini->sc_tem_trans_banco false;
    1028|              }
    1029|              exit;
    1030|          }
    1031|          $rf->Close();
    1032|       ;
    1033| } 
    Line 1032.

    Some idea? I tried on a new blank app with the same situation.

    Don't know if there is something I'm not doing right, or maybe it's an annoying bug.


    Professional Scriptcase Services
    Some Customers opinions

  • #2
    Looks like a generation bug. Looks like that floating ";" is either missing code that is supposed to be there, or it's superfluous (or meant to be a "}" ).

    Out of curiosity what happens if, in the generated code, you either delete the floating ";" - or replace it with a "}" ?


    • #3
      Didn't tried, but don't seems to refer to anything. If I delete sc_exec_sql sentence, code between 1017 and 1032 lines, disppears. I mean, this is the code is generating.

      This file is an import procedure. I tried with just the code pasted, on a new blank, and it failed too, but in original import file, I have the same way to import other files, and works as expected, and code generated for sc_exec_sql is the same.

      Professional Scriptcase Services
      Some Customers opinions


      • #4
        hey gui:

        Actually I think the problem is another, have you tried to do it not using a while?... using something like a foreach?.

        If my theory is correct, you are not getting to the EOF line and the file pointer is going back to the top or something like that.