Problem inserting special characters
Problem inserting special characters
Hi, everybody!
I have a problem working with MySQL and C++ Builder 6.
I can´t find the solution and I hope that maybe
somebody can help me.
I use the MyDAC components (3.50.0.20) to connect the MySQL
database (version 4.1.11) with C++ Builder. The fact
is that everything goes rigth except when I try to
write into the database. When I write special spanish
characters (accents, ñ,...) from Builder, this characters are
changed in the database, so they´re wrong. I think
that it occurs because the default character set of
C++ Builder is not supported by the MySQL database
(but I´m not sure about it). If anyone can explain me
the reason, I´ll be exceedingly grateful.
Thank you very much for your attention.
Regards,
I have a problem working with MySQL and C++ Builder 6.
I can´t find the solution and I hope that maybe
somebody can help me.
I use the MyDAC components (3.50.0.20) to connect the MySQL
database (version 4.1.11) with C++ Builder. The fact
is that everything goes rigth except when I try to
write into the database. When I write special spanish
characters (accents, ñ,...) from Builder, this characters are
changed in the database, so they´re wrong. I think
that it occurs because the default character set of
C++ Builder is not supported by the MySQL database
(but I´m not sure about it). If anyone can explain me
the reason, I´ll be exceedingly grateful.
Thank you very much for your attention.
Regards,
Hi, Ikar and Vincenzo!
I have tried the Ikar solution (set names 'latin1' after connect to the server), but it doesn´t work. In fact, the client character set is latin1 by default, so it doesn´t change anything. I need to find out the way to write spanish characters correctly in the database from builder!!! (from the same client in comand line it works perfectly)
Thanks for your help. I hope new posts!
Regards (un saluto)
I have tried the Ikar solution (set names 'latin1' after connect to the server), but it doesn´t work. In fact, the client character set is latin1 by default, so it doesn´t change anything. I need to find out the way to write spanish characters correctly in the database from builder!!! (from the same client in comand line it works perfectly)
Thanks for your help. I hope new posts!
Regards (un saluto)
Hi again!!
The problem remains!! When you talk about special char ', do you refer to the char used for including strings?
When I use the next sentences:
MyQuery1->SQL->Clear();
MyQuery1->SQL->Add("insert into datos values (2,
'Andrés Perelló Domínguez','11222444-G','1965-2-13',
'C/ España cañí, nº1','922444555','2004-1-1',
'2006-12-31','No')");
MyQuery1->Execute();
MyTable1->Refresh();
I have the mentioned problem. Doing what Vincenzo said (including \ before the ' char (or \)), doesn´t change the result. Part of this result is:
AndrÚs Perell¾ DomÝnguez (second parameter)
C/ Espa±a ca±Ý (fifth parameter)
The problem remains!! When you talk about special char ', do you refer to the char used for including strings?
When I use the next sentences:
MyQuery1->SQL->Clear();
MyQuery1->SQL->Add("insert into datos values (2,
'Andrés Perelló Domínguez','11222444-G','1965-2-13',
'C/ España cañí, nº1','922444555','2004-1-1',
'2006-12-31','No')");
MyQuery1->Execute();
MyTable1->Refresh();
I have the mentioned problem. Doing what Vincenzo said (including \ before the ' char (or \)), doesn´t change the result. Part of this result is:
AndrÚs Perell¾ DomÝnguez (second parameter)
C/ Espa±a ca±Ý (fifth parameter)
Instead of
use
If MyTable1 refers to datos, it would be correct to perform edition in the following way:
Code: Select all
MyQuery1->SQL->Clear();
MyQuery1->SQL->Add("insert into datos values (2,
'Andrés Perelló Domínguez','11222444-G','1965-2-13',
'C/ España cañí, nº1','922444555','2004-1-1',
'2006-12-31','No')");
MyQuery1->Execute();
MyTable1->Refresh();
Code: Select all
MyQuery1->SQL->Clear();
MyQuery1->SQL->Add("insert into datos values (:p1, :p2, :p3, ...)");
MyQuery1->Params[0]->AsInteger = 2;
MyQuery1->Params[1]->AsString = "Andrés Perelló Domínguez";
...
MyQuery1->Execute();
MyTable1->Refresh();
Code: Select all
MyTable1->Edit();
MyTable1->Fields[0].AsInteger := ...
MyTable1->Fields[1].AsString := ...
MyTable1->Post();
Hi!!
If I use the Ikar solution:
[C++ Error] Unit1.cpp(38): E2288 Pointer to structure required on left side of -> or ->*
Ikar, I don´t understand the second part of the code (MyTable1). Could you explain me why do you do it, please?[/code][/quote]
I have tried this way, but the problem still appears.Anonymous wrote: char Q1[512];
sprintf(Q1,"%s","insert into datos values (2,'Andrés Perelló Domínguez')");
MyQuery1->SQL->Clear();
MyQuery1->SQL->Add(Q1);
MyQuery1->Execute();
If I use the Ikar solution:
I have the next error compiling:MyQuery1->SQL->Clear();
MyQuery1->SQL->Add("insert into datos values (:p1, :p2, :p3, ...)");
MyQuery1->Params[0]->AsInteger = 2;
MyQuery1->Params[1]->AsString = "Andrés Perelló Domínguez";
...
MyQuery1->Execute();
MyTable1->Refresh();
[C++ Error] Unit1.cpp(38): E2288 Pointer to structure required on left side of -> or ->*
Ikar, I don´t understand the second part of the code (MyTable1). Could you explain me why do you do it, please?[/code][/quote]
> MyQuery1->Params[0]->AsInteger = 2;
This is a misprint. Use instead
MyQuery1->Params->Items[0]->AsInteger = 2
> Ikar, I don´t understand the second part of the code (MyTable1).
> Could you explain me why do you do it, please?
This is a standard method for data editing on CBuilder. Detailed information about used methods you can see in CBuilder help
This is a misprint. Use instead
MyQuery1->Params->Items[0]->AsInteger = 2
> Ikar, I don´t understand the second part of the code (MyTable1).
> Could you explain me why do you do it, please?
This is a standard method for data editing on CBuilder. Detailed information about used methods you can see in CBuilder help