In version 8 and later syntax (syntaxversion pragma,
here), the $ret.code,
$ret.token, and $ret.msg variables are set by
<sql> to the SQL result integer code, string token, and
readable message, respectively, for the current iteration of the
statement. These can be a more reliable way of checking
success/failure than checking $loop. See
here for details.