Bug 36089 - Web SQL: SQLResultSetRowList does not support indexing of rows
Summary: Web SQL: SQLResultSetRowList does not support indexing of rows
Status: UNCONFIRMED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Windows Vista
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-13 11:29 PST by Torbjörn Lönnemark
Modified: 2013-11-30 15:26 PST (History)
3 users (show)

See Also:


Attachments
Test page that doesn't work, but should work. (916 bytes, text/html)
2010-03-13 11:29 PST, Torbjörn Lönnemark
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Torbjörn Lönnemark 2010-03-13 11:29:39 PST
Created attachment 50659 [details]
Test page that doesn't work, but should work.

http://dev.w3.org/html5/webdatabase/ states (as far as I can tell) that SQLResultSetRowList should support indexing of its contained rows, i.e. resultSet.rows[index]  should work, but it currently does not in Webkit - you must currently use resultSet.rows.item(index) instead.

Tested on version 4.0.4 (531.21.10), nightly build revision 55961.

Attached test page displays '0' when indexing works, and is blank otherwise.
Comment 1 Matt Bishop 2010-09-16 14:57:43 PDT
I disagree.  I don't see anywhere in the html5 webdatabase spec that states the rows object is actually an array.  It is very clear about how to get a specific row:

"The item(index) attribute must return the row with the given index index."

The confusing thing about this spec (see http://dev.w3.org/html5/webdatabase/#sqlresultsetrowlist) is that it has methods that make it _look_ like an array but it is not actually a data structure.

This bug should be closed.
Comment 2 Chris K 2010-09-19 19:51:02 PDT
Yes, the spec *does* require this:

"The object's indices of the supported indexed properties are the numbers in the range zero to length-1, unless the length is zero, in which case there are no supported indexed properties."

This is near the bottom of section 4.5.
Comment 3 Matt Bishop 2010-09-19 22:30:39 PDT
Here is the code from the attached test case:

  db.readTransaction(function (t) {
    t.executeSql('SELECT COUNT(*) AS c FROM docids', [], function (t, r) {
      span.textContent = r.rows[0].c;
    }, function (t, e) {
      // couldn't read database
      span.textContent = '(unknown: ' + e.message + ')';
    });
  });


The correct syntax is:

      span.textContent = r.rows.item(0).c;

SQLResultSetRowList has two methods : item() and length.  For a given item(), that "...object's indices of the supported indexed properties are the numbers..."  This sentence does not mean that rows is an array, but rather a list of rows with an item() accessor method.  The specific row object that is returned by item() does indeed behave like an array

If you really feel this is still a bug, please provide another browser that works the way that is described in this bug report.
Comment 4 Chris K 2010-09-20 05:49:49 PDT
The row object is *not* an array -- it is an object whose keys are the database column names:

"Each row must be represented by a native ordered dictionary data type. In the JavaScript binding, this must be Object. Each row object must have one property (or dictionary entry) per column, with those properties enumerating in the order that these columns were returned by the database. Each property must have the name of the column and the value of the cell, as they were returned by the database."

Opera behaves correctly; run the test case in it and it gives a "0" (correct output).
Comment 5 Luke Stebbing 2013-11-30 15:26:04 PST
SQLResultSetRowList.item is defined as an indexed property getter:

http://www.w3.org/TR/webdatabase/#sqlresultsetrowlist
interface SQLResultSetRowList {
  readonly attribute unsigned long length;
  getter any item(in unsigned long index);
};

According to Web IDL, this means that rows[0] is equivalent to rows.item(0):
http://www.w3.org/TR/WebIDL/#idl-indexed-properties

Maybe when this was originally implemented, item wasn't an indexed property getter.