Solve sqlite3 Chinese garbled problem [windows]

Source: Internet
Author: User

 

# Include <stdio. h>
# Include <iostream>
# Include <string>
# Include <windows. h> // header files required for functions such as multibytetowidechar
Using namespace STD;
# Include "SQLite \ sqlite3.h"

Int importdata () // Test
{
Sqlite3 * SQLite;
Sqlite3_open ("E: \ info. DB", & SQLite); // info. DB has the varchar field line and line_name in advance.
Char STR [256] = "experiment ";
Wchar * stra;
Int I = multibytetowidechar (cp_acp, 0, (char *) STR,-1, null, 0 );
Stra = new wchar [I];
Multibytetowidechar (cp_acp, 0, (char *) STR,-1, stra, I );
I = widechartomultibyte (cp_utf8, 0, stra,-1, null, 0, null, null );
Char * strb = new char [I]; //
That is, the required type.
Widechartomultibyte (cp_utf8, 0, stra,-1, strb, I, null, null );

Char strsql [1024] = {0 };
Sprintf (strsql, "insert into line (line_name) values ('% s')", strb );

Sqlite3_stmt * stmt;
Char ** err = NULL;
Int reterr;
Sqlite3_exec (SQLite, strsql, null, null, err );

// Strb is what you want
Delete [] stra;
Delete [] strb;

Sqlite3_close (SQLite );

Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.