Date: Thursday, January 26, 2006 @ 11:21:04
Author: csaba
Path: /cvsroot/carob/libmysequoia/src
Modified: CarobMySQL.cpp (1.35 -> 1.36) MySQLAPI.cpp (1.32 -> 1.33)
Set the character set.
----------------+
CarobMySQL.cpp | 64 ++++++++++++++++++++++++++++++++++++++-----------------
MySQLAPI.cpp | 3 --
2 files changed, 46 insertions(+), 21 deletions(-)
Index: libmysequoia/src/CarobMySQL.cpp
diff -u libmysequoia/src/CarobMySQL.cpp:1.35
libmysequoia/src/CarobMySQL.cpp:1.36
--- libmysequoia/src/CarobMySQL.cpp:1.35 Wed Jan 25 11:58:42 2006
+++ libmysequoia/src/CarobMySQL.cpp Thu Jan 26 11:21:04 2006
@@ -49,6 +49,9 @@
mysql->protocol_version = PROTOCOL_VERSION;
// TODO fill in other required mysql fields
+ // force reading the my.cnf file
+ mysql->options.my_cnf_group = cstrdup("client");
+
mysqlPtr = mysql;
LOG4CXX_DEBUG(logger, "Leaving constructor.");
@@ -67,12 +70,14 @@
FREE_AND_NULL_ARRAY(mysqlPtr->host_info);
FREE_AND_NULL_ARRAY(mysqlPtr->info);
- FREE_AND_NULL(mysqlPtr->options.my_cnf_file);
- FREE_AND_NULL(mysqlPtr->options.my_cnf_group);
- FREE_AND_NULL(mysqlPtr->options.host);
- FREE_AND_NULL(mysqlPtr->options.user);
- FREE_AND_NULL(mysqlPtr->options.password);
- FREE_AND_NULL(mysqlPtr->options.db);
+ FREE_AND_NULL_ARRAY(mysqlPtr->options.my_cnf_file);
+ FREE_AND_NULL_ARRAY(mysqlPtr->options.my_cnf_group);
+ FREE_AND_NULL_ARRAY(mysqlPtr->options.host);
+ FREE_AND_NULL_ARRAY(mysqlPtr->options.user);
+ FREE_AND_NULL_ARRAY(mysqlPtr->options.password);
+ FREE_AND_NULL_ARRAY(mysqlPtr->options.db);
+ FREE_AND_NULL_ARRAY(mysqlPtr->options.charset_name);
+ FREE_AND_NULL_ARRAY(mysqlPtr->options.charset_dir);
mysqlPtr->options.port = 0;
mysqlPtr->field_alloc.used = 0;
@@ -98,8 +103,8 @@
if (mysqlPtr->options.my_cnf_file || mysqlPtr->options.my_cnf_group)
{
read_ini_file();
- FREE_AND_NULL(mysqlPtr->options.my_cnf_file);
- FREE_AND_NULL(mysqlPtr->options.my_cnf_group);
+ FREE_AND_NULL_ARRAY(mysqlPtr->options.my_cnf_file);
+ FREE_AND_NULL_ARRAY(mysqlPtr->options.my_cnf_group);
}
if (unix_socket)
@@ -142,6 +147,10 @@
port = 25322;
}
+ /* set the default character set if not set */
+ if (!mysqlPtr->options.charset_name)
+ mysqlPtr->options.charset_name = cstrdup("latin1");
+
/* Check for delayed connection. If db name not given, the connection can't
happen, because sequoia doesn't support it.
* The real connection will happen after the user call the command
mysql_select_db or mysql_real_connect */
if (!db || !*db)
@@ -825,13 +834,12 @@
LOG4CXX_DEBUG(logger, "Leaving delete_row_data.");
}
-
void
CarobMYSQL::read_ini_file()
{
char *group;
- string def_home_env = string(getenv("DEFAULT_HOME_ENV")) + "/my.cnf";
- string home_dir = string(getenv("HOME")) + "/.my.cnf";
+ char *def_home_env = getenv("DEFAULT_HOME_ENV");
+ char *home_dir = getenv("HOME");
IniParser ini;
/*
@@ -844,21 +852,39 @@
*/
ini.parseFile("/etc/my.cnf");
- ini.parseFile(def_home_env.c_str());
+ if (def_home_env)
+ {
+ string s = string(def_home_env) + "/my.cnf";
+ ini.parseFile(s.c_str());
+ }
ini.parseFile("my.cnf");
- ini.parseFile(home_dir.c_str());
- ini.parseFile(mysqlPtr->options.my_cnf_file);
+ if (home_dir)
+ {
+ string s = string(home_dir) + "/.my.cnf";
+ ini.parseFile(s.c_str());
+ }
+ if (mysqlPtr->options.my_cnf_file)
+ ini.parseFile(mysqlPtr->options.my_cnf_file);
if (mysqlPtr->options.my_cnf_group && *mysqlPtr->options.my_cnf_group)
group = mysqlPtr->options.my_cnf_group;
else
group = "client";
- mysqlPtr->options.host = cstrdup(ini.get(group, "host").c_str());
- mysqlPtr->options.user = cstrdup(ini.get(group, "user").c_str());
- mysqlPtr->options.password = cstrdup(ini.get(group, "password").c_str());
- mysqlPtr->options.db = cstrdup(ini.get(group, "db").c_str());
+ /*
+ * read the host, user, password, db, default-character-set,
character-sets-dir, port
+ * from the config file
+ */
+ cstrdupcond(mysqlPtr->options.host, ini.get(group, "host").c_str());
+ cstrdupcond(mysqlPtr->options.user, ini.get(group, "user").c_str());
+ cstrdupcond(mysqlPtr->options.password, ini.get(group, "password").c_str());
+ cstrdupcond(mysqlPtr->options.db, ini.get(group, "db").c_str());
mysqlPtr->options.port = atoi(ini.get(group, "port").c_str());
-
+ if (!mysqlPtr->options.charset_name || !*mysqlPtr->options.charset_name)
+ cstrdupcond(mysqlPtr->options.charset_name, ini.get(group,
"default-character-set").c_str());
+ if (!mysqlPtr->options.charset_dir || !*mysqlPtr->options.charset_dir)
+ cstrdupcond(mysqlPtr->options.charset_dir, ini.get(group,
"character-sets-dir").c_str());
+
+ /* read the init_command from the config file */
push_init_command(ini.get(group, "init_command").c_str());
}
Index: libmysequoia/src/MySQLAPI.cpp
diff -u libmysequoia/src/MySQLAPI.cpp:1.32 libmysequoia/src/MySQLAPI.cpp:1.33
--- libmysequoia/src/MySQLAPI.cpp:1.32 Wed Jan 25 09:46:23 2006
+++ libmysequoia/src/MySQLAPI.cpp Thu Jan 26 11:21:04 2006
@@ -838,8 +838,7 @@
{
LOG4CXX_DEBUG(logger, "Entering mysql_character_set_name: mysql=" << mysql);
- // TODO implementation
- char *result = 0;
+ char *result = mysql->options.charset_name;
LOG4CXX_DEBUG(logger, "Leaving mysql_character_set_name: result=" << result);
return result;
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits