/ Check-in [479976955e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Minor changes to function tokenExpr() in order to claw back cycles lost to the rename-column change.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | alter-table-rename-column
Files: files | file ages | folders
SHA3-256: 479976955ecb27c3e77a280187eaf23722178549e072b34f3183354a27a4e5c3
User & Date: dan 2018-08-21 08:29:48
Context
2018-08-21
15:06
Rationalize some duplicated code in alter.c. Also improve error messages for ALTER TABLE RENAME COLUMN in some cases. check-in: 5d2163c734 user: dan tags: alter-table-rename-column
08:29
Minor changes to function tokenExpr() in order to claw back cycles lost to the rename-column change. check-in: 479976955e user: dan tags: alter-table-rename-column
2018-08-20
20:01
Add further tests for RENAME COLUMN. check-in: 82c4c10a96 user: dan tags: alter-table-rename-column
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

   935    935     const char *zOld;               /* Old column name */
   936    936   };
   937    937   
   938    938   /*
   939    939   ** Add a new RenameToken object mapping parse tree element pPtr into
   940    940   ** token *pToken to the Parse object currently under construction.
   941    941   */
   942         -void sqlite3RenameToken(Parse *pParse, void *pPtr, Token *pToken){
          942  +void *sqlite3RenameToken(Parse *pParse, void *pPtr, Token *pToken){
   943    943     RenameToken *pNew;
   944    944     pNew = sqlite3DbMallocZero(pParse->db, sizeof(RenameToken));
   945    945     if( pNew ){
   946    946       pNew->p = pPtr;
   947    947       pNew->t = *pToken;
   948    948       pNew->pNext = pParse->pRename;
   949    949       pParse->pRename = pNew;
   950    950     }
          951  +  return pPtr;
   951    952   }
   952    953   
   953    954   /*
   954    955   ** If there is a RenameToken object associated with parse tree element
   955    956   ** pFrom, then remap that object over to pTo due to a transformation
   956    957   ** in the parse tree.
   957    958   */

Changes to src/parse.y.

   925    925     /* Construct a new Expr object from a single identifier.  Use the
   926    926     ** new Expr to populate pOut.  Set the span of pOut to be the identifier
   927    927     ** that created the expression.
   928    928     */
   929    929     static Expr *tokenExpr(Parse *pParse, int op, Token t){
   930    930       Expr *p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr)+t.n+1);
   931    931       if( p ){
   932         -      memset(p, 0, sizeof(Expr));
          932  +      /* memset(p, 0, sizeof(Expr)); */
   933    933         p->op = (u8)op;
          934  +      p->affinity = 0;
   934    935         p->flags = EP_Leaf;
   935    936         p->iAgg = -1;
          937  +      p->pLeft = p->pRight = 0;
          938  +      p->x.pList = 0;
          939  +      p->pAggInfo = 0;
          940  +      p->pTab = 0;
          941  +      p->op2 = 0;
          942  +#ifndef SQLITE_OMIT_WINDOWFUNC
          943  +      p->pWin = 0;
          944  +#endif
   936    945         p->u.zToken = (char*)&p[1];
   937    946         memcpy(p->u.zToken, t.z, t.n);
   938    947         p->u.zToken[t.n] = 0;
   939    948         if( sqlite3Isquote(p->u.zToken[0]) ){
   940    949           if( p->u.zToken[0]=='"' ) p->flags |= EP_DblQuoted;
   941    950           sqlite3Dequote(p->u.zToken);
   942    951         }
   943         -      if( IN_RENAME_COLUMN ) sqlite3RenameToken(pParse, (void*)p, &t);
   944    952   #if SQLITE_MAX_EXPR_DEPTH>0
   945    953         p->nHeight = 1;
   946    954   #endif  
          955  +      if( IN_RENAME_COLUMN ){
          956  +        return (Expr*)sqlite3RenameToken(pParse, (void*)p, &t);
          957  +      }
   947    958       }
   948    959       return p;
   949    960     }
          961  +
   950    962   }
   951    963   
   952    964   expr(A) ::= term(A).
   953    965   expr(A) ::= LP expr(X) RP. {A = X;}
   954    966   expr(A) ::= id(X).          {A=tokenExpr(pParse,TK_ID,X); /*A-overwrites-X*/}
   955    967   expr(A) ::= JOIN_KW(X).     {A=tokenExpr(pParse,TK_ID,X); /*A-overwrites-X*/}
   956    968   expr(A) ::= nm(X) DOT nm(Y). {

Changes to src/sqliteInt.h.

  4232   4232   int sqlite3ResolveExprListNames(NameContext*, ExprList*);
  4233   4233   void sqlite3ResolveSelectNames(Parse*, Select*, NameContext*);
  4234   4234   void sqlite3ResolveSelfReference(Parse*,Table*,int,Expr*,ExprList*);
  4235   4235   int sqlite3ResolveOrderGroupBy(Parse*, Select*, ExprList*, const char*);
  4236   4236   void sqlite3ColumnDefault(Vdbe *, Table *, int, int);
  4237   4237   void sqlite3AlterFinishAddColumn(Parse *, Token *);
  4238   4238   void sqlite3AlterBeginAddColumn(Parse *, SrcList *);
  4239         -void sqlite3RenameToken(Parse*, void*, Token*);
         4239  +void *sqlite3RenameToken(Parse*, void*, Token*);
  4240   4240   void sqlite3MoveRenameToken(Parse*, void *pTo, void *pFrom);
  4241   4241   CollSeq *sqlite3GetCollSeq(Parse*, u8, CollSeq *, const char*);
  4242   4242   char sqlite3AffinityType(const char*, Column*);
  4243   4243   void sqlite3Analyze(Parse*, Token*, Token*);
  4244   4244   int sqlite3InvokeBusyHandler(BusyHandler*, sqlite3_file*);
  4245   4245   int sqlite3FindDb(sqlite3*, Token*);
  4246   4246   int sqlite3FindDbName(sqlite3 *, const char *);