Extension: Get all TinyDB as Text. Csv, Json. Recovery.

7,100 views
Skip to first unread message

Juan Antonio

unread,
Jul 31, 2017, 1:20:28 PM7/31/17
to MIT App Inventor Forum
Hi friends,

1.- This extension get all TinyDB data of an app.

2.- You can get all TinyDB data as text, in format CSV or JSON.

3.- By File component you can save text in format CSV as a backup in an external file, example: /backuptinydb.txt

4.- You can edit external file, and then load in TinyDB.

5.- "Delete characters from text", again in this extension.
 
 6.- Remember, when you put several TinyDB in your app (TinyDB1, TinyDB2, TinyDB3,...) all are the same file.



 
 Regards.
 
 Juan Antonio Villalpando

 




KIO4_GetTiny.aia
com.KIO4_GetTinyDB.aix

Andres Daniel

unread,
Jul 31, 2017, 3:06:52 PM7/31/17
to MIT App Inventor Forum
hola Juan

por favor también puede publicar tus extensiones en appybuider.com y thunkable.com


gracias por tu trabajo y dedicación

saludos


Andres

Abraham Getzler

unread,
Jul 31, 2017, 3:12:31 PM7/31/17
to MIT App Inventor Forum
Have you tried to run your JSON text output through the Web1 JSONTextDecode block yet?

Does its format match JSON.org specification?

I am suspicious of the sample data you show.
It looks like you were supposed to get as your TinyDB values lists of two texts and a number,
but the double quotes are on the outside of the square brackets [] (list item) instead of
around the text values.

ABG


Evan Patton

unread,
Jul 31, 2017, 10:46:31 PM7/31/17
to MIT App Inventor Forum
@Andres:
Any extension that is built for App Inventor should work in any downstream versions as long as they are keeping up-to-date with our master branch. If you are having difficulty loading an extension in one of those products, you should reach out to them.

@ABG:
I think the data shown in Juan's screenshot is the CSV version, not the JSON version. TinyDB is a really just a mapping of strings to strings implemented using the SharedPreferences object in the Android SDK. When you store something like a list as a value, there are some utility classes in App Inventor that manage the serialization of the data in/out of the SharedPreferences. My guess, without seeing the extension sources, is that Juan is reading the SharedPreferences as key-value pairs without deserializing them and that's the output you get.

Evan

Juan Antonio

unread,
Aug 1, 2017, 5:07:15 AM8/1/17
to MIT App Inventor Forum
Evan, all you write in this post is true, screenshot is CSV version and this code read SharedPreferences as key-value in csv version.

- This is a cat from TinyDB1.xml in shared_prefs



- Look e accent in México and n tilde in España, encoding utf-8

- My code get this file and return in this json format:

{Juan="[Antonio, 22, España]", Luis="[Santos, 44, Colombia]", Pedro="[Banderas, 33 México]"}

- Is this a correct form of json for App Inventor? or should I change the format?

- Csv function adapt to csv

for (String etiqueta : keyList) { // va tomando línea a línea del String.
// Obtiene el valor de cada etiqueta con GetValue.
// Va creando línea a línea el csv.
     csv = csv + etiqueta + "," +  "\""  + GetValue(etiqueta, "") +  "\"" + nuevalinea;
   }

Luis,"[Santos, 44, Colombia]"
Pedro,"[Banderas, 33, México]"
Juan,"[Antonio, 22, España]"

- If user get their TinyDB in csv in an external file, then it is easy change data.





@Evan
Evan Pedro says to publish this extension in others sites, but not to adapt code. :) (sorry my bad English) 


Evan Patton

unread,
Aug 1, 2017, 10:04:06 AM8/1/17
to MIT App Inventor Forum
Hi Juan,

The way I interpreted your post was that the JSON version would be proper JSON (and I assume ABG is thinking similarly). In this case, you will want to use the getObjectFromJson method in com.google.appinventor.components.runtime.util.JsonUtil to turn the string representation back into a proper App Inventor object that you then serialize. Something that still looks very weird to me, and may possibly be a bug, is that the strings internal to the array are not quoted.

Evan

Juan Antonio

unread,
Aug 1, 2017, 12:33:12 PM8/1/17
to MIT App Inventor Forum
In this version I changed json format, now get

{  
   "Juan":"Antonio, 22, España",
   "Luis":"Santos, 44, Colombia",
   "Pedro":"Banderas, 33, México"
}

It run in a validator web json, and is a valid json.


com.KIO4_GetTinyDB.aix

Abraham Getzler

unread,
Aug 1, 2017, 1:18:46 PM8/1/17
to MIT App Inventor Forum
When you retrieve TinyDB tag Juan and apply the block is a list
to the value, what gets returned?  true or false ?

What was originally stored in TinyDB under tag Juan ?
csv from list(...) or a three item list?

(I am testing if list structures are being preserved
going into TinyDB and coming out as JSON.)

ABG

Abraham Getzler

unread,
Aug 1, 2017, 1:38:31 PM8/1/17
to MIT App Inventor Forum
If you want some sample data and a test bed, see this Gallery project ...
to compare it against a blocks-only version.

I also included an Ouroborous generator procedure,
to stress test your code with an infinitely deep list.

Documentation for the project is under way.

ABG

Juan Antonio

unread,
Aug 1, 2017, 1:54:47 PM8/1/17
to MIT App Inventor Forum
Hi Abraham,

Store datas:

Save in TinyDB1xml

Get json format,web1.decodejson, index-1 (Juan) with this values "Antonio, 22, España" is a list

- The main purpose of this extension is to save the TinyDB to an external file in the csv format, that file can be backed up. We can also modify that file and reload it in the TinyDB.


We can have an initial file in the asset directory and when users install the application and run for the first time, that data is loaded into the TinyDB.


Thank you Abraham, I will consult your Gallery project.







Evan Patton

unread,
Aug 1, 2017, 2:21:53 PM8/1/17
to MIT App Inventor Forum
I will note that our JSON serializer isn't robust to lists that eat themselves :).

Evan

Abraham Getzler

unread,
Aug 1, 2017, 2:49:23 PM8/1/17
to MIT App Inventor Forum

Juan Antonio

unread,
Aug 2, 2017, 11:57:00 AM8/2/17
to mitappinv...@googlegroups.com
Last version: 2/august/17

It can load file from asset of Companion or installed. Write file with double slash //backuptiny.txt for load from asset.




com.KIO4_GetTinyDB.aix

Kijana

unread,
Aug 6, 2019, 10:50:47 AM8/6/19
to MIT App Inventor Forum
Hey, can I use this extension in my application and build it, is that your agreement?

Thank you for a really cool solution;)

Juan Antonio

unread,
Aug 6, 2019, 2:11:49 PM8/6/19
to MIT App Inventor Forum
This extension is Free.

Vishal Nage

unread,
Jan 15, 2020, 10:59:06 AM1/15/20
to MIT App Inventor Forum
i want to backup this DB to File. . .  /backup.txt

and clear cache of APP

and again want Restore...from file . . ./backup.txt

Is This Possible ????????

Whats is Solution for this . . .??????

Chris Ward

unread,
Jan 15, 2020, 11:07:04 AM1/15/20
to MIT App Inventor Forum
Free code snippet:

https://www.professorcad.co.uk/appinventorsnippets#TinyDbBackup

============================================================================
For future help please use the new App Inventor Forum: https://community.appinventor.mit.edu
============================================================================
Reply all
Reply to author
Forward
0 new messages