当前位置: 首页>>代码示例>>C#>>正文


C# NameContext类代码示例

本文整理汇总了C#中NameContext的典型用法代码示例。如果您正苦于以下问题:C# NameContext类的具体用法?C# NameContext怎么用?C# NameContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NameContext类属于命名空间,在下文中一共展示了NameContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NameAnalyser

        public NameAnalyser(NameContext context, NameAnalysisOptions options)
        {
            if (context == null)
                throw new ArgumentNullException("context");
            if (options == null)
                throw new ArgumentNullException("options");

            this.context = context;
            this.options = options;
        }
开发者ID:etilic,项目名称:Etilic.Name,代码行数:10,代码来源:NameAnalyser.cs

示例2: ResolveAttachExpr

 static RC ResolveAttachExpr(NameContext name, Expr expr)
 {
     RC rc = RC.OK;
     if (expr != null)
     {
         if (expr.OP != TK.ID)
         {
             rc = sqlite3ResolveExprNames(name, ref expr);
             if (rc == RC.OK && !expr.IsConstant())
             {
                 name.Parse.ErrorMsg("invalid name: \"%s\"", expr.u.Token);
                 return RC.ERROR;
             }
         }
         else
             expr.OP = TK.STRING;
     }
     return rc;
 }
开发者ID:BclEx,项目名称:GpuStructs,代码行数:19,代码来源:Attach.cs

示例3: resolveAttachExpr

/*
** 2003 April 6
**
** The author disclaims copyright to this source code.  In place of
** a legal notice, here is a blessing:
**
**    May you do good and not evil.
**    May you find forgiveness for yourself and forgive others.
**    May you share freely, never taking more than you give.
**
*************************************************************************
** This file contains code used to implement the ATTACH and DETACH commands.
*************************************************************************
**  Included in SQLite3 port to C#-SQLite;  2008 Noah B Hart
**  C#-SQLite is an independent reimplementation of the SQLite software library
**
**  SQLITE_SOURCE_ID: 2011-06-23 19:49:22 4374b7e83ea0a3fbc3691f9c0c936272862f32f2
**
*************************************************************************
*/
//#include "sqliteInt.h"

#if !SQLITE_OMIT_ATTACH
/*
** Resolve an expression that was part of an ATTACH or DETACH statement. This
** is slightly different from resolving a normal SQL expression, because simple
** identifiers are treated as strings, not possible column names or aliases.
**
** i.e. if the parser sees:
**
**     ATTACH DATABASE abc AS def
**
** it treats the two expressions as literal strings 'abc' and 'def' instead of
** looking for columns of the same name.
**
** This only applies to the root node of pExpr, so the statement:
**
**     ATTACH DATABASE abc||def AS 'db2'
**
** will fail because neither abc or def can be resolved.
*/
static int resolveAttachExpr( NameContext pName, Expr pExpr )
{
  int rc = SQLITE_OK;
  if ( pExpr != null )
  {
    if ( pExpr.op != TK_ID )
    {
      rc = sqlite3ResolveExprNames( pName, ref pExpr );
      if ( rc == SQLITE_OK && sqlite3ExprIsConstant( pExpr ) == 0 )
      {
        sqlite3ErrorMsg( pName.pParse, "invalid name: \"%s\"", pExpr.u.zToken );
        return SQLITE_ERROR;
      }
    }
    else
    {
      pExpr.op = TK_STRING;
    }
  }
  return rc;
}
开发者ID:HansMaiser,项目名称:Vocaluxe,代码行数:62,代码来源:attach_c.cs

示例4: RenderName

 protected virtual void RenderName(HtmlTextWriter output, string id, NameContext context)
 {
     Assert.ArgumentNotNull(output, "output");
     Assert.ArgumentNotNullOrEmpty(id, "id");
     if (!context.Editable)
     {
         output.Write("<span class='header-title'>");
         output.Write(context.Name);
         output.Write("</span>");
     }
     else
     {
         output.Write("<a href='#' class='header-title'>");
         output.Write(StringUtil.EscapeQuote(context.Name));
         output.Write("</a>");
         string str = "onkeydown='javascript:return Sitecore.CollapsiblePanel.editNameChanging(this, event);'";
         string str2 = string.IsNullOrEmpty(context.OnNameChanging)
                       	? string.Empty
                       	: ("onkeyup=\"" + context.OnNameChanging + "\"");
         string str3 = string.IsNullOrEmpty(context.OnNameChanged)
                       	? string.Empty
                       	: ("onchange=\"" + context.OnNameChanged + "\"");
         output.Write(
             "<input type='text' {0} {1} id='{2}_name' name='{2}_name' data-meta-id='{2}' data-validation-msg=\"{3}\" style='display:none' class='header-title-edit' value=\"{4}\" {5} />",
             new object[]
                 {str2, str3, id, Translate.Text("The name cannot be blank."), StringUtil.EscapeQuote(context.Name), str});
     }
 }
