static int sqlite3VdbeAddOp4( Vdbe p, int op, int p1, int p2, int p3, byte[] pP4, int p4type ) { Debug.Assert( op == OP_Null || pP4 != null ); union_p4 _p4 = new union_p4(); _p4.z = Encoding.UTF8.GetString( pP4, 0, pP4.Length ); int addr = sqlite3VdbeAddOp3( p, op, p1, p2, p3 ); sqlite3VdbeChangeP4( p, addr, _p4, p4type ); return addr; }
//KeyInfo static int sqlite3VdbeAddOp4( Vdbe p, int op, int p1, int p2, int p3, KeyInfo pP4, int p4type ) { union_p4 _p4 = new union_p4(); _p4.pKeyInfo = pP4; int addr = sqlite3VdbeAddOp3( p, op, p1, p2, p3 ); sqlite3VdbeChangeP4( p, addr, _p4, p4type ); return addr; }
//char static int sqlite3VdbeAddOp4( Vdbe p, int op, int p1, int p2, int p3, char pP4, int p4type ) { union_p4 _p4 = new union_p4(); _p4.z = pP4.ToString(); int addr = sqlite3VdbeAddOp3( p, op, p1, p2, p3 ); sqlite3VdbeChangeP4( p, addr, _p4, p4type ); return addr; }
//StringBuilder static int sqlite3VdbeAddOp4( Vdbe p, int op, int p1, int p2, int p3, StringBuilder pP4, int p4type ) { // Debug.Assert( pP4 != null ); union_p4 _p4 = new union_p4(); _p4.z = pP4.ToString(); int addr = sqlite3VdbeAddOp3( p, op, p1, p2, p3 ); sqlite3VdbeChangeP4( p, addr, _p4, p4type ); return addr; }
static void sqlite3VdbeChangeP4( Vdbe p, int addr, string z, int n ) { union_p4 _p4 = new union_p4(); if ( n > 0 && n <= z.Length ) _p4.z = z.Substring( 0, n ); else _p4.z = z; sqlite3VdbeChangeP4( p, addr, _p4, n ); }
static void sqlite3VdbeChangeP4( Vdbe p, int addr, union_p4 _p4, int n ) { Op pOp; sqlite3 db; Debug.Assert( p != null ); db = p.db; Debug.Assert( p.magic == VDBE_MAGIC_INIT ); if ( p.aOp == null /*|| db.mallocFailed != 0 */) { if ( n != P4_KEYINFO && n != P4_VTAB ) { freeP4( db, n, _p4 ); } return; } Debug.Assert( p.nOp > 0 ); Debug.Assert( addr < p.nOp ); if ( addr < 0 ) { addr = p.nOp - 1; } pOp = p.aOp[addr]; freeP4( db, pOp.p4type, pOp.p4.p ); pOp.p4.p = null; if ( n == P4_INT32 ) { /* Note: this cast is safe, because the origin data point was an int ** that was cast to a (string ). */ pOp.p4.i = _p4.i; // SQLITE_PTR_TO_INT(zP4); pOp.p4type = P4_INT32; } else if ( n == P4_INT64 ) { pOp.p4.pI64 = _p4.pI64; pOp.p4type = n; } else if ( n == P4_REAL ) { pOp.p4.pReal = _p4.pReal; pOp.p4type = n; } else if ( _p4 == null ) { pOp.p4.p = null; pOp.p4type = P4_NOTUSED; } else if ( n == P4_KEYINFO ) { KeyInfo pKeyInfo; int nField, nByte; nField = _p4.pKeyInfo.nField; //nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo.aColl[0]) + nField; pKeyInfo = new KeyInfo();//sqlite3DbMallocRaw(0, nByte); pOp.p4.pKeyInfo = pKeyInfo; if ( pKeyInfo != null ) { //u8 *aSortOrder; // memcpy((char)pKeyInfo, zP4, nByte - nField); //aSortOrder = pKeyInfo.aSortOrder; //if( aSortOrder ){ // pKeyInfo.aSortOrder = (unsigned char)&pKeyInfo.aColl[nField]; // memcpy(pKeyInfo.aSortOrder, aSortOrder, nField); //} pKeyInfo = _p4.pKeyInfo.Copy(); pOp.p4type = P4_KEYINFO; } else { //p.db.mallocFailed = 1; pOp.p4type = P4_NOTUSED; } pOp.p4.pKeyInfo = _p4.pKeyInfo; pOp.p4type = P4_KEYINFO; } else if ( n == P4_KEYINFO_HANDOFF || n == P4_KEYINFO_STATIC ) { pOp.p4.pKeyInfo = _p4.pKeyInfo; pOp.p4type = P4_KEYINFO; } else if ( n == P4_FUNCDEF ) { pOp.p4.pFunc = _p4.pFunc; pOp.p4type = P4_FUNCDEF; } else if ( n == P4_COLLSEQ ) { pOp.p4.pColl = _p4.pColl; pOp.p4type = P4_COLLSEQ; } else if ( n == P4_DYNAMIC || n == P4_STATIC || n == P4_MPRINTF ) { pOp.p4.z = _p4.z; pOp.p4type = P4_DYNAMIC; } else if ( n == P4_MEM ) { pOp.p4.pMem = _p4.pMem; pOp.p4type = P4_MEM; } else if ( n == P4_INTARRAY ) { pOp.p4.ai = _p4.ai; pOp.p4type = P4_INTARRAY; } else if ( n == P4_SUBPROGRAM ) { pOp.p4.pProgram = _p4.pProgram; pOp.p4type = P4_SUBPROGRAM; } else if ( n == P4_VTAB ) { pOp.p4.pVtab = _p4.pVtab; pOp.p4type = P4_VTAB; sqlite3VtabLock( _p4.pVtab ); Debug.Assert( ( _p4.pVtab ).db == p.db ); } else if ( n < 0 ) { pOp.p4.p = _p4.p; pOp.p4type = n; } else { //if (n == 0) n = n = sqlite3Strlen30(zP4); pOp.p4.z = _p4.z;// sqlite3DbStrNDup(p.db, zP4, n); pOp.p4type = P4_DYNAMIC; } }
//STRING //STRING + Type static void sqlite3VdbeChangeP4( Vdbe p, int addr, string z, dxDel P4_Type ) { union_p4 _p4 = new union_p4(); _p4.z = z; sqlite3VdbeChangeP4( p, addr, _p4, P4_DYNAMIC ); }
/* ** Change the value of the P4 operand for a specific instruction. ** This routine is useful when a large program is loaded from a ** static array using sqlite3VdbeAddOpList but we want to make a ** few minor changes to the program. ** ** If n>=0 then the P4 operand is dynamic, meaning that a copy of ** the string is made into memory obtained from sqlite3Malloc(). ** A value of n==0 means copy bytes of zP4 up to and including the ** first null byte. If n>0 then copy n+1 bytes of zP4. ** ** If n==P4_KEYINFO it means that zP4 is a pointer to a KeyInfo structure. ** A copy is made of the KeyInfo structure into memory obtained from ** sqlite3Malloc, to be freed when the Vdbe is finalized. ** n==P4_KEYINFO_HANDOFF indicates that zP4 points to a KeyInfo structure ** stored in memory that the caller has obtained from sqlite3Malloc. The ** caller should not free the allocation, it will be freed when the Vdbe is ** finalized. ** ** Other values of n (P4_STATIC, P4_COLLSEQ etc.) indicate that zP4 points ** to a string or structure that is guaranteed to exist for the lifetime of ** the Vdbe. In these cases we can just copy the pointer. ** ** If addr<0 then change P4 on the most recently inserted instruction. */ //P4_COLLSEQ static void sqlite3VdbeChangeP4( Vdbe p, int addr, CollSeq pColl, int n ) { union_p4 _p4 = new union_p4(); _p4.pColl = pColl; sqlite3VdbeChangeP4( p, addr, _p4, n ); }
//CHAR static void sqlite3VdbeChangeP4( Vdbe p, int addr, char c, int n ) { union_p4 _p4 = new union_p4(); _p4.z = c.ToString(); sqlite3VdbeChangeP4( p, addr, _p4, n ); }
//MEM static void sqlite3VdbeChangeP4( Vdbe p, int addr, Mem m, int n ) { union_p4 _p4 = new union_p4(); _p4.pMem = m; sqlite3VdbeChangeP4( p, addr, _p4, n ); }
//P4_KEYINFO static void sqlite3VdbeChangeP4( Vdbe p, int addr, KeyInfo pKeyInfo, int n ) { union_p4 _p4 = new union_p4(); _p4.pKeyInfo = pKeyInfo; sqlite3VdbeChangeP4( p, addr, _p4, n ); }
//P4_INT32 static void sqlite3VdbeChangeP4( Vdbe p, int addr, int i32n, int n ) { union_p4 _p4 = new union_p4(); _p4.i = i32n; sqlite3VdbeChangeP4( p, addr, _p4, n ); }
//P4_FUNCDEF static void sqlite3VdbeChangeP4( Vdbe p, int addr, FuncDef pFunc, int n ) { union_p4 _p4 = new union_p4(); _p4.pFunc = pFunc; sqlite3VdbeChangeP4( p, addr, _p4, n ); }
//VTable static int sqlite3VdbeAddOp4( Vdbe p, int op, int p1, int p2, int p3, VTable pP4, int p4type ) { Debug.Assert( pP4 != null ); union_p4 _p4 = new union_p4(); _p4.pVtab = pP4; int addr = sqlite3VdbeAddOp3( p, op, p1, p2, p3 ); sqlite3VdbeChangeP4( p, addr, _p4, p4type ); return addr; }
//SUBPROGRAM static void sqlite3VdbeChangeP4( Vdbe p, int addr, SubProgram pProgram, int n ) { union_p4 _p4 = new union_p4(); _p4.pProgram = pProgram; sqlite3VdbeChangeP4( p, addr, _p4, n ); }
/* ** Add an opcode that includes the p4 value as an integer. */ static int sqlite3VdbeAddOp4Int( Vdbe p, /* Add the opcode to this VM */ int op, /* The new opcode */ int p1, /* The P1 operand */ int p2, /* The P2 operand */ int p3, /* The P3 operand */ int p4 /* The P4 operand as an integer */ ) { union_p4 _p4 = new union_p4(); _p4.i = p4; int addr = sqlite3VdbeAddOp3( p, op, p1, p2, p3 ); sqlite3VdbeChangeP4( p, addr, _p4, P4_INT32 ); return addr; }
//CollSeq private static int sqlite3VdbeAddOp4(Vdbe p, int op, int p1, int p2, int p3, CollSeq pP4, int p4type) { union_p4 _p4 = new union_p4(); _p4.pColl = pP4; int addr = sqlite3VdbeAddOp3(p, op, p1, p2, p3); sqlite3VdbeChangeP4(p, addr, _p4, p4type); return addr; }