Bug 692659: Fix sort order for PREV cursors on indexes. r=bent

This commit is contained in:
Jonas Sicking 2011-11-07 23:34:59 -08:00
parent 9bf710eea2
commit ef00405547
2 changed files with 76 additions and 9 deletions

View File

@ -1092,20 +1092,23 @@ OpenKeyCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
switch (mDirection) {
case nsIIDBCursor::NEXT:
case nsIIDBCursor::NEXT_NO_DUPLICATE:
directionClause.AppendLiteral(" ASC");
directionClause += NS_LITERAL_CSTRING(" ASC, ") + keyColumn +
NS_LITERAL_CSTRING(" ASC");
break;
case nsIIDBCursor::PREV:
directionClause += NS_LITERAL_CSTRING(" DESC, ") + keyColumn +
NS_LITERAL_CSTRING(" DESC");
break;
case nsIIDBCursor::PREV_NO_DUPLICATE:
directionClause.AppendLiteral(" DESC");
directionClause += NS_LITERAL_CSTRING(" DESC, ") + keyColumn +
NS_LITERAL_CSTRING(" ASC");
break;
default:
NS_NOTREACHED("Unknown direction!");
}
directionClause += NS_LITERAL_CSTRING(", ") + keyColumn +
NS_LITERAL_CSTRING(" ASC");
nsCString firstQuery = NS_LITERAL_CSTRING("SELECT value, ") + keyColumn +
NS_LITERAL_CSTRING(" FROM ") + table +
NS_LITERAL_CSTRING(" WHERE index_id = :") + id +
@ -1283,19 +1286,23 @@ OpenCursorHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
switch (mDirection) {
case nsIIDBCursor::NEXT:
case nsIIDBCursor::NEXT_NO_DUPLICATE:
directionClause.AppendLiteral(" ASC");
directionClause += NS_LITERAL_CSTRING(" ASC, ") + keyValue +
NS_LITERAL_CSTRING(" ASC");
break;
case nsIIDBCursor::PREV:
directionClause += NS_LITERAL_CSTRING(" DESC, ") + keyValue +
NS_LITERAL_CSTRING(" DESC");
break;
case nsIIDBCursor::PREV_NO_DUPLICATE:
directionClause.AppendLiteral(" DESC");
directionClause += NS_LITERAL_CSTRING(" DESC, ") + keyValue +
NS_LITERAL_CSTRING(" ASC");
break;
default:
NS_NOTREACHED("Unknown direction!");
}
directionClause += NS_LITERAL_CSTRING(", ") + keyValue +
NS_LITERAL_CSTRING(" ASC");
nsCString firstQuery = NS_LITERAL_CSTRING("SELECT ") + value +
NS_LITERAL_CSTRING(", ") + keyValue +

View File

@ -892,6 +892,31 @@
is(keyIndex, 4, "Saw all the expected keys");
ok(true, "Test group 21.5");
keyIndex = 5;
request = objectStore.index("height").openKeyCursor(null, PREV);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.target.result;
if (cursor) {
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
"Correct key");
is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
"Correct value");
cursor.continue();
keyIndex--;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, -1, "Saw all the expected keys");
ok(true, "Test group 22");
keyIndex = 5;
@ -994,6 +1019,41 @@
is(keyIndex, 4, "Saw all the expected keys");
ok(true, "Test group 24.5");
keyIndex = 5;
request = objectStore.index("height").openCursor(null, PREV);
request.onerror = errorHandler;
request.onsuccess = function (event) {
let cursor = event.target.result;
if (cursor) {
is(cursor.key, objectStoreDataHeightSort[keyIndex].value.height,
"Correct key");
is(cursor.primaryKey, objectStoreDataHeightSort[keyIndex].key,
"Correct primary key");
is(cursor.value.name, objectStoreDataHeightSort[keyIndex].value.name,
"Correct name");
is(cursor.value.height,
objectStoreDataHeightSort[keyIndex].value.height,
"Correct height");
if ("weight" in cursor.value) {
is(cursor.value.weight,
objectStoreDataHeightSort[keyIndex].value.weight,
"Correct weight");
}
cursor.continue();
keyIndex--;
}
else {
testGenerator.next();
}
}
yield;
is(keyIndex, -1, "Saw all the expected keys");
ok(true, "Test group 25");
keyIndex = 5;