Hi,

 

According to their definition
(http://sqlite.org/syntaxdiagrams.html#single-source) , Join sources (named
single-source) are either : 

                * a table or view with an optional alias and/or with an
optional index

                * a sub query with an optional alias

                * a sub join (with no alias)

 

In SQLite parser.y source code we can find on line 496 the grammar rule
handling those three cases (in the same order)

 

<snippet line='496'>

...

seltablist(A) ::= stl_prefix(X) nm(Y) dbnm(D) as(Z) indexed_opt(I) on_opt(N)
using_opt(U). {

  A = sqlite3SrcListAppendFromTerm(pParse,X,&Y,&D,&Z,0,N,U);

  sqlite3SrcListIndexedBy(pParse, A, &I); }

 

seltablist(A) ::= stl_prefix(X) LP select(S) RP

                    as(Z) on_opt(N) using_opt(U). {

    A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,S,N,U);

  }

 

seltablist(A) ::= stl_prefix(X) LP seltablist(F) RP

                    as(Z) on_opt(N) using_opt(U). {

    if( X==0 && Z.n==0 && N==0 && U==0 ){

      A = F;

    }else{

      Select *pSubquery;

      sqlite3SrcListShiftJoinType(F);

      pSubquery = sqlite3SelectNew(pParse,0,F,0,0,0,0,0,0,0);

      A = sqlite3SrcListAppendFromTerm(pParse,X,0,0,&Z,pSubquery,N,U);

    }

  }

...

</snippet>

 

Case 1 and 2 are handled properly but as you can see the third definition
(wich should deal with sub joins) contains mistakes :

                #1 : It allows an as clause after the parenthesis

                #2 : on the right of a join operator (else { ... }) it
generates a subquery instead of merging F (which is a seltabList, not a sub
query) with X into A.

 

I wish I could propose a fix but I have no skills in C/yacc.

 

Hope this will help anyway.

 

Thanks

 

 

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to