static RC BindText(Vdbe p, int i, string z, int n, Action <string> del, TEXTENCODE encoding) { RC rc = VdbeUnbind(p, i); if (rc == RC.OK) { if (z != null) { Mem var = p.Vars[i - 1]; rc = MemSetStr(var, z, n, encoding, del); if (rc == RC.OK && encoding != 0) { rc = ChangeEncoding(var, E.CTXENCODE(p.Ctx)); } SysEx.Error(p.Ctx, rc, 0); rc = SysEx.ApiExit(p.Ctx, rc); } MutexEx.Leave(p.Ctx.Mutex); } else if (del != null) { del(z); } return(rc); }
static Mem ColumnMem(Vdbe p, int i) { Mem r; if (p != null && p.ResultSet != null && i < p.ResColumns && i >= 0) { MutexEx.Enter(p.Ctx.Mutex); r = p.ResultSet[i]; } else { if (p != null && C._ALWAYS(p.Ctx != null)) { MutexEx.Enter(p.Ctx.Mutex); SysEx.Error(p.Ctx, RC.RANGE, 0); } r = _nullMem; } return(r); }
// Routines used to attach values to wildcards in a compiled SQL statement. static RC VdbeUnbind(Vdbe p, int i) { if (VdbeSafetyNotNull(p)) { return(SysEx.MISUSE_BKPT()); } MutexEx.Enter(p.Ctx.Mutex); if (p.Magic != VDBE_MAGIC_RUN || p.PC >= 0) { SysEx.Error(p.Ctx, RC.MISUSE, 0); MutexEx.Leave(p.Ctx.Mutex); SysEx.LOG(RC.MISUSE, "bind on a busy prepared statement: [%s]", p.Sql); return(SysEx.MISUSE_BKPT()); } if (i < 1 || i > p.Vars) { SysEx.Error(p.Ctx, RC.RANGE, 0); MutexEx.Leave(p.Ctx.Mutex); return(RC.RANGE); } i--; Mem var = p.Vars[i]; MemRelease(var); var.Flags = MEM.Null; SysEx.Error(p.Ctx, RC.OK, 0); // If the bit corresponding to this variable in Vdbe.expmask is set, then binding a new value to this variable invalidates the current query plan. // // IMPLEMENTATION-OF: R-48440-37595 If the specific value bound to host parameter in the WHERE clause might influence the choice of query plan // for a statement, then the statement will be automatically recompiled, as if there had been a schema change, on the first sqlite3_step() call // following any change to the bindings of that parameter. if (p.IsPrepareV2 && ((i < 32 && p.Expmask != 0 & ((uint)1 << i) != 0) || p.Expmask == 0xffffffff)) { p.Expired = true; } return(RC.OK); }