$?
is usually a multiple of 256. See perldoc -f system
(though this applies to assignment of $?
after backticks and wait
as well).
The exit
(and POSIX::_exit
) functions expect input on the range 0 to 255 -- this is an operating system convention, not a limitation of Perl. If you pass an argument outside that range, Perl or the operating system will treat it as if you called exit($arg % 256)
.
So I think what is happening is that hana sql makes the system call to exit
with the sql error code. This error code is typically greater than 255, so the exit code that gets propogated back to the operating system is hana error code % 256
.
When Perl receives this error code and assigns a value to $?
, it multiplies that value by 256 (as described in perldoc -f system
), so the relationship between the hana sql code and $?
is probably something like:
$? = (<hana-sql-code> % 256) * 256
or more pedantically
$? = (<hana-sql-code> & 255) << 8