diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 1414d518a2..89916b2a55 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -26,6 +26,7 @@ * Anthony Minessale II * Luke Dashjr (OpenMethods, LLC) * Joseph Sullivan + * Emmanuel Schmidbauer * * switch_core.h -- Core Library * @@ -2437,6 +2438,13 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle_dsn(switch_cache_ const char *file, const char *func, int line); #define switch_cache_db_get_db_handle_dsn(_a, _b) _switch_cache_db_get_db_handle_dsn(_a, _b, __FILE__, __SWITCH_FUNC__, __LINE__) +/*! + \brief Executes the create schema sql + \param [in] dbh The handle + \param [in] sql - sql to run + \param [out] err - Error if it exists +*/ +SWITCH_DECLARE(switch_status_t) switch_cache_db_create_schema(switch_cache_db_handle_t *dbh, char *sql, char **err); /*! \brief Executes the sql and returns the result as a string \param [in] dbh The handle diff --git a/src/mod/applications/mod_db/mod_db.c b/src/mod/applications/mod_db/mod_db.c index d0e9dd8931..bfaad70dc3 100644 --- a/src/mod/applications/mod_db/mod_db.c +++ b/src/mod/applications/mod_db/mod_db.c @@ -28,6 +28,7 @@ * Mathieu Rene * Bret McDanel * Rupa Schomaker + * Emmanuel Schmidbauer * * mod_db.c -- Implements simple db API, group support, and limit db backend * @@ -325,7 +326,7 @@ static switch_status_t do_config() switch_cache_db_test_reactive(dbh, "select * from group_data", NULL, group_sql); for (x = 0; indexes[x]; x++) { - switch_cache_db_execute_sql(dbh, indexes[x], NULL); + switch_cache_db_create_schema(dbh, indexes[x], NULL); } switch_cache_db_release_db_handle(&dbh); diff --git a/src/mod/applications/mod_voicemail/mod_voicemail.c b/src/mod/applications/mod_voicemail/mod_voicemail.c index 423f293a8b..2f5f1b950c 100644 --- a/src/mod/applications/mod_voicemail/mod_voicemail.c +++ b/src/mod/applications/mod_voicemail/mod_voicemail.c @@ -782,7 +782,7 @@ static vm_profile_t *load_profile(const char *profile_name) for (x = 0; vm_index_list[x]; x++) { errmsg = NULL; - switch_cache_db_execute_sql(dbh, vm_index_list[x], &errmsg); + switch_cache_db_create_schema(dbh, vm_index_list[x], &errmsg); switch_safe_free(errmsg); } diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 0aafd19789..c26c66740d 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -2271,7 +2271,7 @@ int sofia_glue_init_sql(sofia_profile_t *profile) free(test_sql); for (x = 0; indexes[x]; x++) { - switch_cache_db_execute_sql(dbh, indexes[x], NULL); + switch_cache_db_create_schema(dbh, indexes[x], NULL); } switch_cache_db_release_db_handle(&dbh); diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index 508b68643d..2a73aeb95a 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -26,6 +26,7 @@ * Anthony Minessale II * Michael Jerris * Paul D. Tinsley + * Emmanuel Schmidbauer * * * switch_core_sqldb.c -- Main Core Library (statistics tracker) @@ -1267,6 +1268,19 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback_err(switch_ return status; } +SWITCH_DECLARE(switch_status_t) switch_cache_db_create_schema(switch_cache_db_handle_t *dbh, char *sql, char **err) +{ + switch_status_t r = SWITCH_STATUS_SUCCESS; + + switch_assert(sql != NULL); + + if (switch_test_flag((&runtime), SCF_AUTO_SCHEMAS)) { + r = switch_cache_db_execute_sql(dbh, sql, err); + } + + return r; +} + /*! * \brief Performs test_sql and if it fails performs drop_sql and reactive_sql. * @@ -3399,10 +3413,10 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ switch_cache_db_test_reactive(sql_manager.dbh, "select hostname from recovery", "DROP TABLE recovery", recovery_sql); - switch_cache_db_execute_sql(sql_manager.dbh, "create index recovery1 on recovery(technology)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index recovery2 on recovery(profile_name)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index recovery3 on recovery(uuid)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index recovery3 on recovery(runtime_uuid)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index recovery1 on recovery(technology)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index recovery2 on recovery(profile_name)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index recovery3 on recovery(uuid)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index recovery3 on recovery(runtime_uuid)", NULL); @@ -3536,30 +3550,30 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_ switch_cache_db_execute_sql(sql_manager.dbh, sql, NULL); } - switch_cache_db_execute_sql(sql_manager.dbh, "create index alias1 on aliases (alias)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index tasks1 on tasks (hostname,task_id)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index complete1 on complete (a1,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index complete2 on complete (a2,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index complete3 on complete (a3,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index complete4 on complete (a4,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index complete5 on complete (a5,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index complete6 on complete (a6,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index complete7 on complete (a7,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index complete8 on complete (a8,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index complete9 on complete (a9,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index complete10 on complete (a10,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index complete11 on complete (a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index nat_map_port_proto on nat (port,proto,hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index channels1 on channels(hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index calls1 on calls(hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index chidx1 on channels (hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index uuindex on channels (uuid, hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index uuindex2 on channels (call_uuid)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index callsidx1 on calls (hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index eruuindex on calls (caller_uuid, hostname)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index eeuuindex on calls (callee_uuid)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index eeuuindex2 on calls (call_uuid)", NULL); - switch_cache_db_execute_sql(sql_manager.dbh, "create index regindex1 on registrations (reg_user,realm,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index alias1 on aliases (alias)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index tasks1 on tasks (hostname,task_id)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index complete1 on complete (a1,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index complete2 on complete (a2,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index complete3 on complete (a3,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index complete4 on complete (a4,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index complete5 on complete (a5,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index complete6 on complete (a6,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index complete7 on complete (a7,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index complete8 on complete (a8,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index complete9 on complete (a9,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index complete10 on complete (a10,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index complete11 on complete (a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index nat_map_port_proto on nat (port,proto,hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index channels1 on channels(hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index calls1 on calls(hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index chidx1 on channels (hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index uuindex on channels (uuid, hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index uuindex2 on channels (call_uuid)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index callsidx1 on calls (hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index eruuindex on calls (caller_uuid, hostname)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index eeuuindex on calls (callee_uuid)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index eeuuindex2 on calls (call_uuid)", NULL); + switch_cache_db_create_schema(sql_manager.dbh, "create index regindex1 on registrations (reg_user,realm,hostname)", NULL); skip: