diff options
Diffstat (limited to 'ext/sqlite/libsqlite/src/vdbeaux.c')
-rw-r--r-- | ext/sqlite/libsqlite/src/vdbeaux.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/ext/sqlite/libsqlite/src/vdbeaux.c b/ext/sqlite/libsqlite/src/vdbeaux.c index c08db5c088..6249a29f0b 100644 --- a/ext/sqlite/libsqlite/src/vdbeaux.c +++ b/ext/sqlite/libsqlite/src/vdbeaux.c @@ -992,3 +992,51 @@ void sqliteVdbeDelete(Vdbe *p){ p->magic = VDBE_MAGIC_DEAD; sqliteFree(p); } + +/* +** Convert an integer in between the native integer format and +** the bigEndian format used as the record number for tables. +** +** The bigEndian format (most significant byte first) is used for +** record numbers so that records will sort into the correct order +** even though memcmp() is used to compare the keys. On machines +** whose native integer format is little endian (ex: i486) the +** order of bytes is reversed. On native big-endian machines +** (ex: Alpha, Sparc, Motorola) the byte order is the same. +** +** This function is its own inverse. In other words +** +** X == byteSwap(byteSwap(X)) +*/ +int sqliteVdbeByteSwap(int x){ + union { + char zBuf[sizeof(int)]; + int i; + } ux; + ux.zBuf[3] = x&0xff; + ux.zBuf[2] = (x>>8)&0xff; + ux.zBuf[1] = (x>>16)&0xff; + ux.zBuf[0] = (x>>24)&0xff; + return ux.i; +} + +/* +** If a MoveTo operation is pending on the given cursor, then do that +** MoveTo now. Return an error code. If no MoveTo is pending, this +** routine does nothing and returns SQLITE_OK. +*/ +int sqliteVdbeCursorMoveto(Cursor *p){ + if( p->deferredMoveto ){ + int res; + extern int sqlite_search_count; + sqliteBtreeMoveto(p->pCursor, (char*)&p->movetoTarget, sizeof(int), &res); + p->lastRecno = keyToInt(p->movetoTarget); + p->recnoIsValid = res==0; + if( res<0 ){ + sqliteBtreeNext(p->pCursor, &res); + } + sqlite_search_count++; + p->deferredMoveto = 0; + } + return SQLITE_OK; +} |