<!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][15600] </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=15600">15600</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-11-21 12:57:15 -0600 (Sat, 21 Nov 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>convert sofia to use new core version of cache db handles</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcincludeswitch_coreh">freeswitch/trunk/src/include/switch_core.h</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiamod_sofiah">freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofiac">freeswitch/trunk/src/mod/endpoints/mod_sofia/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="#freeswitchtrunksrcswitch_core_sqldbc">freeswitch/trunk/src/switch_core_sqldb.c</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcincludeswitch_coreh"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/include/switch_core.h (15599 => 15600)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_core.h        2009-11-21 17:57:55 UTC (rev 15599)
+++ freeswitch/trunk/src/include/switch_core.h        2009-11-21 18:57:15 UTC (rev 15600)
</span><span class="lines">@@ -1988,8 +1988,9 @@
</span><span class="cx">                                                                                                                          switch_cache_db_handle_type_t type,
</span><span class="cx">                                                                                                                          switch_cache_db_connection_options_t *connection_options,
</span><span class="cx">                                                                                                                          const char *file, const char *func, int line);
</span><del>-#define switch_cache_db_get_db_handle(_a, _b) _switch_cache_db_get_db_handle(_a, _b, __FILE__, __SWITCH_FUNC__, __LINE__)
</del><ins>+#define switch_cache_db_get_db_handle(_a, _b, _c) _switch_cache_db_get_db_handle(_a, _b, _c, __FILE__, __SWITCH_FUNC__, __LINE__)
</ins><span class="cx">
</span><ins>+SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t *dbh, char *sql, char *str, size_t len, char **err);
</ins><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, char *sql, char **err);
</span><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh, const char *sql,
</span><span class="cx">                                                                                                                                          switch_core_db_callback_func_t callback, void *pdata, char **err);
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiamod_sofiah"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (15599 => 15600)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2009-11-21 17:57:55 UTC (rev 15599)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2009-11-21 18:57:15 UTC (rev 15600)
</span><span class="lines">@@ -476,7 +476,6 @@
</span><span class="cx">         sofia_gateway_t *gateways;
</span><span class="cx">         su_home_t *home;
</span><span class="cx">         switch_hash_t *chat_hash;
</span><del>-        switch_hash_t *db_hash;
</del><span class="cx">         //switch_core_db_t *master_db;
</span><span class="cx">         switch_thread_rwlock_t *rwlock;
</span><span class="cx">         switch_mutex_t *flag_mutex;
</span><span class="lines">@@ -673,14 +672,6 @@
</span><span class="cx"> char *route_uri;
</span><span class="cx"> } sofia_destination_t;
</span><span class="cx">
</span><del>-typedef struct {
-        switch_core_db_t *db;
-        switch_odbc_handle_t *odbc_dbh;
-        time_t last_used;
-        switch_mutex_t *mutex;
-        switch_memory_pool_t *pool;
-} sofia_cache_db_handle_t;
-
</del><span class="cx"> #define sofia_test_pflag(obj, flag) ((obj)->pflags[flag] ? 1 : 0)
</span><span class="cx"> #define sofia_set_pflag(obj, flag) (obj)->pflags[flag] = 1
</span><span class="cx"> #define sofia_set_pflag_locked(obj, flag) assert(obj->flag_mutex != NULL);\
</span><span class="lines">@@ -785,6 +776,7 @@
</span><span class="cx">
</span><span class="cx"> void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic);
</span><span class="cx"> void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex);
</span><ins>+void sofia_glue_actually_execute_sql_trans(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex);
</ins><span class="cx"> void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot);
</span><span class="cx"> void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now);
</span><span class="cx"> void sofia_sub_check_gateway(sofia_profile_t *profile, time_t now);
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (15599 => 15600)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2009-11-21 17:57:55 UTC (rev 15599)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2009-11-21 18:57:15 UTC (rev 15600)
</span><span class="lines">@@ -916,7 +916,7 @@
</span><span class="cx">
</span><span class="cx">                                 switch_mutex_lock(profile->ireg_mutex);
</span><span class="cx">                         
</span><del>-                                sofia_glue_actually_execute_sql(profile, "begin;\n", NULL);
</del><ins>+                                //sofia_glue_actually_execute_sql(profile, "begin;\n", NULL);
</ins><span class="cx">
</span><span class="cx">                                 while (switch_queue_trypop(profile->sql_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) {
</span><span class="cx">                                         char *sql = (char *) pop;
</span><span class="lines">@@ -941,8 +941,8 @@
</span><span class="cx">                                 }
</span><span class="cx">
</span><span class="cx">                                 //printf("TRANS:\n%s\n", sqlbuf);
</span><del>-                                sofia_glue_actually_execute_sql(profile, sqlbuf, NULL);
-                                sofia_glue_actually_execute_sql(profile, "commit;\n", NULL);
</del><ins>+                                sofia_glue_actually_execute_sql_trans(profile, sqlbuf, NULL);
+                                //sofia_glue_actually_execute_sql(profile, "commit;\n", NULL);
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">                                 switch_mutex_unlock(profile->ireg_mutex);
</span><span class="lines">@@ -963,7 +963,6 @@
</span><span class="cx">                         if (++ireg_loops >= IREG_SECONDS) {
</span><span class="cx">                                 time_t now = switch_epoch_time_now(NULL);
</span><span class="cx">                                 sofia_reg_check_expire(profile, now, 0);
</span><del>-                                sofia_glue_sql_close(profile, now);
</del><span class="cx">                                 ireg_loops = 0;
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="lines">@@ -1264,14 +1263,12 @@
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        sofia_glue_sql_close(profile, 0);
</del><span class="cx">         su_home_unref(profile->home);
</span><span class="cx">         su_root_destroy(profile->s_root);
</span><span class="cx">         pool = profile->pool;
</span><span class="cx">
</span><span class="cx">         sofia_glue_del_profile(profile);
</span><span class="cx">         switch_core_hash_destroy(&profile->chat_hash);
</span><del>-        switch_core_hash_destroy(&profile->db_hash);
</del><span class="cx">
</span><span class="cx">         switch_thread_rwlock_unlock(profile->rwlock);
</span><span class="cx">         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Write unlock %s\n", profile->name);
</span><span class="lines">@@ -2393,7 +2390,6 @@
</span><span class="cx">
</span><span class="cx">                                 profile->dbname = switch_core_strdup(profile->pool, url);
</span><span class="cx">                                 switch_core_hash_init(&profile->chat_hash, profile->pool);
</span><del>-                                switch_core_hash_init(&profile->db_hash, profile->pool);
</del><span class="cx">                                 switch_thread_rwlock_create(&profile->rwlock, profile->pool);
</span><span class="cx">                                 switch_mutex_init(&profile->flag_mutex, SWITCH_MUTEX_NESTED, profile->pool);
</span><span class="cx">                                 profile->dtmf_duration = 100;
</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 (15599 => 15600)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-11-21 17:57:55 UTC (rev 15599)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2009-11-21 18:57:15 UTC (rev 15600)
</span><span class="lines">@@ -4080,63 +4080,6 @@
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void sofia_glue_sql_close(sofia_profile_t *profile, time_t prune)
-{
-        switch_hash_index_t *hi;
-        const void *var;
-        void *val;
-        sofia_cache_db_handle_t *dbh = NULL;
-        int locked = 0;
-        char *key;
-
-        switch_mutex_lock(profile->ireg_mutex);
- top:
-        locked = 0;
-        
-        for (hi = switch_hash_first(NULL, profile->db_hash); hi; hi = switch_hash_next(hi)) {
-                switch_hash_this(hi, &var, NULL, &val);
-                key = (char *) var;
-
-                if ((dbh = (sofia_cache_db_handle_t *) val)) {
-                        time_t diff = 0;
-
-                        if (prune > 0) {
-                                if (prune > dbh->last_used) {
-                                        diff = (time_t) prune - dbh->last_used;
-                                }
-                        
-                                if (diff < SQL_CACHE_TIMEOUT) {
-                                        continue;
-                                }
-                        }
-
-                        if (switch_mutex_trylock(dbh->mutex) == SWITCH_STATUS_SUCCESS) {
-                                if (dbh->db) {
-                                        switch_core_db_close(dbh->db);
-                                        dbh->db = NULL;
-                                } else if (switch_odbc_available() && dbh->odbc_dbh) {
-                                        switch_odbc_handle_destroy(&dbh->odbc_dbh);
-                                }
-
-                                switch_core_hash_delete(profile->db_hash, key);
-                                switch_mutex_unlock(dbh->mutex);
-                                switch_core_destroy_memory_pool(&dbh->pool);
-                                goto top;
-        
-                        } else {
-                                if (!prune) locked++;
-                                continue;
-                        }
-                }
-        }
-
-        if (locked) {
-                goto top;
-        }
-
-        switch_mutex_unlock(profile->ireg_mutex);
-}
-
</del><span class="cx"> void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic)
</span><span class="cx"> {
</span><span class="cx">         switch_status_t status = SWITCH_STATUS_FALSE;
</span><span class="lines">@@ -4172,69 +4115,52 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx">
</span><del>-void sofia_glue_release_db_handle(sofia_cache_db_handle_t **dbh)
</del><ins>+switch_cache_db_handle_t *sofia_glue_get_db_handle(sofia_profile_t *profile)
</ins><span class="cx"> {
</span><del>-        if (dbh && *dbh) {
-                switch_mutex_unlock((*dbh)->mutex);
-                *dbh = NULL;
</del><ins>+        switch_cache_db_connection_options_t options = { {0} };
+        switch_cache_db_handle_t *dbh = NULL;
+        
+        if (profile->odbc_dsn && profile->odbc_user && profile->odbc_pass) {
+                options.odbc_options.dsn = profile->odbc_dsn;
+                options.odbc_options.user = profile->odbc_user;
+                options.odbc_options.pass = profile->odbc_pass;
+
+                if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+                return dbh;
+        } else {
+                options.core_db_options.db_path = profile->dbname;
+                if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_CORE_DB, &options) != SWITCH_STATUS_SUCCESS) dbh = NULL;
+                return dbh;
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-sofia_cache_db_handle_t *sofia_glue_get_db_handle(sofia_profile_t *profile)
</del><ins>+void sofia_glue_actually_execute_sql_trans(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex)
</ins><span class="cx"> {
</span><del>-        switch_thread_id_t self = switch_thread_self();
-        char thread_str[256] = "";
-        sofia_cache_db_handle_t *dbh = NULL;
-        
-        snprintf(thread_str, sizeof(thread_str) - 1, "%lu", (unsigned long)(intptr_t)self);
</del><ins>+        switch_cache_db_handle_t *dbh = NULL;
</ins><span class="cx">
</span><del>-        switch_mutex_lock(profile->ireg_mutex);
-        if (!(dbh = switch_core_hash_find(profile->db_hash, thread_str))) {
-                switch_memory_pool_t *pool = NULL;
-                switch_core_db_t *db = NULL;
-                switch_odbc_handle_t *odbc_dbh = NULL;
</del><ins>+        if (mutex) {
+                switch_mutex_lock(mutex);
+        }
</ins><span class="cx">
</span><del>-                if (switch_odbc_available() && profile->odbc_dsn) {
-                        if ((odbc_dbh = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
-                                if (switch_odbc_handle_connect(odbc_dbh) != SWITCH_STATUS_SUCCESS) {
-                                        switch_odbc_handle_destroy(&odbc_dbh);
-                                }
-                        }
-                } else {
-                        db = switch_core_db_open_file(profile->dbname);
-                }
-
-                if (!db && !odbc_dbh) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure!\n");
-                        goto end;
-                }
-
-                switch_core_new_memory_pool(&pool);
-                dbh = switch_core_alloc(pool, sizeof(*dbh));
-                dbh->pool = pool;
-
-                
-                if (db) dbh->db = db; else dbh->odbc_dbh = odbc_dbh;
-                switch_mutex_init(&dbh->mutex, SWITCH_MUTEX_UNNESTED, dbh->pool);
-                switch_mutex_lock(dbh->mutex);
-
-                switch_core_hash_insert(profile->db_hash, thread_str, dbh);
</del><ins>+        if (!(dbh = sofia_glue_get_db_handle(profile))) {
+                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
+                goto end;
</ins><span class="cx">         }
</span><span class="cx">
</span><del>- end:
</del><ins>+        switch_cache_db_persistant_execute_trans(dbh, sql, 1);
</ins><span class="cx">
</span><del>-        if (dbh) dbh->last_used = switch_epoch_time_now(NULL);
</del><ins>+ end:
+        
+        switch_cache_db_release_db_handle(&dbh);
</ins><span class="cx">
</span><del>-        switch_mutex_unlock(profile->ireg_mutex);
-
-        return dbh;
</del><ins>+        if (mutex) {
+                switch_mutex_unlock(mutex);
+        }
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-
-
</del><span class="cx"> void sofia_glue_actually_execute_sql(sofia_profile_t *profile, char *sql, switch_mutex_t *mutex)
</span><span class="cx"> {
</span><del>-        sofia_cache_db_handle_t *dbh = NULL;
</del><ins>+        switch_cache_db_handle_t *dbh = NULL;
</ins><span class="cx">
</span><span class="cx">         if (mutex) {
</span><span class="cx">                 switch_mutex_lock(mutex);
</span><span class="lines">@@ -4245,35 +4171,12 @@
</span><span class="cx">                 goto end;
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if (switch_odbc_available() && dbh->odbc_dbh) {
-                switch_odbc_statement_handle_t stmt;
-                if (switch_odbc_handle_exec(dbh->odbc_dbh, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
-                        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);
-                }
-                switch_odbc_statement_handle_free(&stmt);
-        } else if (profile->odbc_dsn) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
-        } else {
-                char *errmsg;
</del><ins>+        switch_cache_db_execute_sql(dbh, sql, NULL);
</ins><span class="cx">
</span><del>- switch_core_db_exec(dbh->db, sql, NULL, NULL, &errmsg);
-
- 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><span class="cx"> end:
</span><ins>+        
+        switch_cache_db_release_db_handle(&dbh);
</ins><span class="cx">
</span><del>-        sofia_glue_release_db_handle(&dbh);
-
</del><span class="cx">         if (mutex) {
</span><span class="cx">                 switch_mutex_unlock(mutex);
</span><span class="cx">         }
</span><span class="lines">@@ -4284,7 +4187,7 @@
</span><span class="cx"> {
</span><span class="cx">         switch_bool_t ret = SWITCH_FALSE;
</span><span class="cx">         char *errmsg = NULL;
</span><del>-        sofia_cache_db_handle_t *dbh = NULL;
</del><ins>+        switch_cache_db_handle_t *dbh = NULL;
</ins><span class="cx">         
</span><span class="cx">         if (mutex) {
</span><span class="cx">                 switch_mutex_lock(mutex);
</span><span class="lines">@@ -4294,23 +4197,17 @@
</span><span class="cx"> switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
</span><span class="cx"> goto end;
</span><span class="cx"> }
</span><ins>+        
+        switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg);
</ins><span class="cx">
</span><del>-        if (switch_odbc_available() && dbh->odbc_dbh) {
-                switch_odbc_handle_callback_exec(dbh->odbc_dbh, sql, callback, pdata, NULL);
-        } else if (profile->odbc_dsn) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
-        } else {
-                switch_core_db_exec(dbh->db, sql, callback, pdata, &errmsg);
-
-                if (errmsg) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
-                        free(errmsg);
-                }
</del><ins>+        if (errmsg) {
+                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"> end:
</span><span class="cx">
</span><del>-        sofia_glue_release_db_handle(&dbh);
</del><ins>+        switch_cache_db_release_db_handle(&dbh);
</ins><span class="cx">
</span><span class="cx">         if (mutex) {
</span><span class="cx">                 switch_mutex_unlock(mutex);
</span><span class="lines">@@ -4321,66 +4218,26 @@
</span><span class="cx">
</span><span class="cx"> char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len)
</span><span class="cx"> {
</span><del>-        switch_core_db_stmt_t *stmt;
</del><span class="cx">         char *ret = NULL;
</span><span class="cx">
</span><del>-        sofia_cache_db_handle_t *dbh = NULL;
</del><ins>+        switch_cache_db_handle_t *dbh = NULL;
</ins><span class="cx">
</span><span class="cx">         if (!(dbh = sofia_glue_get_db_handle(profile))) {
</span><span class="cx"> switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
</span><del>- goto end;
</del><ins>+                return NULL;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx">         if (mutex) {
</span><span class="cx">                 switch_mutex_lock(mutex);
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if (switch_odbc_available() && dbh->odbc_dbh) {
-                if (switch_odbc_handle_exec_string(dbh->odbc_dbh, sql, resbuf, len) == SWITCH_ODBC_SUCCESS) {
-                        ret = resbuf;
-                }
-                goto end;                
-        }
-
-        if (switch_core_db_prepare(dbh->db, sql, -1, &stmt, 0)) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Statement Error [%s]!\n", sql);
-                goto end;
-        } else {
-                int running = 1;
-                int colcount;
-
-                while (running < 5000) {
-                        int result = switch_core_db_step(stmt);
-                        const unsigned char *txt;
-
-                        if (result == SWITCH_CORE_DB_ROW) {
-                                if ((colcount = switch_core_db_column_count(stmt)) > 0) {
-                                        if ((txt = switch_core_db_column_text(stmt, 0))) {
-                                                switch_copy_string(resbuf, (char *) txt, len);
-                                                ret = resbuf;
-                                        } else {
-                                                goto end;
-                                        }
-                                }
-                                break;
-                        } else if (result == SWITCH_CORE_DB_BUSY) {
-                                running++;
-                                switch_cond_next();
-                                continue;
-                        }
-                        break;
-                }
-
-                switch_core_db_finalize(stmt);
-        }
-
- end:
-
</del><ins>+        ret = switch_cache_db_execute_sql2str(dbh, sql, resbuf, len, NULL);
+        
</ins><span class="cx">         if (mutex) {
</span><span class="cx">                 switch_mutex_unlock(mutex);
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        sofia_glue_release_db_handle(&dbh);
</del><ins>+        switch_cache_db_release_db_handle(&dbh);
</ins><span class="cx">
</span><span class="cx">         return ret;
</span><span class="cx"> }
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_core_sqldbc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_core_sqldb.c (15599 => 15600)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_core_sqldb.c        2009-11-21 17:57:55 UTC (rev 15599)
+++ freeswitch/trunk/src/switch_core_sqldb.c        2009-11-21 18:57:15 UTC (rev 15600)
</span><span class="lines">@@ -314,8 +314,6 @@
</span><span class="cx">
</span><span class="cx">         if (err) *err = NULL;
</span><span class="cx">         
</span><del>-
-
</del><span class="cx">         switch (dbh->type) {
</span><span class="cx">         case SCDB_TYPE_ODBC:
</span><span class="cx">                 {
</span><span class="lines">@@ -428,6 +426,63 @@
</span><span class="cx">
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+
+SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t *dbh, char *sql, char *str, size_t len, char **err)
+{
+        switch_status_t status = SWITCH_STATUS_FALSE;
+
+
+        switch (dbh->type) {
+        case SCDB_TYPE_CORE_DB:
+                {
+                        switch_core_db_stmt_t *stmt;
+                        
+                        if (switch_core_db_prepare(dbh->native_handle.core_db_dbh, sql, -1, &stmt, 0)) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Statement Error [%s]!\n", sql);
+                                return NULL;
+                        } else {
+                                int running = 1;
+                                int colcount;
+
+                                while (running < 5000) {
+                                        int result = switch_core_db_step(stmt);
+                                        const unsigned char *txt;
+                                        
+                                        if (result == SWITCH_CORE_DB_ROW) {
+                                                if ((colcount = switch_core_db_column_count(stmt)) > 0) {
+                                                        if ((txt = switch_core_db_column_text(stmt, 0))) {
+                                                                switch_copy_string(str, (char *) txt, len);
+                                                                status = SWITCH_STATUS_SUCCESS;
+                                                        } else {
+                                                                goto end;
+                                                        }
+                                                }
+                                                break;
+                                        } else if (result == SWITCH_CORE_DB_BUSY) {
+                                                running++;
+                                                switch_cond_next();
+                                                continue;
+                                        }
+                                        break;
+                                }
+                                
+                                switch_core_db_finalize(stmt);
+                        }
+                }
+                break;
+        case SCDB_TYPE_ODBC:
+                {
+                        status = switch_odbc_handle_exec_string(dbh->native_handle.odbc_dbh, sql, str, len);
+                }
+                break;
+        }
+
+ end:
+
+        return status == SWITCH_STATUS_SUCCESS ? str : NULL;
+
+}
+
</ins><span class="cx"> SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute(switch_cache_db_handle_t *dbh, const char *sql, uint32_t retries)
</span><span class="cx"> {
</span><span class="cx">         char *errmsg = NULL;
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>