engine/sqlite/src/pragma.cpp
author teknolog
Sat, 24 Apr 2010 21:46:17 +0100
changeset 120 31d05afa1a52
parent 2 29cda98b007e
permissions -rw-r--r--
Added video podcast icons, but they don't work correctly yet.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     1
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     2
** 2003 April 6
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     3
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     4
** The author disclaims copyright to this source code.  In place of
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     5
** a legal notice, here is a blessing:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     6
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     7
**    May you do good and not evil.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     8
**    May you find forgiveness for yourself and forgive others.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
     9
**    May you share freely, never taking more than you give.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    10
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    11
*************************************************************************
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    12
** This file contains code used to implement the PRAGMA command.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    13
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
** $Id: pragma.cpp 1282 2008-11-13 09:31:33Z LarsPson $
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    15
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    16
#include "sqliteInt.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    17
#include <ctype.h>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    18
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    19
/* Ignore this whole file if pragmas are disabled
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    20
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
#if !defined(SQLITE_OMIT_PRAGMA) && !defined(SQLITE_OMIT_PARSER)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
** Interpret the given string as a safety level.  Return 0 for OFF,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
** 1 for ON or NORMAL and 2 for FULL.  Return 1 for an empty or 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
** unrecognized string argument.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    27
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
** Note that the values returned are one less that the values that
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
** should be passed into sqlite3BtreeSetSafetyLevel().  The is done
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
** to support legacy SQL code.  The safety level used to be boolean
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
** and older scripts may have used numbers 0 for OFF and 1 for ON.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
static int getSafetyLevel(const char *z){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
                             /* 123456789 123456789 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
  static const char zText[] = "onoffalseyestruefull";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
  static const u8 iOffset[] = {0, 1, 2, 4, 9, 12, 16};
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
  static const u8 iLength[] = {2, 2, 3, 5, 3, 4, 4};
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
  static const u8 iValue[] =  {1, 0, 0, 0, 1, 1, 2};
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
  int i, n;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
  if( isdigit(*z) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
    return atoi(z);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
  n = strlen(z);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
  for(i=0; i<sizeof(iLength); i++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
    if( iLength[i]==n && sqlite3StrNICmp(&zText[iOffset[i]],z,n)==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
      return iValue[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
  return 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
** Interpret the given string as a boolean value.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
static int getBoolean(const char *z){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
  return getSafetyLevel(z)&1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
** Interpret the given string as a locking mode value.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
static int getLockingMode(const char *z){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
  if( z ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
    if( 0==sqlite3StrICmp(z, "exclusive") ) return PAGER_LOCKINGMODE_EXCLUSIVE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
    if( 0==sqlite3StrICmp(z, "normal") ) return PAGER_LOCKINGMODE_NORMAL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
  return PAGER_LOCKINGMODE_QUERY;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
#ifndef SQLITE_OMIT_AUTOVACUUM
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
** Interpret the given string as an auto-vacuum mode value.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
** The following strings, "none", "full" and "incremental" are 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
** acceptable, as are their numeric equivalents: 0, 1 and 2 respectively.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    76
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
static int getAutoVacuum(const char *z){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
  int i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
  if( 0==sqlite3StrICmp(z, "none") ) return BTREE_AUTOVACUUM_NONE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
  if( 0==sqlite3StrICmp(z, "full") ) return BTREE_AUTOVACUUM_FULL;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
  if( 0==sqlite3StrICmp(z, "incremental") ) return BTREE_AUTOVACUUM_INCR;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
  i = atoi(z);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
  return ((i>=0&&i<=2)?i:0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
#endif /* ifndef SQLITE_OMIT_AUTOVACUUM */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
** Interpret the given string as a temp db location. Return 1 for file
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
** backed temporary databases, 2 for the Red-Black tree in memory database
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
** and 0 to use the compile-time default.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
static int getTempStore(const char *z){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
  if( z[0]>='0' && z[0]<='2' ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
    return z[0] - '0';
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
  }else if( sqlite3StrICmp(z, "file")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
    return 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
  }else if( sqlite3StrICmp(z, "memory")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
    return 2;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
    return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
#endif /* SQLITE_PAGER_PRAGMAS */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
** Invalidate temp storage, either when the temp storage is changed
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
** from default, or when 'file' and the temp_store_directory has changed
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
static int invalidateTempStorage(Parse *pParse){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
  sqlite3 *db = pParse->db;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
  if( db->aDb[1].pBt!=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
    if( !db->autoCommit ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
      sqlite3ErrorMsg(pParse, "temporary storage cannot be changed "
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
        "from within a transaction");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
      return SQLITE_ERROR;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
    sqlite3BtreeClose(db->aDb[1].pBt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
    db->aDb[1].pBt = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
    sqlite3ResetInternalSchema(db, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
#endif /* SQLITE_PAGER_PRAGMAS */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
** If the TEMP database is open, close it and mark the database schema
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
** as needing reloading.  This must be done when using the TEMP_STORE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
** or DEFAULT_TEMP_STORE pragmas.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
static int changeTempStorage(Parse *pParse, const char *zStorageType){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
  int ts = getTempStore(zStorageType);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
  sqlite3 *db = pParse->db;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
  if( db->temp_store==ts ) return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
  if( invalidateTempStorage( pParse ) != SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
    return SQLITE_ERROR;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   140
  db->temp_store = ts;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
#endif /* SQLITE_PAGER_PRAGMAS */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   145
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
** Generate code to return a single integer value.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
static void returnSingleInt(Parse *pParse, const char *zLabel, int value){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   149
  Vdbe *v = sqlite3GetVdbe(pParse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
  sqlite3VdbeAddOp(v, OP_Integer, value, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
  if( pParse->explain==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
    sqlite3VdbeSetNumCols(v, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLabel, P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
  sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   159
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   160
** Check to see if zRight and zLeft refer to a pragma that queries
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
** or changes one of the flags in db->flags.  Return 1 if so and 0 if not.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
** Also, implement the pragma.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
static int flagPragma(Parse *pParse, const char *zLeft, const char *zRight){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
  static const struct sPragmaType {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
    const char *zName;  /* Name of the pragma */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
    int mask;           /* Mask for the db->flags value */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
  } aPragma[] = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
    { "full_column_names",        SQLITE_FullColNames  },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
    { "short_column_names",       SQLITE_ShortColNames },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
    { "count_changes",            SQLITE_CountRows     },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
    { "empty_result_callbacks",   SQLITE_NullCallback  },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
    { "legacy_file_format",       SQLITE_LegacyFileFmt },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
    { "fullfsync",                SQLITE_FullFSync     },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
#ifdef SQLITE_DEBUG
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
    { "sql_trace",                SQLITE_SqlTrace      },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
    { "vdbe_listing",             SQLITE_VdbeListing   },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
    { "vdbe_trace",               SQLITE_VdbeTrace     },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
#ifndef SQLITE_OMIT_CHECK
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
    { "ignore_check_constraints", SQLITE_IgnoreChecks  },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
    /* The following is VERY experimental */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
    { "writable_schema",          SQLITE_WriteSchema|SQLITE_RecoveryMode },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
    { "omit_readlock",            SQLITE_NoReadlock    },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   187
    /* TODO: Maybe it shouldn't be possible to change the ReadUncommitted
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   188
    ** flag if there are any active statements. */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   189
    { "read_uncommitted",         SQLITE_ReadUncommitted },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
  };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
  int i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
  const struct sPragmaType *p;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
  for(i=0, p=aPragma; i<sizeof(aPragma)/sizeof(aPragma[0]); i++, p++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
    if( sqlite3StrICmp(zLeft, p->zName)==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
      sqlite3 *db = pParse->db;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
      Vdbe *v;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
      v = sqlite3GetVdbe(pParse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
      if( v ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
        if( zRight==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
          returnSingleInt(pParse, p->zName, (db->flags & p->mask)!=0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
        }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   202
          if( getBoolean(zRight) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   203
            db->flags |= p->mask;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   204
          }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
            db->flags &= ~p->mask;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
          /* Many of the flag-pragmas modify the code generated by the SQL 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
          ** compiler (eg. count_changes). So add an opcode to expire all
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
          ** compiled SQL statements after modifying a pragma value.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   211
          */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   212
          sqlite3VdbeAddOp(v, OP_Expire, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
      return 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   218
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
  return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
** Process a pragma statement.  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
** Pragmas are of this form:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
**      PRAGMA [database.]id [= value]
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
** The identifier might also be a string.  The value is a string, and
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
** identifier, or a number.  If minusFlag is true, then the value is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
** a number that was preceded by a minus sign.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
** If the left side is "database.id" then pId1 is the database name
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
** and pId2 is the id.  If the left side is just "id" then pId1 is the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
** id and pId2 is any empty string.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
void sqlite3Pragma(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
  Parse *pParse, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
  Token *pId1,        /* First part of [database.]id field */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
  Token *pId2,        /* Second part of [database.]id field, or NULL */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
  Token *pValue,      /* Token for <value>, or NULL */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
  int minusFlag       /* True if a '-' sign preceded <value> */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   245
  char *zLeft = 0;       /* Nul-terminated UTF-8 string <id> */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
  char *zRight = 0;      /* Nul-terminated UTF-8 string <value>, or NULL */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
  const char *zDb = 0;   /* The database name */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
  Token *pId;            /* Pointer to <id> token */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
  int iDb;               /* Database index for <database> */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
  sqlite3 *db = pParse->db;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
  Db *pDb;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
  Vdbe *v = sqlite3GetVdbe(pParse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
  if( v==0 ) return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
  /* Interpret the [database.] part of the pragma statement. iDb is the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
  ** index of the database this pragma is being applied to in db.aDb[]. */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
  iDb = sqlite3TwoPartName(pParse, pId1, pId2, &pId);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
  if( iDb<0 ) return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
  pDb = &db->aDb[iDb];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
  /* If the temp database has been explicitly named as part of the 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
  ** pragma, make sure it is open. 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
  if( iDb==1 && sqlite3OpenTempDatabase(pParse) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
    return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   267
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
  zLeft = sqlite3NameFromToken(db, pId);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
  if( !zLeft ) return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
  if( minusFlag ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
    zRight = sqlite3MPrintf(db, "-%T", pValue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
    zRight = sqlite3NameFromToken(db, pValue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
  zDb = ((iDb>0)?pDb->zName:0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
  if( sqlite3AuthCheck(pParse, SQLITE_PRAGMA, zLeft, zRight, zDb) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
    goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   280
 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
  **  PRAGMA [database.]default_cache_size
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   284
  **  PRAGMA [database.]default_cache_size=N
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   285
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   286
  ** The first form reports the current persistent setting for the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
  ** page cache size.  The value returned is the maximum number of
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
  ** pages in the page cache.  The second form sets both the current
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
  ** page cache size value and the persistent page cache size value
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
  ** stored in the database file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
  ** The default cache size is stored in meta-value 2 of page 1 of the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
  ** database file.  The cache size is actually the absolute value of
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
  ** this memory location.  The sign of meta-value 2 determines the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
  ** synchronous setting.  A negative value means synchronous is off
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
  ** and a positive value means synchronous is on.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
  if( sqlite3StrICmp(zLeft,"default_cache_size")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
    static const VdbeOpList getCacheSize[] = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
      { OP_ReadCookie,  0, 2,        0},  /* 0 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
      { OP_AbsValue,    0, 0,        0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
      { OP_Dup,         0, 0,        0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
      { OP_Integer,     0, 0,        0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
      { OP_Ne,          0, 6,        0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
      { OP_Integer,     0, 0,        0},  /* 5 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   306
      { OP_Callback,    1, 0,        0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   307
    };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
    int addr;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   309
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
    sqlite3VdbeUsesBtree(v, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   311
    if( !zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
      sqlite3VdbeSetNumCols(v, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cache_size", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
      addr = sqlite3VdbeAddOpList(v, ArraySize(getCacheSize), getCacheSize);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   315
      sqlite3VdbeChangeP1(v, addr, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
      sqlite3VdbeChangeP1(v, addr+5, SQLITE_DEFAULT_CACHE_SIZE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   318
      int size = atoi(zRight);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   319
      if( size<0 ) size = -size;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   320
      sqlite3BeginWriteOperation(pParse, 0, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   321
      sqlite3VdbeAddOp(v, OP_Integer, size, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   322
      sqlite3VdbeAddOp(v, OP_ReadCookie, iDb, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   323
      addr = sqlite3VdbeAddOp(v, OP_Integer, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
      sqlite3VdbeAddOp(v, OP_Ge, 0, addr+3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
      sqlite3VdbeAddOp(v, OP_Negative, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
      sqlite3VdbeAddOp(v, OP_SetCookie, iDb, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   327
      pDb->pSchema->cache_size = size;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   328
      sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   329
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   330
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   331
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   332
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   333
  **  PRAGMA [database.]page_size
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   334
  **  PRAGMA [database.]page_size=N
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   335
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   336
  ** The first form reports the current setting for the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
  ** database page size in bytes.  The second form sets the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   338
  ** database page size value.  The value can only be set if
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   339
  ** the database has not yet been created.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   340
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   341
  if( sqlite3StrICmp(zLeft,"page_size")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   342
    Btree *pBt = pDb->pBt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   343
    if( !zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   344
      int size = pBt ? sqlite3BtreeGetPageSize(pBt) : 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   345
      returnSingleInt(pParse, "page_size", size);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   346
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   347
      /* Malloc may fail when setting the page-size, as there is an internal
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   348
      ** buffer that the pager module resizes using sqlite3_realloc().
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   349
      */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   350
      if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, atoi(zRight), -1) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   351
        db->mallocFailed = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   352
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   353
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   354
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   355
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   356
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   357
  **  PRAGMA [database.]max_page_count
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   358
  **  PRAGMA [database.]max_page_count=N
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   359
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
  ** The first form reports the current setting for the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   361
  ** maximum number of pages in the database file.  The 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
  ** second form attempts to change this setting.  Both
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   363
  ** forms return the current setting.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   364
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   365
  if( sqlite3StrICmp(zLeft,"max_page_count")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   366
    Btree *pBt = pDb->pBt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   367
    int newMax = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   368
    if( zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   369
      newMax = atoi(zRight);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   370
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   371
    if( pBt ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   372
      newMax = sqlite3BtreeMaxPageCount(pBt, newMax);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   373
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
    returnSingleInt(pParse, "max_page_count", newMax);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   376
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   377
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   378
  **  PRAGMA [database.]locking_mode
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   379
  **  PRAGMA [database.]locking_mode = (normal|exclusive)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   380
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   381
  if( sqlite3StrICmp(zLeft,"locking_mode")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   382
    const char *zRet = "normal";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   383
    int eMode = getLockingMode(zRight);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   384
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   385
    if( pId2->n==0 && eMode==PAGER_LOCKINGMODE_QUERY ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   386
      /* Simple "PRAGMA locking_mode;" statement. This is a query for
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   387
      ** the current default locking mode (which may be different to
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   388
      ** the locking-mode of the main database).
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   389
      */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   390
      eMode = db->dfltLockMode;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   391
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   392
      Pager *pPager;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   393
      if( pId2->n==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   394
        /* This indicates that no database name was specified as part
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   395
        ** of the PRAGMA command. In this case the locking-mode must be
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   396
        ** set on all attached databases, as well as the main db file.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   397
        **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   398
        ** Also, the sqlite3.dfltLockMode variable is set so that
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   399
        ** any subsequently attached databases also use the specified
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   400
        ** locking mode.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   401
        */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
        int ii;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   403
        assert(pDb==&db->aDb[0]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
        for(ii=2; ii<db->nDb; ii++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   405
          pPager = sqlite3BtreePager(db->aDb[ii].pBt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   406
          sqlite3PagerLockingMode(pPager, eMode);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   407
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   408
        db->dfltLockMode = eMode;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   409
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   410
      pPager = sqlite3BtreePager(pDb->pBt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   411
      eMode = sqlite3PagerLockingMode(pPager, eMode);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   412
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   413
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   414
    assert(eMode==PAGER_LOCKINGMODE_NORMAL||eMode==PAGER_LOCKINGMODE_EXCLUSIVE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   415
    if( eMode==PAGER_LOCKINGMODE_EXCLUSIVE ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   416
      zRet = "exclusive";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   417
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   418
    sqlite3VdbeSetNumCols(v, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   419
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "locking_mode", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
    sqlite3VdbeOp3(v, OP_String8, 0, 0, zRet, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
    sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   422
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   423
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   424
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   425
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   426
  **  PRAGMA [database.]auto_vacuum
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   427
  **  PRAGMA [database.]auto_vacuum=N
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   428
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   429
  ** Get or set the (boolean) value of the database 'auto-vacuum' parameter.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   430
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   431
#ifndef SQLITE_OMIT_AUTOVACUUM
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   432
  if( sqlite3StrICmp(zLeft,"auto_vacuum")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   433
    Btree *pBt = pDb->pBt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   434
    if( sqlite3ReadSchema(pParse) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   435
      goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   437
    if( !zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   438
      int auto_vacuum = 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   439
          pBt ? sqlite3BtreeGetAutoVacuum(pBt) : SQLITE_DEFAULT_AUTOVACUUM;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   440
      returnSingleInt(pParse, "auto_vacuum", auto_vacuum);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   441
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
      int eAuto = getAutoVacuum(zRight);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   443
      db->nextAutovac = eAuto;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   444
      if( eAuto>=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   445
        /* Call SetAutoVacuum() to set initialize the internal auto and
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   446
        ** incr-vacuum flags. This is required in case this connection
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   447
        ** creates the database file. It is important that it is created
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448
        ** as an auto-vacuum capable db.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   449
        */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   450
        int rc = sqlite3BtreeSetAutoVacuum(pBt, eAuto);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   451
        if( rc==SQLITE_OK && (eAuto==1 || eAuto==2) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   452
          /* When setting the auto_vacuum mode to either "full" or 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   453
          ** "incremental", write the value of meta[6] in the database
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   454
          ** file. Before writing to meta[6], check that meta[3] indicates
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   455
          ** that this really is an auto-vacuum capable database.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   456
          */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   457
          static const VdbeOpList setMeta6[] = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   458
            { OP_Transaction,    0,               1,        0},    /* 0 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   459
            { OP_ReadCookie,     0,               3,        0},    /* 1 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   460
            { OP_If,             0,               0,        0},    /* 2 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   461
            { OP_Halt,           SQLITE_OK,       OE_Abort, 0},    /* 3 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   462
            { OP_Integer,        0,               0,        0},    /* 4 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   463
            { OP_SetCookie,      0,               6,        0},    /* 5 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   464
          };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   465
          int iAddr;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   466
          iAddr = sqlite3VdbeAddOpList(v, ArraySize(setMeta6), setMeta6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   467
          sqlite3VdbeChangeP1(v, iAddr, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   468
          sqlite3VdbeChangeP1(v, iAddr+1, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   469
          sqlite3VdbeChangeP2(v, iAddr+2, iAddr+4);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   470
          sqlite3VdbeChangeP1(v, iAddr+4, eAuto-1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   471
          sqlite3VdbeChangeP1(v, iAddr+5, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   472
          sqlite3VdbeUsesBtree(v, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   473
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   474
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   475
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   476
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   477
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   478
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   479
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   480
  **  PRAGMA [database.]incremental_vacuum(N)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   481
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   482
  ** Do N steps of incremental vacuuming on a database.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   483
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   484
#ifndef SQLITE_OMIT_AUTOVACUUM
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   485
  if( sqlite3StrICmp(zLeft,"incremental_vacuum")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   486
    int iLimit, addr;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   487
    if( sqlite3ReadSchema(pParse) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   488
      goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   489
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   490
    if( zRight==0 || !sqlite3GetInt32(zRight, &iLimit) || iLimit<=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   491
      iLimit = 0x7fffffff;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   492
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   493
    sqlite3BeginWriteOperation(pParse, 0, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   494
    sqlite3VdbeAddOp(v, OP_MemInt, iLimit, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   495
    addr = sqlite3VdbeAddOp(v, OP_IncrVacuum, iDb, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   496
    sqlite3VdbeAddOp(v, OP_Callback, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   497
    sqlite3VdbeAddOp(v, OP_MemIncr, -1, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   498
    sqlite3VdbeAddOp(v, OP_IfMemPos, 0, addr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   499
    sqlite3VdbeJumpHere(v, addr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   500
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   501
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   502
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   503
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   504
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   505
  **  PRAGMA [database.]cache_size
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   506
  **  PRAGMA [database.]cache_size=N
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   507
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   508
  ** The first form reports the current local setting for the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   509
  ** page cache size.  The local setting can be different from
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   510
  ** the persistent cache size value that is stored in the database
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   511
  ** file itself.  The value returned is the maximum number of
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   512
  ** pages in the page cache.  The second form sets the local
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   513
  ** page cache size value.  It does not change the persistent
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   514
  ** cache size stored on the disk so the cache size will revert
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   515
  ** to its default value when the database is closed and reopened.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   516
  ** N should be a positive integer.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   517
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   518
  if( sqlite3StrICmp(zLeft,"cache_size")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   519
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   520
    if( !zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   521
      returnSingleInt(pParse, "cache_size", pDb->pSchema->cache_size);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   522
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   523
      int size = atoi(zRight);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   524
      if( size<0 ) size = -size;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   525
      pDb->pSchema->cache_size = size;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   526
      sqlite3BtreeSetCacheSize(pDb->pBt, pDb->pSchema->cache_size);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   527
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   528
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   529
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   530
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   531
  **   PRAGMA temp_store
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   532
  **   PRAGMA temp_store = "default"|"memory"|"file"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   533
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   534
  ** Return or set the local value of the temp_store flag.  Changing
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   535
  ** the local value does not make changes to the disk file and the default
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   536
  ** value will be restored the next time the database is opened.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   537
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   538
  ** Note that it is possible for the library compile-time options to
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   539
  ** override this setting
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   540
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   541
  if( sqlite3StrICmp(zLeft, "temp_store")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   542
    if( !zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   543
      returnSingleInt(pParse, "temp_store", db->temp_store);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   544
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   545
      changeTempStorage(pParse, zRight);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   546
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   547
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   548
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   549
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   550
  **   PRAGMA temp_store_directory
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   551
  **   PRAGMA temp_store_directory = ""|"directory_name"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   552
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   553
  ** Return or set the local value of the temp_store_directory flag.  Changing
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   554
  ** the value sets a specific directory to be used for temporary files.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   555
  ** Setting to a null string reverts to the default temporary directory search.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   556
  ** If temporary directory is changed, then invalidateTempStorage.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   557
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   558
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   559
  if( sqlite3StrICmp(zLeft, "temp_store_directory")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   560
    if( !zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   561
      if( sqlite3_temp_directory ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   562
        sqlite3VdbeSetNumCols(v, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   563
        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   564
            "temp_store_directory", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   565
        sqlite3VdbeOp3(v, OP_String8, 0, 0, sqlite3_temp_directory, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   566
        sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   567
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   568
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   569
      if( zRight[0] 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   570
       && !sqlite3OsAccess(db->pVfs, zRight, SQLITE_ACCESS_READWRITE) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   571
      ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   572
        sqlite3ErrorMsg(pParse, "not a writable directory");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   573
        goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   574
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   575
      if( TEMP_STORE==0
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   576
       || (TEMP_STORE==1 && db->temp_store<=1)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   577
       || (TEMP_STORE==2 && db->temp_store==1)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   578
      ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   579
        invalidateTempStorage(pParse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   580
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   581
      sqlite3_free(sqlite3_temp_directory);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   582
      if( zRight[0] ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   583
        sqlite3_temp_directory = zRight;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   584
        zRight = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   585
      }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   586
        sqlite3_temp_directory = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   587
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   588
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   589
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   590
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   591
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   592
  **   PRAGMA [database.]synchronous
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   593
  **   PRAGMA [database.]synchronous=OFF|ON|NORMAL|FULL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   594
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   595
  ** Return or set the local value of the synchronous flag.  Changing
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   596
  ** the local value does not make changes to the disk file and the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   597
  ** default value will be restored the next time the database is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   598
  ** opened.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   599
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   600
  if( sqlite3StrICmp(zLeft,"synchronous")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   601
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   602
    if( !zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   603
      returnSingleInt(pParse, "synchronous", pDb->safety_level-1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   604
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   605
      if( !db->autoCommit ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   606
        sqlite3ErrorMsg(pParse, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   607
            "Safety level may not be changed inside a transaction");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   608
      }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   609
        pDb->safety_level = getSafetyLevel(zRight)+1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   610
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   611
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   612
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   613
#endif /* SQLITE_OMIT_PAGER_PRAGMAS */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   614
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   615
#ifndef SQLITE_OMIT_FLAG_PRAGMAS
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   616
  if( flagPragma(pParse, zLeft, zRight) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   617
    /* The flagPragma() subroutine also generates any necessary code
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   618
    ** there is nothing more to do here */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   619
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   620
#endif /* SQLITE_OMIT_FLAG_PRAGMAS */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   621
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   622
#ifndef SQLITE_OMIT_SCHEMA_PRAGMAS
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   623
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   624
  **   PRAGMA table_info(<table>)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   625
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   626
  ** Return a single row for each column of the named table. The columns of
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   627
  ** the returned data set are:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   628
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   629
  ** cid:        Column id (numbered from left to right, starting at 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   630
  ** name:       Column name
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   631
  ** type:       Column declaration type.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   632
  ** notnull:    True if 'NOT NULL' is part of column declaration
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   633
  ** dflt_value: The default value for the column, if any.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   634
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   635
  if( sqlite3StrICmp(zLeft, "table_info")==0 && zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   636
    Table *pTab;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   637
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   638
    pTab = sqlite3FindTable(db, zRight, zDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   639
    if( pTab ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   640
      int i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   641
      int nHidden = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   642
      Column *pCol;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   643
      sqlite3VdbeSetNumCols(v, 6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   644
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "cid", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   645
      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   646
      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "type", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   647
      sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "notnull", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   648
      sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "dflt_value", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   649
      sqlite3VdbeSetColName(v, 5, COLNAME_NAME, "pk", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   650
      sqlite3ViewGetColumnNames(pParse, pTab);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   651
      for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   652
        const Token *pDflt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   653
        if( IsHiddenColumn(pCol) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   654
          nHidden++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   655
          continue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   656
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   657
        sqlite3VdbeAddOp(v, OP_Integer, i-nHidden, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   658
        sqlite3VdbeOp3(v, OP_String8, 0, 0, pCol->zName, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   659
        sqlite3VdbeOp3(v, OP_String8, 0, 0,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   660
           pCol->zType ? pCol->zType : "", 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   661
        sqlite3VdbeAddOp(v, OP_Integer, pCol->notNull, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   662
        if( pCol->pDflt && (pDflt = &pCol->pDflt->span)->z ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   663
          sqlite3VdbeOp3(v, OP_String8, 0, 0, (char*)pDflt->z, pDflt->n);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   664
        }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   665
          sqlite3VdbeAddOp(v, OP_Null, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   666
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   667
        sqlite3VdbeAddOp(v, OP_Integer, pCol->isPrimKey, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   668
        sqlite3VdbeAddOp(v, OP_Callback, 6, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   669
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   670
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   671
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   672
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   673
  if( sqlite3StrICmp(zLeft, "index_info")==0 && zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   674
    Index *pIdx;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   675
    Table *pTab;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   676
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   677
    pIdx = sqlite3FindIndex(db, zRight, zDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   678
    if( pIdx ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   679
      int i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   680
      pTab = pIdx->pTable;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   681
      sqlite3VdbeSetNumCols(v, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   682
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seqno", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   683
      sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "cid", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   684
      sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "name", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   685
      for(i=0; i<pIdx->nColumn; i++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   686
        int cnum = pIdx->aiColumn[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   687
        sqlite3VdbeAddOp(v, OP_Integer, i, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   688
        sqlite3VdbeAddOp(v, OP_Integer, cnum, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   689
        assert( pTab->nCol>cnum );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   690
        sqlite3VdbeOp3(v, OP_String8, 0, 0, pTab->aCol[cnum].zName, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   691
        sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   692
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   693
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   694
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   695
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   696
  if( sqlite3StrICmp(zLeft, "index_list")==0 && zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   697
    Index *pIdx;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   698
    Table *pTab;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   699
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   700
    pTab = sqlite3FindTable(db, zRight, zDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   701
    if( pTab ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   702
      v = sqlite3GetVdbe(pParse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   703
      pIdx = pTab->pIndex;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   704
      if( pIdx ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   705
        int i = 0; 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   706
        sqlite3VdbeSetNumCols(v, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   707
        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   708
        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   709
        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "unique", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   710
        while(pIdx){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   711
          sqlite3VdbeAddOp(v, OP_Integer, i, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   712
          sqlite3VdbeOp3(v, OP_String8, 0, 0, pIdx->zName, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   713
          sqlite3VdbeAddOp(v, OP_Integer, pIdx->onError!=OE_None, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   714
          sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   715
          ++i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   716
          pIdx = pIdx->pNext;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   717
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   718
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   719
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   720
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   721
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   722
  if( sqlite3StrICmp(zLeft, "database_list")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   723
    int i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   724
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   725
    sqlite3VdbeSetNumCols(v, 3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   726
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   727
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   728
    sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "file", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   729
    for(i=0; i<db->nDb; i++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   730
      if( db->aDb[i].pBt==0 ) continue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   731
      assert( db->aDb[i].zName!=0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   732
      sqlite3VdbeAddOp(v, OP_Integer, i, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   733
      sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   734
      sqlite3VdbeOp3(v, OP_String8, 0, 0,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   735
           sqlite3BtreeGetFilename(db->aDb[i].pBt), 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   736
      sqlite3VdbeAddOp(v, OP_Callback, 3, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   737
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   738
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   739
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   740
  if( sqlite3StrICmp(zLeft, "collation_list")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   741
    int i = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   742
    HashElem *p;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   743
    sqlite3VdbeSetNumCols(v, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   744
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "seq", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   745
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "name", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   746
    for(p=sqliteHashFirst(&db->aCollSeq); p; p=sqliteHashNext(p)){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   747
      CollSeq *pColl = (CollSeq *)sqliteHashData(p);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   748
      sqlite3VdbeAddOp(v, OP_Integer, i++, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   749
      sqlite3VdbeOp3(v, OP_String8, 0, 0, pColl->zName, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   750
      sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   751
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   752
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   753
#endif /* SQLITE_OMIT_SCHEMA_PRAGMAS */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   754
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   755
#ifndef SQLITE_OMIT_FOREIGN_KEY
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   756
  if( sqlite3StrICmp(zLeft, "foreign_key_list")==0 && zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   757
    FKey *pFK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   758
    Table *pTab;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   759
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   760
    pTab = sqlite3FindTable(db, zRight, zDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   761
    if( pTab ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   762
      v = sqlite3GetVdbe(pParse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   763
      pFK = pTab->pFKey;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   764
      if( pFK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   765
        int i = 0; 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   766
        sqlite3VdbeSetNumCols(v, 5);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   767
        sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "id", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   768
        sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "seq", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   769
        sqlite3VdbeSetColName(v, 2, COLNAME_NAME, "table", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   770
        sqlite3VdbeSetColName(v, 3, COLNAME_NAME, "from", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   771
        sqlite3VdbeSetColName(v, 4, COLNAME_NAME, "to", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   772
        while(pFK){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   773
          int j;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   774
          for(j=0; j<pFK->nCol; j++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   775
            char *zCol = pFK->aCol[j].zCol;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   776
            sqlite3VdbeAddOp(v, OP_Integer, i, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   777
            sqlite3VdbeAddOp(v, OP_Integer, j, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   778
            sqlite3VdbeOp3(v, OP_String8, 0, 0, pFK->zTo, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   779
            sqlite3VdbeOp3(v, OP_String8, 0, 0,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   780
                             pTab->aCol[pFK->aCol[j].iFrom].zName, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   781
            sqlite3VdbeOp3(v, zCol ? OP_String8 : OP_Null, 0, 0, zCol, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   782
            sqlite3VdbeAddOp(v, OP_Callback, 5, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   783
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   784
          ++i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   785
          pFK = pFK->pNextFrom;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   786
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   787
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   788
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   789
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   790
#endif /* !defined(SQLITE_OMIT_FOREIGN_KEY) */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   791
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   792
#ifndef NDEBUG
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   793
  if( sqlite3StrICmp(zLeft, "parser_trace")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   794
    if( zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   795
      if( getBoolean(zRight) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   796
        sqlite3ParserTrace(stderr, "parser: ");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   797
      }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   798
        sqlite3ParserTrace(0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   799
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   800
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   801
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   802
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   803
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   804
  /* Reinstall the LIKE and GLOB functions.  The variant of LIKE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   805
  ** used will be case sensitive or not depending on the RHS.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   806
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   807
  if( sqlite3StrICmp(zLeft, "case_sensitive_like")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   808
    if( zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   809
      sqlite3RegisterLikeFunctions(db, getBoolean(zRight));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   810
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   811
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   812
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   813
#ifndef SQLITE_INTEGRITY_CHECK_ERROR_MAX
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   814
# define SQLITE_INTEGRITY_CHECK_ERROR_MAX 100
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   815
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   816
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   817
#ifndef SQLITE_OMIT_INTEGRITY_CHECK
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   818
  if( sqlite3StrICmp(zLeft, "integrity_check")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   819
    int i, j, addr, mxErr;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   820
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   821
    /* Code that appears at the end of the integrity check.  If no error
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   822
    ** messages have been generated, output OK.  Otherwise output the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   823
    ** error message
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   824
    */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   825
    static const VdbeOpList endCode[] = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   826
      { OP_MemLoad,     0, 0,        0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   827
      { OP_Integer,     0, 0,        0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   828
      { OP_Ne,          0, 0,        0},    /* 2 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   829
      { OP_String8,     0, 0,        "ok"},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   830
      { OP_Callback,    1, 0,        0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   831
    };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   832
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   833
    /* Initialize the VDBE program */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   834
    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   835
    sqlite3VdbeSetNumCols(v, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   836
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "integrity_check", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   837
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   838
    /* Set the maximum error count */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   839
    mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   840
    if( zRight ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   841
      mxErr = atoi(zRight);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   842
      if( mxErr<=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   843
        mxErr = SQLITE_INTEGRITY_CHECK_ERROR_MAX;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   844
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   845
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   846
    sqlite3VdbeAddOp(v, OP_MemInt, mxErr, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   847
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   848
    /* Do an integrity check on each database file */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   849
    for(i=0; i<db->nDb; i++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   850
      HashElem *x;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   851
      Hash *pTbls;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   852
      int cnt = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   853
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   854
      if( OMIT_TEMPDB && i==1 ) continue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   855
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   856
      sqlite3CodeVerifySchema(pParse, i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   857
      addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   858
      sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   859
      sqlite3VdbeJumpHere(v, addr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   860
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   861
      /* Do an integrity check of the B-Tree
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   862
      */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   863
      pTbls = &db->aDb[i].pSchema->tblHash;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   864
      for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   865
        Table *pTab = (Table*)sqliteHashData(x);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   866
        Index *pIdx;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   867
        sqlite3VdbeAddOp(v, OP_Integer, pTab->tnum, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   868
        cnt++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   869
        for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   870
          sqlite3VdbeAddOp(v, OP_Integer, pIdx->tnum, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   871
          cnt++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   872
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   873
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   874
      if( cnt==0 ) continue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   875
      sqlite3VdbeAddOp(v, OP_IntegrityCk, 0, i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   876
      addr = sqlite3VdbeAddOp(v, OP_IsNull, -1, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   877
      sqlite3VdbeOp3(v, OP_String8, 0, 0,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   878
         sqlite3MPrintf(db, "*** in database %s ***\n", db->aDb[i].zName),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   879
         P3_DYNAMIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   880
      sqlite3VdbeAddOp(v, OP_Pull, 1, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   881
      sqlite3VdbeAddOp(v, OP_Concat, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   882
      sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   883
      sqlite3VdbeJumpHere(v, addr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   884
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   885
      /* Make sure all the indices are constructed correctly.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   886
      */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   887
      for(x=sqliteHashFirst(pTbls); x; x=sqliteHashNext(x)){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   888
        Table *pTab = (Table*)sqliteHashData(x);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   889
        Index *pIdx;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   890
        int loopTop;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   891
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   892
        if( pTab->pIndex==0 ) continue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   893
        addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   894
        sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   895
        sqlite3VdbeJumpHere(v, addr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   896
        sqlite3OpenTableAndIndices(pParse, pTab, 1, OP_OpenRead);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   897
        sqlite3VdbeAddOp(v, OP_MemInt, 0, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   898
        loopTop = sqlite3VdbeAddOp(v, OP_Rewind, 1, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   899
        sqlite3VdbeAddOp(v, OP_MemIncr, 1, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   900
        for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   901
          int jmp2;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   902
          static const VdbeOpList idxErr[] = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   903
            { OP_MemIncr,    -1,  0,  0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   904
            { OP_String8,     0,  0,  "rowid "},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   905
            { OP_Rowid,       1,  0,  0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   906
            { OP_String8,     0,  0,  " missing from index "},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   907
            { OP_String8,     0,  0,  0},    /* 4 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   908
            { OP_Concat,      2,  0,  0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   909
            { OP_Callback,    1,  0,  0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   910
          };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   911
          sqlite3GenerateIndexKey(v, pIdx, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   912
          jmp2 = sqlite3VdbeAddOp(v, OP_Found, j+2, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   913
          addr = sqlite3VdbeAddOpList(v, ArraySize(idxErr), idxErr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   914
          sqlite3VdbeChangeP3(v, addr+4, pIdx->zName, P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   915
          sqlite3VdbeJumpHere(v, jmp2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   916
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   917
        sqlite3VdbeAddOp(v, OP_Next, 1, loopTop+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   918
        sqlite3VdbeJumpHere(v, loopTop);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   919
        for(j=0, pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext, j++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   920
          static const VdbeOpList cntIdx[] = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   921
             { OP_MemInt,       0,  2,  0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   922
             { OP_Rewind,       0,  0,  0},  /* 1 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   923
             { OP_MemIncr,      1,  2,  0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   924
             { OP_Next,         0,  0,  0},  /* 3 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   925
             { OP_MemLoad,      1,  0,  0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   926
             { OP_MemLoad,      2,  0,  0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   927
             { OP_Eq,           0,  0,  0},  /* 6 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   928
             { OP_MemIncr,     -1,  0,  0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   929
             { OP_String8,      0,  0,  "wrong # of entries in index "},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   930
             { OP_String8,      0,  0,  0},  /* 9 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   931
             { OP_Concat,       0,  0,  0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   932
             { OP_Callback,     1,  0,  0},
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   933
          };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   934
          if( pIdx->tnum==0 ) continue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   935
          addr = sqlite3VdbeAddOp(v, OP_IfMemPos, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   936
          sqlite3VdbeAddOp(v, OP_Halt, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   937
          sqlite3VdbeJumpHere(v, addr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   938
          addr = sqlite3VdbeAddOpList(v, ArraySize(cntIdx), cntIdx);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   939
          sqlite3VdbeChangeP1(v, addr+1, j+2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   940
          sqlite3VdbeChangeP2(v, addr+1, addr+4);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   941
          sqlite3VdbeChangeP1(v, addr+3, j+2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   942
          sqlite3VdbeChangeP2(v, addr+3, addr+2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   943
          sqlite3VdbeJumpHere(v, addr+6);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   944
          sqlite3VdbeChangeP3(v, addr+9, pIdx->zName, P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   945
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   946
      } 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   947
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   948
    addr = sqlite3VdbeAddOpList(v, ArraySize(endCode), endCode);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   949
    sqlite3VdbeChangeP1(v, addr+1, mxErr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   950
    sqlite3VdbeJumpHere(v, addr+2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   951
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   952
#endif /* SQLITE_OMIT_INTEGRITY_CHECK */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   953
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   954
#ifndef SQLITE_OMIT_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   955
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   956
  **   PRAGMA encoding
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   957
  **   PRAGMA encoding = "utf-8"|"utf-16"|"utf-16le"|"utf-16be"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   958
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   959
  ** In its first form, this pragma returns the encoding of the main
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   960
  ** database. If the database is not initialized, it is initialized now.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   961
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   962
  ** The second form of this pragma is a no-op if the main database file
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   963
  ** has not already been initialized. In this case it sets the default
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   964
  ** encoding that will be used for the main database file if a new file
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   965
  ** is created. If an existing main database file is opened, then the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   966
  ** default text encoding for the existing database is used.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   967
  ** 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   968
  ** In all cases new databases created using the ATTACH command are
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   969
  ** created to use the same default text encoding as the main database. If
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   970
  ** the main database has not been initialized and/or created when ATTACH
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   971
  ** is executed, this is done before the ATTACH operation.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   972
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   973
  ** In the second form this pragma sets the text encoding to be used in
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   974
  ** new database files created using this database handle. It is only
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   975
  ** useful if invoked immediately after the main database i
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   976
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   977
  if( sqlite3StrICmp(zLeft, "encoding")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   978
    static const struct EncName {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   979
      char *zName;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   980
      u8 enc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   981
    } encnames[] = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   982
      { "UTF-8",    SQLITE_UTF8        },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   983
      { "UTF8",     SQLITE_UTF8        },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   984
      { "UTF-16le", SQLITE_UTF16LE     },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   985
      { "UTF16le",  SQLITE_UTF16LE     },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   986
      { "UTF-16be", SQLITE_UTF16BE     },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   987
      { "UTF16be",  SQLITE_UTF16BE     },
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   988
      { "UTF-16",   0                  }, /* SQLITE_UTF16NATIVE */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   989
      { "UTF16",    0                  }, /* SQLITE_UTF16NATIVE */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   990
      { 0, 0 }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   991
    };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   992
    const struct EncName *pEnc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   993
    if( !zRight ){    /* "PRAGMA encoding" */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   994
      if( sqlite3ReadSchema(pParse) ) goto pragma_out;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   995
      sqlite3VdbeSetNumCols(v, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   996
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "encoding", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   997
      sqlite3VdbeAddOp(v, OP_String8, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   998
      for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   999
        if( pEnc->enc==ENC(pParse->db) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1000
          sqlite3VdbeChangeP3(v, -1, pEnc->zName, P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1001
          break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1002
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1003
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1004
      sqlite3VdbeAddOp(v, OP_Callback, 1, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1005
    }else{                        /* "PRAGMA encoding = XXX" */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1006
      /* Only change the value of sqlite.enc if the database handle is not
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1007
      ** initialized. If the main database exists, the new sqlite.enc value
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1008
      ** will be overwritten when the schema is next loaded. If it does not
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1009
      ** already exists, it will be created to use the new encoding value.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1010
      */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1011
      if( 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1012
        !(DbHasProperty(db, 0, DB_SchemaLoaded)) || 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1013
        DbHasProperty(db, 0, DB_Empty) 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1014
      ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1015
        for(pEnc=&encnames[0]; pEnc->zName; pEnc++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1016
          if( 0==sqlite3StrICmp(zRight, pEnc->zName) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1017
            ENC(pParse->db) = pEnc->enc ? pEnc->enc : SQLITE_UTF16NATIVE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1018
            break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1019
          }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1020
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1021
        if( !pEnc->zName ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1022
          sqlite3ErrorMsg(pParse, "unsupported encoding: %s", zRight);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1023
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1024
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1025
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1026
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1027
#endif /* SQLITE_OMIT_UTF16 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1028
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1029
#ifndef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1030
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1031
  **   PRAGMA [database.]schema_version
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1032
  **   PRAGMA [database.]schema_version = <integer>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1033
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1034
  **   PRAGMA [database.]user_version
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1035
  **   PRAGMA [database.]user_version = <integer>
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1036
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1037
  ** The pragma's schema_version and user_version are used to set or get
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1038
  ** the value of the schema-version and user-version, respectively. Both
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1039
  ** the schema-version and the user-version are 32-bit signed integers
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1040
  ** stored in the database header.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1041
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1042
  ** The schema-cookie is usually only manipulated internally by SQLite. It
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1043
  ** is incremented by SQLite whenever the database schema is modified (by
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1044
  ** creating or dropping a table or index). The schema version is used by
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1045
  ** SQLite each time a query is executed to ensure that the internal cache
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1046
  ** of the schema used when compiling the SQL query matches the schema of
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1047
  ** the database against which the compiled query is actually executed.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1048
  ** Subverting this mechanism by using "PRAGMA schema_version" to modify
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1049
  ** the schema-version is potentially dangerous and may lead to program
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1050
  ** crashes or database corruption. Use with caution!
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1051
  **
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1052
  ** The user-version is not used internally by SQLite. It may be used by
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1053
  ** applications for any purpose.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1054
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1055
  if( sqlite3StrICmp(zLeft, "schema_version")==0 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1056
   || sqlite3StrICmp(zLeft, "user_version")==0 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1057
   || sqlite3StrICmp(zLeft, "freelist_count")==0 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1058
  ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1059
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1060
    int iCookie;   /* Cookie index. 0 for schema-cookie, 6 for user-cookie. */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1061
    sqlite3VdbeUsesBtree(v, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1062
    switch( zLeft[0] ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1063
      case 's': case 'S':
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1064
        iCookie = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1065
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1066
      case 'f': case 'F':
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1067
        iCookie = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1068
        iDb = (-1*(iDb+1));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1069
        assert(iDb<=0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1070
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1071
      default:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1072
        iCookie = 5;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1073
        break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1074
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1075
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1076
    if( zRight && iDb>=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1077
      /* Write the specified cookie value */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1078
      static const VdbeOpList setCookie[] = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1079
        { OP_Transaction,    0,  1,  0},    /* 0 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1080
        { OP_Integer,        0,  0,  0},    /* 1 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1081
        { OP_SetCookie,      0,  0,  0},    /* 2 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1082
      };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1083
      int addr = sqlite3VdbeAddOpList(v, ArraySize(setCookie), setCookie);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1084
      sqlite3VdbeChangeP1(v, addr, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1085
      sqlite3VdbeChangeP1(v, addr+1, atoi(zRight));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1086
      sqlite3VdbeChangeP1(v, addr+2, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1087
      sqlite3VdbeChangeP2(v, addr+2, iCookie);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1088
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1089
      /* Read the specified cookie value */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1090
      static const VdbeOpList readCookie[] = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1091
        { OP_ReadCookie,      0,  0,  0},    /* 0 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1092
        { OP_Callback,        1,  0,  0}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1093
      };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1094
      int addr = sqlite3VdbeAddOpList(v, ArraySize(readCookie), readCookie);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1095
      sqlite3VdbeChangeP1(v, addr, iDb);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1096
      sqlite3VdbeChangeP2(v, addr, iCookie);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1097
      sqlite3VdbeSetNumCols(v, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1098
      sqlite3VdbeSetColName(v, 0, COLNAME_NAME, zLeft, P3_TRANSIENT);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1099
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1100
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1101
#endif /* SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1102
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1103
#if defined(SQLITE_DEBUG) || defined(SQLITE_TEST)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1104
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1105
  ** Report the current state of file logs for all databases
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1106
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1107
  if( sqlite3StrICmp(zLeft, "lock_status")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1108
    static const char *const azLockName[] = {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1109
      "unlocked", "shared", "reserved", "pending", "exclusive"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1110
    };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1111
    int i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1112
    Vdbe *v = sqlite3GetVdbe(pParse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1113
    sqlite3VdbeSetNumCols(v, 2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1114
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "database", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1115
    sqlite3VdbeSetColName(v, 1, COLNAME_NAME, "status", P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1116
    for(i=0; i<db->nDb; i++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1117
      Btree *pBt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1118
      Pager *pPager;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1119
      const char *zState = "unknown";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1120
      int j;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1121
      if( db->aDb[i].zName==0 ) continue;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1122
      sqlite3VdbeOp3(v, OP_String8, 0, 0, db->aDb[i].zName, P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1123
      pBt = db->aDb[i].pBt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1124
      if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1125
        zState = "closed";
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1126
      }else if( sqlite3_file_control(db, db->aDb[i].zName, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1127
                                     SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1128
         zState = azLockName[j];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1129
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1130
      sqlite3VdbeOp3(v, OP_String8, 0, 0, zState, P3_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1131
      sqlite3VdbeAddOp(v, OP_Callback, 2, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1132
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1133
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1134
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1135
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1136
#ifdef SQLITE_SSE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1137
  /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1138
  ** Check to see if the sqlite_statements table exists.  Create it
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1139
  ** if it does not.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1140
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1141
  if( sqlite3StrICmp(zLeft, "create_sqlite_statement_table")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1142
    extern int sqlite3CreateStatementsTable(Parse*);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1143
    sqlite3CreateStatementsTable(pParse);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1144
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1145
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1146
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1147
#if SQLITE_HAS_CODEC
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1148
  if( sqlite3StrICmp(zLeft, "key")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1149
    sqlite3_key(db, zRight, strlen(zRight));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1150
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1151
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1152
#if SQLITE_HAS_CODEC || defined(SQLITE_ENABLE_CEROD)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1153
  if( sqlite3StrICmp(zLeft, "activate_extensions")==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1154
#if SQLITE_HAS_CODEC
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1155
    if( sqlite3StrNICmp(zRight, "see-", 4)==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1156
      extern void sqlite3_activate_see(const char*);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1157
      sqlite3_activate_see(&zRight[4]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1158
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1159
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1160
#ifdef SQLITE_ENABLE_CEROD
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1161
    if( sqlite3StrNICmp(zRight, "cerod-", 6)==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1162
      extern void sqlite3_activate_cerod(const char*);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1163
      sqlite3_activate_cerod(&zRight[6]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1164
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1165
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1166
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1167
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1168
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1169
  {}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1170
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1171
  if( v ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1172
    /* Code an OP_Expire at the end of each PRAGMA program to cause
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1173
    ** the VDBE implementing the pragma to expire. Most (all?) pragmas
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1174
    ** are only valid for a single execution.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1175
    */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1176
    sqlite3VdbeAddOp(v, OP_Expire, 1, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1177
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1178
    /*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1179
    ** Reset the safety level, in case the fullfsync flag or synchronous
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1180
    ** setting changed.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1181
    */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1182
#ifndef SQLITE_OMIT_PAGER_PRAGMAS
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1183
    if( db->autoCommit ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1184
      sqlite3BtreeSetSafetyLevel(pDb->pBt, pDb->safety_level,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1185
                 (db->flags&SQLITE_FullFSync)!=0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1186
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1187
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1188
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1189
pragma_out:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1190
  sqlite3_free(zLeft);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1191
  sqlite3_free(zRight);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1192
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1193
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1194
#endif /* SQLITE_OMIT_PRAGMA || SQLITE_OMIT_PARSER */