C language > Expert questions

Import SQLite

(1/1)

Grincheux:
I have a txt file that I want to import to create a SQLite database.
The C coding is good, import works except one thing:
I am French, so ther are accents in words.
When looking with Notepad++ the text file is in ANSI and would have to be in UTF-8.
How to convert, I tried with WideCharToMultiByte and with code page 28605(iso-8859-15
ISO 8859-15 Latin 9), this not correct for sqlite. When I import the txt file manually using "DB Broowser for SQLIte", it is good. Here is my coding:

--- Code: ---            sqlite3_snprintf(sizeof(_szTmp),_szTmp,
                        "INSERT INTO Distance VALUES(%d%7.7d,%d,%d,%d,%f,%f,\"%w\",%d,%d,%d,%f,%f,\"%w\",%f);",
                        Communes[_i].iDepartement,_iNumRec,
                        _iCode_Insee_1,
                        Communes[_i].iRegion,
                        Communes[_i].iDepartement,
                        _dLatitude1,_dLongitude1,
                        Communes[_i].szNomCommune,
                        _iCode_Insee_2,
                        Communes[_j].iRegion,
                        Communes[_j].iDepartement,
                        _dLatitude2,_dLongitude2,
                        Communes[_j].szNomCommune,
                        dDistance[_j]) ;

                  sqlite3_exec(hParser,_szTmp,0,0,NULL) ;

--- End code ---

The txt file can be found at http://www.mediafire.com/file/y1mi4lyjgtd2sch/Distance_001.txt/file and the databse is at  http://www.mediafire.com/file/jjsylmju833azm6/Distance_001.db3/file

Please help me!!!

Grincheux:
Finaly the answer is at https://dev.w3.org/XML/encoding.c

John Z:
Very useful code link. Especially useful is the CheckUTF8 routine.  Thanks!

If you would like to use the built in functions I believe it is a two step process.
First you use MultiByteToWideChar to get a Unicode string then you pass that to
WideCharToMultiByte using CP_UTF8 to get your final string.


Hope this helps,
John

Navigation

[0] Message Index

Go to full version