static PyObject* wsql_connection_get_charset_info(wsql_connection *self, void* closure) { PyObject *result, *tmp; MY_CHARSET_INFO cs; CHECK_CONNECTION(self, NULL); mysql_get_character_set_info(&(self->connection), &cs); if (!(result = PyDict_New())) return NULL; #define SET_ITEM_STRING(k, v) \ if (v) { tmp = PyString_FromString(v); PyDict_SetItemString(result, k, tmp); Py_DECREF(tmp); } SET_ITEM_STRING("name", cs.csname); SET_ITEM_STRING("collation", cs.name); SET_ITEM_STRING("comment", cs.comment); SET_ITEM_STRING("dir", cs.dir); #undef SET_ITEM_STRING #define SET_ITEM_LONG(k, v) \ { tmp = PyLong_FromLong(v); PyDict_SetItemString(result, k, tmp); Py_DECREF(tmp); } SET_ITEM_LONG("mbminlen", cs.mbminlen); SET_ITEM_LONG("mbmaxlen", cs.mbmaxlen); #undef SET_ITEM_LONG return result; }
BOOL connectDB(void) { MY_CHARSET_INFO cs; if (( mysql_conn = mysql_init(NULL)) == NULL) { fprintf (stderr, "Initializing mysql-library failed\n"); return (FALSE); } if ( mysql_real_connect (mysql_conn, db_host, db_user, db_pass, db_dbname, 0, NULL, CLIENT_COMPRESS) == NULL ) { /* connection failed */ fprintf (stderr, "Connection to %s failed with error:\n\t%s\n", db_host, mysql_error(mysql_conn)); return (FALSE); } printD ("Connection to:%s succeeded.\n", db_host); if (mysql_set_character_set(mysql_conn, "UTF8") != 0) { fprintf (stderr, "Error while setting mysql character set to utf-8\n"); } if (do_debug) { mysql_get_character_set_info(mysql_conn, &cs); printD("character set information:\n"); printD("character set name: %s\n", cs.name); printD("collation name: %s\n", cs.csname); printD("comment: %s\n", cs.comment); printD("directory: %s\n", cs.dir); printD("multi byte character min. length: %d\n", cs.mbminlen); printD("multi byte character max. length: %d\n", cs.mbmaxlen); } return (TRUE); }
int test_client_character_set(MYSQL *mysql) { MY_CHARSET_INFO cs; char *csname= (char*) "utf8"; char *csdefault= (char*)mysql_character_set_name(mysql); FAIL_IF(mysql_set_character_set(mysql, csname), mysql_error(mysql)); mysql_get_character_set_info(mysql, &cs); FAIL_IF(strcmp(cs.csname, "utf8") || strcmp(cs.name, "utf8_general_ci"), "Character set != UTF8"); FAIL_IF(mysql_set_character_set(mysql, csdefault), mysql_error(mysql)); return OK; }
static JSVAL get_character_set_info(JSARGS args) { HandleScope scope; MYSQL *handle = (MYSQL *) args[0]->IntegerValue(); MY_CHARSET_INFO cs; mysql_get_character_set_info(handle, &cs); JSOBJ o = Object::New(); o->Set(String::New("number"), Integer::New(cs.number)); o->Set(String::New("name"), String::New(cs.name)); o->Set(String::New("csname"), String::New(cs.csname)); o->Set(String::New("comment"), String::New(cs.comment)); o->Set(String::New("dir"), String::New(cs.dir)); o->Set(String::New("mbminlen"), Integer::New(cs.mbminlen)); o->Set(String::New("mbmaxlen"), Integer::New(cs.mbmaxlen)); return scope.Close(o); }