Firebase DB with App Inventor tutorial

This is more about the asynchronous logic used by AppInventor.

When you use the .GetValue block, the output is returned in the .GotValue event. You can't do anything with the value you want until you have got it. If you try to do other things with your intended value before you have got the value (which is what your save and second read procedures are trying to do, you can then expect data or program errors. You do not show your entire .GotValue block so I can only guess at what you are trying to achieve....

Still do not understand the logging in stuff....

I understand your point, but if you look at the blocks I posted above I think I have that covered. My 'readCCUserData' procedure calls the GetValue event.. which in turn calls GotValue .. so I have the data at that point, at least this is my understanding.

At one point I even placed a Notifyer ShowMessage block in the GotValue routine after one of my variables to show the value after it was read in and it was correct. That block has since been removed..

I then edit the data pair that I need, and when I check, it's successful.

I then run the 'saveCCUserData' procedure to write the data back.. same as before.. that procedure creates the updated list and calls the StoreValue event. When I walk through this in my head, it should work fine. I then read MY user data back in and continue on..

I don't know how else to explain the logging in stuff. I login with my account (user number 1) and want to edit the data for another user .. for the sake of example, user number 2. I am using the user numbers for my indexes and tags since they are the same. User 1 is Tag 1 in the database, etc.. that just made sense to me.

I hope I am making myself clear, this is obviously not my field of expertise.

Here is the entire GotValue event. I did not include the whole thing before because of the size. Its small now so I could get it to fit on the screen. As you can see the data structure coincides one to one with the SaveData routine.

I will leave you to plough your own furrow for a while :wink:

Thanks for the assistance .. it really does help when someone else makes me think it through. If there is an answer I will find it eventually.

It wouldn't hurt to read a few articles about how to structure data in FireBase

I asked for some at the beginning of this entire conversation.. that's what got this whole thing started. I will figure this out if it's the last thing I do.

Another question please.. what does this mean? I get this when I try to perform a "Do It" on some of my blocks..

image

Obviously this has something to do with my issue..

You are inside a procedure or function that requires an input. App Inventor offers you the opportunity to enter an input so that you can run the function/procedure to get a Do It output

How to Structure a databse in FirebaseDB

After reading the above article AGAIN, I decided to scrap my current database structure and start from scratch. I can see the advantages of this more 'flat' structure compared to what I was trying to do.

Thanks ABG for pointing me in that direction.. I think someone else also posted that link at me earlier, thanks to you too!

I will let you all know how it works out.

1 Like

So I dumped the old database format in favor of something that I understand is called "flatter" than my old one. I do understand the design and it makes sense. It will be easier to edit the fields one at a time I think, which was my issue in my old version. Here is part of what I have so far..

This is the new user creation routine where new users can login and create their account. They fill in 3 fields from the design page, their username, their password, and they choose a chat name for when they are communicating with each other in the app. The other two variables are defined a value at sign up.

I am having some issues though, the Append blocks are not adding anything to my database. I thought well since this is brand new and there is no data, maybe there is nothing to Append to .. so I made a little StoreValue routine to create data.. That data created just fine but my appends still don't seem to add data. Thats one issue..

Second I am getting this error when trying to see if a username already exists in the database:

example04

This is supposed to be looking up and comparing usernames but it doesn't?

Which led me to my third possible issue.. In my old method, someone pointed out that I needed to use the JSONTextDecode block from Web1 .. am I having the second issue because I do not have that block n my routine?

Sorry for all the trouble..

We need to see

  • what is in global Users and
  • how that value got there and
  • when it got there.

Regarding your parallel list structure, I find those very fragile.
They require you to keep all those lists in perfect sync, at risk of mismatching items down the line if you slip a gear. WHat if an item is empty or its insertion fails ?

It is more robust to keep attributes of an object together with tags, regardless of extra storage cost.

Regarding initialization of FireBase lists, you have to write an empty list to the tag value before you can do your first append to that tag.

Users are not an appropriate thing to keep in lists. Better to keep your user collection as an object with tags of unique user names, and each user tag value is an object with all its attributes, by attribute name.
That keeps all information about any particular user together.

If I understand your suggestion correctly, you are saying to use the user name as the tag, and the rest of the data would be the values? Something like in this example:

image

or like this..

image

You need an extra level, like:

  • Employee
    • ABG
      • dob
        • day: 1
        • month: 1
        • year: 1900
      • firstname: Abraham
      • lastname: Getzler
      • username: ABG
    • Carl_Aydelotte
      • dob
        • day: 1
        • month: 1
        • year: 1800
      • firstname: Carl
      • lastname: Aydelotte
      • username: Carl_Aydelotte

There are no lists here, only an Employee branch with unique sub branches, one per employee.

To update your year of birth, the tag to use would be Employee/Carl_Aydelotte/dob/year and value whatever your birth year ir.

I see .. you have given me a lot to think about ...

OK I am stuck again. I like the idea of the data structure you mention in your last post, above. I can see the merits of it from reading all the other posts about DBs and the problems that other users have run into.

example01

I am setting my bucket to 'Users' and the tags to the users' name .. its the values that I cannot seem to get right now. It's easy if there is only the one value but when there are multiples I cannot figure out the blocks. Is it some kind of list? How do I do this?

Hear that? That's frustration setting in once again. I understand the concepts, it's the execution that I can't figure out.

Wait .. i think I may have it..

Darnnit I am so close but I just cant get it ..

This isn't right, its just four values and not pairs that I can reference..

image

image

Took me long enough!

image

image

Thank you ABG for all the help. I really did learn a lot today. Trial and error has its merits.

The double slashes (//) in the tags are new to me.
I have been using single slashes.

I found that in somebody's YouTube video..