Expected Behavior of deleteAllRecords()

Hi,
What is the expected behavior of deleteAllRecords() if there are no records in the foundset to delete?.. Should I get a java.lang.NullPointerException error?.

I have the following, I can easily check for records before deleting, but am curious why the same code in version 5.2 gave no error but since upgrading to 7.3 I have a Error…

var vFs = databaseManager.getFoundSet(Server, Table)
vFs.loadAllRecords()
	
if(vFs.find()){
	vFs.user_uuid = userUID
	vFs.search()
}
	
vFs.deleteAllRecords()

Thanks

Hi Philip,

Aside of your observation : Are you aware of the fact that if the vFS.find() should fail all the records
of Table would / could be deleted ?

Regards,

Hi Lambert,

Thanks, yes I meant for it to be… :-)

var vFs = databaseManager.getFoundSet(Server, Table)
vFs.loadAllRecords()

if(vFs.find()){
vFs.user_uuid = userUID
vFs.search()
vFs.deleteAllRecords()
}

Why not write it like this:

var vFs = databaseManager.getFoundSet(Server, Table);
vFs.loadAllRecords();

if(vFs.find()){
    vFs.user_uuid = userUID;
    vFs.search();
    if (vFS.getSize() > 0 && vFS.user_uuid === userUID){
        vFs.deleteAllRecords();
    }
}

That way, you are only deleting records if there are any, and if they explicitly match your search criteria.

A couple of other observations:

  • Using “===” instead of “==” ensures and exact match and avoids javascript coercion (tries to convert it into a suitable type). In JavaScript world, coercion is considered a sort of evil and can produce unexpected results. Maybe not necessary when checking a uuid, but consider that if(false == 0), if(true == 1) and if(1 == “1”) are all true because of coercion, but if(false === 0), if(true === 1) and if(1 === “1”) are all false. Just a good habit to get into and avoid unexpected results in the future.
  • Always end your statements with the “;”, otherwise Javascript will use automatic insertion where it guesses the semi-colon should go. Again, you can get unexpected results that are hard to track down. Good habits avoid headaches.

More tips in my tutorials at my website if you are interested.

Hi Philip,

If you’re getting a NullPointer exception, that is definitely a bug in Servoy. could you file a case for that in our support system?

Paul