2014년 12월 3일 수요일

CSV to Listpicker


I´ve created a simple database using fusion tables in AI2.
I´ve adapted the pizza party tutorial and now i´m trying to update and delete the values in the table.

I used the "fusioncontrol.getrows"-component to extract the columns and values as csv (i think it´s a csv).

The result looks like this:

col10,col20,col30
val1-1,val2-1,val3-1
val1-2,val2-2,val3-2

I would like to use a listpicker to show the table like this:

------------------ 
col10 = val1-1
col20 = val2-1
col30 = val3-1
------------------
col10 = val1-2
col20 = val2-2
col30 = val3-2
------------------

.....and so on.....

I think i have to extract the columns and the values somehow into a variable to create/fill the listpicker. But i don´t know how...
Can someone please give me a thought-provoking impulse?

--

Try changing csv to array (list) and then selecting item at position x, and then joining the two arrays togather.

Something like this:

join position in list array1
               position 1
join                       = 
join position in list array2
               position 1
join position in list array1
               position 2
join                       = 
join position in list array2
               position 2


And so on,

--
Thanks for your post. 
I don't understand that. How can i change the csv output to array?

--
http://appinventor.mit.edu/explore/ai2/support/blocks/lists.html

list from csv table
Parses a text as a CSV (comma-separated value) formatted table to produce a list of rows, each of which is a list of fields.
Rows can be separated by newlines (\n) or CRLF (\r\n).

--
As result to the csv->"list from csv table" i get ((col10 col20 col30) (val1-1 val 2-1 val3-1) (val1-2 val2-2 val3-2)).....
I´m not sure what to do with this....

--
It is now a list (array), use 


with the list as the name of the list and index as 1.

Next use the "join" block and below add a text box that says " = "

Add a third join section by clicking the blue sqare (mutator block) and dragging the "join" from the left and place it under the already existing "join" blocks (if this makes sense)

As previously use the select list item with the list as your 2nd list and index as 1.

This should make col10 = val1-1

Add more text or change it as required.

--
see the prepaareListpicker procedure here https://puravidaapps.com/fusionDB.php#select to get an idea how this could be done

--
Have you seen 
?

The UPDATE and DELETE queries let you 
change the fusion table directly, if you can build up
the proper query as a text string.

You might need to add extra fusion table objects in the Designer
for different phases in the UPDATE and DELETE process, like getting
a ROWID for later use in an UPDATE or DELETE.

--
Yes i´ve seen it.
At the moment i´m trying to write the rowid in a column named "RowID" for later use.
But it did not work.....

As result of the "send query" i´m getting "rowid\n 12001\n", from this i tried to remove rowid\n and the \n after the rowid itself (the \n ist not really there but the...idon´t know the word...it´s like someone hits enter after the words... :-))

then tried to update the send-query and "update" it right after the "insert"

I´m a newbie in AI2 but i like it very much. Now trying since monday to solve this problem...

See pictures for my blocks...maybe you see where i am wrong.



--
Take particular attention in Taifun's example
how you don't try to extract the rowid until you are in
the event handler that returns the rowid.

Don't assume the rowid will be instantly available.

--
Thank you very much! The "select item list->split at..."-Block helped me out!

I´ll try it now with that and let you know if it will work for me

--
i tried it with the update procedure but it won´t write the rowid in the RowID column in my fusion table.
The UPDATE-SQL-String looks good....but it won´t work....
On screen initialize i set the api-key of the fusion.control2 to the same as the fusion.control1.

Edit: Never ending story....As result of the second fusion.control i get "403 Forbidden Daily Limit for Unauthenticated Use Exceeded. Continue use requires signup."

--
Found the error by myself.
Created a second api-key and set it at the update-procedure.
Then i´ve got a "bad request error..." because i had named one column "RowID". When you set column names to reserved word you have to quotify the column name in the query. (thx taifuns "FAQ´s on FT!!)
--
Exactly what are you updating?
You are setting the row id to itself?

The row id is the LAST thing any one would want to update.
You usually update another field that is dependent upon the row id.

--
what ABG said...
and: why do you need a second api key? this does not make sense.
If you like to connect to another table, another tableid (of the new table) would be sufficient

--
thank you very much for your answers.
I just wanted to create an app to use a fusion table as an online inventory. 
I just need to edit columns (Product, Manufacturer, Quantity) just like your sample an your webpage, Taifun.
But i think it´s to difficult to me.....
INSERT is no problem but UPDATE and DELETE is a little bit too tricky for me....

--
let's assume, you like to update the Quantity of a Product

the first step is to get the rowid of the Product you like to update with a SELECT statement like this
SELECT ROWID FROM< tableID> WHERE Produkt = productNumberOfTheProductYouWantToUpdate

you get back the rowid as described in this example https://groups.google.com/d/msg/mitappinventortest/JBPLDUJhEM8/4ZXUfIEv0b8J
the second step is to do the UPDATE
UPDATE <tableid> SET Quantity = 42 WHERE ROWID = rowidFromStep1

That's all...

--

댓글 없음:

댓글 쓰기