(MRWD) Data and Databases Lesson
Data and Databases
Apps created with App Inventor are initialized each time they run. So any information stored in variables will not be remembered the next time the app is opened. To store information, you need a database. A database is a collection of information that is organized so that it can be easily accessed, managed and updated.
To have a database, you need software like Oracle or MySQL and then write code that interfaces with that database. Rather than having to go through this process, App inventor provides a way to store and get information easily.
App inventor provides two components to carry out database activity.
TinyDB
TinyDB is a persistent data store for the app. This means the data stored in a TinyDB will be available each time the app is run. The data is stored in a database directly on the device and is associated with your app. TinyDB can be used to store information you want your app to remember such as a personal high score, location data and other non-personal data.
A tag value scheme is used to store the data as strings.
To Store Data
A call TinyDB.StoreValue block is used to store data into the database.
To store a data item, you type a string for the tag. This is the name, tag, used to store the data. This same tag is used to retrieve the data.
The valueToStore is the is the text the user has entered for a custom response. In the example above it is data that is stored in a label. It could be text that the user has entered from a textbox.
It creates a tag-value pair.
Tag |
Value |
To Retrieve Data
To retrieve data from the TinyDB, the call TinyDB1.GetValue is used to retrieve data from the database using the assigned tag.
If the tag is not there, it will return valueIfTagNotThere.
Each app has its own data store. There is only one data store per app. Even if you have multiple TinyDB components, they will use the same data store. To get the effect of separate stores, use different keys. You cannot use the TinyDB to pass data between two different apps on the phone.
TinyWebDB
TinyWebDB is a database on the cloud in a test service provided by App Inventor.
TinyWebDB has a property SourceURL. You can set it to any App Inventor compliant web service, that is, any site that has been set up especially for use with App Inventor and TinyWebDB. By default, TinyWebDB stores data at appinvtinywebdb.appspot.com.
However, all app inventor users share this space. It has a limit of 1000 entries. Since all users are sharing the space, it often overwrites past entries. Since everyone has access to the data, never put sensitive information into the database such as personal data. Personal data is anything that you wouldn't want someone else seeing or obtaining.
- TinyWebDB is for talking to special App Inventor web services that store data in the same format as TinyDB.
- It is different than the Web component, which is for communicating with any kind of API and doesn't have the StoreValue/GetValue commands.
[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION