2015년 1월 4일 일요일

How to combine tinydb and tinywebdb?

I wanna combine tinywebdb and tinydb to save values to an online database but still be able to view the data in the app when offline. is this possible? how would the blocks need to be arranged to get this to happen? any direct help would be appreciated.



Use the TinyWedDB to maintain the values on the web.  Do all of your work in a local TinyDB.  When you need to update, do it int he TinyDB, then upload the results to the web with the TinyDB.  When you open the app, get the info from the web with the TinyWebDB, build lists and store them in the TinyDB.  



so, i have created the database online with appspot.com and added the tinywebdb block to the project. basically, i have the app set to pull the tags at app initialize and then using a listpicker to choose the values from the tag. I dont have a list created in the app. how it works is when you click the tag in the app, the value is then pulled and displayed. i am trying to figure out how to add the tinydb block to save the tag and values that the tinywebdb pulls from the internet and have it accessible from the same listpicker when you go offline.


so for screen initialize, i have the tinywebdb getvalue and for the listpicker afterpicking, i have the tinywebdb get value. the tinyweb gotvalue has the populate listpicker elements. where would i use the tinydb? would i use the tinydb storevalue with the listpicker after picking and the tindb getvalue in the screen intialize?



can anyone help me?



What information are you saving in each record of your Fusion Table?




it's not a fusion table. i am trying to use tinywebdb and tinydb together in a singles app. tinywebdb will store and pull information on a online database and show in the app when online. tinydb will save the information in the app to use when offline. they will both respond to a single listpicker. what i would like to do is have the online database be the main source of information, where i update the tag and value and it gets saved in the app by tinydb. I have the app set up to use tinywebdb to pull the tag and value and display the tag in the listpicker and the value in the label but i cant figure out the next step of having tinydb save the information that tinywebdb pulls in.

how would i get this done?



WHAT INFORMATION ARE YOU GETTING FROM THE ONLINE DATABASE???



what exactly do you you mean "WHAT INFORMATION ARE YOU GETTING FROM THE ONLINE DATABASE???" ? the online database contains tags and value aka text, not images or files. the information i am getting is exactly what i said in my previous posts. can you clarify what exactly you want me to tell you? i assume information is information so are you asking me to tell you the exact text used for the tags and what is entered for the values?

by the way, what is with the all caps? I asked a question to the forum and you chose to answer and were not obligated to. A question is meant to be asked and if you do not know the answer, it is more beneficial not to respond and allow someone else who knows the answer to chime in. Thanks.



Yes... please give me a list of fields that you've used to store the info on the web like: Name, Street Address, Age, Gender, Location... that sort of thing.  You have to have some structure to what you're saving.  What is that structure?

If we ask you for something, it's to help you out.  In your response, you totally ignored the question.  I understandwhat you want to do.  Now, I'm asking you to provide information.

What is the structure of the data you're saving.  If you have no structure in the data, then that's what you have to tackle first, because every record in a database has to have the same fields, although the information is different IN those fields.



Here is the aia file so you can see what i have so far




Here is the aia file so you can see what i have so far



Are you trying to have your tinydb synced with tinywebdb all the time OR, if network not available, fall back on tinydb?



so, the idea is, if I add new tag/values to the database, tinywebdb would be able to capture and display the changes while tinydb saves it for offline use. if I go offline with the app, tinydb still shows the last saved tag/value in the app. in other words, the app can update new content when online but displays the currently saved data when offline.



So this means that everytime you start the app, in the Screen1.Initialize, you have to check to see if you have connection, 
if have-connection, get data from webdb and sync the tinydb and init data from tinydb
if no-connection, get data from tinydb and init data



ok, cool. so how would I set the blocks to get that done? I have done an app before using tinydb to save data and now a tinyweb to pull data but cannot figure out the blocks correctly to tie tinywebdb and tinydb together. can you help me?



