Rework SQL insert machanizm to handle SQL_BUSY better

- fix bug with SIG_PIPE killing daemon