Page 1 of 1

4.2 Beta - SQLite problem with unicode characters

Posted: Sun Apr 06, 2008 4:41 pm
by thanos
Hello to everyone.
I'm a PureBasic newbie and i tried to made a simple application which retrieves data from a SQLite database.

When i try to retrieve the data from one table i always take the following results:
Image

Instead of the correct:
Image
(The above screen is from a SQLite data manager).

I already choose UTF-8 at the Compiler Options on the PureBasic environment.

Beyond the SQLite manager i opened my database file with notepad and i took the following text:
3 00-00-03 ΠΑΠΑΙΩΑΝΝΟΥΚΥΡΙΑΚΟΣ
which is correct.
I checked the database's encoding using the sqlite-manager addin for Firefox (http://code.google.com/p/sqlite-manager/) and it is UTF-8.
I also wrote a simple wrapper in Visual Basic to check the data using sample VB data controls. The data was displayed correctly.
Do you have any idea how can i fix this problem?


Thanos


Here is my code:

Code: Select all

EnableExplicit
Declare DoEvents()
Declare WindowProc()

Enumeration
#MainWindow
#ListIcon
#ProgressBar
#FontForListIcon
EndEnumeration

;- Constants
#Database = 0
#Total_Records = 15 ;- Just set a limit on retrieving records

;- Variables
Global Result.l
Global SQLiteDatabaseName$ = "C:\Aktinologos.db"
Global User$ = ""
Global Password$ = ""
Global CurrentRec.l = 0
Global strOutPut.s
Global Epwnymo.s
Global Epwnymo_uc.s

;-Start
Result = UseSQLiteDatabase()
If Result
  Result = OpenDatabase(#Database, SQLiteDatabaseName$, User$, Password$)
  If Result
    If DatabaseQuery ( #Database , " SELECT * FROM Prom_Pel")
      WindowProc() ;- Open the main gui
      ;-
      CurrentRec = 1
      While NextDatabaseRow(#Database) ;- Loop for each record
        strOutPut = ""
        strOutPut + GetDatabaseString(#Database, 1)
        strOutPut + Chr(10) + GetDatabaseString(#Database, 2) + Chr(10) + GetDatabaseString(#Database, 3)
        strOutPut + Chr(10) + GetDatabaseString(#Database, 4) + Chr(10)
        ;- Check if is it necessary to terminate the loop
        If CurrentRec > #Total_Records
          Break ;- Exit loop
        EndIf
        AddGadgetItem(#ListIcon, -1, strOutPut)
        CurrentRec + 1
        SetGadgetState(#ProgressBar, CurrentRec)   ;- Update progress bar value
        DoEvents() ;- Return control to the system
      Wend
      ;- End of retrieval
      Repeat
      Until WaitWindowEvent() = #PB_Event_CloseWindow
    Else
      MessageRequester("Error", "Bad query")
    EndIf
  Else
    MessageRequester("Error", "No Database")
  EndIf
Else
  MessageRequester("Error", "Bad initialization of SQLite")
EndIf
CloseDatabase(#Database)
End


Procedure WindowProc()
  OpenWindow(#MainWindow, 0, 0, 645, 600, "Πελατολόγιο...", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  CreateGadgetList(WindowID(#MainWindow))
  ListIconGadget(#ListIcon, 0, 0, 645, 570, "Κωδικός (ID)", 120, #PB_ListIcon_GridLines|#PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect)
  AddGadgetColumn(#ListIcon, 1, "Επώνυμο (Last Name)", 100)
  AddGadgetColumn(#ListIcon, 2, "Όνομα (First Name)", 100)
  LoadFont(#FontForListIcon, "Courier New", 10, #PB_Font_HighQuality)
  SetGadgetFont(#ListIcon,FontID(#FontForListIcon))
  ProgressBarGadget(#ProgressBar, 5, 575,  435, 20, 0, #Total_Records) ;, #PB_ProgressBar_Smooth)
EndProcedure


Procedure DoEvents()
  Protected MSG.msg
  msg.MSG
  If PeekMessage_(msg,0,0,0,1)
    TranslateMessage_(msg)
    DispatchMessage_(msg)
  Else
    Sleep_(1)
  EndIf
EndProcedure

Posted: Sun Apr 06, 2008 4:53 pm
by Progi1984
Small question : Have you compiled your code in Unicode mode ?

Posted: Sun Apr 06, 2008 4:58 pm
by thanos
Thanks for your reply.
Progi1984 wrote:Small question : Have you compiled your code in Unicode mode ?
Yes, i compiled my code in unicode mode.

Posted: Sat May 24, 2008 5:51 pm
by thanos
The problem solved :D

I tried many alternatives.
Finally i downloaded the SQLite Manager (this is a free add on for the Mozilla Firefox), i created a new database, i choose the UTF-8 as the codepage for the database, i create the structure and i saved the database.
Then i wrote a small program in PureBasic to transfer the data from my old database to the new one.
It is worked correctly.
Regards,

Thanos