It depends how your data is set up.
If you have simple tag, value, then from TinyWebDb, get tag and do TinyDb1.StoreValue

You'll need to post screenshot of what you have done so far so that we can help you better.



wow!!!

ok. i thought i added the aia file above but here is a screenshot:




You are setting the value list to the tag List...why?  Also, where is your store value call for saving the information?
 
 so, the idea is, if I add new tag/values to the database, tinywebdb would be able to capture and display the changes while tinydb saves it for offline use. if I go offline with the app, tinydb still shows the last saved tag/value in the app. in other words, the app can update new content when online but displays the currently saved data when offline.

Just make sure you are storing the information to both at the same time.  You might be able to detect when you aren't online simply by using the TinyWebDB.WebServiceError event.  If you get an error there, you could store the information you tried to save to the TinyDB instead of the webDB and upload it online later.



Honestly Stephen, I have no idea what I am doing. I am just trying something and seeing if I get the desired result. I don't know how to use the store value call or where to put it. I don't know how to use the web service error event. basically, I came here to seek help to do my app and it seems I have spent more time answering questions than actually getting any assistance to figure out how to get what I am trying to do done. it seems everyone is assuming I know this and know that, I am not a programmer. All I am looking for is guidance to fix the app. what would I do with the webservice event aka where would I put it? where would I put the store call value? how should the value/tag list be set up?

If no one can help me, that's fine but I really don't understand why we are having these long conversations but I am still thankful that you, Enis and Hossien have taken the time to respond.



Just out of curiosity, have you done any of the tutorials?  They can be a huge help in learning how all of this works.  In addition, the Pizza Party tutorial teaches how to get and put info to the web.

I really do understand what you want to do, and as Stephen says, you basically have to shadow everything you're doing with the TinyWebDB with the TinyDB, so that you have a web, AND a local copy of all data.  What you're trying to do is definitely a bit complicated. 

Everytime you add something to the table on the web, you also have to add it to the local TinyDB.

One problem in your AIA file is that I don't see any place where you actually ADD the data to the table on the web.  Is the table on the web being changed by someone else?  If so, are you only concerned about copying that data and having it locally?  If that's the case, then it's not so difficult.  But that's a very important distinction.  Let us know about this as it completely changes the way you need to do things.

Honestly, the BEST way to learn how to work with web data is to do the Pizza Party tutorial.  It won't take that long, but you'll learn mountains about how to deal with data on the web.  The tutorials are located here:http://appinventor.mit.edu/explore/ai2/tutorials.



ok Enis. I will try to see if I can do this again.

I have a database created on appspot.com. I will manually update tags and values in the database online meaning I will pull up my internet browser and then go to my database on appspot and enter the tag and value by hand to store there. I know how to do this and am comfortable in doing it and have NO PROBLEM with this part. This part is not and has not been a problem.

What I want to do now is build an android app where tinywebdb calls the database and pulls the tags into a listpicker where they will reside as the elements. when you make a selection in the listpicker, the tag selected will pull and show the corresponding value in a label component. With what I have done already, this is already achieved. If I make a change to the appspot database, the app will refresh and show the update on initialize. This is already done and if anyone had looked at the aia file I added, they would have seen that that part is accomplished. I have to admit that I still don't understand the blocks used but I got the desired result so I am moving on to the next phase.

The part I am having trouble with is:

if you go offline with the app (meaning no internet on the phone), the values and tags do not load. this is understandable since the tinywebdb needs the internet to pull the information from the online database to display in the app. I do not understand where I need to add the tinydb get block and the tinydb store block. I have tried different places in the blocks editor that I have in my app and they never work when I go offline.

so, to recap:
I do not understand most of the blocks or how they should be used but I am trying.
I achieved most of what I have in the aia file by trial and error but cant seem to get the tinydb part to work.
I want to know what block should be added where to get the desired result.
I plan only to update the database on appspot so I did not add a tinywebdb store block in the app because there was no reason to

