Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » my_sql's charset in linux
my_sql's charset in linux [message #5351] Fri, 15 September 2006 18:49 Go to previous message
nicomesas is currently offline  nicomesas
Messages: 104
Registered: September 2006
Location: Barcelona, Spain
Experienced Member
I have been two days proving MySQL and have had a serious problem with charset.
I have a series of tables utf8 codified, and in principle it must not have very normal problems with the accents: áéíóú, ñ and other special characters in my language.
This is the sample:
#include <Core/Core.h>
#include <MySql/MySql.h>

CONSOLE_APP_MAIN
{
  String s = "SELECT nombre, refcontable FROM actividades_clases" ; 

  MySqlSession sesion ;
  if (sesion.Connect( "root", "mundoflipi", "skorg_dsrllo_v3", "localhost" ))
  {
    Sql q(sesion) ;
    q.Execute(theSelect) ;
    int row = 0;	
    while(q.Fetch())
    {
      String resp =   ;
      Cout() << "[" << row << "] " << resp << (String)q[0] << "  " << (String)q[1] << "\r\n" ;
      row++ ;
     }
     sesion.Close() ;
   }
}



Columns "nombre" can contain leters with accents, by example, my name is Nicolás.
There are a script to create the table:
CREATE TABLE `actividades_clases` (
  `code` varchar(22) collate utf8_spanish_ci NOT NULL default '',
  `nombre` varchar(30) collate utf8_spanish_ci default NULL,
  `dAdmin` varchar(2) collate utf8_spanish_ci default NULL,
  `isVentas` int(11) default NULL,
  `refContable` varchar(30) collate utf8_spanish_ci default NULL,
  PRIMARY KEY  (`code`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci;
INSERT INTO `actividades_clases` VALUES  ('0070000000000002','NICOLÁS','D',0,'DHARMA'),
 ('0070000000000003','cúlturá','F',0,'CULTURAL'),
 ('0070000000000004','DOCENCIA','F',0,'DOCENCIA'),
 ('0070000000000005','VOLUNTARIADO','?F',0,'VOLUNTARIADO'),
 ('0070000000000006','RESIDENCIA','?F',0,'CONVIVENCIA'),
 ('0070000000000007','COMEDOR','?F',0,'CONVIVENCIA'),
 ('0706401e1a6607402b3500','VENTAS','F',1,'VENTAS FUNDACIÓN'),
 ('0706401e10216c0f1c6100','ARTICULOS DEL REFUGIO','F',1,'REFUGIO');


After thinking much, to prove it in Windows (and it works correctly), to spend to me all the day of yesterday reading documentation of MySQL.com, and mainly, to dive by the code of the UPP, I believe that I have found the solution.

By some reason my MySQL does not return the characters to me in UTF, although I hoped that I took root outside. Possibly he would have to change the configuration in the server.

But the case is that there is a function of the API of MySQL that serves to change the codification of a given connection. This function is mysql_set_character_set.

Simply it would have to call to that function after establishing the connection

  MySqlSession sesion ;
  if (sesion.Connect( "root", "mundoflipi", "skorg_dsrllo_v3", "localhost" ))
  {
    mysql_set_character_set( sesion, "utf8") ;

    Sql q(sesion) ;
    q.Execute(theSelect) ;

Perhaps the MySQLSession object would have to be in charge to compare the codification that comes by defect in the server with defined by the system or the present language, that we can obtain with this code:
String sysCharSetName = CharsetName(GetDefaultCharset());

Nico

[Updated on: Fri, 15 September 2006 18:51]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Multiple fields primary key
Next Topic: SqlCtrl error linux
Goto Forum:
  


Current Time: Mon Jun 16 10:14:52 CEST 2025

Total time taken to generate the page: 0.04647 seconds