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.
$fichero=fopen("../kogestdata/PRODUCTO.csv", "r");
$n = 1;
while($linea=fgetcsv($fichero, 0, ";", '"')){
$nombreProducto=$linea[7];
$departamentoProducto=$linea[15];
if($departamentoProducto=="")$departamentoProducto="null";
else $departamentoProducto="'".$departamentoProducto."'";
$codigoBarras="null";
$refProducto=$linea[8];
if($refProducto=="")$refProducto="null";
else $refProducto="'".$refProducto."'";
$stockTeorico=0;
$iva=21;
$guuid=$linea[0];
$query = "INSERT INTO tpvproducto(nombreProducto, departamentoProducto, codigoBarras, refProducto, stockTeorico, iva, guuid) VALUES ('" .$nombreProducto."',".$departamentoProducto.",".$codigoBarras.",".$refProducto.",".$stockTeorico.",".$iva.",'".$guuid."')";
echo $query." $n
";
$n++;
sc_exec_sql($query);
}
fclose($fichero);
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
Error
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:
1012| echo $query." $n
";
1013|
1014| $n++;
1015|
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.
Regards.