Skip to content

Commit

Permalink
Test showing duplicate names in rowIterator are being overwritten
Browse files Browse the repository at this point in the history
  • Loading branch information
geelen committed Jul 24, 2023
1 parent 7f927c6 commit e9e1d6e
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/workerd/api/sql-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,37 @@ async function test(storage) {
assert.equal(getI(), 2);
}

// Test joining two tables with overlapping names
{
sql.exec(`CREATE TABLE abc (a INT, b INT, c INT);`)
sql.exec(`CREATE TABLE cde (c INT, d INT, e INT);`)
sql.exec(`INSERT INTO abc VALUES (1,2,3),(4,5,6);`)
sql.exec(`INSERT INTO cde VALUES (7,8,9),(1,2,3);`)
const fullJoin = sql.prepare(`SELECT * FROM abc, cde`)

// Raw results include both 'c' columns
const rawResults = Array.from(fullJoin().raw())
assert.equal(rawResults.length, 4)
assert.equal(rawResults[0].length, 6)
assert.equal(rawResults[1].length, 6)
assert.equal(rawResults[2].length, 6)
assert.equal(rawResults[3].length, 6)

// Obj results _should_ preserve full data, but the two 'c' columns are overwriting one another
const objResults = Array.from(fullJoin())
assert.equal(objResults.length, 4)
// TODO: restore
//assert.equal(Object.values(objResults[0]).length, 6)
//assert.equal(Object.values(objResults[1]).length, 6)
//assert.equal(Object.values(objResults[2]).length, 6)
//assert.equal(Object.values(objResults[3]).length, 6)

// Perhaps we should handle collision as so?
assert.equal(objResults[0].c, 3) // First use of 'c' in result set
assert.equal(objResults[0].c_1, 7) // Second use of 'c' gets suffix with collision count?

}

await scheduler.wait(1);

// Test for bug where a cursor constructed from a prepared statement didn't have a strong ref
Expand Down

0 comments on commit e9e1d6e

Please sign in to comment.