afsql: afsql_dd_insert_db() refactor

A lot of the code that was previously in afsql_dd_insert_db() have been
extracted to smaller functions, and afsql_dd_insert_db() was rebuilt on
top of these. At the same time, memory leaks were plugged, and in case
of a transaction error, backlog rewinding has been fixed too, to not
loose messages since the last BEGIN command.

Signed-off-by: Juhasz Viktor <jviktor@balabit.hu>
Signed-off-by: Laszlo Budai <lbudai@balabit.hu>
afsql: afsql_dd_init() should fail without a queue

When log_dest_driver_acquire_queue() fails to acquire the queue,
afsql_dd_init() should fail too.

Signed-off-by: Juhasz Viktor <jviktor@balabit.hu>
Signed-off-by: Budai Laszlo <lbudai@balabit.hu>
afsql: sequence number handling corrected

Sequence numbering was restarted upon reload before, but with this
patch, the number gets stored in the persist config, and read back from
there upon reload.

Signed-off-by: Juhasz Viktor <jviktor@balabit.hu>
Signed-off-by: Budai Laszlo <lbudai@balabit.hu>