knadh / localStorageDB

A simple database layer for localStorage and sessionStorage for creating structured data in the form of databases and tables
http://nadh.in/code/localstoragedb
814 stars 128 forks source link

Distinct query bug #61

Closed girishawate closed 8 years ago

girishawate commented 8 years ago

lib.queryAll("books", { distinct: ["year", "author"]});

I have used DomSQL.queryAll("prodlist", { distinct: ["pName", "pLocalName", "pImage2"]}); where pName and pLocalName are having spaces and pImage2 may or may not be distinct alone eg. record 1: Orange small, Orange small, org.jpg record 2: Orange large, Orange large, org.jpg record 3: Sweet Lime, Sweet Lime, org.jpg

return data fails to provide all three records Note: data is to explain the case and has no literal meaning

Thanks for good work

knadh commented 8 years ago

@girishawate Apologies for the delay, but looking into this.

girishawate commented 8 years ago

Did you manage to arrest the issue..

girishawate commented 8 years ago

Let me know if you need any more clarity on the same .. regards

knadh commented 8 years ago

Yeah, it's a bug (triggered by the spaces in the strings). Will issue a fix.

girishawate commented 8 years ago

Hi ! Did you manage to get the fix .. Can you help with a workaround if any ..

knadh commented 8 years ago

@girishawate sorry for the confusion. I misjudged it as a bug earlier, but in fact, it's not. I was unable to reproduce the problem. I ran this sample and got 1 row back as expected.

lib.createTable("prodlist", ["pName", "pLocalName", "pImage2"]);
lib.insert("prodlist", {pName: "Orange small", pLocalName: "Orange small", pImage2: "org.jpg"});
lib.insert("prodlist", {pName: "Orange large", pLocalName: "Orange large", pImage2: "org.jpg"});
lib.insert("prodlist", {pName: "Sweet Lime", pLocalName: "Sweet Lime", pImage2: "org.jpg"});

lib.commit();

console.log(lib.queryAll("prodlist", { distinct: ["pName", "pLocalName", "pImage2"]}));
girishawate commented 8 years ago

multiple fields usage in distinct parameter is expected to play the role in the feature and uniqueness criteria

as three fields are used it is expected to return all the three rows as unique

console.log(lib.queryAll("prodlist", { distinct: ["pName", "pLocalName", "pImage2"]})); expected to return all three

console.log(lib.queryAll("prodlist", { distinct: ["pImage2"]})); may return 1 row

knadh commented 8 years ago

@girishawate Similar to SQL DISTINCT, the uniqueness is applied to columns across different rows, not columns across one row.