A couple questions regarding TinyDB and Lists

318 views
Skip to first unread message

Shorty

unread,
Feb 22, 2016, 9:26:47 AM2/22/16
to MIT App Inventor Forum
Ok, so I have a project going that is pretty far along.....

I am using a database to store user content, a total of 36 fields of entry - populated in Tiny DB "AssetDB" with tag as "HeadText" (text box input), and stored values as all 36 fields from an entry page - ultimately I am 'exporting' this to a csv format, for import into DOS

I am sure there is a better way to do it than how I am doing it - so for Q1, I could use some input on exporting the database content to csv
Here is how I am doing it now, but I feel like there is probably a LIST function that would do this cleaner? The function works perfect, I just wonder if it could be done 'better?' or 'cleaner?'... I'm actually doing it 'wrong' as, if a comma were entered into a text field, it would mess up my DOS import, as, the comma would separate a field - what I really need is a true CSV format, with text fields containing commas being surrounded by quotes. Little help? Here's what I have now:




Ok, so... to clarify something about TinyDB... there is only 1 database right? I mean, I can add another database component into my project, and name it different, and handle/access it different, but even is pickers set up for specific DB's, they show the same content.

I read that there is only one DB..... so I believe this to be the case..... but... if so, then why can I make more than one, and name them differently? What's the point?
Am I missing something with TinyDB? Ideally for my needs, I would have 4 or 5 DB's in use....  that would be amazing... but doesn't look like it's possible.

The reason I could use more DB's, brings me to my current issue.

I have a CSV file with database templates that I would like to be able to add to a picker list, and when an item is selected, each of my 36 entry page fields populate with the indexes of the CSV rows from the file. I have the CSV file on the SD card of the tablet I am using with AI Companion. I have the file added to my project. 

I can access the file, and view some row content in list picker (which I would eventually change to just index 1 as the content in the list picker)....
But, I am not able to properly 'extract' / 'delimit' the content in indexes. 
I'm seriously doing this wrong. I could really use help here. 

Here is the formatting of the FILE that I want to use and 'delimit' and create a list of lists.
“MASTER Database, 001”,1001, 0, 0, 0, 0, 0, 0, 0,comment, 0, 0, 0, 0, 0,,,,,This custom cost database was established to provide uniform costs and,data entry formatting among multiple reserve planners.,,,,,,,,, 0, 0, 0, 0, 0, 0, 0 

The text document includes MULTIPLE entries in the same syntax. Each ROW / line if the text document is a different component (list item, with 36 indexes).
I will have a text document with around 250 rows/components to select from, each with 36 indexes (comma separated)

Notice that "MASTER Database, 001" should be index 1. Where any comma inside quotes is ignored as a separator. Follow? Pretty standard CSV stuff right?
Here is where I am at with this part so far.... which makes a picker list separating each row of content to it's own row in the picker, but it's not recognizing them as comma separated I believe...... as, I cannot see commas in the picker list, and, when I make a list selection, I get an error trying to retrieve number 3 of a list of 1 (I only have the after picking set to 3 indexes for testing.... it will be 36 actually)



I've tried so many things that seem like they would make sense, but they don't work. 

I've searched and searched google, but not finding my solution.

I could use some help.

I am happy to explain the project further if needed. I am so close to having my entire structure down to be able to button this up, but this is holding me up right now.
If I were able to use multiple TinyDB's, that would be great, but doesn't look possible, so I need to be able to use files.

Any help? Pretty please?

Thanks!!!!!!!!!!

Taifun

unread,
Feb 22, 2016, 10:44:41 AM2/22/16
to MIT App Inventor Forum
see the documentation http://ai2.appinventor.mit.edu/reference/components/storage.html#TinyDB

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, although you can use the TinyDB to share data between the different screens of a multi-screen app. 

learn how to work with lists and list of lists!

Taifun

Shorty

unread,
Feb 22, 2016, 11:34:55 AM2/22/16
to MIT App Inventor Forum
Thanks Taifun

I have been reading your stuff over the last couple weeks.

Unfortunately, I have already visited all these links, and they aren't getting me there.

