engine/sqlite/src/callback.cpp
author Sebastian Brannstrom <sebastianb@symbian.org>
Fri, 22 Oct 2010 14:28:27 +0100
branchsymbian1
changeset 266 ff6cd24e77e2
parent 2 29cda98b007e
permissions -rw-r--r--
Slightly tweaked icons
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
** 2005 May 23 
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
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    13
** This file contains functions used to access the internal hash tables
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
** of user defined functions and collation sequences.
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
** $Id: callback.cpp 1282 2008-11-13 09:31:33Z LarsPson $
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    17
*/
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
#include "sqliteInt.h"
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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
** Invoke the 'collation needed' callback to request a collation sequence
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
** in the database text encoding of name zName, length nName.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
** If the collation sequence
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
static void callCollNeeded(sqlite3 *db, const char *zName, int nName){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    27
  assert( !db->xCollNeeded || !db->xCollNeeded16 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
  if( nName<0 ) nName = strlen(zName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
  if( db->xCollNeeded ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
    char *zExternal = sqlite3DbStrNDup(db, zName, nName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
    if( !zExternal ) return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
    db->xCollNeeded(db->pCollNeededArg, db, (int)ENC(db), zExternal);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
    sqlite3_free(zExternal);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
#ifndef SQLITE_OMIT_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
  if( db->xCollNeeded16 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
    char const *zExternal;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
    sqlite3_value *pTmp = sqlite3ValueNew(db);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
    sqlite3ValueSetStr(pTmp, nName, zName, SQLITE_UTF8, SQLITE_STATIC);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
    zExternal = (const char*)sqlite3ValueText(pTmp, SQLITE_UTF16NATIVE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
    if( zExternal ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
      db->xCollNeeded16(db->pCollNeededArg, db, (int)ENC(db), zExternal);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
    sqlite3ValueFree(pTmp);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
#endif
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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
** This routine is called if the collation factory fails to deliver a
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
** collation function in the best encoding but there may be other versions
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
** of this collation function (for other text encodings) available. Use one
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
** of these instead if they exist. Avoid a UTF-8 <-> UTF-16 conversion if
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    54
** possible.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
static int synthCollSeq(sqlite3 *db, CollSeq *pColl){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
  CollSeq *pColl2;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
  char *z = pColl->zName;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
  int n = strlen(z);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    60
  int i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
  static const u8 aEnc[] = { SQLITE_UTF16BE, SQLITE_UTF16LE, SQLITE_UTF8 };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
  for(i=0; i<3; i++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
    pColl2 = sqlite3FindCollSeq(db, aEnc[i], z, n, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
    if( pColl2->xCmp!=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
      memcpy(pColl, pColl2, sizeof(CollSeq));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
      pColl->xDel = 0;         /* Do not copy the destructor */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
      return SQLITE_OK;
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
  return SQLITE_ERROR;
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
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
** This function is responsible for invoking the collation factory callback
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
** or substituting a collation sequence of a different encoding when the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    76
** requested collation sequence is not available in the database native
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
** encoding.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
** 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
** If it is not NULL, then pColl must point to the database native encoding 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
** collation sequence with name zName, length nName.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
** The return value is either the collation sequence to be used in database
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
** db for collation type name zName, length nName, or NULL, if no collation
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
** sequence can be found.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
CollSeq *sqlite3GetCollSeq(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
  sqlite3* db, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    88
  CollSeq *pColl, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    89
  const char *zName, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
  int nName
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    92
  CollSeq *p;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    93
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
  p = pColl;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
  if( !p ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
    p = sqlite3FindCollSeq(db, ENC(db), zName, nName, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    97
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
  if( !p || !p->xCmp ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
    /* No collation sequence of this type for this encoding is registered.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
    ** Call the collation factory to see if it can supply us with one.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
    */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
    callCollNeeded(db, zName, nName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
    p = sqlite3FindCollSeq(db, ENC(db), zName, nName, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
  if( p && !p->xCmp && synthCollSeq(db, p) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
    p = 0;
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
  assert( !p || p->xCmp );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
  return p;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   112
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
** This routine is called on a collation sequence before it is used to
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
** check that it is defined. An undefined collation sequence exists when
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
** a database is loaded that contains references to collation sequences
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
** that have not been defined by sqlite3_create_collation() etc.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   117
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   118
** If required, this routine calls the 'collation needed' callback to
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
** request a definition of the collating sequence. If this doesn't work, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
** an equivalent collating sequence that uses a text encoding different
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
** from the main database is substituted, if one is available.
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
int sqlite3CheckCollSeq(Parse *pParse, CollSeq *pColl){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
  if( pColl ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
    const char *zName = pColl->zName;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   126
    CollSeq *p = sqlite3GetCollSeq(pParse->db, pColl, zName, -1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
    if( !p ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
      if( pParse->nErr==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
        sqlite3ErrorMsg(pParse, "no such collation sequence: %s", zName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   130
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
      pParse->nErr++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
      return SQLITE_ERROR;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
    assert( p==pColl );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   141
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   142
** Locate and return an entry from the db.aCollSeq hash table. If the entry
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
** specified by zName and nName is not found and parameter 'create' is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
** true, then create a new entry. Otherwise return NULL.
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
** Each pointer stored in the sqlite3.aCollSeq hash table contains an
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
** array of three CollSeq structures. The first is the collation sequence
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
** prefferred for UTF-8, the second UTF-16le, and the third UTF-16be.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   149
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
** Stored immediately after the three collation sequences is a copy of
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
** the collation sequence name. A pointer to this string is stored in
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
** each collation sequence structure.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
static CollSeq *findCollSeqEntry(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
  sqlite3 *db,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
  const char *zName,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
  int nName,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
  int create
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
  CollSeq *pColl;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
  if( nName<0 ) nName = strlen(zName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
  pColl = (CollSeq*)sqlite3HashFind(&db->aCollSeq, zName, nName);
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
  if( 0==pColl && create ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
    pColl = (CollSeq*)sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
    if( pColl ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
      CollSeq *pDel = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
      pColl[0].zName = (char*)&pColl[3];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
      pColl[0].enc = SQLITE_UTF8;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
      pColl[1].zName = (char*)&pColl[3];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
      pColl[1].enc = SQLITE_UTF16LE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
      pColl[2].zName = (char*)&pColl[3];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
      pColl[2].enc = SQLITE_UTF16BE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
      memcpy(pColl[0].zName, zName, nName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
      pColl[0].zName[nName] = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
      pDel = (CollSeq*)sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
      /* If a malloc() failure occured in sqlite3HashInsert(), it will 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
      ** return the pColl pointer to be deleted (because it wasn't added
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
      ** to the hash table).
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
      */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
      assert( pDel==0 || pDel==pColl );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
      if( pDel!=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
        db->mallocFailed = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
        sqlite3_free(pDel);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
        pColl = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   187
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   188
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   189
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
  return pColl;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
** Parameter zName points to a UTF-8 encoded string nName bytes long.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
** Return the CollSeq* pointer for the collation sequence named zName
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
** for the encoding 'enc' from the database 'db'.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
** If the entry specified is not found and 'create' is true, then create a
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
** new entry.  Otherwise return NULL.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
** A separate function sqlite3LocateCollSeq() is a wrapper around
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   202
** this routine.  sqlite3LocateCollSeq() invokes the collation factory
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   203
** if necessary and generates an error message if the collating sequence
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   204
** cannot be found.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
CollSeq *sqlite3FindCollSeq(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
  sqlite3 *db,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
  u8 enc,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
  const char *zName,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
  int nName,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   211
  int create
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   212
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
  CollSeq *pColl;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
  if( zName ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
    pColl = findCollSeqEntry(db, zName, nName, create);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   217
    pColl = db->pDfltColl;
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
  assert( SQLITE_UTF8==1 && SQLITE_UTF16LE==2 && SQLITE_UTF16BE==3 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   220
  assert( enc>=SQLITE_UTF8 && enc<=SQLITE_UTF16BE );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
  if( pColl ) pColl += enc-1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
  return pColl;
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
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
** Locate a user function given a name, a number of arguments and a flag
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
** indicating whether the function prefers UTF-16 over UTF-8.  Return a
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
** pointer to the FuncDef structure that defines that function, or return
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
** NULL if the function does not exist.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
** If the createFlag argument is true, then a new (blank) FuncDef
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
** structure is created and liked into the "db" structure if a
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
** no matching function previously existed.  When createFlag is true
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
** and the nArg parameter is -1, then only a function that accepts
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
** any number of arguments will be returned.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   236
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   237
** If createFlag is false and nArg is -1, then the first valid
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
** function found is returned.  A function is valid if either xFunc
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
** or xStep is non-zero.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
** If createFlag is false, then a function with the required name and
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
** number of arguments may be returned even if the eTextRep flag does not
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
** match that requested.
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
FuncDef *sqlite3FindFunction(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
  sqlite3 *db,       /* An open database */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
  const char *zName, /* Name of the function.  Not null-terminated */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
  int nName,         /* Number of characters in the name */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
  int nArg,          /* Number of arguments.  -1 means any number */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
  u8 enc,            /* Preferred text encoding */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
  int createFlag     /* Create new entry if true and does not otherwise exist */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
  FuncDef *p;         /* Iterator variable */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
  FuncDef *pFirst;    /* First function with this name */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
  FuncDef *pBest = 0; /* Best match found so far */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
  int bestmatch = 0;  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   258
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
  assert( enc==SQLITE_UTF8 || enc==SQLITE_UTF16LE || enc==SQLITE_UTF16BE );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
  if( nArg<-1 ) nArg = -1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   261
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   262
  pFirst = (FuncDef*)sqlite3HashFind(&db->aFunc, zName, nName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
  for(p=pFirst; p; p=p->pNext){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
    /* During the search for the best function definition, bestmatch is set
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
    ** as follows to indicate the quality of the match with the definition
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   266
    ** pointed to by pBest:
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
    ** 0: pBest is NULL. No match has been found.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
    ** 1: A variable arguments function that prefers UTF-8 when a UTF-16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
    **    encoding is requested, or vice versa.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
    ** 2: A variable arguments function that uses UTF-16BE when UTF-16LE is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
    **    requested, or vice versa.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
    ** 3: A variable arguments function using the same text encoding.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
    ** 4: A function with the exact number of arguments requested that
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
    **    prefers UTF-8 when a UTF-16 encoding is requested, or vice versa.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
    ** 5: A function with the exact number of arguments requested that
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
    **    prefers UTF-16LE when UTF-16BE is requested, or vice versa.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
    ** 6: An exact match.
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
    ** A larger value of 'matchqual' indicates a more desirable match.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
    */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
    if( p->nArg==-1 || p->nArg==nArg || nArg==-1 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
      int match = 1;          /* Quality of this match */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   284
      if( p->nArg==nArg || nArg==-1 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   285
        match = 4;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   286
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
      if( enc==p->iPrefEnc ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
        match += 2;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
      else if( (enc==SQLITE_UTF16LE && p->iPrefEnc==SQLITE_UTF16BE) ||
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
               (enc==SQLITE_UTF16BE && p->iPrefEnc==SQLITE_UTF16LE) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
        match += 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
      if( match>bestmatch ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
        pBest = p;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
        bestmatch = match;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
  /* If the createFlag parameter is true, and the seach did not reveal an
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
  ** exact match for the name, number of arguments and encoding, then add a
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
  ** new entry to the hash table and return it.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   306
  if( createFlag && bestmatch<6 && 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   307
      (pBest = (FuncDef*)sqlite3DbMallocZero(db, sizeof(*pBest)+nName))!=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
    pBest->nArg = nArg;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   309
    pBest->pNext = pFirst;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
    pBest->iPrefEnc = enc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   311
    memcpy(pBest->zName, zName, nName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
    pBest->zName[nName] = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
    if( pBest==sqlite3HashInsert(&db->aFunc,pBest->zName,nName,(void*)pBest) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
      db->mallocFailed = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   315
      sqlite3_free(pBest);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
      return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   318
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   319
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   320
  if( pBest && (pBest->xStep || pBest->xFunc || createFlag) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   321
    return pBest;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   322
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   323
  return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   327
** Free all resources held by the schema structure. The void* argument points
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   328
** at a Schema struct. This function does not call sqlite3_free() on the 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   329
** pointer itself, it just cleans up subsiduary resources (i.e. the contents
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   330
** of the schema hash tables).
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
void sqlite3SchemaFree(void *p){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   333
  Hash temp1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   334
  Hash temp2;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   335
  HashElem *pElem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   336
  Schema *pSchema = (Schema *)p;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   338
  temp1 = pSchema->tblHash;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   339
  temp2 = pSchema->trigHash;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   340
  sqlite3HashInit(&pSchema->trigHash, SQLITE_HASH_STRING, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   341
  sqlite3HashClear(&pSchema->aFKey);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   342
  sqlite3HashClear(&pSchema->idxHash);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   343
  for(pElem=sqliteHashFirst(&temp2); pElem; pElem=sqliteHashNext(pElem)){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   344
    sqlite3DeleteTrigger((Trigger*)sqliteHashData(pElem));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   345
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   346
  sqlite3HashClear(&temp2);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   347
  sqlite3HashInit(&pSchema->tblHash, SQLITE_HASH_STRING, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   348
  for(pElem=sqliteHashFirst(&temp1); pElem; pElem=sqliteHashNext(pElem)){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   349
    Table *pTab = (Table*)sqliteHashData(pElem);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   350
    sqlite3DeleteTable(pTab);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   351
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   352
  sqlite3HashClear(&temp1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   353
  pSchema->pSeqTab = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   354
  pSchema->flags &= ~DB_SchemaLoaded;
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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   358
** Find and return the schema associated with a BTree.  Create
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   359
** a new one if necessary.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   361
Schema *sqlite3SchemaGet(sqlite3 *db, Btree *pBt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
  Schema * p;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   363
  if( pBt ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   364
    p = (Schema *)sqlite3BtreeSchema(pBt, sizeof(Schema), sqlite3SchemaFree);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   365
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   366
    p = (Schema *)sqlite3MallocZero(sizeof(Schema));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   367
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   368
  if( !p ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   369
    db->mallocFailed = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   370
  }else if ( 0==p->file_format ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   371
    sqlite3HashInit(&p->tblHash, SQLITE_HASH_STRING, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   372
    sqlite3HashInit(&p->idxHash, SQLITE_HASH_STRING, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   373
    sqlite3HashInit(&p->trigHash, SQLITE_HASH_STRING, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
    sqlite3HashInit(&p->aFKey, SQLITE_HASH_STRING, 1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
    p->enc = SQLITE_UTF8;
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
  return p;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   378
}