afsql: the indexes() is a valid option. No parameter means that indexing is disabled

but the self->indexes should be non-NULL,
because it cause initializing error and syslog-ng will stop.
So if set_indexes get NULL it means, that the indexing is turned off.

Signed-off-by: Juhasz Viktor <jviktor@balabit.hu>
afsql: afsql_dd_insert_db() refactor

validate_table(): split into two functions:
  - validate_table(): do not generate table name, just validate
    [and create table if neccessary]
  - afsql_dd_ensure_accessible_database_table():
     - generate table name then calls new validate_table()
     - error handling when validation failed
     - return the generated table name

Extracting some functions like insert command generator, connection
setup and verification reveals several memory leaks around error
handling, e.g. in most cases, afsql_dd_insert_db() did not free the
GString it generated the insert command into.

Last, but not least, when transaction handling is enabled but an INSERT
command fails due to a lost connection, the backlog needs to be rewound,
otherwise all the messages since the last BEGIN command get lost.

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

Sequence_number was lost during reload, because afsql_dd_new is on called
every reload(). In order to keep seq.num after reload it should be add to
persist_config[afsql_dd_deinit()]

Note, that sequence number should start from 1, so extra check is
needed after seq_num is fetched[afsql_dd_init()] from persist_config
[and set to 1 if the fetched value is 0].

Signed-off-by: Juhasz Viktor <jviktor@balabit.hu>
afsql: sql destination init fix

The initialization of the afmongodb and sql destination fails if they have no queue

Signed-off-by: Juhasz Viktor <jviktor@balabit.hu>
afsql: not only columns and values, but indexes should also be specified

The same set of defaults will not work on all SQL databases, so it's
preferable to rely on the admin to specify values explicitly.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>