Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'SELECT' returns an object with 'rows.length' but no 'rows.items' #441

Closed
benshope opened this issue Mar 14, 2016 · 11 comments
Closed

'SELECT' returns an object with 'rows.length' but no 'rows.items' #441

benshope opened this issue Mar 14, 2016 · 11 comments

Comments

@benshope
Copy link

I am having the same issue as this person:

http://stackoverflow.com/questions/32973678/cordova-sqlite-query-rows-length-0-but-items-throws-exception

My sql SELECT returns an object with rows.length but no rows.item. My script works fine in Chrome. I attempted to downgrade, but that did not appear to solve the problem. Any idea what might be going on?

@brodycj
Copy link
Contributor

brodycj commented Mar 14, 2016

Please specify which platform(s), which Xcode version in case of iOS, and a small test program to reproduce the issue thanks!

@benshope
Copy link
Author

Nvm, sorry! Tried a few more things and it works. Thanks for writing a great plugin!

@osro
Copy link

osro commented Mar 23, 2016

@benshope Any idea what did you do? I'm having this same issue after I upgraded cordova, cordova project version and cordova plugins including this plugin.

Same thing happens on iOS and Android.

I have database that is holding blop images. The result comes out just fine when I example COUNT images that I have in my database.

tx.executeSql("SELECT count(tile_id) AS cnt FROM images;", [], function (tx, res) {
       console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 2191");
     });
} 

And the output is 2191 like it should be.

But when I try to fetch the actual image BLOP

tx.executeSql("SELECT tile_data FROM images INNER JOIN map ON images.tile_id = map.tile_id WHERE zoom_level = ? AND tile_column = ? AND tile_row = ?", [z, x, y], function (tx, res) {               
                    console.log("%o", res.rows.item(0));                
            }

The rows length is 1 like it should be, but when I try to access it by item(0) it is completely empty.
I have tested that the SQL-statement is correct and it works fine with SQLite Browser. Also this actually used to work earlier, but now something happen in the updates.

cordova 6.0.0
cordova-sqlite-storage 0.8.4-dev

@brodycj
Copy link
Contributor

brodycj commented Mar 23, 2016

@osro I think you meant that you tried to fetch an image BLOB.

The storage and retrieval of the BLOB data type is currently not supported by this project. A version that supports retrieval of BLOB data is available with a different licensing scheme at: https://github.com/litehelpers/Cordova-sqlite-evfree-ext

@osro
Copy link

osro commented Mar 23, 2016

Yep, that was it 😄 Thanks!

@doc-brown
Copy link

@benshope I am having the same problem and I am just trying to read a string from the database. Can you tell me what you did to solve this problem?

@brodycj
Copy link
Contributor

brodycj commented Jan 29, 2018

@doc-brown please raise a new issue in https://github.com/litehelpers/Cordova-sqlite-help with a self-contained demo if you are having this kind of an issue.

@brodycj
Copy link
Contributor

brodycj commented Jan 29, 2018

http://stackoverflow.com/questions/32973678/cordova-sqlite-query-rows-length-0-but-items-throws-exception

The code in this question will not work since it is missing the location setting.

The accepted solution is NOT recommended since it will miss over 2 years of updates, including a couple data loss risk issues #666 and #716 that were discovered and fixed over the past year.

I would like to ask anyone facing this kind of an issue to discuss in https://github.com/litehelpers/Cordova-sqlite-help/issues, with self-contained reproduction code. I would also like to recommend giving https://github.com/brodybits/cordova-sqlite-storage-starter-app a try.

@benshope
Copy link
Author

benshope commented Jan 29, 2018

@doc-brown @osro sorry for the late response to some questions, what I think might have fixed my problem is that things have to be fetched from the sql response object using things.get('items') instead of normal javascript syntax things.items or things["items"]

EDIT: after reading the comment below, I realized that it was not a .get(), that confused me - it was rows.item(index) instead of rows[index] syntax

@brodycj
Copy link
Contributor

brodycj commented Jan 29, 2018

@benshope thanks for commenting. Your response indicates that you are using some kind of a library to access the data in the sql response object, which would probably not work the same for most other users.

In general the row object is accessed in the following forms:

resultSet.rows.item(rowIndex).columnName // individual column from a row
resultSet.rows.item(rowIndex) // full row object

So far I have seen the following possible causes of this kind of issue:

@benshope
Copy link
Author

@brodybits Yes, you're totally right, it wasn't .get(), that confused me was the rows.item(index) syntax that was my issue. Thanks for the correction!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants