* options that are useful for constructing SQL statements.
*
* The strings returned by this routine should be freed by calling
- * switch_core_db_free().
+ * free().
*
* All of the usual printf formatting options apply. In addition, there
* is a "%q" option. %q works like %s in that it substitutes a null-terminated
*
* We can use this text in an SQL statement as follows:
*
- * char *z = switch_core_db_mprintf("INSERT INTO TABLES('%q')", zText);
+ * char *z = switch_mprintf("INSERT INTO TABLES('%q')", zText);
* switch_core_db_exec(db, z, callback1, 0, 0);
- * switch_core_db_free(z);
+ * free(z);
*
* Because the %q format string is used, the '\'' character in zText
* is escaped and the SQL generated is as follows:
/* malloc or DIE macros */
#ifdef NDEBUG
#define switch_malloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr )
-#define switch_zmalloc(ptr, len) (void)( (!!(ptr = malloc(len))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), memset(ptr, 0, len))
+#define switch_zmalloc(ptr, len) (void)( (!!(ptr = calloc(1, (len)))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr)
+#define switch_strdup(ptr, s) (void)( (!!(ptr = strdup(s))) || (fprintf(stderr,"ABORT! Malloc failure at: %s:%s", __FILE__, __LINE__),abort(), 0), ptr)
#else
#if (_MSC_VER >= 1500) // VC9+
#define switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr);__analysis_assume( ptr )
-#define switch_zmalloc(ptr, len) (void)(assert((ptr = malloc(len))),memset(ptr, 0, len));__analysis_assume( ptr )
+#define switch_zmalloc(ptr, len) (void)(assert((ptr = calloc(1, (len)))),ptr);__analysis_assume( ptr )
+#define switch_strdup(ptr, s) (void)(assert(((ptr) = _strdup(s)((len)))),ptr);__analysis_assume( ptr )
#else
#define switch_malloc(ptr, len) (void)(assert(((ptr) = malloc((len)))),ptr)
-#define switch_zmalloc(ptr, len) (void)(assert((ptr = malloc(len))),memset(ptr, 0, len))
+#define switch_zmalloc(ptr, len) (void)(assert((ptr = calloc(1, (len)))),ptr)
+#define switch_strdup(ptr, s) (void)(assert(((ptr) = strdup((s)))),ptr)
#endif
#endif
if (errmsg) {
stream->write_function(stream, "-ERR SQL Error [%s]\n", errmsg);
- switch_core_db_free(errmsg);
+ free(errmsg);
errmsg = NULL;
} else if (help) {
if (holder.count == 0)
if (errmsg) {
stream->write_function(stream, "-ERR SQL Error [%s]\n", errmsg);
- switch_core_db_free(errmsg);
+ free(errmsg);
errmsg = NULL;
}
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
- free(errmsg);
+ switch_core_db_free(errmsg);
}
if (db) {
switch_cache_db_release_db_handle(&db);
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Error: %s\n", errmsg);
- switch_core_db_free(errmsg);
+ free(errmsg);
if ((file = switch_channel_get_variable(channel, "eavesdrop_indicate_failed"))) {
switch_ivr_play_file(session, NULL, file, NULL);
}
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
- free(errmsg);
+ switch_core_db_free(errmsg);
}
if (db) {
if ((sql = switch_mprintf("delete from jabber_subscriptions where sub_from='%q' and sub_to='%q';", from, to))) {
mdl_execute_sql(profile, sql, profile->mutex);
- switch_core_db_free(sql);
+ free(sql);
}
break;
switch_mutex_lock(profile->mutex);
if ((sql = switch_mprintf("delete from jabber_subscriptions where sub_from='%q' and sub_to='%q'", from, to))) {
mdl_execute_sql(profile, sql, NULL);
- switch_core_db_free(sql);
+ free(sql);
}
if ((sql = switch_mprintf("insert into jabber_subscriptions values('%q','%q','%q','%q');\n",
switch_str_nil(from), switch_str_nil(to), switch_str_nil(msg), switch_str_nil(subject)))) {
mdl_execute_sql(profile, sql, NULL);
- switch_core_db_free(sql);
+ free(sql);
}
switch_mutex_unlock(profile->mutex);
if (is_special(to)) {
if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
mdl_execute_sql(profile, sql, profile->mutex);
- switch_core_db_free(sql);
+ free(sql);
}
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_IN) == SWITCH_STATUS_SUCCESS) {
if ((sql = switch_mprintf("update jabber_subscriptions set show_pres='%q', status='%q' where sub_from='%q'",
switch_str_nil(msg), switch_str_nil(subject), switch_str_nil(from)))) {
mdl_execute_sql(profile, sql, profile->mutex);
- switch_core_db_free(sql);
+ free(sql);
}
if (switch_event_create(&event, SWITCH_EVENT_PRESENCE_OUT) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "proto", MDL_CHAT_PROTO);
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
- free(errmsg);
+ switch_core_db_free(errmsg);
}
if (db) {
ret = sqlite3_exec(db, sql, callback, data, &err);
if (ret == SQLITE_BUSY || ret == SQLITE_LOCKED) {
if (sane > 1) {
- switch_safe_free(err);
+ switch_core_db_free(err);
switch_yield(100000);
continue;
}
{
switch_status_t status = SWITCH_STATUS_FALSE;
char *errmsg = NULL;
+ char *tmp = NULL;
if (dbh->io_mutex) {
switch_mutex_lock(dbh->io_mutex);
case SCDB_TYPE_CORE_DB:
{
status = switch_core_db_exec(dbh->native_handle.core_db_dbh, sql, NULL, NULL, &errmsg);
+ if (errmsg) {
+ switch_strdup(tmp, errmsg);
+ switch_core_db_free(errmsg);
+ errmsg = tmp;
+ }
}
break;
}
if (errmsg) {
dbh->last_used = switch_epoch_time_now(NULL) - (SQL_CACHE_TIMEOUT * 2);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
- free(errmsg);
+ switch_core_db_free(errmsg);
}
}
break;
len += newlen;
}
- switch_core_db_free(sql);
+ free(sql);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "SQL thread ending\n");
break;