engine/sqlite/src/vdbeapi.cpp
author Lars Persson <lars.persson@embeddev.se>
Wed, 31 Mar 2010 18:09:02 +0200
changeset 64 b52f6033af15
parent 2 29cda98b007e
permissions -rw-r--r--
Add so image conversion is done in feedinfo if image already exist. Check in feedengine if image exist from previous database(files might exist, even though the db is corrupt.
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
** 2004 May 26
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 code use to implement APIs that are part of the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    14
** VDBE.
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 "vdbeInt.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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    20
** Return TRUE (non-zero) of the statement supplied as an argument needs
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    21
** to be recompiled.  A statement needs to be recompiled whenever the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    22
** execution environment changes in a way that would alter the program
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
** that sqlite3_prepare() generates.  For example, if new functions or
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
** collating sequences are registered or if an authorizer function is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
** added or changed.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    27
EXPORT_C int sqlite3_expired(sqlite3_stmt *pStmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    28
  Vdbe *p = (Vdbe*)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
  return p==0 || p->expired;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    30
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    31
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
** The following routine destroys a virtual machine that is created by
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    34
** the sqlite3_compile() routine. The integer returned is an SQLITE_
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    35
** success/failure code that describes the result of executing the virtual
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
** machine.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    37
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    38
** This routine sets the error code and string returned by
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    39
** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16().
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    40
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    41
EXPORT_C int sqlite3_finalize(sqlite3_stmt *pStmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    42
  int rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    43
  if( pStmt==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    44
    rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    45
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
    Vdbe *v = (Vdbe*)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
    sqlite3_mutex *mutex = v->db->mutex;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
    sqlite3_mutex_enter(mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
    rc = sqlite3VdbeFinalize(v);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
    sqlite3_mutex_leave(mutex);
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
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    53
}
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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
** Terminate the current execution of an SQL statement and reset it
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
** back to its starting state so that it can be reused. A success code from
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
** the prior execution is returned.
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
** This routine sets the error code and string returned by
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    61
** sqlite3_errcode(), sqlite3_errmsg() and sqlite3_errmsg16().
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
EXPORT_C int sqlite3_reset(sqlite3_stmt *pStmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    64
  int rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
  if( pStmt==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
    rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
    Vdbe *v = (Vdbe*)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
    sqlite3_mutex_enter(v->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    70
    rc = sqlite3VdbeReset(v);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
    sqlite3VdbeMakeReady(v, -1, 0, 0, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
    assert( (rc & (v->db->errMask))==rc );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    73
    sqlite3_mutex_leave(v->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
  return rc;
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
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
** Set all the parameters in the compiled SQL statement to NULL.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    80
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    81
EXPORT_C int sqlite3_clear_bindings(sqlite3_stmt *pStmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    82
  int i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    83
  int rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    84
  Vdbe *v = (Vdbe*)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    85
  sqlite3_mutex_enter(v->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    86
  for(i=1; rc==SQLITE_OK && i<=sqlite3_bind_parameter_count(pStmt); i++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    87
    rc = sqlite3_bind_null(pStmt, i);
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
  sqlite3_mutex_leave(v->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    90
  return rc;
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
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
/**************************** sqlite3_value_  *******************************
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
** The following routines extract information from a Mem or sqlite3_value
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
** structure.
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
EXPORT_C const void *sqlite3_value_blob(sqlite3_value *pVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    99
  Mem *p = (Mem*)pVal;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   100
  if( p->flags & (MEM_Blob|MEM_Str) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   101
    sqlite3VdbeMemExpandBlob(p);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
    p->flags &= ~MEM_Str;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
    p->flags |= MEM_Blob;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
    return p->z;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
    return sqlite3_value_text(pVal);
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
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   109
EXPORT_C int sqlite3_value_bytes(sqlite3_value *pVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   110
  return sqlite3ValueBytes(pVal, SQLITE_UTF8);
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
EXPORT_C int sqlite3_value_bytes16(sqlite3_value *pVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   113
  return sqlite3ValueBytes(pVal, SQLITE_UTF16NATIVE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   114
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   115
EXPORT_C double sqlite3_value_double(sqlite3_value *pVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
  return sqlite3VdbeRealValue((Mem*)pVal);
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
EXPORT_C int sqlite3_value_int(sqlite3_value *pVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
  return sqlite3VdbeIntValue((Mem*)pVal);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   120
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
EXPORT_C sqlite_int64 sqlite3_value_int64(sqlite3_value *pVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   122
  return sqlite3VdbeIntValue((Mem*)pVal);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   123
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   124
EXPORT_C const unsigned char *sqlite3_value_text(sqlite3_value *pVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   125
  return (const unsigned char *)sqlite3ValueText(pVal, SQLITE_UTF8);
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_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   128
EXPORT_C const void *sqlite3_value_text16(sqlite3_value* pVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   129
  return sqlite3ValueText(pVal, SQLITE_UTF16NATIVE);
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
EXPORT_C const void *sqlite3_value_text16be(sqlite3_value *pVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
  return sqlite3ValueText(pVal, SQLITE_UTF16BE);
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
EXPORT_C const void *sqlite3_value_text16le(sqlite3_value *pVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
  return sqlite3ValueText(pVal, SQLITE_UTF16LE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
#endif /* SQLITE_OMIT_UTF16 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
EXPORT_C int sqlite3_value_type(sqlite3_value* pVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   139
  return pVal->type;
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
/**************************** sqlite3_result_  *******************************
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   143
** The following routines are used by user-defined functions to specify
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   144
** the function result.
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
EXPORT_C void sqlite3_result_blob(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
  sqlite3_context *pCtx, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   148
  const void *z, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   149
  int n, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
  void (*xDel)(void *)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   151
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   152
  assert( n>=0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
  sqlite3VdbeMemSetStr(&pCtx->s, (const char*)z, n, 0, xDel);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   155
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   156
EXPORT_C void sqlite3_result_double(sqlite3_context *pCtx, double rVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   157
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   158
  sqlite3VdbeMemSetDouble(&pCtx->s, rVal);
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
EXPORT_C void sqlite3_result_error(sqlite3_context *pCtx, const char *z, int n){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   161
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   162
  pCtx->isError = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   163
  sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, SQLITE_TRANSIENT);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   164
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   165
#ifndef SQLITE_OMIT_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   166
EXPORT_C void sqlite3_result_error16(sqlite3_context *pCtx, const void *z, int n){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   168
  pCtx->isError = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
  sqlite3VdbeMemSetStr(&pCtx->s, (const char*)z, n, SQLITE_UTF16NATIVE, SQLITE_TRANSIENT);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
EXPORT_C void sqlite3_result_int(sqlite3_context *pCtx, int iVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   174
  sqlite3VdbeMemSetInt64(&pCtx->s, (i64)iVal);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
EXPORT_C void sqlite3_result_int64(sqlite3_context *pCtx, i64 iVal){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   177
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   178
  sqlite3VdbeMemSetInt64(&pCtx->s, iVal);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
EXPORT_C void sqlite3_result_null(sqlite3_context *pCtx){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
  sqlite3VdbeMemSetNull(&pCtx->s);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
EXPORT_C void sqlite3_result_text(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
  sqlite3_context *pCtx, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   186
  const char *z, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   187
  int n,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   188
  void (*xDel)(void *)
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
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
  sqlite3VdbeMemSetStr(&pCtx->s, z, n, SQLITE_UTF8, xDel);
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
#ifndef SQLITE_OMIT_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
EXPORT_C void sqlite3_result_text16(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
  sqlite3_context *pCtx, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
  const void *z, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   197
  int n, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
  void (*xDel)(void *)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   199
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   200
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   201
  sqlite3VdbeMemSetStr(&pCtx->s, (const char*)z, n, SQLITE_UTF16NATIVE, xDel);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   202
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   203
EXPORT_C void sqlite3_result_text16be(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   204
  sqlite3_context *pCtx, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
  const void *z, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
  int n, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
  void (*xDel)(void *)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
  sqlite3VdbeMemSetStr(&pCtx->s, (const char*)z, n, SQLITE_UTF16BE, xDel);
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
EXPORT_C void sqlite3_result_text16le(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
  sqlite3_context *pCtx, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
  const void *z, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   215
  int n, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   216
  void (*xDel)(void *)
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
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
  sqlite3VdbeMemSetStr(&pCtx->s, (const char*)z, n, SQLITE_UTF16LE, xDel);
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_UTF16 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
EXPORT_C void sqlite3_result_value(sqlite3_context *pCtx, sqlite3_value *pValue){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
  sqlite3VdbeMemCopy(&pCtx->s, pValue);
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
EXPORT_C void sqlite3_result_zeroblob(sqlite3_context *pCtx, int n){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
  sqlite3VdbeMemSetZeroBlob(&pCtx->s, n);
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
/* Force an SQLITE_TOOBIG error. */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
EXPORT_C void sqlite3_result_error_toobig(sqlite3_context *pCtx){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
  sqlite3VdbeMemSetZeroBlob(&pCtx->s, SQLITE_MAX_LENGTH+1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
}
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
/* An SQLITE_NOMEM error. */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
EXPORT_C void sqlite3_result_error_nomem(sqlite3_context *pCtx){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
  sqlite3VdbeMemSetNull(&pCtx->s);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
  pCtx->isError = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   242
  pCtx->s.db->mallocFailed = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   243
}
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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
** Execute the statement pStmt, either until a row of data is ready, the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
** statement is completely executed or an error occurs.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   248
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   249
** This routine implements the bulk of the logic behind the sqlite_step()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
** API.  The only thing omitted is the automatic recompile if a 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
** schema change has occurred.  That detail is handled by the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
** outer sqlite3_step() wrapper procedure.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
static int sqlite3Step(Vdbe *p){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   255
  sqlite3 *db;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
  int rc;
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
  assert(p);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   259
  if( p->magic!=VDBE_MAGIC_RUN ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   260
    return SQLITE_MISUSE;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   263
  /* Assert that malloc() has not failed */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   264
  db = p->db;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   265
  assert( !db->mallocFailed );
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
  if( p->aborted ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   268
    return SQLITE_ABORT;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   269
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   270
  if( p->pc<=0 && p->expired ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   271
    if( p->rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   272
      p->rc = SQLITE_SCHEMA;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   273
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   274
    rc = SQLITE_ERROR;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   275
    goto end_of_step;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   276
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   277
  if( sqlite3SafetyOn(db) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
    p->rc = SQLITE_MISUSE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   279
    return SQLITE_MISUSE;
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
  if( p->pc<0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
    /* If there are no other statements currently running, then
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
    ** reset the interrupt flag.  This prevents a call to sqlite3_interrupt
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   284
    ** from interrupting a statement that has not yet started.
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
    if( db->activeVdbeCnt==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
      db->u1.isInterrupted = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
    }
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
#ifndef SQLITE_OMIT_TRACE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
    /* Invoke the trace callback if there is one
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
    */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
    if( db->xTrace && !db->init.busy ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
      assert( p->nOp>0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
      assert( p->aOp[p->nOp-1].opcode==OP_Noop );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
      assert( p->aOp[p->nOp-1].p3!=0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
      assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
      sqlite3SafetyOff(db);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
      db->xTrace(db->pTraceArg, p->aOp[p->nOp-1].p3);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
      if( sqlite3SafetyOn(db) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
        p->rc = SQLITE_MISUSE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
        return SQLITE_MISUSE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
    if( db->xProfile && !db->init.busy ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   306
      double rNow;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   307
      sqlite3OsCurrentTime(db->pVfs, &rNow);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
      p->startTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   309
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   311
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
    /* Print a copy of SQL as it is executed if the SQL_TRACE pragma is turned
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   313
    ** on in debugging mode.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   314
    */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   315
#ifdef SQLITE_DEBUG
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
    if( (db->flags & SQLITE_SqlTrace)!=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
      sqlite3DebugPrintf("SQL-trace: %s\n", p->aOp[p->nOp-1].p3);
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
#endif /* SQLITE_DEBUG */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   320
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   321
    db->activeVdbeCnt++;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   322
    p->pc = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   323
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
#ifndef SQLITE_OMIT_EXPLAIN
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
  if( p->explain ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
    rc = sqlite3VdbeList(p);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   327
  }else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   328
#endif /* SQLITE_OMIT_EXPLAIN */
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
    rc = sqlite3VdbeExec(p);
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
  if( sqlite3SafetyOff(db) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   334
    rc = SQLITE_MISUSE;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
#ifndef SQLITE_OMIT_TRACE
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   338
  /* Invoke the profile callback if there is one
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   339
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   340
  if( rc!=SQLITE_ROW && db->xProfile && !db->init.busy ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   341
    double rNow;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   342
    u64 elapseTime;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   343
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   344
    sqlite3OsCurrentTime(db->pVfs, &rNow);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   345
    elapseTime = (rNow - (int)rNow)*3600.0*24.0*1000000000.0 - p->startTime;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   346
    assert( p->nOp>0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   347
    assert( p->aOp[p->nOp-1].opcode==OP_Noop );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   348
    assert( p->aOp[p->nOp-1].p3!=0 );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   349
    assert( p->aOp[p->nOp-1].p3type==P3_DYNAMIC );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   350
    db->xProfile(db->pProfileArg, p->aOp[p->nOp-1].p3, elapseTime);
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
#endif
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
  sqlite3Error(p->db, rc, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   355
  p->rc = sqlite3ApiExit(p->db, p->rc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   356
end_of_step:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   357
  assert( (rc&0xff)==rc );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   358
  if( p->zSql && (rc&0xff)<SQLITE_ROW ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   359
    /* This behavior occurs if sqlite3_prepare_v2() was used to build
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
    ** the prepared statement.  Return error codes directly */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   361
    sqlite3Error(p->db, p->rc, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
    return p->rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   363
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   364
    /* This is for legacy sqlite3_prepare() builds and when the code
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   365
    ** is SQLITE_ROW or SQLITE_DONE */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   366
    return rc;
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
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   369
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
** This is the top-level implementation of sqlite3_step().  Call
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   372
** sqlite3Step() to do most of the work.  If a schema error occurs,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   373
** call sqlite3Reprepare() and try again.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
#ifdef SQLITE_OMIT_PARSER
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   376
int sqlite3_step(sqlite3_stmt *pStmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   377
  int rc = SQLITE_MISUSE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   378
  if( pStmt ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   379
    Vdbe *v;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   380
    v = (Vdbe*)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   381
    sqlite3_mutex_enter(v->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   382
    rc = sqlite3Step(v);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   383
    sqlite3_mutex_leave(v->db->mutex);
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
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   386
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   387
#else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   388
EXPORT_C int sqlite3_step(sqlite3_stmt *pStmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   389
  int rc = SQLITE_MISUSE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   390
  if( pStmt ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   391
    int cnt = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   392
    Vdbe *v = (Vdbe*)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   393
    sqlite3 *db = v->db;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   394
    sqlite3_mutex_enter(db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   395
    while( (rc = sqlite3Step(v))==SQLITE_SCHEMA
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   396
           && cnt++ < 5
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   397
           && sqlite3Reprepare(v) ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   398
      sqlite3_reset(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   399
      v->expired = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   400
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   401
    if( rc==SQLITE_SCHEMA && v->zSql && db->pErr ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
      /* This case occurs after failing to recompile an sql statement. 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   403
      ** The error message from the SQL compiler has already been loaded 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
      ** into the database handle. This block copies the error message 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   405
      ** from the database handle into the statement and sets the statement
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   406
      ** program counter to 0 to ensure that when the statement is 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   407
      ** finalized or reset the parser error message is available via
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   408
      ** sqlite3_errmsg() and sqlite3_errcode().
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
      const char *zErr = (const char *)sqlite3_value_text(db->pErr); 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   411
      sqlite3_free(v->zErrMsg);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   412
      if( !db->mallocFailed ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   413
        v->zErrMsg = sqlite3DbStrDup(db, zErr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   414
      } else {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   415
        v->zErrMsg = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   416
        v->rc = SQLITE_NOMEM;
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
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   419
    rc = sqlite3ApiExit(db, rc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
    sqlite3_mutex_leave(db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   422
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   423
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   424
#endif
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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   427
** Extract the user data from a sqlite3_context structure and return a
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   428
** pointer to it.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   429
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   430
EXPORT_C void *sqlite3_user_data(sqlite3_context *p){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   431
  assert( p && p->pFunc );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   432
  return p->pFunc->pUserData;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   433
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   434
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   435
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
** The following is the implementation of an SQL function that always
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   437
** fails with an error message stating that the function is used in the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   438
** wrong context.  The sqlite3_overload_function() API might construct
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   439
** SQL function that use this routine so that the functions will exist
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   440
** for name resolution but are actually overloaded by the xFindFunction
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   441
** method of virtual tables.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   443
void sqlite3InvalidFunction(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   444
  sqlite3_context *context,  /* The function calling context */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   445
  int argc,                  /* Number of arguments to the function */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   446
  sqlite3_value **argv       /* Value of each argument */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   447
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448
  const char *zName = context->pFunc->zName;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   449
  char *zErr;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   450
  zErr = sqlite3MPrintf(0,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   451
      "unable to use function %s in the requested context", zName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   452
  sqlite3_result_error(context, zErr, -1);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   453
  sqlite3_free(zErr);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   454
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   455
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
** Allocate or return the aggregate context for a user function.  A new
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   458
** context is allocated on the first call.  Subsequent calls return the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   459
** same context that was returned on prior calls.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   460
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   461
EXPORT_C void *sqlite3_aggregate_context(sqlite3_context *p, int nByte){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   462
  Mem *pMem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   463
  assert( p && p->pFunc && p->pFunc->xStep );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   464
  assert( sqlite3_mutex_held(p->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   465
  pMem = p->pMem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   466
  if( (pMem->flags & MEM_Agg)==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   467
    if( nByte==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   468
      assert( pMem->flags==MEM_Null );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   469
      pMem->z = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   470
    }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   471
      pMem->flags = MEM_Agg;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   472
      pMem->xDel = sqlite3_free;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   473
      pMem->u.pDef = p->pFunc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   474
      pMem->z = (char*)sqlite3DbMallocZero(p->s.db, nByte);
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
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   477
  return (void*)pMem->z;
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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   481
** Return the auxilary data pointer, if any, for the iArg'th argument to
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   482
** the user-function defined by pCtx.
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
EXPORT_C void *sqlite3_get_auxdata(sqlite3_context *pCtx, int iArg){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   485
  VdbeFunc *pVdbeFunc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   486
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   487
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   488
  pVdbeFunc = pCtx->pVdbeFunc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   489
  if( !pVdbeFunc || iArg>=pVdbeFunc->nAux || iArg<0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   490
    return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   491
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   492
  return pVdbeFunc->apAux[iArg].pAux;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   493
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   494
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   495
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   496
** Set the auxilary data pointer and delete function, for the iArg'th
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   497
** argument to the user-function defined by pCtx. Any previous value is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   498
** deleted by calling the delete function specified when it was set.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   499
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   500
EXPORT_C void sqlite3_set_auxdata(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   501
  sqlite3_context *pCtx, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   502
  int iArg, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   503
  void *pAux, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   504
  void (*xDelete)(void*)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   505
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   506
	VdbeFunc::AuxData *pAuxData;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   507
  VdbeFunc *pVdbeFunc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   508
  if( iArg<0 ) goto failed;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   509
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   510
  assert( sqlite3_mutex_held(pCtx->s.db->mutex) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   511
  pVdbeFunc = pCtx->pVdbeFunc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   512
  if( !pVdbeFunc || pVdbeFunc->nAux<=iArg ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   513
    int nAux = (pVdbeFunc ? pVdbeFunc->nAux : 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   514
	int nMalloc = sizeof(VdbeFunc) + sizeof(VdbeFunc::AuxData)*iArg;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   515
    pVdbeFunc = (VdbeFunc*)sqlite3DbRealloc(pCtx->s.db, pVdbeFunc, nMalloc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   516
    if( !pVdbeFunc ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   517
      goto failed;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   518
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   519
    pCtx->pVdbeFunc = pVdbeFunc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   520
	memset(&pVdbeFunc->apAux[nAux], 0, sizeof(VdbeFunc::AuxData)*(iArg+1-nAux));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   521
    pVdbeFunc->nAux = iArg+1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   522
    pVdbeFunc->pFunc = pCtx->pFunc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   523
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   524
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   525
  pAuxData = &pVdbeFunc->apAux[iArg];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   526
  if( pAuxData->pAux && pAuxData->xDelete ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   527
    pAuxData->xDelete(pAuxData->pAux);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   528
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   529
  pAuxData->pAux = pAux;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   530
  pAuxData->xDelete = xDelete;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   531
  return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   532
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   533
failed:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   534
  if( xDelete ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   535
    xDelete(pAux);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   536
  }
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   539
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   540
** Return the number of times the Step function of a aggregate has been 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   541
** called.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   542
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   543
** This function is deprecated.  Do not use it for new code.  It is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   544
** provide only to avoid breaking legacy code.  New aggregate function
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   545
** implementations should keep their own counts within their aggregate
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   546
** context.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   547
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   548
EXPORT_C int sqlite3_aggregate_count(sqlite3_context *p){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   549
  assert( p && p->pFunc && p->pFunc->xStep );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   550
  return p->pMem->n;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   551
}
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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   554
** Return the number of columns in the result set for the statement pStmt.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   555
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   556
EXPORT_C int sqlite3_column_count(sqlite3_stmt *pStmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   557
  Vdbe *pVm = (Vdbe *)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   558
  return pVm ? pVm->nResColumn : 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   559
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   560
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   561
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   562
** Return the number of values available from the current row of the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   563
** currently executing statement pStmt.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   564
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   565
EXPORT_C int sqlite3_data_count(sqlite3_stmt *pStmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   566
  Vdbe *pVm = (Vdbe *)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   567
  if( pVm==0 || !pVm->resOnStack ) return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   568
  return pVm->nResColumn;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   569
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   570
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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   573
** Check to see if column iCol of the given statement is valid.  If
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   574
** it is, return a pointer to the Mem for the value of that column.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   575
** If iCol is not valid, return a pointer to a Mem which has a value
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   576
** of NULL.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   577
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   578
static Mem *columnMem(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   579
  Vdbe *pVm;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   580
  int vals;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   581
  Mem *pOut;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   582
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   583
  pVm = (Vdbe *)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   584
  if( pVm && pVm->resOnStack && i<pVm->nResColumn && i>=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   585
    sqlite3_mutex_enter(pVm->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   586
    vals = sqlite3_data_count(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   587
    pOut = &pVm->pTos[(1-vals)+i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   588
  }else{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   589
    static const Mem nullMem = {{0}, 0.0, 0, "", 0, MEM_Null, SQLITE_NULL };
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   590
    if( pVm->db ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   591
      sqlite3_mutex_enter(pVm->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   592
      sqlite3Error(pVm->db, SQLITE_RANGE, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   593
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   594
    pOut = (Mem*)&nullMem;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   595
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   596
  return pOut;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   597
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   598
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
** This function is called after invoking an sqlite3_value_XXX function on a 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   601
** column value (i.e. a value returned by evaluating an SQL expression in the
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   602
** select list of a SELECT statement) that may cause a malloc() failure. If 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   603
** malloc() has failed, the threads mallocFailed flag is cleared and the result
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   604
** code of statement pStmt set to SQLITE_NOMEM.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   605
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   606
** Specifically, this is called from within:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   607
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   608
**     sqlite3_column_int()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   609
**     sqlite3_column_int64()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   610
**     sqlite3_column_text()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   611
**     sqlite3_column_text16()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   612
**     sqlite3_column_real()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   613
**     sqlite3_column_bytes()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   614
**     sqlite3_column_bytes16()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   615
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   616
** But not for sqlite3_column_blob(), which never calls malloc().
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   617
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   618
static void columnMallocFailure(sqlite3_stmt *pStmt)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   619
{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   620
  /* If malloc() failed during an encoding conversion within an
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   621
  ** sqlite3_column_XXX API, then set the return code of the statement to
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   622
  ** SQLITE_NOMEM. The next call to _step() (if any) will return SQLITE_ERROR
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   623
  ** and _finalize() will return NOMEM.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   624
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   625
  Vdbe *p = (Vdbe *)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   626
  if( p ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   627
    p->rc = sqlite3ApiExit(p->db, p->rc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   628
    sqlite3_mutex_leave(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   629
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   630
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   631
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   632
/**************************** sqlite3_column_  *******************************
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   633
** The following routines are used to access elements of the current row
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   634
** in the result set.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   635
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   636
EXPORT_C const void *sqlite3_column_blob(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   637
  const void *val;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   638
  val = sqlite3_value_blob( columnMem(pStmt,i) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   639
  /* Even though there is no encoding conversion, value_blob() might
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   640
  ** need to call malloc() to expand the result of a zeroblob() 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   641
  ** expression. 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   642
  */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   643
  columnMallocFailure(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   644
  return val;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   645
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   646
EXPORT_C int sqlite3_column_bytes(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   647
  int val = sqlite3_value_bytes( columnMem(pStmt,i) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   648
  columnMallocFailure(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   649
  return val;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   650
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   651
EXPORT_C int sqlite3_column_bytes16(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   652
  int val = sqlite3_value_bytes16( columnMem(pStmt,i) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   653
  columnMallocFailure(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   654
  return val;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   655
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   656
EXPORT_C double sqlite3_column_double(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   657
  double val = sqlite3_value_double( columnMem(pStmt,i) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   658
  columnMallocFailure(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   659
  return val;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   660
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   661
EXPORT_C int sqlite3_column_int(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   662
  int val = sqlite3_value_int( columnMem(pStmt,i) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   663
  columnMallocFailure(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   664
  return val;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   665
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   666
EXPORT_C sqlite_int64 sqlite3_column_int64(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   667
  sqlite_int64 val = sqlite3_value_int64( columnMem(pStmt,i) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   668
  columnMallocFailure(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   669
  return val;
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
EXPORT_C const unsigned char *sqlite3_column_text(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   672
  const unsigned char *val = sqlite3_value_text( columnMem(pStmt,i) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   673
  columnMallocFailure(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   674
  return val;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   675
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   676
EXPORT_C sqlite3_value *sqlite3_column_value(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   677
  sqlite3_value *pOut = columnMem(pStmt, i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   678
  columnMallocFailure(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   679
  return pOut;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   680
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   681
#ifndef SQLITE_OMIT_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   682
EXPORT_C const void *sqlite3_column_text16(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   683
  const void *val = sqlite3_value_text16( columnMem(pStmt,i) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   684
  columnMallocFailure(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   685
  return val;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   686
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   687
#endif /* SQLITE_OMIT_UTF16 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   688
EXPORT_C int sqlite3_column_type(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   689
  int iType = sqlite3_value_type( columnMem(pStmt,i) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   690
  columnMallocFailure(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   691
  return iType;
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
/* The following function is experimental and subject to change or
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   695
** removal */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   696
/*int sqlite3_column_numeric_type(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   697
**  return sqlite3_value_numeric_type( columnMem(pStmt,i) );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   698
**}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   699
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   700
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   701
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   702
** Convert the N-th element of pStmt->pColName[] into a string using
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   703
** xFunc() then return that string.  If N is out of range, return 0.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   704
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   705
** There are up to 5 names for each column.  useType determines which
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   706
** name is returned.  Here are the names:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   707
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   708
**    0      The column name as it should be displayed for output
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   709
**    1      The datatype name for the column
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   710
**    2      The name of the database that the column derives from
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   711
**    3      The name of the table that the column derives from
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   712
**    4      The name of the table column that the result column derives from
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   713
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   714
** If the result is not a simple column reference (if it is an expression
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   715
** or a constant) then useTypes 2, 3, and 4 return NULL.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   716
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   717
static const void *columnName(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   718
  sqlite3_stmt *pStmt,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   719
  int N,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   720
  const void *(*xFunc)(Mem*),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   721
  int useType
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   722
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   723
  const void *ret = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   724
  Vdbe *p = (Vdbe *)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   725
  int n;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   726
  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   727
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   728
  if( p!=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   729
    n = sqlite3_column_count(pStmt);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   730
    if( N<n && N>=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   731
      N += useType*n;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   732
      sqlite3_mutex_enter(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   733
      ret = xFunc(&p->aColName[N]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   734
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   735
      /* A malloc may have failed inside of the xFunc() call. If this
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   736
      ** is the case, clear the mallocFailed flag and return NULL.
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
      if( p->db && p->db->mallocFailed ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   739
        p->db->mallocFailed = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   740
        ret = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   741
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   742
      sqlite3_mutex_leave(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   743
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   744
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   745
  return ret;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   746
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   747
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   748
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   749
** Return the name of the Nth column of the result set returned by SQL
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   750
** statement pStmt.
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
EXPORT_C const char *sqlite3_column_name(sqlite3_stmt *pStmt, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   753
  return (const char*)columnName(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   754
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_NAME);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   755
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   756
#ifndef SQLITE_OMIT_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   757
EXPORT_C const void *sqlite3_column_name16(sqlite3_stmt *pStmt, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   758
  return columnName(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   759
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_NAME);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   760
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   761
#endif
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   762
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   763
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   764
** Return the column declaration type (if applicable) of the 'i'th column
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   765
** of the result set of SQL statement pStmt.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   766
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   767
EXPORT_C const char *sqlite3_column_decltype(sqlite3_stmt *pStmt, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   768
  return (const char*)columnName(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   769
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DECLTYPE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   770
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   771
#ifndef SQLITE_OMIT_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   772
EXPORT_C const void *sqlite3_column_decltype16(sqlite3_stmt *pStmt, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   773
  return columnName(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   774
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DECLTYPE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   775
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   776
#endif /* SQLITE_OMIT_UTF16 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   777
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   778
#ifdef SQLITE_ENABLE_COLUMN_METADATA
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   779
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   780
** Return the name of the database from which a result column derives.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   781
** NULL is returned if the result column is an expression or constant or
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   782
** anything else which is not an unabiguous reference to a database column.
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
const char *sqlite3_column_database_name(sqlite3_stmt *pStmt, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   785
  return columnName(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   786
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_DATABASE);
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
#ifndef SQLITE_OMIT_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   789
const void *sqlite3_column_database_name16(sqlite3_stmt *pStmt, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   790
  return columnName(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   791
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_DATABASE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   792
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   793
#endif /* SQLITE_OMIT_UTF16 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   794
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   795
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   796
** Return the name of the table from which a result column derives.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   797
** NULL is returned if the result column is an expression or constant or
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   798
** anything else which is not an unabiguous reference to a database column.
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
const char *sqlite3_column_table_name(sqlite3_stmt *pStmt, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   801
  return columnName(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   802
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_TABLE);
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
#ifndef SQLITE_OMIT_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   805
const void *sqlite3_column_table_name16(sqlite3_stmt *pStmt, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   806
  return columnName(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   807
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_TABLE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   808
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   809
#endif /* SQLITE_OMIT_UTF16 */
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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   812
** Return the name of the table column from which a result column derives.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   813
** NULL is returned if the result column is an expression or constant or
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   814
** anything else which is not an unabiguous reference to a database column.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   815
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   816
const char *sqlite3_column_origin_name(sqlite3_stmt *pStmt, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   817
  return columnName(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   818
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text, COLNAME_COLUMN);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   819
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   820
#ifndef SQLITE_OMIT_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   821
const void *sqlite3_column_origin_name16(sqlite3_stmt *pStmt, int N){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   822
  return columnName(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   823
      pStmt, N, (const void*(*)(Mem*))sqlite3_value_text16, COLNAME_COLUMN);
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
#endif /* SQLITE_OMIT_UTF16 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   826
#endif /* SQLITE_ENABLE_COLUMN_METADATA */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   827
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   828
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   829
/******************************* sqlite3_bind_  ***************************
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   830
** 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   831
** Routines used to attach values to wildcards in a compiled SQL statement.
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
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   834
** Unbind the value bound to variable i in virtual machine p. This is the 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   835
** the same as binding a NULL value to the column. If the "i" parameter is
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   836
** out of range, then SQLITE_RANGE is returned. Othewise SQLITE_OK.
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
** The error code stored in database p->db is overwritten with the return
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   839
** value in any case.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   840
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   841
static int vdbeUnbind(Vdbe *p, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   842
  Mem *pVar;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   843
  if( p==0 || p->magic!=VDBE_MAGIC_RUN || p->pc>=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   844
    if( p ) sqlite3Error(p->db, SQLITE_MISUSE, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   845
    return SQLITE_MISUSE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   846
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   847
  if( i<1 || i>p->nVar ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   848
    sqlite3Error(p->db, SQLITE_RANGE, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   849
    return SQLITE_RANGE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   850
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   851
  i--;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   852
  pVar = &p->aVar[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   853
  sqlite3VdbeMemRelease(pVar);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   854
  pVar->flags = MEM_Null;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   855
  sqlite3Error(p->db, SQLITE_OK, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   856
  return SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   857
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   858
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   859
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   860
** Bind a text or BLOB value.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   861
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   862
static int bindText(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   863
  sqlite3_stmt *pStmt,   /* The statement to bind against */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   864
  int i,                 /* Index of the parameter to bind */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   865
  const void *zData,     /* Pointer to the data to be bound */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   866
  int nData,             /* Number of bytes of data to be bound */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   867
  void (*xDel)(void*),   /* Destructor for the data */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   868
  int encoding           /* Encoding for the data */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   869
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   870
  Vdbe *p = (Vdbe *)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   871
  Mem *pVar;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   872
  int rc;
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( p==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   875
    return SQLITE_MISUSE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   876
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   877
  sqlite3_mutex_enter(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   878
  rc = vdbeUnbind(p, i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   879
  if( rc==SQLITE_OK && zData!=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   880
    pVar = &p->aVar[i-1];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   881
    rc = sqlite3VdbeMemSetStr(pVar, (const char*)zData, nData, encoding, xDel);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   882
    if( rc==SQLITE_OK && encoding!=0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   883
      rc = sqlite3VdbeChangeEncoding(pVar, ENC(p->db));
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
    sqlite3Error(p->db, rc, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   886
    rc = sqlite3ApiExit(p->db, rc);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   887
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   888
  sqlite3_mutex_leave(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   889
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   890
}
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   893
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   894
** Bind a blob value to an SQL statement variable.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   895
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   896
EXPORT_C int sqlite3_bind_blob(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   897
  sqlite3_stmt *pStmt, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   898
  int i, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   899
  const void *zData, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   900
  int nData, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   901
  void (*xDel)(void*)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   902
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   903
  return bindText(pStmt, i, zData, nData, xDel, 0);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   904
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   905
EXPORT_C int sqlite3_bind_double(sqlite3_stmt *pStmt, int i, double rValue){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   906
  int rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   907
  Vdbe *p = (Vdbe *)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   908
  sqlite3_mutex_enter(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   909
  rc = vdbeUnbind(p, i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   910
  if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   911
    sqlite3VdbeMemSetDouble(&p->aVar[i-1], rValue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   912
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   913
  sqlite3_mutex_leave(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   914
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   915
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   916
EXPORT_C int sqlite3_bind_int(sqlite3_stmt *p, int i, int iValue){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   917
  return sqlite3_bind_int64(p, i, (i64)iValue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   918
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   919
EXPORT_C int sqlite3_bind_int64(sqlite3_stmt *pStmt, int i, sqlite_int64 iValue){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   920
  int rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   921
  Vdbe *p = (Vdbe *)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   922
  sqlite3_mutex_enter(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   923
  rc = vdbeUnbind(p, i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   924
  if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   925
    sqlite3VdbeMemSetInt64(&p->aVar[i-1], iValue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   926
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   927
  sqlite3_mutex_leave(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   928
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   929
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   930
EXPORT_C int sqlite3_bind_null(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   931
  int rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   932
  Vdbe *p = (Vdbe*)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   933
  sqlite3_mutex_enter(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   934
  rc = vdbeUnbind(p, i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   935
  sqlite3_mutex_leave(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   936
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   937
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   938
EXPORT_C int sqlite3_bind_text( 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   939
  sqlite3_stmt *pStmt, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   940
  int i, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   941
  const char *zData, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   942
  int nData, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   943
  void (*xDel)(void*)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   944
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   945
  return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF8);
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
#ifndef SQLITE_OMIT_UTF16
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   948
EXPORT_C int sqlite3_bind_text16(
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   949
  sqlite3_stmt *pStmt, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   950
  int i, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   951
  const void *zData, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   952
  int nData, 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   953
  void (*xDel)(void*)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   954
){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   955
  return bindText(pStmt, i, zData, nData, xDel, SQLITE_UTF16NATIVE);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   956
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   957
#endif /* SQLITE_OMIT_UTF16 */
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   958
EXPORT_C int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   959
  int rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   960
  Vdbe *p = (Vdbe *)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   961
  sqlite3_mutex_enter(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   962
  rc = vdbeUnbind(p, i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   963
  if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   964
    rc = sqlite3VdbeMemCopy(&p->aVar[i-1], pValue);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   965
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   966
  sqlite3_mutex_leave(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   967
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   968
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   969
EXPORT_C int sqlite3_bind_zeroblob(sqlite3_stmt *pStmt, int i, int n){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   970
  int rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   971
  Vdbe *p = (Vdbe *)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   972
  sqlite3_mutex_enter(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   973
  rc = vdbeUnbind(p, i);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   974
  if( rc==SQLITE_OK ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   975
    sqlite3VdbeMemSetZeroBlob(&p->aVar[i-1], n);
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
  sqlite3_mutex_leave(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   978
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   979
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   980
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   981
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   982
** Return the number of wildcards that can be potentially bound to.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   983
** This routine is added to support DBD::SQLite.  
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   984
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   985
EXPORT_C int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   986
  Vdbe *p = (Vdbe*)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   987
  return p ? p->nVar : 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   988
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   989
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   990
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   991
** Create a mapping from variable numbers to variable names
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   992
** in the Vdbe.azVar[] array, if such a mapping does not already
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   993
** exist.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   994
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   995
static void createVarMap(Vdbe *p){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   996
  if( !p->okVar ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   997
    sqlite3_mutex_enter(p->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   998
    if( !p->okVar ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   999
      int j;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1000
      Op *pOp;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1001
      for(j=0, pOp=p->aOp; j<p->nOp; j++, pOp++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1002
        if( pOp->opcode==OP_Variable ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1003
          assert( pOp->p1>0 && pOp->p1<=p->nVar );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1004
          p->azVar[pOp->p1-1] = pOp->p3;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1005
        }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1006
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1007
      p->okVar = 1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1008
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1009
    sqlite3_mutex_leave(p->db->mutex);
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
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1012
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1013
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1014
** Return the name of a wildcard parameter.  Return NULL if the index
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1015
** is out of range or if the wildcard is unnamed.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1016
**
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1017
** The result is always UTF-8.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1018
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1019
EXPORT_C const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1020
  Vdbe *p = (Vdbe*)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1021
  if( p==0 || i<1 || i>p->nVar ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1022
    return 0;
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
  createVarMap(p);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1025
  return p->azVar[i-1];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1026
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1027
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
** Given a wildcard parameter name, return the index of the variable
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1030
** with that name.  If there is no variable with the given name,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1031
** return 0.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1032
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1033
EXPORT_C int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1034
  Vdbe *p = (Vdbe*)pStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1035
  int i;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1036
  if( p==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1037
    return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1038
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1039
  createVarMap(p); 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1040
  if( zName ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1041
    for(i=0; i<p->nVar; i++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1042
      const char *z = p->azVar[i];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1043
      if( z && strcmp(z,zName)==0 ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1044
        return i+1;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1045
      }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1046
    }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1047
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1048
  return 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1049
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1050
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
** Transfer all bindings from the first statement over to the second.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1053
** If the two statements contain a different number of bindings, then
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1054
** an SQLITE_ERROR is returned.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1055
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1056
EXPORT_C int sqlite3_transfer_bindings(sqlite3_stmt *pFromStmt, sqlite3_stmt *pToStmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1057
  Vdbe *pFrom = (Vdbe*)pFromStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1058
  Vdbe *pTo = (Vdbe*)pToStmt;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1059
  int i, rc = SQLITE_OK;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1060
  if( (pFrom->magic!=VDBE_MAGIC_RUN && pFrom->magic!=VDBE_MAGIC_HALT)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1061
    || (pTo->magic!=VDBE_MAGIC_RUN && pTo->magic!=VDBE_MAGIC_HALT)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1062
    || pTo->db!=pFrom->db ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1063
    return SQLITE_MISUSE;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1064
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1065
  if( pFrom->nVar!=pTo->nVar ){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1066
    return SQLITE_ERROR;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1067
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1068
  sqlite3_mutex_enter(pTo->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1069
  for(i=0; rc==SQLITE_OK && i<pFrom->nVar; i++){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1070
    sqlite3MallocDisallow();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1071
    rc = sqlite3VdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1072
    sqlite3MallocAllow();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1073
  }
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1074
  sqlite3_mutex_leave(pTo->db->mutex);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1075
  assert( rc==SQLITE_OK || rc==SQLITE_NOMEM );
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1076
  return rc;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1077
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1078
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1079
/*
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1080
** Return the sqlite3* database handle to which the prepared statement given
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1081
** in the argument belongs.  This is the same database handle that was
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1082
** the first argument to the sqlite3_prepare() that was used to create
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1083
** the statement in the first place.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1084
*/
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1085
EXPORT_C sqlite3 *sqlite3_db_handle(sqlite3_stmt *pStmt){
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1086
  return pStmt ? ((Vdbe*)pStmt)->db : 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
  1087
}