Пример #1
0
        /*
        ** The expression is the default value for the most recently added column
        ** of the table currently under construction.
        **
        ** Default value expressions must be constant.  Raise an exception if this
        ** is not the case.
        **
        ** This routine is called by the parser while in the middle of
        ** parsing a CREATE TABLE statement.
        */
        static void sqlite3AddDefaultValue(Parse pParse, ExprSpan pSpan)
        {
            Table   p;
            Column  pCol;
            sqlite3 db = pParse.db;

            p = pParse.pNewTable;
            if (p != null)
            {
                pCol = (p.aCol[p.nCol - 1]);
                if (sqlite3ExprIsConstantOrFunction(pSpan.pExpr) == 0)
                {
                    sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
                                    pCol.zName);
                }
                else
                {
                    /* A copy of pExpr is used instead of the original, as pExpr contains
                    ** tokens that point to volatile memory. The 'span' of the expression
                    ** is required by pragma table_info.
                    */
                    sqlite3ExprDelete(db, ref pCol.pDflt);
                    pCol.pDflt = sqlite3ExprDup(db, pSpan.pExpr, EXPRDUP_REDUCE);
                    sqlite3DbFree(db, ref pCol.zDflt);
                    pCol.zDflt = pSpan.zStart.Substring(0, pSpan.zStart.Length - pSpan.zEnd.Length);
                    //sqlite3DbStrNDup( db, pSpan.zStart,
                    //                               (int)( pSpan.zEnd.Length - pSpan.zStart.Length ) );
                }
            }
            sqlite3ExprDelete(db, ref pSpan.pExpr);
        }
Пример #2
0
 /*
 ** Set the ExprList.a[].zSpan element of the most recently added item
 ** on the expression list.
 **
 ** pList might be NULL following an OOM error.  But pSpan should never be
 ** NULL.  If a memory allocation fails, the pParse.db.mallocFailed flag
 ** is set.
 */
 static void sqlite3ExprListSetSpan(
 Parse pParse,          /* Parsing context */
 ExprList pList,        /* List to which to add the span. */
 ExprSpan pSpan         /* The span to be added */
 )
 {
   sqlite3 db = pParse.db;
   Debug.Assert( pList != null /*|| db.mallocFailed != 0 */ );
   if ( pList != null )
   {
     ExprList_item pItem = pList.a[pList.nExpr - 1];
     Debug.Assert( pList.nExpr > 0 );
     Debug.Assert( /* db.mallocFailed != 0 || */ pItem.pExpr == pSpan.pExpr );
     sqlite3DbFree( db, ref pItem.zSpan );
     pItem.zSpan = pSpan.zStart.Substring( 0, pSpan.zStart.Length <= pSpan.zEnd.Length ? pSpan.zStart.Length : pSpan.zStart.Length - pSpan.zEnd.Length );// sqlite3DbStrNDup( db, pSpan.zStart,
     //(int)( pSpan.zEnd- pSpan.zStart) );
   }
 }
Пример #3
0
 /*
 ** The expression is the default value for the most recently added column
 ** of the table currently under construction.
 **
 ** Default value expressions must be constant.  Raise an exception if this
 ** is not the case.
 **
 ** This routine is called by the parser while in the middle of
 ** parsing a CREATE TABLE statement.
 */
 static void sqlite3AddDefaultValue(Parse pParse, ExprSpan pSpan)
 {
     Table p;
     Column pCol;
     sqlite3 db = pParse.db;
     p = pParse.pNewTable;
     if (p != null)
     {
         pCol = (p.aCol[p.nCol - 1]);
         if (sqlite3ExprIsConstantOrFunction(pSpan.pExpr) == 0)
         {
             sqlite3ErrorMsg(pParse, "default value of column [%s] is not constant",
             pCol.zName);
         }
         else
         {
             /* A copy of pExpr is used instead of the original, as pExpr contains
             ** tokens that point to volatile memory. The 'span' of the expression
             ** is required by pragma table_info.
             */
             sqlite3ExprDelete(db, ref pCol.pDflt);
             pCol.pDflt = sqlite3ExprDup(db, pSpan.pExpr, EXPRDUP_REDUCE);
             sqlite3DbFree(db, ref pCol.zDflt);
             pCol.zDflt = pSpan.zStart.Substring(0, pSpan.zStart.Length - pSpan.zEnd.Length);
             //sqlite3DbStrNDup( db, pSpan.zStart,
             //                               (int)( pSpan.zEnd.Length - pSpan.zStart.Length ) );
         }
     }
     sqlite3ExprDelete(db, ref pSpan.pExpr);
 }