NO

Author Topic: Import SQLite  (Read 5664 times)

Grincheux

  • Guest
Import SQLite
« 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 and the databse is at  http://www.mediafire.com/file/jjsylmju833azm6/Distance_001.db3/file

Please help me!!!
« Last Edit: June 15, 2020, 06:50:43 PM by Grincheux »

Grincheux

  • Guest
Re: Import SQLite
« Reply #1 on: June 15, 2020, 07:33:56 PM »
Finaly the answer is at https://dev.w3.org/XML/encoding.c

Offline John Z

  • Member
  • *
  • Posts: 860
Re: Import SQLite
« Reply #2 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