"Invalid Query" error when trying to update a record in a Fusion Table

234 views
Skip to first unread message

Forrest Kendall

unread,
Feb 10, 2015, 6:34:36 PM2/10/15
to mitappinv...@googlegroups.com
I am getting the following error:

Invalid query: Parse error near '2001' (line 1, Position 81).  for the following UPDATE statement:

UPDATE <table id key> SET userid='admin2' WHERE rowid=2001

The parse error occurs with the rowid that I saved when the record was accessed earlier.    I have tried putting quotes around the rowid value, but that generates another error stating that only numbers and underlines are allow in the value.

Thanks for your help on this!

Taifun

unread,
Feb 10, 2015, 6:53:17 PM2/10/15
to mitappinv...@googlegroups.com
how do you extract the rowid? probably there is an invisible \n included?
why this can happen and how to do it correctly, see also here https://groups.google.com/d/msg/mitappinventortest/8Q96DKcylqA/O0hObwUQbd8J
see also
Taifun

Trying to push the limits of App Inventor! Snippets and Tutorials from Pura Vida Apps by Taifun.                

Forrest Kendall

unread,
Feb 10, 2015, 7:00:00 PM2/10/15
to mitappinv...@googlegroups.com
I extracted the ROWID from the queried record.

The SELECT QUERY was as follows:

SELECT rowid,userid,password,organization,delimiter FROM <table id key> WHERE ....

I then parsed the record on the string ",delimiter",   The parsed the data record on commas (",").

You could be right regarding the newline character.   I will try parsing the header record from the data record on newline to see what happens.

Thank you for the suggestion.    I will let you know.

Forrest Kendall

unread,
Feb 10, 2015, 7:18:18 PM2/10/15
to mitappinv...@googlegroups.com
Hi:
just for a test I hard-coded the ROWID=2001 into my UPDATE query.   I get the same results as I initially reported.

Forrest Kendall

unread,
Feb 10, 2015, 7:24:20 PM2/10/15
to mitappinv...@googlegroups.com
The "Do It" test produced no errors.

Taifun

unread,
Feb 10, 2015, 8:59:54 PM2/10/15
to mitappinv...@googlegroups.com
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

Forrest Kendall

unread,
Feb 11, 2015, 11:05:09 AM2/11/15
to mitappinv...@googlegroups.com
I have made a simplified App to isolate the Fusion Table UPDATE query problem. All of the code for performing the UPDATE is in the logic for one button.

The ROWID for this test is: 3001.   This value was retrieved and stored when the App initialized.  Below is a screen shot of the button logic to perform the update.  I have used a text box for diagnostic information to try to see the problem.

Below are 2 screen shots of the Application.   The information in the text box is what is most significant.  The first screen shot the text box contains information for the record to be updated.   This is when the record id (rowid) is captured and saved.

