Usually in PHP when I need to insert a record in an SQL table I check first the primary key value to avoid to get an error for duplicate key entry.
I'm uploading a .dbf file to a SQL table. The .dbf has values there exist in the SQL table. I'm using the AddNew() and Update() Method but on having tried to insert a duplicate value into the SQL table I get an error of course.
How can I check the value before the insert sentence?
This is my code
Code: Select all
do while !cSource->( Eof() )
// cSQLCommand := "SELECT * FROM FPPtoNom WHERE PtoNomCod=" + bTrans( AllTrim( cSource->PtoNomCod ) )
// if oCursor:Open( cSQLCommand, oSQL:oConexion:oConnection ) .and. oCursor:oRs:RecordCount = 0
oCursor:oRs:AddNew()
oCursor:oRs:fields("PtoNomCod"):value := AllTrim( cSource->PtoNomCod )
oCursor:oRs:fields("PtoNomAbr"):value := AllTrim( cSource->PtoNomAbr )
oCursor:oRs:fields("PtoNomDes"):value := AllTrim( cSource->PtoNomDes )
oCursor:oRs:fields("PtoNomtip"):value := AllTrim( cSource->PtoNomTip )
oCursor:oRs:Update()
// endif
cSource->( dBSkip() )
enddo
Thanks