本文整理汇总了C#中UnpackedRecord类的典型用法代码示例。如果您正苦于以下问题:C# UnpackedRecord类的具体用法?C# UnpackedRecord怎么用?C# UnpackedRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnpackedRecord类属于命名空间,在下文中一共展示了UnpackedRecord类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: sqlite3VdbeIdxKeyCompare
/*
** Compare the key of the index entry that cursor pC is pointing to against
** the key string in pUnpacked. Write into *pRes a number
** that is negative, zero, or positive if pC is less than, equal to,
** or greater than pUnpacked. Return SQLITE_OK on success.
**
** pUnpacked is either created without a rowid or is truncated so that it
** omits the rowid at the end. The rowid at the end of the index entry
** is ignored as well. Hence, this routine only compares the prefixes
** of the keys prior to the final rowid, not the entire key.
*/
static int sqlite3VdbeIdxKeyCompare(
VdbeCursor pC, /* The cursor to compare against */
UnpackedRecord pUnpacked, /* Unpacked version of key to compare against */
ref int res /* Write the comparison result here */
)
{
i64 nCellKey = 0;
int rc;
BtCursor pCur = pC.pCursor;
Mem m = null;
Debug.Assert( sqlite3BtreeCursorIsValid( pCur ) );
rc = sqlite3BtreeKeySize( pCur, ref nCellKey );
Debug.Assert( rc == SQLITE_OK ); /* pCur is always valid so KeySize cannot fail */
/* nCellKey will always be between 0 and 0xffffffff because of the say
** that btreeParseCellPtr() and sqlite3GetVarint32() are implemented */
if ( nCellKey <= 0 || nCellKey > 0x7fffffff )
{
res = 0;
return SQLITE_CORRUPT_BKPT();
}
m = sqlite3Malloc( m );
// memset(&m, 0, sizeof(m));
rc = sqlite3VdbeMemFromBtree( pC.pCursor, 0, (int)nCellKey, true, m );
if ( rc != 0 )
{
return rc;
}
Debug.Assert( ( pUnpacked.flags & UNPACKED_IGNORE_ROWID ) != 0 );
res = sqlite3VdbeRecordCompare( m.n, m.zBLOB, pUnpacked );
sqlite3VdbeMemRelease( m );
return SQLITE_OK;
}
示例2: sqlite3VdbeExec
//.........这里部分代码省略.........
**
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
** use the value in register P3 as a key. If cursor P1 refers
** to an SQL index, then P3 is the first in an array of P4 registers
** that are used as an unpacked index key.
**
** Reposition cursor P1 so that it points to the largest entry that
** is less than the key value. If there are no records less than
** the key and P2 is not zero, then jump to P2.
**
** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLe
*/
/* Opcode: SeekLe P1 P2 P3 P4 *
**
** If cursor P1 refers to an SQL table (B-Tree that uses integer keys),
** use the value in register P3 as a key. If cursor P1 refers
** to an SQL index, then P3 is the first in an array of P4 registers
** that are used as an unpacked index key.
**
** Reposition cursor P1 so that it points to the largest entry that
** is less than or equal to the key value. If there are no records
** less than or equal to the key and P2 is not zero, then jump to P2.
**
** See also: Found, NotFound, Distinct, SeekGt, SeekGe, SeekLt
*/
case OP_SeekLt: /* jump, in3 */
case OP_SeekLe: /* jump, in3 */
case OP_SeekGe: /* jump, in3 */
case OP_SeekGt:
{ /* jump, in3 */
int res;
int oc;
VdbeCursor pC;
UnpackedRecord r;
int nField;
i64 iKey; /* The rowid we are to seek to */
res = 0;
r = new UnpackedRecord();
Debug.Assert(pOp.p1 >= 0 && pOp.p1 < p.nCursor);
Debug.Assert(pOp.p2 != 0);
pC = p.apCsr[pOp.p1];
Debug.Assert(pC != null);
Debug.Assert(pC.pseudoTableReg == 0);
Debug.Assert(OP_SeekLe == OP_SeekLt + 1);
Debug.Assert(OP_SeekGe == OP_SeekLt + 2);
Debug.Assert(OP_SeekGt == OP_SeekLt + 3);
Debug.Assert(pC.isOrdered);
if (pC.pCursor != null)
{
oc = pOp.opcode;
pC.nullRow = false;
if (pC.isTable)
{
/* The input value in P3 might be of any type: integer, real, string,
** blob, or NULL. But it needs to be an integer before we can do
** the seek, so convert it. */
pIn3 = aMem[pOp.p3];
applyNumericAffinity(pIn3);
iKey = sqlite3VdbeIntValue(pIn3);
pC.rowidIsValid = false;
/* If the P3 value could not be converted into an integer without
** loss of information, then special processing is required... */
if ((pIn3.flags & MEM_Int) == 0)
示例3: sqlite3VdbeRecordCompare
// ALTERNATE FORM for C#
static int sqlite3VdbeRecordCompare(
int nKey1, byte[] pKey1, /* Left key */
UnpackedRecord pPKey2 /* Right key */
)
{
return sqlite3VdbeRecordCompare( nKey1, pKey1, 0, pPKey2 );
}
示例4: sqlite3VdbeDeleteUnpackedRecord
/*
** This routine destroys a UnpackedRecord object.
*/
static void sqlite3VdbeDeleteUnpackedRecord( UnpackedRecord p )
{
#if SQLITE_DEBUG
int i;
Mem pMem;
Debug.Assert( p != null );
Debug.Assert( ( p.flags & UNPACKED_NEED_DESTROY ) != 0 );
//for ( i = 0, pMem = p->aMem ; i < p->nField ; i++, pMem++ )
//{
// /* The unpacked record is always constructed by the
// ** sqlite3VdbeUnpackRecord() function above, which makes all
// ** strings and blobs static. And none of the elements are
// ** ever transformed, so there is never anything to delete.
// */
// if ( NEVER( pMem->zMalloc ) ) sqlite3VdbeMemRelease( pMem );
//}
#endif
if ( ( p.flags & UNPACKED_NEED_FREE ) != 0 )
{
sqlite3DbFree( p.pKeyInfo.db, ref p.aMem );
p = null;
}
}
示例5: sqlite3VdbeRecordUnpack
/*
** Given the nKey-byte encoding of a record in pKey[], parse the
** record into a UnpackedRecord structure. Return a pointer to
** that structure.
**
** The calling function might provide szSpace bytes of memory
** space at pSpace. This space can be used to hold the returned
** VDbeParsedRecord structure if it is large enough. If it is
** not big enough, space is obtained from sqlite3Malloc().
**
** The returned structure should be closed by a call to
** sqlite3VdbeDeleteUnpackedRecord().
*/
static UnpackedRecord sqlite3VdbeRecordUnpack(
KeyInfo pKeyInfo, /* Information about the record format */
int nKey, /* Size of the binary record */
byte[] pKey, /* The binary record */
UnpackedRecord pSpace, // char *pSpace, /* Unaligned space available to hold the object */
int szSpace /* Size of pSpace[] in bytes */
)
{
byte[] aKey = pKey;
UnpackedRecord p; /* The unpacked record that we will return */
int nByte; /* Memory space needed to hold p, in bytes */
int d;
u32 idx;
int u; /* Unsigned loop counter */
int szHdr = 0;
Mem pMem;
int nOff; /* Increase pSpace by this much to 8-byte align it */
/*
** We want to shift the pointer pSpace up such that it is 8-byte aligned.
** Thus, we need to calculate a value, nOff, between 0 and 7, to shift
** it by. If pSpace is already 8-byte aligned, nOff should be zero.
*/
//nOff = ( 8 - ( SQLITE_PTR_TO_INT( pSpace ) & 7 ) ) & 7;
//pSpace += nOff;
//szSpace -= nOff;
//nByte = ROUND8( sizeof( UnpackedRecord ) ) + sizeof( Mem ) * ( pKeyInfo->nField + 1 );
//if ( nByte > szSpace)
//{
//var p = new UnpackedRecord();//sqlite3DbMallocRaw(pKeyInfo.db, nByte);
// if ( p == null ) return null;
// p.flags = UNPACKED_NEED_FREE | UNPACKED_NEED_DESTROY;
//}
//else
{
p = pSpace;//(UnpackedRecord)pSpace;
p.flags = UNPACKED_NEED_DESTROY;
}
p.pKeyInfo = pKeyInfo;
p.nField = (u16)( pKeyInfo.nField + 1 );
//p->aMem = pMem = (Mem)&( (char)p )[ROUND8( sizeof( UnpackedRecord ) )];
//Debug.Assert( EIGHT_BYTE_ALIGNMENT( pMem ) );
p.aMem = new Mem[p.nField + 1];
idx = (u32)getVarint32( aKey, 0, out szHdr );// GetVarint( aKey, szHdr );
d = (int)szHdr;
u = 0;
while ( idx < (int)szHdr && u < p.nField && d <= nKey )
{
p.aMem[u] = sqlite3Malloc( p.aMem[u] );
pMem = p.aMem[u];
u32 serial_type = 0;
idx += (u32)getVarint32( aKey, idx, out serial_type );// GetVarint( aKey + idx, serial_type );
pMem.enc = pKeyInfo.enc;
pMem.db = pKeyInfo.db;
/* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
//pMem.zMalloc = null;
d += (int)sqlite3VdbeSerialGet( aKey, d, serial_type, pMem );
//pMem++;
u++;
}
Debug.Assert( u <= pKeyInfo.nField + 1 );
p.nField = (u16)u;
return p;// (void)p;
}
示例6: btreeMoveto
/*
** In this version of BtreeMoveto, pKey is a packed index record
** such as is generated by the OP_MakeRecord opcode. Unpack the
** record and then call BtreeMovetoUnpacked() to do the work.
*/
static int btreeMoveto(
BtCursor pCur, /* Cursor open on the btree to be searched */
byte[] pKey, /* Packed key if the btree is an index */
i64 nKey, /* Integer key for tables. Size of pKey for indices */
int bias, /* Bias search to the high end */
ref int pRes /* Write search results here */
)
{
int rc; /* Status code */
UnpackedRecord pIdxKey; /* Unpacked index key */
UnpackedRecord aSpace = new UnpackedRecord();//char aSpace[150]; /* Temp space for pIdxKey - to avoid a malloc */
if ( pKey != null )
{
Debug.Assert( nKey == (i64)(int)nKey );
pIdxKey = sqlite3VdbeRecordUnpack( pCur.pKeyInfo, (int)nKey, pKey,
aSpace, 16 );//sizeof( aSpace ) );
//if ( pIdxKey == null )
// return SQLITE_NOMEM;
}
else
{
pIdxKey = null;
}
rc = sqlite3BtreeMovetoUnpacked( pCur, pIdxKey, nKey, bias != 0 ? 1 : 0, ref pRes );
if ( pKey != null )
{
sqlite3VdbeDeleteUnpackedRecord( pIdxKey );
}
return rc;
}
示例7: btreeMoveto
/// <summary>
/// In this version of BtreeMoveto, pKey is a packed index record
/// such as is generated by the OP_MakeRecord opcode. Unpack the
/// record and then call BtreeMovetoUnpacked() to do the work.
/// </summary>
/// <returns>
/// The moveto.
/// </returns>
/// <param name='pCur'>
/// Cursor open on the btree to be searched
/// </param>
/// <param name='pKey'>
/// Packed key if the btree is an index
/// </param>
/// <param name='nKey'>
/// Integer key for tables. Size of pKey for indices
/// </param>
/// <param name='bias'>
/// Bias search to the high end
/// </param>
/// <param name='pRes'>
/// Write search results here
/// </param>
static int btreeMoveto(BtCursor pCur, byte[] pKey, i64 nKey, int bias, ref int pRes)
{
int rc; /* Status code */
UnpackedRecord pIdxKey; /* Unpacked index key */
UnpackedRecord aSpace = new UnpackedRecord();//char aSpace[150]; /* Temp space for pIdxKey - to avoid a malloc */
if (pKey != null)
{
Debug.Assert(nKey == (i64)(int)nKey);
pIdxKey = sqlite3VdbeRecordUnpack(pCur.pKeyInfo, (int)nKey, pKey,
aSpace, 16);//sizeof( aSpace ) );
//if ( pIdxKey == null )
// return SQLITE_NOMEM;
}
else
{
pIdxKey = null;
}
rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias != 0 ? 1 : 0, ref pRes);
if (pKey != null)
{
sqlite3VdbeDeleteUnpackedRecord(pIdxKey);
}
return rc;
}
示例8: sqlite3VdbeRecordCompare
static int sqlite3VdbeRecordCompare(
int nKey1, byte[] pKey1, /* Left key */
int offset,
ref UnpackedRecord pPKey2 /* Right key */
)
{
int d1; /* Offset into aKey[] of next data element */
u32 idx1; /* Offset into aKey[] of next header element */
u32 szHdr1; /* Number of bytes in header */
int i = 0;
int nField;
int rc = 0;
KeyInfo pKeyInfo;
MemRef mem1 = VdbeRecordCompareScratchMem;
pKeyInfo = pPKey2.pKeyInfo;
mem1.enc = pKeyInfo.enc;
mem1.db = pKeyInfo.db;
mem1.flags = 0;
mem1.ui = 0; /* not needed, here to silence compiler warning */
//mem1.zMalloc = null;
idx1 = (u32)( ( szHdr1 = pKey1[offset] ) <= 0x7f ? 1 : getVarint32( pKey1, offset, ref szHdr1 ) );// GetVarint( aKey1, szHdr1 );
d1 = (int)szHdr1;
if ( ( pPKey2.flags & UNPACKED_IGNORE_ROWID ) != 0 )
{
szHdr1--;
}
nField = pKeyInfo.nField;
while ( idx1 < szHdr1 && i < pPKey2.nField )
{
u32 serial_type1;
/* Read the serial types for the next element in each key. */
idx1 += (u32)( ( serial_type1 = pKey1[idx1 + offset] ) <= 0x7f ? 1 : getVarint32( pKey1, (uint)(idx1 + offset), ref serial_type1 ) ); //GetVarint( aKey1 + idx1, serial_type1 );
if ( d1 >= nKey1 && sqlite3VdbeSerialTypeLen( serial_type1 ) > 0 ) break;
/* Extract the values to be compared.
*/
d1 += (int)sqlite3VdbeSerialGet( pKey1, d1 + offset, serial_type1, mem1 );
/* Do the comparison
*/
rc = sqlite3MemCompare( mem1, pPKey2.aMem[i], i < nField ? pKeyInfo.aColl[i] : null );
if ( rc != 0 )
{
break;
}
i++;
}
/* No memory allocation is ever used on mem1. */
//if ( NEVER( mem1.zMalloc ) ) sqlite3VdbeMemRelease( &mem1 );
/* If the PREFIX_SEARCH flag is set and all fields except the final
** rowid field were equal, then clear the PREFIX_SEARCH flag and set
** pPKey2->rowid to the value of the rowid field in (pKey1, nKey1).
** This is used by the OP_IsUnique opcode.
*/
if ( ( pPKey2.flags & UNPACKED_PREFIX_SEARCH ) != 0 && i == ( pPKey2.nField - 1 ) )
{
Debug.Assert( idx1 == szHdr1 && rc != 0 );
Debug.Assert( ( mem1.flags & MEM_Int ) != 0 );
pPKey2.flags = (ushort)( pPKey2.flags & ~UNPACKED_PREFIX_SEARCH );
pPKey2.rowid = mem1.ui;
}
if ( rc == 0 )
{
/* rc==0 here means that one of the keys ran out of fields and
** all the fields up to that point were equal. If the UNPACKED_INCRKEY
** flag is set, then break the tie by treating key2 as larger.
** If the UPACKED_PREFIX_MATCH flag is set, then keys with common prefixes
** are considered to be equal. Otherwise, the longer key is the
** larger. As it happens, the pPKey2 will always be the longer
** if there is a difference.
*/
if ( ( pPKey2.flags & UNPACKED_INCRKEY ) != 0 )
{
rc = -1;
}
else if ( ( pPKey2.flags & UNPACKED_PREFIX_MATCH ) != 0 )
{
/* Leave rc==0 */
}
else if ( idx1 < szHdr1 )
{
rc = 1;
}
}
else if ( pKeyInfo.aSortOrder != null && i < pKeyInfo.nField
&& pKeyInfo.aSortOrder[i] != 0 )
{
rc = -rc;
}
return rc;
}