示例#1
0
    static int flagPragma( Parse pParse, string zLeft, string zRight )
    {
      sPragmaType[] aPragma = new sPragmaType[]{
new sPragmaType( "full_column_names",        SQLITE_FullColNames  ),
new sPragmaType( "short_column_names",       SQLITE_ShortColNames ),
new sPragmaType( "count_changes",            SQLITE_CountRows     ),
new sPragmaType( "empty_result_callbacks",   SQLITE_NullCallback  ),
new sPragmaType( "legacy_file_format",       SQLITE_LegacyFileFmt ),
new sPragmaType( "fullfsync",                SQLITE_FullFSync     ),
new sPragmaType( "checkpoint_fullfsync",     SQLITE_CkptFullFSync ),
new sPragmaType(  "reverse_unordered_selects", SQLITE_ReverseOrder),
#if !SQLITE_OMIT_AUTOMATIC_INDEX
new sPragmaType(  "automatic_index",          SQLITE_AutoIndex    ),
#endif
#if SQLITE_DEBUG
new sPragmaType( "sql_trace",                SQLITE_SqlTrace      ),
new sPragmaType( "vdbe_listing",             SQLITE_VdbeListing   ),
new sPragmaType( "vdbe_trace",               SQLITE_VdbeTrace     ),
#endif
#if !SQLITE_OMIT_CHECK
new sPragmaType( "ignore_check_constraints", SQLITE_IgnoreChecks  ),
#endif
/* The following is VERY experimental */
new sPragmaType( "writable_schema",          SQLITE_WriteSchema|SQLITE_RecoveryMode ),
new sPragmaType( "omit_readlock",            SQLITE_NoReadlock    ),

/* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
** flag if there are any active statements. */
new sPragmaType( "read_uncommitted",         SQLITE_ReadUncommitted ),
new sPragmaType( "recursive_triggers",       SQLITE_RecTriggers ),

/* This flag may only be set if both foreign-key and trigger support
** are present in the build.  */
#if !(SQLITE_OMIT_FOREIGN_KEY) && !(SQLITE_OMIT_TRIGGER)
new sPragmaType( "foreign_keys",             SQLITE_ForeignKeys ),
#endif
};
      int i;
      sPragmaType p;
      for ( i = 0; i < ArraySize( aPragma ); i++ )//, p++)
      {
        p = aPragma[i];
        if ( zLeft.Equals( p.zName ,StringComparison.InvariantCultureIgnoreCase )  )
        {
          sqlite3 db = pParse.db;
          Vdbe v;
          v = sqlite3GetVdbe( pParse );
          Debug.Assert( v != null );  /* Already allocated by sqlite3Pragma() */
          if ( ALWAYS( v ) )
          {
            if ( null == zRight )
            {
              returnSingleInt( pParse, p.zName, ( ( db.flags & p.mask ) != 0 ) ? 1 : 0 );
            }
            else
            {
              int mask = p.mask;          /* Mask of bits to set or clear. */
              if ( db.autoCommit == 0 )
              {
                /* Foreign key support may not be enabled or disabled while not
                ** in auto-commit mode.  */
                mask &= ~( SQLITE_ForeignKeys );
              }
              if ( sqlite3GetBoolean( zRight ) != 0 )
              {
                db.flags |= mask;
              }
              else
              {
                db.flags &= ~mask;
              }

              /* Many of the flag-pragmas modify the code generated by the SQL
              ** compiler (eg. count_changes). So add an opcode to expire all
              ** compiled SQL statements after modifying a pragma value.
              */
              sqlite3VdbeAddOp2( v, OP_Expire, 0, 0 );
            }
          }

          return 1;
        }
      }
      return 0;
    }
示例#2
0
    static int flagPragma( Parse pParse, string zLeft, string zRight )
    {
      sPragmaType[] aPragma = new sPragmaType[]{
new sPragmaType( "full_column_names",        SQLITE_FullColNames  ),
new sPragmaType( "short_column_names",       SQLITE_ShortColNames ),
new sPragmaType( "count_changes",            SQLITE_CountRows     ),
new sPragmaType( "empty_result_callbacks",   SQLITE_NullCallback  ),
new sPragmaType( "legacy_file_format",       SQLITE_LegacyFileFmt ),
new sPragmaType( "fullfsync",                SQLITE_FullFSync     ),
new sPragmaType(  "reverse_unordered_selects", SQLITE_ReverseOrder  ),
#if SQLITE_DEBUG
new sPragmaType( "sql_trace",                SQLITE_SqlTrace      ),
new sPragmaType( "vdbe_listing",             SQLITE_VdbeListing   ),
new sPragmaType( "vdbe_trace",               SQLITE_VdbeTrace     ),
#endif
#if !SQLITE_OMIT_CHECK
new sPragmaType( "ignore_check_constraints", SQLITE_IgnoreChecks  ),
#endif
/* The following is VERY experimental */
new sPragmaType( "writable_schema",          SQLITE_WriteSchema|SQLITE_RecoveryMode ),
new sPragmaType( "omit_readlock",            SQLITE_NoReadlock    ),

/* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
** flag if there are any active statements. */
new sPragmaType( "read_uncommitted",         SQLITE_ReadUncommitted ),
};
      int i;
      sPragmaType p;
      for ( i = 0 ; i < ArraySize( aPragma ) ; i++ )//, p++)
      {
        p = aPragma[i];
        if ( sqlite3StrICmp( zLeft, p.zName ) == 0 )
        {
          sqlite3 db = pParse.db;
          Vdbe v;
          v = sqlite3GetVdbe( pParse );
          Debug.Assert( v != null );  /* Already allocated by sqlite3Pragma() */
          if ( ALWAYS( v ) )
          {
            if ( null == zRight )
            {
              returnSingleInt( pParse, p.zName, ( ( db.flags & p.mask ) != 0 ) ? 1 : 0 );
            }
            else
            {
              if ( getBoolean( zRight ) != 0 )
              {
                db.flags |= p.mask;
              }
              else
              {
                db.flags &= ~p.mask;
              }

              /* Many of the flag-pragmas modify the code generated by the SQL
              ** compiler (eg. count_changes). So add an opcode to expire all
              ** compiled SQL statements after modifying a pragma value.
              */
              sqlite3VdbeAddOp2( v, OP_Expire, 0, 0 );
            }
          }

          return 1;
        }
      }
      return 0;
    }