[asterisk-addons-commits] tilghman: trunk r707 - in /trunk: cdr/ configs/
SVN commits to the Asterisk addons project
asterisk-addons-commits at lists.digium.com
Thu Dec 11 15:16:12 CST 2008
Author: tilghman
Date: Thu Dec 11 15:16:11 2008
New Revision: 707
URL: http://svn.digium.com/view/asterisk-addons?view=rev&rev=707
Log:
Allow setting the MySQL character set on each connect.
(closes issue #13775)
Reported by: sergee
Patches:
cdr_mysql_charset-r679-v2.diff uploaded by sergee (license 138)
Modified:
trunk/cdr/cdr_addon_mysql.c
trunk/configs/cdr_mysql.conf.sample
Modified: trunk/cdr/cdr_addon_mysql.c
URL: http://svn.digium.com/view/asterisk-addons/trunk/cdr/cdr_addon_mysql.c?view=diff&rev=707&r1=706&r2=707
==============================================================================
--- trunk/cdr/cdr_addon_mysql.c (original)
+++ trunk/cdr/cdr_addon_mysql.c Thu Dec 11 15:16:11 2008
@@ -59,7 +59,7 @@
static char *name = "mysql";
static char *config = "cdr_mysql.conf";
-static struct ast_str *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL, *dbsock = NULL, *dbtable = NULL;
+static struct ast_str *hostname = NULL, *dbname = NULL, *dbuser = NULL, *password = NULL, *dbsock = NULL, *dbtable = NULL, *dbcharset = NULL;
static struct ast_str *ssl_ca = NULL, *ssl_cert = NULL, *ssl_key = NULL;
@@ -186,6 +186,11 @@
connected = 1;
connect_time = time(NULL);
records = 0;
+ if (dbcharset) {
+ snprintf(sql1, sizeof(sql1), "SET NAMES '%s'", dbcharset->str);
+ mysql_real_query(&mysql, sql1, strlen(sql1));
+ ast_debug(1, "SQL command as follows: %s\n", sql1);
+ }
} else {
ast_log(LOG_ERROR, "Cannot connect to database server %s: (%d) %s\n", hostname->str, mysql_errno(&mysql), mysql_error(&mysql));
connected = 0;
@@ -446,6 +451,8 @@
res |= my_load_config_string(cfg, "global", "table", &dbtable, "cdr");
res |= my_load_config_string(cfg, "global", "password", &password, "");
+ res |= my_load_config_string(cfg, "global", "charset", &dbcharset, "");
+
res |= my_load_config_string(cfg, "global", "ssl_ca", &ssl_ca, "");
res |= my_load_config_string(cfg, "global", "ssl_cert", &ssl_cert, "");
res |= my_load_config_string(cfg, "global", "ssl_key", &ssl_key, "");
@@ -478,6 +485,10 @@
ast_debug(1, "Got dbname of %s\n", dbname->str);
ast_debug(1, "Got password of %s\n", password->str);
ast_debug(1, "%sunning in calldate compatibility mode\n", calldate_compat ? "R" : "Not r");
+
+ if (dbcharset) {
+ ast_debug(1, "Got DB charste of %s\n", dbcharset->str);
+ }
mysql_init(&mysql);
@@ -505,6 +516,11 @@
connected = 1;
records = 0;
connect_time = time(NULL);
+ if (dbcharset) {
+ snprintf(sqldesc, sizeof(sqldesc), "SET NAMES '%s'", dbcharset->str);
+ mysql_real_query(&mysql, sqldesc, strlen(sqldesc));
+ ast_debug(1, "SQL command as follows: %s\n", sqldesc);
+ }
/* Get table description */
snprintf(sqldesc, sizeof(sqldesc), "DESC %s", dbtable ? dbtable->str : "cdr");
Modified: trunk/configs/cdr_mysql.conf.sample
URL: http://svn.digium.com/view/asterisk-addons/trunk/configs/cdr_mysql.conf.sample?view=diff&rev=707&r1=706&r2=707
==============================================================================
--- trunk/configs/cdr_mysql.conf.sample (original)
+++ trunk/configs/cdr_mysql.conf.sample Thu Dec 11 15:16:11 2008
@@ -18,6 +18,11 @@
;user=asteriskcdruser
;port=3306
;sock=/tmp/mysql.sock
+;
+; If your system's locale differs from mysql database character set,
+; cdr_mysql can damage non-latin characters in CDR variables. Use this
+; option to protect your data.
+;charset=koi8r
;
; Older versions of cdr_mysql set the calldate field to whenever the
; record was posted, rather than the start date of the call. This flag
More information about the asterisk-addons-commits
mailing list