Update csv file

I could create and save data into .csv. I created a procedure to read existing ID from .csv and generate uniID . I also created some produces to filter data and show limited values in the listview. Unique ID helped me to track which item I selected in the listview.

I would like to update a selected row of data. Delete the row and upload an updated row data back into .csv file. I loaded all data from .cvs into memory (a variable) but I don’t prefer to load the whole list of data from variable back to .cvs. SaveAs (Overwrite) the whole .csv. I worry insufficient memory when data is too big.

Please share if you know how to do it.

I prefer not to upload data into server. I prefer to save data into phone only. Are there other apps (like VB link with Microsoft Access) that is allowable for me to use and data transfer is pure in the phone.

Your method is the easiest way when working with a csv file on the device. How big do you expect the data to become ?

I would make it as daily record. So, I would expect around 2MB storage for the largest cvs file. Lots of them are as small as kB. In between cvs files, I would like to create main ID and subID (subID refer to another cvs mainID). Sometimes, I need at least three variables to store for the same data from cvs. For example, variable 1 would collect data from cvs (this variable is also monitor the next unique ID), variable 2 would filter data and show specific row, variable 3 is same as variable 2 but some columns like ID and internal calculations won’t display for user. You may think variable 3 is redundant but like listview will display everything. I need to create variable 3 and insert it into listview. When user select an item in the listview, the selected index can be used for variable 2 and find the right ID.

For many global variables in a program, I afraid insufficient memory or really slow to run the program.

I am not a programmer but interest to play this. I am a beginner. Can you please provide some suggestions that I can use MIT app, link with other SQL app and run without internet? In Australia, rural areas still don’t have good internet or signals. I went to Saibai recently. Saibai belongs to Australia but internet is terrible slow and could be no phone signal in some days. Of course I could use international roaming or satellite but price is terrible expensive. That is why I try to build an app and data saved in the phone.

You could consider sqlite for an on device database

https://puravidaapps.com/sqlite.php

(There are other extensions for this)

If you decide upon using sqlite you might consider these capable (free) extensions below. The linked extension mentioned by Tim is a paid extension.

This one works great for me https://github.com/frdfsnlght/aix-SQLite

and here is another one

https://community.thunkable.com/t/free-sqlite-extension-sponsored/8802

Alternatively, store your information in a flat file database using the TinyDB component. A TinyDB stores information (like your csv file) on your device. This solution does not require an extension. There is a brief introduction showing how it works here Chapter 22. Databases What you want to do is complex but should be possible by manipulating the data using Lists if you store your csv information as a Tag that contains the information in a List format.

Here are some resources to help you learn to use the AI2 tools A very good way to learn App Inventor is to read the free Inventor’s Manual here in the AI2 free online eBook http://www.appinventor.org/book2 … the links are at the bottom of the Web page. The book ‘teaches’ users how to program with AI2 blocks.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro and the aia files for the projects in the book are here: http://www.appinventor.org/bookFiles

How to do a lot of basic things with App Inventor are described here: http://www.appinventor.org/content/howDoYou/eventHandling .

Regards,
Steve

1 Like

Thanks Tim and Steve. I will read the manual first and go back to create my own app. I will try TinyDB first and then SQL.

My last question in this topic:

For csv, comma is the separator and split the whole row into items. How about TinyDB? Does it use special characters to split items? Any special characters will destroy or divide the item into multi items and what is the maximum length on each item in TinyDB? Does TinyDB hold more data when compare with csv?

If your csv data is properly formatted (as csv) then you should be able to load it into a tinydb using a variable and the list from csv row or list from csv table blocks in the Lists palette.

In csv:

A row would be:

dog,cat,pig,cow (quotes may show - “dog”,“cat”,“pig”,“cow”)

A table would be: (you will probably have invisible “\n” at the end of each line)

name, number,image
bob,21,image1.png
jim,45,image2.png
jane,34,image3.png

or with quotes

“name”,“number”,“image”
“bob”,“21”,“image1.png”
“jim”,“45”,“image2.png”
“jane”,“34”,“image3.png”

if you want to go the TinyDB route, here’s a sample app that builds up complex tags to store different kinds of data structures …
https://docs.google.com/document/d/1GLQJY9q3b8KsEAcfzPEcA-j0zWgyRjTI2Pa792znsBI/edit?usp=sharing

If you are accumulating daily data and you might want to tabulate and summarize it, SQLite is better for that.

There are probably local spreadsheet apps you can use for this too.

Thanks for your example. This is a such good starting point for me to understand the concept of TinyDB and the better way to use Procedure Sub and function.

For TinyDB, does MIT APp Inventor allow us to use multi-TinyDB (LIke other Apps)?

Thanks a lot for your explanation.

Thanks SteveJG, It is nice to group and point out lots of referencing. This is one of the best option for me to start from beginning.

yes, you can use the TinyDBX Extension by Juan Antonio to use several TinyDBs in an app
see also the extensions directory here App Inventor Extensions | Pura Vida Apps

Taifun


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

Thanks Taifun.

1 Like