Pelles C forum

C language => Expert questions => Topic started by: Grincheux on June 15, 2020, 06:48:05 PM

Title: Import SQLite
Post by: Grincheux on June 15, 2020, 06:48:05 PM
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: [Select]
            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) ;

The txt file can be found at http://www.mediafire.com/file/y1mi4lyjgtd2sch/Distance_001.txt/file (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 (http://www.mediafire.com/file/jjsylmju833azm6/Distance_001.db3/file)

Please help me!!!
Title: Re: Import SQLite
Post by: Grincheux on June 15, 2020, 07:33:56 PM
Finaly the answer is at https://dev.w3.org/XML/encoding.c (https://dev.w3.org/XML/encoding.c)
Title: Re: Import SQLite
Post by: John Z on June 16, 2020, 11:23:41 AM
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