<!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][15599] </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=15599">15599</a></dd>
<dt>Author</dt> <dd>anthm</dd>
<dt>Date</dt> <dd>2009-11-21 11:57:55 -0600 (Sat, 21 Nov 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>refactor/abstract the core sql stuff more</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcincludeswitch_coreh">freeswitch/trunk/src/include/switch_core.h</a></li>
<li><a href="#freeswitchtrunksrcswitch_corec">freeswitch/trunk/src/switch_core.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 (15598 => 15599)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/include/switch_core.h        2009-11-21 07:37:35 UTC (rev 15598)
+++ freeswitch/trunk/src/include/switch_core.h        2009-11-21 17:57:55 UTC (rev 15599)
</span><span class="lines">@@ -1926,25 +1926,71 @@
</span><span class="cx">         CDF_INUSE = (1 << 0)
</span><span class="cx"> } cache_db_flag_t;
</span><span class="cx">
</span><ins>+typedef enum {
+        SCDB_TYPE_CORE_DB,
+        SCDB_TYPE_ODBC
+} switch_cache_db_handle_type_t;
+
+typedef union {
+        switch_core_db_t *core_db_dbh;
+        switch_odbc_handle_t *odbc_dbh;        
+} switch_cache_db_native_handle_t;
+
</ins><span class="cx"> typedef struct {
</span><ins>+        char *db_path;
+} switch_cache_db_core_db_options_t;
+
+typedef struct {
+        char *dsn;
+        char *user;
+        char *pass;
+} switch_cache_db_odbc_options_t;
+
+typedef union {
+        switch_cache_db_core_db_options_t core_db_options;
+        switch_cache_db_odbc_options_t odbc_options;
+} switch_cache_db_connection_options_t;
+
+typedef struct {
</ins><span class="cx">         char name[CACHE_DB_LEN];
</span><del>-        switch_core_db_t *db;
-        switch_odbc_handle_t *odbc_dbh;
</del><ins>+        switch_cache_db_handle_type_t type;
+        switch_cache_db_native_handle_t native_handle;
</ins><span class="cx">         time_t last_used;
</span><span class="cx">         switch_mutex_t *mutex;
</span><span class="cx">         switch_memory_pool_t *pool;
</span><span class="cx">         int32_t flags;
</span><span class="cx"> } switch_cache_db_handle_t;
</span><span class="cx">
</span><ins>+
+static inline const char *switch_cache_db_type_name(switch_cache_db_handle_type_t type)
+{
+        const char *type_str = "INVALID";
+
+        switch (type) {
+        case SCDB_TYPE_ODBC:
+                {
+                        type_str = "ODBC";
+                }
+                break;
+        case SCDB_TYPE_CORE_DB:
+                {
+                        type_str = "CORE_DB";
+                }
+                break;
+        }
+
+        return type_str;
+}
+
</ins><span class="cx"> SWITCH_DECLARE(void) switch_cache_db_release_db_handle(switch_cache_db_handle_t **dbh);
</span><span class="cx"> SWITCH_DECLARE(void) switch_cache_db_destroy_db_handle(switch_cache_db_handle_t **dbh);
</span><span class="cx"> SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_handle_t **dbh,
</span><del>-                                                                                                                         const char *db_name,
-                                                                                                                         const char *odbc_user,
-                                                                                                                         const char *odbc_pass, const char *file, const char *func, int line);
-#define switch_cache_db_get_db_handle(_a, _b, _c, _d) _switch_cache_db_get_db_handle(_a, _b, _c, _d, __FILE__, __SWITCH_FUNC__, __LINE__)
</del><ins>+                                                                                                                         switch_cache_db_handle_type_t type,
+                                                                                                                         switch_cache_db_connection_options_t *connection_options,
+                                                                                                                         const char *file, const char *func, int line);
+#define switch_cache_db_get_db_handle(_a, _b) _switch_cache_db_get_db_handle(_a, _b, __FILE__, __SWITCH_FUNC__, __LINE__)
</ins><span class="cx">
</span><del>-SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_handle_t *dbh, const char *sql, char **err);
</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"> 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 class="cx">
</span><span class="lines">@@ -1953,7 +1999,7 @@
</span><span class="cx">
</span><span class="cx"> SWITCH_DECLARE(void) switch_cache_db_test_reactive(switch_cache_db_handle_t *db, const char *test_sql, const char *drop_sql, const char *reactive_sql);
</span><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><del>-SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans(switch_cache_db_handle_t *dbh, const 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"> SWITCH_DECLARE(void) switch_cache_db_detach(void);
</span><span class="cx"> SWITCH_DECLARE(uint32_t) switch_core_debug_level(void);
</span><span class="cx">
</span></span></pre></div>
<a id="freeswitchtrunksrcswitch_corec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/switch_core.c (15598 => 15599)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_core.c        2009-11-21 07:37:35 UTC (rev 15598)
+++ freeswitch/trunk/src/switch_core.c        2009-11-21 17:57:55 UTC (rev 15599)
</span><span class="lines">@@ -1470,10 +1470,17 @@
</span><span class="cx"> */
</span><span class="cx"> SWITCH_DECLARE(switch_status_t) _switch_core_db_handle(switch_cache_db_handle_t **dbh, const char *file, const char *func, int line)
</span><span class="cx"> {
</span><ins>+        switch_cache_db_connection_options_t options = { {0} };
+
</ins><span class="cx">         if (runtime.odbc_dsn && runtime.odbc_user && runtime.odbc_pass) {
</span><del>-                return _switch_cache_db_get_db_handle(dbh, runtime.odbc_dsn, runtime.odbc_user, runtime.odbc_pass, file, func, line);
</del><ins>+                options.odbc_options.dsn = runtime.odbc_dsn;
+                options.odbc_options.user = runtime.odbc_user;
+                options.odbc_options.pass = runtime.odbc_pass;
+
+                return _switch_cache_db_get_db_handle(dbh, SCDB_TYPE_ODBC, &options, file, func, line);
</ins><span class="cx">         } else {
</span><del>-                return _switch_cache_db_get_db_handle(dbh, SWITCH_CORE_DB, NULL, NULL, file, func, line);
</del><ins>+                options.core_db_options.db_path = SWITCH_CORE_DB;
+                return _switch_cache_db_get_db_handle(dbh, SCDB_TYPE_CORE_DB, &options, file, func, line);
</ins><span class="cx">         }
</span><span class="cx"> }
</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 (15598 => 15599)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/switch_core_sqldb.c        2009-11-21 07:37:35 UTC (rev 15598)
+++ freeswitch/trunk/src/switch_core_sqldb.c        2009-11-21 17:57:55 UTC (rev 15599)
</span><span class="lines">@@ -80,11 +80,19 @@
</span><span class="cx">
</span><span class="cx">                         if (switch_mutex_trylock(dbh->mutex) == SWITCH_STATUS_SUCCESS) {
</span><span class="cx">                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Dropping idle DB connection %s\n", key);
</span><del>-                                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);
</del><ins>+
+                                switch (dbh->type) {
+                                case SCDB_TYPE_ODBC:
+                                        {
+                                                switch_odbc_handle_destroy(&dbh->native_handle.odbc_dbh);
+                                        }
+                                        break;
+                                case SCDB_TYPE_CORE_DB:
+                                        {
+                                                switch_core_db_close(dbh->native_handle.core_db_dbh);
+                                                dbh->native_handle.core_db_dbh = NULL;        
+                                        }
+                                        break;
</ins><span class="cx">                                 }
</span><span class="cx">
</span><span class="cx">                                 switch_core_hash_delete(dbh_hash, key);
</span><span class="lines">@@ -121,12 +129,21 @@
</span><span class="cx">         if (dbh && *dbh) {
</span><span class="cx">                 switch_mutex_lock(dbh_mutex);
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Deleting DB connection %s\n", (*dbh)->name);
</span><del>-                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);
</del><ins>+
+                switch ((*dbh)->type) {
+                case SCDB_TYPE_ODBC:
+                        {
+                                switch_odbc_handle_destroy(&(*dbh)->native_handle.odbc_dbh);
+                        }
+                        break;
+                case SCDB_TYPE_CORE_DB:
+                        {
+                                switch_core_db_close((*dbh)->native_handle.core_db_dbh);
+                                (*dbh)->native_handle.core_db_dbh = NULL;                
+                        }
+                        break;
</ins><span class="cx">                 }
</span><ins>+
</ins><span class="cx">                 
</span><span class="cx">                 switch_core_hash_delete(dbh_hash, (*dbh)->name);                
</span><span class="cx">                 switch_mutex_unlock((*dbh)->mutex);
</span><span class="lines">@@ -165,21 +182,39 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> SWITCH_DECLARE(switch_status_t)_switch_cache_db_get_db_handle(switch_cache_db_handle_t **dbh,
</span><del>-                                                                                                                         const char *db_name, const char *odbc_user, const char *odbc_pass,
</del><ins>+                                                                                                                         switch_cache_db_handle_type_t type,
+                                                                                                                         switch_cache_db_connection_options_t *connection_options,
</ins><span class="cx">                                                                                                                          const char *file, const char *func, int line)
</span><span class="cx"> {
</span><span class="cx">         switch_thread_id_t self = switch_thread_self();
</span><span class="cx">         char thread_str[CACHE_DB_LEN] = "";
</span><span class="cx">         switch_cache_db_handle_t *new_dbh = NULL;
</span><del>-        
-        switch_assert(db_name);
</del><ins>+        const char *db_name = NULL;
</ins><span class="cx">
</span><ins>+        switch (type) {
+        case SCDB_TYPE_ODBC:
+                {
+                        db_name = connection_options->odbc_options.dsn;
+                }
+                break;
+        case SCDB_TYPE_CORE_DB:
+                {
+                        db_name = connection_options->core_db_options.db_path;
+                }
+                break;
+        }
+
+        if (!db_name) {
+                return SWITCH_STATUS_FALSE;
+        }
+
+
</ins><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><span class="cx">         if ((new_dbh = switch_core_hash_find(dbh_hash, thread_str))) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG1,
</span><del>-                                                 "Reuse Cached DB handle %s [%s]\n", thread_str, new_dbh->db ? "sqlite" : "ODBC");
</del><ins>+                                                 "Reuse Cached DB handle %s [%s]\n", thread_str, switch_cache_db_type_name(new_dbh->type));
</ins><span class="cx">         } else {
</span><span class="cx">                 switch_hash_index_t *hi;
</span><span class="cx">                 const void *var;
</span><span class="lines">@@ -195,7 +230,7 @@
</span><span class="cx">                                         switch_set_flag(new_dbh, CDF_INUSE);
</span><span class="cx">                                         switch_set_string(new_dbh->name, thread_str);
</span><span class="cx">                                         switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG1,
</span><del>-                                                                         "Reuse Unused Cached DB handle %s [%s]\n", thread_str, new_dbh->db ? "sqlite" : "ODBC");
</del><ins>+                                                                         "Reuse Unused Cached DB handle %s [%s]\n", thread_str, switch_cache_db_type_name(new_dbh->type));
</ins><span class="cx">                                         break;
</span><span class="cx">                                 }
</span><span class="cx">                         }
</span><span class="lines">@@ -208,14 +243,34 @@
</span><span class="cx">                 switch_core_db_t *db = NULL;
</span><span class="cx">                 switch_odbc_handle_t *odbc_dbh = NULL;
</span><span class="cx">
</span><del>-                if (switch_odbc_available() && db_name && odbc_user && odbc_pass) {
-                        if ((odbc_dbh = switch_odbc_handle_new(db_name, odbc_user, odbc_pass))) {
-                                if (switch_odbc_handle_connect(odbc_dbh) != SWITCH_STATUS_SUCCESS) {
-                                        switch_odbc_handle_destroy(&odbc_dbh);
</del><ins>+                switch (type) {
+                case SCDB_TYPE_ODBC:
+                        {
+
+                                if (!switch_odbc_available()) {
+                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure! OBDC NOT AVAILABLE!\n");
+                                        goto end;
</ins><span class="cx">                                 }
</span><ins>+
+                                if ((odbc_dbh = switch_odbc_handle_new(connection_options->odbc_options.dsn,
+                                                                                                         connection_options->odbc_options.user,
+                                                                                                         connection_options->odbc_options.pass))) {
+                                        if (switch_odbc_handle_connect(odbc_dbh) != SWITCH_STATUS_SUCCESS) {
+                                                switch_odbc_handle_destroy(&odbc_dbh);
+                                        }
+                                }
+                                
+
</ins><span class="cx">                         }
</span><del>-                } else {
-                        db = switch_core_db_open_file(db_name);
</del><ins>+                        break;
+                case SCDB_TYPE_CORE_DB:
+                        {
+                                db = switch_core_db_open_file(connection_options->core_db_options.db_path);
+                        }
+                        break;
+
+                default:
+                        goto end;
</ins><span class="cx">                 }
</span><span class="cx">
</span><span class="cx">                 if (!db && !odbc_dbh) {
</span><span class="lines">@@ -229,10 +284,11 @@
</span><span class="cx">                 switch_core_new_memory_pool(&pool);
</span><span class="cx">                 new_dbh = switch_core_alloc(pool, sizeof(*new_dbh));
</span><span class="cx">                 new_dbh->pool = pool;
</span><ins>+                new_dbh->type = type;
</ins><span class="cx">                 switch_set_string(new_dbh->name, thread_str);
</span><span class="cx">                 switch_set_flag(new_dbh, CDF_INUSE);
</span><span class="cx">                 
</span><del>-                if (db) new_dbh->db = db; else new_dbh->odbc_dbh = odbc_dbh;
</del><ins>+                if (db) new_dbh->native_handle.core_db_dbh = db; else new_dbh->native_handle.odbc_dbh = odbc_dbh;
</ins><span class="cx">                 switch_mutex_init(&new_dbh->mutex, SWITCH_MUTEX_UNNESTED, new_dbh->pool);
</span><span class="cx">                 switch_mutex_lock(new_dbh->mutex);
</span><span class="cx">
</span><span class="lines">@@ -258,14 +314,23 @@
</span><span class="cx">
</span><span class="cx">         if (err) *err = NULL;
</span><span class="cx">         
</span><del>-        if (switch_odbc_available() && dbh->odbc_dbh) {
-                switch_odbc_statement_handle_t stmt = NULL;
-                if ((status = switch_odbc_handle_exec(dbh->odbc_dbh, sql, &stmt)) != SWITCH_ODBC_SUCCESS) {
-                        errmsg = switch_odbc_handle_get_error(dbh->odbc_dbh, stmt);
</del><ins>+
+
+        switch (dbh->type) {
+        case SCDB_TYPE_ODBC:
+                {
+                        switch_odbc_statement_handle_t stmt = NULL;
+                        if ((status = switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, sql, &stmt)) != SWITCH_ODBC_SUCCESS) {
+                                errmsg = switch_odbc_handle_get_error(dbh->native_handle.odbc_dbh, stmt);
+                        }
+                        switch_odbc_statement_handle_free(&stmt);
</ins><span class="cx">                 }
</span><del>-                switch_odbc_statement_handle_free(&stmt);
-        } else {
- status = switch_core_db_exec(dbh->db, sql, NULL, NULL, &errmsg);
</del><ins>+                break;
+        case SCDB_TYPE_CORE_DB:
+                {
+                        status = switch_core_db_exec(dbh->native_handle.core_db_dbh, sql, NULL, NULL, &errmsg);
+                }
+                break;
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if (errmsg) {
</span><span class="lines">@@ -285,12 +350,11 @@
</span><span class="cx"> /**
</span><span class="cx"> OMFG you cruel bastards. Who chooses 64k as a max buffer len for a sql statement, have you ever heard of transactions?
</span><span class="cx"> **/
</span><del>-static switch_status_t switch_cache_db_execute_sql_chunked(switch_cache_db_handle_t *dbh, const char *sql, uint32_t chunk_size, char **err)
</del><ins>+static switch_status_t switch_cache_db_execute_sql_chunked(switch_cache_db_handle_t *dbh, char *sql, uint32_t chunk_size, char **err)
</ins><span class="cx"> {
</span><span class="cx">         switch_status_t status = SWITCH_STATUS_FALSE;
</span><span class="cx">         char *p, *s, *e;
</span><span class="cx">         int chunk_count;
</span><del>-        char *dup = NULL;
</del><span class="cx">         switch_size_t len;
</span><span class="cx">         
</span><span class="cx">         switch_assert(chunk_size);
</span><span class="lines">@@ -307,12 +371,9 @@
</span><span class="cx">                 return SWITCH_STATUS_FALSE;
</span><span class="cx">         }
</span><span class="cx">         
</span><del>-        dup = strdup(sql);
</del><ins>+        e = end_of_p(sql);
+        s = sql;
</ins><span class="cx">
</span><del>-
-        e = end_of_p(dup);
-        s = dup;
-
</del><span class="cx">         while(s && s < e) {
</span><span class="cx">                 p = s + chunk_size;
</span><span class="cx">
</span><span class="lines">@@ -340,23 +401,29 @@
</span><span class="cx">         
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        free(dup);
-
</del><span class="cx">         return status;
</span><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, const char *sql, char **err)
</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><span class="cx">
</span><del>-        if (dbh->db) {
-                status = switch_cache_db_execute_sql_real(dbh, sql, err);
-        } else {
-                status = switch_cache_db_execute_sql_chunked(dbh, (char *)sql, 32000, err);
</del><ins>+
+        switch (dbh->type) {
+        case SCDB_TYPE_CORE_DB:
+                {
+                        status = switch_cache_db_execute_sql_real(dbh, sql, err);
+                }
+                break;
+        default:
+                {
+                        status = switch_cache_db_execute_sql_chunked(dbh, (char *)sql, 32000, err);
+                }
+                break;
</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="lines">@@ -373,7 +440,7 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         while (retries > 0) {
</span><del>-                switch_cache_db_execute_sql(dbh, sql, &errmsg);
</del><ins>+                switch_cache_db_execute_sql_real(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><span class="cx">                         switch_safe_free(errmsg);
</span><span class="lines">@@ -392,7 +459,8 @@
</span><span class="cx">         return status;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-SWITCH_DECLARE(switch_status_t) switch_cache_db_persistant_execute_trans(switch_cache_db_handle_t *dbh, const 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><span class="cx">         char *errmsg = NULL;
</span><span class="cx">         switch_status_t status = SWITCH_STATUS_FALSE;
</span><span class="lines">@@ -410,7 +478,7 @@
</span><span class="cx">         while (begin_retries > 0) {
</span><span class="cx">                 again = 0;
</span><span class="cx">
</span><del>-                switch_cache_db_execute_sql(dbh, "BEGIN", &errmsg);
</del><ins>+                switch_cache_db_execute_sql_real(dbh, "BEGIN", &errmsg);
</ins><span class="cx">
</span><span class="cx">                 if (errmsg) {
</span><span class="cx">                         begin_retries--;
</span><span class="lines">@@ -423,7 +491,7 @@
</span><span class="cx">                         errmsg = NULL;
</span><span class="cx">
</span><span class="cx">                         if (again) {
</span><del>-                                switch_cache_db_execute_sql(dbh, "COMMIT", NULL);
</del><ins>+                                switch_cache_db_execute_sql_real(dbh, "COMMIT", NULL);
</ins><span class="cx">                                 goto again;
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="lines">@@ -461,7 +529,7 @@
</span><span class="cx">
</span><span class="cx"> done:
</span><span class="cx">
</span><del>-        switch_cache_db_execute_sql(dbh, "COMMIT", NULL);
</del><ins>+        switch_cache_db_execute_sql_real(dbh, "COMMIT", NULL);
</ins><span class="cx">
</span><span class="cx">         return status;
</span><span class="cx"> }
</span><span class="lines">@@ -475,17 +543,26 @@
</span><span class="cx">
</span><span class="cx">         if (err) *err = NULL;
</span><span class="cx">
</span><del>-        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);
-                
-                if (errmsg) {
-                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
-                        free(errmsg);
</del><ins>+
+
+        switch (dbh->type) {
+        case SCDB_TYPE_ODBC:
+                {
+                        status = switch_odbc_handle_callback_exec(dbh->native_handle.odbc_dbh, sql, callback, pdata, err);
</ins><span class="cx">                 }
</span><ins>+                break;
+        case SCDB_TYPE_CORE_DB:
+                {
+                        status = switch_core_db_exec(dbh->native_handle.core_db_dbh, sql, callback, pdata, &errmsg);
+                        
+                        if (errmsg) {
+                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
+                                free(errmsg);
+                        }
+                }
+                break;
</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="lines">@@ -493,37 +570,43 @@
</span><span class="cx"> {
</span><span class="cx">         char *errmsg;
</span><span class="cx">
</span><del>-        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);
</del><ins>+        switch (dbh->type) {
+        case SCDB_TYPE_ODBC:
+                {
+                        if (switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, test_sql, NULL) != SWITCH_ODBC_SUCCESS) {
+                                switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, drop_sql, NULL);
+                                switch_odbc_handle_exec(dbh->native_handle.odbc_dbh, reactive_sql, NULL);
+                        }
</ins><span class="cx">                 }
</span><del>-        } else if (dbh->db) {
-                if (test_sql) {
-                        switch_core_db_exec(dbh->db, test_sql, NULL, NULL, &errmsg);
</del><ins>+                break;
+        case SCDB_TYPE_CORE_DB:
+                {
+                        if (test_sql) {
+                                switch_core_db_exec(dbh->native_handle.core_db_dbh, test_sql, NULL, NULL, &errmsg);
</ins><span class="cx">
</span><del>-                        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);
-                                }
</del><span class="cx">                                 if (errmsg) {
</span><del>-                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\n", errmsg, reactive_sql);
</del><ins>+                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "SQL ERR [%s]\n[%s]\nAuto Generating Table!\n", errmsg, test_sql);
</ins><span class="cx">                                         switch_core_db_free(errmsg);
</span><span class="cx">                                         errmsg = NULL;
</span><ins>+                                        if (drop_sql) {
+                                                switch_core_db_exec(dbh->native_handle.core_db_dbh, 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->native_handle.core_db_dbh, 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><del>-                                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;
-                                }
</del><span class="cx">                         }
</span><span class="cx">                 }
</span><ins>+                break;
</ins><span class="cx">         }
</span><del>-
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -1016,25 +1099,33 @@
</span><span class="cx">
</span><span class="cx">         
</span><span class="cx">         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Opening DB\n");
</span><del>-        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);
-        } else {
-                char sql[512] = "";
-                char *tables[] = {"channels", "calls", "interfaces", "tasks", NULL};
-                int i;
-                const char *hostname = switch_core_get_variable("hostname");
</del><span class="cx">
</span><del>-                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);
</del><ins>+        switch (dbh->type) {
+        case SCDB_TYPE_ODBC:
+                {
+                        char sql[512] = "";
+                        char *tables[] = {"channels", "calls", "interfaces", "tasks", NULL};
+                        int i;
+                        const char *hostname = switch_core_get_variable("hostname");
+
+                        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><ins>+                break;
+        case SCDB_TYPE_CORE_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);
+                }
+                break;
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">                 
</span><span class="lines">@@ -1042,34 +1133,39 @@
</span><span class="cx">         switch_cache_db_test_reactive(dbh, "select hostname from aliases", "DROP TABLE aliases", create_alias_sql);
</span><span class="cx">         switch_cache_db_test_reactive(dbh, "select hostname from nat", "DROP TABLE nat", create_nat_sql);
</span><span class="cx">
</span><del>-        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);
-                
-        }
</del><span class="cx">
</span><del>-        if (dbh->odbc_dbh) {
-                char *err;
-
-                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;
</del><ins>+        switch (dbh->type) {
+        case SCDB_TYPE_ODBC:
+                {
+                        char *err;
+                        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, "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;
+                        }
</ins><span class="cx">                 }
</span><ins>+                break;
+        case SCDB_TYPE_CORE_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);
+                }
+                break;
</ins><span class="cx">         }
</span><ins>+        
</ins><span class="cx">
</span><span class="cx">         switch_cache_db_execute_sql(dbh, "delete from complete where sticky=0", NULL);
</span><span class="cx">         switch_cache_db_execute_sql(dbh, "delete from aliases where sticky=0", NULL);
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>