Page 1 of 2

Kanji Dictionary in SQLite

Posted: Sat Sep 15, 2007 2:48 am
by pdwyer
I got a couple of PM's about the source for this so I'll post it here.

The app is not really very amazing, it's just a kanji database I put together off the free EDICT text from Monasch University.

the first char in the search text is check for kanji/hiragana/english and the search based on that. the code is a very simple example of SQLite without the wrappers. The zip file below the screenshot contains the exe, database and sqlite dll, just copy to a folder and run as is.

Image

http://www.dwyer-family.net/download/kanji.zip

Source is below. Anyone have any improvements or suggestions (like, "don't update gui's from callbacks because it dangerous") please let me know, there's not a lot of error checking either.

Code: Select all


#SQLITE3_ISO8859         =   1   ;
#SQLITE3_OK              =   0   ;'*/ Successful result */
#SQLITE3_ERROR           =   1   ;'*/ SQL error or missing database */
#SQLITE3_INTERNAL        =   2   ;'*/ An internal logic error in SQLite */
#SQLITE3_PERM            =   3   ;'*/ Access permission denied */
#SQLITE3_ABORT           =   4   ;'*/ Callback routine requested an abort */
#SQLITE3_BUSY            =   5   ;'*/ The database file is locked */
#SQLITE3_LOCKED          =   6   ;'*/ A table in the database is locked */
#SQLITE3_NOMEM           =   7   ;'*/ A malloc() failed */
#SQLITE3_READONLY        =   8   ;'*/ Attempt to write a readonly database */
#SQLITE3_INTERRUPT       =   9   ;'*/ Operation terminated by sqlite3_interrupt() */
#SQLITE3_IOERR           =   10   ;'*/ Some kind of disk I/O error occurred */
#SQLITE3_CORRUPT         =   11   ;'*/ The database disk image is malformed */
#SQLITE3_NOTFOUND        =   12   ;'*/ (Internal Only) Table or record not found */
#SQLITE3_FULL            =   13   ;'*/ Insertion failed because database is full */
#SQLITE3_CANTOPEN        =   14   ;'*/ Unable to open the database file */
#SQLITE3_PROTOCOL        =   15   ;'*/ Database lock protocol error */
#SQLITE3_EMPTY           =   16   ;'*/ (Internal Only) Database table is empty */
#SQLITE3_SCHEMA          =   17   ;'*/ The database schema changed */
#SQLITE3_TOOBIG          =   18   ;'*/ Too much data for one row of a table */
#SQLITE3_CONSTRAINT      =   19   ;'*/ Abort due to contraint violation */
#SQLITE3_MISMATCH        =   20   ;'*/ Data type mismatch */
#SQLITE3_MISUSE          =   21   ;'*/ Library used incorrectly */
#SQLITE3_NOLFS           =   22   ;'*/ Uses OS features not supported on host */
#SQLITE3_AUTH            =   23   ;'*/ Authorization denied */
#SQLITE3_ROW             =   100  ;'*/ sqlite3_step() has another row ready */
#SQLITE3_DONE            =   101  ;'*/ sqlite3_step() has finished executing */

#SQL_LIB = 1 ; dll ID

;- Window Constants
Enumeration
  #FrmMain
EndEnumeration

;- Gadget Constants
Enumeration
  #String_0
  #CMD_Search
  #Listview_0
  #CMD_Paste
  #Chk_ExactSearch
  #StatusBar_0
EndEnumeration

Enumeration
    #English
    #Kanji
    #Hiragana
EndEnumeration

Declare ProcSQL(SQL.s)
Declare CallBack_ReturnRows(NullPtr.l,ArgCount.l,*Values.l, *ColNames.l)
Declare Open_FrmMain()
Declare CmdSearch(SearchType.l, Keyword.s, Exact.l)
Declare.l GetTextType(SearchText.s)

Global RowCount.l
Global FontID1
FontID1 = LoadFont(1, "MS Sans Serif", 11)

