<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][15487] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=15487">15487</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-11-16 18:12:54 -0600 (Mon, 16 Nov 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>add support for running core-db over odbc</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcincludeprivateswitch_core_pvth">freeswitch/trunk/src/include/private/switch_core_pvt.h</a></li>
<li><a href="#freeswitchtrunksrcincludeswitch_coreh">freeswitch/trunk/src/include/switch_core.h</a></li>
<li><a href="#freeswitchtrunksrcincludeswitch_odbch">freeswitch/trunk/src/include/switch_odbc.h</a></li>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_cidlookupmod_cidlookupc">freeswitch/trunk/src/mod/applications/mod_cidlookup/mod_cidlookup.c</a></li>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_commandsmod_commandsc">freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c</a></li>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_dptoolsmod_dptoolsc">freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c</a></li>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_fifomod_fifoc">freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c</a></li>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_limitmod_limitc">freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c</a></li>
<li><a href="#freeswitchtrunksrcmodapplicationsmod_voicemailmod_voicemailc">freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiamod_sofiac">freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_gluec">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_regc">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_channelc">freeswitch/trunk/src/switch_channel.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_consolec">freeswitch/trunk/src/switch_console.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_corec">freeswitch/trunk/src/switch_core.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_core_dbc">freeswitch/trunk/src/switch_core_db.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_core_sqldbc">freeswitch/trunk/src/switch_core_sqldb.c</a></li>
<li><a href="#freeswitchtrunksrcswitch_odbcc">freeswitch/trunk/src/switch_odbc.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcincludeprivateswitch_core_pvth"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/private/switch_core_pvt.h (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/private/switch_core_pvt.h        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/include/private/switch_core_pvt.h        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -207,11 +207,14 @@
</span><span class="cx">         switch_frame_t dummy_cng_frame;
</span><span class="cx">         char dummy_data[5];
</span><span class="cx">         switch_bool_t colorize_console;
</span><ins>+        char *odbc_dsn;
+        char *odbc_user;
+        char *odbc_pass;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> extern struct switch_runtime runtime;
</span><span class="cx">
</span><del>-void switch_core_sqldb_start(switch_memory_pool_t *pool);
</del><ins>+switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_t manage);
</ins><span class="cx"> void switch_core_sqldb_stop(void);
</span><span class="cx"> void switch_core_session_init(switch_memory_pool_t *pool);
</span><span class="cx"> void switch_core_session_uninit(void);
</span></span></pre></div>
<a id="freeswitchtrunksrcincludeswitch_coreh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_core.h (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_core.h        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/include/switch_core.h        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -1415,6 +1415,7 @@
</span><span class="cx">
</span><span class="cx"> */
</span><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_core_db_persistant_execute(switch_core_db_t *db, char *sql, uint32_t retries);
</span><ins>+SWITCH_DECLARE(switch_status_t) switch_core_db_persistant_execute_trans(switch_core_db_t *db, char *sql, uint32_t retries);
</ins><span class="cx">
</span><span class="cx"> /*!
</span><span class="cx"> \brief perform a test query then perform a reactive query if the first one fails
</span><span class="lines">@@ -1425,12 +1426,6 @@
</span><span class="cx"> */
</span><span class="cx"> SWITCH_DECLARE(void) switch_core_db_test_reactive(switch_core_db_t *db, char *test_sql, char *drop_sql, char *reactive_sql);
</span><span class="cx">
</span><del>-#define SWITCH_CORE_DB "core"
-/*!
- \brief Open the default system database
-*/
-#define switch_core_db_handle() switch_core_db_open_file(SWITCH_CORE_DB)
-
</del><span class="cx"> ///\}
</span><span class="cx">
</span><span class="cx"> ///\defgroup Media File Functions
</span><span class="lines">@@ -1930,13 +1925,17 @@
</span><span class="cx"> } switch_cache_db_handle_t;
</span><span class="cx">
</span><span class="cx"> SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t **dbh);
</span><del>-SWITCH_DECLARE(switch_cache_db_handle_t *)switch_cache_db_get_db_handle(const char *db_name, const char *odbc_user, const char *odbc_pass);
-SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql);
</del><ins>+SWITCH_DECLARE(switch_status_t) switch_cache_db_get_db_handle(switch_cache_db_handle_t **dbh,
+                                                                                                                                                const char *db_name, const char *odbc_user, const char *odbc_pass);
+SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err);
</ins><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh, char *sql,
</span><del>-                                                                                                                                         switch_core_db_callback_func_t callback, void *pdata);
</del><ins>+                                                                                                                                         switch_core_db_callback_func_t callback, void *pdata, char **err);
</ins><span class="cx">
</span><ins>+SWITCH_DECLARE(switch_status_t)switch_core_db_handle(switch_cache_db_handle_t **dbh);
+SWITCH_DECLARE(void) switch_cache_db_test_reactive(switch_cache_db_handle_t *db, char *test_sql, char *drop_sql, char *reactive_sql);
+SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute(switch_cache_db_handle_t *dbh, char *sql, uint32_t retries);
+SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans(switch_cache_db_handle_t *dbh, char *sql, uint32_t retries);
</ins><span class="cx">
</span><del>-
</del><span class="cx"> SWITCH_END_EXTERN_C
</span><span class="cx"> #endif
</span><span class="cx"> /* For Emacs:
</span></span></pre></div>
<a id="freeswitchtrunksrcincludeswitch_odbch"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_odbc.h (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_odbc.h        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/include/switch_odbc.h        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -77,7 +77,7 @@
</span><span class="cx"> \note none
</span><span class="cx"> */
</span><span class="cx"> SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(const char *file, const char *func, int line, switch_odbc_handle_t *handle,
</span><del>-                                                                                                                                         char *sql, switch_core_db_callback_func_t callback, void *pdata);
</del><ins>+                                                                                                                                                         char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err);
</ins><span class="cx"> /*!
</span><span class="cx"> \brief Execute the sql query and issue a callback for each row returned
</span><span class="cx"> \param handle the ODBC handle
</span><span class="lines">@@ -87,9 +87,9 @@
</span><span class="cx"> \return SWITCH_STATUS_SUCCESS if the operation was successful
</span><span class="cx"> \note none
</span><span class="cx"> */
</span><del>-#define switch_odbc_handle_callback_exec(handle, sql, callback, pdata) \
</del><ins>+#define switch_odbc_handle_callback_exec(handle, sql, callback, pdata, err) \
</ins><span class="cx">                 switch_odbc_handle_callback_exec_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, \
</span><del>-                                                                                                 handle, sql, callback, pdata)
</del><ins>+                                                                                                 handle, sql, callback, pdata, err)
</ins><span class="cx">
</span><span class="cx">                                                                                                                                         
</span><span class="cx"> SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, switch_odbc_statement_handle_t stmt);
</span></span></pre></div>
<a id="freeswitchtrunksrcmodapplicationsmod_cidlookupmod_cidlookupc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_cidlookup/mod_cidlookup.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_cidlookup/mod_cidlookup.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/mod/applications/mod_cidlookup/mod_cidlookup.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -186,7 +186,7 @@
</span><span class="cx">         
</span><span class="cx">         switch_mutex_lock(globals.db_mutex);
</span><span class="cx">         if (globals.odbc_dsn) {
</span><del>-                if (switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata)
</del><ins>+                if (switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata, NULL)
</ins><span class="cx">                                 == SWITCH_ODBC_FAIL) {
</span><span class="cx">                         retval = SWITCH_FALSE;
</span><span class="cx">                 } else {
</span></span></pre></div>
<a id="freeswitchtrunksrcmodapplicationsmod_commandsmod_commandsc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -2914,7 +2914,7 @@
</span><span class="cx"> {
</span><span class="cx">         char sql[1024];
</span><span class="cx">         char *errmsg;
</span><del>-        switch_core_db_t *db;
</del><ins>+        switch_cache_db_handle_t *db;
</ins><span class="cx">         struct holder holder = { 0 };
</span><span class="cx">         int help = 0;
</span><span class="cx">         char *mydata = NULL, *argv[6] = { 0 };
</span><span class="lines">@@ -2923,7 +2923,7 @@
</span><span class="cx">         switch_core_flag_t cflags = switch_core_flags();
</span><span class="cx">         switch_status_t status = SWITCH_STATUS_SUCCESS;
</span><span class="cx">
</span><del>-        db = switch_core_db_handle();
</del><ins>+        switch_core_db_handle(&db);
</ins><span class="cx">         
</span><span class="cx">         holder.justcount = 0;
</span><span class="cx">         
</span><span class="lines">@@ -3090,7 +3090,7 @@
</span><span class="cx">                                 holder.delim = ",";
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><del>-                switch_core_db_exec(db, sql, show_callback, &holder, &errmsg);
</del><ins>+                switch_cache_db_execute_sql_callback(db, sql, show_callback, &holder, &errmsg);
</ins><span class="cx">                 if (holder.http) {
</span><span class="cx">                         holder.stream->write_function(holder.stream, "</table>");
</span><span class="cx">                 }
</span><span class="lines">@@ -3106,7 +3106,7 @@
</span><span class="cx">                         stream->write_function(stream, "\n%u total.\n", holder.count);
</span><span class="cx">                 }
</span><span class="cx">         } else if (!strcasecmp(as, "xml")) {
</span><del>-                switch_core_db_exec(db, sql, show_as_xml_callback, &holder, &errmsg);
</del><ins>+                switch_cache_db_execute_sql_callback(db, sql, show_as_xml_callback, &holder, &errmsg);
</ins><span class="cx">
</span><span class="cx">                 if (errmsg) {
</span><span class="cx">                         stream->write_function(stream, "-ERR SQL Error [%s]\n", errmsg);
</span><span class="lines">@@ -3141,7 +3141,7 @@
</span><span class="cx">         switch_safe_free(mydata);
</span><span class="cx">
</span><span class="cx">         if (db) {
</span><del>-                switch_core_db_close(db);
</del><ins>+                switch_cache_db_release_db_handle(&db);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         return status;
</span></span></pre></div>
<a id="freeswitchtrunksrcmodapplicationsmod_dptoolsmod_dptoolsc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -336,7 +336,7 @@
</span><span class="cx">                 switch_channel_t *channel = switch_core_session_get_channel(session);
</span><span class="cx">                 const char *require_group = switch_channel_get_variable(channel, "eavesdrop_require_group");
</span><span class="cx">                 if (!strcasecmp((char *) data, "all")) {
</span><del>-                        switch_core_db_t *db = switch_core_db_handle();
</del><ins>+                        switch_cache_db_handle_t *db = NULL;
</ins><span class="cx">                         char *errmsg = NULL;
</span><span class="cx">                         struct e_data e_data = { {0} };
</span><span class="cx">                         char *sql = switch_mprintf("select uuid from channels where uuid != '%q'", switch_core_session_get_uuid(session));
</span><span class="lines">@@ -347,12 +347,14 @@
</span><span class="cx">                         char terminator;
</span><span class="cx">                         switch_status_t status;
</span><span class="cx">
</span><ins>+                        switch_core_db_handle(&db);
+
</ins><span class="cx">                         while (switch_channel_ready(channel)) {
</span><span class="cx">                                 for (x = 0; x < MAX_SPY; x++) {
</span><span class="cx">                                         switch_safe_free(e_data.uuid_list[x]);
</span><span class="cx">                                 }
</span><span class="cx">                                 e_data.total = 0;
</span><del>-                                switch_core_db_exec(db, sql, e_callback, &e_data, &errmsg);
</del><ins>+                                switch_cache_db_execute_sql_callback(db, sql, e_callback, &e_data, &errmsg);
</ins><span class="cx">                                 if (errmsg) {
</span><span class="cx">                                         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Error: %s\n", errmsg);
</span><span class="cx">                                         switch_core_db_free(errmsg);
</span><span class="lines">@@ -393,7 +395,7 @@
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         free(sql);
</span><del>-                        switch_core_db_close(db);
</del><ins>+                        switch_cache_db_release_db_handle(&db);
</ins><span class="cx">
</span><span class="cx">                 } else {
</span><span class="cx">                         switch_ivr_eavesdrop_session(session, data, require_group, ED_DTMF);
</span></span></pre></div>
<a id="freeswitchtrunksrcmodapplicationsmod_fifomod_fifoc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -339,7 +339,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if (switch_odbc_available() && globals.odbc_dsn) {
</span><del>-                switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata);
</del><ins>+                switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata, NULL);
</ins><span class="cx">         } else {
</span><span class="cx">                 if (!(db = switch_core_db_open_file(globals.dbname))) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
</span></span></pre></div>
<a id="freeswitchtrunksrcmodapplicationsmod_limitmod_limitc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -138,7 +138,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if (switch_odbc_available() && globals.odbc_dsn) {
</span><del>-                switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata);
</del><ins>+                switch_odbc_handle_callback_exec(globals.master_odbc, sql, callback, pdata, NULL);
</ins><span class="cx">         } else {
</span><span class="cx">                 if (!(db = switch_core_db_open_file(globals.dbname))) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
</span></span></pre></div>
<a id="freeswitchtrunksrcmodapplicationsmod_voicemailmod_voicemailc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -201,7 +201,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if (switch_odbc_available() && profile->odbc_dsn) {
</span><del>-                switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
</del><ins>+                switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata, NULL);
</ins><span class="cx">         } else {
</span><span class="cx">                 if (!(db = switch_core_db_open_file(profile->dbname))) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiamod_sofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -2876,7 +2876,8 @@
</span><span class="cx">         switch_channel_t *nchannel;
</span><span class="cx">         char *host = NULL, *dest_to = NULL;
</span><span class="cx">         const char *hval = NULL;
</span><del>-
</del><ins>+        char *not_const = NULL;
+                
</ins><span class="cx">         *new_session = NULL;
</span><span class="cx">
</span><span class="cx">         if (!outbound_profile || zstr(outbound_profile->destination_number)) {
</span><span class="lines">@@ -3115,10 +3116,12 @@
</span><span class="cx">
</span><span class="cx">         caller_profile = switch_caller_profile_clone(nsession, outbound_profile);
</span><span class="cx">         
</span><del>-
</del><ins>+        
</ins><span class="cx">         caller_profile->destination_number = switch_sanitize_number(caller_profile->destination_number);
</span><del>-        caller_profile->caller_id_name = switch_sanitize_number((char *)caller_profile->caller_id_name);
-        caller_profile->caller_id_number = switch_sanitize_number((char *)caller_profile->caller_id_number);
</del><ins>+        not_const = (char *)caller_profile->caller_id_name;
+        caller_profile->caller_id_name = switch_sanitize_number(not_const);
+        not_const = (char *)caller_profile->caller_id_number;
+        caller_profile->caller_id_number = switch_sanitize_number(not_const);
</ins><span class="cx">         
</span><span class="cx">         //caller_profile->destination_number = switch_core_strdup(caller_profile->pool, dest_num);
</span><span class="cx">         switch_channel_set_caller_profile(nchannel, caller_profile);
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_gluec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -4008,12 +4008,14 @@
</span><span class="cx">                 if ((dbh = (sofia_cache_db_handle_t *) val)) {
</span><span class="cx">                         time_t diff = 0;
</span><span class="cx">
</span><del>-                        if (prune > 0 && prune > dbh->last_used) {
-                                diff = (time_t) prune - dbh->last_used;
-                        }
</del><ins>+                        if (prune > 0) {
+                                if (prune > dbh->last_used) {
+                                        diff = (time_t) prune - dbh->last_used;
+                                }
</ins><span class="cx">                         
</span><del>-                        if (diff < SQL_CACHE_TIMEOUT) {
-                                continue;
</del><ins>+                                if (diff < SQL_CACHE_TIMEOUT) {
+                                        continue;
+                                }
</ins><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         if (switch_mutex_trylock(dbh->mutex) == SWITCH_STATUS_SUCCESS) {
</span><span class="lines">@@ -4121,7 +4123,7 @@
</span><span class="cx">
</span><span class="cx">                 
</span><span class="cx">                 if (db) dbh->db = db; else dbh->odbc_dbh = odbc_dbh;
</span><del>-                switch_mutex_init(&dbh->mutex, SWITCH_MUTEX_NESTED, dbh->pool);
</del><ins>+                switch_mutex_init(&dbh->mutex, 0, dbh->pool);
</ins><span class="cx">                 switch_mutex_lock(dbh->mutex);
</span><span class="cx">
</span><span class="cx">                 switch_core_hash_insert(profile->db_hash, thread_str, dbh);
</span><span class="lines">@@ -4202,7 +4204,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx">         if (switch_odbc_available() && dbh->odbc_dbh) {
</span><del>-                switch_odbc_handle_callback_exec(dbh->odbc_dbh, sql, callback, pdata);
</del><ins>+                switch_odbc_handle_callback_exec(dbh->odbc_dbh, sql, callback, pdata, NULL);
</ins><span class="cx">         } else if (profile->odbc_dsn) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
</span><span class="cx">         } else {
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_regc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -1678,7 +1678,9 @@
</span><span class="cx">         if ((regtype == REG_REGISTER) && sofia_test_pflag(profile, PFLAG_CHECKUSER)) {
</span><span class="cx">                 if (zstr(username) || zstr(to_user) || strcasecmp(to_user, username)) {
</span><span class="cx">                         /* Names don't match, so fail */
</span><del>-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SIP username %s does not match auth username\n", switch_str_nil(to_user));
</del><ins>+                        if (profile->debug) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SIP username %s does not match auth username\n", switch_str_nil(to_user));
+                        }
</ins><span class="cx">                         goto end;
</span><span class="cx">                 }
</span><span class="cx">         }
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_channelc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_channel.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_channel.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/switch_channel.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -1403,7 +1403,8 @@
</span><span class="cx">         switch_caller_profile_t *caller_profile, *originator_caller_profile = NULL, *originatee_caller_profile = NULL;
</span><span class="cx">         switch_codec_implementation_t impl = {0};
</span><span class="cx">         char state_num[25];
</span><del>-
</del><ins>+        const char *v;
+        
</ins><span class="cx">         switch_mutex_lock(channel->profile_mutex);
</span><span class="cx">
</span><span class="cx">         if ((caller_profile = switch_channel_get_caller_profile(channel))) {
</span><span class="lines">@@ -1422,7 +1423,15 @@
</span><span class="cx">         switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Presence-Call-Direction",
</span><span class="cx">                                                                  channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
</span><span class="cx">
</span><ins>+        if ((v = switch_channel_get_variable(channel, "presence_id"))) {
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-ID", v);
+        }
</ins><span class="cx">
</span><ins>+        if ((v = switch_channel_get_variable(channel, "presence_data"))) {
+                switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Presence-Data", v);
+        }
+
+
</ins><span class="cx">         if (switch_channel_test_flag(channel, CF_ANSWERED)) {
</span><span class="cx">                 switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Answer-State", "answered");
</span><span class="cx">         } else if (switch_channel_test_flag(channel, CF_EARLY_MEDIA)) {
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_consolec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_console.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_console.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/switch_console.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -199,12 +199,15 @@
</span><span class="cx">         char *r = NULL;
</span><span class="cx">         char *sql = NULL;
</span><span class="cx">         char *exp = NULL;
</span><del>-        switch_core_db_t *db = switch_core_db_handle();
</del><ins>+        switch_cache_db_handle_t *db = NULL;
</ins><span class="cx">         int full = 0;
</span><span class="cx">
</span><ins>+
+        switch_core_db_handle(&db);
+
</ins><span class="cx">         sql = switch_mprintf("select command from aliases where alias='%q'", cmd);
</span><span class="cx">
</span><del>-        switch_core_db_exec(db, sql, alias_callback, &r, &errmsg);
</del><ins>+        switch_cache_db_execute_sql_callback(db, sql, alias_callback, &r, &errmsg);
</ins><span class="cx">
</span><span class="cx">         if (errmsg) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", sql, errmsg);
</span><span class="lines">@@ -216,7 +219,7 @@
</span><span class="cx">         if (!r) {
</span><span class="cx">                 sql = switch_mprintf("select command from aliases where alias='%q %q'", cmd, arg);
</span><span class="cx">
</span><del>-                switch_core_db_exec(db, sql, alias_callback, &r, &errmsg);
</del><ins>+                switch_cache_db_execute_sql_callback(db, sql, alias_callback, &r, &errmsg);
</ins><span class="cx">
</span><span class="cx">                 if (errmsg) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", sql, errmsg);
</span><span class="lines">@@ -240,7 +243,8 @@
</span><span class="cx">                 exp = cmd;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        switch_core_db_close(db);
</del><ins>+        switch_cache_db_release_db_handle(&db);
+
</ins><span class="cx">         return exp;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -524,7 +528,7 @@
</span><span class="cx">
</span><span class="cx"> static unsigned char complete(EditLine * el, int ch)
</span><span class="cx"> {
</span><del>-        switch_core_db_t *db = switch_core_db_handle();
</del><ins>+        switch_cache_db_handle_t *db = NULL;
</ins><span class="cx">         char *sql;
</span><span class="cx">         const LineInfo *lf = el_line(el);
</span><span class="cx">         char *dup = strdup(lf->buffer);
</span><span class="lines">@@ -534,6 +538,8 @@
</span><span class="cx">         struct helper h = { el };
</span><span class="cx">         unsigned char ret = CC_REDISPLAY;
</span><span class="cx">
</span><ins>+        switch_core_db_handle(&db);
+
</ins><span class="cx">         h.out = switch_core_get_console();
</span><span class="cx">
</span><span class="cx">         if ((p = strchr(buf, '\r')) || (p = strchr(buf, '\n'))) {
</span><span class="lines">@@ -560,12 +566,14 @@
</span><span class="cx">         fprintf(h.out, "\n\n");
</span><span class="cx">
</span><span class="cx">         if (h.words == 0) {
</span><del>-                sql = switch_mprintf("select distinct name from interfaces where type='api' and name like '%s%%' order by name", buf);
</del><ins>+                sql = switch_mprintf("select distinct name from interfaces where type='api' and name like '%q%%' and hostname='%q' order by name",
+                                                         buf, switch_core_get_variable("hostname"));
</ins><span class="cx">         } else {
</span><del>-                sql = switch_mprintf("select distinct uuid from channels where uuid like '%s%%' order by uuid", buf);
</del><ins>+                sql = switch_mprintf("select distinct uuid from channels where uuid like '%q%%' and hostname='%q' order by uuid",
+                                                         buf, switch_core_get_variable("hostname"));
</ins><span class="cx">         }
</span><span class="cx">
</span><del>-        switch_core_db_exec(db, sql, comp_callback, &h, &errmsg);
</del><ins>+        switch_cache_db_execute_sql_callback(db, sql, comp_callback, &h, &errmsg);
</ins><span class="cx">
</span><span class="cx">         if (errmsg) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", sql, errmsg);
</span><span class="lines">@@ -586,7 +594,8 @@
</span><span class="cx">                 argc = switch_separate_string(dupdup, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
</span><span class="cx">
</span><span class="cx">                 if (h.words == 0) {
</span><del>-                        stream.write_function(&stream, "select distinct a1 from complete where " "a1 not in (select name from interfaces) %s ", argc ? "and" : "");
</del><ins>+                        stream.write_function(&stream, "select distinct a1 from complete where " "a1 not in (select name from interfaces where hostname='%s') %s ",
+                                                                 switch_core_get_variable("hostname"), argc ? "and" : "");
</ins><span class="cx">                 } else {
</span><span class="cx">                         stream.write_function(&stream, "select distinct a%d from complete where ", h.words + 1);
</span><span class="cx">
</span><span class="lines">@@ -596,8 +605,10 @@
</span><span class="cx">                         stream.write_function(&stream, "(a%d = '' or a%d like '%s%%')%s", x + 1, x + 1, switch_str_nil(argv[x]), x == argc - 1 ? "" : " and ");
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-                switch_core_db_exec(db, stream.data, comp_callback, &h, &errmsg);
</del><ins>+                stream.write_function(&stream, " and hostname='%s'", switch_core_get_variable("hostname"));
</ins><span class="cx">
</span><ins>+                switch_cache_db_execute_sql_callback(db, stream.data, comp_callback, &h, &errmsg);
+
</ins><span class="cx">                 if (errmsg) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error [%s][%s]\n", (char *) stream.data, errmsg);
</span><span class="cx">                         free(errmsg);
</span><span class="lines">@@ -626,7 +637,7 @@
</span><span class="cx">         switch_safe_free(sql);
</span><span class="cx">         switch_safe_free(dup);
</span><span class="cx">
</span><del>-        switch_core_db_close(db);
</del><ins>+        switch_cache_db_release_db_handle(&db);
</ins><span class="cx">
</span><span class="cx">         return (ret);
</span><span class="cx"> }
</span><span class="lines">@@ -640,40 +651,44 @@
</span><span class="cx">
</span><span class="cx">         if (string && (mydata = strdup(string))) {
</span><span class="cx">                 if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))))) {
</span><del>-                        switch_core_db_t *db = switch_core_db_handle();
</del><ins>+                        switch_cache_db_handle_t *db = NULL;
</ins><span class="cx">                         switch_stream_handle_t mystream = { 0 };
</span><span class="cx">                         SWITCH_STANDARD_STREAM(mystream);
</span><span class="cx">
</span><del>-
</del><ins>+                        switch_core_db_handle(&db);
+                        
</ins><span class="cx">                         if (!strcasecmp(argv[0], "stickyadd")) {
</span><span class="cx">                                 mystream.write_function(&mystream, "insert into complete values (1,");
</span><span class="cx">                                 for (x = 0; x < 10; x++) {
</span><del>-                                        mystream.write_function(&mystream, "'%s'%s", switch_str_nil(argv[x + 1]), x == 9 ? ")" : ", ");
</del><ins>+                                        mystream.write_function(&mystream, "'%s', ", switch_str_nil(argv[x + 1]));
</ins><span class="cx">                                 }
</span><del>-                                switch_core_db_persistant_execute(db, mystream.data, 5);
</del><ins>+                                mystream.write_function(&mystream, " '%s')", switch_core_get_variable("hostname"));
+                                switch_cache_db_persistant_execute(db, mystream.data, 5);
</ins><span class="cx">                                 status = SWITCH_STATUS_SUCCESS;
</span><span class="cx">                         } else if (!strcasecmp(argv[0], "add")) {
</span><span class="cx">                                 mystream.write_function(&mystream, "insert into complete values (0,");
</span><span class="cx">                                 for (x = 0; x < 10; x++) {
</span><del>-                                        mystream.write_function(&mystream, "'%s'%s", switch_str_nil(argv[x + 1]), x == 9 ? ")" : ", ");
</del><ins>+                                        mystream.write_function(&mystream, "'%s', ", switch_str_nil(argv[x + 1]));
</ins><span class="cx">                                 }
</span><del>-                                switch_core_db_persistant_execute(db, mystream.data, 5);
</del><ins>+                                mystream.write_function(&mystream, " '%s')", switch_core_get_variable("hostname"));
+                                switch_cache_db_persistant_execute(db, mystream.data, 5);
</ins><span class="cx">                                 status = SWITCH_STATUS_SUCCESS;
</span><span class="cx">                         } else if (!strcasecmp(argv[0], "del")) {
</span><span class="cx">                                 char *what = argv[1];
</span><span class="cx">                                 if (!strcasecmp(what, "*")) {
</span><del>-                                        switch_core_db_persistant_execute(db, "delete from complete", 1);
</del><ins>+                                        switch_cache_db_persistant_execute(db, "delete from complete", 1);
</ins><span class="cx">                                 } else {
</span><span class="cx">                                         mystream.write_function(&mystream, "delete from complete where ");
</span><span class="cx">                                         for (x = 0; x < argc - 1; x++) {
</span><span class="cx">                                                 mystream.write_function(&mystream, "a%d = '%s'%s", x + 1, switch_str_nil(argv[x + 1]), x == argc - 2 ? "" : " and ");
</span><span class="cx">                                         }
</span><del>-                                        switch_core_db_persistant_execute(db, mystream.data, 1);
</del><ins>+                                        mystream.write_function(&mystream, " and hostname='%s'", switch_core_get_variable("hostname"));
+                                        switch_cache_db_persistant_execute(db, mystream.data, 1);
</ins><span class="cx">                                 }
</span><span class="cx">                                 status = SWITCH_STATUS_SUCCESS;
</span><span class="cx">                         }
</span><span class="cx">                         switch_safe_free(mystream.data);
</span><del>-                        switch_core_db_close(db);
</del><ins>+                        switch_cache_db_release_db_handle(&db);
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -692,36 +707,40 @@
</span><span class="cx">
</span><span class="cx">         if (string && (mydata = strdup(string))) {
</span><span class="cx">                 if ((argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) >= 2) {
</span><del>-                        switch_core_db_t *db = switch_core_db_handle();
</del><ins>+                        switch_cache_db_handle_t *db = NULL;
</ins><span class="cx">                         char *sql = NULL;
</span><span class="cx">
</span><ins>+                        switch_core_db_handle(&db);
</ins><span class="cx">
</span><span class="cx">                         if (!strcasecmp(argv[0], "stickyadd") && argc == 3) {
</span><del>-                                sql = switch_mprintf("delete from aliases where alias='%q'", argv[1]);
-                                switch_core_db_persistant_execute(db, sql, 5);
</del><ins>+                                sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_variable("hostname"));
+                                switch_cache_db_persistant_execute(db, sql, 5);
</ins><span class="cx">                                 switch_safe_free(sql);
</span><del>-                                sql = switch_mprintf("insert into aliases (sticky, alias, command) values (1, '%q','%q')", argv[1], argv[2]);
-                                switch_core_db_persistant_execute(db, sql, 5);
</del><ins>+                                sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (1, '%q','%q','%q')",
+                                                                         argv[1], argv[2], switch_core_get_variable("hostname"));
+                                switch_cache_db_persistant_execute(db, sql, 5);
</ins><span class="cx">                                 status = SWITCH_STATUS_SUCCESS;
</span><span class="cx">                         } else if (!strcasecmp(argv[0], "add") && argc == 3) {
</span><del>-                                sql = switch_mprintf("delete from aliases where alias='%q'", argv[1]);
-                                switch_core_db_persistant_execute(db, sql, 5);
</del><ins>+                                sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_variable("hostname"));
+                                switch_cache_db_persistant_execute(db, sql, 5);
</ins><span class="cx">                                 switch_safe_free(sql);
</span><del>-                                sql = switch_mprintf("insert into aliases (sticky, alias, command) values (0, '%q','%q')", argv[1], argv[2]);
-                                switch_core_db_persistant_execute(db, sql, 5);
</del><ins>+                                sql = switch_mprintf("insert into aliases (sticky, alias, command, hostname) values (0, '%q','%q')",
+                                                                         argv[1], argv[2], switch_core_get_variable("hostname"));
+                                switch_cache_db_persistant_execute(db, sql, 5);
</ins><span class="cx">                                 status = SWITCH_STATUS_SUCCESS;
</span><span class="cx">                         } else if (!strcasecmp(argv[0], "del") && argc == 2) {
</span><span class="cx">                                 char *what = argv[1];
</span><span class="cx">                                 if (!strcasecmp(what, "*")) {
</span><del>-                                        switch_core_db_persistant_execute(db, "delete from aliases", 1);
</del><ins>+                                        sql = switch_mprintf("delete from aliases where hostname='%q'", switch_core_get_variable("hostname"));
+                                        switch_cache_db_persistant_execute(db, sql, 1);
</ins><span class="cx">                                 } else {
</span><del>-                                        sql = switch_mprintf("delete from aliases where alias='%q'", argv[1]);
-                                        switch_core_db_persistant_execute(db, sql, 5);
</del><ins>+                                        sql = switch_mprintf("delete from aliases where alias='%q' and hostname='%q'", argv[1], switch_core_get_variable("hostname"));
+                                        switch_cache_db_persistant_execute(db, sql, 5);
</ins><span class="cx">                                 }
</span><span class="cx">                                 status = SWITCH_STATUS_SUCCESS;
</span><span class="cx">                         }
</span><span class="cx">                         switch_safe_free(sql);
</span><del>-                        switch_core_db_close(db);
</del><ins>+                        switch_cache_db_release_db_handle(&db);
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_corec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_core.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_core.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/switch_core.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -1282,9 +1282,10 @@
</span><span class="cx">
</span><span class="cx">         switch_core_state_machine_init(runtime.memory_pool);
</span><span class="cx">
</span><del>-        if (switch_test_flag((&runtime), SCF_USE_SQL)) {
-                switch_core_sqldb_start(runtime.memory_pool);
</del><ins>+        if (switch_core_sqldb_start(runtime.memory_pool, switch_test_flag((&runtime), SCF_USE_SQL) ? SWITCH_TRUE : SWITCH_FALSE) != SWITCH_STATUS_SUCCESS) {
+                abort();
</ins><span class="cx">         }
</span><ins>+
</ins><span class="cx">         switch_scheduler_task_thread_start();
</span><span class="cx">
</span><span class="cx">         switch_rtp_init(runtime.memory_pool);
</span><span class="lines">@@ -1422,6 +1423,18 @@
</span><span class="cx">                                         switch_rtp_set_start_port((switch_port_t) atoi(val));
</span><span class="cx">                                 } else if (!strcasecmp(var, "rtp-end-port") && !zstr(val)) {
</span><span class="cx">                                         switch_rtp_set_end_port((switch_port_t) atoi(val));
</span><ins>+                                } else if (!strcasecmp(var, "core-db-dsn") && !zstr(val)) {
+                                        if (switch_odbc_available()) {
+                                                runtime.odbc_dsn = switch_core_strdup(runtime.memory_pool, val);
+                                                if ((runtime.odbc_user = strchr(runtime.odbc_dsn, ':'))) {
+                                                        *runtime.odbc_user++ = '\0';
+                                                        if ((runtime.odbc_pass = strchr(runtime.odbc_user, ':'))) {
+                                                                *runtime.odbc_pass++ = '\0';
+                                                        }
+                                                }
+                                        } else {
+                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
+                                        }
</ins><span class="cx"> #ifdef ENABLE_ZRTP
</span><span class="cx">                                 } else if (!strcasecmp(var, "rtp-enable-zrtp")) {
</span><span class="cx">                                         switch_core_set_variable("zrtp_enabled", val);
</span><span class="lines">@@ -1446,7 +1459,20 @@
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#define SWITCH_CORE_DB "core"
+/*!
+ \brief Open the default system database
+*/
+SWITCH_DECLARE(switch_status_t)switch_core_db_handle(switch_cache_db_handle_t **dbh)
+{
+        if (runtime.odbc_dsn && runtime.odbc_user && runtime.odbc_pass) {
+                return switch_cache_db_get_db_handle(dbh, runtime.odbc_dsn, runtime.odbc_user, runtime.odbc_pass);
+        } else {
+                return switch_cache_db_get_db_handle(dbh, SWITCH_CORE_DB, NULL, NULL);
+        }
+}
</ins><span class="cx">
</span><ins>+
</ins><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_core_init_and_modload(switch_core_flag_t flags, switch_bool_t console, const char **err)
</span><span class="cx"> {
</span><span class="cx">         switch_event_t *event;
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_core_dbc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_core_db.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_core_db.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/switch_core_db.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -241,6 +241,111 @@
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+
+SWITCH_DECLARE(switch_status_t) switch_core_db_persistant_execute_trans(switch_core_db_t *db, char *sql, uint32_t retries)
+{
+        char *errmsg;
+        switch_status_t status = SWITCH_STATUS_FALSE;
+        uint8_t forever = 0;
+        unsigned begin_retries = 100;
+        uint8_t again = 0;
+
+        if (!retries) {
+                forever = 1;
+                retries = 1000;
+        }
+
+again:
+
+        while (begin_retries > 0) {
+                again = 0;
+
+                switch_core_db_exec(db, "BEGIN", NULL, NULL, &errmsg);
+
+                if (errmsg) {
+                        begin_retries--;
+                        if (strstr(errmsg, "cannot start a transaction within a transaction")) {
+                                again = 1;
+                        } else {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL Retry [%s]\n", errmsg);
+                        }
+                        switch_core_db_free(errmsg);
+                        errmsg = NULL;
+
+                        if (again) {
+                                switch_core_db_exec(db, "COMMIT", NULL, NULL, NULL);
+                                goto again;
+                        }
+
+                        switch_yield(100000);
+
+                        if (begin_retries == 0) {
+                                goto done;
+                        }
+                } else {
+                        break;
+                }
+
+        }
+
+        while (retries > 0) {
+                switch_core_db_exec(db, sql, NULL, NULL, &errmsg);
+                if (errmsg) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
+                        switch_core_db_free(errmsg);
+                        errmsg = NULL;
+                        switch_yield(100000);
+                        retries--;
+                        if (retries == 0 && forever) {
+                                retries = 1000;
+                                continue;
+                        }
+                } else {
+                        status = SWITCH_STATUS_SUCCESS;
+                        break;
+                }
+        }
+
+done:
+
+        switch_core_db_exec(db, "COMMIT", NULL, NULL, NULL);
+
+        return status;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_core_db_persistant_execute(switch_core_db_t *db, char *sql, uint32_t retries)
+{
+        char *errmsg;
+        switch_status_t status = SWITCH_STATUS_FALSE;
+        uint8_t forever = 0;
+
+        if (!retries) {
+                forever = 1;
+                retries = 1000;
+        }
+
+        while (retries > 0) {
+                switch_core_db_exec(db, sql, NULL, NULL, &errmsg);
+                if (errmsg) {
+                        //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
+                        switch_core_db_free(errmsg);
+                        switch_yield(100000);
+                        retries--;
+                        if (retries == 0 && forever) {
+                                retries = 1000;
+                                continue;
+                        }
+                } else {
+                        status = SWITCH_STATUS_SUCCESS;
+                        break;
+                }
+        }
+
+        return status;
+}
+
+
+
</ins><span class="cx"> /* For Emacs:
</span><span class="cx"> * Local Variables:
</span><span class="cx"> * mode:c
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_core_sqldbc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_core_sqldb.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_core_sqldb.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/switch_core_sqldb.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -36,13 +36,13 @@
</span><span class="cx"> #include "private/switch_core_pvt.h"
</span><span class="cx">
</span><span class="cx"> static struct {
</span><del>-        switch_core_db_t *db;
-        switch_core_db_t *event_db;
</del><ins>+        switch_cache_db_handle_t *event_db;
</ins><span class="cx">         switch_queue_t *sql_queue[2];
</span><span class="cx">         switch_memory_pool_t *memory_pool;
</span><span class="cx">         switch_event_node_t *event_node;
</span><span class="cx">         switch_thread_t *thread;
</span><span class="cx">         int thread_running;
</span><ins>+        switch_bool_t manage;
</ins><span class="cx"> } sql_manager;
</span><span class="cx">
</span><span class="cx"> static switch_mutex_t *dbh_mutex = NULL;
</span><span class="lines">@@ -58,7 +58,7 @@
</span><span class="cx">         switch_cache_db_handle_t *dbh = NULL;
</span><span class="cx">         int locked = 0;
</span><span class="cx">         char *key;
</span><del>-
</del><ins>+        
</ins><span class="cx">         switch_mutex_lock(dbh_mutex);
</span><span class="cx"> top:
</span><span class="cx">         locked = 0;
</span><span class="lines">@@ -74,11 +74,12 @@
</span><span class="cx">                                 diff = (time_t) prune - dbh->last_used;
</span><span class="cx">                         }
</span><span class="cx">                         
</span><del>-                        if (diff < SQL_CACHE_TIMEOUT) {
</del><ins>+                        if (prune > 0 && diff < SQL_CACHE_TIMEOUT) {
</ins><span class="cx">                                 continue;
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         if (switch_mutex_trylock(dbh->mutex) == SWITCH_STATUS_SUCCESS) {
</span><ins>+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Dropping idle DB connection %s\n", key);
</ins><span class="cx">                                 if (dbh->db) {
</span><span class="cx">                                         switch_core_db_close(dbh->db);
</span><span class="cx">                                         dbh->db = NULL;
</span><span class="lines">@@ -113,18 +114,19 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-SWITCH_DECLARE(switch_cache_db_handle_t *)switch_cache_db_get_db_handle(const char *db_name, const char *odbc_user, const char *odbc_pass)
</del><ins>+SWITCH_DECLARE(switch_status_t)switch_cache_db_get_db_handle(switch_cache_db_handle_t **dbh,
+                                                                                                                         const char *db_name, const char *odbc_user, const char *odbc_pass)
</ins><span class="cx"> {
</span><span class="cx">         switch_thread_id_t self = switch_thread_self();
</span><span class="cx">         char thread_str[256] = "";
</span><del>-        switch_cache_db_handle_t *dbh = NULL;
</del><ins>+        switch_cache_db_handle_t *new_dbh = NULL;
</ins><span class="cx">         
</span><span class="cx">         switch_assert(db_name);
</span><span class="cx">
</span><span class="cx">         snprintf(thread_str, sizeof(thread_str) - 1, "%s_%lu", db_name, (unsigned long)(intptr_t)self);
</span><span class="cx">
</span><span class="cx">         switch_mutex_lock(dbh_mutex);
</span><del>-        if (!(dbh = switch_core_hash_find(dbh_hash, thread_str))) {
</del><ins>+        if (!(new_dbh = switch_core_hash_find(dbh_hash, thread_str))) {
</ins><span class="cx">                 switch_memory_pool_t *pool = NULL;
</span><span class="cx">                 switch_core_db_t *db = NULL;
</span><span class="cx">                 switch_odbc_handle_t *odbc_dbh = NULL;
</span><span class="lines">@@ -145,83 +147,96 @@
</span><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 switch_core_new_memory_pool(&pool);
</span><del>-                dbh = switch_core_alloc(pool, sizeof(*dbh));
-                dbh->pool = pool;
</del><ins>+                new_dbh = switch_core_alloc(pool, sizeof(*new_dbh));
+                new_dbh->pool = pool;
</ins><span class="cx">
</span><span class="cx">                 
</span><del>-                if (db) dbh->db = db; else dbh->odbc_dbh = odbc_dbh;
-                switch_mutex_init(&dbh->mutex, SWITCH_MUTEX_NESTED, dbh->pool);
-                switch_mutex_lock(dbh->mutex);
</del><ins>+                if (db) new_dbh->db = db; else new_dbh->odbc_dbh = odbc_dbh;
+                switch_mutex_init(&new_dbh->mutex, 0, new_dbh->pool);
+                switch_mutex_lock(new_dbh->mutex);
</ins><span class="cx">
</span><del>-                switch_core_hash_insert(dbh_hash, thread_str, dbh);
</del><ins>+                switch_core_hash_insert(dbh_hash, thread_str, new_dbh);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx"> end:
</span><span class="cx">
</span><del>-        if (dbh) dbh->last_used = switch_epoch_time_now(NULL);
</del><ins>+        if (new_dbh) new_dbh->last_used = switch_epoch_time_now(NULL);
</ins><span class="cx">
</span><span class="cx">         switch_mutex_unlock(dbh_mutex);
</span><span class="cx">
</span><del>-        return dbh;
</del><ins>+        *dbh = new_dbh;
+
+        return *dbh ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_FALSE;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><del>-SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql)
</del><ins>+SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err)
</ins><span class="cx"> {
</span><span class="cx">         switch_status_t status = SWITCH_STATUS_FALSE;
</span><ins>+        char *errmsg = NULL;
</ins><span class="cx">
</span><ins>+        if (err) *err = NULL;
+
</ins><span class="cx">         if (switch_odbc_available() && dbh->odbc_dbh) {
</span><span class="cx">                 switch_odbc_statement_handle_t stmt;
</span><span class="cx">                 if ((status = switch_odbc_handle_exec(dbh->odbc_dbh, sql, &stmt)) != SWITCH_ODBC_SUCCESS) {
</span><del>-                        char *err_str;
-                        err_str = switch_odbc_handle_get_error(dbh->odbc_dbh, stmt);
-                        if (!zstr(err_str)) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, err_str);
-                        }
-                        switch_safe_free(err_str);
</del><ins>+                        errmsg = switch_odbc_handle_get_error(dbh->odbc_dbh, stmt);
</ins><span class="cx">                 }
</span><span class="cx">                 switch_odbc_statement_handle_free(&stmt);
</span><span class="cx">         } else {
</span><del>-                char *errmsg;
-
</del><span class="cx"> status = switch_core_db_exec(dbh->db, sql, NULL, NULL, &errmsg);
</span><ins>+        }
</ins><span class="cx">
</span><del>- if (errmsg) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n%s\n", errmsg, sql);
- switch_core_db_free(errmsg);
- }
-                
</del><ins>+        if (errmsg) {
+                if (!switch_stristr("already exists", errmsg)) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n%s\n", errmsg, sql);
+                }
+                if (err) {
+                        *err = errmsg;
+                } else {
+                        free(errmsg);
+                }
</ins><span class="cx">         }
</span><del>-
</del><ins>+        
</ins><span class="cx">         return status;
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><del>-SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh,
-                                                                                                                                         char *sql, switch_core_db_callback_func_t callback, void *pdata)
-        
</del><ins>+SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute(switch_cache_db_handle_t *dbh, char *sql, uint32_t retries)
</ins><span class="cx"> {
</span><ins>+        char *errmsg = NULL;
</ins><span class="cx">         switch_status_t status = SWITCH_STATUS_FALSE;
</span><del>-        char *errmsg = NULL;
-        
-        if (switch_odbc_available() && dbh->odbc_dbh) {
-                status = switch_odbc_handle_callback_exec(dbh->odbc_dbh, sql, callback, pdata);
-        } else {
-                status = switch_core_db_exec(dbh->db, sql, callback, pdata, &errmsg);
-                
</del><ins>+        uint8_t forever = 0;
+
+        if (!retries) {
+                forever = 1;
+                retries = 1000;
+        }
+
+        while (retries > 0) {
+                switch_cache_db_execute_sql(dbh, sql, &errmsg);
</ins><span class="cx">                 if (errmsg) {
</span><del>-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
-                        free(errmsg);
</del><ins>+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
+                        switch_safe_free(errmsg);
+                        switch_yield(100000);
+                        retries--;
+                        if (retries == 0 && forever) {
+                                retries = 1000;
+                                continue;
+                        }
+                } else {
+                        status = SWITCH_STATUS_SUCCESS;
+                        break;
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         return status;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static switch_status_t switch_core_db_persistant_execute_trans(switch_core_db_t *db, char *sql, uint32_t retries)
</del><ins>+SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans(switch_cache_db_handle_t *dbh, char *sql, uint32_t retries)
</ins><span class="cx"> {
</span><del>-        char *errmsg;
</del><ins>+        char *errmsg = NULL;
</ins><span class="cx">         switch_status_t status = SWITCH_STATUS_FALSE;
</span><span class="cx">         uint8_t forever = 0;
</span><span class="cx">         unsigned begin_retries = 100;
</span><span class="lines">@@ -237,7 +252,7 @@
</span><span class="cx">         while (begin_retries > 0) {
</span><span class="cx">                 again = 0;
</span><span class="cx">
</span><del>-                switch_core_db_exec(db, "BEGIN", NULL, NULL, &errmsg);
</del><ins>+                switch_cache_db_execute_sql(dbh, "BEGIN", &errmsg);
</ins><span class="cx">
</span><span class="cx">                 if (errmsg) {
</span><span class="cx">                         begin_retries--;
</span><span class="lines">@@ -246,11 +261,11 @@
</span><span class="cx">                         } else {
</span><span class="cx">                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL Retry [%s]\n", errmsg);
</span><span class="cx">                         }
</span><del>-                        switch_core_db_free(errmsg);
</del><ins>+                        free(errmsg);
</ins><span class="cx">                         errmsg = NULL;
</span><span class="cx">
</span><span class="cx">                         if (again) {
</span><del>-                                switch_core_db_exec(db, "COMMIT", NULL, NULL, NULL);
</del><ins>+                                switch_cache_db_execute_sql(dbh, "COMMIT", NULL);
</ins><span class="cx">                                 goto again;
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="lines">@@ -266,10 +281,10 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         while (retries > 0) {
</span><del>-                switch_core_db_exec(db, sql, NULL, NULL, &errmsg);
</del><ins>+                switch_cache_db_execute_sql(dbh, sql, &errmsg);
</ins><span class="cx">                 if (errmsg) {
</span><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
</span><del>-                        switch_core_db_free(errmsg);
</del><ins>+                        free(errmsg);
</ins><span class="cx">                         errmsg = NULL;
</span><span class="cx">                         switch_yield(100000);
</span><span class="cx">                         retries--;
</span><span class="lines">@@ -285,45 +300,70 @@
</span><span class="cx">
</span><span class="cx"> done:
</span><span class="cx">
</span><del>-        switch_core_db_exec(db, "COMMIT", NULL, NULL, NULL);
</del><ins>+        switch_cache_db_execute_sql(dbh, "COMMIT", NULL);
</ins><span class="cx">
</span><span class="cx">         return status;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-SWITCH_DECLARE(switch_status_t) switch_core_db_persistant_execute(switch_core_db_t *db, char *sql, uint32_t retries)
</del><ins>+SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh,
+                                                                                                                                         char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err)
+        
</ins><span class="cx"> {
</span><del>-        char *errmsg;
</del><span class="cx">         switch_status_t status = SWITCH_STATUS_FALSE;
</span><del>-        uint8_t forever = 0;
</del><ins>+        char *errmsg = NULL;
</ins><span class="cx">
</span><del>-        if (!retries) {
-                forever = 1;
-                retries = 1000;
-        }
</del><ins>+        if (err) *err = NULL;
</ins><span class="cx">
</span><del>-        while (retries > 0) {
-                switch_core_db_exec(db, sql, NULL, NULL, &errmsg);
</del><ins>+        if (switch_odbc_available() && dbh->odbc_dbh) {
+                status = switch_odbc_handle_callback_exec(dbh->odbc_dbh, sql, callback, pdata, err);
+        } else {
+                status = switch_core_db_exec(dbh->db, sql, callback, pdata, &errmsg);
+                
</ins><span class="cx">                 if (errmsg) {
</span><del>-                        //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", errmsg);
-                        switch_core_db_free(errmsg);
-                        switch_yield(100000);
-                        retries--;
-                        if (retries == 0 && forever) {
-                                retries = 1000;
-                                continue;
-                        }
-                } else {
-                        status = SWITCH_STATUS_SUCCESS;
-                        break;
</del><ins>+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
+                        free(errmsg);
</ins><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         return status;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+SWITCH_DECLARE(void) switch_cache_db_test_reactive(switch_cache_db_handle_t *dbh, char *test_sql, char *drop_sql, char *reactive_sql)
+{
+        char *errmsg;
</ins><span class="cx">
</span><ins>+        if (switch_odbc_available() && dbh->odbc_dbh) {
+                if (switch_odbc_handle_exec(dbh->odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
+                        switch_odbc_handle_exec(dbh->odbc_dbh, drop_sql, NULL);
+                        switch_odbc_handle_exec(dbh->odbc_dbh, reactive_sql, NULL);
+                }
+        } else if (dbh->db) {
+                if (test_sql) {
+                        switch_core_db_exec(dbh->db, test_sql, NULL, NULL, &errmsg);
</ins><span class="cx">
</span><ins>+                        if (errmsg) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\nAuto Generating Table!\n", errmsg, test_sql);
+                                switch_core_db_free(errmsg);
+                                errmsg = NULL;
+                                if (drop_sql) {
+                                        switch_core_db_exec(dbh->db, drop_sql, NULL, NULL, &errmsg);
+                                }
+                                if (errmsg) {
+                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql);
+                                        switch_core_db_free(errmsg);
+                                        errmsg = NULL;
+                                }
+                                switch_core_db_exec(dbh->db, reactive_sql, NULL, NULL, &errmsg);
+                                if (errmsg) {
+                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql);
+                                        switch_core_db_free(errmsg);
+                                        errmsg = NULL;
+                                }
+                        }
+                }
+        }
</ins><span class="cx">
</span><ins>+}
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -340,24 +380,34 @@
</span><span class="cx">         switch_size_t newlen;
</span><span class="cx">         int lc = 0;
</span><span class="cx">         uint32_t loops = 0, sec = 0;
</span><ins>+        uint32_t l1 = 1000;
</ins><span class="cx">
</span><span class="cx">         switch_assert(sqlbuf);
</span><span class="cx">
</span><ins>+        if (!sql_manager.manage) {
+                l1 = 10;
+        }
+
</ins><span class="cx">         if (!sql_manager.event_db) {
</span><del>-                sql_manager.event_db = switch_core_db_handle();
</del><ins>+                switch_core_db_handle(&sql_manager.event_db);
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         sql_manager.thread_running = 1;
</span><span class="cx">
</span><del>-        for (;;) {
-                if (++loops == 1000) {
</del><ins>+        while(sql_manager.thread_running == 1) {
+                if (++loops == l1) {
</ins><span class="cx">                         if (++sec == SQL_CACHE_TIMEOUT) {
</span><span class="cx">                                 sql_close(switch_epoch_time_now(NULL));
</span><span class="cx">                                 sec = 0;
</span><span class="cx">                         }
</span><span class="cx">                         loops = 0;
</span><span class="cx">                 }
</span><del>-
</del><ins>+                
+                if (!sql_manager.manage) {
+                        switch_yield(100000);
+                        continue;
+                }
+                
</ins><span class="cx">                 if (switch_queue_trypop(sql_manager.sql_queue[0], &pop) == SWITCH_STATUS_SUCCESS ||
</span><span class="cx">                         switch_queue_trypop(sql_manager.sql_queue[1], &pop) == SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                         sql = (char *) pop;
</span><span class="lines">@@ -396,7 +446,7 @@
</span><span class="cx">                 
</span><span class="cx">                 
</span><span class="cx">                 if (trans && ((itterations == target) || (nothing_in_queue && ++lc >= 500))) {
</span><del>-                        if (switch_core_db_persistant_execute_trans(sql_manager.event_db, sqlbuf, 100) != SWITCH_STATUS_SUCCESS) {
</del><ins>+                        if (switch_cache_db_persistant_execute_trans(sql_manager.event_db, sqlbuf, 100) != SWITCH_STATUS_SUCCESS) {
</ins><span class="cx">                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "SQL thread unable to commit transaction, records lost!\n");
</span><span class="cx">                         }
</span><span class="cx">                         itterations = 0;
</span><span class="lines">@@ -421,6 +471,9 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         free(sqlbuf);
</span><ins>+
+        sql_manager.thread_running = 0;
+
</ins><span class="cx">         return NULL;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -432,45 +485,65 @@
</span><span class="cx">
</span><span class="cx">         switch (event->event_id) {
</span><span class="cx">         case SWITCH_EVENT_ADD_SCHEDULE:
</span><del>-                sql = switch_mprintf("insert into tasks values('%q','%q','%q','%q')",
-                                                         switch_event_get_header_nil(event, "task-id"),
-                                                         switch_event_get_header_nil(event, "task-desc"),
-                                                         switch_event_get_header_nil(event, "task-group"),
-                                                         switch_event_get_header_nil(event, "task-sql_manager")
-                                                         );
</del><ins>+                {
+                        const char *id = switch_event_get_header(event, "task-id");
+                        const char *manager = switch_event_get_header(event, "task-sql_manager");
+                        
+                        if (id) {
+                                sql = switch_mprintf("insert into tasks values(%q,'%q','%q',%q, '%q')",
+                                                                         id,
+                                                                         switch_event_get_header_nil(event, "task-desc"),
+                                                                         switch_event_get_header_nil(event, "task-group"),
+                                                                         manager ? manager : "0",
+                                                                         switch_core_get_variable("hostname")
+                                                                         );
+                        }
+                }
</ins><span class="cx">                 break;
</span><span class="cx">         case SWITCH_EVENT_DEL_SCHEDULE:
</span><span class="cx">         case SWITCH_EVENT_EXE_SCHEDULE:
</span><del>-                sql = switch_mprintf("delete from tasks where task_id=%q", switch_event_get_header_nil(event, "task-id"));
</del><ins>+                sql = switch_mprintf("delete from tasks where task_id=%q and hostname='%q'",
+                                                         switch_event_get_header_nil(event, "task-id"), switch_core_get_variable("hostname"));
</ins><span class="cx">                 break;
</span><span class="cx">         case SWITCH_EVENT_RE_SCHEDULE:
</span><del>-                sql = switch_mprintf("update tasks set task_desc='%q',task_group='%q', task_sql_manager='%q' where task_id=%q",
-                                                         switch_event_get_header_nil(event, "task-desc"),
-                                                         switch_event_get_header_nil(event, "task-group"),
-                                                         switch_event_get_header_nil(event, "task-sql_manager"),
-                                                         switch_event_get_header_nil(event, "task-id"));
</del><ins>+                {
+                        const char *id = switch_event_get_header(event, "task-id");
+                        const char *manager = switch_event_get_header(event, "task-sql_manager");
+                
+                        if (id) {
+                                sql = switch_mprintf("update tasks set task_desc='%q',task_group='%q', task_sql_manager=%q where task_id=%q and hostname='%q'",
+                                                                         switch_event_get_header_nil(event, "task-desc"),
+                                                                         switch_event_get_header_nil(event, "task-group"),
+                                                                         manager ? manager : "0",
+                                                                         id, switch_core_get_variable("hostname"));
+                        }
+                }
</ins><span class="cx">                 break;
</span><span class="cx">         case SWITCH_EVENT_CHANNEL_DESTROY:
</span><del>-                sql = switch_mprintf("delete from channels where uuid='%q'", switch_event_get_header_nil(event, "unique-id"));
</del><ins>+                sql = switch_mprintf("delete from channels where uuid='%q' and hostname='%q'",
+                                                         switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
</ins><span class="cx">                 break;
</span><span class="cx">         case SWITCH_EVENT_CHANNEL_UUID:
</span><span class="cx">                 {
</span><span class="cx">                         sql = switch_mprintf(
</span><del>-                                                                 "update channels set uuid='%q' where uuid='%q';"
-                                                                 "update calls set caller_uuid='%q' where caller_uuid='%q';"
-                                                                 "update calls set callee_uuid='%q' where callee_uuid='%q'",
</del><ins>+                                                                 "update channels set uuid='%q' where uuid='%q' and hostname='%q';"
+                                                                 "update calls set caller_uuid='%q' where caller_uuid='%q' and hostname='%q';"
+                                                                 "update calls set callee_uuid='%q' where callee_uuid='%q' and hostname='%q'",
</ins><span class="cx">                                                                  switch_event_get_header_nil(event, "unique-id"),
</span><span class="cx">                                                                  switch_event_get_header_nil(event, "old-unique-id"),
</span><ins>+                                                                 switch_core_get_variable("hostname"),
</ins><span class="cx">                                                                  switch_event_get_header_nil(event, "unique-id"),
</span><span class="cx">                                                                  switch_event_get_header_nil(event, "old-unique-id"),
</span><ins>+                                                                 switch_core_get_variable("hostname"),
</ins><span class="cx">                                                                  switch_event_get_header_nil(event, "unique-id"),
</span><del>-                                                                 switch_event_get_header_nil(event, "old-unique-id")
</del><ins>+                                                                 switch_event_get_header_nil(event, "old-unique-id"),
+                                                                 switch_core_get_variable("hostname")
</ins><span class="cx">                                                                  );
</span><span class="cx">                         break;
</span><span class="cx">                 }
</span><span class="cx">         case SWITCH_EVENT_CHANNEL_CREATE:
</span><del>-                sql = switch_mprintf("insert into channels (uuid,direction,created,created_epoch, name,state,dialplan,context) "
-                                                         "values('%q','%q','%q','%ld','%q','%q','%q','%q')",
</del><ins>+                sql = switch_mprintf("insert into channels (uuid,direction,created,created_epoch, name,state,dialplan,context,hostname) "
+                                                         "values('%q','%q','%q','%ld','%q','%q','%q','%q','%q')",
</ins><span class="cx">                                                          switch_event_get_header_nil(event, "unique-id"),
</span><span class="cx">                                                          switch_event_get_header_nil(event, "call-direction"),
</span><span class="cx">                                                          switch_event_get_header_nil(event, "event-date-local"),
</span><span class="lines">@@ -478,24 +551,28 @@
</span><span class="cx">                                                          switch_event_get_header_nil(event, "channel-name"),
</span><span class="cx">                                                          switch_event_get_header_nil(event, "channel-state"),
</span><span class="cx">                                                          switch_event_get_header_nil(event, "caller-dialplan"),
</span><del>-                                                         switch_event_get_header_nil(event, "caller-context")
</del><ins>+                                                         switch_event_get_header_nil(event, "caller-context"),
+                                                         switch_core_get_variable("hostname")
</ins><span class="cx">                                                          );
</span><span class="cx">                 break;
</span><span class="cx">         case SWITCH_EVENT_CODEC:
</span><span class="cx">                 sql =
</span><span class="cx">                         switch_mprintf
</span><del>-                        ("update channels set read_codec='%q',read_rate='%q',write_codec='%q',write_rate='%q' where uuid='%q'",
</del><ins>+                        ("update channels set read_codec='%q',read_rate='%q',write_codec='%q',write_rate='%q' where uuid='%q' and hostname='%q'",
</ins><span class="cx">                          switch_event_get_header_nil(event, "channel-read-codec-name"),
</span><span class="cx">                          switch_event_get_header_nil(event, "channel-read-codec-rate"),
</span><span class="cx">                          switch_event_get_header_nil(event, "channel-write-codec-name"),
</span><span class="cx">                          switch_event_get_header_nil(event, "channel-write-codec-rate"),
</span><del>-                         switch_event_get_header_nil(event, "unique-id"));
</del><ins>+                         switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
</ins><span class="cx">                 break;
</span><span class="cx">         case SWITCH_EVENT_CHANNEL_EXECUTE:
</span><del>-                sql = switch_mprintf("update channels set application='%q',application_data='%q' where uuid='%q'",
</del><ins>+                sql = switch_mprintf("update channels set application='%q',application_data='%q',"
+                                                         "presence_id='%q',presence_data='%q' where uuid='%q' and hostname='%q'",
</ins><span class="cx">                                                          switch_event_get_header_nil(event, "application"),
</span><span class="cx">                                                          switch_event_get_header_nil(event, "application-data"),
</span><del>-                                                         switch_event_get_header_nil(event, "unique-id")
</del><ins>+                                                         switch_event_get_header_nil(event, "channel-presence-id"),
+                                                         switch_event_get_header_nil(event, "channel-presence-data"),
+                                                         switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname")
</ins><span class="cx">
</span><span class="cx">                                                          );
</span><span class="cx">
</span><span class="lines">@@ -514,26 +591,30 @@
</span><span class="cx">                         case CS_DESTROY:
</span><span class="cx">                                 break;
</span><span class="cx">                         case CS_ROUTING:
</span><del>-                                sql = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',ip_addr='%s',dest='%q',dialplan='%q',context='%q' "
-                                                                         "where uuid='%s'",
</del><ins>+                                sql = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',"
+                                                                         "ip_addr='%s',dest='%q',dialplan='%q',context='%q',presence_id='%q',presence_data='%q' "
+                                                                         "where uuid='%s' and hostname='%q'",
</ins><span class="cx">                                                                          switch_event_get_header_nil(event, "channel-state"),
</span><span class="cx">                                                                          switch_event_get_header_nil(event, "caller-caller-id-name"),
</span><span class="cx">                                                                          switch_event_get_header_nil(event, "caller-caller-id-number"),
</span><span class="cx">                                                                          switch_event_get_header_nil(event, "caller-network-addr"),
</span><span class="cx">                                                                          switch_event_get_header_nil(event, "caller-destination-number"),
</span><span class="cx">                                                                          switch_event_get_header_nil(event, "caller-dialplan"),
</span><del>-                                                                         switch_event_get_header_nil(event, "caller-context"),
-                                                                         switch_event_get_header_nil(event, "unique-id"));
</del><ins>+                                                                         switch_event_get_header_nil(event, "caller-context"),
+                                                                         switch_event_get_header_nil(event, "channel-presence-id"),
+                                                                         switch_event_get_header_nil(event, "channel-presence-data"),
+                                                                         switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
</ins><span class="cx">                                 break;
</span><span class="cx">                         default:
</span><del>-                                sql = switch_mprintf("update channels set state='%s' where uuid='%s'",
-                                                                         switch_event_get_header_nil(event, "channel-state"), switch_event_get_header_nil(event, "unique-id"));
</del><ins>+                                sql = switch_mprintf("update channels set state='%s' where uuid='%s' and hostname='%q'",
+                                                                         switch_event_get_header_nil(event, "channel-state"),
+                                                                         switch_event_get_header_nil(event, "unique-id"), switch_core_get_variable("hostname"));
</ins><span class="cx">                                 break;
</span><span class="cx">                         }
</span><span class="cx">                         break;
</span><span class="cx">                 }
</span><span class="cx">         case SWITCH_EVENT_CHANNEL_BRIDGE:
</span><del>-                sql = switch_mprintf("insert into calls values ('%s', '%ld', '%s','%q','%q','%q','%q','%s','%q','%q','%q','%q','%s')",
</del><ins>+                sql = switch_mprintf("insert into calls values ('%s', '%ld', '%s','%q','%q','%q','%q','%s','%q','%q','%q','%q','%s','%q')",
</ins><span class="cx">                                                          switch_event_get_header_nil(event, "event-date-local"),
</span><span class="cx">                                                          (long)switch_epoch_time_now(NULL),
</span><span class="cx">                                                          switch_event_get_header_nil(event, "event-calling-function"),
</span><span class="lines">@@ -545,14 +626,23 @@
</span><span class="cx">                                                          switch_event_get_header_nil(event, "Other-Leg-caller-id-name"),
</span><span class="cx">                                                          switch_event_get_header_nil(event, "Other-Leg-caller-id-number"),
</span><span class="cx">                                                          switch_event_get_header_nil(event, "Other-Leg-destination-number"),
</span><del>-                                                         switch_event_get_header_nil(event, "Other-Leg-channel-name"), switch_event_get_header_nil(event, "Other-Leg-unique-id")
</del><ins>+                                                         switch_event_get_header_nil(event, "Other-Leg-channel-name"),
+                                                         switch_event_get_header_nil(event, "Other-Leg-unique-id"),
+                                                         switch_core_get_variable("hostname")
</ins><span class="cx">                         );
</span><span class="cx">                 break;
</span><span class="cx">         case SWITCH_EVENT_CHANNEL_UNBRIDGE:
</span><del>-                sql = switch_mprintf("delete from calls where caller_uuid='%s'", switch_event_get_header_nil(event, "caller-unique-id"));
</del><ins>+                sql = switch_mprintf("delete from calls where caller_uuid='%s' and hostname='%q'",
+                                                         switch_event_get_header_nil(event, "caller-unique-id"), switch_core_get_variable("hostname"));
</ins><span class="cx">                 break;
</span><span class="cx">         case SWITCH_EVENT_SHUTDOWN:
</span><del>-                sql = switch_mprintf("delete from channels;delete from interfaces;delete from calls");
</del><ins>+                sql = switch_mprintf("delete from channels where hostname='%q';"
+                                                         "delete from interfaces where hostname='%q';"
+                                                         "delete from calls where hostname='%q'",
+                                                         switch_core_get_variable("hostname"),
+                                                         switch_core_get_variable("hostname"),
+                                                         switch_core_get_variable("hostname")
+                                                         );
</ins><span class="cx">                 break;
</span><span class="cx">         case SWITCH_EVENT_LOG:
</span><span class="cx">                 return;
</span><span class="lines">@@ -566,9 +656,10 @@
</span><span class="cx">                         const char *filename = switch_event_get_header_nil(event, "filename");
</span><span class="cx">                         if (!zstr(type) && !zstr(name)) {
</span><span class="cx">                                 sql =
</span><del>-                                        switch_mprintf("insert into interfaces (type,name,description,syntax,key,filename) values('%q','%q','%q','%q','%q','%q')",
-                                                                 type, name, switch_str_nil(description), switch_str_nil(syntax), switch_str_nil(key), switch_str_nil(filename)
-                                        );
</del><ins>+                                        switch_mprintf("insert into interfaces (type,name,description,syntax,key,filename,hostname) values('%q','%q','%q','%q','%q','%q','%q')",
+                                                                 type, name, switch_str_nil(description), switch_str_nil(syntax),
+                                                                 switch_str_nil(key), switch_str_nil(filename), switch_core_get_variable("hostname")
+                                                                 );
</ins><span class="cx">                         }
</span><span class="cx">                         break;
</span><span class="cx">                 }
</span><span class="lines">@@ -577,7 +668,8 @@
</span><span class="cx">                         const char *type = switch_event_get_header_nil(event, "type");
</span><span class="cx">                         const char *name = switch_event_get_header_nil(event, "name");
</span><span class="cx">                         if (!zstr(type) && !zstr(name)) {
</span><del>-                                sql = switch_mprintf("delete from interfaces where type='%q' and name='%q'", type, name);
</del><ins>+                                sql = switch_mprintf("delete from interfaces where type='%q' and name='%q' and hostname='%q'", type, name,
+                                                                         switch_core_get_variable("hostname"));
</ins><span class="cx">                         }
</span><span class="cx">                         break;
</span><span class="cx">                 }
</span><span class="lines">@@ -588,9 +680,11 @@
</span><span class="cx">                         if (zstr(type)) {
</span><span class="cx">                                 break;
</span><span class="cx">                         }
</span><del>-                        sql = switch_mprintf("update channels set secure='%s' where uuid='%s'",
</del><ins>+                        sql = switch_mprintf("update channels set secure='%s' where uuid='%s' and hostname='%q'",
</ins><span class="cx">                                                                  type,
</span><del>-                                                                 switch_event_get_header_nil(event, "caller-unique-id"));
</del><ins>+                                                                 switch_event_get_header_nil(event, "caller-unique-id"),
+                                                                 switch_core_get_variable("hostname")
+                                                                 );
</ins><span class="cx">                         break;
</span><span class="cx">                 }
</span><span class="cx">         case SWITCH_EVENT_NAT:
</span><span class="lines">@@ -598,14 +692,17 @@
</span><span class="cx">                         const char *op = switch_event_get_header_nil(event, "op");
</span><span class="cx">                         switch_bool_t sticky = switch_true(switch_event_get_header_nil(event, "sticky"));
</span><span class="cx">                         if (!strcmp("add", op)) {
</span><del>-                                sql = switch_mprintf("insert into nat (port, proto, sticky) values (%s, %s, %d)",
-                                                                        switch_event_get_header_nil(event, "port"),
-                                                                        switch_event_get_header_nil(event, "proto"),
-                                                                        sticky);
</del><ins>+                                sql = switch_mprintf("insert into nat (port, proto, sticky, hostname) values (%s, %s, %d,'%q')",
+                                                                         switch_event_get_header_nil(event, "port"),
+                                                                         switch_event_get_header_nil(event, "proto"),
+                                                                         sticky,
+                                                                         switch_core_get_variable("hostname")
+                                                                         );
</ins><span class="cx">                         } else if (!strcmp("del", op)) {
</span><del>-                                sql = switch_mprintf("delete from nat where port=%s and proto=%s",
-                                                                        switch_event_get_header_nil(event, "port"),
-                                                                        switch_event_get_header_nil(event, "proto"));
</del><ins>+                                sql = switch_mprintf("delete from nat where port=%s and proto=%s and hostname='%q'",
+                                                                         switch_event_get_header_nil(event, "port"),
+                                                                         switch_event_get_header_nil(event, "proto"),
+                                                                         switch_core_get_variable("hostname"));
</ins><span class="cx">                         } else if (!strcmp("status", op)) {
</span><span class="cx">                                 /* call show nat api */
</span><span class="cx">                         } else if (!strcmp("status_response", op)) {
</span><span class="lines">@@ -629,146 +726,219 @@
</span><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void switch_core_sqldb_start(switch_memory_pool_t *pool)
</del><ins>+
+static char create_complete_sql[] =
+        "CREATE TABLE complete (\n"
+        " sticky INTEGER,\n"
+        " a1 VARCHAR(4096),\n"
+        " a2 VARCHAR(4096),\n"
+        " a3 VARCHAR(4096),\n"
+        " a4 VARCHAR(4096),\n"
+        " a5 VARCHAR(4096),\n"
+        " a6 VARCHAR(4096),\n"
+        " a7 VARCHAR(4096),\n"
+        " a8 VARCHAR(4096),\n"
+        " a9 VARCHAR(4096),\n"
+        " a10 VARCHAR(4096),\n"
+        " hostname VARCHAR(4096)\n"
+        ");\n";
+
+static char create_alias_sql[] =
+        "CREATE TABLE aliases (\n"
+        " sticky INTEGER,\n"
+        " alias VARCHAR(4096),\n"
+        " command VARCHAR(4096),\n"
+        " hostname VARCHAR(4096)\n"
+        ");\n";
+
+static char create_channels_sql[] =
+        "CREATE TABLE channels (\n"
+        " uuid VARCHAR(4096),\n"
+        " direction VARCHAR(4096),\n"
+        " created VARCHAR(4096),\n"
+        " created_epoch INTEGER,\n"
+        " name VARCHAR(4096),\n"
+        " state VARCHAR(4096),\n"
+        " cid_name VARCHAR(4096),\n"
+        " cid_num VARCHAR(4096),\n"
+        " ip_addr VARCHAR(4096),\n"
+        " dest VARCHAR(4096),\n"
+        " application VARCHAR(4096),\n"
+        " application_data VARCHAR(4096),\n"
+        " dialplan VARCHAR(4096),\n"
+        " context VARCHAR(4096),\n"
+        " read_codec VARCHAR(4096),\n"
+        " read_rate VARCHAR(4096),\n"
+        " write_codec VARCHAR(4096),\n"
+        " write_rate VARCHAR(4096),\n"
+        " secure VARCHAR(4096),\n"
+        " hostname VARCHAR(4096),\n"
+        " presence_id VARCHAR(4096),\n"
+        " presence_data VARCHAR(4096)\n"
+        ");\ncreate index uuindex on channels (uuid,hostname);\n";
+static char create_calls_sql[] =
+        "CREATE TABLE calls (\n"
+        " call_created VARCHAR(4096),\n"
+        " call_created_epoch INTEGER,\n"
+        " function VARCHAR(4096),\n"
+        " caller_cid_name VARCHAR(4096),\n"
+        " caller_cid_num VARCHAR(4096),\n"
+        " caller_dest_num VARCHAR(4096),\n"
+        " caller_chan_name VARCHAR(4096),\n"
+        " caller_uuid VARCHAR(4096),\n"
+        " callee_cid_name VARCHAR(4096),\n"
+        " callee_cid_num VARCHAR(4096),\n"
+        " callee_dest_num VARCHAR(4096),\n"
+        " callee_chan_name VARCHAR(4096),\n"
+        " callee_uuid VARCHAR(4096),\n"
+        " hostname VARCHAR(4096)\n"
+        ");\n"
+        "create index eruuindex on calls (caller_uuid,hostname);\n"
+        "create index eeuuindex on calls (callee_uuid,hostname);\n";
+static char create_interfaces_sql[] =
+        "CREATE TABLE interfaces (\n"
+        " type VARCHAR(4096),\n"
+        " name VARCHAR(4096),\n"
+        " description VARCHAR(4096),\n"
+        " key VARCHAR(4096),\n"
+        " filename VARCHAR(4096),\n"
+        " syntax VARCHAR(4096),\n"
+        " hostname VARCHAR(4096)\n"
+        ");\n";
+static char create_tasks_sql[] =
+        "CREATE TABLE tasks (\n"
+        " task_id INTEGER,\n"
+        " task_desc VARCHAR(4096),\n"
+        " task_group VARCHAR(4096),\n"
+        " task_sql_manager INTEGER,\n"
+        " hostname VARCHAR(4096)\n"
+        ");\n";
+static char create_nat_sql[] =
+        "CREATE TABLE nat (\n"
+        " sticky INTEGER,\n"
+        "        port        INTEGER,\n"
+        "        proto        INTEGER,\n"
+        " hostname VARCHAR(4096)\n"
+        ");\n";
+
+switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_t manage)
</ins><span class="cx"> {
</span><span class="cx">         switch_threadattr_t *thd_attr;
</span><ins>+        switch_cache_db_handle_t *dbh;
</ins><span class="cx">
</span><span class="cx">         sql_manager.memory_pool = pool;
</span><del>-
</del><ins>+        sql_manager.manage = manage;
+        
</ins><span class="cx">         switch_mutex_init(&dbh_mutex, SWITCH_MUTEX_NESTED, sql_manager.memory_pool);
</span><span class="cx">         switch_core_hash_init(&dbh_hash, sql_manager.memory_pool);
</span><span class="cx">
</span><ins>+ top:
+        
</ins><span class="cx">         /* Activate SQL database */
</span><del>-        if ((sql_manager.db = switch_core_db_handle()) == 0) {
</del><ins>+        if (switch_core_db_handle(&dbh) != SWITCH_STATUS_SUCCESS) {
</ins><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB!\n");
</span><ins>+
+                if (runtime.odbc_dsn) {
+                        runtime.odbc_dsn = NULL;
+                        runtime.odbc_user = NULL;
+                        runtime.odbc_pass = NULL;
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Falling back to sqlite.\n");
+                        goto top;
+                }
+
+
</ins><span class="cx">                 switch_clear_flag((&runtime), SCF_USE_SQL);
</span><ins>+                return SWITCH_STATUS_FALSE;
+        }
+
+        
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Opening DB\n");
+        if (dbh->db) {
+                switch_cache_db_execute_sql(dbh, "drop table channels", NULL);
+                switch_cache_db_execute_sql(dbh, "drop table calls", NULL);
+                switch_cache_db_execute_sql(dbh, "drop table interfaces", NULL);
+                switch_cache_db_execute_sql(dbh, "drop table tasks", NULL);
+                switch_cache_db_execute_sql(dbh, "PRAGMA synchronous=OFF;", NULL);
+                switch_cache_db_execute_sql(dbh, "PRAGMA count_changes=OFF;", NULL);
+                switch_cache_db_execute_sql(dbh, "PRAGMA cache_size=8000", NULL);
+                switch_cache_db_execute_sql(dbh, "PRAGMA temp_store=MEMORY;", NULL);
</ins><span class="cx">         } else {
</span><del>-                char create_complete_sql[] =
-                        "CREATE TABLE complete (\n"
-                        " sticky INTEGER,\n"
-                        " a1 VARCHAR(255),\n"
-                        " a2 VARCHAR(255),\n"
-                        " a3 VARCHAR(255),\n"
-                        " a4 VARCHAR(255),\n"
-                        " a5 VARCHAR(255),\n"
-                        " a6 VARCHAR(255),\n"
-                        " a7 VARCHAR(255),\n"
-                        " a8 VARCHAR(255),\n"
-                        " a9 VARCHAR(255),\n"
-                        " a10 VARCHAR(255)\n"
-                        ");\n";
</del><ins>+                char sql[512] = "";
+                char *tables[] = {"channels", "calls", "interfaces", "tasks", NULL};
+                int i;
+                const char *hostname = switch_core_get_variable("hostname");
</ins><span class="cx">
</span><del>-                char create_alias_sql[] =
-                        "CREATE TABLE aliases (\n"
-                        " sticky INTEGER,\n"
-                        " alias VARCHAR(255),\n"
-                        " command VARCHAR(255)\n"
-                        ");\n";
</del><ins>+                for(i = 0; tables[i]; i++) {
+                        switch_snprintf(sql, sizeof(sql), "delete from %s where hostname='%s'", tables[i], hostname);
+                        switch_cache_db_execute_sql(dbh, sql, NULL);
+                }
+        }
</ins><span class="cx">
</span><del>-                char create_channels_sql[] =
-                        "CREATE TABLE channels (\n"
-                        " uuid VARCHAR(255),\n"
-                        " direction VARCHAR(255),\n"
-                        " created VARCHAR(255),\n"
-                        " created_epoch INTEGER,\n"
-                        " name VARCHAR(255),\n"
-                        " state VARCHAR(255),\n"
-                        " cid_name VARCHAR(255),\n"
-                        " cid_num VARCHAR(255),\n"
-                        " ip_addr VARCHAR(255),\n"
-                        " dest VARCHAR(255),\n"
-                        " application VARCHAR(255),\n"
-                        " application_data VARCHAR(255),\n"
-                        " dialplan VARCHAR(255),\n"
-                        " context VARCHAR(255),\n"
-                        " read_codec VARCHAR(255),\n"
-                        " read_rate VARCHAR(255),\n"
-                        " write_codec VARCHAR(255),\n"
-                        " write_rate VARCHAR(255),\n"
-                        " secure VARCHAR(255)\n"
-                        ");\ncreate index uuindex on channels (uuid);\n";
-                char create_calls_sql[] =
-                        "CREATE TABLE calls (\n"
-                        " call_created VARCHAR(255),\n"
-                        " call_created_epoch INTEGER,\n"
-                        " function VARCHAR(255),\n"
-                        " caller_cid_name VARCHAR(255),\n"
-                        " caller_cid_num VARCHAR(255),\n"
-                        " caller_dest_num VARCHAR(255),\n"
-                        " caller_chan_name VARCHAR(255),\n"
-                        " caller_uuid VARCHAR(255),\n"
-                        " callee_cid_name VARCHAR(255),\n"
-                        " callee_cid_num VARCHAR(255),\n"
-                        " callee_dest_num VARCHAR(255),\n"
-                        " callee_chan_name VARCHAR(255),\n"
-                        " callee_uuid VARCHAR(255)\n"
-                        ");\n"
-                        "create index eruuindex on calls (caller_uuid);\n"
-                        "create index eeuuindex on calls (callee_uuid);\n";
-                char create_interfaces_sql[] =
-                        "CREATE TABLE interfaces (\n"
-                        " type VARCHAR(255),\n"
-                        " name VARCHAR(255),\n"
-                        " description VARCHAR(255),\n"
-                        " key VARCHAR(255),\n"
-                        " filename VARCHAR(255),\n"
-                        " syntax VARCHAR(255)\n"
-                        ");\n";
-                char create_tasks_sql[] =
-                        "CREATE TABLE tasks (\n"
-                        " task_id INTEGER(4),\n"
-                        " task_desc VARCHAR(255),\n"
-                        " task_group VARCHAR(255),\n"
-                        " task_sql_manager INTEGER(8)\n"
-                        ");\n";
-                char create_nat_sql[] =
-                        "CREATE TABLE nat (\n"
-                        " sticky INTEGER,\n"
-                        "        port        INTEGER,\n"
-                        "        proto        INTEGER\n"
-                        ");\n";
</del><ins>+                
+        switch_cache_db_test_reactive(dbh, "select hostname from complete", "DROP TABLE complete", create_complete_sql);
+        switch_cache_db_test_reactive(dbh, "select hostname from aliases", "DROP TABLE aliases", create_alias_sql);
+        switch_cache_db_test_reactive(dbh, "select hostname from nat", "DROP TABLE nat", create_nat_sql);
</ins><span class="cx">
</span><del>-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Opening DB\n");
-                switch_core_db_exec(sql_manager.db, "drop table channels", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "drop table calls", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "drop table interfaces", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "drop table tasks", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "PRAGMA synchronous=OFF;", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "PRAGMA count_changes=OFF;", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "PRAGMA cache_size=8000", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "PRAGMA temp_store=MEMORY;", NULL, NULL, NULL);
</del><span class="cx">
</span><del>-                switch_core_db_test_reactive(sql_manager.db, "select sticky from complete", "DROP TABLE complete", create_complete_sql);
-                switch_core_db_test_reactive(sql_manager.db, "select sticky from aliases", "DROP TABLE aliases", create_alias_sql);
-                switch_core_db_test_reactive(sql_manager.db, "select sticky from nat", "DROP TABLE nat", create_nat_sql);
-                switch_core_db_exec(sql_manager.db, "delete from complete where sticky=0", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "delete from aliases where sticky=0", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "delete from nat where sticky=0", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create index if not exists alias1 on aliases (alias)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create index if not exists complete1 on complete (a1)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create index if not exists complete2 on complete (a2)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create index if not exists complete3 on complete (a3)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create index if not exists complete4 on complete (a4)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create index if not exists complete5 on complete (a5)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create index if not exists complete6 on complete (a6)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create index if not exists complete7 on complete (a7)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create index if not exists complete8 on complete (a8)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create index if not exists complete9 on complete (a9)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create index if not exists complete10 on complete (a10)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, "create unique index if not exists nat_map_port_proto on nat (port,proto)", NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, create_channels_sql, NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, create_calls_sql, NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, create_interfaces_sql, NULL, NULL, NULL);
-                switch_core_db_exec(sql_manager.db, create_tasks_sql, NULL, NULL, NULL);
</del><ins>+        if (dbh->odbc_dbh) {
+                char *err;
</ins><span class="cx">
</span><del>-                if (switch_event_bind_removable("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, core_event_handler, NULL, &sql_manager.event_node) != SWITCH_STATUS_SUCCESS) {
</del><ins>+                switch_cache_db_execute_sql(dbh, "begin;delete from channels where hostname='';delete from channels where hostname='';commit;", &err);
+
+                if (err) {
+                        runtime.odbc_dsn = NULL;
+                        runtime.odbc_user = NULL;
+                        runtime.odbc_pass = NULL;
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Transactions not supported on your DB, disabling ODBC\n");
+                        switch_cache_db_release_db_handle(&dbh);
+                        free(err);
+                        goto top;
+                }
+        }
+
+
+        if (dbh->db) {
+                switch_cache_db_execute_sql(dbh, create_channels_sql, NULL);
+                switch_cache_db_execute_sql(dbh, create_calls_sql, NULL);
+                switch_cache_db_execute_sql(dbh, create_interfaces_sql, NULL);
+                switch_cache_db_execute_sql(dbh, create_tasks_sql, NULL);
+        } else {
+                switch_cache_db_test_reactive(dbh, "select hostname from channels", "DROP TABLE channels", create_channels_sql);
+                switch_cache_db_test_reactive(dbh, "select hostname from calls", "DROP TABLE calls", create_calls_sql);
+                switch_cache_db_test_reactive(dbh, "select hostname from interfaces", "DROP TABLE interfaces", create_interfaces_sql);
+                switch_cache_db_test_reactive(dbh, "select hostname from tasks", "DROP TABLE tasks", create_tasks_sql);
+                
+        }
+
+        switch_cache_db_execute_sql(dbh, "delete from complete where sticky=0", NULL);
+        switch_cache_db_execute_sql(dbh, "delete from aliases where sticky=0", NULL);
+        switch_cache_db_execute_sql(dbh, "delete from nat where sticky=0", NULL);
+        switch_cache_db_execute_sql(dbh, "create index alias1 on aliases (alias)", NULL);
+        switch_cache_db_execute_sql(dbh, "create index complete1 on complete (a1,hostname)", NULL);
+        switch_cache_db_execute_sql(dbh, "create index complete2 on complete (a2,hostname)", NULL);
+        switch_cache_db_execute_sql(dbh, "create index complete3 on complete (a3,hostname)", NULL);
+        switch_cache_db_execute_sql(dbh, "create index complete4 on complete (a4,hostname)", NULL);
+        switch_cache_db_execute_sql(dbh, "create index complete5 on complete (a5,hostname)", NULL);
+        switch_cache_db_execute_sql(dbh, "create index complete6 on complete (a6,hostname)", NULL);
+        switch_cache_db_execute_sql(dbh, "create index complete7 on complete (a7,hostname)", NULL);
+        switch_cache_db_execute_sql(dbh, "create index complete8 on complete (a8,hostname)", NULL);
+        switch_cache_db_execute_sql(dbh, "create index complete9 on complete (a9,hostname)", NULL);
+        switch_cache_db_execute_sql(dbh, "create index complete10 on complete (a10,hostname)", NULL);
+        switch_cache_db_execute_sql(dbh, "create unique index nat_map_port_proto on nat (port,proto,hostname)", NULL);
+        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);
+
+
+        if (sql_manager.manage) {
+                if (switch_event_bind_removable("core_db", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY,
+                                                                                core_event_handler, NULL, &sql_manager.event_node) != SWITCH_STATUS_SUCCESS) {
</ins><span class="cx">                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind event handler!\n");
</span><span class="cx">                 }
</span><ins>+
+                switch_queue_create(&sql_manager.sql_queue[0], SWITCH_SQL_QUEUE_LEN, sql_manager.memory_pool);
+                switch_queue_create(&sql_manager.sql_queue[1], SWITCH_SQL_QUEUE_LEN, sql_manager.memory_pool);
</ins><span class="cx">         }
</span><span class="cx">
</span><del>-        switch_queue_create(&sql_manager.sql_queue[0], SWITCH_SQL_QUEUE_LEN, sql_manager.memory_pool);
-        switch_queue_create(&sql_manager.sql_queue[1], SWITCH_SQL_QUEUE_LEN, sql_manager.memory_pool);
-
</del><span class="cx">         switch_threadattr_create(&thd_attr, sql_manager.memory_pool);
</span><span class="cx">         switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
</span><span class="cx">         switch_thread_create(&sql_manager.thread, thd_attr, switch_core_sql_thread, NULL, sql_manager.memory_pool);
</span><span class="lines">@@ -776,6 +946,10 @@
</span><span class="cx">         while (!sql_manager.thread_running) {
</span><span class="cx">                 switch_yield(10000);
</span><span class="cx">         }
</span><ins>+        
+        switch_cache_db_release_db_handle(&dbh);
+
+        return SWITCH_STATUS_SUCCESS;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void switch_core_sqldb_stop(void)
</span><span class="lines">@@ -783,17 +957,23 @@
</span><span class="cx">         switch_status_t st;
</span><span class="cx">
</span><span class="cx">         switch_event_unbind(&sql_manager.event_node);
</span><ins>+        
+        switch_cache_db_release_db_handle(&sql_manager.event_db);
+        sql_close(0);
</ins><span class="cx">
</span><del>-        switch_queue_push(sql_manager.sql_queue[0], NULL);
-        switch_queue_push(sql_manager.sql_queue[1], NULL);
</del><ins>+        if (sql_manager.thread && sql_manager.thread_running) {
</ins><span class="cx">
</span><del>-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n");
-        switch_thread_join(&st, sql_manager.thread);
-        sql_close(0);
</del><ins>+                if (sql_manager.manage) {
+                        switch_queue_push(sql_manager.sql_queue[0], NULL);
+                        switch_queue_push(sql_manager.sql_queue[1], NULL);
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n");
+                }
</ins><span class="cx">
</span><del>-        switch_core_db_close(sql_manager.db);
-        switch_core_db_close(sql_manager.event_db);
</del><ins>+                sql_manager.thread_running = -1;
+                switch_thread_join(&st, sql_manager.thread);
+        }
</ins><span class="cx">
</span><ins>+
</ins><span class="cx">         switch_core_hash_destroy(&dbh_hash);
</span><span class="cx">
</span><span class="cx"> }
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_odbcc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_odbc.c (15486 => 15487)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_odbc.c        2009-11-16 21:14:38 UTC (rev 15486)
+++ freeswitch/trunk/src/switch_odbc.c        2009-11-17 00:12:54 UTC (rev 15487)
</span><span class="lines">@@ -424,7 +424,7 @@
</span><span class="cx">
</span><span class="cx"> SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(const char *file, const char *func, int line,
</span><span class="cx">                                                                                                                                                          switch_odbc_handle_t *handle,
</span><del>-                                                                                                                                                         char *sql, switch_core_db_callback_func_t callback, void *pdata)
</del><ins>+                                                                                                                                                         char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err)
</ins><span class="cx"> {
</span><span class="cx"> #ifdef SWITCH_HAVE_ODBC
</span><span class="cx">         SQLHSTMT stmt = NULL;
</span><span class="lines">@@ -432,7 +432,6 @@
</span><span class="cx">         SQLLEN m = 0, t = 0;
</span><span class="cx">         char *err_str = NULL;
</span><span class="cx">         int result;
</span><del>-        int err = 0;
</del><span class="cx">         
</span><span class="cx">         switch_assert(callback != NULL);
</span><span class="cx">
</span><span class="lines">@@ -441,12 +440,12 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
</span><del>-                err_str = "Unable to SQL allocate handle.";
</del><ins>+                err_str = strdup("Unable to SQL allocate handle.");
</ins><span class="cx">                 goto error;
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if (SQLPrepare(stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
</span><del>-                err_str = "Unable to prepare SQL statement.";
</del><ins>+                err_str = strdup("Unable to prepare SQL statement.");
</ins><span class="cx">                 goto error;
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -517,27 +516,24 @@
</span><span class="cx">         
</span><span class="cx">         SQLFreeHandle(SQL_HANDLE_STMT, stmt);
</span><span class="cx">
</span><del>-        if (!err) {
-                return SWITCH_ODBC_SUCCESS;
-        }
-
</del><span class="cx"> error:
</span><span class="cx">
</span><del>-        /* err_str is already defined for some error cases */
-        if (err_str != NULL) {
-                switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
-                err_str = NULL;
-        }
-        
</del><span class="cx">         if (stmt) {
</span><span class="cx">                 err_str = switch_odbc_handle_get_error(handle, stmt);
</span><del>-                if (!zstr(err_str)) {
-                        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
-                }
-                switch_safe_free(err_str);
</del><span class="cx">                 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        if (err_str) {
+                switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
+                if (err) {
+                        *err = err_str;
+                } else {
+                        *err = NULL;
+                        free(err_str);
+                }
+        }
+        
+
</ins><span class="cx"> #endif
</span><span class="cx">         return SWITCH_ODBC_FAIL;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>