/* ** Usage: btree_payload_size ID ** ** Return the number of bytes of payload */ static int btree_payload_size( void *NotUsed, Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ int argc, /* Number of arguments */ const char **argv /* Text of each argument */ ){ BtCursor *pCur; int n2; u64 n1; char zBuf[50]; if( argc!=2 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " ID\"", 0); return TCL_ERROR; } pCur = sqlite3TestTextToPtr(argv[1]); sqlite3BtreeEnter(pCur->pBtree); /* The cursor may be in "require-seek" state. If this is the case, the ** call to BtreeDataSize() will fix it. */ sqlite3BtreeDataSize(pCur, (u32*)&n2); if( pCur->apPage[pCur->iPage]->intKey ){ n1 = 0; }else{ sqlite3BtreeKeySize(pCur, (i64*)&n1); } sqlite3BtreeLeave(pCur->pBtree); sqlite3_snprintf(sizeof(zBuf),zBuf, "%d", (int)(n1+n2)); Tcl_AppendResult(interp, zBuf, 0); return SQLITE_OK; }
__declspec(dllexport) int WINAPI sqlite3_cursor_rowid(sqlite3_stmt *pstmt, int cursor, sqlite_int64 *prowid) { Vdbe *p = (Vdbe *)pstmt; sqlite3 *db = (p == NULL) ? NULL : p->db; int rc = 0; VdbeCursor *pC; int ret = 0; sqlite3_mutex_enter(db->mutex); while (1) { if (cursor < 0 || cursor >= p->nCursor) { ret = SQLITE_ERROR; break; } if (p->apCsr[cursor] == NULL) { ret = SQLITE_ERROR; break; } pC = p->apCsr[cursor]; ret = sqlite3VdbeCursorMoveto(pC); if(ret) break; if(pC->rowidIsValid) { *prowid = pC->lastRowid; } else if(pC->pseudoTableReg > 0) { ret = SQLITE_ERROR; break; } else if(pC->nullRow || pC->pCursor==0) { ret = SQLITE_ERROR; break; } else { if (pC->pCursor == NULL) { ret = SQLITE_ERROR; break; } sqlite3BtreeKeySize(pC->pCursor, prowid); *prowid = *prowid; } break; } sqlite3_mutex_leave(db->mutex); return ret; }