Android ရဲ့ data store ၏ နောက်ကွယ် (၃)

SQLite ဟာ လူသိများတဲ့ embedded database တစ်ခုဖြစ်ပါတယ်။ ဘာလိုလဲဆိုတော့ သူ့မှာ memory နေရာယူတာအရမ်းနည်း ပြီး မြန်တဲ့ ရိုးရှင်းတဲ့ SQL interface ရှိတာကြောင့်ပါ။ ဒါကြောင့် opensource projects တွေဖြစ်ကြတဲ့ Mozilla, PHP, Python တို့မှာ SQLite ကိုသုးံပါတယ်။ JDBC လိုမျိုး memory overhead အရမ်းများတဲ့ database ဆိုရင် memory ကိုအကန့်သတ်နဲ့သုံးရတဲ့ ဖုန်း application တွေအတွက် အဆင်မပြေနိုင်ပါဘူး။

ပထမဆုံးအနေနဲ့ database helper class ကို create လုပ်ရပါမယ်။ အဲ့ဒီထဲမှာ database ကို create လုပ်တာတို့ opening လုပ်တာတို့၊ closing လုပ်တာတို့ query လှမ်းလုပ်တာတို့ကို ထပ်ခါထပ်ခါ ရေးစရာ မလိုပဲ တစ်နေရာထဲမှာ encapsulate လုပ်ထားတဲ့ သဘောပေါ့။ ကိုယ်ဆောက်လိုက်တဲ့ Activity တို့ Service ကနေပြီးတော့ simple method တွေဖြစ်တဲ့ ”get” တို့ “insert” ကနေတဆင့် သုံးနိုင်ပါတယ်။ ဒါကြောင့် ဒီ class ကိုဘယ်လို မြင်နိုင်သလဲဆိုရင် 3-Tier Application တွေလိုမျိုး Data Access Layer လို့မြင်နိုင်ပါတယ်။ ဒီနေ့တော့ database ထဲကို ဖုန်းရဲ ့ Interface လေးကနေပြီး data လှမ်းထည့်မယ် ပြီးရင် interface လေးကနေဘဲထည့်ထားတဲ့ data ကို List View ကနေပြန်ကြည့်မယ့် ကျုတိုရီရယ်လေး လုပ်ကြည့်ပါမယ်။ ဒီ ကျုတိုရီရယ်မှာ database ဘယ်လို အသုံးချတာဘဲ ဇောင်းပေးပြီး ပြောမှာဖြစ်လို ကျုတိုရီရယ် တစ်ခုလုံးပေါ်အောင် ရေးချင်ရင်တော့ Source Code ကို download လုပ်ပြီး နမူနာ ယူနိုင်ကြပါတယ်။

ပထမဆုံး DBHelper class ဆောက်ကြရအောင်။

ခုချိန်မှာ database အတွက် DBHelper ဆောက်ပြီးပြီဆိုတော့ Activity ကနေ ဘယ်လိုသုံးမလဲဘဲပြောတော့မှာပါ။

DBHelper နဲ့ Cursor တို့ကို ကြေငြာပေးပါ။ Database က ပြန်ဆွဲထုတ်ရင် return ကို Cursor ကနေတဆင့်ကိုင်ရမှာမို့ပါ။

Source Code: Downlaod ယူရန် SQLite_tut.zip

Ps. အရမ်းလွယ်လွန်းတာ ကိုတင်ပေးမိတဲ့ အတွက် အရမ်းပဲ အားနာရပါတယ်။ မသိသေးတဲ့ လူများအတွက် ကိုရည်ညွှန်းတာပါ။ ပျော်ရွှင်ပါစေ။

Facebook comments:

2 Responses

  1. Zuuluu says:

    Thanks u very much aemon.
    U’r good in android and i use a android phone (Htc Desire).
    But i want to rise my phone to android version 2.2 and how can i do that?
    If u know that, please tell me how can i do.
    Thanks a lot for ur tutorials!!!!!!!!!!

    ht

    • အဲမွန် says:

      sorry for my useless reply in advance. I am only trying with Android emulator and haven’t got experience with physical device. Wish someone can tell you more.

Leave a comment


*