Skip to content

Case insensitive table/column names - #909

Merged
mathiasrw merged 2 commits into
AlaSQL:developfrom
amitauras:develop
Jul 20, 2017
Merged

mathiasrw merged 2 commits into
AlaSQL:developfrom
amitauras:develop

Conversation

@amitauras

Copy link
Copy Markdown
Contributor
  1. yy.casesensitive option doesn't update after changing value of alasql.options.casesensitive. Therefore, used alasql.options.casesensitive in alasqlparser.js

  2. Now, as alasqlparser file when case-sensitive options set to false sets all the column names to lowercase therefore in 84form.js file we are changing all column names to lowercase. This way now whatever case whether upper, lower or mixed case column names are specified in excel then also alasql can read data for all those columns when alasql.options.casesensitive is set to false.

I have commited only my changes to the repository. I have not commited changes after build which includes changes in dist folder etc.

Thank you for the time you are putting into AlaSQL!

…sql.options.casesensitive. Therefore, used alasql.options.casesensitive in alasqlparser.js

2) Now, as alasqlparser file when casesensitive options set to false sets all the column names to lowercase therefore in 84form.js file we are changing all column names to lowercase. This way now whatever case whether upper, lower or mixed case column names are specified in excel then also alasql can read data for all those columns when alasql.options.casesensitive is set to false.
@mathiasrw

Copy link
Copy Markdown
Member

This looks great - thank you!

Please submit the builded files too so the automated tests can let us merge the code :)

Comment thread src/84from.js Outdated
if(opt.headers) {
if(workbook.Sheets[sheetid][col+""+row0]) {
hh[col] = workbook.Sheets[sheetid][col+""+row0].v;
hh[col] = alasql.options.casesensitive ? workbook.Sheets[sheetid][col+""+row0].v : (workbook.Sheets[sheetid][col+""+row0].v ? workbook.Sheets[sheetid][col+""+row0].v.toLowerCase() : workbook.Sheets[sheetid][col+""+row0].v);

@mathiasrw mathiasrw Jul 20, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works - but its not so easy for future contributors to grasp.

Please restructure without using the if?then:else; structure.

Comment thread src/84from.js Outdated
hh[col] = alasql.options.casesensitive ? workbook.Sheets[sheetid][col+""+row0].v : (workbook.Sheets[sheetid][col+""+row0].v ? workbook.Sheets[sheetid][col+""+row0].v.toLowerCase() : workbook.Sheets[sheetid][col+""+row0].v);
} else {
hh[col] = col;
hh[col] = alasql.options.casesensitive ? col : (col ? col.toLowerCase() : col);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please restructure without using the if?then:else; structure.

Comment thread test/test614.js Outdated

var test = '614'; // insert test file number

describe('Test ' + test + ' - Read data from column irrespective of case in query', function () {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for remembering to make a test for your PR :)

Comment thread test/test614.js Outdated
alasql.options.casesensitive = true;
});

it('1) Read Data and Check Value', function (done) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please describe the test in a way that tells what it is doing. Example could be "Mixed case excel with camel case select"

Comment thread test/test614.js
assert.equal(res[0]['Account'.toLowerCase()], 12);
done();
});
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest having a few more tests both from a positive and a negative side.

A negative test would be that setting the flag to false, the same test would give an error / not find data

there could also be two columns with different case'ing setup (one only upper, one only lower) where it could be tested what happens on casesensetive = off or on

@amitauras

amitauras commented Jul 20, 2017 via email

Copy link
Copy Markdown
Contributor Author

2) added test cases for Mixed Case, Upper Case and Lower Case. Both positive and negative tests are used
3) added files generated at build time in the commit
@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #909 into develop will increase coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #909      +/-   ##
===========================================
+ Coverage     67.9%   67.92%   +0.02%     
===========================================
  Files            1        1              
  Lines         9908     9912       +4     
  Branches      2963     2964       +1     
===========================================
+ Hits          6728     6733       +5     
+ Misses        3180     3179       -1
Impacted Files Coverage Δ
dist/alasql.fs.js 67.92% <ø> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d16eaf4...0f30ed6. Read the comment docs.

@amitauras

Copy link
Copy Markdown
Contributor Author
  1. removed if?then:else, restructured the code and added comments
  2. added test cases for Mixed Case, Upper Case and Lower Case. Both positive and negative tests are used
  3. added files generated at build time in the commit

@mathiasrw
mathiasrw merged commit af32605 into AlaSQL:develop Jul 20, 2017
@mathiasrw

Copy link
Copy Markdown
Member

Looks really really good. Thank you for taking the time to contribute...

@amitauras

Copy link
Copy Markdown
Contributor Author

It's my pleasure to have any contribution to such a great library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants