avoid SQL error in case a user exists in a external directory but not in Joomla

This is the error experienced with the system LDAP plugin enabled
1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near ....
at line 3 SQL=INSERT INTO `xxxx_userlogin_tracking`
(`userid`,`username`,`ip`,`timestamp`) VALUES (,'xxxx','79.56.247.43',1417120661)

You can see that the userid is null.