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 » Sticky problem : MySql and UTF8
Sticky problem : MySql and UTF8 [message #35044] Mon, 02 January 2012 10:56 Go to previous message
BioBytes is currently offline  BioBytes
Messages: 307
Registered: October 2008
Location: France
Senior Member
Hi alls,

Sorry to come back on a discussion that have already been developped in the forum but I still face some issues with MySql encoding UTF8.

I added the line forcing MySql encoding to UTF8 starting with opening of my application session "rmSession"

if(rmSession.Connect(cnxStr.At(3),cnxStr.At(4),"dbrisks",server,ScanInt(cnxStr.At(2),NULL,10)))
{
mysql_set_character_set(rmSession,"utf8");

SQL = rmSession;

...
}


I have an SqlArray with 7 columns linked each to a specific SqlId (fields described in Schema file). Data input are controlled by SqlCtrls (DocEdit for the first 2 columns). When I implement the action WhenAcceptEdit, I got a Sql Error telling that string encoding of the second DocEdit is incorrect if there is some accents (My application is in French).

If I delete the mysql_set_character_set(...) line, no more error when accept edit but of course the string is incorrectly encoded in the MySql table (accents are replaced with ? chararacter).

I turned this problem in another part of my source as follows. I checked the window closing and I save the current charset, forcing then charset to UTF8 then proceed SqlCtrls updating and return to saved charset. I must say that my application degfauly charset is already UTF8. So something remains undertandable for me.

[I]void rmFileDlg::Close()
{
int idRisk;
String qtfStr;

byte previousCharset = GetDefaultCharset();

try
{
if(ok.HasFocus()||(ok.HasMouse()))
{
if(GetMode()==ADD)
{
if(IsPackArrayEmpty()||IsRisksArrayEmpty())
{
qtfStr<<"[=A2*@r "<<DeQtfLf(t_("Aucune catégorie n'est cochée dans les listes de Présentation et des Risques spécifiques."))<<"]&[<10A2*@r "<<DeQtfLf(t_("Il est nécessaire de cocher des catégories de présentation et de risques pour valider un nouvel enregistrement."))<<"]";
Exclamation(qtfStr);
}
else
{
PromptOK(t_("Enregistrement du nouveau dossier et ouverture de la fiche de saisie des risques et des actions de réduction."));
SQL &numFileCtrls.Insert(TBLPROD);

for(int i=0;i<arrayPres.GetCount();i++)
if((bool)arrayPres.Get(i,2))SQL &Insert(TBLPRODPACK)(IDPRODUCT,~rmNumFileEdit)(DEVICE,As String(arrayPres.Get(i,1)));

for(int i=0;i<arrayCatSpecRisk.GetCount();i++)
if((bool)arrayCatSpecRisk.Get(i,2))
{
SQL &Select(IDRISKGEN).From(TBLRISKGEN).Where(NAME==AsString (arrayCatSpecRisk.Get(i,1)));
while(SQL.Fetch())idRisk=SQL[IDRISKGEN];

SQL.Clear();
SQL &Insert(TBLRISKGENPROD)(NUMRISKFILE,~rmNumFileEdit)(NUMG ENRISK,idRisk);
}

risksWin.SetDropLists();
risksWin.Execute();
}

}

if(GetMode()==SELECT)
{
SetDefaultCharset(CHARSET_UTF8);
SQL & numFileCtrls.UpdateModified(TBLPROD).Where(NUM==~rmNumFileEd it);
//numFileCtrls.Load(SQL,TBLPROD,NUM==~rmNumFileEdit);
numFileCtrls.ClearModify();

if(IsPackArrayModified())
{
SQL &Delete(TBLPRODPACK).Where(IDPRODUCT==~rmNumFileEdit);

for(int i=0;i<arrayPres.GetCount();i++)
if((bool)arrayPres.Get(i,2))SQL &Insert(TBLPRODPACK)(IDPRODUCT,~rmNumFileEdit)(DEVICE,As String(arrayPres.Get(i,1)));
}

if(IsRiskArrayModified())
{
SQL &Delete(TBLRISKGENPROD).Where(NUMRISKFILE==~rmNumFileEdi t);

for(int i=0;i<arrayCatSpecRisk.GetCount();i++)
if((bool)arrayCatSpecRisk.Get(i,2))
{
SQL &Select(IDRISKGEN).From(TBLRISKGEN).Where(NAME==AsString (arrayCatSpecRisk.Get(i,1)));
while(SQL.Fetch())idRisk=SQL[IDRISKGEN];

SQL.Clear();
SQL &Insert(TBLRISKGENPROD)(NUMRISKFILE,~rmNumFileEdit)(NUMG ENRISK,idRisk);
}
}
}
}

SetDefaultCharset(previousCharset);
TopWindow::Close();
}
catch(SqlExc &ex)
{
PanicMessageBox(t_("Erreur SQL"),t_("L'erreur suivante s'est produite : ")+ex.ToString());
TopWindow::Close();
}
}
[/I]

Some help or comments ?

Thank you in advance and Happy New Year with U++

Cheers
Biobytes
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Added partial support for ODBC output parameters, but the solution is ugly
Next Topic: MSSQL, default DB, datetime
Goto Forum:
  


Current Time: Sun Apr 28 19:35:06 CEST 2024

Total time taken to generate the page: 0.03302 seconds