TinyDB functions

I am having fun learning how to use App Inventor at my age. Yes, I am an old fart. Having used it in the past, it's amazing how much I have forgotten.

I am writing an app for my son and know once I have mastered this one, I will be able to do more with it.

I want to learn and understand how things work. I use to be a developer in my younger days and feel there is much more to learn.

Here is what I am wanting to do and being directed to tutorials and a little help, I think I'll be able to create an awesome app.

I have a Google sheet that is imported into a LIST and then imported to TINBYDB (I Hope I did that right).

I have a screen where I will do the following.

  1. Search for a name. (Need to learn)
  2. Display the information on the screen. (Once I get the right record)
  3. Have a Next, Prev, Delete and Save button.
  4. Then call Google Maps (I have done this part already and this part works great.)

This is the import section that I have completed.

The lat part in the txtDisply is giving me an error. I am doing more research as I write this.

Thanks again.

1 Like

Generally use Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools

Use the tag dbRP to get the data

Also in case the table does have less than 4 rows you will get an error.. you might want to check if the list is long enough before selecting the 4th item
Also the valueIfTagNotThere socket should be a create empty list block rather than an empty text block

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

2 Likes

If you have multiple columns just separate inyo different variable the each col.

And then use index is in the list to search for a name in particular variable

1 Like

Taifun,

There are 1100 rows and about 12 columns in the data.

I will read your links and see where I can go from there.

@ Spicy_Topics
This is my plan as soon as I figure out how to.

Thank you as well.

Thank you.

1 Like

Here is a starter kit for working with tables ....

1 Like

What about using the SQlite database?
My sqlite extension is able to import an initial database, see here App Inventor Extensions: SQlite | Pura Vida Apps

Taifun

3 Likes

This is interesting using SQlite.

I'll read up on it to see how it works. Now, this will run on Android phones correct?

What are the benefits using SQLite vs TinyDB
Thanks again

1 Like

SQLite is an actual searchable database using a version of the SQL query language that allows sophisticated searches directly in the DB.
https://www.sqlite.org/about.html

TinyDb is a flat XML file, there are currently no dedicated blocks for searching in it (data is not indexed) and it's not intended for large data storage.
http://ai2.appinventor.mit.edu/reference/components/storage.html#TinyDB

2 Likes


You have only stored value with dbRP so why you are using txtDisplay use dbRP on marked place

1 Like

Doh! That's right I forgot about that.

Thanks for the help.

1 Like

I am making good headway. I am able to import my CSV and save it to TinyDB.

I can read the file, but I can't seem to set the Text fields correctly. I have 15 fields but display a handful of them.

This is what I have and what the error is.

Is you have stored any value with this tag name

You cannot select the list item of an empty string (replace it with an empty list). Also, since you cannot select the list item from an empty list, you need to handle what will happen when the value is an empty list.

IF the value is an empty list
THEN this means that there is no such entry stored.

ELSE if the value is not an empty list
THEN show the information needed.
2 Likes

I looked at some of my old code and I am using some of the same calls so this is puzzling me. Here is the whole thing.

What this does is allow the user to select a name from the list and MapIt. The map features work great.
The import works great and the listpicker works great. What isn't working great is populating the fields.


I have looked over my old code and other examples and I am missing something that I am not seeing.

I can read my data into my ListPicker but I still keep getting that bad argument error. I have 15 columns but only a few are used.

What am I missing? It has to be something simple I am missing.

Thanks agian.

This exposes a weakness in the use of tables (lists of lists) for storing sparse data.

How do you like having to remember 15 column numbers for the 15 contact fields? Fun, huh? And what if you want to add a new column in the future, and deal with missing columns in old entries?

For that reason, consider storing a dictionary for each contact, with tag = contact name and value = a dictionary with keys=attribute names ("First", "Last",...,"Phone","Notes") and associated values of whatever was in the textbox.Text for that attribute.

Dictionaries don't complain if the associated key/value is missing, they just return whatever default value you sugget.

There is a cost, however.

When you ask for a contact from TinyDB, you should ask for an empty dictionary as a default value, not a 'not found' text, so you can go to work setting key/values in that new dictionary.

If you have old data already in TinyDB, you would have to go back and test if it is a dictionary before trying to get or set key/values. Use the is a dictionary block.

Also, don't get hung up on the idea of displaying your contact details in a spreadsheet format. Retire that fellow sitting on a tall stool with a quill and a ledger book.

1 Like

I guess I need to figure out how to get my data from Tinydb which is fixed by the way into a dictionary so I can display the information on my contact form.

Time to google some more.

Thanks.

I took a couple of hours to whip a quick and sloppy TinyDB Contact list app with dictionaries.

Here's a video of it at work ...

(I used my phone's screen recorder, which unfortunately does not catch cursor actions.)

Designer:


Components include:

  • A list Picker to pick Contacts from a TinyDB TagList
  • A text box to show the current ContactName or enter a new one
  • A Horizontal Arrangement to present a contact Attribute and its value, and allow Enter of a new value
  • A ListView (Main, Detail view) to present the chosen Contact's attributes and values (Who needs a bunch of text boxes, anyway?)
  • A TinyDB set aside just for Contacts, with its own NameSpace.

The Contacts List Picker:

After selecting a ContactName from the TinyDB TagList, it needs to be formatted as ListView Elements and loaded into the ListView:

I chose to use a standard list of Attribute names, hard coded into a global list:

With further effort, this could be extended to also include new attribute types entered by the user, contact by contact (Left Shoe Size,...)

When an attribute is selected from the ListView for the current contact, the attribute name and value are loaded into the Label and textbox for editting and replacement via the Enter button:


The Enter button uses the TinyDB as the data source for its updates, so it reads, updates, and stores in one shot.

The source:
TinyDB_Contact_Dictionaries.aia (3.9 KB)

All blocks:

1 Like

ABG,

I can't tell you how much I appreciate you helping this old guy out. It's a bugger getting old and when I was younger I used to be a developer.

This is fun learning and I really do want to get better at it. Some things are just harder to grasp nowadays.

I did realize one problem I made. When I imported the CSV file from GOOGLE sheets, each row was added as 1 record with 1 field instead of 15 different fields.

I will take the time and watch your video and look at your code.