OpenLibrary(#SQL_LIB, "sqlite3.dll")
Open_FrmMain()
CloseLibrary(#SQL_LIB)

Procedure Open_FrmMain()

    If OpenWindow(#FrmMain, 305, 168, 571, 445, "QuickSearch Kanji Dictionary",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar )
        CreateStatusBar(#StatusBar_0, WindowID(#FrmMain))
        SetGadgetFont(#StatusBar_0, FontID1)
        If CreateGadgetList(WindowID(#FrmMain))
            StringGadget(#String_0, 3, 0, 100, 21, "")
            ;SetGadgetFont(#String_0, FontID1)
            ButtonGadget(#CMD_Search, 105, 0, 54, 21, "Search")
            SetGadgetFont(#CMD_Search, FontID1)
            ListViewGadget(#Listview_0, 3, 24, 567, 400, #LBS_USETABSTOPS | #WS_HSCROLL | #WS_VSCROLL )
            SetGadgetFont(#Listview_0, FontID1)
            ButtonGadget(#CMD_Paste, 162, 0, 54, 21, "Paste")
            SetGadgetFont(#CMD_Paste, FontID1)
            CheckBoxGadget(#Chk_ExactSearch, 219, 0, 108, 21, "Exact Search")
            SetGadgetFont(#Chk_ExactSearch, FontID1)
        EndIf
    EndIf
   
    Dim tStop(1)
    tstop(0) = 70
    tstop(1) = 150
    SendMessage_(GadgetID(#Listview_0), #LB_SETTABSTOPS, 2, @tStop(0))
    
    SendMessage_(GadgetID(#Listview_0), #LB_SETHORIZONTALEXTENT, 2000,0) 
    
    Window_Icon.l=LoadImage_(GetModuleHandle_(0),"F:\Programming\PBasic\icons\Bookshelf.ico",#IMAGE_ICON,16,16,#LR_LOADFROMFILE)
    SendMessage_(WindowID(#FrmMain), #WM_SETICON, 0, Window_Icon)
    
    SearchText.s = ""
    SearchTextType.l = 0
    ExactSearch.l
     
    Repeat
        Event.l = WaitWindowEvent()
        If Event
            Select Event  
                   
                Case #PB_Event_Gadget
                    Select EventGadget()
                        Case #CMD_Search                       
                            If GetGadgetText(#String_0) <> ""
                                RowCount = 0
                                ClearGadgetItemList(#Listview_0) 
                                SearchText = GetGadgetText(#String_0)
                                ExactSearch = GetGadgetState(#Chk_ExactSearch)
                                SearchTextType = GetTextType(SearchText)
                                CMDSearch(SearchTextType, SearchText, ExactSearch)    
                            EndIf
                        Case #CMD_Paste
                            SetGadgetText(#String_0,GetClipboardText())   
                    EndSelect
                    
                Case #PB_Event_SizeWindow
                    ResizeGadget(#Listview_0, #PB_Ignore, #PB_Ignore, WindowWidth(#FrmMain) - 5, WindowHeight(#FrmMain) - 45)
                                   
            EndSelect           
        EndIf        
    Until Event = #PB_Event_CloseWindow
    
    
EndProcedure

;==============================================================================

Procedure ProcSQL(SQL.s)

    sDBFileName.s = "Kanji.db"

    RetResult = CallCFunction(#SQL_LIB, "sqlite3_open" ,sDBFileName, @hDB)
    Debug RetResult
 
    ;Send  Query
    QueryRet.l = CallCFunction(#SQL_LIB, "sqlite3_exec" ,hDB, SQL, @CallBack_ReturnRows() , #Null, @ReturnValue) 
    Debug QueryRet
    If QueryRet
        Debug  "ret:" + PeekS(ReturnValue)
    EndIf 
    
    RetResult = CallCFunction(#SQL_LIB, "sqlite3_close" ,@hDB) 
    ;Debug retresult
    
        

EndProcedure

; ==========================================================

ProcedureC.l CallBack_ReturnRows(NullPtr.l,ArgCount.l,*Values.l, *ColNames.l) ;argcount = column count
  
    Dim ValuePts.l(ArgCount)
    Row.s = ""

    For ValLoop.l = 0 To ArgCount -1
        ValuePts(ValLoop) = PeekL(*Values + (ValLoop * 4)) 
        Row = Row + PeekS(ValuePts(ValLoop) ) + #TAB$ 
    Next
        
    AddGadgetItem(#Listview_0, -1, Row)
    RowCount + 1
    StatusBarText(#StatusBar_0, 0, "Rows Found: " + Str(Rowcount))

    ProcedureReturn 0  ;Proceed with next row

EndProcedure                          

;======================================================================================

Procedure CmdSearch(SearchType.l, Keyword.s, Exact.l)
    
    SQL.s
    keyword = Trim(keyword)
    
    Select SearchType

        Case #Kanji
            If Exact = 1
                SQL = "Select kanji, reading, meaning from kanji where kanji = '" + keyword + "' order by kanji"
            Else
                SQL = "Select kanji, reading, meaning from kanji where kanji like '%" + keyword + "%' order by kanji"
            EndIf
        Case #hiragana
            If Exact = 1
                SQL = "Select kanji, reading, meaning from kanji where reading = '" + keyword + "' order by kanji"
            Else
                SQL = "Select kanji, reading, meaning from kanji where reading like '%" + keyword + "%' order by kanji"
            EndIf
        Case #English
            SQL = "Select kanji, reading, meaning from kanji where meaning like '%" + keyword + "%' order by kanji"
    
    EndSelect
    
    Debug sql 
    Debug "EX " + Str(exact)
      
    ProcSQL(SQL)

EndProcedure 

;======================================================================================

Procedure.l GetTextType(SearchText.s) ;Written for sjis, would need to change if DB changed ti UTF

    FirstChar.l = Asc(Left(searchtext,1))
    
    If firstchar < 129
        ProcedureReturn  #English
    ElseIf firstchar > 135
        ProcedureReturn #Kanji
    Else
        ProcedureReturn #Hiragana
    EndIf    

EndProcedure

;======================================================================================




Posted: Sun Sep 16, 2007 4:06 am
by Rook Zimbabwe
Tis looks really interesting... is there a section in the database where there is the Roman spelling as well... eg: ARIGATO for thank you not just the kanji??? That would be a super addin that means you could take this out a whole new door! :D

Keep up the great work!

I wonder if there is a chinese version of this database!

Posted: Sun Sep 16, 2007 4:22 am
by pdwyer
I could do that programatically I suppose.

Interesting idea! :)

Grab the hiragana and do text replacement

ka = か
ki = き
ku = く
ke = け
ko = こ

etc ...

I'll have a think about it

Posted: Sun Sep 16, 2007 5:52 am
by rsts
A few of your posts have tweaked my interest in sqlite 'raw' so to speak.

Thanks for posting the code. Gives me something to study.

cheers

Posted: Wed Sep 26, 2007 12:24 am
by mskuma
Hi Paul, thanks for this code. Can you provide a source code version that compiles & works ok as a unicode exe?

Posted: Wed Sep 26, 2007 12:41 am
by pdwyer
I need to take a look into this, the tasks involved have me putting it in the too hard basket ;)

- I've never done a PB unicode app (local codecs like shift-jis have been fine) so I need to do some experimentation
- I need to recode the DB, might not be too hard with those multibyte APIs
- I need to look into Unicode APIs in sqlite, haven't really done this (once again, as shiftjis has been ok)

I do need to take a look at it though, SQLite has a bug so that I can't use versions higher than 3.3.5 since they changed the way unicode works and it's second guessing me and trying to read the shiftjis as unicode, what this means is I need a proper unicode kanji DB in order to move to later versions of SQLite - which I'd like to do.

Also, there seems to be a bug in my app where some character search are returning extra data so you look for a kanji that should return say 5 rows but you get 20 back, 15 of which don't have what you are looking for, it's rare but I have seen it.

When I get my arse into gear I'll be sure to post the code. :)

Posted: Wed Sep 26, 2007 3:52 am
by mskuma
pdwyer wrote:I need to take a look into this, the tasks involved have me putting it in the too hard basket ;)

- I've never done a PB unicode app (local codecs like shift-jis have been fine) so I need to do some experimentation
- I need to recode the DB, might not be too hard with those multibyte APIs
- I need to look into Unicode APIs in sqlite, haven't really done this (once again, as shiftjis has been ok)

I do need to take a look at it though, SQLite has a bug so that I can't use versions higher than 3.3.5 since they changed the way unicode works and it's second guessing me and trying to read the shiftjis as unicode, what this means is I need a proper unicode kanji DB in order to move to later versions of SQLite - which I'd like to do.
You've kinda hit the nail on the head here.. to be honest I was kinda scratching my head at how your program could work, because it seems you've got a UTF-8 db (but maybe it's stored as Shift-JIS?) but doing selects via strings using a program compiled as regular ASCII. It seems risky to me, and I think it's better to compile it as unicode and/or pass the strings as UTF-8. I'm guessing sqlite is taking the text you've supplied and cleaning it up to be UTF-8 as it goes. I think when it comes time to have Japanese text in the source and pass it as part of the select string, there will be problems with the current approach.

Actually my eventual interest is to learn to use PB & sqlite in native unicode (UTF-16le) format when compiling for unicode (because strings etc are stored in unicode rather than UTF-8, I think).

Posted: Wed Sep 26, 2007 5:08 am
by pdwyer
Actually this is how most Japanese (and other DBCS) apps are still written. More and more are moving to Unicode but win9x didn't really support unicode very well so this is how it was done.

The only 'danger' with doing it this way is that libs like sqlite sometimes misunderstand. The 932 codepage is still very much in standard usage, more so than unicode in japanese AFAIK.

Unicode is more future proof though and I'd like to try a conversion for my own study sake

Posted: Wed Sep 26, 2007 9:34 am
by mskuma
I found a solution I think (using the latest SQLite3_Include from here)

This is rough & surely someone else can do better, but the following works as a starting point (both the source below & the include have to be flagged as compile for unicode). I could achieve my goal of having UTF8 content in the source and have it passed properly to the database & get intelligible output (in this case a Japanese string) instead of junk chars.

Code: Select all

XIncludeFile "SQLite3_Include.pbi" 

;===================== 
;|||    EXAMPLE    ||| 
;;;;;;;;;;;;;;;;;;;;;; 

Define.l hDB, r, i 


If SQLiteInit() = 0 
  MessageRequester("Error", "Couldn't init SQLite3 lib") : End 
EndIf 

hDB = SQLiteOpen("michael2.db3") 
If Not hDB 
  MessageRequester("Error", SQliteErrorMsg(hDB)) : End 
EndIf 

lStatement = SQLitePrepare(hDB, "SELECT * FROM testtable where f1 like '%子%'")

While SQLiteStep(lStatement) <> #False

  Debug SQLiteColumnText(lStatement, 0) + " " + SQLiteColumnText(lStatement, 1) + " " + SQLiteColumnText(lStatement, 2)
  
Wend

SQLiteFinalize(lStatement) ; not sure if this is needed

SQLiteClose(hDB) 
SQLiteEnd()
The prereq is the database has to be UTF-16le & populated properly (I've found it a frustrating exercise to find a tool that can let you input content correctly or appears correctly).

Posted: Sun Sep 30, 2007 2:12 pm
by michaeled314
How do you get your icon to appear in the top-left corner of the window

Posted: Sun Sep 30, 2007 2:24 pm
by pdwyer
What are you trying to achieve exactly with this?

Input to a search will depend on the app and OS settings. These need to match the DB codec unless you want to do translation between codecs on the fly. If you are using a Unicode app then the input will generally be UTF16 little endian, otherwise if your language settings for non unicode are set to "Japanese" in the third tab of the regional settings in control panel then input will be code page 932 (shift Jis) which was the standard for win9x systems (XP handles this better than win2k for english versions).

If you want to convert to UTF16 from SJIS then use:
(I think asian character support needs to be installed for this to work too

Code: Select all

MultiByteToWideChar_(932,0,@kanjiIn,-1,@kanjiOut,OutTextLen)
For my app, I got around my bugs with sjis so I can put off full unicode conversion for the moment :P (sorry) The problem is that SQLite has an "issue" (not really a bug) that the "LIKE" operator is not case sensitive (and can't be).

This means, in SJIS, char 1 will be > 127 but char 2 may not be so char 1 will stay as is but if char 2 matches a standard ascii char then it will match with it's upper and lower case version so 2 kanji will be sometimes found.

In the case of "核" the first char is 138 and the second is 106. 106 is lower case "j" so it will match in sqlite with "J" too which is is 74 and so the Kanji "開" will also match. This had me pulling my hair out for quite some time!!!

A filter on the output cleaned this up so my app works again. I also added a couple of tiny features like hitting enter for a search start etc.




Code: Select all

;Problem kanji "核"


#SQLITE3_ISO8859         =   1   ;
#SQLITE3_OK              =   0   ;'*/ Successful result */
#SQLITE3_ERROR           =   1   ;'*/ SQL error or missing database */
#SQLITE3_INTERNAL        =   2   ;'*/ An internal logic error in SQLite */
#SQLITE3_PERM            =   3   ;'*/ Access permission denied */
#SQLITE3_ABORT           =   4   ;'*/ Callback routine requested an abort */
#SQLITE3_BUSY            =   5   ;'*/ The database file is locked */
#SQLITE3_LOCKED          =   6   ;'*/ A table in the database is locked */
#SQLITE3_NOMEM           =   7   ;'*/ A malloc() failed */
#SQLITE3_READONLY        =   8   ;'*/ Attempt to write a readonly database */
#SQLITE3_INTERRUPT       =   9   ;'*/ Operation terminated by sqlite3_interrupt() */
#SQLITE3_IOERR           =   10   ;'*/ Some kind of disk I/O error occurred */
#SQLITE3_CORRUPT         =   11   ;'*/ The database disk image is malformed */
#SQLITE3_NOTFOUND        =   12   ;'*/ (Internal Only) Table or record not found */
#SQLITE3_FULL            =   13   ;'*/ Insertion failed because database is full */
#SQLITE3_CANTOPEN        =   14   ;'*/ Unable to open the database file */
#SQLITE3_PROTOCOL        =   15   ;'*/ Database lock protocol error */
#SQLITE3_EMPTY           =   16   ;'*/ (Internal Only) Database table is empty */
#SQLITE3_SCHEMA          =   17   ;'*/ The database schema changed */
#SQLITE3_TOOBIG          =   18   ;'*/ Too much data for one row of a table */
#SQLITE3_CONSTRAINT      =   19   ;'*/ Abort due to contraint violation */
#SQLITE3_MISMATCH        =   20   ;'*/ Data type mismatch */
#SQLITE3_MISUSE          =   21   ;'*/ Library used incorrectly */
#SQLITE3_NOLFS           =   22   ;'*/ Uses OS features not supported on host */
#SQLITE3_AUTH            =   23   ;'*/ Authorization denied */
#SQLITE3_ROW             =   100  ;'*/ sqlite3_step() has another row ready */
#SQLITE3_DONE            =   101  ;'*/ sqlite3_step() has finished executing */

#SQL_LIB = 1 ; dll ID

;- Window Constants
Enumeration
  #FrmMain
EndEnumeration

;- Gadget Constants
Enumeration
  #String_0
  #CMD_Search
  #Listview_0
  #CMD_Paste
  #Chk_ExactSearch
  #StatusBar_0
EndEnumeration

Enumeration
    #English
    #Kanji
    #Hiragana
EndEnumeration

Declare ProcSQL(SQL.s)
Declare CallBack_ReturnRows(NullPtr.l,ArgCount.l,*Values.l, *ColNames.l)
Declare Open_FrmMain()
Declare CmdSearch(SearchType.l, Keyword.s, Exact.l)
Declare.l GetTextType(SearchText.s)

Global RowCount.l
Global FontID1
Global KeywordCheck.s
Global SearchType.l

FontID1 = LoadFont(1, "MS Sans Serif", 11)

OpenLibrary(#SQL_LIB, "sqlite3.dll")
Open_FrmMain()
CloseLibrary(#SQL_LIB)

Procedure Open_FrmMain()

    If OpenWindow(#FrmMain, 305, 168, 571, 445, "QuickSearch Kanji Dictionary",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar )
        CreateStatusBar(#StatusBar_0, WindowID(#FrmMain))
        AddStatusBarField(150)
        AddStatusBarField(200)
        SetGadgetFont(#StatusBar_0, FontID1)
        If CreateGadgetList(WindowID(#FrmMain))
            StringGadget(#String_0, 3, 0, 100, 21, "", #ES_WANTRETURN | #ES_MULTILINE)
            ;SetGadgetFont(#String_0, FontID1)
            ButtonGadget(#CMD_Search, 105, 0, 54, 21, "Search")
            SetGadgetFont(#CMD_Search, FontID1)
            ListViewGadget(#Listview_0, 3, 24, 567, 400, #LBS_USETABSTOPS | #WS_HSCROLL | #WS_VSCROLL )
            SetGadgetFont(#Listview_0, FontID1)
            ButtonGadget(#CMD_Paste, 162, 0, 54, 21, "Paste")
            SetGadgetFont(#CMD_Paste, FontID1)
            CheckBoxGadget(#Chk_ExactSearch, 219, 0, 108, 21, "Exact Search")
            SetGadgetFont(#Chk_ExactSearch, FontID1)
        EndIf
    EndIf
   
    ;Set list tab stops and scrollbar
    Dim tStop(1)
    tstop(0) = 70
    tstop(1) = 150
    SendMessage_(GadgetID(#Listview_0), #LB_SETTABSTOPS, 2, @tStop(0))   
    SendMessage_(GadgetID(#Listview_0), #LB_SETHORIZONTALEXTENT, 2000,0) 

    ;Set Window Icon    
    Window_Icon.l=LoadImage_(GetModuleHandle_(0),"F:\Programming\PBasic\icons\Bookshelf.ico",#IMAGE_ICON,16,16,#LR_LOADFROMFILE)
    SendMessage_(WindowID(#FrmMain), #WM_SETICON, 0, Window_Icon)

    ;Init defaults    
    SearchText.s = ""
    SearchTextType.l = 0
    ExactSearch.l
    
    AddKeyboardShortcut(0, #PB_Shortcut_Return, 99)
    SetActiveGadget(#String_0)
     
    Repeat
        Event.l = WaitWindowEvent()
        If Event
            Select Event  
                   
                Case #PB_Event_Gadget
                    Select EventGadget()
                        Case #CMD_Search                       
                            If GetGadgetText(#String_0) <> ""
                                RowCount = 0
                                ClearGadgetItemList(#Listview_0) 
                                SearchText = GetGadgetText(#String_0)
                                ExactSearch = GetGadgetState(#Chk_ExactSearch)
                                SearchTextType = GetTextType(SearchText)
                                CMDSearch(SearchTextType, SearchText, ExactSearch)    
                            EndIf
                        Case #CMD_Paste
                            SetGadgetText(#String_0,GetClipboardText()) 
                              
                    EndSelect
                    
                Case #PB_Event_SizeWindow
                    ResizeGadget(#Listview_0, #PB_Ignore, #PB_Ignore, WindowWidth(#FrmMain) - 5, WindowHeight(#FrmMain) - 45)
                
                Case #PB_Event_Menu
                    Select EventMenu()
                        Case 99 
                            If GetGadgetText(#String_0) <> ""
                                RowCount = 0
                                ClearGadgetItemList(#Listview_0) 
                                SearchText = GetGadgetText(#String_0)
                                ExactSearch = GetGadgetState(#Chk_ExactSearch)
                                SearchTextType = GetTextType(SearchText)
                                CMDSearch(SearchTextType, SearchText, ExactSearch)    
                            EndIf                 
                    EndSelect
            
            
                               
            EndSelect           
        EndIf        
    Until Event = #PB_Event_CloseWindow
    
    
EndProcedure

;==============================================================================

Procedure ProcSQL(SQL.s)

    sDBFileName.s = "Kanji.db"

    RetResult = CallCFunction(#SQL_LIB, "sqlite3_open" ,sDBFileName, @hDB)
    Debug RetResult
 
    ;Send  Query
    QueryRet.l = CallCFunction(#SQL_LIB, "sqlite3_exec" ,hDB, SQL, @CallBack_ReturnRows() , #Null, @ReturnValue) 
    Debug QueryRet
    If QueryRet
        Debug  "ret:" + PeekS(ReturnValue)
    EndIf 
    
    RetResult = CallCFunction(#SQL_LIB, "sqlite3_close" ,@hDB) 
    ;Debug retresult
    
        

EndProcedure

; ==========================================================

ProcedureC.l CallBack_ReturnRows(NullPtr.l,ArgCount.l,*Values.l, *ColNames.l) ;argcount = column count
  
    Dim ValuePts.l(ArgCount)
    Row.s = ""

    For ValLoop.l = 0 To ArgCount -1
        ValuePts(ValLoop) = PeekL(*Values + (ValLoop * 4)) 
        Row = Row + PeekS(ValuePts(ValLoop) ) + #TAB$ 
    Next
    
    If FindString(row,keywordCheck,1) = 1 Or SearchType = #English  ;catch sjis case overmatch
        AddGadgetItem(#Listview_0, -1, Row)
        RowCount + 1
        StatusBarText(#StatusBar_0, 0, "Matches Found: " + Str(Rowcount))
    EndIf

    ProcedureReturn 0  ;Proceed with next row

EndProcedure                          

;======================================================================================

Procedure CmdSearch(SearchType.l, Keyword.s, Exact.l)
    
    SQL.s
    keyword = Trim(keyword)
    
    Select SearchType

        Case #Kanji
            StatusBarText(#StatusBar_0, 1, "Search Type: Kanji")
            If Exact = 1
                SQL = "Select kanji, reading, meaning from kanji where kanji = '" + keyword + "' order by kanji"
            Else
                SQL = "Select kanji, reading, meaning from kanji where kanji like '" + keyword + "%' order by kanji"
            EndIf
        Case #hiragana
            StatusBarText(#StatusBar_0, 1, "Search Type: Hiragana")
            If Exact = 1
                SQL = "Select kanji, reading, meaning from kanji where reading = '" + keyword + "' order by kanji"
            Else
                SQL = "Select kanji, reading, meaning from kanji where reading like '" + keyword + "%' order by kanji"
            EndIf
        Case #English
            StatusBarText(#StatusBar_0, 1, "Search Type: English")
            SQL = "Select kanji, reading, meaning from kanji where meaning like '%" + keyword + "%' order by kanji"
    
    EndSelect
    
    Debug sql 
    Debug "EX " + Str(exact)
    
    SearchType = SearchType
    KeywordCheck = keyword  
    ProcSQL(SQL)

EndProcedure 

;======================================================================================

Procedure.l GetTextType(SearchText.s)

    FirstChar.l = Asc(Left(searchtext,1))
    
    If firstchar < 129
        ProcedureReturn  #English
    ElseIf firstchar > 135
        ProcedureReturn #Kanji
    Else
        ProcedureReturn #Hiragana
    EndIf    

EndProcedure

;======================================================================================


Posted: Sun Sep 30, 2007 2:27 pm
by pdwyer
michaeled314 wrote:How do you get your icon to appear in the top-left corner of the window
our posts crossed

Code: Select all


    Window_Icon.l=LoadImage_(GetModuleHandle_(0),"c:\book.ico",#IMAGE_ICON,16,16,#LR_LOADFROMFILE)
    SendMessage_(WindowID(#FrmMain), #WM_SETICON, 0, Window_Icon)

took me ages to work out so I put it in the tips forum a little while ago.

Kale needs to add this to his book :)

Posted: Sun Sep 30, 2007 2:42 pm
by michaeled314
Thx

Posted: Sun Sep 30, 2007 2:50 pm
by pdwyer
Found another bug, I fixed it and update the code above.

the filter was causing english searches to fail... :?

Posted: Mon Oct 01, 2007 3:55 am
by mskuma
pdwyer wrote:This means, in SJIS, char 1 will be > 127 but char 2 may not be [snip].. In the case of "核" the first char is 138 and the second is 106. 106 is lower case "j" so it will match in sqlite with "J" too which is is 74 and so the Kanji "開" will also match. This had me pulling my hair out for quite some time!!
I think you'll find these sort of bizarre (& unnecessary) situations become a non-issue when you work in unicode.

Also working in unicode avoids the need for the user to set the language setting you mentioned. As long as they have the fonts, they're good to go.