Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement JavaScript property access in SQL queries#2372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge4 commits intodevelop
base:develop
Choose a base branch
Loading
fromcopilot/fix-javascript-property-access
Draft
Show file tree
Hide file tree
Changes from3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletionssrc/424select.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -198,6 +198,16 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
var tbid = col.tableid;
//console.log(query.sources);
var dbid = col.databaseid || query.sources[0].databaseid || query.database.databaseid;

// Check if tableid is actually a column name (property access pattern like name.length)
// This handles cases where the parser sees "columnname.property" and interprets it as "table.column"
var isPropertyAccess = false;
if (tbid && query.defcols && query.defcols[tbid] && query.defcols[tbid] !== '-') {
// tbid is actually a column name, so this is property access
isPropertyAccess = true;
var actualTableid = query.defcols[tbid];
}

if (!tbid) tbid = query.defcols[col.columnid];
if (!tbid) tbid = query.defaultTableid;
if (col.columnid !== '_') {
Expand DownExpand Up@@ -260,6 +270,20 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
.join(' ?? ');

ss.push("'" + escapeq(col.as || col.columnid) + "':(" + searchExpr + ')');
} else if (isPropertyAccess) {
// Property access pattern: columnname.property (e.g., name.length)
// Generate code to access the property on the column value
ss.push(
"'" +
escapeq(col.as || col.columnid) +
"':((p['" +
actualTableid +
"']['" +
col.tableid +
"'] || {})['" +
col.columnid +
"'])"
);
} else {
ss.push(
"'" +
Expand Down
11 changes: 11 additions & 0 deletionssrc/50expression.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -782,6 +782,17 @@
}

if (this.tableid) {
// Check if tableid is actually a column name (property access pattern like name.length)
// This handles cases where the parser sees "columnname.property" and interprets it as "table.column"
if (defcols && defcols[this.tableid] && defcols[this.tableid] !== '-') {
// tableid is actually a column name, so this is property access
// Generate code to access the property on the column value
const actualTable = defcols[this.tableid];
if (this.columnid !== '_') {
return `((${context}['${actualTable}']['${this.tableid}'] || {})['${this.columnid}'])`;
}
}
// Otherwise, tableid is a table name (normal table.column access)
return this.columnid !== '_'
? `${context}['${this.tableid}']['${this.columnid}']`
: context === 'g'
Expand Down
7 changes: 4 additions & 3 deletionstest/test341.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -35,13 +35,14 @@ describe('Test 341 Intellectual DOT operator', function () {
done();
});

it.skip('4. JavaScript way', function (done) {
it('4. JavaScript way', function (done) {
var res = alasql('SET @a = "who".length');
assert.deepEqual(res, [6, 6, 7]);
assert.deepEqual(res, 1);
assert.deepEqual(alasql.vars.a, 3);
done();
});

it.skip('5. JavaScript way', function (done) {
it('5. JavaScript way', function (done) {
var res = alasql('SELECT COLUMN name.length FROM persons');
assert.deepEqual(res, [6, 6, 7]);
done();
Comment on lines -44 to 47
Copy link
Member

Choose a reason for hiding this comment

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

Can we adda a test if I can name a table.col.length ?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Added test fortable.column.length syntax! ✅

The three-level dot notation already works correctly with the current implementation. Added test "6. JavaScript way with table.column.length" that verifies:

  • SELECT COLUMN persons.name.length FROM persons → [6, 6, 7]
  • Also works with aliases:SELECT COLUMN p.name.length FROM persons AS p

All 2086 tests passing. Commit:ddb0088

Copy link
Member

Choose a reason for hiding this comment

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

Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp