UNCONFIRMED 45926
JSDatabase ResultSet.rows.item(pos) throws exception, but it should return null
https://bugs.webkit.org/show_bug.cgi?id=45926
Summary JSDatabase ResultSet.rows.item(pos) throws exception, but it should return null
Matt Bishop
Reported 2010-09-16 15:38:53 PDT
A SQL query ResultSet rows object gives one access to the result rows of a query. The way to access a particular row is by using this call: var aRow = resultSet.rows.item(rowPos); If the rowPos indicates a row that is not in the row list, the method should return null. For instance, if there are 5 rows but I ask for rows.item(10) I should get null. Instead, I get an error: "INDEX_SIZE_ERR: DOM Exception 1: Index or size was negative, or greater than the allowed value." This is according to the Web SQL Database spec (http://dev.w3.org/html5/webdatabase/#sqlresultsetrowlist). WHY THIS IS IMPORTANT The only way to safely iterate a resultset is like this: var len = resultSet.rows.length; for (int i = 0; i < len; i++) { var aRow = resultSet.rows.item(i); //process the row } Not bad, but rows.length should be avoided, as an implementation may need to scan the entire resultSet; if the resultSet is large, it can cause memory troubles, slowdowns, etc. If the implementation of rows.item() is lazy, then length() need never be called. The safer way to iterate is to do this: var i = -1; while ((aRow = resultSet.rows.item(++i)) != null) { //process the row }
Attachments
HTML file showing bug. (1.58 KB, text/html)
2010-09-16 15:39 PDT, Matt Bishop
no flags
Matt Bishop
Comment 1 2010-09-16 15:39:34 PDT
Created attachment 67849 [details] HTML file showing bug.
Note You need to log in before you can comment on or make changes to this bug.