p.s. I did recreate the pizza app which deals only with tinydb and as far as I can tell, still do not understand it. All I am asking for (and hope to get an answer to) is how to tie the tinywebdb get or got block to the tinydb store block or get block so when you are offline, the app still displays the tags and values. can you send me a pic or edit the aia file to let me see where the blocks should be placed or at least write back to say how to do it (example - put the tinydb get block with a global variable in the plug under the tinywebdb got event...)



What you're missing here is an entire dump from the web to the app.  That's the only way you can keep it synced.

I've got to run out for a while now, but I'll see if I can get you something later, if nobody else jumps in first.  Since you're updating the appspot database yourself, outside the app, you need to check, in screen1.initialize, if you have a connection.  If you have a connection, you need to download ALL of the data to lists, then run through the lists and compare them to the TinyDB, altering it if necessary.  The reason you need lists is that you may not have to update the TinyDB data if it matches.  Also, you don't want to nuke the information in the TinyDB until you're sure that your data download from the web was complete, or you'd corrupt the TinyDB which IS as complete as the last full update.

I won't be back for about 7 hours, but I'll take a look when I return.

Just out of curiosity, how many tags are you storing in the AppSpot database?  Just curious as that will determine how long the process may take to get all of the data before a connection craps out.



solidgear, check out my TinyWebDB tutorial here.  I'm presently looking at your project but it's going to take me a bit of time to get something back to you.

If no one can help me, that's fine

We can help, don't worry about that.
 
but I really don't understand why we are having these long conversations 

Unfortunately we cannot accurately help if we don't have most (or maybe just a large chunk) of the information for what you're trying to do.  It may seem like we're just running around in circles, but I promise you that we're trying to get our heads wrapped around your idea, since we can't read your mind.  :)  Please don't lose faith and wait just a little longer okay?



solid:

I think I have a solution to your problem, but I want to know if it's OK to modify your data on appspot.  

If you say yes, then leave the database alone for a day and I'll post the solution for you tomorrow afternoon sometime...

Just let me know...



I am perfectly fine with this. You may modify as much as you want



Something's come up and I'll have to do this late tonight.  Check inthe morning and it'll be here...  I did add a single field.



I looked at the database and saw an entry. Is this the single field you are referring to or did you mean you added 1 field in my app to make it work? if the second is correct, I would love to know what field :)



No, I added the single counter field... you need it to know how many fields to cycle through... More later... gotta run...



Sorry Solid... had a bunch of issues here I had to resolve... I'm tinkering with this now and should be able to upload something in an hour or two for you...



Thanks. Real curious what you will have to show me. I am also curious what I left out of mine.



hey Enis, any update?



Sent you an private email.  Did you get it?



yeah. I just saw it.



OK, here it is, and it works.  HOWEVER, you still need to do a little work, and I don't have the time now to figure the rest out.  Here's what you need to do:
You need to check CONNECTIVITY.  What that means is that if you can't connect to the database (use the TinyWebDb Error Block), you'll need to take what's in the TinyDB instead.  Frankly, that's a bit of a difficult problem in that you only know if the TinyWebDB can't connect if you try and get the error.  You might have to use another component to test the connectivity to the web first, and if that succeeds, then do the TinyWebDB call and go from there.  If it doesn't succeed, then just use the existing TinyDB, the first record of which will be the list...
However, you'll see that the TinyDB is populated. and will be persistent.  Since it's persistent, if the connectivity fails, the data's already in the TinyDB...
Hope this helps you out... I'm going to post the same message on the forum with a screenshot so that if anyone sees something wrong or missing, they can add to it.  The blocks are shown below.
Good luck & best wishes...




thanks for the help. the .aia file did not work as expected when i built it as an apk and installed it. After fiddling around for a few days, i finally got it working how i want it to. thanks for your help



i know how to do it pay me 2p



plzzz i am poor my name is uwais from older hill school in bradfpord


댓글 없음:

댓글 쓰기