diff --git a/src/mod/applications/mod_commands/mod_commands.c b/src/mod/applications/mod_commands/mod_commands.c index 4646473c75..6c43f25d44 100644 --- a/src/mod/applications/mod_commands/mod_commands.c +++ b/src/mod/applications/mod_commands/mod_commands.c @@ -3483,6 +3483,12 @@ SWITCH_STANDARD_API(show_function) char hostname[256] = ""; gethostname(hostname, sizeof(hostname)); + + if (!(cflags & SCF_USE_SQL)) { + stream->write_function(stream, "-ERR SQL DISABLED NO DATA AVAILABLE!\n"); + return SWITCH_STATUS_SUCCESS; + } + if (switch_core_db_handle(&db) != SWITCH_STATUS_SUCCESS) { stream->write_function(stream, "%s", "-ERR Databse Error!\n"); return SWITCH_STATUS_SUCCESS; @@ -3515,11 +3521,6 @@ SWITCH_STANDARD_API(show_function) holder.print_title = 1; - if (!(cflags & SCF_USE_SQL) && command && !strcasecmp(command, "channels")) { - stream->write_function(stream, "-ERR SQL DISABLED NO CHANNEL DATA AVAILABLE!\n"); - goto end; - } - /* If you change the field qty or order of any of these select */ /* statements, you must also change show_callback and friends to match! */ if (!command) { diff --git a/src/switch_console.c b/src/switch_console.c index 9f13823198..fdfb09bd80 100644 --- a/src/switch_console.c +++ b/src/switch_console.c @@ -238,9 +238,14 @@ SWITCH_DECLARE(char *) switch_console_expand_alias(char *cmd, char *arg) char *sql = NULL; char *exp = NULL; switch_cache_db_handle_t *db = NULL; + switch_core_flag_t cflags = switch_core_flags(); int full = 0; + if (!(cflags & SCF_USE_SQL)) { + return NULL; + } + if (switch_core_db_handle(&db) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Database Error\n"); return NULL; diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index a85766c60c..9551e5dea2 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -1590,6 +1590,8 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ top: + if (!sql_manager.manage) goto skip; + /* Activate SQL database */ if (switch_core_db_handle(&dbh) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n"); @@ -1707,6 +1709,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ switch_cache_db_execute_sql(dbh, "create index channels1 on channels(hostname)", NULL); switch_cache_db_execute_sql(dbh, "create index calls1 on calls(hostname)", NULL); + skip: if (sql_manager.manage) { if (switch_event_bind_removable("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, @@ -1729,7 +1732,7 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ switch_yield(10000); } - switch_cache_db_release_db_handle(&dbh); + if (sql_manager.manage) switch_cache_db_release_db_handle(&dbh); return SWITCH_STATUS_SUCCESS; }