2017년 1월 4일 수요일

Searching in TinyDB


I created a TinyDB in which the user can store productinformation, they read out from a NFC tag. 
The information looks like shown below:

Serielno: 12345
Type: T-Shirt
Size: Large

The information is loaded in the TinyDB as one entry.
Now I am creating a searchoption. The user needs to search for serialnumber and the enty containing this number is shown in a textbox.
I have tried multiple blocks to filter te TinyDB for a given serialnumber, but is doesn't filter the entry which contains that number/piece of text. I always get the message that the product is not found.
See the screenshot for the used blocks.

Hope someone can help me out!

 21 NFCDB (blocks) - zoekfunctie 5 (niet werkend).jpg

--
This should work.

 Capture.PNG

-- 
I see two different names for the TinyDB component ...
TinyDB2 and SavedApronsDB ?

You know that they are the same database, right?

--
Thanks for your reply.

I copied your setup but I keep getting the same message, product not found. Probably it has the same problem as my setup, it can't find the tag with only the serialnumber.

--
Thanks for your reply.

It was a little mistake, but doesn't change the problem I'm having.

--
Both images in this thread are currently irretrievable, for some unknown reason,
so I'll offer some blind ideas ...

The TinyDb storage of your data is in an unexpected format;
Code a test routine to loop through all tags and dump their
tag/value pairs to a ListView.  Surround both the tag and value with quotes,
to expose hidden whitespace.

Your scanner is adding whitespace to its input.
Wrap its output in quotes and display it in a label.

-- 
Thanks for your time! 

Is it possible that you can show an example of what your saying?
I'm not really understanding what you mean.

--
See attached for how to dump the contents of your TinyDB.

 2016-03-03 13_06_47-5554__build_.png

 blocks.png

 Designer.png



-- 
Thanks for your response! You helped me 1 step closer to the wanted result. 

I got the app to show the listed data, but is still doesn't filter on a given serialnumber. Instead it just shows al the listed data.

--
Can you post your modified blocks? And maybe an .aia?

--  
See the attachment for my implementation of the blocks.

 21 NFCDB (blocks) - zoekfunctie 7 (niet werkend).jpg

--
When you click the search button, you will get in the listview all tags that are in the SavedApronsDB. If that is what you want, fine.
But you could do that directly by set listviiw1 elements to call SavedApronsDB.getTags.
And, you are building a list in global tag of all the values of these tags. Why?? You have them in the TinyDB, and you could retrieve the value from the TinyDB if your user selects a tag from the listview.
I am missing a: when ListView1.AfterPicking block. If the user selects an item from the listview, you could retrieve the value from the SavedAprons_DB and display what you receive in a label.

-- 
Let's get back to the original problem.

You say you read serial numbers with a sensor, and want to look up TinyDB tags by the incoming serial numbers, but you never get a match.

So there are these things that might be going wrong ...

The serial numbers never arrive from the sensor,
The serial numbers aren't in your TinyDB tags, or are coded weird,
The serial numbers arrive from the sensor, but are coded weird.

I gave you a dump procedure to answer the second hypotheses, by seeing what's in TinyDB.

At this point, if you have actually seen what is in TinyDB (which I am not sure of, by the typos in your copy of my procedure),
the next step is to display the sensor reading of the serial number and screen print it.
Wrap the serial number in quotes, so we can see if there is anything extra riding along.

I do NOT mean typing a serial number into a block.
I mean capturing a serial number from the sensor into a global variable or label,
then displaying its contents in the Blocks Editor using a right-click-DoIt ,
taking a screen shot, and posting it here.

This mismatch can not be diagnosed without the Do It shot.

-- 
I got the TinyDB up and running and since your example I can find the tags that are saved in the TinyDB. The only problem is that when I use my Search optoin, it shows al the saved tags.
The next step in need to build is that the saved tag can been search for by entering a little piece of text of the tag.
So when the following tag is in the TinyDB:

Typ: Shirt
Serialno.: 12345
Size: XL

User need to get access to this piece of data by searching for: 12345. The user enters this in a textbox and another textbox shows the matching tag.
The problem now is, that the app ignores the 12345 and just shows the whole list. Both in the listviewer and in the textbox version. (The perfect app for us is one whitout the listviewer option)
What I want is that the app looks for an entry in the list, by searching for a little piece of the tag.

I think that the problem maybe caused by the fact that the listentry is multilined, the three lines above are one piece in the list. 
Or that the app doesn't make a new listitem when a new tag is entered?

EDIT: 

I have been trying to make the searchfunction work, but so far I have come only to display an message when the entry is in our searchbox is false. When a serialnumber is enter that is in the TinyDB I wil get the saved Tag. But, when multiple tags are entered, only the first one wil show, even when the serialnumber of the second tag is being searched for.

Attached you find the blocks.

 21 NFCDB (blocks) - zoekfunctie 9 (filter nog niet werkend).jpg

--
to simplify things, my recommendation is to use a fusiontable to store your data
you can easily send queries to the table like this
SELECT * FROM <tableid> WHERE Serialno = "12345"

--
For the TinyDB case, did you think of filtering the list entries by using the "contains text ... piece ... " text block?

--
The data needs to bestored on the device of the user. There are going to be multiple users, where each user has his own database. Thereby it can't be that databases of multiple users are stored together.
We want the users of the app to get a database of the products they are using. Not a database with the product their neighbour is using.


I have been looking at the Fusion Table DB, but I don't think it's a suitable solution for what we want with the app. (correct me if I'm wrong)

--
I have tried that option, but could not get it to work somehow. 

-- 
you could use a fusiontable, but you would have to add another column to identify the user to make sure, a user can only see his data

unfortunately MIT App Inventor does not offer access to the local SQlite database, but I can offer my SQlite extension
for more information see here https://puravidaapps.com/sqliteExt.php

The App Inventor Extensions are currently in testing. See the announcement for more information and read the App Inventor Extensions document about how to use an App Inventor Extension.

--
But isn't it possible to use the TinyDB? 

--
But isn't it possible to use the TinyDB? 
sure, it's possible, but more complicated

I think that the problem maybe caused by the fact that the listentry is multilined, the three lines above are one piece in the list. 
probably yes

you also can work with lists and list of lists
for example use one list to only store the serial numbers
and another list to store the detail data (this will be a list of lists)
then store the 2 lists in 2 separate tags in TinyDB

to search for a serial number, just get the selection index in list1 and use that selection index to get the detail data from list2


--
The user is going to scan the data from a NFC chip in the products. I have been looking at lists of lists, but is seems not to work. 
I wasn't able to separed the different lines from the chip into different textboxes, to make a list of list.

--
you always can use text blocks to split information

--
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  .

Also do the tutorials http://appinventor.mit.edu/explore/ai2/tutorials.html to learn the basics of App Inventor, then try something and follow the
 Top 5 Tips: How to learn App Inventor

You will not find a tutorial, which does exactly what you are looking for. But doing the tutorials (not only reading a little bit) help you to understand, how things are working. This is important and this is the first step to do.

--

댓글 없음:

댓글 쓰기