sqlite存入中文字符

MFC在多字节集的格式下如何将带中文的字符存入sqlite?

可以先把多字符转换为Unicode

//多字符集转换为Unicode 
WCHAR* mbcsToUnicode(const char *zFilename)  
{  
	int nByte;  
	WCHAR *zMbcsFilename;  

	int codepage = AreFileApisANSI() ? CP_ACP : CP_OEMCP;  

	nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, NULL,0)*sizeof(WCHAR);  

	zMbcsFilename = (WCHAR *)malloc(nByte*sizeof(zMbcsFilename[0]));  

	if( zMbcsFilename==0 )  
	{  
		return 0;  
	}  
	nByte = MultiByteToWideChar(codepage, 0, zFilename, -1, zMbcsFilename, nByte);

	if(nByte == 0)  
	{  
		free(zMbcsFilename);  
		zMbcsFilename = 0;  
	} 
	return zMbcsFilename;  
}  

,然后再把Unicode转为UTF-8

//Unicode转为UTF-8 
char* unicodeToUtf8(const WCHAR *zWideFilename)  
{  
	int nByte; char *zFilename;  
	nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, 0, 0, 0, 0);  
	zFilename = (char *)malloc(nByte);  
	if(zFilename == 0)  
	{   
		return 0; 
	}  
	nByte = WideCharToMultiByte(CP_UTF8, 0, zWideFilename, -1, zFilename, nByte, 0, 0);  
	if( nByte == 0 )  
	{  
		free(zFilename);  
		zFilename = 0;  
	}  
	return zFilename;  
}

 

你可能感兴趣的:(unicode,乱码,数据库,c++)