Fix buffer overflow in sql error message buffer

Also use existing buffer when printing to stderr