[asterisk-addons-commits] tilghman: branch 1.6.0 r690 - in /branches/1.6.0: configs/ res/
SVN commits to the Asterisk addons project
asterisk-addons-commits at lists.digium.com
Mon Nov 10 14:25:53 CST 2008
Author: tilghman
Date: Mon Nov 10 14:25:53 2008
New Revision: 690
URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=690
Log:
Fix specification of different databases in extconfig.conf when using MySQL
backend. This fixes a regression.
(closes issue #13603)
Reported by: atis
Patches:
multi_db.patch uploaded by atis (license 242)
Modified:
branches/1.6.0/configs/res_mysql.conf.sample
branches/1.6.0/res/res_config_mysql.c
Modified: branches/1.6.0/configs/res_mysql.conf.sample
URL: http://svn.digium.com/view/asterisk-addons/branches/1.6.0/configs/res_mysql.conf.sample?view=diff&rev=690&r1=689&r2=690
==============================================================================
--- branches/1.6.0/configs/res_mysql.conf.sample (original)
+++ branches/1.6.0/configs/res_mysql.conf.sample Mon Nov 10 14:25:53 2008
@@ -6,6 +6,21 @@
; to the local host is assumed and dbsock is used instead of TCP/IP
; to connect to the server.
;
+; In addition to a [general] section, this file may also be configured
+; with separate [read] and [write] sections, which permits separation
+; of read-only queries from queries which alter the database. This
+; enables the use of master and slave replication servers for
+; scalability.
+;
+; The way this meshes with extconfig.conf is kind of tricky. If the
+; externally specified database is the same as the [read] database,
+; then reads and writes will go to the separate places as specified
+; in this file. However, if the externally specified database is
+; different than in the [read] database, then both reads and writes
+; will go to the same place, as specified. That there is only read/
+; write separation for a single set of databases will be corrected
+; in a future version of Asterisk-Addons.
+;
[general]
;dbhost = 127.0.0.1
;dbname = asterisk
Modified: branches/1.6.0/res/res_config_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/branches/1.6.0/res/res_config_mysql.c?view=diff&rev=690&r1=689&r2=690
==============================================================================
--- branches/1.6.0/res/res_config_mysql.c (original)
+++ branches/1.6.0/res/res_config_mysql.c Mon Nov 10 14:25:53 2008
@@ -100,6 +100,7 @@
char *stringp;
char *chunk;
char *op;
+ char dbname[50] = "";
const char *newparam, *newval;
struct ast_variable *var=NULL, *prev=NULL;
@@ -134,7 +135,10 @@
if ((valsz = strlen (newval)) * 2 + 1 > sizeof(buf))
valsz = (sizeof(buf) - 1) / 2;
mysql_real_escape_string(&dbread.handle, buf, newval, valsz);
- snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s '%s'", table, newparam, op, buf);
+ if (strcmp(database, dbread.name)) {
+ snprintf(dbname, sizeof(dbname), "%s.", database);
+ }
+ snprintf(sql, sizeof(sql), "SELECT * FROM %s%s WHERE %s%s '%s'", dbname, table, newparam, op, buf);
while ((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
if (!strchr(newparam, ' '))
@@ -203,6 +207,7 @@
char *stringp;
char *chunk;
char *op;
+ char dbname[50] = "";
const char *newparam, *newval;
struct ast_variable *var = NULL;
struct ast_config *cfg = NULL;
@@ -253,7 +258,10 @@
if ((valsz = strlen (newval)) * 2 + 1 > sizeof(buf))
valsz = (sizeof(buf) - 1) / 2;
mysql_real_escape_string(&dbread.handle, buf, newval, valsz);
- snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE %s%s '%s'", table, newparam, op, buf);
+ if (strcmp(database, dbread.name)) {
+ snprintf(dbname, sizeof(dbname), "%s.", database);
+ }
+ snprintf(sql, sizeof(sql), "SELECT * FROM %s%s WHERE %s%s '%s'", dbname, table, newparam, op, buf);
while ((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
if (!strchr(newparam, ' ')) op = " ="; else op = "";
@@ -322,6 +330,7 @@
my_ulonglong numrows;
char sql[512];
char buf[511]; /* Keep this size uneven as it is 2n+1. */
+ char dbname[50] = "";
int valsz;
const char *newparam, *newval;
@@ -351,7 +360,10 @@
if ((valsz = strlen (newval)) * 2 + 1 > sizeof(buf))
valsz = (sizeof(buf) - 1) / 2;
mysql_real_escape_string(&dbwrite.handle, buf, newval, valsz);
- snprintf(sql, sizeof(sql), "UPDATE %s SET %s = '%s'", table, newparam, buf);
+ if (strcmp(database, dbwrite.name)) {
+ snprintf(dbname, sizeof(dbname), "%s.", database);
+ }
+ snprintf(sql, sizeof(sql), "UPDATE %s%s SET %s = '%s'", dbname, table, newparam, buf);
while((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
if ((valsz = strlen (newval)) * 2 + 1 > sizeof(buf))
@@ -365,7 +377,7 @@
mysql_real_escape_string(&dbwrite.handle, buf, lookup, valsz);
snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " WHERE %s = '%s'", keyfield, buf);
- ast_debug(1,"MySQL RealTime: Update SQL: %s\n", sql);
+ ast_debug(1, "MySQL RealTime: Update SQL: %s\n", sql);
/* Execution. */
if (mysql_real_query(&dbwrite.handle, sql, strlen(sql))) {
@@ -379,7 +391,7 @@
numrows = mysql_affected_rows(&dbwrite.handle);
ast_mutex_unlock(&dbwrite.lock);
- ast_debug(1,"MySQL RealTime: Updated %llu rows on table: %s\n", numrows, table);
+ ast_debug(1, "MySQL RealTime: Updated %llu rows on table: %s\n", numrows, table);
/* From http://dev.mysql.com/doc/mysql/en/mysql-affected-rows.html
* An integer greater than zero indicates the number of rows affected
@@ -397,6 +409,7 @@
char buf[511]; /* Keep this size uneven as it is 2n+1. */
char fields[512];
char values[512];
+ char dbname[50] = "";
int valsz;
const char *newparam, *newval;
@@ -441,8 +454,11 @@
snprintf(values + strlen(values), sizeof(values), ", '%s'", buf);
}
va_end(ap);
- snprintf(sql, sizeof(sql), "INSERT into %s (%s) values (%s)", table, fields, values);
- ast_debug(1,"MySQL RealTime: Insert SQL: %s\n", sql);
+ if (strcmp(database, dbwrite.name)) {
+ snprintf(dbname, sizeof(dbname), "%s.", database);
+ }
+ snprintf(sql, sizeof(sql), "INSERT into %s%s (%s) values (%s)", dbname, table, fields, values);
+ ast_debug(1, "MySQL RealTime: Insert SQL: %s\n", sql);
/* Execution. */
if (mysql_real_query(&dbwrite.handle, sql, strlen(sql))) {
@@ -472,6 +488,7 @@
char sql[512];
char buf[511]; /* Keep this size uneven as it is 2n+1. */
int valsz;
+ char dbname[50] = "";
const char *newparam, *newval;
if (!table) {
@@ -500,7 +517,10 @@
if ((valsz = strlen (lookup)) * 2 + 1 > sizeof(buf))
valsz = (sizeof(buf) - 1) / 2;
mysql_real_escape_string(&dbwrite.handle, buf, lookup, valsz);
- snprintf(sql, sizeof(sql), "DELETE FROM %s WHERE %s = '%s'", table, keyfield, buf);
+ if (strcmp(database, dbwrite.name)) {
+ snprintf(dbname, sizeof(dbname), "%s.", database);
+ }
+ snprintf(sql, sizeof(sql), "DELETE FROM %s%s WHERE %s = '%s'", dbname, table, keyfield, buf);
while ((newparam = va_arg(ap, const char *))) {
newval = va_arg(ap, const char *);
if ((valsz = strlen (newval)) * 2 + 1 > sizeof(buf))
@@ -544,6 +564,7 @@
struct ast_category *cur_cat;
char sql[250] = "";
char last[80] = "";
+ char dbname[50] = "";
int last_cat_metric = 0;
ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED);
@@ -554,16 +575,18 @@
return NULL;
}
- snprintf(sql, sizeof(sql), "SELECT category, var_name, var_val, cat_metric FROM %s WHERE filename='%s' and commented=0 ORDER BY filename, cat_metric desc, var_metric asc, category, var_name, var_val, id", table, file);
-
- ast_debug(1, "MySQL RealTime: Static SQL: %s\n", sql);
-
- /* We now have our complete statement; Lets connect to the server and execute it. */
ast_mutex_lock(&dbread.lock);
if (!mysql_reconnect(&dbread)) {
ast_mutex_unlock(&dbread.lock);
return NULL;
}
+
+ if (strcmp(database, dbread.name)) {
+ snprintf(dbname, sizeof(dbname), "%s.", database);
+ }
+ snprintf(sql, sizeof(sql), "SELECT category, var_name, var_val, cat_metric FROM %s%s WHERE filename='%s' and commented=0 ORDER BY filename, cat_metric desc, var_metric asc, category, var_name, var_val, id", dbname, table, file);
+
+ ast_debug(1, "MySQL RealTime: Static SQL: %s\n", sql);
if (mysql_real_query(&dbread.handle, sql, strlen(sql))) {
ast_log(LOG_WARNING, "MySQL RealTime: Failed to query database. Check debug for more info.\n");
More information about the asterisk-addons-commits
mailing list