开发者ID:Velir,项目名称:Sitecore-Analytics,代码行数:28,代码来源:SetTestDetailsForm.cs

示例5: sqlite3Update

		/*
		** Process an UPDATE statement.
		**
		**   UPDATE OR IGNORE table_wxyz SET a=b, c=d WHERE e<5 AND f NOT NULL;
		**          \_______/ \________/     \______/       \________________/
		*            onError   pTabList      pChanges             pWhere
		*/
		static void sqlite3Update(
		Parse pParse,         /* The parser context */
		SrcList pTabList,     /* The table in which we should change things */
		ExprList pChanges,    /* Things to be changed */
		Expr pWhere,          /* The WHERE clause.  May be null */
		int onError           /* How to handle constraint errors */
		)
		{
			int i, j;                   /* Loop counters */
			Table pTab;                 /* The table to be updated */
			int addr = 0;               /* VDBE instruction address of the start of the loop */
			WhereInfo pWInfo;           /* Information about the WHERE clause */
			Vdbe v;                     /* The virtual database engine */
			Index pIdx;                 /* For looping over indices */
			int nIdx;                   /* Number of indices that need updating */
			int iCur;                   /* VDBE Cursor number of pTab */
			sqlite3 db;                 /* The database structure */
			int[] aRegIdx = null;       /* One register assigned to each index to be updated */
			int[] aXRef = null;         /* aXRef[i] is the index in pChanges.a[] of the
** an expression for the i-th column of the table.
** aXRef[i]==-1 if the i-th column is not changed. */
			bool chngRowid;             /* True if the record number is being changed */
			Expr pRowidExpr = null;     /* Expression defining the new record number */
			bool openAll = false;       /* True if all indices need to be opened */
			AuthContext sContext;       /* The authorization context */
			NameContext sNC;            /* The name-context to resolve expressions in */
			int iDb;                    /* Database containing the table being updated */
			bool okOnePass;             /* True for one-pass algorithm without the FIFO */
			bool hasFK;                 /* True if foreign key processing is required */

#if !SQLITE_OMIT_TRIGGER
			bool isView;            /* True when updating a view (INSTEAD OF trigger) */
			Trigger pTrigger;      /* List of triggers on pTab, if required */
			int tmask = 0;         /* Mask of TRIGGER_BEFORE|TRIGGER_AFTER */
#endif
			int newmask;           /* Mask of NEW.* columns accessed by BEFORE triggers */

			/* Register Allocations */
			int regRowCount = 0;         /* A count of rows changed */
			int regOldRowid;             /* The old rowid */
			int regNewRowid;             /* The new rowid */
			int regNew;
			int regOld = 0;
			int regRowSet = 0;           /* Rowset of rows to be updated */

			sContext = new AuthContext(); //memset( &sContext, 0, sizeof( sContext ) );
			db = pParse.db;
			if (pParse.nErr != 0 /*|| db.mallocFailed != 0 */ )
			{
				goto update_cleanup;
			}
			Debug.Assert(pTabList.nSrc == 1);

			/* Locate the table which we want to update.
			*/
			pTab = sqlite3SrcListLookup(pParse, pTabList);
			if (pTab == null)
				goto update_cleanup;
			iDb = sqlite3SchemaToIndex(pParse.db, pTab.pSchema);

			/* Figure out if we have any triggers and if the table being
			** updated is a view.
			*/
#if !SQLITE_OMIT_TRIGGER
			pTrigger = sqlite3TriggersExist(pParse, pTab, TK_UPDATE, pChanges, out tmask);
			isView = pTab.pSelect != null;
			Debug.Assert(pTrigger != null || tmask == 0);
#else
	  const Trigger pTrigger = null;//# define pTrigger 0
	  const int tmask = 0;          //# define tmask 0
#endif
#if SQLITE_OMIT_TRIGGER || SQLITE_OMIT_VIEW
//    # undef isView
	  const bool isView = false;    //# define isView 0
#endif

			if (sqlite3ViewGetColumnNames(pParse, pTab) != 0)
			{
				goto update_cleanup;
			}
			if (sqlite3IsReadOnly(pParse, pTab, tmask))
			{
				goto update_cleanup;
			}
			aXRef = new int[pTab.nCol];// sqlite3DbMallocRaw(db, sizeof(int) * pTab.nCol);
			//if ( aXRef == null ) goto update_cleanup;
			for (i = 0; i < pTab.nCol; i++)
				aXRef[i] = -1;

			/* Allocate a cursors for the main database table and for all indices.
			** The index cursors might not be used, but if they are used they
			** need to occur right after the database cursor.  So go ahead and
			** allocate enough space, just in case.
//.........这里部分代码省略.........
开发者ID:jcwmoore,项目名称:athena,代码行数:101,代码来源:update_c.cs

示例6: sqlite3Select


//.........这里部分代码省略.........
      {
        /* This case is for non-aggregate queries
        ** Begin the database scan
        */
        pWInfo = sqlite3WhereBegin( pParse, pTabList, pWhere, ref pOrderBy, 0 );
        if ( pWInfo == null )
          goto select_end;
        if ( pWInfo.nRowOut < p.nSelectRow )
          p.nSelectRow = pWInfo.nRowOut;

        /* If sorting index that was created by a prior OP_OpenEphemeral
        ** instruction ended up not being needed, then change the OP_OpenEphemeral
        ** into an OP_Noop.
        */
        if ( addrSortIndex >= 0 && pOrderBy == null )
        {
          sqlite3VdbeChangeToNoop( v, addrSortIndex, 1 );
          p.addrOpenEphm[2] = -1;
        }

        /* Use the standard inner loop
        */
        Debug.Assert( !isDistinct );
        selectInnerLoop( pParse, p, pEList, 0, 0, pOrderBy, -1, pDest,
        pWInfo.iContinue, pWInfo.iBreak );

        /* End the database scan loop.
        */
        sqlite3WhereEnd( pWInfo );
      }
      else
      {
        /* This is the processing for aggregate queries */
        NameContext sNC;    /* Name context for processing aggregate information */
        int iAMem;          /* First Mem address for storing current GROUP BY */
        int iBMem;          /* First Mem address for previous GROUP BY */
        int iUseFlag;       /* Mem address holding flag indicating that at least
** one row of the input to the aggregator has been
** processed */
        int iAbortFlag;     /* Mem address which causes query abort if positive */
        int groupBySort;    /* Rows come from source in GR BY' clause thanROUP BY order */

        int addrEnd;        /* End of processing for this SELECT */

        /* Remove any and all aliases between the result set and the
        ** GROUP BY clause.
        */
        if ( pGroupBy != null )
        {
          int k;                        /* Loop counter */
          ExprList_item pItem;          /* For looping over expression in a list */

          for ( k = p.pEList.nExpr; k > 0; k-- )//, pItem++)
          {
            pItem = p.pEList.a[p.pEList.nExpr - k];
            pItem.iAlias = 0;
          }
          for ( k = pGroupBy.nExpr; k > 0; k-- )//, pItem++ )
          {
            pItem = pGroupBy.a[pGroupBy.nExpr - k];
            pItem.iAlias = 0;
          }
          if ( p.nSelectRow > (double)100 )
            p.nSelectRow = (double)100;
        }
        else
开发者ID:CryptoManiac,项目名称:csharpsqlite,代码行数:67,代码来源:select_c.cs

示例7: selectAddColumnTypeAndCollation

    /*
    ** Add type and collation information to a column list based on
    ** a SELECT statement.
    **
    ** The column list presumably came from selectColumnNamesFromExprList().
    ** The column list has only names, not types or collations.  This
    ** routine goes through and adds the types and collations.
    **
    ** This routine requires that all identifiers in the SELECT
    ** statement be resolved.
    */
    static void selectAddColumnTypeAndCollation(
    Parse pParse,         /* Parsing contexts */
    int nCol,             /* Number of columns */
    Column[] aCol,        /* List of columns */
    Select pSelect        /* SELECT used to determine types and collations */
    )
    {
      ////sqlite3 db = pParse.db;
      NameContext sNC;
      Column pCol;
      CollSeq pColl;
      int i;
      Expr p;
      ExprList_item[] a;

      Debug.Assert( pSelect != null );
      Debug.Assert( ( pSelect.selFlags & SF_Resolved ) != 0 );
      Debug.Assert( nCol == pSelect.pEList.nExpr /*|| db.mallocFailed != 0 */ );
      //      if ( db.mallocFailed != 0 ) return;
      sNC = new NameContext();// memset( &sNC, 0, sizeof( sNC ) );
      sNC.pSrcList = pSelect.pSrc;
      a = pSelect.pEList.a;
      for ( i = 0; i < nCol; i++ )//, pCol++ )
      {
        pCol = aCol[i];
        p = a[i].pExpr;
        string bDummy = null;
        pCol.zType = columnType( sNC, p, ref bDummy, ref bDummy, ref bDummy );// sqlite3DbStrDup( db, columnType( sNC, p, 0, 0, 0 ) );
        pCol.affinity = sqlite3ExprAffinity( p );
        if ( pCol.affinity == 0 )
          pCol.affinity = SQLITE_AFF_NONE;
        pColl = sqlite3ExprCollSeq( pParse, p );
        if ( pColl != null )
        {
          pCol.zColl = pColl.zName;// sqlite3DbStrDup( db, pColl.zName );
        }
      }
    }
开发者ID:CryptoManiac,项目名称:csharpsqlite,代码行数:49,代码来源:select_c.cs

示例8: columnType

    /*
    ** Return a pointer to a string containing the 'declaration type' of the
    ** expression pExpr. The string may be treated as static by the caller.
    **
    ** The declaration type is the exact datatype definition extracted from the
    ** original CREATE TABLE statement if the expression is a column. The
    ** declaration type for a ROWID field is INTEGER. Exactly when an expression
    ** is considered a column can be complex in the presence of subqueries. The
    ** result-set expression in all of the following SELECT statements is
    ** considered a column by this function.
    **
    **   SELECT col FROM tbl;
    **   SELECT (SELECT col FROM tbl;
    **   SELECT (SELECT col FROM tbl);
    **   SELECT abc FROM (SELECT col AS abc FROM tbl);
    **
    ** The declaration type for any expression other than a column is NULL.
    */
    static string columnType(
    NameContext pNC,
    Expr pExpr,
    ref string pzOriginDb,
    ref string pzOriginTab,
    ref string pzOriginCol
    )
    {
      string zType = null;
      string zOriginDb = null;
      string zOriginTab = null;
      string zOriginCol = null;
      int j;
      if ( NEVER( pExpr == null ) || pNC.pSrcList == null )
        return null;

      switch ( pExpr.op )
      {
        case TK_AGG_COLUMN:
        case TK_COLUMN:
          {
            /* The expression is a column. Locate the table the column is being
            ** extracted from in NameContext.pSrcList. This table may be real
            ** database table or a subquery.
            */
            Table pTab = null;            /* Table structure column is extracted from */
            Select pS = null;            /* Select the column is extracted from */
            int iCol = pExpr.iColumn;  /* Index of column in pTab */
            testcase( pExpr.op == TK_AGG_COLUMN );
            testcase( pExpr.op == TK_COLUMN );
            while ( pNC != null && pTab == null )
            {
              SrcList pTabList = pNC.pSrcList;
              for ( j = 0; j < pTabList.nSrc && pTabList.a[j].iCursor != pExpr.iTable; j++ )
                ;
              if ( j < pTabList.nSrc )
              {
                pTab = pTabList.a[j].pTab;
                pS = pTabList.a[j].pSelect;
              }
              else
              {
                pNC = pNC.pNext;
              }
            }

            if ( pTab == null )
            {
              /* At one time, code such as "SELECT new.x" within a trigger would
              ** cause this condition to run.  Since then, we have restructured how
              ** trigger code is generated and so this condition is no longer 
              ** possible. However, it can still be true for statements like
              ** the following:
              **
              **   CREATE TABLE t1(col INTEGER);
              **   SELECT (SELECT t1.col) FROM FROM t1;
              **
              ** when columnType() is called on the expression "t1.col" in the 
              ** sub-select. In this case, set the column type to NULL, even
              ** though it should really be "INTEGER".
              **
              ** This is not a problem, as the column type of "t1.col" is never
              ** used. When columnType() is called on the expression 
              ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT
              ** branch below.  */
              break;
            }

            //Debug.Assert( pTab != null && pExpr.pTab == pTab );
            if ( pS != null )
            {
              /* The "table" is actually a sub-select or a view in the FROM clause
              ** of the SELECT statement. Return the declaration type and origin
              ** data for the result-set column of the sub-select.
              */
              if ( iCol >= 0 && ALWAYS( iCol < pS.pEList.nExpr ) )
              {
                /* If iCol is less than zero, then the expression requests the
                ** rowid of the sub-select or view. This expression is legal (see
                ** test case misc2.2.2) - it always evaluates to NULL.
                */
                NameContext sNC = new NameContext();
//.........这里部分代码省略.........
开发者ID:CryptoManiac,项目名称:csharpsqlite,代码行数:101,代码来源:select_c.cs

示例9: ColumnType

        static string ColumnType(NameContext nc, Expr expr, ref string originDbNameOut, ref string originTableNameOut, ref string originColumnNameOut)
        {
            string typeName = null;
            string originDbName = null;
            string originTableName = null;
            string originColumnName = null;
            int j;
            if (C._NEVER(expr == null) || nc.SrcList == null) return null;

            switch (expr.OP)
            {
                case TK.AGG_COLUMN:
                case TK.COLUMN:
                    {
                        // The expression is a column. Locate the table the column is being extracted from in NameContext.pSrcList. This table may be real
                        // database table or a subquery.
                        Table table = null; // Table structure column is extracted from
                        Select s = null; // Select the column is extracted from
                        int colId = expr.ColumnIdx; // Index of column in pTab
                        C.ASSERTCOVERAGE(expr.OP == TK.AGG_COLUMN);
                        C.ASSERTCOVERAGE(expr.OP == TK.COLUMN);
                        while (nc != null && table == null)
                        {
                            SrcList tabList = nc.SrcList;
                            for (j = 0; j < tabList.Srcs && tabList.Ids[j].Cursor != expr.TableId; j++) ;
                            if (j < tabList.Srcs)
                            {
                                table = tabList.Ids[j].Table;
                                s = tabList.Ids[j].Select;
                            }
                            else
                                nc = nc.Next;
                        }

                        if (table == null)
                        {
                            // At one time, code such as "SELECT new.x" within a trigger would cause this condition to run.  Since then, we have restructured how
                            // trigger code is generated and so this condition is no longer possible. However, it can still be true for statements like
                            // the following:
                            //
                            //   CREATE TABLE t1(col INTEGER);
                            //   SELECT (SELECT t1.col) FROM FROM t1;
                            //
                            // when columnType() is called on the expression "t1.col" in the sub-select. In this case, set the column type to NULL, even
                            // though it should really be "INTEGER".
                            //
                            // This is not a problem, as the column type of "t1.col" is never used. When columnType() is called on the expression 
                            // "(SELECT t1.col)", the correct type is returned (see the TK_SELECT branch below.
                            break;
                        }

                        Debug.Assert(table != null && expr.Table == table);
                        if (s != null)
                        {
                            // The "table" is actually a sub-select or a view in the FROM clause of the SELECT statement. Return the declaration type and origin
                            // data for the result-set column of the sub-select.
                            if (colId >= 0 && C._ALWAYS(colId < s.EList.Exprs))
                            {
                                // If colId is less than zero, then the expression requests the rowid of the sub-select or view. This expression is legal (see 
                                // test case misc2.2.2) - it always evaluates to NULL.
                                NameContext sNC = new NameContext();
                                Expr p = s.EList.Ids[colId].Expr;
                                sNC.SrcList = s.Src;
                                sNC.Next = nc;
                                sNC.Parse = nc.Parse;
                                typeName = ColumnType(sNC, p, ref originDbName, ref originTableName, ref originColumnName);
                            }
                        }
                        else if (C._ALWAYS(table.Schema))
                        {
                            // A real table
                            Debug.Assert(s == null);
                            if (colId < 0) colId = table.PKey;
                            Debug.Assert(colId == -1 || (colId >= 0 && colId < table.Cols.length));
                            if (colId < 0)
                            {
                                typeName = "INTEGER";
                                originColumnName = "rowid";
                            }
                            else
                            {
                                typeName = table.Cols[colId].Type;
                                originColumnName = table.Cols[colId].Name;
                            }
                            originTableName = table.Name;
                            if (nc.Parse != null)
                            {
                                Context ctx = nc.Parse.Ctx;
                                int db = Prepare.SchemaToIndex(ctx, table.Schema);
                                originDbName = ctx.DBs[db].Name;
                            }
                        }
                        break;
                    }
#if !OMIT_SUBQUERY
                case TK.SELECT:
                    {
                        // The expression is a sub-select. Return the declaration type and origin info for the single column in the result set of the SELECT statement.
                        NameContext sNC = new NameContext();
                        Select s = expr.x.Select;
//.........这里部分代码省略.........
开发者ID:BclEx,项目名称:GpuStructs,代码行数:101,代码来源:Select.cs

示例10: sqlite3ExprAnalyzeAggList

 /*
 ** Call sqlite3ExprAnalyzeAggregates() for every expression in an
 ** expression list.  Return the number of errors.
 **
 ** If an error is found, the analysis is cut short.
 */
 static void sqlite3ExprAnalyzeAggList( NameContext pNC, ExprList pList )
 {
   ExprList_item pItem;
   int i;
   if ( pList != null )
   {
     for ( i = 0; i < pList.nExpr; i++ )//, pItem++)
     {
       pItem = pList.a[i];
       sqlite3ExprAnalyzeAggregates( pNC, ref pItem.pExpr );
     }
   }
 }
开发者ID:laboratoryyingong,项目名称:BARLESS,代码行数:19,代码来源:expr_c.cs

示例11: sqlite3ResolveSelectNames

        /// <summary>
        /// Resolve all names in all expressions of a SELECT and in all
        /// decendents of the SELECT, including compounds off of p.pPrior,
        /// subqueries in expressions, and subqueries used as FROM clause
        /// terms.
        /// 
        /// See sqlite3ResolveExprNames() for a description of the kinds of
        /// transformations that occur.
        /// 
        /// All SELECT statements should have been expanded using
        /// sqlite3SelectExpand() prior to invoking this routine.
        /// </summary>
        /// <param name='pParse'>
        /// The parser context
        /// </param>
        /// <param name='p'>
        /// The SELECT statement being coded.
        /// </param>
        /// <param name='pOuterNC'>
        /// Name context for parent SELECT statement
        /// </param>
        static void sqlite3ResolveSelectNames(Parse pParse, Select p, NameContext pOuterNC)
        {
            Walker w = new Walker();

            Debug.Assert(p != null);
            w.xExprCallback = resolveExprStep;
            w.xSelectCallback = resolveSelectStep;
            w.pParse = pParse;
            w.u.pNC = pOuterNC;
            sqlite3WalkSelect(w, p);
        }
开发者ID:RainsSoft,项目名称:CsharpSQLite,代码行数:32,代码来源:resolve_c.cs

示例12: fkScanChildren

    /*
    ** This function is called to generate code executed when a row is deleted
    ** from the parent table of foreign key constraint pFKey and, if pFKey is 
    ** deferred, when a row is inserted into the same table. When generating
    ** code for an SQL UPDATE operation, this function may be called twice -
    ** once to "delete" the old row and once to "insert" the new row.
    **
    ** The code generated by this function scans through the rows in the child
    ** table that correspond to the parent table row being deleted or inserted.
    ** For each child row found, one of the following actions is taken:
    **
    **   Operation | FK type   | Action taken
    **   --------------------------------------------------------------------------
    **   DELETE      immediate   Increment the "immediate constraint counter".
    **                           Or, if the ON (UPDATE|DELETE) action is RESTRICT,
    **                           throw a "foreign key constraint failed" exception.
    **
    **   INSERT      immediate   Decrement the "immediate constraint counter".
    **
    **   DELETE      deferred    Increment the "deferred constraint counter".
    **                           Or, if the ON (UPDATE|DELETE) action is RESTRICT,
    **                           throw a "foreign key constraint failed" exception.
    **
    **   INSERT      deferred    Decrement the "deferred constraint counter".
    **
    ** These operations are identified in the comment at the top of this file 
    ** (fkey.c) as "I.2" and "D.2".
    */
    static void fkScanChildren(
      Parse pParse,                   /* Parse context */
      SrcList pSrc,                   /* SrcList containing the table to scan */
      Table pTab,
      Index pIdx,                     /* Foreign key index */
      FKey pFKey,                     /* Foreign key relationship */
      int[] aiCol,                    /* Map from pIdx cols to child table cols */
      int regData,                    /* Referenced table data starts here */
      int nIncr                       /* Amount to increment deferred counter by */
    )
    {
      sqlite3 db = pParse.db;        /* Database handle */
      int i;                          /* Iterator variable */
      Expr pWhere = null;             /* WHERE clause to scan with */
      NameContext sNameContext;       /* Context used to resolve WHERE clause */
      WhereInfo pWInfo;               /* Context used by sqlite3WhereXXX() */
      int iFkIfZero = 0;              /* Address of OP_FkIfZero */
      Vdbe v = sqlite3GetVdbe( pParse );

      Debug.Assert( null == pIdx || pIdx.pTable == pTab );

      if ( nIncr < 0 )
      {
        iFkIfZero = sqlite3VdbeAddOp2( v, OP_FkIfZero, pFKey.isDeferred, 0 );
      }

      /* Create an Expr object representing an SQL expression like:
      **
      **   <parent-key1> = <child-key1> AND <parent-key2> = <child-key2> ...
      **
      ** The collation sequence used for the comparison should be that of
      ** the parent key columns. The affinity of the parent key column should
      ** be applied to each child key value before the comparison takes place.
      */
      for ( i = 0; i < pFKey.nCol; i++ )
      {
        Expr pLeft;                  /* Value from parent table row */
        Expr pRight;                 /* Column ref to child table */
        Expr pEq;                    /* Expression (pLeft = pRight) */
        int iCol;                     /* Index of column in child table */
        string zCol;             /* Name of column in child table */

        pLeft = sqlite3Expr( db, TK_REGISTER, null );
        if ( pLeft != null )
        {
          /* Set the collation sequence and affinity of the LHS of each TK_EQ
          ** expression to the parent key column defaults.  */
          if ( pIdx != null )
          {
            Column pCol;
            iCol = pIdx.aiColumn[i];
            pCol = pTab.aCol[iCol];
            if ( pTab.iPKey == iCol )
              iCol = -1;
            pLeft.iTable = regData + iCol + 1;
            pLeft.affinity = pCol.affinity;
            pLeft.pColl = sqlite3LocateCollSeq( pParse, pCol.zColl );
          }
          else
          {
            pLeft.iTable = regData;
            pLeft.affinity = SQLITE_AFF_INTEGER;
          }
        }
        iCol = aiCol != null ? aiCol[i] : pFKey.aCol[0].iFrom;
        Debug.Assert( iCol >= 0 );
        zCol = pFKey.pFrom.aCol[iCol].zName;
        pRight = sqlite3Expr( db, TK_ID, zCol );
        pEq = sqlite3PExpr( pParse, TK_EQ, pLeft, pRight, 0 );
        pWhere = sqlite3ExprAnd( db, pWhere, pEq );
      }

//.........这里部分代码省略.........
开发者ID:TerabyteX,项目名称:ironpython3,代码行数:101,代码来源:fkey_c.cs

示例13: codeAttach

/*
** This procedure generates VDBE code for a single invocation of either the
** sqlite_detach() or sqlite_attach() SQL user functions.
*/
static void codeAttach(
Parse pParse,       /* The parser context */
int type,           /* Either SQLITE_ATTACH or SQLITE_DETACH */
FuncDef pFunc,      /* FuncDef wrapper for detachFunc() or attachFunc() */
Expr pAuthArg,      /* Expression to pass to authorization callback */
Expr pFilename,     /* Name of database file */
Expr pDbname,       /* Name of the database to use internally */
Expr pKey           /* Database key for encryption extension */
)
{
  int rc;
  NameContext sName;
  Vdbe v;
  sqlite3 db = pParse.db;
  int regArgs;

  sName = new NameContext();// memset( &sName, 0, sizeof(NameContext));
  sName.pParse = pParse;

  if (
  SQLITE_OK != ( rc = resolveAttachExpr( sName, pFilename ) ) ||
  SQLITE_OK != ( rc = resolveAttachExpr( sName, pDbname ) ) ||
  SQLITE_OK != ( rc = resolveAttachExpr( sName, pKey ) )
  )
  {
    pParse.nErr++;
    goto attach_end;
  }

#if !SQLITE_OMIT_AUTHORIZATION
if( pAuthArg ){
char *zAuthArg;
if( pAuthArg->op==TK_STRING ){
  zAuthArg = pAuthArg->u.zToken;
}else{
  zAuthArg = 0;
}
rc = sqlite3AuthCheck(pParse, type, zAuthArg, 0, 0);
if(rc!=SQLITE_OK ){
goto attach_end;
}
}
#endif //* SQLITE_OMIT_AUTHORIZATION */

  v = sqlite3GetVdbe( pParse );
  regArgs = sqlite3GetTempRange( pParse, 4 );
  sqlite3ExprCode( pParse, pFilename, regArgs );
  sqlite3ExprCode( pParse, pDbname, regArgs + 1 );
  sqlite3ExprCode( pParse, pKey, regArgs + 2 );

  Debug.Assert( v != null /*|| db.mallocFailed != 0 */ );
  if ( v != null )
  {
    sqlite3VdbeAddOp3( v, OP_Function, 0, regArgs + 3 - pFunc.nArg, regArgs + 3 );
    Debug.Assert( pFunc.nArg == -1 || ( pFunc.nArg & 0xff ) == pFunc.nArg );
    sqlite3VdbeChangeP5( v, (u8)( pFunc.nArg ) );
    sqlite3VdbeChangeP4( v, -1, pFunc, P4_FUNCDEF );

    /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
    ** statement only). For DETACH, set it to false (expire all existing
    ** statements).
    */
    sqlite3VdbeAddOp1( v, OP_Expire, ( type == SQLITE_ATTACH ) ? 1 : 0 );
  }

attach_end:
  sqlite3ExprDelete( db, ref pFilename );
  sqlite3ExprDelete( db, ref pDbname );
  sqlite3ExprDelete( db, ref pKey );
}
开发者ID:HansMaiser,项目名称:Vocaluxe,代码行数:74,代码来源:attach_c.cs

示例14: columnType

    /*
    ** Return a pointer to a string containing the 'declaration type' of the
    ** expression pExpr. The string may be treated as static by the caller.
    **
    ** The declaration type is the exact datatype definition extracted from the
    ** original CREATE TABLE statement if the expression is a column. The
    ** declaration type for a ROWID field is INTEGER. Exactly when an expression
    ** is considered a column can be complex in the presence of subqueries. The
    ** result-set expression in all of the following SELECT statements is
    ** considered a column by this function.
    **
    **   SELECT col FROM tbl;
    **   SELECT (SELECT col FROM tbl;
    **   SELECT (SELECT col FROM tbl);
    **   SELECT abc FROM (SELECT col AS abc FROM tbl);
    **
    ** The declaration type for any expression other than a column is NULL.
    */
    static string columnType(
    NameContext pNC,
    Expr pExpr,
    ref string pzOriginDb,
    ref string pzOriginTab,
    ref string pzOriginCol
    )
    {
      string zType = null;
      string zOriginDb = null;
      string zOriginTab = null;
      string zOriginCol = null;
      int j;
      if ( NEVER( pExpr == null ) || pNC.pSrcList == null ) return null;

      switch ( pExpr.op )
      {
        case TK_AGG_COLUMN:
        case TK_COLUMN:
          {
            /* The expression is a column. Locate the table the column is being
            ** extracted from in NameContext.pSrcList. This table may be real
            ** database table or a subquery.
            */
            Table pTab = null;            /* Table structure column is extracted from */
            Select pS = null;            /* Select the column is extracted from */
            int iCol = pExpr.iColumn;  /* Index of column in pTab */
            testcase( pExpr.op == TK_AGG_COLUMN );
            testcase( pExpr.op == TK_COLUMN );
            while ( pNC != null && pTab == null )
            {
              SrcList pTabList = pNC.pSrcList;
              for ( j = 0 ; j < pTabList.nSrc && pTabList.a[j].iCursor != pExpr.iTable ; j++ ) ;
              if ( j < pTabList.nSrc )
              {
                pTab = pTabList.a[j].pTab;
                pS = pTabList.a[j].pSelect;
              }
              else
              {
                pNC = pNC.pNext;
              }
            }

            if ( pTab == null )
            {
              /* FIX ME:
              ** This can occurs if you have something like "SELECT new.x;" inside
              ** a trigger.  In other words, if you reference the special "new"
              ** table in the result set of a select.  We do not have a good way
              ** to find the actual table type, so call it "TEXT".  This is really
              ** something of a bug, but I do not know how to fix it.
              **
              ** This code does not produce the correct answer - it just prevents
              ** a segfault.  See ticket #1229.
              */
              zType = "TEXT";
              break;
            }

            Debug.Assert( pTab != null );
            if ( pS != null )
            {
              /* The "table" is actually a sub-select or a view in the FROM clause
              ** of the SELECT statement. Return the declaration type and origin
              ** data for the result-set column of the sub-select.
              */
              if ( ALWAYS( iCol >= 0 && iCol < pS.pEList.nExpr ) )
              {
                /* If iCol is less than zero, then the expression requests the
                ** rowid of the sub-select or view. This expression is legal (see
                ** test case misc2.2.2) - it always evaluates to NULL.
                */
                NameContext sNC = new NameContext();
                Expr p = pS.pEList.a[iCol].pExpr;
                sNC.pSrcList = pS.pSrc;
                sNC.pNext = null;
                sNC.pParse = pNC.pParse;
                zType = columnType( sNC, p, ref zOriginDb, ref zOriginTab, ref zOriginCol );
              }
            }
            else if ( ALWAYS( pTab.pSchema ) )
//.........这里部分代码省略.........
开发者ID:mbahar94,项目名称:fracture,代码行数:101,代码来源:select_c.cs

示例15: sqlite3EndTable

        static void sqlite3EndTable(
            Parse pParse,          /* Parse context */
            Token pCons,           /* The ',' token after the last column defn. */
            Token pEnd,            /* The final ')' token in the CREATE TABLE */
            Select pSelect         /* Select from a "CREATE ... AS SELECT" */
            )
        {
            Table p;
            sqlite3 db = pParse.db;
            int iDb;

            if ((pEnd == null && pSelect == null) /*|| db.mallocFailed != 0 */ )
            {
                return;
            }
            p = pParse.pNewTable;
            if (p == null)
                return;

            Debug.Assert(0 == db.init.busy || pSelect == null);

            iDb = sqlite3SchemaToIndex(db, p.pSchema);

            #if !SQLITE_OMIT_CHECK
            /* Resolve names in all CHECK constraint expressions.
            */
            if (p.pCheck != null)
            {
                SrcList sSrc;                   /* Fake SrcList for pParse.pNewTable */
                NameContext sNC;                /* Name context for pParse.pNewTable */

                sNC = new NameContext();// memset(sNC, 0, sizeof(sNC));
                sSrc = new SrcList();// memset(sSrc, 0, sizeof(sSrc));
                sSrc.nSrc = 1;
                sSrc.a = new SrcList_item[1];
                sSrc.a[0] = new SrcList_item();
                sSrc.a[0].zName = p.zName;
                sSrc.a[0].pTab = p;
                sSrc.a[0].iCursor = -1;
                sNC.pParse = pParse;
                sNC.pSrcList = sSrc;
                sNC.isCheck = 1;
                if (sqlite3ResolveExprNames(sNC, ref p.pCheck) != 0)
                {
                    return;
                }
            }
            #endif // * !SQLITE_OMIT_CHECK) */

            /* If the db.init.busy is 1 it means we are reading the SQL off the
            ** "sqlite_master" or "sqlite_temp_master" table on the disk.
            ** So do not write to the disk again.  Extract the root page number
            ** for the table from the db.init.newTnum field.  (The page number
            ** should have been put there by the sqliteOpenCb routine.)
            */
            if (db.init.busy != 0)
            {
                p.tnum = db.init.newTnum;
            }

            /* If not initializing, then create a record for the new table
            ** in the SQLITE_MASTER table of the database.
            **
            ** If this is a TEMPORARY table, write the entry into the auxiliary
            ** file instead of into the main database file.
            */
            if (0 == db.init.busy)
            {
                int n;
                Vdbe v;
                String zType = "";    /* "view" or "table" */
                String zType2 = "";    /* "VIEW" or "TABLE" */
                String zStmt = "";    /* Text of the CREATE TABLE or CREATE VIEW statement */

                v = sqlite3GetVdbe(pParse);
                if (NEVER(v == null))
                    return;

                sqlite3VdbeAddOp1(v, OP_Close, 0);

                /*
                ** Initialize zType for the new view or table.
                */
                if (p.pSelect == null)
                {
                    /* A regular table */
                    zType = "table";
                    zType2 = "TABLE";
            #if !SQLITE_OMIT_VIEW
                }
                else
                {
                    /* A view */
                    zType = "view";
                    zType2 = "VIEW";
            #endif
                }

                /* If this is a CREATE TABLE xx AS SELECT ..., execute the SELECT
                ** statement to populate the new table. The root-page number for the
//.........这里部分代码省略.........
开发者ID:JiujiangZhu,项目名称:feaserver,代码行数:101,代码来源:Build+Table.cs


注:本文中的NameContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。