Hla Hla Htay's Notes

Just another WordPress.com weblog

How to use Sqlite in B4A September 4, 2016

Filed under: Japan,Language,Myanmar — hhh123 @ 3:16 pm
Tags: , , ,

I am learning how to write Android programs in B4A at Skylight. I want to know to how to use Sqlite in B4A (Basic For Android). As I am interested in dictionary project, I take a small dictionary project which use Sqlite database. The program will accept either Romaji (English) or Myanmar(Myamar3/Zawgyi).

Screenshot_2016-09-04-21-10-35

Screenshot_2016-09-04-21-11-27

Screenshot_2016-09-04-21-11-49

 

 

 

 

 

 

 

 

 

 

 

 

 

A Sqlite database is made from MS Excel. DB Browser for Sqlite can be downloaded here. MS Excel *.xls
is saved as *.odf*.ods in OpenOffice.The data sheet is saved as text csv in OpenOffice. Choose UTF-8 while the file is saved.

CSVinUnicode1

Open DB Browser for Sqlite. Click New Database -> Choose a location to store . Open this CSV in DB Browser for Sqlite. File–> Import–> Table from CSV file. You can rename your database and table.

sqlite-import

        Before you are using your SQL statement in program, you can check your desired result in DB Browser.

sqlite-query

Choose SQL in Library Manager.

Add your sqlite file through File Manager.

Declare in Process_Globals.

       Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
               Dim sql1 As SQL
               Dim cursor1 As Cursor
 
End Sub

Open your db in Activity_Create.

        If File.Exists(File.DirInternal,"jpdictionary1.sqlite") = False Then
		File.Copy(File.DirAssets,"jpdictionary1.sqlite",File.DirInternal,"jpdictionary1.sqlite")
	End If
	
	If sql1.IsInitialized = False Then
		sql1.Initialize(File.DirInternal, "jpdictionary1.sqlite", False)
	End If

Write query statement as below and put the passed data into Editext.

         Dim cursor1 As Cursor
    cursor1 = sql1.ExecQuery("SELECT Romaji, HiraganaKatakana, Kanji, Myanmar, Myanmar3 FROM dictionarytable WHERE " 
& choice1 & "='"  & edtSearch.text.trim & "'")

	
    For i = 0 To cursor1.RowCount - 1
                cursor1.Position = i
		edtRomaji.Text=edtSearch.text
		
		edtHiragana.Text=cursor1.GetString("HiraganaKatakana") 
		edtKanji.Text=cursor1.GetString("Kanji")
		
		If choice1="Romaji" Then
		
		edtMyanmar.Text=cursor1.GetString("Myanmar3")	
		
                else If choice1="Myanmar3" Then

		 lblMyanmar.Text="Romaji"	
		 edtMyanmar.Text=cursor1.GetString("Romaji")
		End If 
    Next
	
    cursor1.Close

Credit:

Download:JP dic sample project

Advertisements
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s