[Core] ODBC: Add odbc-skip-autocommit-flip switch param.

This commit is contained in:
Andrey Volk 2022-08-25 20:14:47 +03:00
parent a8dee4b2ff
commit a1d2f83104
4 changed files with 19 additions and 0 deletions

View File

@ -184,6 +184,9 @@
<!-- <param name="core-db-dsn" value="postgresql://freeswitch:@127.0.0.1/freeswitch?options=-c%20client_min_messages%3DNOTICE" /> --> <!-- <param name="core-db-dsn" value="postgresql://freeswitch:@127.0.0.1/freeswitch?options=-c%20client_min_messages%3DNOTICE" /> -->
<!-- <param name="core-db-dsn" value="mariadb://Server=localhost;Database=freeswitch;Uid=freeswitch;Pwd=pass;" /> --> <!-- <param name="core-db-dsn" value="mariadb://Server=localhost;Database=freeswitch;Uid=freeswitch;Pwd=pass;" /> -->
<!-- <param name="core-db-dsn" value="dsn:username:password" /> --> <!-- <param name="core-db-dsn" value="dsn:username:password" /> -->
<!-- <param name="odbc-skip-autocommit-flip" value="true" /> -->
<!-- <!--
Allow to specify the sqlite db at a different location (In this example, move it to ramdrive for Allow to specify the sqlite db at a different location (In this example, move it to ramdrive for
better performance on most linux distro (note, you loose the data if you reboot)) better performance on most linux distro (note, you loose the data if you reboot))

View File

@ -51,6 +51,7 @@ typedef enum {
SWITCH_ODBC_FAIL = -1 SWITCH_ODBC_FAIL = -1
} switch_odbc_status_t; } switch_odbc_status_t;
SWITCH_DECLARE(void) switch_odbc_skip_autocommit_flip();
SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(const char *dsn, const char *username, const char *password); SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(const char *dsn, const char *username, const char *password);
SWITCH_DECLARE(void) switch_odbc_set_num_retries(switch_odbc_handle_t *handle, int num_retries); SWITCH_DECLARE(void) switch_odbc_set_num_retries(switch_odbc_handle_t *handle, int num_retries);
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_disconnect(switch_odbc_handle_t *handle); SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_disconnect(switch_odbc_handle_t *handle);

View File

@ -2172,6 +2172,10 @@ static void switch_load_core_config(const char *file)
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "max-db-handles must be between 5 and 5000\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "max-db-handles must be between 5 and 5000\n");
} }
} else if (!strcasecmp(var, "odbc-skip-autocommit-flip")) {
if (switch_true(val)) {
switch_odbc_skip_autocommit_flip();
}
} else if (!strcasecmp(var, "db-handle-timeout")) { } else if (!strcasecmp(var, "db-handle-timeout")) {
long tmp = atol(val); long tmp = atol(val);

View File

@ -62,6 +62,13 @@ struct switch_odbc_handle {
}; };
#endif #endif
uint8_t skip_autocommit_flip = 0;
SWITCH_DECLARE(void) switch_odbc_skip_autocommit_flip()
{
skip_autocommit_flip = 1;
}
SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(const char *dsn, const char *username, const char *password) SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(const char *dsn, const char *username, const char *password)
{ {
#ifdef SWITCH_HAVE_ODBC #ifdef SWITCH_HAVE_ODBC
@ -811,6 +818,10 @@ SWITCH_DECLARE(switch_bool_t) switch_odbc_available(void)
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_SQLSetAutoCommitAttr(switch_odbc_handle_t *handle, switch_bool_t on) SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_SQLSetAutoCommitAttr(switch_odbc_handle_t *handle, switch_bool_t on)
{ {
#ifdef SWITCH_HAVE_ODBC #ifdef SWITCH_HAVE_ODBC
if (skip_autocommit_flip) {
return SWITCH_ODBC_SUCCESS;
}
if (on) { if (on) {
return SQLSetConnectAttr(handle->con, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER *) SQL_AUTOCOMMIT_ON, 0 ); return SQLSetConnectAttr(handle->con, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER *) SQL_AUTOCOMMIT_ON, 0 );
} else { } else {