File tree Expand file tree Collapse file tree 6 files changed +621
-503
lines changed
Expand file tree Collapse file tree 6 files changed +621
-503
lines changed Original file line number Diff line number Diff line change @@ -15,13 +15,14 @@ yy.Select.prototype.compileJoins = function (query) {
1515
1616 this . joins . forEach ( jn => {
1717 let tq , ps , source ;
18- // Test CROSS-JOIN
18+ // Handle CROSS JOIN (SQLite-compatible behavior)
19+ // SQLite allows CROSS JOIN with ON/USING clauses, treating them as INNER JOIN
1920 if ( jn . joinmode === 'CROSS' ) {
20- if ( jn . using || jn . on ) {
21- throw new Error ( 'CROSS JOIN cannot have USING or ON clauses' ) ;
22- } else {
23- jn . joinmode = ' INNER' ;
24- }
21+ // Convert all CROSS JOINs to INNER JOIN for consistent processing
22+ // Result behavior:
23+ // - Without ON/USING: Produces cartesian product (standard CROSS JOIN)
24+ // - With ON/USING: Filters results like INNER JOIN (SQLite extension)
25+ jn . joinmode = 'INNER' ;
2526 }
2627
2728 if ( jn instanceof yy . Apply ) {
Original file line number Diff line number Diff line change @@ -853,6 +853,32 @@ FromClause
853853 { $$ = { from: [$2], joins: $3 }; }
854854*/ | FROM FromTablesList JoinTablesList
855855 { $$ = { from: $2 , joins: $3 }; }
856+ | FROM FromTablesList JoinTablesList COMMA FromTablesList
857+ {
858+ // Convert comma-separated tables after joins into CROSS JOINs
859+ var joins = $3 ;
860+ $5 .forEach (t => {
861+ var join = new yy.Join ({joinmode: " CROSS" });
862+ if (t .tableid ) {
863+ join .table = new yy.Table ({databaseid: t .databaseid , tableid: t .tableid });
864+ } else if (t instanceof yy .Select ) {
865+ join .select = t;
866+ } else if (t instanceof yy .Search ) {
867+ join .search = t;
868+ } else if (t instanceof yy .ParamValue ) {
869+ join .param = t;
870+ } else if (t instanceof yy .VarValue ) {
871+ join .variable = t .variable ;
872+ } else if (t instanceof yy .FuncValue ) {
873+ join .func = t;
874+ } else if (t instanceof yy .Json ) {
875+ join .json = t;
876+ }
877+ if (t .as ) join .as = t .as ;
878+ joins .push (join);
879+ });
880+ $$ = { from: $2 , joins: joins };
881+ }
856882/* | FROM LPAR FromTable JoinTablesList RPAR
857883 { $$ = { from: [$3], joins: $4 }; }
858884*/ | FROM LPAR FromTablesList JoinTablesList RPAR
You can’t perform that action at this time.
0 commit comments