The next screen shot shows the text box with both the UPDATE query string (built in the click event for the button logic above.  The text box also shows the results of the UPDATE query.



Abraham Getzler

unread,
Feb 11, 2015, 1:40:42 PM2/11/15
to
What's the purpose of the FORGET LOGIN  call immediately after sending the UPDATE
and before any response can  arrive?

It looks rude.

ABG

Taifun

unread,
Feb 11, 2015, 2:07:21 PM2/11/15
to mitappinv...@googlegroups.com
I'm not sure, if the trim block can remove the invisible \n in the rowid

I extracted the ROWID from the queried record.
The SELECT QUERY was as follows:
SELECT rowid,userid,password,organization,delimiter FROM <table id key> WHERE ....
I then parsed the record on the string ",delimiter",   The parsed the data record on commas (",").

my suggestion to get the rowid is to convert the result of your select query in to a list of lists
set myList to list from csv table get result

and then select the rowid (which is the first item in the second sublist) like this

set firstDataRow to select list item myList
                             2

set rowid to select list item firstDataRow
                                        1

Taifun

Forrest Kendall

unread,
Feb 11, 2015, 2:45:27 PM2/11/15
to mitappinv...@googlegroups.com
In my original project I extracted the rowid exactly as you suggested.

If you look at the first screen image (from my phone) it shows the record id (rowid) as 3001, right below it I verified that its length is 4 (i.e. there are no hidden characters in the rowid string.

Taifun

unread,
Feb 11, 2015, 3:17:54 PM2/11/15
to mitappinv...@googlegroups.com
as far as I know, the rowid does not need to be quotified...
but it's worth a try 

... WHERE rowid = '3001'

Taifun

Forrest Kendall

unread,
Feb 11, 2015, 3:19:02 PM2/11/15
to mitappinv...@googlegroups.com
I have tried it both ways .... with quotes it tells me that only numeric values are expected for the value.

Taifun

unread,
Feb 11, 2015, 3:24:22 PM2/11/15
to mitappinv...@googlegroups.com
If you look at the first screen image (from my phone) it shows the record id (rowid) as 3001, right below it I verified that its length is 4 (i.e. there are no hidden characters in the rowid string.
post a screenshot of your blocks after receiving the result of the select statement and how you extract the rowid

 I verified that its length is 4 (i.e. there are no hidden characters in the rowid string.
I think, the invisible \n does not have any length...
Taifun

Forrest Kendall

unread,
Feb 11, 2015, 3:55:55 PM2/11/15
to mitappinv...@googlegroups.com
Screen image of SELECT query parsing block ....

temp - receives the split (parsed) result of the SELECT query - parsed on newline (\n).   This should have removed all newline characters.
         temp has a list of the returned records: List item 1 - header record; List item 2 - the data record including the rowid.

rec - string that has record number 2 in it (a CSV string)

userrec - is a list - it contains the split (parse) record 2 (rec string) - parsed on commas (,)

global recid - receives the first item of the userrec list; this should be the rowid returned with as part of the SELECT query

global recid is used when build the UPDATE query string segement "rowid=" + global recid



Abraham Getzler

unread,
Feb 11, 2015, 4:17:48 PM2/11/15
to mitappinv...@googlegroups.com
Is that trailing blank in your SQL UPDATE join necessary?
ABG

Forrest Kendall

unread,
Feb 11, 2015, 4:21:10 PM2/11/15
to mitappinv...@googlegroups.com
No.  It is not necessary.   I have tried not having it in the join, I have put a space in that string, and I have tried a semi-colon (;).   None of these seem make any difference on the problem I am experiencing.

Taifun

unread,
Feb 11, 2015, 4:23:52 PM2/11/15
to mitappinv...@googlegroups.com
instead of using the split blocks, try the list from csv table block as recommended
Taifun

Forrest Kendall

unread,
Feb 11, 2015, 4:25:07 PM2/11/15
to mitappinv...@googlegroups.com
Just as a test I downloaded the PizzaParty app and test it.   This app INSERTs records without problems into my linked Fusion Table.  However, when I modified this app a bit to UPDATE one of the records I get the same error as we are tracking in this post dialog.

Forrest Kendall

unread,
Feb 11, 2015, 4:35:42 PM2/11/15
to mitappinv...@googlegroups.com
OK ... I replaced the "split" on comma block with the "list from csv".   The extracted rowid from the new list is the same (no change); and the Invalid Query error still persists at the same location.

Forrest Kendall

unread,
Feb 11, 2015, 4:37:16 PM2/11/15
to mitappinv...@googlegroups.com
do you have any examples of an UPDATE query that works correctly?  If so please send me the aia file for the project and/or test code.

Paul LeChef

unread,
Feb 11, 2015, 5:32:06 PM2/11/15
to mitappinv...@googlegroups.com
No doubt about it, Fusion Tables are weird. In your shoes, I would check the fusion table itself to make sure the rowid hasn't changed, which it will do if you re-insert rows or, sometimes, when you delete some. Next I would try using ROWID instead of rowid. I know it doesn't make sense, but rowid seems to work intermittently while ROWID always seems to.

I always, quote-out the row id.

Are you using the FusiontablesControl? If so, the key should not be included in the query. the error reads, "near 2001&" so I'm thinking that may be the problem. Put the key in the block that AI2 has for it.

Cheers

Paul

Taifun

unread,
Feb 11, 2015, 5:32:21 PM2/11/15
to mitappinv...@googlegroups.com
an update statement like this

UPDATE 1Ty90w_LWJEgZHNwEWgoebigLDEXPYLAgJHVHSFkk SET Date='11.02.2015 16:23:59', Pizza='Pepperoni', Drink='Cerveza', Comment='and beer' WHERE ROWID='2001'

worked fine for me (note: the rowid must be quotified)
Taifun

Forrest Kendall

unread,
Feb 11, 2015, 6:43:51 PM2/11/15
to mitappinv...@googlegroups.com
Paul: Thank you for the suggestions.

The API Key (I assume that is the Key you referred to) is set with at different block, it is NOT part of the SQL UPDATE string.

The strange number you see in the query example in the Table ID number (i.e the table name) for the query.

I will test variations of ROWID and rowid again, but I think I have already done this.   I will let you know.

Forrest Kendall

unread,
Feb 11, 2015, 6:49:45 PM2/11/15
to mitappinv...@googlegroups.com
Paul:
THANK YOU!!   What finally worked was as you suggested:   UPDATE ..... WHERE ROWID='3001' (rowid in caps and the number in single quotes.

Forrest Kendall

unread,
Feb 11, 2015, 6:53:56 PM2/11/15
to mitappinv...@googlegroups.com
Taifun:
Thank you for your suggestion, I also had the same suggestion from Paul LeChef in post right before yours.   The proper syntax for and UPDATE query is:

UPDATE ..... WHERE ROWID='3001' (rowid in caps and the number in single quotes.)

Thank for you patience and diligence in tracking this problem down.    It would be helpful if the documentation for the FusionTable control included this.   I am going to mark this problem as "closed."

Thanks to everyone who got involved!!

Taifun

unread,
Feb 11, 2015, 7:00:49 PM2/11/15
to mitappinv...@googlegroups.com
see also the fusiontable documentation https://developers.google.com/fusiontables/docs/v1/sql-reference#updateRow
Taifun

<row_id>The ID of the row you want to update. A quoted string. To get the row ID, perform a SELECT before the UPDATE.

Reply all
Reply to author
Forward
0 new messages