Perhaps the ABG one is what I need to be doing, with CSV stuff

But let me ask you this.

Is there a way to Tag within a Tag?

So I could have a Tag named ASSETS, with tagged values within the ASSETS tag?
So then I could also have a Tag named TEMPLATES, with tagged values within the TEMPLATES tag?

I need at minimum two separate groups of things I can access.... the example of how I am using the DB above, is close, but it's like they are the ROOT of the database... it's like I need multiple lists within lists, within a database tag, and still need to be able to populate a picker list of that list of lists

follow?

I can't seem to find an example that lays out anything close... or I'm really not getting it. but I have tried EVERYTHING from the first 4 links you posted.... and stuff from loads of others. I've been working on this for 10+ hours a day for two weeks :)

Taifun

unread,
Feb 22, 2016, 12:04:28 PM2/22/16
to MIT App Inventor Forum
Is there a way to Tag within a Tag?
no, but as already said, learn how to work with list of lists and store your complex list in only one tag!
see also how the lookup in pairs block works

Taifun

Abraham Getzler

unread,
Feb 22, 2016, 2:50:08 PM2/22/16
to MIT App Inventor Forum
Tagging within tags sounds like JSON coding.
See the attached, for a sample of how to go back and forth.

There are a couple of Web blocks that can de-fuse and reinstate those
dangerous embedded commas - 
HTMLTextDecode and URIEncode 

(I probably got the Decode and Encode switched.)
You don't need to have Web access to use them, just the component.

ABG

JSON_pairs_to_text.jpg
JSON_XYZ_encoding.jpg
pairs_to_JSON_to_pairs_to_lookup_value.jpg
JSON_encode_pairs.aia

Shorty

unread,
Feb 22, 2016, 6:22:19 PM2/22/16
to MIT App Inventor Forum
I've been trying to work with lists for this, but I have not been successful.

I need to 'parse' or 'delimit' each row of the text or csv file, into lists I can pick from - where each row is a component in the list, and each field of the row (36 fields) will populate all 36 of my text boxes in the screen.

I've been beating this to death for a very long time now with now success.

I have tried everything I could find that was even remotely similar, even if it didn't make logical sense.

I can't find a single tutorial anywhere that clearly explains, and/or shows, how to do this.

This is straight from the database csv file (asset 1)

“MASTER Database, 001”,1001, 0, 0, 0, 0, 0, 0, 0,comment, 0, 0, 0, 0, 0,,,,,This custom cost database was established to provide uniform costs and,data entry formatting among multiple reserve planners.,,,,,,,,, 0, 0, 0, 0, 0, 0, 0 

I need this in a picker list, and upon picker list selection, I can set each Texbox # to index # (1-36)

Follow?

I feel like I'm missing something. I've tried so many different things. can't seem to do it.

I have rows in the picker list, but they don't show comma's, they are truncated, and selecting them, they are only seen as a single index, not 36

Abraham Getzler

unread,
Feb 22, 2016, 6:32:17 PM2/22/16
to MIT App Inventor Forum
You will need to walk the text character by character, from 1 to length(text).
You will need to keep a true/false variable named "inside".
Start with inside false.
Go from left to right.
As you encounter a quote mark, set inside = not inside.
If you encounter  comma, check if inside.
  If inside, ignore it
  else  use segment block to grab before comma and after comma part.
Add the first part to your empty list, and repeat process after the comma.

This is basically a smarter csv to list operation.

ABG

Abraham Getzler

unread,
Feb 22, 2016, 9:16:10 PM2/22/16
to MIT App Inventor Forum
See attached for a working sample.
ABG

dequote_and_split.aia
sample_run.png
blocks.png

Abraham Getzler

unread,
Feb 22, 2016, 9:44:01 PM2/22/16
to MIT App Inventor Forum
See attached for a result procedure implementation of
quote removal and splitting.

ABG

dequote_and_split.aia
qsplit.png
tests.png

Shorty

unread,
Feb 22, 2016, 10:16:34 PM2/22/16
to MIT App Inventor Forum
Thanks so much for the help!

