1.strlen()求的是字节长度
_tcsclen()求的是所看到的汉字以及字母个数
例如:strlen("你好") == 4;
_tcsclen("你好") == 2;
2.多字符集->unicode->utf8
TCHAR* CTerAdd::Convert(CHAR* tmpSql)
{
DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, tmpSql, -1, NULL, 0);
wchar_t *pwText;
pwText = new wchar_t[dwNum];
memset(pwText,0,dwNum);
MultiByteToWideChar(CP_ACP,0,tmpSql,-1,pwText,dwNum);
DWORD nLength = WideCharToMultiByte(CP_UTF8,0,pwText,-1,NULL,0,NULL,NULL);
TCHAR* buffer = new TCHAR[nLength];
memset(buffer,0,nLength);
WideCharToMultiByte(CP_UTF8,0,pwText,-1,buffer,nLength,NULL,NULL);
// //delete [] buffer;
delete [] pwText;
return buffer;
}
3.mysql administrator
程序里转换前代码:
insert into terminal_info(ter_sn,tel_no,sim_no,gps_no,type,comm_type,setup_date,manufacturer) values('111','222','333','444','555','666','08-12-20 17:25:16','测试')
经过上面函数Convert()转化,返回
insert into terminal_info(ter_sn,tel_no,sim_no,gps_no,type,comm_type,setup_date,manufacturer) values('111','222','333','444','555','666','08-12-20 17:25:16','娴嬭瘯')
添加成功后在查看manufacturer字段为 ‘娴嬭瘯’
如果把插入语句insert into terminal_info(ter_sn,tel_no,sim_no,gps_no,type,comm_type,setup_date,manufacturer) values('111','222','333','444','555','666','08-12-20 17:25:16','娴嬭瘯')在cmd下面执行再administrator查看为“测试”如果执行前set
names gbk;再插入就则为'娴嬭瘯‘。
4.错误Data too long for column 'color' at row 1
说明再clolor字段不符合要求,比如该字符集不能够满足要插入的字符,经查看,改color字段,latin1 为utf8,OK.