Presentation is loading. Please wait.

Presentation is loading. Please wait.

Working with Databases (I) 靜宜大學資管系 楊子青

Similar presentations


Presentation on theme: "Working with Databases (I) 靜宜大學資管系 楊子青"— Presentation transcript:

1 Working with Databases (I) 靜宜大學資管系 楊子青

2 Database Facebook has a database of every member’s account information, friends list, and posts. Amazon has a database of just about everything you can buy. Google has a database of information about every page in the World Wide Web.

3 Database Course In most programming environments, building an app that communicates with a database is an advanced programming technique: you have to set up a server with database software like Oracle or MySQL and then write code that interfaces with that database.

4 App Inventor provide useful things
provides components that reduce database communication to simple store and get operations. You can create apps that store data : directly on the Android device, and with some setup, you can create apps that share data with other devices and people by storing it in a centralized web database. even when you close the app and reopen it, the data is still available.

5 Two components to facilitate database activity
TinyDB is used to store persistent data directly on the Android device; this is useful for highly personalized apps where the user won’t need to share her data with another device or person. TinyWebDB is used to store data in a web database that can be shared among devices. Being able to access data from a web database is essential for multiuser games and apps where users can enter and share information.

6 1. TinyDB The TinyDB.StoreValue block stores data to the device’s long-term memory. A tag-value scheme is used for database storage. You retrieve data from the database with the TinyDB.GetValue block.

7 TinyDB

8 (1) 介面設計

9 (2) 程式碼

10 (3) 模擬程式執行結果 輸入名字 再更新 資料庫 任意輸入名字,但 不要按更新資料庫 讀取 資料庫

11 打包安裝至手機 第一次先輸入名字 關掉APP再開啟,或是按Retrieve DB,會顯示先前貯存的User Name

12 2. TinyWebDB Many apps do share data:
think of Facebook, Twitter, and popular multiuser games. For such data-sharing apps, the database must live on the Web, not the device. TinyWebDB is the web counterpart to TinyDB. It allows you to write apps that store data on the Web. By default, the TinyWebDB component stores data using a web database set up by the App Inventor team and accessible at .

13 TinyWebDB Service

14 TinyWebDB Service: StoreValue實例

15 TinyWebDB Service: GetValue實例

16 2.1 Storing Data with TinyWebDB
The TinyWebDB.StoreValue block sends the tag-value pair over the Web to the database server.

17 2.2 Requesting and Processing Data with TinyWebDB
Retrieving data with TinyWebDB is more complicated. TinyDB: the GetValue operation immediately returns a value because your app is communicating with a database directly on the Android device. TinyWebDB: the app is requesting data over the Web, so Android requires a two-step scheme for handling it.

18 Get Value差異 TinyWebDB.GetValue block does not return a value immediately, so there is no plug on its left side. Instead, when the web database fulfills the request and the data arrives back at the device, a TinyWebDB.GotValue event is triggered.

19 TinyWebDB實例1:讀取tcyang標籤值

20 程式碼及執行結果

21 TinyWebDB實例2:記錄最高分玩家

22 送出此次玩家分數,並先判斷是否有此tag

23 若已有tag,判斷分數是否最高

24 若未破紀錄,還要顯示紀錄保持人 (回傳的欄位除了tcyangScore外, 還可能是tcyangPlayer)

25 3. Creating a Custom TinyWebDB Service (App Inventor 2)
作業:請分組自行設定,下週上課時Demo

26 為什麼需要自行設定Web Service?
TinyWebDB is an App Inventor component that allows you to store data persistently in a database on the web. By default, the TinyWebDB component stores data on a test service provided by App Inventor, . This service is helpful for testing, but it is shared by all App Inventor users, and it has a limit of 1000 entries. If you use it, your data will be overwritten eventually. For most apps you write, you'll want to create a custom web service that isn't shared with other App Inventor apps and programmers.


Download ppt "Working with Databases (I) 靜宜大學資管系 楊子青"

Similar presentations


Ads by Google