switch from utf8 to utf8mb4 on the database level

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO
2017-06-24 06:07:38 +00:00
parent 44760a7e0f
commit 1a0acb0185
10 changed files with 39 additions and 28 deletions

View File

@ -88,6 +88,7 @@ struct _parse_rule config_parse_rules[] =
{ "min_message_size", "integer", (void*) int_parser, offsetof(struct __config, min_message_size), "100", sizeof(int)},
{ "min_word_len", "integer", (void*) int_parser, offsetof(struct __config, min_word_len), "1", sizeof(int)},
{ "mmap_dedup_test", "integer", (void*) int_parser, offsetof(struct __config, mmap_dedup_test), "0", sizeof(int)},
{ "mysqlcharset", "string", (void*) string_parser, offsetof(struct __config, mysqlcharset), "utf8mb4", MAXVAL-1},
{ "mysqlhost", "string", (void*) string_parser, offsetof(struct __config, mysqlhost), "", MAXVAL-1},
{ "mysqlport", "integer", (void*) int_parser, offsetof(struct __config, mysqlport), "", sizeof(int)},
{ "mysqlsocket", "string", (void*) string_parser, offsetof(struct __config, mysqlsocket), "/tmp/mysql.sock", MAXVAL-1},

View File

@ -65,6 +65,7 @@ struct __config {
// mysql stuff
char mysqlcharset[MAXVAL];
char mysqlhost[MAXVAL];
int mysqlport;
char mysqlsocket[MAXVAL];

View File

@ -11,6 +11,7 @@
int open_database(struct session_data *sdata, struct __config *cfg){
int rc=1;
char buf[BUFLEN];
mysql_init(&(sdata->mysql));
@ -22,8 +23,11 @@ int open_database(struct session_data *sdata, struct __config *cfg){
return ERR;
}
mysql_real_query(&(sdata->mysql), "SET NAMES utf8", strlen("SET NAMES utf8"));
mysql_real_query(&(sdata->mysql), "SET CHARACTER SET utf8", strlen("SET CHARACTER SET utf8"));
snprintf(buf, sizeof(buf)-2, "SET NAMES %s", cfg->mysqlcharset);
mysql_real_query(&(sdata->mysql), buf, strlen(buf));
snprintf(buf, sizeof(buf)-2, "SET CHARACTER SET %s", cfg->mysqlcharset);
mysql_real_query(&(sdata->mysql), buf, strlen(buf));
return OK;
}