Unfortunately it didn't work for me. I got the same result I had at one point before - with each CSV value on it's own row in picker.


Really not sure what to do


Abraham Getzler

unread,
Feb 22, 2016, 10:29:19 PM2/22/16
to MIT App Inventor Forum
That's not what you wanted?

I thought it was all about commas in quotes.

Could the problem be that you are reading an entire table
from the file, and you want to split it at every \n to 
get rows consisting of csv text rows?

ABG

Shorty

unread,
Feb 22, 2016, 10:33:40 PM2/22/16
to MIT App Inventor Forum
That sounds about right? I'm very new to this....

I have a CSV file and I need to make a list in AI, with CSV rows separated \n are their own row in the list, but still contain indexes, so when I select one in picker, I can assign all 36 of the indexes to textboxes in the app

Follow?

THANK YOU ! ! ! ! ! !  ! !!

Abraham Getzler

unread,
Feb 22, 2016, 10:45:02 PM2/22/16
to MIT App Inventor Forum
There's a block, either in the text or list section, that does a split of a string into a list,
breaking it at each occurrence of whatever delimiter you supply.
It's like a super charged csv to list block.

In your case the delimiter is \n.

That should give you a list of 250 text strings, with each text string a comma delimited row of your 36 items.

You can create a separate list of just the first items, by looping thru your  list of 250 text strings,
running each string thru qsplit, selecting the 1st element, and adding the resulting string to an empty list.
Load that into your Elements.

ABG



Shorty

unread,
Feb 23, 2016, 2:40:41 PM2/23/16
to MIT App Inventor Forum
Abraham, thank you so much for taking the time to help.

Your input got me thinking a little different, and while this approach is very different, it ended up working out.
What I'm doing is creating a list from CSV table (from the text file) and setting it to the DBpicker variable and assigning that as the picker elements. 
Then, after selecting from the picker, I'm setting the MASTERDB variable to the picker selection index of the DBpicker variable (list), and assigning the textboxes from those indexes.

Works how I want.

There are still a couple things I need to figure out, like, making the picker list populate with only the first index of each list item, but this works and populates all fields (text boxes) correctly from the list item indexes.

Interestingly to me, the commas in indexes populated properly. Must be how the CSV functions work in AI. Which will now require that I revisit my export function, where I was manually building a CSV type text file, but without commas in the textbox fields.... looks as though I'll have to figure out how to export my TinyDB to CSV including commas in values.... I'm hoping 'list to CSV table' will work for this. it may.

If I don't have to remove commas from indexes, that is a good thing.

I will likely be back with a couple more questions as I get further along. :)


Abraham Getzler

unread,
Feb 23, 2016, 3:48:10 PM2/23/16
to MIT App Inventor Forum

There are still a couple things I need to figure out, like, making the picker list populate with only the first index of each list item, but this works and populates all fields (text boxes) correctly from the list item indexes.

 Either of the attached routines should work for selecting a column from a table, for the purpose of loading a picker.

ABG

SELECT2 with automatic PEEL.jpg
DISTINCT.jpg

Shorty

unread,
Feb 23, 2016, 4:14:44 PM2/23/16
to MIT App Inventor Forum
Thanks! I will try these later

One thing I am searching for now, which is probably not possible, or basic and I missed it, is the 'resolution' of the designer window in AI

The tablet I am using with companion has a wider screen than the designer window in AI, and I would like to use that extra width, however app inventors designer window is not allowing that.

As I understand it, I want the screens set to responsive in order to fit other devices...... so I have that set, but, my AI designer window is full, and I still have a bunch of blank space available on the actual tablet screen.

Follow?

Is there a way to change this in AI???? (Sorry if this is basic and I missed it. I have been googling and searching and can't find an answer)

Abraham Getzler

unread,
Feb 23, 2016, 4:28:22 PM2/23/16
to MIT App Inventor Forum
This would be a good question for a new thread.
I personally use "fill parent" on everything, to make everything visible
and to leave room to squeeze in new things, within Arrangements 
I can hide and unhide as needed.

Others on this forum no doubt have better ideas.

ABG

Reply all
Reply to author
Forward
0 new messages