I have an amazing problem with postgresql
foreign key. I have postgresql 7.1.
that's my problem :
I have a table which contains a foreign key.
When I want to insert into this table I have a foreign key error that tells me that the values don't exists into the another table. But I'm sure that they exist. MOreover, I haven't got this error for all values (however i don't use special caracters only a-zéè).
There is what the serveur send to me :
(I have had comments)
--------------------------------------------
//this is the parameter's value transmit to the function
the school name: mon établissement -- the town : vannes
// I make a test to be sure that the value exist
the test sql request: select * from etablissement where e_libelle='mon établissement' AND e_localite='vannes'
// It exists since I have the third value of the etablissement table (ubs)
res test :: mon établissement -- vannes -- ubs
// and there is no error
tst error ::
// That's the request I want to do
// (the values (mon établissement, vannes) are the same since it's the same function)
the SQL request :
INSERT INTO RDipEta VALUES (222, 113, 0, 'A', 'BB', 'mon établissement', 'vannes', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, '');
// that's the error i receive
the generated error :ERROR: fkrde_etablissementkey_ins referential integrity violation - key referenced from rdipeta not found in etablissement
--------------------------------------------
!! BUT the first request make sure that the reference exist !!!
What does it means...
There the function I talk about :
------------------------------------------
function insertRelationDiplomeEtablissement($Rde_NivCod, $Rde_GroupCod, $Rde_ForNum, $Rde_LettreCod, $Rde_TypeForCod, $Rde_Mot, $Rde_Localite, $Rde_FInitiale, $Rde_FContinue, $Rde_TPlein, $Rde_Correspondance, $Rde_Apprentissage, $Rde_Alternance, $Rde_Qualification, $Rde_Autre) {
GLOBAL $DB, $q;
// The parameters
print("the school name: $Rde_Mot -- the town : $Rde_Localite<BR>"
// test if the school exists into the etablissement table
$tst = "select * from etablissement where e_libelle='$Rde_Mot' AND e_localite='$Rde_Localite'";
print("the test sql request: $tst <BR>"
$q = new query($DB,$tst);
$tst = $q->getrow();
// print the result of the test (it works good since i have the structure ratchment, the third value)
print("res test :: $tst[0] -- $tst[1] -- $tst[2]<BR>"
// print the error of the test
print("tst error :: ".$q->error()."<BR>"
// the query that I want execute
$sSQL = "INSERT INTO RDipEta VALUES
($Rde_NivCod, $Rde_GroupCod, $Rde_ForNum, '$Rde_LettreCod', '$Rde_TypeForCod', '$Rde_Mot', '$Rde_Localite', $Rde_FInitiale, $Rde_FContinue, $Rde_TPlein, $Rde_Correspondance, $Rde_Apprentissage, $Rde_Alternance, $Rde_Qualification, '$Rde_Autre');";
$q = new query($DB, $sSQL);
print("the SQL request : <BR>$sSQL<BR>"
print("the generated error :".$q->error()."<BR>"
return $q;
}
---------------------------------------------
More over sometimes it work :
(there are values with wich it works and another with wich it doesn't work...)
ex :
--------------------------------------------
the school name: l\'établissement -- the town : vannes
the test sql request: select * from etablissement where e_libelle='l\'établissement' AND e_localite='vannes'
res test :: l'établissement -- vannes -- ubs
tst error ::
the SQL request :
INSERT INTO RDipEta VALUES (222, 113, 0, 'A', 'BB', 'l\'établissement', 'vannes', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, '');
// There is no error !!!
the generated error :
---------------------------------------------
foreign key. I have postgresql 7.1.
that's my problem :
I have a table which contains a foreign key.
When I want to insert into this table I have a foreign key error that tells me that the values don't exists into the another table. But I'm sure that they exist. MOreover, I haven't got this error for all values (however i don't use special caracters only a-zéè).
There is what the serveur send to me :
(I have had comments)
--------------------------------------------
//this is the parameter's value transmit to the function
the school name: mon établissement -- the town : vannes
// I make a test to be sure that the value exist
the test sql request: select * from etablissement where e_libelle='mon établissement' AND e_localite='vannes'
// It exists since I have the third value of the etablissement table (ubs)
res test :: mon établissement -- vannes -- ubs
// and there is no error
tst error ::
// That's the request I want to do
// (the values (mon établissement, vannes) are the same since it's the same function)
the SQL request :
INSERT INTO RDipEta VALUES (222, 113, 0, 'A', 'BB', 'mon établissement', 'vannes', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, '');
// that's the error i receive
the generated error :ERROR: fkrde_etablissementkey_ins referential integrity violation - key referenced from rdipeta not found in etablissement
--------------------------------------------
!! BUT the first request make sure that the reference exist !!!
What does it means...
There the function I talk about :
------------------------------------------
function insertRelationDiplomeEtablissement($Rde_NivCod, $Rde_GroupCod, $Rde_ForNum, $Rde_LettreCod, $Rde_TypeForCod, $Rde_Mot, $Rde_Localite, $Rde_FInitiale, $Rde_FContinue, $Rde_TPlein, $Rde_Correspondance, $Rde_Apprentissage, $Rde_Alternance, $Rde_Qualification, $Rde_Autre) {
GLOBAL $DB, $q;
// The parameters
print("the school name: $Rde_Mot -- the town : $Rde_Localite<BR>"
// test if the school exists into the etablissement table
$tst = "select * from etablissement where e_libelle='$Rde_Mot' AND e_localite='$Rde_Localite'";
print("the test sql request: $tst <BR>"
$q = new query($DB,$tst);
$tst = $q->getrow();
// print the result of the test (it works good since i have the structure ratchment, the third value)
print("res test :: $tst[0] -- $tst[1] -- $tst[2]<BR>"
// print the error of the test
print("tst error :: ".$q->error()."<BR>"
// the query that I want execute
$sSQL = "INSERT INTO RDipEta VALUES
($Rde_NivCod, $Rde_GroupCod, $Rde_ForNum, '$Rde_LettreCod', '$Rde_TypeForCod', '$Rde_Mot', '$Rde_Localite', $Rde_FInitiale, $Rde_FContinue, $Rde_TPlein, $Rde_Correspondance, $Rde_Apprentissage, $Rde_Alternance, $Rde_Qualification, '$Rde_Autre');";
$q = new query($DB, $sSQL);
print("the SQL request : <BR>$sSQL<BR>"
print("the generated error :".$q->error()."<BR>"
return $q;
}
---------------------------------------------
More over sometimes it work :
(there are values with wich it works and another with wich it doesn't work...)
ex :
--------------------------------------------
the school name: l\'établissement -- the town : vannes
the test sql request: select * from etablissement where e_libelle='l\'établissement' AND e_localite='vannes'
res test :: l'établissement -- vannes -- ubs
tst error ::
the SQL request :
INSERT INTO RDipEta VALUES (222, 113, 0, 'A', 'BB', 'l\'établissement', 'vannes', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, '');
// There is no error !!!
the generated error :
---------------------------------------------